pdf.combined.js 1.3 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821
  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.682';
  24. PDFJS.build = '9b3c96d';
  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 stringToBytes(str) {
  417. var length = str.length;
  418. var bytes = new Uint8Array(length);
  419. for (var i = 0; i < length; ++i) {
  420. bytes[i] = str.charCodeAt(i) & 0xFF;
  421. }
  422. return bytes;
  423. }
  424. function string32(value) {
  425. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  426. (value >> 8) & 0xff, value & 0xff);
  427. }
  428. function log2(x) {
  429. var n = 1, i = 0;
  430. while (x > n) {
  431. n <<= 1;
  432. i++;
  433. }
  434. return i;
  435. }
  436. function readInt8(data, start) {
  437. return (data[start] << 24) >> 24;
  438. }
  439. function readUint16(data, offset) {
  440. return (data[offset] << 8) | data[offset + 1];
  441. }
  442. function readUint32(data, offset) {
  443. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  444. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  445. }
  446. // Lazy test the endianness of the platform
  447. // NOTE: This will be 'true' for simulated TypedArrays
  448. function isLittleEndian() {
  449. var buffer8 = new Uint8Array(2);
  450. buffer8[0] = 1;
  451. var buffer16 = new Uint16Array(buffer8.buffer);
  452. return (buffer16[0] === 1);
  453. }
  454. Object.defineProperty(PDFJS, 'isLittleEndian', {
  455. configurable: true,
  456. get: function PDFJS_isLittleEndian() {
  457. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  458. }
  459. });
  460. // Lazy test if the userAgant support CanvasTypedArrays
  461. function hasCanvasTypedArrays() {
  462. var canvas = document.createElement('canvas');
  463. canvas.width = canvas.height = 1;
  464. var ctx = canvas.getContext('2d');
  465. var imageData = ctx.createImageData(1, 1);
  466. return (typeof imageData.data.buffer !== 'undefined');
  467. }
  468. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  469. configurable: true,
  470. get: function PDFJS_hasCanvasTypedArrays() {
  471. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  472. }
  473. });
  474. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  475. function Uint32ArrayView(buffer, length) {
  476. this.buffer = buffer;
  477. this.byteLength = buffer.length;
  478. this.length = length === undefined ? (this.byteLength >> 2) : length;
  479. ensureUint32ArrayViewProps(this.length);
  480. }
  481. Uint32ArrayView.prototype = Object.create(null);
  482. var uint32ArrayViewSetters = 0;
  483. function createUint32ArrayProp(index) {
  484. return {
  485. get: function () {
  486. var buffer = this.buffer, offset = index << 2;
  487. return (buffer[offset] | (buffer[offset + 1] << 8) |
  488. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  489. },
  490. set: function (value) {
  491. var buffer = this.buffer, offset = index << 2;
  492. buffer[offset] = value & 255;
  493. buffer[offset + 1] = (value >> 8) & 255;
  494. buffer[offset + 2] = (value >> 16) & 255;
  495. buffer[offset + 3] = (value >>> 24) & 255;
  496. }
  497. };
  498. }
  499. function ensureUint32ArrayViewProps(length) {
  500. while (uint32ArrayViewSetters < length) {
  501. Object.defineProperty(Uint32ArrayView.prototype,
  502. uint32ArrayViewSetters,
  503. createUint32ArrayProp(uint32ArrayViewSetters));
  504. uint32ArrayViewSetters++;
  505. }
  506. }
  507. return Uint32ArrayView;
  508. })();
  509. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  510. var Util = PDFJS.Util = (function UtilClosure() {
  511. function Util() {}
  512. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  513. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  514. // creating many intermediate strings.
  515. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  516. rgbBuf[1] = rgb[0];
  517. rgbBuf[3] = rgb[1];
  518. rgbBuf[5] = rgb[2];
  519. return rgbBuf.join('');
  520. };
  521. // Concatenates two transformation matrices together and returns the result.
  522. Util.transform = function Util_transform(m1, m2) {
  523. return [
  524. m1[0] * m2[0] + m1[2] * m2[1],
  525. m1[1] * m2[0] + m1[3] * m2[1],
  526. m1[0] * m2[2] + m1[2] * m2[3],
  527. m1[1] * m2[2] + m1[3] * m2[3],
  528. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  529. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  530. ];
  531. };
  532. // For 2d affine transforms
  533. Util.applyTransform = function Util_applyTransform(p, m) {
  534. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  535. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  536. return [xt, yt];
  537. };
  538. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  539. var d = m[0] * m[3] - m[1] * m[2];
  540. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  541. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  542. return [xt, yt];
  543. };
  544. // Applies the transform to the rectangle and finds the minimum axially
  545. // aligned bounding box.
  546. Util.getAxialAlignedBoundingBox =
  547. function Util_getAxialAlignedBoundingBox(r, m) {
  548. var p1 = Util.applyTransform(r, m);
  549. var p2 = Util.applyTransform(r.slice(2, 4), m);
  550. var p3 = Util.applyTransform([r[0], r[3]], m);
  551. var p4 = Util.applyTransform([r[2], r[1]], m);
  552. return [
  553. Math.min(p1[0], p2[0], p3[0], p4[0]),
  554. Math.min(p1[1], p2[1], p3[1], p4[1]),
  555. Math.max(p1[0], p2[0], p3[0], p4[0]),
  556. Math.max(p1[1], p2[1], p3[1], p4[1])
  557. ];
  558. };
  559. Util.inverseTransform = function Util_inverseTransform(m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  562. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  563. };
  564. // Apply a generic 3d matrix M on a 3-vector v:
  565. // | a b c | | X |
  566. // | d e f | x | Y |
  567. // | g h i | | Z |
  568. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  569. // with v as [X,Y,Z]
  570. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  571. return [
  572. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  573. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  574. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  575. ];
  576. };
  577. // This calculation uses Singular Value Decomposition.
  578. // The SVD can be represented with formula A = USV. We are interested in the
  579. // matrix S here because it represents the scale values.
  580. Util.singularValueDecompose2dScale =
  581. function Util_singularValueDecompose2dScale(m) {
  582. var transpose = [m[0], m[2], m[1], m[3]];
  583. // Multiply matrix m with its transpose.
  584. var a = m[0] * transpose[0] + m[1] * transpose[2];
  585. var b = m[0] * transpose[1] + m[1] * transpose[3];
  586. var c = m[2] * transpose[0] + m[3] * transpose[2];
  587. var d = m[2] * transpose[1] + m[3] * transpose[3];
  588. // Solve the second degree polynomial to get roots.
  589. var first = (a + d) / 2;
  590. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  591. var sx = first + second || 1;
  592. var sy = first - second || 1;
  593. // Scale values are the square roots of the eigenvalues.
  594. return [Math.sqrt(sx), Math.sqrt(sy)];
  595. };
  596. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  597. // For coordinate systems whose origin lies in the bottom-left, this
  598. // means normalization to (BL,TR) ordering. For systems with origin in the
  599. // top-left, this means (TL,BR) ordering.
  600. Util.normalizeRect = function Util_normalizeRect(rect) {
  601. var r = rect.slice(0); // clone rect
  602. if (rect[0] > rect[2]) {
  603. r[0] = rect[2];
  604. r[2] = rect[0];
  605. }
  606. if (rect[1] > rect[3]) {
  607. r[1] = rect[3];
  608. r[3] = rect[1];
  609. }
  610. return r;
  611. };
  612. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  613. // intersection of rect1 and rect2. If no intersection, returns 'false'
  614. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  615. Util.intersect = function Util_intersect(rect1, rect2) {
  616. function compare(a, b) {
  617. return a - b;
  618. }
  619. // Order points along the axes
  620. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  621. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  622. result = [];
  623. rect1 = Util.normalizeRect(rect1);
  624. rect2 = Util.normalizeRect(rect2);
  625. // X: first and second points belong to different rectangles?
  626. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  627. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  628. // Intersection must be between second and third points
  629. result[0] = orderedX[1];
  630. result[2] = orderedX[2];
  631. } else {
  632. return false;
  633. }
  634. // Y: first and second points belong to different rectangles?
  635. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  636. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  637. // Intersection must be between second and third points
  638. result[1] = orderedY[1];
  639. result[3] = orderedY[2];
  640. } else {
  641. return false;
  642. }
  643. return result;
  644. };
  645. Util.sign = function Util_sign(num) {
  646. return num < 0 ? -1 : 1;
  647. };
  648. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  649. Array.prototype.push.apply(arr1, arr2);
  650. };
  651. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  652. Array.prototype.unshift.apply(arr1, arr2);
  653. };
  654. Util.extendObj = function extendObj(obj1, obj2) {
  655. for (var key in obj2) {
  656. obj1[key] = obj2[key];
  657. }
  658. };
  659. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  660. name) {
  661. while (dict && !dict.has(name)) {
  662. dict = dict.get('Parent');
  663. }
  664. if (!dict) {
  665. return null;
  666. }
  667. return dict.get(name);
  668. };
  669. Util.inherit = function Util_inherit(sub, base, prototype) {
  670. sub.prototype = Object.create(base.prototype);
  671. sub.prototype.constructor = sub;
  672. for (var prop in prototype) {
  673. sub.prototype[prop] = prototype[prop];
  674. }
  675. };
  676. Util.loadScript = function Util_loadScript(src, callback) {
  677. var script = document.createElement('script');
  678. var loaded = false;
  679. script.setAttribute('src', src);
  680. if (callback) {
  681. script.onload = function() {
  682. if (!loaded) {
  683. callback();
  684. }
  685. loaded = true;
  686. };
  687. }
  688. document.getElementsByTagName('head')[0].appendChild(script);
  689. };
  690. return Util;
  691. })();
  692. /**
  693. * PDF page viewport created based on scale, rotation and offset.
  694. * @class
  695. * @alias PDFJS.PageViewport
  696. */
  697. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  698. /**
  699. * @constructor
  700. * @private
  701. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  702. * @param scale {number} scale of the viewport.
  703. * @param rotation {number} rotations of the viewport in degrees.
  704. * @param offsetX {number} offset X
  705. * @param offsetY {number} offset Y
  706. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  707. */
  708. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  709. this.viewBox = viewBox;
  710. this.scale = scale;
  711. this.rotation = rotation;
  712. this.offsetX = offsetX;
  713. this.offsetY = offsetY;
  714. // creating transform to convert pdf coordinate system to the normal
  715. // canvas like coordinates taking in account scale and rotation
  716. var centerX = (viewBox[2] + viewBox[0]) / 2;
  717. var centerY = (viewBox[3] + viewBox[1]) / 2;
  718. var rotateA, rotateB, rotateC, rotateD;
  719. rotation = rotation % 360;
  720. rotation = rotation < 0 ? rotation + 360 : rotation;
  721. switch (rotation) {
  722. case 180:
  723. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  724. break;
  725. case 90:
  726. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  727. break;
  728. case 270:
  729. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  730. break;
  731. //case 0:
  732. default:
  733. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  734. break;
  735. }
  736. if (dontFlip) {
  737. rotateC = -rotateC; rotateD = -rotateD;
  738. }
  739. var offsetCanvasX, offsetCanvasY;
  740. var width, height;
  741. if (rotateA === 0) {
  742. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  743. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  744. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  745. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  746. } else {
  747. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  748. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  749. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  750. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  751. }
  752. // creating transform for the following operations:
  753. // translate(-centerX, -centerY), rotate and flip vertically,
  754. // scale, and translate(offsetCanvasX, offsetCanvasY)
  755. this.transform = [
  756. rotateA * scale,
  757. rotateB * scale,
  758. rotateC * scale,
  759. rotateD * scale,
  760. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  761. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  762. ];
  763. this.width = width;
  764. this.height = height;
  765. this.fontScale = scale;
  766. }
  767. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  768. /**
  769. * Clones viewport with additional properties.
  770. * @param args {Object} (optional) If specified, may contain the 'scale' or
  771. * 'rotation' properties to override the corresponding properties in
  772. * the cloned viewport.
  773. * @returns {PDFJS.PageViewport} Cloned viewport.
  774. */
  775. clone: function PageViewPort_clone(args) {
  776. args = args || {};
  777. var scale = 'scale' in args ? args.scale : this.scale;
  778. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  779. return new PageViewport(this.viewBox.slice(), scale, rotation,
  780. this.offsetX, this.offsetY, args.dontFlip);
  781. },
  782. /**
  783. * Converts PDF point to the viewport coordinates. For examples, useful for
  784. * converting PDF location into canvas pixel coordinates.
  785. * @param x {number} X coordinate.
  786. * @param y {number} Y coordinate.
  787. * @returns {Object} Object that contains 'x' and 'y' properties of the
  788. * point in the viewport coordinate space.
  789. * @see {@link convertToPdfPoint}
  790. * @see {@link convertToViewportRectangle}
  791. */
  792. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  793. return Util.applyTransform([x, y], this.transform);
  794. },
  795. /**
  796. * Converts PDF rectangle to the viewport coordinates.
  797. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  798. * @returns {Array} Contains corresponding coordinates of the rectangle
  799. * in the viewport coordinate space.
  800. * @see {@link convertToViewportPoint}
  801. */
  802. convertToViewportRectangle:
  803. function PageViewport_convertToViewportRectangle(rect) {
  804. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  805. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  806. return [tl[0], tl[1], br[0], br[1]];
  807. },
  808. /**
  809. * Converts viewport coordinates to the PDF location. For examples, useful
  810. * for converting canvas pixel location into PDF one.
  811. * @param x {number} X coordinate.
  812. * @param y {number} Y coordinate.
  813. * @returns {Object} Object that contains 'x' and 'y' properties of the
  814. * point in the PDF coordinate space.
  815. * @see {@link convertToViewportPoint}
  816. */
  817. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  818. return Util.applyInverseTransform([x, y], this.transform);
  819. }
  820. };
  821. return PageViewport;
  822. })();
  823. var PDFStringTranslateTable = [
  824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  825. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  826. 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,
  827. 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,
  828. 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,
  829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  830. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  831. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  832. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  833. ];
  834. function stringToPDFString(str) {
  835. var i, n = str.length, strBuf = [];
  836. if (str[0] === '\xFE' && str[1] === '\xFF') {
  837. // UTF16BE BOM
  838. for (i = 2; i < n; i += 2) {
  839. strBuf.push(String.fromCharCode(
  840. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  841. }
  842. } else {
  843. for (i = 0; i < n; ++i) {
  844. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  845. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  846. }
  847. }
  848. return strBuf.join('');
  849. }
  850. function stringToUTF8String(str) {
  851. return decodeURIComponent(escape(str));
  852. }
  853. function isEmptyObj(obj) {
  854. for (var key in obj) {
  855. return false;
  856. }
  857. return true;
  858. }
  859. function isBool(v) {
  860. return typeof v === 'boolean';
  861. }
  862. function isInt(v) {
  863. return typeof v === 'number' && ((v | 0) === v);
  864. }
  865. function isNum(v) {
  866. return typeof v === 'number';
  867. }
  868. function isString(v) {
  869. return typeof v === 'string';
  870. }
  871. function isNull(v) {
  872. return v === null;
  873. }
  874. function isName(v) {
  875. return v instanceof Name;
  876. }
  877. function isCmd(v, cmd) {
  878. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  879. }
  880. function isDict(v, type) {
  881. if (!(v instanceof Dict)) {
  882. return false;
  883. }
  884. if (!type) {
  885. return true;
  886. }
  887. var dictType = v.get('Type');
  888. return isName(dictType) && dictType.name === type;
  889. }
  890. function isArray(v) {
  891. return v instanceof Array;
  892. }
  893. function isStream(v) {
  894. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  895. }
  896. function isArrayBuffer(v) {
  897. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  898. }
  899. function isRef(v) {
  900. return v instanceof Ref;
  901. }
  902. /**
  903. * Promise Capability object.
  904. *
  905. * @typedef {Object} PromiseCapability
  906. * @property {Promise} promise - A promise object.
  907. * @property {function} resolve - Fullfills the promise.
  908. * @property {function} reject - Rejects the promise.
  909. */
  910. /**
  911. * Creates a promise capability object.
  912. * @alias PDFJS.createPromiseCapability
  913. *
  914. * @return {PromiseCapability} A capability object contains:
  915. * - a Promise, resolve and reject methods.
  916. */
  917. function createPromiseCapability() {
  918. var capability = {};
  919. capability.promise = new Promise(function (resolve, reject) {
  920. capability.resolve = resolve;
  921. capability.reject = reject;
  922. });
  923. return capability;
  924. }
  925. PDFJS.createPromiseCapability = createPromiseCapability;
  926. /**
  927. * Polyfill for Promises:
  928. * The following promise implementation tries to generally implement the
  929. * Promise/A+ spec. Some notable differences from other promise libaries are:
  930. * - There currently isn't a seperate deferred and promise object.
  931. * - Unhandled rejections eventually show an error if they aren't handled.
  932. *
  933. * Based off of the work in:
  934. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  935. */
  936. (function PromiseClosure() {
  937. if (globalScope.Promise) {
  938. // Promises existing in the DOM/Worker, checking presence of all/resolve
  939. if (typeof globalScope.Promise.all !== 'function') {
  940. globalScope.Promise.all = function (iterable) {
  941. var count = 0, results = [], resolve, reject;
  942. var promise = new globalScope.Promise(function (resolve_, reject_) {
  943. resolve = resolve_;
  944. reject = reject_;
  945. });
  946. iterable.forEach(function (p, i) {
  947. count++;
  948. p.then(function (result) {
  949. results[i] = result;
  950. count--;
  951. if (count === 0) {
  952. resolve(results);
  953. }
  954. }, reject);
  955. });
  956. if (count === 0) {
  957. resolve(results);
  958. }
  959. return promise;
  960. };
  961. }
  962. if (typeof globalScope.Promise.resolve !== 'function') {
  963. globalScope.Promise.resolve = function (value) {
  964. return new globalScope.Promise(function (resolve) { resolve(value); });
  965. };
  966. }
  967. if (typeof globalScope.Promise.reject !== 'function') {
  968. globalScope.Promise.reject = function (reason) {
  969. return new globalScope.Promise(function (resolve, reject) {
  970. reject(reason);
  971. });
  972. };
  973. }
  974. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  975. globalScope.Promise.prototype.catch = function (onReject) {
  976. return globalScope.Promise.prototype.then(undefined, onReject);
  977. };
  978. }
  979. return;
  980. }
  981. var STATUS_PENDING = 0;
  982. var STATUS_RESOLVED = 1;
  983. var STATUS_REJECTED = 2;
  984. // In an attempt to avoid silent exceptions, unhandled rejections are
  985. // tracked and if they aren't handled in a certain amount of time an
  986. // error is logged.
  987. var REJECTION_TIMEOUT = 500;
  988. var HandlerManager = {
  989. handlers: [],
  990. running: false,
  991. unhandledRejections: [],
  992. pendingRejectionCheck: false,
  993. scheduleHandlers: function scheduleHandlers(promise) {
  994. if (promise._status === STATUS_PENDING) {
  995. return;
  996. }
  997. this.handlers = this.handlers.concat(promise._handlers);
  998. promise._handlers = [];
  999. if (this.running) {
  1000. return;
  1001. }
  1002. this.running = true;
  1003. setTimeout(this.runHandlers.bind(this), 0);
  1004. },
  1005. runHandlers: function runHandlers() {
  1006. var RUN_TIMEOUT = 1; // ms
  1007. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1008. while (this.handlers.length > 0) {
  1009. var handler = this.handlers.shift();
  1010. var nextStatus = handler.thisPromise._status;
  1011. var nextValue = handler.thisPromise._value;
  1012. try {
  1013. if (nextStatus === STATUS_RESOLVED) {
  1014. if (typeof handler.onResolve === 'function') {
  1015. nextValue = handler.onResolve(nextValue);
  1016. }
  1017. } else if (typeof handler.onReject === 'function') {
  1018. nextValue = handler.onReject(nextValue);
  1019. nextStatus = STATUS_RESOLVED;
  1020. if (handler.thisPromise._unhandledRejection) {
  1021. this.removeUnhandeledRejection(handler.thisPromise);
  1022. }
  1023. }
  1024. } catch (ex) {
  1025. nextStatus = STATUS_REJECTED;
  1026. nextValue = ex;
  1027. }
  1028. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1029. if (Date.now() >= timeoutAt) {
  1030. break;
  1031. }
  1032. }
  1033. if (this.handlers.length > 0) {
  1034. setTimeout(this.runHandlers.bind(this), 0);
  1035. return;
  1036. }
  1037. this.running = false;
  1038. },
  1039. addUnhandledRejection: function addUnhandledRejection(promise) {
  1040. this.unhandledRejections.push({
  1041. promise: promise,
  1042. time: Date.now()
  1043. });
  1044. this.scheduleRejectionCheck();
  1045. },
  1046. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1047. promise._unhandledRejection = false;
  1048. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1049. if (this.unhandledRejections[i].promise === promise) {
  1050. this.unhandledRejections.splice(i);
  1051. i--;
  1052. }
  1053. }
  1054. },
  1055. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1056. if (this.pendingRejectionCheck) {
  1057. return;
  1058. }
  1059. this.pendingRejectionCheck = true;
  1060. setTimeout(function rejectionCheck() {
  1061. this.pendingRejectionCheck = false;
  1062. var now = Date.now();
  1063. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1064. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1065. var unhandled = this.unhandledRejections[i].promise._value;
  1066. var msg = 'Unhandled rejection: ' + unhandled;
  1067. if (unhandled.stack) {
  1068. msg += '\n' + unhandled.stack;
  1069. }
  1070. warn(msg);
  1071. this.unhandledRejections.splice(i);
  1072. i--;
  1073. }
  1074. }
  1075. if (this.unhandledRejections.length) {
  1076. this.scheduleRejectionCheck();
  1077. }
  1078. }.bind(this), REJECTION_TIMEOUT);
  1079. }
  1080. };
  1081. function Promise(resolver) {
  1082. this._status = STATUS_PENDING;
  1083. this._handlers = [];
  1084. try {
  1085. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1086. } catch (e) {
  1087. this._reject(e);
  1088. }
  1089. }
  1090. /**
  1091. * Builds a promise that is resolved when all the passed in promises are
  1092. * resolved.
  1093. * @param {array} array of data and/or promises to wait for.
  1094. * @return {Promise} New dependant promise.
  1095. */
  1096. Promise.all = function Promise_all(promises) {
  1097. var resolveAll, rejectAll;
  1098. var deferred = new Promise(function (resolve, reject) {
  1099. resolveAll = resolve;
  1100. rejectAll = reject;
  1101. });
  1102. var unresolved = promises.length;
  1103. var results = [];
  1104. if (unresolved === 0) {
  1105. resolveAll(results);
  1106. return deferred;
  1107. }
  1108. function reject(reason) {
  1109. if (deferred._status === STATUS_REJECTED) {
  1110. return;
  1111. }
  1112. results = [];
  1113. rejectAll(reason);
  1114. }
  1115. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1116. var promise = promises[i];
  1117. var resolve = (function(i) {
  1118. return function(value) {
  1119. if (deferred._status === STATUS_REJECTED) {
  1120. return;
  1121. }
  1122. results[i] = value;
  1123. unresolved--;
  1124. if (unresolved === 0) {
  1125. resolveAll(results);
  1126. }
  1127. };
  1128. })(i);
  1129. if (Promise.isPromise(promise)) {
  1130. promise.then(resolve, reject);
  1131. } else {
  1132. resolve(promise);
  1133. }
  1134. }
  1135. return deferred;
  1136. };
  1137. /**
  1138. * Checks if the value is likely a promise (has a 'then' function).
  1139. * @return {boolean} true if value is thenable
  1140. */
  1141. Promise.isPromise = function Promise_isPromise(value) {
  1142. return value && typeof value.then === 'function';
  1143. };
  1144. /**
  1145. * Creates resolved promise
  1146. * @param value resolve value
  1147. * @returns {Promise}
  1148. */
  1149. Promise.resolve = function Promise_resolve(value) {
  1150. return new Promise(function (resolve) { resolve(value); });
  1151. };
  1152. /**
  1153. * Creates rejected promise
  1154. * @param reason rejection value
  1155. * @returns {Promise}
  1156. */
  1157. Promise.reject = function Promise_reject(reason) {
  1158. return new Promise(function (resolve, reject) { reject(reason); });
  1159. };
  1160. Promise.prototype = {
  1161. _status: null,
  1162. _value: null,
  1163. _handlers: null,
  1164. _unhandledRejection: null,
  1165. _updateStatus: function Promise__updateStatus(status, value) {
  1166. if (this._status === STATUS_RESOLVED ||
  1167. this._status === STATUS_REJECTED) {
  1168. return;
  1169. }
  1170. if (status === STATUS_RESOLVED &&
  1171. Promise.isPromise(value)) {
  1172. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1173. this._updateStatus.bind(this, STATUS_REJECTED));
  1174. return;
  1175. }
  1176. this._status = status;
  1177. this._value = value;
  1178. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1179. this._unhandledRejection = true;
  1180. HandlerManager.addUnhandledRejection(this);
  1181. }
  1182. HandlerManager.scheduleHandlers(this);
  1183. },
  1184. _resolve: function Promise_resolve(value) {
  1185. this._updateStatus(STATUS_RESOLVED, value);
  1186. },
  1187. _reject: function Promise_reject(reason) {
  1188. this._updateStatus(STATUS_REJECTED, reason);
  1189. },
  1190. then: function Promise_then(onResolve, onReject) {
  1191. var nextPromise = new Promise(function (resolve, reject) {
  1192. this.resolve = resolve;
  1193. this.reject = reject;
  1194. });
  1195. this._handlers.push({
  1196. thisPromise: this,
  1197. onResolve: onResolve,
  1198. onReject: onReject,
  1199. nextPromise: nextPromise
  1200. });
  1201. HandlerManager.scheduleHandlers(this);
  1202. return nextPromise;
  1203. },
  1204. catch: function Promise_catch(onReject) {
  1205. return this.then(undefined, onReject);
  1206. }
  1207. };
  1208. globalScope.Promise = Promise;
  1209. })();
  1210. var StatTimer = (function StatTimerClosure() {
  1211. function rpad(str, pad, length) {
  1212. while (str.length < length) {
  1213. str += pad;
  1214. }
  1215. return str;
  1216. }
  1217. function StatTimer() {
  1218. this.started = {};
  1219. this.times = [];
  1220. this.enabled = true;
  1221. }
  1222. StatTimer.prototype = {
  1223. time: function StatTimer_time(name) {
  1224. if (!this.enabled) {
  1225. return;
  1226. }
  1227. if (name in this.started) {
  1228. warn('Timer is already running for ' + name);
  1229. }
  1230. this.started[name] = Date.now();
  1231. },
  1232. timeEnd: function StatTimer_timeEnd(name) {
  1233. if (!this.enabled) {
  1234. return;
  1235. }
  1236. if (!(name in this.started)) {
  1237. warn('Timer has not been started for ' + name);
  1238. }
  1239. this.times.push({
  1240. 'name': name,
  1241. 'start': this.started[name],
  1242. 'end': Date.now()
  1243. });
  1244. // Remove timer from started so it can be called again.
  1245. delete this.started[name];
  1246. },
  1247. toString: function StatTimer_toString() {
  1248. var i, ii;
  1249. var times = this.times;
  1250. var out = '';
  1251. // Find the longest name for padding purposes.
  1252. var longest = 0;
  1253. for (i = 0, ii = times.length; i < ii; ++i) {
  1254. var name = times[i]['name'];
  1255. if (name.length > longest) {
  1256. longest = name.length;
  1257. }
  1258. }
  1259. for (i = 0, ii = times.length; i < ii; ++i) {
  1260. var span = times[i];
  1261. var duration = span.end - span.start;
  1262. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1263. }
  1264. return out;
  1265. }
  1266. };
  1267. return StatTimer;
  1268. })();
  1269. PDFJS.createBlob = function createBlob(data, contentType) {
  1270. if (typeof Blob !== 'undefined') {
  1271. return new Blob([data], { type: contentType });
  1272. }
  1273. // Blob builder is deprecated in FF14 and removed in FF18.
  1274. var bb = new MozBlobBuilder();
  1275. bb.append(data);
  1276. return bb.getBlob(contentType);
  1277. };
  1278. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1279. // Blob/createObjectURL is not available, falling back to data schema.
  1280. var digits =
  1281. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1282. return function createObjectURL(data, contentType) {
  1283. if (!PDFJS.disableCreateObjectURL &&
  1284. typeof URL !== 'undefined' && URL.createObjectURL) {
  1285. var blob = PDFJS.createBlob(data, contentType);
  1286. return URL.createObjectURL(blob);
  1287. }
  1288. var buffer = 'data:' + contentType + ';base64,';
  1289. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1290. var b1 = data[i] & 0xFF;
  1291. var b2 = data[i + 1] & 0xFF;
  1292. var b3 = data[i + 2] & 0xFF;
  1293. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1294. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1295. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1296. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1297. }
  1298. return buffer;
  1299. };
  1300. })();
  1301. function MessageHandler(name, comObj) {
  1302. this.name = name;
  1303. this.comObj = comObj;
  1304. this.callbackIndex = 1;
  1305. this.postMessageTransfers = true;
  1306. var callbacksCapabilities = this.callbacksCapabilities = {};
  1307. var ah = this.actionHandler = {};
  1308. ah['console_log'] = [function ahConsoleLog(data) {
  1309. console.log.apply(console, data);
  1310. }];
  1311. ah['console_error'] = [function ahConsoleError(data) {
  1312. console.error.apply(console, data);
  1313. }];
  1314. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1315. UnsupportedManager.notify(data);
  1316. }];
  1317. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1318. var data = event.data;
  1319. if (data.isReply) {
  1320. var callbackId = data.callbackId;
  1321. if (data.callbackId in callbacksCapabilities) {
  1322. var callback = callbacksCapabilities[callbackId];
  1323. delete callbacksCapabilities[callbackId];
  1324. if ('error' in data) {
  1325. callback.reject(data.error);
  1326. } else {
  1327. callback.resolve(data.data);
  1328. }
  1329. } else {
  1330. error('Cannot resolve callback ' + callbackId);
  1331. }
  1332. } else if (data.action in ah) {
  1333. var action = ah[data.action];
  1334. if (data.callbackId) {
  1335. Promise.resolve().then(function () {
  1336. return action[0].call(action[1], data.data);
  1337. }).then(function (result) {
  1338. comObj.postMessage({
  1339. isReply: true,
  1340. callbackId: data.callbackId,
  1341. data: result
  1342. });
  1343. }, function (reason) {
  1344. comObj.postMessage({
  1345. isReply: true,
  1346. callbackId: data.callbackId,
  1347. error: reason
  1348. });
  1349. });
  1350. } else {
  1351. action[0].call(action[1], data.data);
  1352. }
  1353. } else {
  1354. error('Unknown action from worker: ' + data.action);
  1355. }
  1356. };
  1357. }
  1358. MessageHandler.prototype = {
  1359. on: function messageHandlerOn(actionName, handler, scope) {
  1360. var ah = this.actionHandler;
  1361. if (ah[actionName]) {
  1362. error('There is already an actionName called "' + actionName + '"');
  1363. }
  1364. ah[actionName] = [handler, scope];
  1365. },
  1366. /**
  1367. * Sends a message to the comObj to invoke the action with the supplied data.
  1368. * @param {String} actionName Action to call.
  1369. * @param {JSON} data JSON data to send.
  1370. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1371. */
  1372. send: function messageHandlerSend(actionName, data, transfers) {
  1373. var message = {
  1374. action: actionName,
  1375. data: data
  1376. };
  1377. this.postMessage(message, transfers);
  1378. },
  1379. /**
  1380. * Sends a message to the comObj to invoke the action with the supplied data.
  1381. * Expects that other side will callback with the response.
  1382. * @param {String} actionName Action to call.
  1383. * @param {JSON} data JSON data to send.
  1384. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1385. * @returns {Promise} Promise to be resolved with response data.
  1386. */
  1387. sendWithPromise:
  1388. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1389. var callbackId = this.callbackIndex++;
  1390. var message = {
  1391. action: actionName,
  1392. data: data,
  1393. callbackId: callbackId
  1394. };
  1395. var capability = createPromiseCapability();
  1396. this.callbacksCapabilities[callbackId] = capability;
  1397. try {
  1398. this.postMessage(message, transfers);
  1399. } catch (e) {
  1400. capability.reject(e);
  1401. }
  1402. return capability.promise;
  1403. },
  1404. /**
  1405. * Sends raw message to the comObj.
  1406. * @private
  1407. * @param message {Object} Raw message.
  1408. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1409. */
  1410. postMessage: function (message, transfers) {
  1411. if (transfers && this.postMessageTransfers) {
  1412. this.comObj.postMessage(message, transfers);
  1413. } else {
  1414. this.comObj.postMessage(message);
  1415. }
  1416. }
  1417. };
  1418. function loadJpegStream(id, imageUrl, objs) {
  1419. var img = new Image();
  1420. img.onload = (function loadJpegStream_onloadClosure() {
  1421. objs.resolve(id, img);
  1422. });
  1423. img.onerror = (function loadJpegStream_onerrorClosure() {
  1424. objs.resolve(id, null);
  1425. warn('Error during JPEG image loading');
  1426. });
  1427. img.src = imageUrl;
  1428. }
  1429. /**
  1430. * The maximum allowed image size in total pixels e.g. width * height. Images
  1431. * above this value will not be drawn. Use -1 for no limit.
  1432. * @var {number}
  1433. */
  1434. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1435. -1 : PDFJS.maxImageSize);
  1436. /**
  1437. * The url of where the predefined Adobe CMaps are located. Include trailing
  1438. * slash.
  1439. * @var {string}
  1440. */
  1441. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1442. /**
  1443. * Specifies if CMaps are binary packed.
  1444. * @var {boolean}
  1445. */
  1446. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1447. /*
  1448. * By default fonts are converted to OpenType fonts and loaded via font face
  1449. * rules. If disabled, the font will be rendered using a built in font renderer
  1450. * that constructs the glyphs with primitive path commands.
  1451. * @var {boolean}
  1452. */
  1453. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1454. false : PDFJS.disableFontFace);
  1455. /**
  1456. * Path for image resources, mainly for annotation icons. Include trailing
  1457. * slash.
  1458. * @var {string}
  1459. */
  1460. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1461. '' : PDFJS.imageResourcesPath);
  1462. /**
  1463. * Disable the web worker and run all code on the main thread. This will happen
  1464. * automatically if the browser doesn't support workers or sending typed arrays
  1465. * to workers.
  1466. * @var {boolean}
  1467. */
  1468. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1469. false : PDFJS.disableWorker);
  1470. /**
  1471. * Path and filename of the worker file. Required when the worker is enabled in
  1472. * development mode. If unspecified in the production build, the worker will be
  1473. * loaded based on the location of the pdf.js file.
  1474. * @var {string}
  1475. */
  1476. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1477. /**
  1478. * Disable range request loading of PDF files. When enabled and if the server
  1479. * supports partial content requests then the PDF will be fetched in chunks.
  1480. * Enabled (false) by default.
  1481. * @var {boolean}
  1482. */
  1483. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1484. false : PDFJS.disableRange);
  1485. /**
  1486. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1487. * will automatically keep fetching more data even if it isn't needed to display
  1488. * the current page. This default behavior can be disabled.
  1489. * @var {boolean}
  1490. */
  1491. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1492. false : PDFJS.disableAutoFetch);
  1493. /**
  1494. * Enables special hooks for debugging PDF.js.
  1495. * @var {boolean}
  1496. */
  1497. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1498. /**
  1499. * Enables transfer usage in postMessage for ArrayBuffers.
  1500. * @var {boolean}
  1501. */
  1502. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1503. true : PDFJS.postMessageTransfers);
  1504. /**
  1505. * Disables URL.createObjectURL usage.
  1506. * @var {boolean}
  1507. */
  1508. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1509. false : PDFJS.disableCreateObjectURL);
  1510. /**
  1511. * Disables WebGL usage.
  1512. * @var {boolean}
  1513. */
  1514. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1515. true : PDFJS.disableWebGL);
  1516. /**
  1517. * Enables CSS only zooming.
  1518. * @var {boolean}
  1519. */
  1520. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1521. false : PDFJS.useOnlyCssZoom);
  1522. /**
  1523. * Controls the logging level.
  1524. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1525. * - errors
  1526. * - warnings [default]
  1527. * - infos
  1528. * @var {number}
  1529. */
  1530. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1531. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1532. /**
  1533. * The maximum supported canvas size in total pixels e.g. width * height.
  1534. * The default value is 4096 * 4096. Use -1 for no limit.
  1535. * @var {number}
  1536. */
  1537. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1538. 16777216 : PDFJS.maxCanvasPixels);
  1539. /**
  1540. * Document initialization / loading parameters object.
  1541. *
  1542. * @typedef {Object} DocumentInitParameters
  1543. * @property {string} url - The URL of the PDF.
  1544. * @property {TypedArray} data - A typed array with PDF data.
  1545. * @property {Object} httpHeaders - Basic authentication headers.
  1546. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1547. * Access-Control requests should be made using credentials such as cookies
  1548. * or authorization headers. The default is false.
  1549. * @property {string} password - For decrypting password-protected PDFs.
  1550. * @property {TypedArray} initialData - A typed array with the first portion or
  1551. * all of the pdf data. Used by the extension since some data is already
  1552. * loaded before the switch to range requests.
  1553. */
  1554. /**
  1555. * @typedef {Object} PDFDocumentStats
  1556. * @property {Array} streamTypes - Used stream types in the document (an item
  1557. * is set to true if specific stream ID was used in the document).
  1558. * @property {Array} fontTypes - Used font type in the document (an item is set
  1559. * to true if specific font ID was used in the document).
  1560. */
  1561. /**
  1562. * This is the main entry point for loading a PDF and interacting with it.
  1563. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1564. * is used, which means it must follow the same origin rules that any XHR does
  1565. * e.g. No cross domain requests without CORS.
  1566. *
  1567. * @param {string|TypedArray|DocumentInitParameters} source Can be a url to
  1568. * where a PDF is located, a typed array (Uint8Array) already populated with
  1569. * data or parameter object.
  1570. *
  1571. * @param {Object} pdfDataRangeTransport is optional. It is used if you want
  1572. * to manually serve range requests for data in the PDF. See viewer.js for
  1573. * an example of pdfDataRangeTransport's interface.
  1574. *
  1575. * @param {function} passwordCallback is optional. It is used to request a
  1576. * password if wrong or no password was provided. The callback receives two
  1577. * parameters: function that needs to be called with new password and reason
  1578. * (see {PasswordResponses}).
  1579. *
  1580. * @return {Promise} A promise that is resolved with {@link PDFDocumentProxy}
  1581. * object.
  1582. */
  1583. PDFJS.getDocument = function getDocument(source,
  1584. pdfDataRangeTransport,
  1585. passwordCallback,
  1586. progressCallback) {
  1587. var workerInitializedCapability, workerReadyCapability, transport;
  1588. if (typeof source === 'string') {
  1589. source = { url: source };
  1590. } else if (isArrayBuffer(source)) {
  1591. source = { data: source };
  1592. } else if (typeof source !== 'object') {
  1593. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1594. 'string or a parameter object');
  1595. }
  1596. if (!source.url && !source.data) {
  1597. error('Invalid parameter array, need either .data or .url');
  1598. }
  1599. // copy/use all keys as is except 'url' -- full path is required
  1600. var params = {};
  1601. for (var key in source) {
  1602. if (key === 'url' && typeof window !== 'undefined') {
  1603. params[key] = combineUrl(window.location.href, source[key]);
  1604. continue;
  1605. }
  1606. params[key] = source[key];
  1607. }
  1608. workerInitializedCapability = createPromiseCapability();
  1609. workerReadyCapability = createPromiseCapability();
  1610. transport = new WorkerTransport(workerInitializedCapability,
  1611. workerReadyCapability, pdfDataRangeTransport,
  1612. progressCallback);
  1613. workerInitializedCapability.promise.then(function transportInitialized() {
  1614. transport.passwordCallback = passwordCallback;
  1615. transport.fetchDocument(params);
  1616. });
  1617. return workerReadyCapability.promise;
  1618. };
  1619. /**
  1620. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1621. * properties that can be read synchronously.
  1622. * @class
  1623. */
  1624. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1625. function PDFDocumentProxy(pdfInfo, transport) {
  1626. this.pdfInfo = pdfInfo;
  1627. this.transport = transport;
  1628. }
  1629. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1630. /**
  1631. * @return {number} Total number of pages the PDF contains.
  1632. */
  1633. get numPages() {
  1634. return this.pdfInfo.numPages;
  1635. },
  1636. /**
  1637. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1638. * unique.
  1639. */
  1640. get fingerprint() {
  1641. return this.pdfInfo.fingerprint;
  1642. },
  1643. /**
  1644. * @param {number} pageNumber The page number to get. The first page is 1.
  1645. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1646. * object.
  1647. */
  1648. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1649. return this.transport.getPage(pageNumber);
  1650. },
  1651. /**
  1652. * @param {{num: number, gen: number}} ref The page reference. Must have
  1653. * the 'num' and 'gen' properties.
  1654. * @return {Promise} A promise that is resolved with the page index that is
  1655. * associated with the reference.
  1656. */
  1657. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1658. return this.transport.getPageIndex(ref);
  1659. },
  1660. /**
  1661. * @return {Promise} A promise that is resolved with a lookup table for
  1662. * mapping named destinations to reference numbers.
  1663. */
  1664. getDestinations: function PDFDocumentProxy_getDestinations() {
  1665. return this.transport.getDestinations();
  1666. },
  1667. /**
  1668. * @return {Promise} A promise that is resolved with a lookup table for
  1669. * mapping named attachments to their content.
  1670. */
  1671. getAttachments: function PDFDocumentProxy_getAttachments() {
  1672. return this.transport.getAttachments();
  1673. },
  1674. /**
  1675. * @return {Promise} A promise that is resolved with an array of all the
  1676. * JavaScript strings in the name tree.
  1677. */
  1678. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1679. return this.transport.getJavaScript();
  1680. },
  1681. /**
  1682. * @return {Promise} A promise that is resolved with an {Array} that is a
  1683. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1684. * [
  1685. * {
  1686. * title: string,
  1687. * bold: boolean,
  1688. * italic: boolean,
  1689. * color: rgb array,
  1690. * dest: dest obj,
  1691. * items: array of more items like this
  1692. * },
  1693. * ...
  1694. * ].
  1695. */
  1696. getOutline: function PDFDocumentProxy_getOutline() {
  1697. return this.transport.getOutline();
  1698. },
  1699. /**
  1700. * @return {Promise} A promise that is resolved with an {Object} that has
  1701. * info and metadata properties. Info is an {Object} filled with anything
  1702. * available in the information dictionary and similarly metadata is a
  1703. * {Metadata} object with information from the metadata section of the PDF.
  1704. */
  1705. getMetadata: function PDFDocumentProxy_getMetadata() {
  1706. return this.transport.getMetadata();
  1707. },
  1708. /**
  1709. * @return {Promise} A promise that is resolved with a TypedArray that has
  1710. * the raw data from the PDF.
  1711. */
  1712. getData: function PDFDocumentProxy_getData() {
  1713. return this.transport.getData();
  1714. },
  1715. /**
  1716. * @return {Promise} A promise that is resolved when the document's data
  1717. * is loaded. It is resolved with an {Object} that contains the length
  1718. * property that indicates size of the PDF data in bytes.
  1719. */
  1720. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1721. return this.transport.downloadInfoCapability.promise;
  1722. },
  1723. /**
  1724. * @returns {Promise} A promise this is resolved with current stats about
  1725. * document structures (see {@link PDFDocumentStats}).
  1726. */
  1727. getStats: function PDFDocumentProxy_getStats() {
  1728. return this.transport.getStats();
  1729. },
  1730. /**
  1731. * Cleans up resources allocated by the document, e.g. created @font-face.
  1732. */
  1733. cleanup: function PDFDocumentProxy_cleanup() {
  1734. this.transport.startCleanup();
  1735. },
  1736. /**
  1737. * Destroys current document instance and terminates worker.
  1738. */
  1739. destroy: function PDFDocumentProxy_destroy() {
  1740. this.transport.destroy();
  1741. }
  1742. };
  1743. return PDFDocumentProxy;
  1744. })();
  1745. /**
  1746. * Page text content.
  1747. *
  1748. * @typedef {Object} TextContent
  1749. * @property {array} items - array of {@link TextItem}
  1750. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1751. * name.
  1752. */
  1753. /**
  1754. * Page text content part.
  1755. *
  1756. * @typedef {Object} TextItem
  1757. * @property {string} str - text content.
  1758. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1759. * @property {array} transform - transformation matrix.
  1760. * @property {number} width - width in device space.
  1761. * @property {number} height - height in device space.
  1762. * @property {string} fontName - font name used by pdf.js for converted font.
  1763. */
  1764. /**
  1765. * Text style.
  1766. *
  1767. * @typedef {Object} TextStyle
  1768. * @property {number} ascent - font ascent.
  1769. * @property {number} descent - font descent.
  1770. * @property {boolean} vertical - text is in vertical mode.
  1771. * @property {string} fontFamily - possible font family
  1772. */
  1773. /**
  1774. * Page render parameters.
  1775. *
  1776. * @typedef {Object} RenderParameters
  1777. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1778. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1779. * calling of PDFPage.getViewport method.
  1780. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1781. * (default value is 'display').
  1782. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1783. * endLayout and appendImage functions.
  1784. * @property {function} continueCallback - (optional) A function that will be
  1785. * called each time the rendering is paused. To continue
  1786. * rendering call the function that is the first argument
  1787. * to the callback.
  1788. */
  1789. /**
  1790. * PDF page operator list.
  1791. *
  1792. * @typedef {Object} PDFOperatorList
  1793. * @property {Array} fnArray - Array containing the operator functions.
  1794. * @property {Array} argsArray - Array containing the arguments of the
  1795. * functions.
  1796. */
  1797. /**
  1798. * Proxy to a PDFPage in the worker thread.
  1799. * @class
  1800. */
  1801. var PDFPageProxy = (function PDFPageProxyClosure() {
  1802. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1803. this.pageIndex = pageIndex;
  1804. this.pageInfo = pageInfo;
  1805. this.transport = transport;
  1806. this.stats = new StatTimer();
  1807. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1808. this.commonObjs = transport.commonObjs;
  1809. this.objs = new PDFObjects();
  1810. this.cleanupAfterRender = false;
  1811. this.pendingDestroy = false;
  1812. this.intentStates = {};
  1813. }
  1814. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  1815. /**
  1816. * @return {number} Page number of the page. First page is 1.
  1817. */
  1818. get pageNumber() {
  1819. return this.pageIndex + 1;
  1820. },
  1821. /**
  1822. * @return {number} The number of degrees the page is rotated clockwise.
  1823. */
  1824. get rotate() {
  1825. return this.pageInfo.rotate;
  1826. },
  1827. /**
  1828. * @return {Object} The reference that points to this page. It has 'num' and
  1829. * 'gen' properties.
  1830. */
  1831. get ref() {
  1832. return this.pageInfo.ref;
  1833. },
  1834. /**
  1835. * @return {Array} An array of the visible portion of the PDF page in the
  1836. * user space units - [x1, y1, x2, y2].
  1837. */
  1838. get view() {
  1839. return this.pageInfo.view;
  1840. },
  1841. /**
  1842. * @param {number} scale The desired scale of the viewport.
  1843. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  1844. * defaults to the page rotation.
  1845. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  1846. * along with transforms required for rendering.
  1847. */
  1848. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  1849. if (arguments.length < 2) {
  1850. rotate = this.rotate;
  1851. }
  1852. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  1853. },
  1854. /**
  1855. * @return {Promise} A promise that is resolved with an {Array} of the
  1856. * annotation objects.
  1857. */
  1858. getAnnotations: function PDFPageProxy_getAnnotations() {
  1859. if (this.annotationsPromise) {
  1860. return this.annotationsPromise;
  1861. }
  1862. var promise = this.transport.getAnnotations(this.pageIndex);
  1863. this.annotationsPromise = promise;
  1864. return promise;
  1865. },
  1866. /**
  1867. * Begins the process of rendering a page to the desired context.
  1868. * @param {RenderParameters} params Page render parameters.
  1869. * @return {RenderTask} An object that contains the promise, which
  1870. * is resolved when the page finishes rendering.
  1871. */
  1872. render: function PDFPageProxy_render(params) {
  1873. var stats = this.stats;
  1874. stats.time('Overall');
  1875. // If there was a pending destroy cancel it so no cleanup happens during
  1876. // this call to render.
  1877. this.pendingDestroy = false;
  1878. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  1879. if (!this.intentStates[renderingIntent]) {
  1880. this.intentStates[renderingIntent] = {};
  1881. }
  1882. var intentState = this.intentStates[renderingIntent];
  1883. // If there's no displayReadyCapability yet, then the operatorList
  1884. // was never requested before. Make the request and create the promise.
  1885. if (!intentState.displayReadyCapability) {
  1886. intentState.receivingOperatorList = true;
  1887. intentState.displayReadyCapability = createPromiseCapability();
  1888. intentState.operatorList = {
  1889. fnArray: [],
  1890. argsArray: [],
  1891. lastChunk: false
  1892. };
  1893. this.stats.time('Page Request');
  1894. this.transport.messageHandler.send('RenderPageRequest', {
  1895. pageIndex: this.pageNumber - 1,
  1896. intent: renderingIntent
  1897. });
  1898. }
  1899. var internalRenderTask = new InternalRenderTask(complete, params,
  1900. this.objs,
  1901. this.commonObjs,
  1902. intentState.operatorList,
  1903. this.pageNumber);
  1904. if (!intentState.renderTasks) {
  1905. intentState.renderTasks = [];
  1906. }
  1907. intentState.renderTasks.push(internalRenderTask);
  1908. var renderTask = new RenderTask(internalRenderTask);
  1909. var self = this;
  1910. intentState.displayReadyCapability.promise.then(
  1911. function pageDisplayReadyPromise(transparency) {
  1912. if (self.pendingDestroy) {
  1913. complete();
  1914. return;
  1915. }
  1916. stats.time('Rendering');
  1917. internalRenderTask.initalizeGraphics(transparency);
  1918. internalRenderTask.operatorListChanged();
  1919. },
  1920. function pageDisplayReadPromiseError(reason) {
  1921. complete(reason);
  1922. }
  1923. );
  1924. function complete(error) {
  1925. var i = intentState.renderTasks.indexOf(internalRenderTask);
  1926. if (i >= 0) {
  1927. intentState.renderTasks.splice(i, 1);
  1928. }
  1929. if (self.cleanupAfterRender) {
  1930. self.pendingDestroy = true;
  1931. }
  1932. self._tryDestroy();
  1933. if (error) {
  1934. internalRenderTask.capability.reject(error);
  1935. } else {
  1936. internalRenderTask.capability.resolve();
  1937. }
  1938. stats.timeEnd('Rendering');
  1939. stats.timeEnd('Overall');
  1940. }
  1941. return renderTask;
  1942. },
  1943. /**
  1944. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  1945. * object that represents page's operator list.
  1946. */
  1947. getOperatorList: function PDFPageProxy_getOperatorList() {
  1948. function operatorListChanged() {
  1949. if (intentState.operatorList.lastChunk) {
  1950. intentState.opListReadCapability.resolve(intentState.operatorList);
  1951. }
  1952. }
  1953. var renderingIntent = 'oplist';
  1954. if (!this.intentStates[renderingIntent]) {
  1955. this.intentStates[renderingIntent] = {};
  1956. }
  1957. var intentState = this.intentStates[renderingIntent];
  1958. if (!intentState.opListReadCapability) {
  1959. var opListTask = {};
  1960. opListTask.operatorListChanged = operatorListChanged;
  1961. intentState.receivingOperatorList = true;
  1962. intentState.opListReadCapability = createPromiseCapability();
  1963. intentState.renderTasks = [];
  1964. intentState.renderTasks.push(opListTask);
  1965. intentState.operatorList = {
  1966. fnArray: [],
  1967. argsArray: [],
  1968. lastChunk: false
  1969. };
  1970. this.transport.messageHandler.send('RenderPageRequest', {
  1971. pageIndex: this.pageIndex,
  1972. intent: renderingIntent
  1973. });
  1974. }
  1975. return intentState.opListReadCapability.promise;
  1976. },
  1977. /**
  1978. * @return {Promise} That is resolved a {@link TextContent}
  1979. * object that represent the page text content.
  1980. */
  1981. getTextContent: function PDFPageProxy_getTextContent() {
  1982. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  1983. pageIndex: this.pageNumber - 1
  1984. });
  1985. },
  1986. /**
  1987. * Destroys resources allocated by the page.
  1988. */
  1989. destroy: function PDFPageProxy_destroy() {
  1990. this.pendingDestroy = true;
  1991. this._tryDestroy();
  1992. },
  1993. /**
  1994. * For internal use only. Attempts to clean up if rendering is in a state
  1995. * where that's possible.
  1996. * @ignore
  1997. */
  1998. _tryDestroy: function PDFPageProxy__destroy() {
  1999. if (!this.pendingDestroy ||
  2000. Object.keys(this.intentStates).some(function(intent) {
  2001. var intentState = this.intentStates[intent];
  2002. return (intentState.renderTasks.length !== 0 ||
  2003. intentState.receivingOperatorList);
  2004. }, this)) {
  2005. return;
  2006. }
  2007. Object.keys(this.intentStates).forEach(function(intent) {
  2008. delete this.intentStates[intent];
  2009. }, this);
  2010. this.objs.clear();
  2011. this.annotationsPromise = null;
  2012. this.pendingDestroy = false;
  2013. },
  2014. /**
  2015. * For internal use only.
  2016. * @ignore
  2017. */
  2018. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2019. intent) {
  2020. var intentState = this.intentStates[intent];
  2021. // TODO Refactor RenderPageRequest to separate rendering
  2022. // and operator list logic
  2023. if (intentState.displayReadyCapability) {
  2024. intentState.displayReadyCapability.resolve(transparency);
  2025. }
  2026. },
  2027. /**
  2028. * For internal use only.
  2029. * @ignore
  2030. */
  2031. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2032. intent) {
  2033. var intentState = this.intentStates[intent];
  2034. var i, ii;
  2035. // Add the new chunk to the current operator list.
  2036. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2037. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2038. intentState.operatorList.argsArray.push(
  2039. operatorListChunk.argsArray[i]);
  2040. }
  2041. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2042. // Notify all the rendering tasks there are more operators to be consumed.
  2043. for (i = 0; i < intentState.renderTasks.length; i++) {
  2044. intentState.renderTasks[i].operatorListChanged();
  2045. }
  2046. if (operatorListChunk.lastChunk) {
  2047. intentState.receivingOperatorList = false;
  2048. this._tryDestroy();
  2049. }
  2050. }
  2051. };
  2052. return PDFPageProxy;
  2053. })();
  2054. /**
  2055. * For internal use only.
  2056. * @ignore
  2057. */
  2058. var WorkerTransport = (function WorkerTransportClosure() {
  2059. function WorkerTransport(workerInitializedCapability, workerReadyCapability,
  2060. pdfDataRangeTransport, progressCallback) {
  2061. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2062. this.workerInitializedCapability = workerInitializedCapability;
  2063. this.workerReadyCapability = workerReadyCapability;
  2064. this.progressCallback = progressCallback;
  2065. this.commonObjs = new PDFObjects();
  2066. this.pageCache = [];
  2067. this.pagePromises = [];
  2068. this.downloadInfoCapability = createPromiseCapability();
  2069. this.passwordCallback = null;
  2070. // If worker support isn't disabled explicit and the browser has worker
  2071. // support, create a new web worker and test if it/the browser fullfills
  2072. // all requirements to run parts of pdf.js in a web worker.
  2073. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2074. // as it arrives on the worker. Chrome added this with version 15.
  2075. // Either workers are disabled, not supported or have thrown an exception.
  2076. // Thus, we fallback to a faked worker.
  2077. this.setupFakeWorker();
  2078. }
  2079. WorkerTransport.prototype = {
  2080. destroy: function WorkerTransport_destroy() {
  2081. this.pageCache = [];
  2082. this.pagePromises = [];
  2083. var self = this;
  2084. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2085. FontLoader.clear();
  2086. if (self.worker) {
  2087. self.worker.terminate();
  2088. }
  2089. });
  2090. },
  2091. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2092. globalScope.PDFJS.disableWorker = true;
  2093. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2094. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2095. // In the developer build load worker_loader which in turn loads all the
  2096. // other files and resolves the promise. In production only the
  2097. // pdf.worker.js file is needed.
  2098. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2099. }
  2100. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2101. warn('Setting up fake worker.');
  2102. // If we don't use a worker, just post/sendMessage to the main thread.
  2103. var fakeWorker = {
  2104. postMessage: function WorkerTransport_postMessage(obj) {
  2105. fakeWorker.onmessage({data: obj});
  2106. },
  2107. terminate: function WorkerTransport_terminate() {}
  2108. };
  2109. var messageHandler = new MessageHandler('main', fakeWorker);
  2110. this.setupMessageHandler(messageHandler);
  2111. // If the main thread is our worker, setup the handling for the messages
  2112. // the main thread sends to it self.
  2113. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2114. this.workerInitializedCapability.resolve();
  2115. }.bind(this));
  2116. },
  2117. setupMessageHandler:
  2118. function WorkerTransport_setupMessageHandler(messageHandler) {
  2119. this.messageHandler = messageHandler;
  2120. function updatePassword(password) {
  2121. messageHandler.send('UpdatePassword', password);
  2122. }
  2123. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2124. if (pdfDataRangeTransport) {
  2125. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2126. messageHandler.send('OnDataRange', {
  2127. begin: begin,
  2128. chunk: chunk
  2129. });
  2130. });
  2131. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2132. messageHandler.send('OnDataProgress', {
  2133. loaded: loaded
  2134. });
  2135. });
  2136. messageHandler.on('RequestDataRange',
  2137. function transportDataRange(data) {
  2138. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2139. }, this);
  2140. }
  2141. messageHandler.on('GetDoc', function transportDoc(data) {
  2142. var pdfInfo = data.pdfInfo;
  2143. this.numPages = data.pdfInfo.numPages;
  2144. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2145. this.pdfDocument = pdfDocument;
  2146. this.workerReadyCapability.resolve(pdfDocument);
  2147. }, this);
  2148. messageHandler.on('NeedPassword', function transportPassword(data) {
  2149. if (this.passwordCallback) {
  2150. return this.passwordCallback(updatePassword,
  2151. PasswordResponses.NEED_PASSWORD);
  2152. }
  2153. this.workerReadyCapability.reject(data.exception.message,
  2154. data.exception);
  2155. }, this);
  2156. messageHandler.on('IncorrectPassword', function transportBadPass(data) {
  2157. if (this.passwordCallback) {
  2158. return this.passwordCallback(updatePassword,
  2159. PasswordResponses.INCORRECT_PASSWORD);
  2160. }
  2161. this.workerReadyCapability.reject(data.exception.message,
  2162. data.exception);
  2163. }, this);
  2164. messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
  2165. this.workerReadyCapability.reject(data.exception.name, data.exception);
  2166. }, this);
  2167. messageHandler.on('MissingPDF', function transportMissingPDF(data) {
  2168. this.workerReadyCapability.reject(data.exception.message,
  2169. data.exception);
  2170. }, this);
  2171. messageHandler.on('UnknownError', function transportUnknownError(data) {
  2172. this.workerReadyCapability.reject(data.exception.message,
  2173. data.exception);
  2174. }, this);
  2175. messageHandler.on('DataLoaded', function transportPage(data) {
  2176. this.downloadInfoCapability.resolve(data);
  2177. }, this);
  2178. messageHandler.on('StartRenderPage', function transportRender(data) {
  2179. var page = this.pageCache[data.pageIndex];
  2180. page.stats.timeEnd('Page Request');
  2181. page._startRenderPage(data.transparency, data.intent);
  2182. }, this);
  2183. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2184. var page = this.pageCache[data.pageIndex];
  2185. page._renderPageChunk(data.operatorList, data.intent);
  2186. }, this);
  2187. messageHandler.on('commonobj', function transportObj(data) {
  2188. var id = data[0];
  2189. var type = data[1];
  2190. if (this.commonObjs.hasData(id)) {
  2191. return;
  2192. }
  2193. switch (type) {
  2194. case 'Font':
  2195. var exportedData = data[2];
  2196. var font;
  2197. if ('error' in exportedData) {
  2198. var error = exportedData.error;
  2199. warn('Error during font loading: ' + error);
  2200. this.commonObjs.resolve(id, error);
  2201. break;
  2202. } else {
  2203. font = new FontFace(exportedData);
  2204. }
  2205. FontLoader.bind(
  2206. [font],
  2207. function fontReady(fontObjs) {
  2208. this.commonObjs.resolve(id, font);
  2209. }.bind(this)
  2210. );
  2211. break;
  2212. case 'FontPath':
  2213. this.commonObjs.resolve(id, data[2]);
  2214. break;
  2215. default:
  2216. error('Got unknown common object type ' + type);
  2217. }
  2218. }, this);
  2219. messageHandler.on('obj', function transportObj(data) {
  2220. var id = data[0];
  2221. var pageIndex = data[1];
  2222. var type = data[2];
  2223. var pageProxy = this.pageCache[pageIndex];
  2224. var imageData;
  2225. if (pageProxy.objs.hasData(id)) {
  2226. return;
  2227. }
  2228. switch (type) {
  2229. case 'JpegStream':
  2230. imageData = data[3];
  2231. loadJpegStream(id, imageData, pageProxy.objs);
  2232. break;
  2233. case 'Image':
  2234. imageData = data[3];
  2235. pageProxy.objs.resolve(id, imageData);
  2236. // heuristics that will allow not to store large data
  2237. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2238. if (imageData && 'data' in imageData &&
  2239. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2240. pageProxy.cleanupAfterRender = true;
  2241. }
  2242. break;
  2243. default:
  2244. error('Got unknown object type ' + type);
  2245. }
  2246. }, this);
  2247. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2248. if (this.progressCallback) {
  2249. this.progressCallback({
  2250. loaded: data.loaded,
  2251. total: data.total
  2252. });
  2253. }
  2254. }, this);
  2255. messageHandler.on('DocError', function transportDocError(data) {
  2256. this.workerReadyCapability.reject(data);
  2257. }, this);
  2258. messageHandler.on('PageError', function transportError(data) {
  2259. var page = this.pageCache[data.pageNum - 1];
  2260. var intentState = page.intentStates[data.intent];
  2261. if (intentState.displayReadyCapability) {
  2262. intentState.displayReadyCapability.reject(data.error);
  2263. } else {
  2264. error(data.error);
  2265. }
  2266. }, this);
  2267. messageHandler.on('JpegDecode', function(data) {
  2268. var imageUrl = data[0];
  2269. var components = data[1];
  2270. if (components !== 3 && components !== 1) {
  2271. return Promise.reject(
  2272. new Error('Only 3 components or 1 component can be returned'));
  2273. }
  2274. return new Promise(function (resolve, reject) {
  2275. var img = new Image();
  2276. img.onload = function () {
  2277. var width = img.width;
  2278. var height = img.height;
  2279. var size = width * height;
  2280. var rgbaLength = size * 4;
  2281. var buf = new Uint8Array(size * components);
  2282. var tmpCanvas = createScratchCanvas(width, height);
  2283. var tmpCtx = tmpCanvas.getContext('2d');
  2284. tmpCtx.drawImage(img, 0, 0);
  2285. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2286. var i, j;
  2287. if (components === 3) {
  2288. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2289. buf[j] = data[i];
  2290. buf[j + 1] = data[i + 1];
  2291. buf[j + 2] = data[i + 2];
  2292. }
  2293. } else if (components === 1) {
  2294. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2295. buf[j] = data[i];
  2296. }
  2297. }
  2298. resolve({ data: buf, width: width, height: height});
  2299. };
  2300. img.onerror = function () {
  2301. reject(new Error('JpegDecode failed to load image'));
  2302. };
  2303. img.src = imageUrl;
  2304. });
  2305. });
  2306. },
  2307. fetchDocument: function WorkerTransport_fetchDocument(source) {
  2308. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2309. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2310. this.messageHandler.send('GetDocRequest', {
  2311. source: source,
  2312. disableRange: PDFJS.disableRange,
  2313. maxImageSize: PDFJS.maxImageSize,
  2314. cMapUrl: PDFJS.cMapUrl,
  2315. cMapPacked: PDFJS.cMapPacked,
  2316. disableFontFace: PDFJS.disableFontFace,
  2317. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2318. verbosity: PDFJS.verbosity
  2319. });
  2320. },
  2321. getData: function WorkerTransport_getData() {
  2322. return this.messageHandler.sendWithPromise('GetData', null);
  2323. },
  2324. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2325. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2326. (pageNumber|0) !== pageNumber) {
  2327. return Promise.reject(new Error('Invalid page request'));
  2328. }
  2329. var pageIndex = pageNumber - 1;
  2330. if (pageIndex in this.pagePromises) {
  2331. return this.pagePromises[pageIndex];
  2332. }
  2333. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2334. pageIndex: pageIndex
  2335. }).then(function (pageInfo) {
  2336. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2337. this.pageCache[pageIndex] = page;
  2338. return page;
  2339. }.bind(this));
  2340. this.pagePromises[pageIndex] = promise;
  2341. return promise;
  2342. },
  2343. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2344. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2345. },
  2346. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2347. return this.messageHandler.sendWithPromise('GetAnnotations',
  2348. { pageIndex: pageIndex });
  2349. },
  2350. getDestinations: function WorkerTransport_getDestinations() {
  2351. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2352. },
  2353. getAttachments: function WorkerTransport_getAttachments() {
  2354. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2355. },
  2356. getJavaScript: function WorkerTransport_getJavaScript() {
  2357. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2358. },
  2359. getOutline: function WorkerTransport_getOutline() {
  2360. return this.messageHandler.sendWithPromise('GetOutline', null);
  2361. },
  2362. getMetadata: function WorkerTransport_getMetadata() {
  2363. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2364. then(function transportMetadata(results) {
  2365. return {
  2366. info: results[0],
  2367. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2368. };
  2369. });
  2370. },
  2371. getStats: function WorkerTransport_getStats() {
  2372. return this.messageHandler.sendWithPromise('GetStats', null);
  2373. },
  2374. startCleanup: function WorkerTransport_startCleanup() {
  2375. this.messageHandler.sendWithPromise('Cleanup', null).
  2376. then(function endCleanup() {
  2377. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2378. var page = this.pageCache[i];
  2379. if (page) {
  2380. page.destroy();
  2381. }
  2382. }
  2383. this.commonObjs.clear();
  2384. FontLoader.clear();
  2385. }.bind(this));
  2386. }
  2387. };
  2388. return WorkerTransport;
  2389. })();
  2390. /**
  2391. * A PDF document and page is built of many objects. E.g. there are objects
  2392. * for fonts, images, rendering code and such. These objects might get processed
  2393. * inside of a worker. The `PDFObjects` implements some basic functions to
  2394. * manage these objects.
  2395. * @ignore
  2396. */
  2397. var PDFObjects = (function PDFObjectsClosure() {
  2398. function PDFObjects() {
  2399. this.objs = {};
  2400. }
  2401. PDFObjects.prototype = {
  2402. /**
  2403. * Internal function.
  2404. * Ensures there is an object defined for `objId`.
  2405. */
  2406. ensureObj: function PDFObjects_ensureObj(objId) {
  2407. if (this.objs[objId]) {
  2408. return this.objs[objId];
  2409. }
  2410. var obj = {
  2411. capability: createPromiseCapability(),
  2412. data: null,
  2413. resolved: false
  2414. };
  2415. this.objs[objId] = obj;
  2416. return obj;
  2417. },
  2418. /**
  2419. * If called *without* callback, this returns the data of `objId` but the
  2420. * object needs to be resolved. If it isn't, this function throws.
  2421. *
  2422. * If called *with* a callback, the callback is called with the data of the
  2423. * object once the object is resolved. That means, if you call this
  2424. * function and the object is already resolved, the callback gets called
  2425. * right away.
  2426. */
  2427. get: function PDFObjects_get(objId, callback) {
  2428. // If there is a callback, then the get can be async and the object is
  2429. // not required to be resolved right now
  2430. if (callback) {
  2431. this.ensureObj(objId).capability.promise.then(callback);
  2432. return null;
  2433. }
  2434. // If there isn't a callback, the user expects to get the resolved data
  2435. // directly.
  2436. var obj = this.objs[objId];
  2437. // If there isn't an object yet or the object isn't resolved, then the
  2438. // data isn't ready yet!
  2439. if (!obj || !obj.resolved) {
  2440. error('Requesting object that isn\'t resolved yet ' + objId);
  2441. }
  2442. return obj.data;
  2443. },
  2444. /**
  2445. * Resolves the object `objId` with optional `data`.
  2446. */
  2447. resolve: function PDFObjects_resolve(objId, data) {
  2448. var obj = this.ensureObj(objId);
  2449. obj.resolved = true;
  2450. obj.data = data;
  2451. obj.capability.resolve(data);
  2452. },
  2453. isResolved: function PDFObjects_isResolved(objId) {
  2454. var objs = this.objs;
  2455. if (!objs[objId]) {
  2456. return false;
  2457. } else {
  2458. return objs[objId].resolved;
  2459. }
  2460. },
  2461. hasData: function PDFObjects_hasData(objId) {
  2462. return this.isResolved(objId);
  2463. },
  2464. /**
  2465. * Returns the data of `objId` if object exists, null otherwise.
  2466. */
  2467. getData: function PDFObjects_getData(objId) {
  2468. var objs = this.objs;
  2469. if (!objs[objId] || !objs[objId].resolved) {
  2470. return null;
  2471. } else {
  2472. return objs[objId].data;
  2473. }
  2474. },
  2475. clear: function PDFObjects_clear() {
  2476. this.objs = {};
  2477. }
  2478. };
  2479. return PDFObjects;
  2480. })();
  2481. /**
  2482. * Allows controlling of the rendering tasks.
  2483. * @class
  2484. */
  2485. var RenderTask = (function RenderTaskClosure() {
  2486. function RenderTask(internalRenderTask) {
  2487. this.internalRenderTask = internalRenderTask;
  2488. /**
  2489. * Promise for rendering task completion.
  2490. * @type {Promise}
  2491. */
  2492. this.promise = this.internalRenderTask.capability.promise;
  2493. }
  2494. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2495. /**
  2496. * Cancels the rendering task. If the task is currently rendering it will
  2497. * not be cancelled until graphics pauses with a timeout. The promise that
  2498. * this object extends will resolved when cancelled.
  2499. */
  2500. cancel: function RenderTask_cancel() {
  2501. this.internalRenderTask.cancel();
  2502. },
  2503. /**
  2504. * Registers callback to indicate the rendering task completion.
  2505. *
  2506. * @param {function} onFulfilled The callback for the rendering completion.
  2507. * @param {function} onRejected The callback for the rendering failure.
  2508. * @return {Promise} A promise that is resolved after the onFulfilled or
  2509. * onRejected callback.
  2510. */
  2511. then: function RenderTask_then(onFulfilled, onRejected) {
  2512. return this.promise.then(onFulfilled, onRejected);
  2513. }
  2514. };
  2515. return RenderTask;
  2516. })();
  2517. /**
  2518. * For internal use only.
  2519. * @ignore
  2520. */
  2521. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2522. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2523. pageNumber) {
  2524. this.callback = callback;
  2525. this.params = params;
  2526. this.objs = objs;
  2527. this.commonObjs = commonObjs;
  2528. this.operatorListIdx = null;
  2529. this.operatorList = operatorList;
  2530. this.pageNumber = pageNumber;
  2531. this.running = false;
  2532. this.graphicsReadyCallback = null;
  2533. this.graphicsReady = false;
  2534. this.cancelled = false;
  2535. this.capability = createPromiseCapability();
  2536. // caching this-bound methods
  2537. this._continueBound = this._continue.bind(this);
  2538. this._scheduleNextBound = this._scheduleNext.bind(this);
  2539. this._nextBound = this._next.bind(this);
  2540. }
  2541. InternalRenderTask.prototype = {
  2542. initalizeGraphics:
  2543. function InternalRenderTask_initalizeGraphics(transparency) {
  2544. if (this.cancelled) {
  2545. return;
  2546. }
  2547. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2548. globalScope.StepperManager.enabled) {
  2549. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2550. this.stepper.init(this.operatorList);
  2551. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2552. }
  2553. var params = this.params;
  2554. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2555. this.objs, params.imageLayer);
  2556. this.gfx.beginDrawing(params.viewport, transparency);
  2557. this.operatorListIdx = 0;
  2558. this.graphicsReady = true;
  2559. if (this.graphicsReadyCallback) {
  2560. this.graphicsReadyCallback();
  2561. }
  2562. },
  2563. cancel: function InternalRenderTask_cancel() {
  2564. this.running = false;
  2565. this.cancelled = true;
  2566. this.callback('cancelled');
  2567. },
  2568. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2569. if (!this.graphicsReady) {
  2570. if (!this.graphicsReadyCallback) {
  2571. this.graphicsReadyCallback = this._continueBound;
  2572. }
  2573. return;
  2574. }
  2575. if (this.stepper) {
  2576. this.stepper.updateOperatorList(this.operatorList);
  2577. }
  2578. if (this.running) {
  2579. return;
  2580. }
  2581. this._continue();
  2582. },
  2583. _continue: function InternalRenderTask__continue() {
  2584. this.running = true;
  2585. if (this.cancelled) {
  2586. return;
  2587. }
  2588. if (this.params.continueCallback) {
  2589. this.params.continueCallback(this._scheduleNextBound);
  2590. } else {
  2591. this._scheduleNext();
  2592. }
  2593. },
  2594. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2595. window.requestAnimationFrame(this._nextBound);
  2596. },
  2597. _next: function InternalRenderTask__next() {
  2598. if (this.cancelled) {
  2599. return;
  2600. }
  2601. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2602. this.operatorListIdx,
  2603. this._continueBound,
  2604. this.stepper);
  2605. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2606. this.running = false;
  2607. if (this.operatorList.lastChunk) {
  2608. this.gfx.endDrawing();
  2609. this.callback();
  2610. }
  2611. }
  2612. }
  2613. };
  2614. return InternalRenderTask;
  2615. })();
  2616. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2617. function fixMetadata(meta) {
  2618. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2619. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2620. function(code, d1, d2, d3) {
  2621. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2622. });
  2623. var chars = '';
  2624. for (var i = 0; i < bytes.length; i += 2) {
  2625. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2626. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2627. code !== 38 && false ? String.fromCharCode(code) :
  2628. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2629. }
  2630. return '>' + chars;
  2631. });
  2632. }
  2633. function Metadata(meta) {
  2634. if (typeof meta === 'string') {
  2635. // Ghostscript produces invalid metadata
  2636. meta = fixMetadata(meta);
  2637. var parser = new DOMParser();
  2638. meta = parser.parseFromString(meta, 'application/xml');
  2639. } else if (!(meta instanceof Document)) {
  2640. error('Metadata: Invalid metadata object');
  2641. }
  2642. this.metaDocument = meta;
  2643. this.metadata = {};
  2644. this.parse();
  2645. }
  2646. Metadata.prototype = {
  2647. parse: function Metadata_parse() {
  2648. var doc = this.metaDocument;
  2649. var rdf = doc.documentElement;
  2650. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2651. rdf = rdf.firstChild;
  2652. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2653. rdf = rdf.nextSibling;
  2654. }
  2655. }
  2656. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2657. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2658. return;
  2659. }
  2660. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2661. for (i = 0, length = children.length; i < length; i++) {
  2662. desc = children[i];
  2663. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2664. continue;
  2665. }
  2666. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2667. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2668. entry = desc.childNodes[ii];
  2669. name = entry.nodeName.toLowerCase();
  2670. this.metadata[name] = entry.textContent.trim();
  2671. }
  2672. }
  2673. }
  2674. },
  2675. get: function Metadata_get(name) {
  2676. return this.metadata[name] || null;
  2677. },
  2678. has: function Metadata_has(name) {
  2679. return typeof this.metadata[name] !== 'undefined';
  2680. }
  2681. };
  2682. return Metadata;
  2683. })();
  2684. // <canvas> contexts store most of the state we need natively.
  2685. // However, PDF needs a bit more state, which we store here.
  2686. // Minimal font size that would be used during canvas fillText operations.
  2687. var MIN_FONT_SIZE = 16;
  2688. var MAX_GROUP_SIZE = 4096;
  2689. var COMPILE_TYPE3_GLYPHS = true;
  2690. function createScratchCanvas(width, height) {
  2691. var canvas = document.createElement('canvas');
  2692. canvas.width = width;
  2693. canvas.height = height;
  2694. return canvas;
  2695. }
  2696. function addContextCurrentTransform(ctx) {
  2697. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2698. if (!ctx.mozCurrentTransform) {
  2699. // Store the original context
  2700. ctx._scaleX = ctx._scaleX || 1.0;
  2701. ctx._scaleY = ctx._scaleY || 1.0;
  2702. ctx._originalSave = ctx.save;
  2703. ctx._originalRestore = ctx.restore;
  2704. ctx._originalRotate = ctx.rotate;
  2705. ctx._originalScale = ctx.scale;
  2706. ctx._originalTranslate = ctx.translate;
  2707. ctx._originalTransform = ctx.transform;
  2708. ctx._originalSetTransform = ctx.setTransform;
  2709. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2710. ctx._transformStack = [];
  2711. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2712. get: function getCurrentTransform() {
  2713. return this._transformMatrix;
  2714. }
  2715. });
  2716. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2717. get: function getCurrentTransformInverse() {
  2718. // Calculation done using WolframAlpha:
  2719. // http://www.wolframalpha.com/input/?
  2720. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2721. var m = this._transformMatrix;
  2722. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2723. var ad_bc = a * d - b * c;
  2724. var bc_ad = b * c - a * d;
  2725. return [
  2726. d / ad_bc,
  2727. b / bc_ad,
  2728. c / bc_ad,
  2729. a / ad_bc,
  2730. (d * e - c * f) / bc_ad,
  2731. (b * e - a * f) / ad_bc
  2732. ];
  2733. }
  2734. });
  2735. ctx.save = function ctxSave() {
  2736. var old = this._transformMatrix;
  2737. this._transformStack.push(old);
  2738. this._transformMatrix = old.slice(0, 6);
  2739. this._originalSave();
  2740. };
  2741. ctx.restore = function ctxRestore() {
  2742. var prev = this._transformStack.pop();
  2743. if (prev) {
  2744. this._transformMatrix = prev;
  2745. this._originalRestore();
  2746. }
  2747. };
  2748. ctx.translate = function ctxTranslate(x, y) {
  2749. var m = this._transformMatrix;
  2750. m[4] = m[0] * x + m[2] * y + m[4];
  2751. m[5] = m[1] * x + m[3] * y + m[5];
  2752. this._originalTranslate(x, y);
  2753. };
  2754. ctx.scale = function ctxScale(x, y) {
  2755. var m = this._transformMatrix;
  2756. m[0] = m[0] * x;
  2757. m[1] = m[1] * x;
  2758. m[2] = m[2] * y;
  2759. m[3] = m[3] * y;
  2760. this._originalScale(x, y);
  2761. };
  2762. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2763. var m = this._transformMatrix;
  2764. this._transformMatrix = [
  2765. m[0] * a + m[2] * b,
  2766. m[1] * a + m[3] * b,
  2767. m[0] * c + m[2] * d,
  2768. m[1] * c + m[3] * d,
  2769. m[0] * e + m[2] * f + m[4],
  2770. m[1] * e + m[3] * f + m[5]
  2771. ];
  2772. ctx._originalTransform(a, b, c, d, e, f);
  2773. };
  2774. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  2775. this._transformMatrix = [a, b, c, d, e, f];
  2776. ctx._originalSetTransform(a, b, c, d, e, f);
  2777. };
  2778. ctx.rotate = function ctxRotate(angle) {
  2779. var cosValue = Math.cos(angle);
  2780. var sinValue = Math.sin(angle);
  2781. var m = this._transformMatrix;
  2782. this._transformMatrix = [
  2783. m[0] * cosValue + m[2] * sinValue,
  2784. m[1] * cosValue + m[3] * sinValue,
  2785. m[0] * (-sinValue) + m[2] * cosValue,
  2786. m[1] * (-sinValue) + m[3] * cosValue,
  2787. m[4],
  2788. m[5]
  2789. ];
  2790. this._originalRotate(angle);
  2791. };
  2792. }
  2793. }
  2794. var CachedCanvases = (function CachedCanvasesClosure() {
  2795. var cache = {};
  2796. return {
  2797. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  2798. trackTransform) {
  2799. var canvasEntry;
  2800. if (id in cache) {
  2801. canvasEntry = cache[id];
  2802. canvasEntry.canvas.width = width;
  2803. canvasEntry.canvas.height = height;
  2804. // reset canvas transform for emulated mozCurrentTransform, if needed
  2805. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  2806. } else {
  2807. var canvas = createScratchCanvas(width, height);
  2808. var ctx = canvas.getContext('2d');
  2809. if (trackTransform) {
  2810. addContextCurrentTransform(ctx);
  2811. }
  2812. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  2813. }
  2814. return canvasEntry;
  2815. },
  2816. clear: function () {
  2817. for (var id in cache) {
  2818. var canvasEntry = cache[id];
  2819. // Zeroing the width and height causes Firefox to release graphics
  2820. // resources immediately, which can greatly reduce memory consumption.
  2821. canvasEntry.canvas.width = 0;
  2822. canvasEntry.canvas.height = 0;
  2823. delete cache[id];
  2824. }
  2825. }
  2826. };
  2827. })();
  2828. function compileType3Glyph(imgData) {
  2829. var POINT_TO_PROCESS_LIMIT = 1000;
  2830. var width = imgData.width, height = imgData.height;
  2831. var i, j, j0, width1 = width + 1;
  2832. var points = new Uint8Array(width1 * (height + 1));
  2833. var POINT_TYPES =
  2834. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  2835. // decodes bit-packed mask data
  2836. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  2837. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  2838. for (i = 0, ii = data0.length; i < ii; i++) {
  2839. var mask = 128, elem = data0[i];
  2840. while (mask > 0) {
  2841. data[pos++] = (elem & mask) ? 0 : 255;
  2842. mask >>= 1;
  2843. }
  2844. }
  2845. // finding iteresting points: every point is located between mask pixels,
  2846. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  2847. // will have flags assigned based on neighboring mask pixels:
  2848. // 4 | 8
  2849. // --P--
  2850. // 2 | 1
  2851. // We are interested only in points with the flags:
  2852. // - outside corners: 1, 2, 4, 8;
  2853. // - inside corners: 7, 11, 13, 14;
  2854. // - and, intersections: 5, 10.
  2855. var count = 0;
  2856. pos = 0;
  2857. if (data[pos] !== 0) {
  2858. points[0] = 1;
  2859. ++count;
  2860. }
  2861. for (j = 1; j < width; j++) {
  2862. if (data[pos] !== data[pos + 1]) {
  2863. points[j] = data[pos] ? 2 : 1;
  2864. ++count;
  2865. }
  2866. pos++;
  2867. }
  2868. if (data[pos] !== 0) {
  2869. points[j] = 2;
  2870. ++count;
  2871. }
  2872. for (i = 1; i < height; i++) {
  2873. pos = i * lineSize;
  2874. j0 = i * width1;
  2875. if (data[pos - lineSize] !== data[pos]) {
  2876. points[j0] = data[pos] ? 1 : 8;
  2877. ++count;
  2878. }
  2879. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  2880. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  2881. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  2882. for (j = 1; j < width; j++) {
  2883. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  2884. (data[pos - lineSize + 1] ? 8 : 0);
  2885. if (POINT_TYPES[sum]) {
  2886. points[j0 + j] = POINT_TYPES[sum];
  2887. ++count;
  2888. }
  2889. pos++;
  2890. }
  2891. if (data[pos - lineSize] !== data[pos]) {
  2892. points[j0 + j] = data[pos] ? 2 : 4;
  2893. ++count;
  2894. }
  2895. if (count > POINT_TO_PROCESS_LIMIT) {
  2896. return null;
  2897. }
  2898. }
  2899. pos = lineSize * (height - 1);
  2900. j0 = i * width1;
  2901. if (data[pos] !== 0) {
  2902. points[j0] = 8;
  2903. ++count;
  2904. }
  2905. for (j = 1; j < width; j++) {
  2906. if (data[pos] !== data[pos + 1]) {
  2907. points[j0 + j] = data[pos] ? 4 : 8;
  2908. ++count;
  2909. }
  2910. pos++;
  2911. }
  2912. if (data[pos] !== 0) {
  2913. points[j0 + j] = 4;
  2914. ++count;
  2915. }
  2916. if (count > POINT_TO_PROCESS_LIMIT) {
  2917. return null;
  2918. }
  2919. // building outlines
  2920. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  2921. var outlines = [];
  2922. for (i = 0; count && i <= height; i++) {
  2923. var p = i * width1;
  2924. var end = p + width;
  2925. while (p < end && !points[p]) {
  2926. p++;
  2927. }
  2928. if (p === end) {
  2929. continue;
  2930. }
  2931. var coords = [p % width1, i];
  2932. var type = points[p], p0 = p, pp;
  2933. do {
  2934. var step = steps[type];
  2935. do {
  2936. p += step;
  2937. } while (!points[p]);
  2938. pp = points[p];
  2939. if (pp !== 5 && pp !== 10) {
  2940. // set new direction
  2941. type = pp;
  2942. // delete mark
  2943. points[p] = 0;
  2944. } else { // type is 5 or 10, ie, a crossing
  2945. // set new direction
  2946. type = pp & ((0x33 * type) >> 4);
  2947. // set new type for "future hit"
  2948. points[p] &= (type >> 2 | type << 2);
  2949. }
  2950. coords.push(p % width1);
  2951. coords.push((p / width1) | 0);
  2952. --count;
  2953. } while (p0 !== p);
  2954. outlines.push(coords);
  2955. --i;
  2956. }
  2957. var drawOutline = function(c) {
  2958. c.save();
  2959. // the path shall be painted in [0..1]x[0..1] space
  2960. c.scale(1 / width, -1 / height);
  2961. c.translate(0, -height);
  2962. c.beginPath();
  2963. for (var i = 0, ii = outlines.length; i < ii; i++) {
  2964. var o = outlines[i];
  2965. c.moveTo(o[0], o[1]);
  2966. for (var j = 2, jj = o.length; j < jj; j += 2) {
  2967. c.lineTo(o[j], o[j+1]);
  2968. }
  2969. }
  2970. c.fill();
  2971. c.beginPath();
  2972. c.restore();
  2973. };
  2974. return drawOutline;
  2975. }
  2976. var CanvasExtraState = (function CanvasExtraStateClosure() {
  2977. function CanvasExtraState(old) {
  2978. // Are soft masks and alpha values shapes or opacities?
  2979. this.alphaIsShape = false;
  2980. this.fontSize = 0;
  2981. this.fontSizeScale = 1;
  2982. this.textMatrix = IDENTITY_MATRIX;
  2983. this.textMatrixScale = 1;
  2984. this.fontMatrix = FONT_IDENTITY_MATRIX;
  2985. this.leading = 0;
  2986. // Current point (in user coordinates)
  2987. this.x = 0;
  2988. this.y = 0;
  2989. // Start of text line (in text coordinates)
  2990. this.lineX = 0;
  2991. this.lineY = 0;
  2992. // Character and word spacing
  2993. this.charSpacing = 0;
  2994. this.wordSpacing = 0;
  2995. this.textHScale = 1;
  2996. this.textRenderingMode = TextRenderingMode.FILL;
  2997. this.textRise = 0;
  2998. // Default fore and background colors
  2999. this.fillColor = '#000000';
  3000. this.strokeColor = '#000000';
  3001. // Note: fill alpha applies to all non-stroking operations
  3002. this.fillAlpha = 1;
  3003. this.strokeAlpha = 1;
  3004. this.lineWidth = 1;
  3005. this.activeSMask = null; // nonclonable field (see the save method below)
  3006. this.old = old;
  3007. }
  3008. CanvasExtraState.prototype = {
  3009. clone: function CanvasExtraState_clone() {
  3010. return Object.create(this);
  3011. },
  3012. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3013. this.x = x;
  3014. this.y = y;
  3015. }
  3016. };
  3017. return CanvasExtraState;
  3018. })();
  3019. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3020. // Defines the time the executeOperatorList is going to be executing
  3021. // before it stops and shedules a continue of execution.
  3022. var EXECUTION_TIME = 15;
  3023. // Defines the number of steps before checking the execution time
  3024. var EXECUTION_STEPS = 10;
  3025. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3026. this.ctx = canvasCtx;
  3027. this.current = new CanvasExtraState();
  3028. this.stateStack = [];
  3029. this.pendingClip = null;
  3030. this.pendingEOFill = false;
  3031. this.res = null;
  3032. this.xobjs = null;
  3033. this.commonObjs = commonObjs;
  3034. this.objs = objs;
  3035. this.imageLayer = imageLayer;
  3036. this.groupStack = [];
  3037. this.processingType3 = null;
  3038. // Patterns are painted relative to the initial page/form transform, see pdf
  3039. // spec 8.7.2 NOTE 1.
  3040. this.baseTransform = null;
  3041. this.baseTransformStack = [];
  3042. this.groupLevel = 0;
  3043. this.smaskStack = [];
  3044. this.smaskCounter = 0;
  3045. this.tempSMask = null;
  3046. if (canvasCtx) {
  3047. addContextCurrentTransform(canvasCtx);
  3048. }
  3049. }
  3050. function putBinaryImageData(ctx, imgData) {
  3051. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3052. ctx.putImageData(imgData, 0, 0);
  3053. return;
  3054. }
  3055. // Put the image data to the canvas in chunks, rather than putting the
  3056. // whole image at once. This saves JS memory, because the ImageData object
  3057. // is smaller. It also possibly saves C++ memory within the implementation
  3058. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3059. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3060. // because too many putImageData() calls will slow things down.
  3061. //
  3062. // Note: as written, if the last chunk is partial, the putImageData() call
  3063. // will (conceptually) put pixels past the bounds of the canvas. But
  3064. // that's ok; any such pixels are ignored.
  3065. var height = imgData.height, width = imgData.width;
  3066. var fullChunkHeight = 16;
  3067. var fracChunks = height / fullChunkHeight;
  3068. var fullChunks = Math.floor(fracChunks);
  3069. var totalChunks = Math.ceil(fracChunks);
  3070. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3071. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3072. var srcPos = 0, destPos;
  3073. var src = imgData.data;
  3074. var dest = chunkImgData.data;
  3075. var i, j, thisChunkHeight, elemsInThisChunk;
  3076. // There are multiple forms in which the pixel data can be passed, and
  3077. // imgData.kind tells us which one this is.
  3078. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3079. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3080. var srcLength = src.byteLength;
  3081. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3082. new Uint32ArrayView(dest);
  3083. var dest32DataLength = dest32.length;
  3084. var fullSrcDiff = (width + 7) >> 3;
  3085. var white = 0xFFFFFFFF;
  3086. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3087. 0xFF000000 : 0x000000FF;
  3088. for (i = 0; i < totalChunks; i++) {
  3089. thisChunkHeight =
  3090. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3091. destPos = 0;
  3092. for (j = 0; j < thisChunkHeight; j++) {
  3093. var srcDiff = srcLength - srcPos;
  3094. var k = 0;
  3095. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3096. var kEndUnrolled = kEnd & ~7;
  3097. var mask = 0;
  3098. var srcByte = 0;
  3099. for (; k < kEndUnrolled; k += 8) {
  3100. srcByte = src[srcPos++];
  3101. dest32[destPos++] = (srcByte & 128) ? white : black;
  3102. dest32[destPos++] = (srcByte & 64) ? white : black;
  3103. dest32[destPos++] = (srcByte & 32) ? white : black;
  3104. dest32[destPos++] = (srcByte & 16) ? white : black;
  3105. dest32[destPos++] = (srcByte & 8) ? white : black;
  3106. dest32[destPos++] = (srcByte & 4) ? white : black;
  3107. dest32[destPos++] = (srcByte & 2) ? white : black;
  3108. dest32[destPos++] = (srcByte & 1) ? white : black;
  3109. }
  3110. for (; k < kEnd; k++) {
  3111. if (mask === 0) {
  3112. srcByte = src[srcPos++];
  3113. mask = 128;
  3114. }
  3115. dest32[destPos++] = (srcByte & mask) ? white : black;
  3116. mask >>= 1;
  3117. }
  3118. }
  3119. // We ran out of input. Make all remaining pixels transparent.
  3120. while (destPos < dest32DataLength) {
  3121. dest32[destPos++] = 0;
  3122. }
  3123. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3124. }
  3125. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3126. // RGBA, 32-bits per pixel.
  3127. j = 0;
  3128. elemsInThisChunk = width * fullChunkHeight * 4;
  3129. for (i = 0; i < fullChunks; i++) {
  3130. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3131. srcPos += elemsInThisChunk;
  3132. ctx.putImageData(chunkImgData, 0, j);
  3133. j += fullChunkHeight;
  3134. }
  3135. if (i < totalChunks) {
  3136. elemsInThisChunk = width * partialChunkHeight * 4;
  3137. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3138. ctx.putImageData(chunkImgData, 0, j);
  3139. }
  3140. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3141. // RGB, 24-bits per pixel.
  3142. thisChunkHeight = fullChunkHeight;
  3143. elemsInThisChunk = width * thisChunkHeight;
  3144. for (i = 0; i < totalChunks; i++) {
  3145. if (i >= fullChunks) {
  3146. thisChunkHeight =partialChunkHeight;
  3147. elemsInThisChunk = width * thisChunkHeight;
  3148. }
  3149. destPos = 0;
  3150. for (j = elemsInThisChunk; j--;) {
  3151. dest[destPos++] = src[srcPos++];
  3152. dest[destPos++] = src[srcPos++];
  3153. dest[destPos++] = src[srcPos++];
  3154. dest[destPos++] = 255;
  3155. }
  3156. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3157. }
  3158. } else {
  3159. error('bad image kind: ' + imgData.kind);
  3160. }
  3161. }
  3162. function putBinaryImageMask(ctx, imgData) {
  3163. var height = imgData.height, width = imgData.width;
  3164. var fullChunkHeight = 16;
  3165. var fracChunks = height / fullChunkHeight;
  3166. var fullChunks = Math.floor(fracChunks);
  3167. var totalChunks = Math.ceil(fracChunks);
  3168. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3169. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3170. var srcPos = 0;
  3171. var src = imgData.data;
  3172. var dest = chunkImgData.data;
  3173. for (var i = 0; i < totalChunks; i++) {
  3174. var thisChunkHeight =
  3175. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3176. // Expand the mask so it can be used by the canvas. Any required
  3177. // inversion has already been handled.
  3178. var destPos = 3; // alpha component offset
  3179. for (var j = 0; j < thisChunkHeight; j++) {
  3180. var mask = 0;
  3181. for (var k = 0; k < width; k++) {
  3182. if (!mask) {
  3183. var elem = src[srcPos++];
  3184. mask = 128;
  3185. }
  3186. dest[destPos] = (elem & mask) ? 0 : 255;
  3187. destPos += 4;
  3188. mask >>= 1;
  3189. }
  3190. }
  3191. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3192. }
  3193. }
  3194. function copyCtxState(sourceCtx, destCtx) {
  3195. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3196. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3197. 'globalCompositeOperation', 'font'];
  3198. for (var i = 0, ii = properties.length; i < ii; i++) {
  3199. var property = properties[i];
  3200. if (property in sourceCtx) {
  3201. destCtx[property] = sourceCtx[property];
  3202. }
  3203. }
  3204. if ('setLineDash' in sourceCtx) {
  3205. destCtx.setLineDash(sourceCtx.getLineDash());
  3206. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3207. } else if ('mozDash' in sourceCtx) {
  3208. destCtx.mozDash = sourceCtx.mozDash;
  3209. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3210. }
  3211. }
  3212. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3213. var length = bytes.length;
  3214. for (var i = 3; i < length; i += 4) {
  3215. var alpha = bytes[i];
  3216. if (alpha === 0) {
  3217. bytes[i - 3] = r0;
  3218. bytes[i - 2] = g0;
  3219. bytes[i - 1] = b0;
  3220. } else if (alpha < 255) {
  3221. var alpha_ = 255 - alpha;
  3222. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3223. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3224. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3225. }
  3226. }
  3227. }
  3228. function composeSMaskAlpha(maskData, layerData) {
  3229. var length = maskData.length;
  3230. var scale = 1 / 255;
  3231. for (var i = 3; i < length; i += 4) {
  3232. var alpha = maskData[i];
  3233. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3234. }
  3235. }
  3236. function composeSMaskLuminosity(maskData, layerData) {
  3237. var length = maskData.length;
  3238. for (var i = 3; i < length; i += 4) {
  3239. var y = ((maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3240. (maskData[i - 2] * 152) + // * 0.59 ....
  3241. (maskData[i - 1] * 28)) | 0; // * 0.11 ....
  3242. layerData[i] = (layerData[i] * y) >> 16;
  3243. }
  3244. }
  3245. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3246. subtype, backdrop) {
  3247. var hasBackdrop = !!backdrop;
  3248. var r0 = hasBackdrop ? backdrop[0] : 0;
  3249. var g0 = hasBackdrop ? backdrop[1] : 0;
  3250. var b0 = hasBackdrop ? backdrop[2] : 0;
  3251. var composeFn;
  3252. if (subtype === 'Luminosity') {
  3253. composeFn = composeSMaskLuminosity;
  3254. } else {
  3255. composeFn = composeSMaskAlpha;
  3256. }
  3257. // processing image in chunks to save memory
  3258. var PIXELS_TO_PROCESS = 65536;
  3259. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3260. for (var row = 0; row < height; row += chunkSize) {
  3261. var chunkHeight = Math.min(chunkSize, height - row);
  3262. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3263. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3264. if (hasBackdrop) {
  3265. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3266. }
  3267. composeFn(maskData.data, layerData.data);
  3268. maskCtx.putImageData(layerData, 0, row);
  3269. }
  3270. }
  3271. function composeSMask(ctx, smask, layerCtx) {
  3272. var mask = smask.canvas;
  3273. var maskCtx = smask.context;
  3274. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3275. smask.offsetX, smask.offsetY);
  3276. var backdrop = smask.backdrop || null;
  3277. if (WebGLUtils.isEnabled) {
  3278. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3279. {subtype: smask.subtype, backdrop: backdrop});
  3280. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3281. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3282. return;
  3283. }
  3284. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3285. smask.subtype, backdrop);
  3286. ctx.drawImage(mask, 0, 0);
  3287. }
  3288. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3289. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3290. var NORMAL_CLIP = {};
  3291. var EO_CLIP = {};
  3292. CanvasGraphics.prototype = {
  3293. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3294. // For pdfs that use blend modes we have to clear the canvas else certain
  3295. // blend modes can look wrong since we'd be blending with a white
  3296. // backdrop. The problem with a transparent backdrop though is we then
  3297. // don't get sub pixel anti aliasing on text, so we fill with white if
  3298. // we can.
  3299. var width = this.ctx.canvas.width;
  3300. var height = this.ctx.canvas.height;
  3301. if (transparency) {
  3302. this.ctx.clearRect(0, 0, width, height);
  3303. } else {
  3304. this.ctx.mozOpaque = true;
  3305. this.ctx.save();
  3306. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3307. this.ctx.fillRect(0, 0, width, height);
  3308. this.ctx.restore();
  3309. }
  3310. var transform = viewport.transform;
  3311. this.ctx.save();
  3312. this.ctx.transform.apply(this.ctx, transform);
  3313. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3314. if (this.imageLayer) {
  3315. this.imageLayer.beginLayout();
  3316. }
  3317. },
  3318. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3319. operatorList,
  3320. executionStartIdx, continueCallback,
  3321. stepper) {
  3322. var argsArray = operatorList.argsArray;
  3323. var fnArray = operatorList.fnArray;
  3324. var i = executionStartIdx || 0;
  3325. var argsArrayLen = argsArray.length;
  3326. // Sometimes the OperatorList to execute is empty.
  3327. if (argsArrayLen === i) {
  3328. return i;
  3329. }
  3330. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3331. typeof continueCallback === 'function');
  3332. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3333. var steps = 0;
  3334. var commonObjs = this.commonObjs;
  3335. var objs = this.objs;
  3336. var fnId;
  3337. while (true) {
  3338. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3339. stepper.breakIt(i, continueCallback);
  3340. return i;
  3341. }
  3342. fnId = fnArray[i];
  3343. if (fnId !== OPS.dependency) {
  3344. this[fnId].apply(this, argsArray[i]);
  3345. } else {
  3346. var deps = argsArray[i];
  3347. for (var n = 0, nn = deps.length; n < nn; n++) {
  3348. var depObjId = deps[n];
  3349. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3350. var objsPool = common ? commonObjs : objs;
  3351. // If the promise isn't resolved yet, add the continueCallback
  3352. // to the promise and bail out.
  3353. if (!objsPool.isResolved(depObjId)) {
  3354. objsPool.get(depObjId, continueCallback);
  3355. return i;
  3356. }
  3357. }
  3358. }
  3359. i++;
  3360. // If the entire operatorList was executed, stop as were done.
  3361. if (i === argsArrayLen) {
  3362. return i;
  3363. }
  3364. // If the execution took longer then a certain amount of time and
  3365. // `continueCallback` is specified, interrupt the execution.
  3366. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3367. if (Date.now() > endTime) {
  3368. continueCallback();
  3369. return i;
  3370. }
  3371. steps = 0;
  3372. }
  3373. // If the operatorList isn't executed completely yet OR the execution
  3374. // time was short enough, do another execution round.
  3375. }
  3376. },
  3377. endDrawing: function CanvasGraphics_endDrawing() {
  3378. this.ctx.restore();
  3379. CachedCanvases.clear();
  3380. WebGLUtils.clear();
  3381. if (this.imageLayer) {
  3382. this.imageLayer.endLayout();
  3383. }
  3384. },
  3385. // Graphics state
  3386. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3387. this.current.lineWidth = width;
  3388. this.ctx.lineWidth = width;
  3389. },
  3390. setLineCap: function CanvasGraphics_setLineCap(style) {
  3391. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3392. },
  3393. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3394. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3395. },
  3396. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3397. this.ctx.miterLimit = limit;
  3398. },
  3399. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3400. var ctx = this.ctx;
  3401. if ('setLineDash' in ctx) {
  3402. ctx.setLineDash(dashArray);
  3403. ctx.lineDashOffset = dashPhase;
  3404. } else {
  3405. ctx.mozDash = dashArray;
  3406. ctx.mozDashOffset = dashPhase;
  3407. }
  3408. },
  3409. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3410. // Maybe if we one day fully support color spaces this will be important
  3411. // for now we can ignore.
  3412. // TODO set rendering intent?
  3413. },
  3414. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3415. // There's no way to control this with canvas, but we can safely ignore.
  3416. // TODO set flatness?
  3417. },
  3418. setGState: function CanvasGraphics_setGState(states) {
  3419. for (var i = 0, ii = states.length; i < ii; i++) {
  3420. var state = states[i];
  3421. var key = state[0];
  3422. var value = state[1];
  3423. switch (key) {
  3424. case 'LW':
  3425. this.setLineWidth(value);
  3426. break;
  3427. case 'LC':
  3428. this.setLineCap(value);
  3429. break;
  3430. case 'LJ':
  3431. this.setLineJoin(value);
  3432. break;
  3433. case 'ML':
  3434. this.setMiterLimit(value);
  3435. break;
  3436. case 'D':
  3437. this.setDash(value[0], value[1]);
  3438. break;
  3439. case 'RI':
  3440. this.setRenderingIntent(value);
  3441. break;
  3442. case 'FL':
  3443. this.setFlatness(value);
  3444. break;
  3445. case 'Font':
  3446. this.setFont(value[0], value[1]);
  3447. break;
  3448. case 'CA':
  3449. this.current.strokeAlpha = state[1];
  3450. break;
  3451. case 'ca':
  3452. this.current.fillAlpha = state[1];
  3453. this.ctx.globalAlpha = state[1];
  3454. break;
  3455. case 'BM':
  3456. if (value && value.name && (value.name !== 'Normal')) {
  3457. var mode = value.name.replace(/([A-Z])/g,
  3458. function(c) {
  3459. return '-' + c.toLowerCase();
  3460. }
  3461. ).substring(1);
  3462. this.ctx.globalCompositeOperation = mode;
  3463. if (this.ctx.globalCompositeOperation !== mode) {
  3464. warn('globalCompositeOperation "' + mode +
  3465. '" is not supported');
  3466. }
  3467. } else {
  3468. this.ctx.globalCompositeOperation = 'source-over';
  3469. }
  3470. break;
  3471. case 'SMask':
  3472. if (this.current.activeSMask) {
  3473. this.endSMaskGroup();
  3474. }
  3475. this.current.activeSMask = value ? this.tempSMask : null;
  3476. if (this.current.activeSMask) {
  3477. this.beginSMaskGroup();
  3478. }
  3479. this.tempSMask = null;
  3480. break;
  3481. }
  3482. }
  3483. },
  3484. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3485. var activeSMask = this.current.activeSMask;
  3486. var drawnWidth = activeSMask.canvas.width;
  3487. var drawnHeight = activeSMask.canvas.height;
  3488. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3489. var scratchCanvas = CachedCanvases.getCanvas(
  3490. cacheId, drawnWidth, drawnHeight, true);
  3491. var currentCtx = this.ctx;
  3492. var currentTransform = currentCtx.mozCurrentTransform;
  3493. this.ctx.save();
  3494. var groupCtx = scratchCanvas.context;
  3495. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3496. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3497. groupCtx.transform.apply(groupCtx, currentTransform);
  3498. copyCtxState(currentCtx, groupCtx);
  3499. this.ctx = groupCtx;
  3500. this.setGState([
  3501. ['BM', 'Normal'],
  3502. ['ca', 1],
  3503. ['CA', 1]
  3504. ]);
  3505. this.groupStack.push(currentCtx);
  3506. this.groupLevel++;
  3507. },
  3508. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3509. var groupCtx = this.ctx;
  3510. this.groupLevel--;
  3511. this.ctx = this.groupStack.pop();
  3512. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3513. this.ctx.restore();
  3514. },
  3515. save: function CanvasGraphics_save() {
  3516. this.ctx.save();
  3517. var old = this.current;
  3518. this.stateStack.push(old);
  3519. this.current = old.clone();
  3520. this.current.activeSMask = null;
  3521. },
  3522. restore: function CanvasGraphics_restore() {
  3523. if (this.stateStack.length !== 0) {
  3524. if (this.current.activeSMask !== null) {
  3525. this.endSMaskGroup();
  3526. }
  3527. this.current = this.stateStack.pop();
  3528. this.ctx.restore();
  3529. }
  3530. },
  3531. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3532. this.ctx.transform(a, b, c, d, e, f);
  3533. },
  3534. // Path
  3535. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3536. var ctx = this.ctx;
  3537. var current = this.current;
  3538. var x = current.x, y = current.y;
  3539. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3540. switch (ops[i] | 0) {
  3541. case OPS.rectangle:
  3542. x = args[j++];
  3543. y = args[j++];
  3544. var width = args[j++];
  3545. var height = args[j++];
  3546. if (width === 0) {
  3547. width = this.getSinglePixelWidth();
  3548. }
  3549. if (height === 0) {
  3550. height = this.getSinglePixelWidth();
  3551. }
  3552. var xw = x + width;
  3553. var yh = y + height;
  3554. this.ctx.moveTo(x, y);
  3555. this.ctx.lineTo(xw, y);
  3556. this.ctx.lineTo(xw, yh);
  3557. this.ctx.lineTo(x, yh);
  3558. this.ctx.lineTo(x, y);
  3559. this.ctx.closePath();
  3560. break;
  3561. case OPS.moveTo:
  3562. x = args[j++];
  3563. y = args[j++];
  3564. ctx.moveTo(x, y);
  3565. break;
  3566. case OPS.lineTo:
  3567. x = args[j++];
  3568. y = args[j++];
  3569. ctx.lineTo(x, y);
  3570. break;
  3571. case OPS.curveTo:
  3572. x = args[j + 4];
  3573. y = args[j + 5];
  3574. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3575. x, y);
  3576. j += 6;
  3577. break;
  3578. case OPS.curveTo2:
  3579. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3580. args[j + 2], args[j + 3]);
  3581. x = args[j + 2];
  3582. y = args[j + 3];
  3583. j += 4;
  3584. break;
  3585. case OPS.curveTo3:
  3586. x = args[j + 2];
  3587. y = args[j + 3];
  3588. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3589. j += 4;
  3590. break;
  3591. case OPS.closePath:
  3592. ctx.closePath();
  3593. break;
  3594. }
  3595. }
  3596. current.setCurrentPoint(x, y);
  3597. },
  3598. closePath: function CanvasGraphics_closePath() {
  3599. this.ctx.closePath();
  3600. },
  3601. stroke: function CanvasGraphics_stroke(consumePath) {
  3602. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3603. var ctx = this.ctx;
  3604. var strokeColor = this.current.strokeColor;
  3605. if (this.current.lineWidth === 0) {
  3606. ctx.lineWidth = this.getSinglePixelWidth();
  3607. }
  3608. // For stroke we want to temporarily change the global alpha to the
  3609. // stroking alpha.
  3610. ctx.globalAlpha = this.current.strokeAlpha;
  3611. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3612. strokeColor.type === 'Pattern') {
  3613. // for patterns, we transform to pattern space, calculate
  3614. // the pattern, call stroke, and restore to user space
  3615. ctx.save();
  3616. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3617. ctx.stroke();
  3618. ctx.restore();
  3619. } else {
  3620. ctx.stroke();
  3621. }
  3622. if (consumePath) {
  3623. this.consumePath();
  3624. }
  3625. // Restore the global alpha to the fill alpha
  3626. ctx.globalAlpha = this.current.fillAlpha;
  3627. },
  3628. closeStroke: function CanvasGraphics_closeStroke() {
  3629. this.closePath();
  3630. this.stroke();
  3631. },
  3632. fill: function CanvasGraphics_fill(consumePath) {
  3633. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3634. var ctx = this.ctx;
  3635. var fillColor = this.current.fillColor;
  3636. var needRestore = false;
  3637. if (fillColor && fillColor.hasOwnProperty('type') &&
  3638. fillColor.type === 'Pattern') {
  3639. ctx.save();
  3640. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3641. needRestore = true;
  3642. }
  3643. if (this.pendingEOFill) {
  3644. if (ctx.mozFillRule !== undefined) {
  3645. ctx.mozFillRule = 'evenodd';
  3646. ctx.fill();
  3647. ctx.mozFillRule = 'nonzero';
  3648. } else {
  3649. try {
  3650. ctx.fill('evenodd');
  3651. } catch (ex) {
  3652. // shouldn't really happen, but browsers might think differently
  3653. ctx.fill();
  3654. }
  3655. }
  3656. this.pendingEOFill = false;
  3657. } else {
  3658. ctx.fill();
  3659. }
  3660. if (needRestore) {
  3661. ctx.restore();
  3662. }
  3663. if (consumePath) {
  3664. this.consumePath();
  3665. }
  3666. },
  3667. eoFill: function CanvasGraphics_eoFill() {
  3668. this.pendingEOFill = true;
  3669. this.fill();
  3670. },
  3671. fillStroke: function CanvasGraphics_fillStroke() {
  3672. this.fill(false);
  3673. this.stroke(false);
  3674. this.consumePath();
  3675. },
  3676. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3677. this.pendingEOFill = true;
  3678. this.fillStroke();
  3679. },
  3680. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3681. this.closePath();
  3682. this.fillStroke();
  3683. },
  3684. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3685. this.pendingEOFill = true;
  3686. this.closePath();
  3687. this.fillStroke();
  3688. },
  3689. endPath: function CanvasGraphics_endPath() {
  3690. this.consumePath();
  3691. },
  3692. // Clipping
  3693. clip: function CanvasGraphics_clip() {
  3694. this.pendingClip = NORMAL_CLIP;
  3695. },
  3696. eoClip: function CanvasGraphics_eoClip() {
  3697. this.pendingClip = EO_CLIP;
  3698. },
  3699. // Text
  3700. beginText: function CanvasGraphics_beginText() {
  3701. this.current.textMatrix = IDENTITY_MATRIX;
  3702. this.current.textMatrixScale = 1;
  3703. this.current.x = this.current.lineX = 0;
  3704. this.current.y = this.current.lineY = 0;
  3705. },
  3706. endText: function CanvasGraphics_endText() {
  3707. var paths = this.pendingTextPaths;
  3708. var ctx = this.ctx;
  3709. if (paths === undefined) {
  3710. ctx.beginPath();
  3711. return;
  3712. }
  3713. ctx.save();
  3714. ctx.beginPath();
  3715. for (var i = 0; i < paths.length; i++) {
  3716. var path = paths[i];
  3717. ctx.setTransform.apply(ctx, path.transform);
  3718. ctx.translate(path.x, path.y);
  3719. path.addToPath(ctx, path.fontSize);
  3720. }
  3721. ctx.restore();
  3722. ctx.clip();
  3723. ctx.beginPath();
  3724. delete this.pendingTextPaths;
  3725. },
  3726. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3727. this.current.charSpacing = spacing;
  3728. },
  3729. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3730. this.current.wordSpacing = spacing;
  3731. },
  3732. setHScale: function CanvasGraphics_setHScale(scale) {
  3733. this.current.textHScale = scale / 100;
  3734. },
  3735. setLeading: function CanvasGraphics_setLeading(leading) {
  3736. this.current.leading = -leading;
  3737. },
  3738. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3739. var fontObj = this.commonObjs.get(fontRefName);
  3740. var current = this.current;
  3741. if (!fontObj) {
  3742. error('Can\'t find font for ' + fontRefName);
  3743. }
  3744. current.fontMatrix = (fontObj.fontMatrix ?
  3745. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3746. // A valid matrix needs all main diagonal elements to be non-zero
  3747. // This also ensures we bypass FF bugzilla bug #719844.
  3748. if (current.fontMatrix[0] === 0 ||
  3749. current.fontMatrix[3] === 0) {
  3750. warn('Invalid font matrix for font ' + fontRefName);
  3751. }
  3752. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3753. // and in some docs this can be negative (inverted x-y axes).
  3754. if (size < 0) {
  3755. size = -size;
  3756. current.fontDirection = -1;
  3757. } else {
  3758. current.fontDirection = 1;
  3759. }
  3760. this.current.font = fontObj;
  3761. this.current.fontSize = size;
  3762. if (fontObj.isType3Font) {
  3763. return; // we don't need ctx.font for Type3 fonts
  3764. }
  3765. var name = fontObj.loadedName || 'sans-serif';
  3766. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  3767. (fontObj.bold ? 'bold' : 'normal');
  3768. var italic = fontObj.italic ? 'italic' : 'normal';
  3769. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  3770. // Some font backends cannot handle fonts below certain size.
  3771. // Keeping the font at minimal size and using the fontSizeScale to change
  3772. // the current transformation matrix before the fillText/strokeText.
  3773. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  3774. var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
  3775. this.current.fontSizeScale = browserFontSize !== MIN_FONT_SIZE ? 1.0 :
  3776. size / MIN_FONT_SIZE;
  3777. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  3778. this.ctx.font = rule;
  3779. },
  3780. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  3781. this.current.textRenderingMode = mode;
  3782. },
  3783. setTextRise: function CanvasGraphics_setTextRise(rise) {
  3784. this.current.textRise = rise;
  3785. },
  3786. moveText: function CanvasGraphics_moveText(x, y) {
  3787. this.current.x = this.current.lineX += x;
  3788. this.current.y = this.current.lineY += y;
  3789. },
  3790. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  3791. this.setLeading(-y);
  3792. this.moveText(x, y);
  3793. },
  3794. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  3795. this.current.textMatrix = [a, b, c, d, e, f];
  3796. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  3797. this.current.x = this.current.lineX = 0;
  3798. this.current.y = this.current.lineY = 0;
  3799. },
  3800. nextLine: function CanvasGraphics_nextLine() {
  3801. this.moveText(0, this.current.leading);
  3802. },
  3803. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  3804. var ctx = this.ctx;
  3805. var current = this.current;
  3806. var font = current.font;
  3807. var textRenderingMode = current.textRenderingMode;
  3808. var fontSize = current.fontSize / current.fontSizeScale;
  3809. var fillStrokeMode = textRenderingMode &
  3810. TextRenderingMode.FILL_STROKE_MASK;
  3811. var isAddToPathSet = !!(textRenderingMode &
  3812. TextRenderingMode.ADD_TO_PATH_FLAG);
  3813. var addToPath;
  3814. if (font.disableFontFace || isAddToPathSet) {
  3815. addToPath = font.getPathGenerator(this.commonObjs, character);
  3816. }
  3817. if (font.disableFontFace) {
  3818. ctx.save();
  3819. ctx.translate(x, y);
  3820. ctx.beginPath();
  3821. addToPath(ctx, fontSize);
  3822. if (fillStrokeMode === TextRenderingMode.FILL ||
  3823. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3824. ctx.fill();
  3825. }
  3826. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3827. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3828. ctx.stroke();
  3829. }
  3830. ctx.restore();
  3831. } else {
  3832. if (fillStrokeMode === TextRenderingMode.FILL ||
  3833. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3834. ctx.fillText(character, x, y);
  3835. }
  3836. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3837. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3838. ctx.strokeText(character, x, y);
  3839. }
  3840. }
  3841. if (isAddToPathSet) {
  3842. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  3843. paths.push({
  3844. transform: ctx.mozCurrentTransform,
  3845. x: x,
  3846. y: y,
  3847. fontSize: fontSize,
  3848. addToPath: addToPath
  3849. });
  3850. }
  3851. },
  3852. get isFontSubpixelAAEnabled() {
  3853. // Checks if anti-aliasing is enabled when scaled text is painted.
  3854. // On Windows GDI scaled fonts looks bad.
  3855. var ctx = document.createElement('canvas').getContext('2d');
  3856. ctx.scale(1.5, 1);
  3857. ctx.fillText('I', 0, 10);
  3858. var data = ctx.getImageData(0, 0, 10, 10).data;
  3859. var enabled = false;
  3860. for (var i = 3; i < data.length; i += 4) {
  3861. if (data[i] > 0 && data[i] < 255) {
  3862. enabled = true;
  3863. break;
  3864. }
  3865. }
  3866. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  3867. },
  3868. showText: function CanvasGraphics_showText(glyphs) {
  3869. var current = this.current;
  3870. var font = current.font;
  3871. if (font.isType3Font) {
  3872. return this.showType3Text(glyphs);
  3873. }
  3874. var fontSize = current.fontSize;
  3875. if (fontSize === 0) {
  3876. return;
  3877. }
  3878. var ctx = this.ctx;
  3879. var fontSizeScale = current.fontSizeScale;
  3880. var charSpacing = current.charSpacing;
  3881. var wordSpacing = current.wordSpacing;
  3882. var fontDirection = current.fontDirection;
  3883. var textHScale = current.textHScale * fontDirection;
  3884. var glyphsLength = glyphs.length;
  3885. var vertical = font.vertical;
  3886. var defaultVMetrics = font.defaultVMetrics;
  3887. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  3888. var simpleFillText =
  3889. current.textRenderingMode === TextRenderingMode.FILL &&
  3890. !font.disableFontFace;
  3891. ctx.save();
  3892. ctx.transform.apply(ctx, current.textMatrix);
  3893. ctx.translate(current.x, current.y + current.textRise);
  3894. if (fontDirection > 0) {
  3895. ctx.scale(textHScale, -1);
  3896. } else {
  3897. ctx.scale(textHScale, 1);
  3898. }
  3899. var lineWidth = current.lineWidth;
  3900. var scale = current.textMatrixScale;
  3901. if (scale === 0 || lineWidth === 0) {
  3902. lineWidth = this.getSinglePixelWidth();
  3903. } else {
  3904. lineWidth /= scale;
  3905. }
  3906. if (fontSizeScale !== 1.0) {
  3907. ctx.scale(fontSizeScale, fontSizeScale);
  3908. lineWidth /= fontSizeScale;
  3909. }
  3910. ctx.lineWidth = lineWidth;
  3911. var x = 0, i;
  3912. for (i = 0; i < glyphsLength; ++i) {
  3913. var glyph = glyphs[i];
  3914. if (glyph === null) {
  3915. // word break
  3916. x += fontDirection * wordSpacing;
  3917. continue;
  3918. } else if (isNum(glyph)) {
  3919. x += -glyph * fontSize * 0.001;
  3920. continue;
  3921. }
  3922. var restoreNeeded = false;
  3923. var character = glyph.fontChar;
  3924. var accent = glyph.accent;
  3925. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  3926. var width = glyph.width;
  3927. if (vertical) {
  3928. var vmetric, vx, vy;
  3929. vmetric = glyph.vmetric || defaultVMetrics;
  3930. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  3931. vx = -vx * widthAdvanceScale;
  3932. vy = vmetric[2] * widthAdvanceScale;
  3933. width = vmetric ? -vmetric[0] : width;
  3934. scaledX = vx / fontSizeScale;
  3935. scaledY = (x + vy) / fontSizeScale;
  3936. } else {
  3937. scaledX = x / fontSizeScale;
  3938. scaledY = 0;
  3939. }
  3940. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  3941. // some standard fonts may not have the exact width, trying to
  3942. // rescale per character
  3943. var measuredWidth = ctx.measureText(character).width * 1000 /
  3944. fontSize * fontSizeScale;
  3945. var characterScaleX = width / measuredWidth;
  3946. restoreNeeded = true;
  3947. ctx.save();
  3948. ctx.scale(characterScaleX, 1);
  3949. scaledX /= characterScaleX;
  3950. }
  3951. if (simpleFillText && !accent) {
  3952. // common case
  3953. ctx.fillText(character, scaledX, scaledY);
  3954. } else {
  3955. this.paintChar(character, scaledX, scaledY);
  3956. if (accent) {
  3957. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  3958. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  3959. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  3960. }
  3961. }
  3962. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  3963. x += charWidth;
  3964. if (restoreNeeded) {
  3965. ctx.restore();
  3966. }
  3967. }
  3968. if (vertical) {
  3969. current.y -= x * textHScale;
  3970. } else {
  3971. current.x += x * textHScale;
  3972. }
  3973. ctx.restore();
  3974. },
  3975. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  3976. // Type3 fonts - each glyph is a "mini-PDF"
  3977. var ctx = this.ctx;
  3978. var current = this.current;
  3979. var font = current.font;
  3980. var fontSize = current.fontSize;
  3981. var fontDirection = current.fontDirection;
  3982. var charSpacing = current.charSpacing;
  3983. var wordSpacing = current.wordSpacing;
  3984. var textHScale = current.textHScale * fontDirection;
  3985. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  3986. var glyphsLength = glyphs.length;
  3987. var i, glyph, width;
  3988. if (fontSize === 0) {
  3989. return;
  3990. }
  3991. ctx.save();
  3992. ctx.transform.apply(ctx, current.textMatrix);
  3993. ctx.translate(current.x, current.y);
  3994. ctx.scale(textHScale, 1);
  3995. for (i = 0; i < glyphsLength; ++i) {
  3996. glyph = glyphs[i];
  3997. if (glyph === null) {
  3998. // word break
  3999. this.ctx.translate(wordSpacing, 0);
  4000. current.x += wordSpacing * textHScale;
  4001. continue;
  4002. } else if (isNum(glyph)) {
  4003. var spacingLength = -glyph * 0.001 * fontSize;
  4004. this.ctx.translate(spacingLength, 0);
  4005. current.x += spacingLength * textHScale;
  4006. continue;
  4007. }
  4008. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4009. if (!operatorList) {
  4010. warn('Type3 character \"' + glyph.operatorListId +
  4011. '\" is not available');
  4012. continue;
  4013. }
  4014. this.processingType3 = glyph;
  4015. this.save();
  4016. ctx.scale(fontSize, fontSize);
  4017. ctx.transform.apply(ctx, fontMatrix);
  4018. this.executeOperatorList(operatorList);
  4019. this.restore();
  4020. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4021. width = ((transformed[0] * fontSize + charSpacing) * fontDirection);
  4022. ctx.translate(width, 0);
  4023. current.x += width * textHScale;
  4024. }
  4025. ctx.restore();
  4026. this.processingType3 = null;
  4027. },
  4028. // Type3 fonts
  4029. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4030. // We can safely ignore this since the width should be the same
  4031. // as the width in the Widths array.
  4032. },
  4033. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4034. yWidth,
  4035. llx,
  4036. lly,
  4037. urx,
  4038. ury) {
  4039. // TODO According to the spec we're also suppose to ignore any operators
  4040. // that set color or include images while processing this type3 font.
  4041. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4042. this.clip();
  4043. this.endPath();
  4044. },
  4045. // Color
  4046. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4047. var pattern;
  4048. if (IR[0] === 'TilingPattern') {
  4049. var color = IR[1];
  4050. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4051. this.commonObjs, this.baseTransform);
  4052. } else {
  4053. pattern = getShadingPatternFromIR(IR);
  4054. }
  4055. return pattern;
  4056. },
  4057. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4058. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4059. },
  4060. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4061. this.current.fillColor = this.getColorN_Pattern(arguments);
  4062. },
  4063. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4064. var color = Util.makeCssRgb(arguments);
  4065. this.ctx.strokeStyle = color;
  4066. this.current.strokeColor = color;
  4067. },
  4068. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4069. var color = Util.makeCssRgb(arguments);
  4070. this.ctx.fillStyle = color;
  4071. this.current.fillColor = color;
  4072. },
  4073. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4074. var ctx = this.ctx;
  4075. this.save();
  4076. var pattern = getShadingPatternFromIR(patternIR);
  4077. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4078. var inv = ctx.mozCurrentTransformInverse;
  4079. if (inv) {
  4080. var canvas = ctx.canvas;
  4081. var width = canvas.width;
  4082. var height = canvas.height;
  4083. var bl = Util.applyTransform([0, 0], inv);
  4084. var br = Util.applyTransform([0, height], inv);
  4085. var ul = Util.applyTransform([width, 0], inv);
  4086. var ur = Util.applyTransform([width, height], inv);
  4087. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4088. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4089. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4090. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4091. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4092. } else {
  4093. // HACK to draw the gradient onto an infinite rectangle.
  4094. // PDF gradients are drawn across the entire image while
  4095. // Canvas only allows gradients to be drawn in a rectangle
  4096. // The following bug should allow us to remove this.
  4097. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4098. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4099. }
  4100. this.restore();
  4101. },
  4102. // Images
  4103. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4104. error('Should not call beginInlineImage');
  4105. },
  4106. beginImageData: function CanvasGraphics_beginImageData() {
  4107. error('Should not call beginImageData');
  4108. },
  4109. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4110. bbox) {
  4111. this.save();
  4112. this.baseTransformStack.push(this.baseTransform);
  4113. if (isArray(matrix) && 6 === matrix.length) {
  4114. this.transform.apply(this, matrix);
  4115. }
  4116. this.baseTransform = this.ctx.mozCurrentTransform;
  4117. if (isArray(bbox) && 4 === bbox.length) {
  4118. var width = bbox[2] - bbox[0];
  4119. var height = bbox[3] - bbox[1];
  4120. this.ctx.rect(bbox[0], bbox[1], width, height);
  4121. this.clip();
  4122. this.endPath();
  4123. }
  4124. },
  4125. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4126. this.restore();
  4127. this.baseTransform = this.baseTransformStack.pop();
  4128. },
  4129. beginGroup: function CanvasGraphics_beginGroup(group) {
  4130. this.save();
  4131. var currentCtx = this.ctx;
  4132. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4133. // group results aren't usually that different and they even have tools
  4134. // that ignore this setting. Notes from Rik on implmenting:
  4135. // - When you encounter an transparency group, create a new canvas with
  4136. // the dimensions of the bbox
  4137. // - copy the content from the previous canvas to the new canvas
  4138. // - draw as usual
  4139. // - remove the backdrop alpha:
  4140. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4141. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4142. // backdrop
  4143. // - remove background color:
  4144. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4145. if (!group.isolated) {
  4146. info('TODO: Support non-isolated groups.');
  4147. }
  4148. // TODO knockout - supposedly possible with the clever use of compositing
  4149. // modes.
  4150. if (group.knockout) {
  4151. warn('Knockout groups not supported.');
  4152. }
  4153. var currentTransform = currentCtx.mozCurrentTransform;
  4154. if (group.matrix) {
  4155. currentCtx.transform.apply(currentCtx, group.matrix);
  4156. }
  4157. assert(group.bbox, 'Bounding box is required.');
  4158. // Based on the current transform figure out how big the bounding box
  4159. // will actually be.
  4160. var bounds = Util.getAxialAlignedBoundingBox(
  4161. group.bbox,
  4162. currentCtx.mozCurrentTransform);
  4163. // Clip the bounding box to the current canvas.
  4164. var canvasBounds = [0,
  4165. 0,
  4166. currentCtx.canvas.width,
  4167. currentCtx.canvas.height];
  4168. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4169. // Use ceil in case we're between sizes so we don't create canvas that is
  4170. // too small and make the canvas at least 1x1 pixels.
  4171. var offsetX = Math.floor(bounds[0]);
  4172. var offsetY = Math.floor(bounds[1]);
  4173. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4174. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4175. var scaleX = 1, scaleY = 1;
  4176. if (drawnWidth > MAX_GROUP_SIZE) {
  4177. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4178. drawnWidth = MAX_GROUP_SIZE;
  4179. }
  4180. if (drawnHeight > MAX_GROUP_SIZE) {
  4181. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4182. drawnHeight = MAX_GROUP_SIZE;
  4183. }
  4184. var cacheId = 'groupAt' + this.groupLevel;
  4185. if (group.smask) {
  4186. // Using two cache entries is case if masks are used one after another.
  4187. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4188. }
  4189. var scratchCanvas = CachedCanvases.getCanvas(
  4190. cacheId, drawnWidth, drawnHeight, true);
  4191. var groupCtx = scratchCanvas.context;
  4192. // Since we created a new canvas that is just the size of the bounding box
  4193. // we have to translate the group ctx.
  4194. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4195. groupCtx.translate(-offsetX, -offsetY);
  4196. groupCtx.transform.apply(groupCtx, currentTransform);
  4197. if (group.smask) {
  4198. // Saving state and cached mask to be used in setGState.
  4199. this.smaskStack.push({
  4200. canvas: scratchCanvas.canvas,
  4201. context: groupCtx,
  4202. offsetX: offsetX,
  4203. offsetY: offsetY,
  4204. scaleX: scaleX,
  4205. scaleY: scaleY,
  4206. subtype: group.smask.subtype,
  4207. backdrop: group.smask.backdrop
  4208. });
  4209. } else {
  4210. // Setup the current ctx so when the group is popped we draw it at the
  4211. // right location.
  4212. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4213. currentCtx.translate(offsetX, offsetY);
  4214. currentCtx.scale(scaleX, scaleY);
  4215. }
  4216. // The transparency group inherits all off the current graphics state
  4217. // except the blend mode, soft mask, and alpha constants.
  4218. copyCtxState(currentCtx, groupCtx);
  4219. this.ctx = groupCtx;
  4220. this.setGState([
  4221. ['BM', 'Normal'],
  4222. ['ca', 1],
  4223. ['CA', 1]
  4224. ]);
  4225. this.groupStack.push(currentCtx);
  4226. this.groupLevel++;
  4227. },
  4228. endGroup: function CanvasGraphics_endGroup(group) {
  4229. this.groupLevel--;
  4230. var groupCtx = this.ctx;
  4231. this.ctx = this.groupStack.pop();
  4232. // Turn off image smoothing to avoid sub pixel interpolation which can
  4233. // look kind of blurry for some pdfs.
  4234. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4235. this.ctx.imageSmoothingEnabled = false;
  4236. } else {
  4237. this.ctx.mozImageSmoothingEnabled = false;
  4238. }
  4239. if (group.smask) {
  4240. this.tempSMask = this.smaskStack.pop();
  4241. } else {
  4242. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4243. }
  4244. this.restore();
  4245. },
  4246. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4247. this.save();
  4248. this.current = new CanvasExtraState();
  4249. },
  4250. endAnnotations: function CanvasGraphics_endAnnotations() {
  4251. this.restore();
  4252. },
  4253. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4254. matrix) {
  4255. this.save();
  4256. if (isArray(rect) && 4 === rect.length) {
  4257. var width = rect[2] - rect[0];
  4258. var height = rect[3] - rect[1];
  4259. this.ctx.rect(rect[0], rect[1], width, height);
  4260. this.clip();
  4261. this.endPath();
  4262. }
  4263. this.transform.apply(this, transform);
  4264. this.transform.apply(this, matrix);
  4265. },
  4266. endAnnotation: function CanvasGraphics_endAnnotation() {
  4267. this.restore();
  4268. },
  4269. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4270. var domImage = this.objs.get(objId);
  4271. if (!domImage) {
  4272. warn('Dependent image isn\'t ready yet');
  4273. return;
  4274. }
  4275. this.save();
  4276. var ctx = this.ctx;
  4277. // scale the image to the unit square
  4278. ctx.scale(1 / w, -1 / h);
  4279. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4280. 0, -h, w, h);
  4281. if (this.imageLayer) {
  4282. var currentTransform = ctx.mozCurrentTransformInverse;
  4283. var position = this.getCanvasPosition(0, 0);
  4284. this.imageLayer.appendImage({
  4285. objId: objId,
  4286. left: position[0],
  4287. top: position[1],
  4288. width: w / currentTransform[0],
  4289. height: h / currentTransform[3]
  4290. });
  4291. }
  4292. this.restore();
  4293. },
  4294. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4295. var ctx = this.ctx;
  4296. var width = img.width, height = img.height;
  4297. var glyph = this.processingType3;
  4298. if (COMPILE_TYPE3_GLYPHS && glyph && !('compiled' in glyph)) {
  4299. var MAX_SIZE_TO_COMPILE = 1000;
  4300. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4301. glyph.compiled =
  4302. compileType3Glyph({data: img.data, width: width, height: height});
  4303. } else {
  4304. glyph.compiled = null;
  4305. }
  4306. }
  4307. if (glyph && glyph.compiled) {
  4308. glyph.compiled(ctx);
  4309. return;
  4310. }
  4311. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4312. var maskCtx = maskCanvas.context;
  4313. maskCtx.save();
  4314. putBinaryImageMask(maskCtx, img);
  4315. maskCtx.globalCompositeOperation = 'source-in';
  4316. var fillColor = this.current.fillColor;
  4317. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4318. fillColor.type === 'Pattern') ?
  4319. fillColor.getPattern(maskCtx, this) : fillColor;
  4320. maskCtx.fillRect(0, 0, width, height);
  4321. maskCtx.restore();
  4322. this.paintInlineImageXObject(maskCanvas.canvas);
  4323. },
  4324. paintImageMaskXObjectRepeat:
  4325. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4326. scaleY, positions) {
  4327. var width = imgData.width;
  4328. var height = imgData.height;
  4329. var ctx = this.ctx;
  4330. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4331. var maskCtx = maskCanvas.context;
  4332. maskCtx.save();
  4333. putBinaryImageMask(maskCtx, imgData);
  4334. maskCtx.globalCompositeOperation = 'source-in';
  4335. var fillColor = this.current.fillColor;
  4336. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4337. fillColor.type === 'Pattern') ?
  4338. fillColor.getPattern(maskCtx, this) : fillColor;
  4339. maskCtx.fillRect(0, 0, width, height);
  4340. maskCtx.restore();
  4341. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4342. ctx.save();
  4343. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4344. ctx.scale(1, -1);
  4345. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4346. 0, -1, 1, 1);
  4347. ctx.restore();
  4348. }
  4349. },
  4350. paintImageMaskXObjectGroup:
  4351. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4352. var ctx = this.ctx;
  4353. for (var i = 0, ii = images.length; i < ii; i++) {
  4354. var image = images[i];
  4355. var width = image.width, height = image.height;
  4356. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4357. var maskCtx = maskCanvas.context;
  4358. maskCtx.save();
  4359. putBinaryImageMask(maskCtx, image);
  4360. maskCtx.globalCompositeOperation = 'source-in';
  4361. var fillColor = this.current.fillColor;
  4362. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4363. fillColor.type === 'Pattern') ?
  4364. fillColor.getPattern(maskCtx, this) : fillColor;
  4365. maskCtx.fillRect(0, 0, width, height);
  4366. maskCtx.restore();
  4367. ctx.save();
  4368. ctx.transform.apply(ctx, image.transform);
  4369. ctx.scale(1, -1);
  4370. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4371. 0, -1, 1, 1);
  4372. ctx.restore();
  4373. }
  4374. },
  4375. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4376. var imgData = this.objs.get(objId);
  4377. if (!imgData) {
  4378. warn('Dependent image isn\'t ready yet');
  4379. return;
  4380. }
  4381. this.paintInlineImageXObject(imgData);
  4382. },
  4383. paintImageXObjectRepeat:
  4384. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4385. positions) {
  4386. var imgData = this.objs.get(objId);
  4387. if (!imgData) {
  4388. warn('Dependent image isn\'t ready yet');
  4389. return;
  4390. }
  4391. var width = imgData.width;
  4392. var height = imgData.height;
  4393. var map = [];
  4394. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4395. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4396. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4397. }
  4398. this.paintInlineImageXObjectGroup(imgData, map);
  4399. },
  4400. paintInlineImageXObject:
  4401. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4402. var width = imgData.width;
  4403. var height = imgData.height;
  4404. var ctx = this.ctx;
  4405. this.save();
  4406. // scale the image to the unit square
  4407. ctx.scale(1 / width, -1 / height);
  4408. var currentTransform = ctx.mozCurrentTransformInverse;
  4409. var a = currentTransform[0], b = currentTransform[1];
  4410. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4411. var c = currentTransform[2], d = currentTransform[3];
  4412. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4413. var imgToPaint, tmpCanvas;
  4414. // instanceof HTMLElement does not work in jsdom node.js module
  4415. if (imgData instanceof HTMLElement || !imgData.data) {
  4416. imgToPaint = imgData;
  4417. } else {
  4418. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4419. var tmpCtx = tmpCanvas.context;
  4420. putBinaryImageData(tmpCtx, imgData);
  4421. imgToPaint = tmpCanvas.canvas;
  4422. }
  4423. var paintWidth = width, paintHeight = height;
  4424. var tmpCanvasId = 'prescale1';
  4425. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4426. // pixels during drawImage operation, painting on the temporary canvas(es)
  4427. // that are twice smaller in size
  4428. while ((widthScale > 2 && paintWidth > 1) ||
  4429. (heightScale > 2 && paintHeight > 1)) {
  4430. var newWidth = paintWidth, newHeight = paintHeight;
  4431. if (widthScale > 2 && paintWidth > 1) {
  4432. newWidth = Math.ceil(paintWidth / 2);
  4433. widthScale /= paintWidth / newWidth;
  4434. }
  4435. if (heightScale > 2 && paintHeight > 1) {
  4436. newHeight = Math.ceil(paintHeight / 2);
  4437. heightScale /= paintHeight / newHeight;
  4438. }
  4439. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4440. tmpCtx = tmpCanvas.context;
  4441. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4442. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4443. 0, 0, newWidth, newHeight);
  4444. imgToPaint = tmpCanvas.canvas;
  4445. paintWidth = newWidth;
  4446. paintHeight = newHeight;
  4447. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4448. }
  4449. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4450. 0, -height, width, height);
  4451. if (this.imageLayer) {
  4452. var position = this.getCanvasPosition(0, -height);
  4453. this.imageLayer.appendImage({
  4454. imgData: imgData,
  4455. left: position[0],
  4456. top: position[1],
  4457. width: width / currentTransform[0],
  4458. height: height / currentTransform[3]
  4459. });
  4460. }
  4461. this.restore();
  4462. },
  4463. paintInlineImageXObjectGroup:
  4464. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4465. var ctx = this.ctx;
  4466. var w = imgData.width;
  4467. var h = imgData.height;
  4468. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4469. var tmpCtx = tmpCanvas.context;
  4470. putBinaryImageData(tmpCtx, imgData);
  4471. for (var i = 0, ii = map.length; i < ii; i++) {
  4472. var entry = map[i];
  4473. ctx.save();
  4474. ctx.transform.apply(ctx, entry.transform);
  4475. ctx.scale(1, -1);
  4476. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4477. 0, -1, 1, 1);
  4478. if (this.imageLayer) {
  4479. var position = this.getCanvasPosition(entry.x, entry.y);
  4480. this.imageLayer.appendImage({
  4481. imgData: imgData,
  4482. left: position[0],
  4483. top: position[1],
  4484. width: w,
  4485. height: h
  4486. });
  4487. }
  4488. ctx.restore();
  4489. }
  4490. },
  4491. paintSolidColorImageMask:
  4492. function CanvasGraphics_paintSolidColorImageMask() {
  4493. this.ctx.fillRect(0, 0, 1, 1);
  4494. },
  4495. // Marked content
  4496. markPoint: function CanvasGraphics_markPoint(tag) {
  4497. // TODO Marked content.
  4498. },
  4499. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4500. // TODO Marked content.
  4501. },
  4502. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4503. // TODO Marked content.
  4504. },
  4505. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4506. tag, properties) {
  4507. // TODO Marked content.
  4508. },
  4509. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4510. // TODO Marked content.
  4511. },
  4512. // Compatibility
  4513. beginCompat: function CanvasGraphics_beginCompat() {
  4514. // TODO ignore undefined operators (should we do that anyway?)
  4515. },
  4516. endCompat: function CanvasGraphics_endCompat() {
  4517. // TODO stop ignoring undefined operators
  4518. },
  4519. // Helper functions
  4520. consumePath: function CanvasGraphics_consumePath() {
  4521. var ctx = this.ctx;
  4522. if (this.pendingClip) {
  4523. if (this.pendingClip === EO_CLIP) {
  4524. if (ctx.mozFillRule !== undefined) {
  4525. ctx.mozFillRule = 'evenodd';
  4526. ctx.clip();
  4527. ctx.mozFillRule = 'nonzero';
  4528. } else {
  4529. try {
  4530. ctx.clip('evenodd');
  4531. } catch (ex) {
  4532. // shouldn't really happen, but browsers might think differently
  4533. ctx.clip();
  4534. }
  4535. }
  4536. } else {
  4537. ctx.clip();
  4538. }
  4539. this.pendingClip = null;
  4540. }
  4541. ctx.beginPath();
  4542. },
  4543. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4544. var inverse = this.ctx.mozCurrentTransformInverse;
  4545. // max of the current horizontal and vertical scale
  4546. return Math.sqrt(Math.max(
  4547. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4548. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4549. },
  4550. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4551. var transform = this.ctx.mozCurrentTransform;
  4552. return [
  4553. transform[0] * x + transform[2] * y + transform[4],
  4554. transform[1] * x + transform[3] * y + transform[5]
  4555. ];
  4556. }
  4557. };
  4558. for (var op in OPS) {
  4559. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4560. }
  4561. return CanvasGraphics;
  4562. })();
  4563. var WebGLUtils = (function WebGLUtilsClosure() {
  4564. function loadShader(gl, code, shaderType) {
  4565. var shader = gl.createShader(shaderType);
  4566. gl.shaderSource(shader, code);
  4567. gl.compileShader(shader);
  4568. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4569. if (!compiled) {
  4570. var errorMsg = gl.getShaderInfoLog(shader);
  4571. throw new Error('Error during shader compilation: ' + errorMsg);
  4572. }
  4573. return shader;
  4574. }
  4575. function createVertexShader(gl, code) {
  4576. return loadShader(gl, code, gl.VERTEX_SHADER);
  4577. }
  4578. function createFragmentShader(gl, code) {
  4579. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4580. }
  4581. function createProgram(gl, shaders) {
  4582. var program = gl.createProgram();
  4583. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4584. gl.attachShader(program, shaders[i]);
  4585. }
  4586. gl.linkProgram(program);
  4587. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4588. if (!linked) {
  4589. var errorMsg = gl.getProgramInfoLog(program);
  4590. throw new Error('Error during program linking: ' + errorMsg);
  4591. }
  4592. return program;
  4593. }
  4594. function createTexture(gl, image, textureId) {
  4595. gl.activeTexture(textureId);
  4596. var texture = gl.createTexture();
  4597. gl.bindTexture(gl.TEXTURE_2D, texture);
  4598. // Set the parameters so we can render any size image.
  4599. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4600. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4601. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4602. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4603. // Upload the image into the texture.
  4604. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4605. return texture;
  4606. }
  4607. var currentGL, currentCanvas;
  4608. function generageGL() {
  4609. if (currentGL) {
  4610. return;
  4611. }
  4612. currentCanvas = document.createElement('canvas');
  4613. currentGL = currentCanvas.getContext('webgl',
  4614. { premultipliedalpha: false });
  4615. }
  4616. var smaskVertexShaderCode = '\
  4617. attribute vec2 a_position; \
  4618. attribute vec2 a_texCoord; \
  4619. \
  4620. uniform vec2 u_resolution; \
  4621. \
  4622. varying vec2 v_texCoord; \
  4623. \
  4624. void main() { \
  4625. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4626. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4627. \
  4628. v_texCoord = a_texCoord; \
  4629. } ';
  4630. var smaskFragmentShaderCode = '\
  4631. precision mediump float; \
  4632. \
  4633. uniform vec4 u_backdrop; \
  4634. uniform int u_subtype; \
  4635. uniform sampler2D u_image; \
  4636. uniform sampler2D u_mask; \
  4637. \
  4638. varying vec2 v_texCoord; \
  4639. \
  4640. void main() { \
  4641. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4642. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4643. if (u_backdrop.a > 0.0) { \
  4644. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4645. u_backdrop.rgb * (1.0 - maskColor.a); \
  4646. } \
  4647. float lum; \
  4648. if (u_subtype == 0) { \
  4649. lum = maskColor.a; \
  4650. } else { \
  4651. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4652. maskColor.b * 0.11; \
  4653. } \
  4654. imageColor.a *= lum; \
  4655. imageColor.rgb *= imageColor.a; \
  4656. gl_FragColor = imageColor; \
  4657. } ';
  4658. var smaskCache = null;
  4659. function initSmaskGL() {
  4660. var canvas, gl;
  4661. generageGL();
  4662. canvas = currentCanvas;
  4663. currentCanvas = null;
  4664. gl = currentGL;
  4665. currentGL = null;
  4666. // setup a GLSL program
  4667. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4668. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4669. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4670. gl.useProgram(program);
  4671. var cache = {};
  4672. cache.gl = gl;
  4673. cache.canvas = canvas;
  4674. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4675. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4676. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4677. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4678. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4679. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4680. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4681. // provide texture coordinates for the rectangle.
  4682. var texCoordBuffer = gl.createBuffer();
  4683. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4684. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4685. 0.0, 0.0,
  4686. 1.0, 0.0,
  4687. 0.0, 1.0,
  4688. 0.0, 1.0,
  4689. 1.0, 0.0,
  4690. 1.0, 1.0]), gl.STATIC_DRAW);
  4691. gl.enableVertexAttribArray(texCoordLocation);
  4692. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4693. gl.uniform1i(texLayerLocation, 0);
  4694. gl.uniform1i(texMaskLocation, 1);
  4695. smaskCache = cache;
  4696. }
  4697. function composeSMask(layer, mask, properties) {
  4698. var width = layer.width, height = layer.height;
  4699. if (!smaskCache) {
  4700. initSmaskGL();
  4701. }
  4702. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4703. canvas.width = width;
  4704. canvas.height = height;
  4705. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4706. gl.uniform2f(cache.resolutionLocation, width, height);
  4707. if (properties.backdrop) {
  4708. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4709. properties.backdrop[1], properties.backdrop[2], 1);
  4710. } else {
  4711. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4712. }
  4713. gl.uniform1i(cache.subtypeLocation,
  4714. properties.subtype === 'Luminosity' ? 1 : 0);
  4715. // Create a textures
  4716. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4717. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4718. // Create a buffer and put a single clipspace rectangle in
  4719. // it (2 triangles)
  4720. var buffer = gl.createBuffer();
  4721. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4722. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4723. 0, 0,
  4724. width, 0,
  4725. 0, height,
  4726. 0, height,
  4727. width, 0,
  4728. width, height]), gl.STATIC_DRAW);
  4729. gl.enableVertexAttribArray(cache.positionLocation);
  4730. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4731. // draw
  4732. gl.clearColor(0, 0, 0, 0);
  4733. gl.enable(gl.BLEND);
  4734. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4735. gl.clear(gl.COLOR_BUFFER_BIT);
  4736. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4737. gl.flush();
  4738. gl.deleteTexture(texture);
  4739. gl.deleteTexture(maskTexture);
  4740. gl.deleteBuffer(buffer);
  4741. return canvas;
  4742. }
  4743. var figuresVertexShaderCode = '\
  4744. attribute vec2 a_position; \
  4745. attribute vec3 a_color; \
  4746. \
  4747. uniform vec2 u_resolution; \
  4748. uniform vec2 u_scale; \
  4749. uniform vec2 u_offset; \
  4750. \
  4751. varying vec4 v_color; \
  4752. \
  4753. void main() { \
  4754. vec2 position = (a_position + u_offset) * u_scale; \
  4755. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  4756. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4757. \
  4758. v_color = vec4(a_color / 255.0, 1.0); \
  4759. } ';
  4760. var figuresFragmentShaderCode = '\
  4761. precision mediump float; \
  4762. \
  4763. varying vec4 v_color; \
  4764. \
  4765. void main() { \
  4766. gl_FragColor = v_color; \
  4767. } ';
  4768. var figuresCache = null;
  4769. function initFiguresGL() {
  4770. var canvas, gl;
  4771. generageGL();
  4772. canvas = currentCanvas;
  4773. currentCanvas = null;
  4774. gl = currentGL;
  4775. currentGL = null;
  4776. // setup a GLSL program
  4777. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  4778. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  4779. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4780. gl.useProgram(program);
  4781. var cache = {};
  4782. cache.gl = gl;
  4783. cache.canvas = canvas;
  4784. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4785. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  4786. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  4787. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4788. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  4789. figuresCache = cache;
  4790. }
  4791. function drawFigures(width, height, backgroundColor, figures, context) {
  4792. if (!figuresCache) {
  4793. initFiguresGL();
  4794. }
  4795. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  4796. canvas.width = width;
  4797. canvas.height = height;
  4798. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4799. gl.uniform2f(cache.resolutionLocation, width, height);
  4800. // count triangle points
  4801. var count = 0;
  4802. var i, ii, rows;
  4803. for (i = 0, ii = figures.length; i < ii; i++) {
  4804. switch (figures[i].type) {
  4805. case 'lattice':
  4806. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  4807. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  4808. break;
  4809. case 'triangles':
  4810. count += figures[i].coords.length;
  4811. break;
  4812. }
  4813. }
  4814. // transfer data
  4815. var coords = new Float32Array(count * 2);
  4816. var colors = new Uint8Array(count * 3);
  4817. var coordsMap = context.coords, colorsMap = context.colors;
  4818. var pIndex = 0, cIndex = 0;
  4819. for (i = 0, ii = figures.length; i < ii; i++) {
  4820. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  4821. switch (figure.type) {
  4822. case 'lattice':
  4823. var cols = figure.verticesPerRow;
  4824. rows = (ps.length / cols) | 0;
  4825. for (var row = 1; row < rows; row++) {
  4826. var offset = row * cols + 1;
  4827. for (var col = 1; col < cols; col++, offset++) {
  4828. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  4829. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  4830. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  4831. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  4832. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  4833. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  4834. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  4835. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  4836. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  4837. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  4838. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  4839. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  4840. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  4841. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  4842. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  4843. coords[pIndex + 6] = coords[pIndex + 2];
  4844. coords[pIndex + 7] = coords[pIndex + 3];
  4845. coords[pIndex + 8] = coords[pIndex + 4];
  4846. coords[pIndex + 9] = coords[pIndex + 5];
  4847. coords[pIndex + 10] = coordsMap[ps[offset]];
  4848. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  4849. colors[cIndex + 9] = colors[cIndex + 3];
  4850. colors[cIndex + 10] = colors[cIndex + 4];
  4851. colors[cIndex + 11] = colors[cIndex + 5];
  4852. colors[cIndex + 12] = colors[cIndex + 6];
  4853. colors[cIndex + 13] = colors[cIndex + 7];
  4854. colors[cIndex + 14] = colors[cIndex + 8];
  4855. colors[cIndex + 15] = colorsMap[cs[offset]];
  4856. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  4857. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  4858. pIndex += 12;
  4859. cIndex += 18;
  4860. }
  4861. }
  4862. break;
  4863. case 'triangles':
  4864. for (var j = 0, jj = ps.length; j < jj; j++) {
  4865. coords[pIndex] = coordsMap[ps[j]];
  4866. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  4867. colors[cIndex] = colorsMap[cs[i]];
  4868. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  4869. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  4870. pIndex += 2;
  4871. cIndex += 3;
  4872. }
  4873. break;
  4874. }
  4875. }
  4876. // draw
  4877. if (backgroundColor) {
  4878. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  4879. backgroundColor[2] / 255, 1.0);
  4880. } else {
  4881. gl.clearColor(0, 0, 0, 0);
  4882. }
  4883. gl.clear(gl.COLOR_BUFFER_BIT);
  4884. var coordsBuffer = gl.createBuffer();
  4885. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  4886. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  4887. gl.enableVertexAttribArray(cache.positionLocation);
  4888. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4889. var colorsBuffer = gl.createBuffer();
  4890. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  4891. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  4892. gl.enableVertexAttribArray(cache.colorLocation);
  4893. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  4894. 0, 0);
  4895. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  4896. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  4897. gl.drawArrays(gl.TRIANGLES, 0, count);
  4898. gl.flush();
  4899. gl.deleteBuffer(coordsBuffer);
  4900. gl.deleteBuffer(colorsBuffer);
  4901. return canvas;
  4902. }
  4903. function cleanup() {
  4904. if (smaskCache && smaskCache.canvas) {
  4905. smaskCache.canvas.width = 0;
  4906. smaskCache.canvas.height = 0;
  4907. }
  4908. if (figuresCache && figuresCache.canvas) {
  4909. figuresCache.canvas.width = 0;
  4910. figuresCache.canvas.height = 0;
  4911. }
  4912. smaskCache = null;
  4913. figuresCache = null;
  4914. }
  4915. return {
  4916. get isEnabled() {
  4917. if (PDFJS.disableWebGL) {
  4918. return false;
  4919. }
  4920. var enabled = false;
  4921. try {
  4922. generageGL();
  4923. enabled = !!currentGL;
  4924. } catch (e) { }
  4925. return shadow(this, 'isEnabled', enabled);
  4926. },
  4927. composeSMask: composeSMask,
  4928. drawFigures: drawFigures,
  4929. clear: cleanup
  4930. };
  4931. })();
  4932. var ShadingIRs = {};
  4933. ShadingIRs.RadialAxial = {
  4934. fromIR: function RadialAxial_fromIR(raw) {
  4935. var type = raw[1];
  4936. var colorStops = raw[2];
  4937. var p0 = raw[3];
  4938. var p1 = raw[4];
  4939. var r0 = raw[5];
  4940. var r1 = raw[6];
  4941. return {
  4942. type: 'Pattern',
  4943. getPattern: function RadialAxial_getPattern(ctx) {
  4944. var grad;
  4945. if (type === 'axial') {
  4946. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  4947. } else if (type === 'radial') {
  4948. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  4949. }
  4950. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  4951. var c = colorStops[i];
  4952. grad.addColorStop(c[0], c[1]);
  4953. }
  4954. return grad;
  4955. }
  4956. };
  4957. }
  4958. };
  4959. var createMeshCanvas = (function createMeshCanvasClosure() {
  4960. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  4961. // Very basic Gouraud-shaded triangle rasterization algorithm.
  4962. var coords = context.coords, colors = context.colors;
  4963. var bytes = data.data, rowSize = data.width * 4;
  4964. var tmp;
  4965. if (coords[p1 + 1] > coords[p2 + 1]) {
  4966. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4967. }
  4968. if (coords[p2 + 1] > coords[p3 + 1]) {
  4969. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  4970. }
  4971. if (coords[p1 + 1] > coords[p2 + 1]) {
  4972. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4973. }
  4974. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  4975. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  4976. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  4977. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  4978. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  4979. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  4980. if (y1 >= y3) {
  4981. return;
  4982. }
  4983. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  4984. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  4985. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  4986. var minY = Math.round(y1), maxY = Math.round(y3);
  4987. var xa, car, cag, cab;
  4988. var xb, cbr, cbg, cbb;
  4989. var k;
  4990. for (var y = minY; y <= maxY; y++) {
  4991. if (y < y2) {
  4992. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  4993. xa = x1 - (x1 - x2) * k;
  4994. car = c1r - (c1r - c2r) * k;
  4995. cag = c1g - (c1g - c2g) * k;
  4996. cab = c1b - (c1b - c2b) * k;
  4997. } else {
  4998. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  4999. xa = x2 - (x2 - x3) * k;
  5000. car = c2r - (c2r - c3r) * k;
  5001. cag = c2g - (c2g - c3g) * k;
  5002. cab = c2b - (c2b - c3b) * k;
  5003. }
  5004. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5005. xb = x1 - (x1 - x3) * k;
  5006. cbr = c1r - (c1r - c3r) * k;
  5007. cbg = c1g - (c1g - c3g) * k;
  5008. cbb = c1b - (c1b - c3b) * k;
  5009. var x1_ = Math.round(Math.min(xa, xb));
  5010. var x2_ = Math.round(Math.max(xa, xb));
  5011. var j = rowSize * y + x1_ * 4;
  5012. for (var x = x1_; x <= x2_; x++) {
  5013. k = (xa - x) / (xa - xb);
  5014. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5015. bytes[j++] = (car - (car - cbr) * k) | 0;
  5016. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5017. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5018. bytes[j++] = 255;
  5019. }
  5020. }
  5021. }
  5022. function drawFigure(data, figure, context) {
  5023. var ps = figure.coords;
  5024. var cs = figure.colors;
  5025. var i, ii;
  5026. switch (figure.type) {
  5027. case 'lattice':
  5028. var verticesPerRow = figure.verticesPerRow;
  5029. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5030. var cols = verticesPerRow - 1;
  5031. for (i = 0; i < rows; i++) {
  5032. var q = i * verticesPerRow;
  5033. for (var j = 0; j < cols; j++, q++) {
  5034. drawTriangle(data, context,
  5035. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5036. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5037. drawTriangle(data, context,
  5038. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5039. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5040. }
  5041. }
  5042. break;
  5043. case 'triangles':
  5044. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5045. drawTriangle(data, context,
  5046. ps[i], ps[i + 1], ps[i + 2],
  5047. cs[i], cs[i + 1], cs[i + 2]);
  5048. }
  5049. break;
  5050. default:
  5051. error('illigal figure');
  5052. break;
  5053. }
  5054. }
  5055. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5056. backgroundColor) {
  5057. // we will increase scale on some weird factor to let antialiasing take
  5058. // care of "rough" edges
  5059. var EXPECTED_SCALE = 1.1;
  5060. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5061. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5062. var offsetX = Math.floor(bounds[0]);
  5063. var offsetY = Math.floor(bounds[1]);
  5064. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5065. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5066. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5067. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5068. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5069. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5070. var scaleX = boundsWidth / width;
  5071. var scaleY = boundsHeight / height;
  5072. var context = {
  5073. coords: coords,
  5074. colors: colors,
  5075. offsetX: -offsetX,
  5076. offsetY: -offsetY,
  5077. scaleX: 1 / scaleX,
  5078. scaleY: 1 / scaleY
  5079. };
  5080. var canvas, tmpCanvas, i, ii;
  5081. if (WebGLUtils.isEnabled) {
  5082. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5083. figures, context);
  5084. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5085. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5086. tmpCanvas.context.drawImage(canvas, 0, 0);
  5087. canvas = tmpCanvas.canvas;
  5088. } else {
  5089. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5090. var tmpCtx = tmpCanvas.context;
  5091. var data = tmpCtx.createImageData(width, height);
  5092. if (backgroundColor) {
  5093. var bytes = data.data;
  5094. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5095. bytes[i] = backgroundColor[0];
  5096. bytes[i + 1] = backgroundColor[1];
  5097. bytes[i + 2] = backgroundColor[2];
  5098. bytes[i + 3] = 255;
  5099. }
  5100. }
  5101. for (i = 0; i < figures.length; i++) {
  5102. drawFigure(data, figures[i], context);
  5103. }
  5104. tmpCtx.putImageData(data, 0, 0);
  5105. canvas = tmpCanvas.canvas;
  5106. }
  5107. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5108. scaleX: scaleX, scaleY: scaleY};
  5109. }
  5110. return createMeshCanvas;
  5111. })();
  5112. ShadingIRs.Mesh = {
  5113. fromIR: function Mesh_fromIR(raw) {
  5114. //var type = raw[1];
  5115. var coords = raw[2];
  5116. var colors = raw[3];
  5117. var figures = raw[4];
  5118. var bounds = raw[5];
  5119. var matrix = raw[6];
  5120. //var bbox = raw[7];
  5121. var background = raw[8];
  5122. return {
  5123. type: 'Pattern',
  5124. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5125. var scale;
  5126. if (shadingFill) {
  5127. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5128. } else {
  5129. // Obtain scale from matrix and current transformation matrix.
  5130. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5131. if (matrix) {
  5132. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5133. scale = [scale[0] * matrixScale[0],
  5134. scale[1] * matrixScale[1]];
  5135. }
  5136. }
  5137. // Rasterizing on the main thread since sending/queue large canvases
  5138. // might cause OOM.
  5139. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5140. colors, figures, shadingFill ? null : background);
  5141. if (!shadingFill) {
  5142. ctx.setTransform.apply(ctx, owner.baseTransform);
  5143. if (matrix) {
  5144. ctx.transform.apply(ctx, matrix);
  5145. }
  5146. }
  5147. ctx.translate(temporaryPatternCanvas.offsetX,
  5148. temporaryPatternCanvas.offsetY);
  5149. ctx.scale(temporaryPatternCanvas.scaleX,
  5150. temporaryPatternCanvas.scaleY);
  5151. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5152. }
  5153. };
  5154. }
  5155. };
  5156. ShadingIRs.Dummy = {
  5157. fromIR: function Dummy_fromIR() {
  5158. return {
  5159. type: 'Pattern',
  5160. getPattern: function Dummy_fromIR_getPattern() {
  5161. return 'hotpink';
  5162. }
  5163. };
  5164. }
  5165. };
  5166. function getShadingPatternFromIR(raw) {
  5167. var shadingIR = ShadingIRs[raw[0]];
  5168. if (!shadingIR) {
  5169. error('Unknown IR type: ' + raw[0]);
  5170. }
  5171. return shadingIR.fromIR(raw);
  5172. }
  5173. var TilingPattern = (function TilingPatternClosure() {
  5174. var PaintType = {
  5175. COLORED: 1,
  5176. UNCOLORED: 2
  5177. };
  5178. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5179. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5180. this.operatorList = IR[2];
  5181. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5182. this.bbox = IR[4];
  5183. this.xstep = IR[5];
  5184. this.ystep = IR[6];
  5185. this.paintType = IR[7];
  5186. this.tilingType = IR[8];
  5187. this.color = color;
  5188. this.objs = objs;
  5189. this.commonObjs = commonObjs;
  5190. this.baseTransform = baseTransform;
  5191. this.type = 'Pattern';
  5192. this.ctx = ctx;
  5193. }
  5194. TilingPattern.prototype = {
  5195. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5196. var operatorList = this.operatorList;
  5197. var bbox = this.bbox;
  5198. var xstep = this.xstep;
  5199. var ystep = this.ystep;
  5200. var paintType = this.paintType;
  5201. var tilingType = this.tilingType;
  5202. var color = this.color;
  5203. var objs = this.objs;
  5204. var commonObjs = this.commonObjs;
  5205. info('TilingType: ' + tilingType);
  5206. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5207. var topLeft = [x0, y0];
  5208. // we want the canvas to be as large as the step size
  5209. var botRight = [x0 + xstep, y0 + ystep];
  5210. var width = botRight[0] - topLeft[0];
  5211. var height = botRight[1] - topLeft[1];
  5212. // Obtain scale from matrix and current transformation matrix.
  5213. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5214. var curMatrixScale = Util.singularValueDecompose2dScale(
  5215. this.baseTransform);
  5216. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5217. matrixScale[1] * curMatrixScale[1]];
  5218. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5219. // Use width and height values that are as close as possible to the end
  5220. // result when the pattern is used. Too low value makes the pattern look
  5221. // blurry. Too large value makes it look too crispy.
  5222. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5223. MAX_PATTERN_SIZE);
  5224. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5225. MAX_PATTERN_SIZE);
  5226. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5227. var tmpCtx = tmpCanvas.context;
  5228. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5229. graphics.groupLevel = owner.groupLevel;
  5230. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5231. this.setScale(width, height, xstep, ystep);
  5232. this.transformToScale(graphics);
  5233. // transform coordinates to pattern space
  5234. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5235. graphics.transform.apply(graphics, tmpTranslate);
  5236. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5237. graphics.executeOperatorList(operatorList);
  5238. return tmpCanvas.canvas;
  5239. },
  5240. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5241. this.scale = [width / xstep, height / ystep];
  5242. },
  5243. transformToScale: function TilingPattern_transformToScale(graphics) {
  5244. var scale = this.scale;
  5245. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5246. graphics.transform.apply(graphics, tmpScale);
  5247. },
  5248. scaleToContext: function TilingPattern_scaleToContext() {
  5249. var scale = this.scale;
  5250. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5251. },
  5252. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5253. if (bbox && isArray(bbox) && bbox.length === 4) {
  5254. var bboxWidth = x1 - x0;
  5255. var bboxHeight = y1 - y0;
  5256. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5257. graphics.clip();
  5258. graphics.endPath();
  5259. }
  5260. },
  5261. setFillAndStrokeStyleToContext:
  5262. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5263. switch (paintType) {
  5264. case PaintType.COLORED:
  5265. var ctx = this.ctx;
  5266. context.fillStyle = ctx.fillStyle;
  5267. context.strokeStyle = ctx.strokeStyle;
  5268. break;
  5269. case PaintType.UNCOLORED:
  5270. var cssColor = Util.makeCssRgb(color);
  5271. context.fillStyle = cssColor;
  5272. context.strokeStyle = cssColor;
  5273. break;
  5274. default:
  5275. error('Unsupported paint type: ' + paintType);
  5276. }
  5277. },
  5278. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5279. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5280. ctx = this.ctx;
  5281. ctx.setTransform.apply(ctx, this.baseTransform);
  5282. ctx.transform.apply(ctx, this.matrix);
  5283. this.scaleToContext();
  5284. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5285. }
  5286. };
  5287. return TilingPattern;
  5288. })();
  5289. PDFJS.disableFontFace = false;
  5290. var FontLoader = {
  5291. insertRule: function fontLoaderInsertRule(rule) {
  5292. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5293. if (!styleElement) {
  5294. styleElement = document.createElement('style');
  5295. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5296. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5297. styleElement);
  5298. }
  5299. var styleSheet = styleElement.sheet;
  5300. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5301. },
  5302. clear: function fontLoaderClear() {
  5303. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5304. if (styleElement) {
  5305. styleElement.parentNode.removeChild(styleElement);
  5306. }
  5307. },
  5308. get loadTestFont() {
  5309. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5310. // height.
  5311. return shadow(this, 'loadTestFont', atob(
  5312. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5313. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5314. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5315. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5316. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5317. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5318. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5319. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5320. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5321. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5322. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5323. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5324. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5325. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5326. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5327. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5328. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5329. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5330. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5331. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5332. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5333. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5334. ));
  5335. },
  5336. loadTestFontId: 0,
  5337. loadingContext: {
  5338. requests: [],
  5339. nextRequestId: 0
  5340. },
  5341. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5342. if (isWorker) {
  5343. return false;
  5344. }
  5345. // User agent string sniffing is bad, but there is no reliable way to tell
  5346. // if font is fully loaded and ready to be used with canvas.
  5347. var userAgent = window.navigator.userAgent;
  5348. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5349. if (m && m[1] >= 14) {
  5350. return true;
  5351. }
  5352. // TODO other browsers
  5353. if (userAgent === 'node') {
  5354. return true;
  5355. }
  5356. return false;
  5357. })(),
  5358. bind: function fontLoaderBind(fonts, callback) {
  5359. assert(!isWorker, 'bind() shall be called from main thread');
  5360. var rules = [], fontsToLoad = [];
  5361. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5362. var font = fonts[i];
  5363. // Add the font to the DOM only once or skip if the font
  5364. // is already loaded.
  5365. if (font.attached || font.loading === false) {
  5366. continue;
  5367. }
  5368. font.attached = true;
  5369. var rule = font.bindDOM();
  5370. if (rule) {
  5371. rules.push(rule);
  5372. fontsToLoad.push(font);
  5373. }
  5374. }
  5375. var request = FontLoader.queueLoadingCallback(callback);
  5376. if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5377. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5378. } else {
  5379. request.complete();
  5380. }
  5381. },
  5382. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5383. function LoadLoader_completeRequest() {
  5384. assert(!request.end, 'completeRequest() cannot be called twice');
  5385. request.end = Date.now();
  5386. // sending all completed requests in order how they were queued
  5387. while (context.requests.length > 0 && context.requests[0].end) {
  5388. var otherRequest = context.requests.shift();
  5389. setTimeout(otherRequest.callback, 0);
  5390. }
  5391. }
  5392. var context = FontLoader.loadingContext;
  5393. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5394. var request = {
  5395. id: requestId,
  5396. complete: LoadLoader_completeRequest,
  5397. callback: callback,
  5398. started: Date.now()
  5399. };
  5400. context.requests.push(request);
  5401. return request;
  5402. },
  5403. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5404. fonts,
  5405. request) {
  5406. /** Hack begin */
  5407. // There's currently no event when a font has finished downloading so the
  5408. // following code is a dirty hack to 'guess' when a font is
  5409. // ready. It's assumed fonts are loaded in order, so add a known test
  5410. // font after the desired fonts and then test for the loading of that
  5411. // test font.
  5412. function int32(data, offset) {
  5413. return (data.charCodeAt(offset) << 24) |
  5414. (data.charCodeAt(offset + 1) << 16) |
  5415. (data.charCodeAt(offset + 2) << 8) |
  5416. (data.charCodeAt(offset + 3) & 0xff);
  5417. }
  5418. function spliceString(s, offset, remove, insert) {
  5419. var chunk1 = s.substr(0, offset);
  5420. var chunk2 = s.substr(offset + remove);
  5421. return chunk1 + insert + chunk2;
  5422. }
  5423. var i, ii;
  5424. var canvas = document.createElement('canvas');
  5425. canvas.width = 1;
  5426. canvas.height = 1;
  5427. var ctx = canvas.getContext('2d');
  5428. var called = 0;
  5429. function isFontReady(name, callback) {
  5430. called++;
  5431. // With setTimeout clamping this gives the font ~100ms to load.
  5432. if(called > 30) {
  5433. warn('Load test font never loaded.');
  5434. callback();
  5435. return;
  5436. }
  5437. ctx.font = '30px ' + name;
  5438. ctx.fillText('.', 0, 20);
  5439. var imageData = ctx.getImageData(0, 0, 1, 1);
  5440. if (imageData.data[3] > 0) {
  5441. callback();
  5442. return;
  5443. }
  5444. setTimeout(isFontReady.bind(null, name, callback));
  5445. }
  5446. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5447. // Chromium seems to cache fonts based on a hash of the actual font data,
  5448. // so the font must be modified for each load test else it will appear to
  5449. // be loaded already.
  5450. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5451. // font by splitting it in chunks before hand and padding the font id.
  5452. var data = this.loadTestFont;
  5453. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5454. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5455. loadTestFontId);
  5456. // CFF checksum is important for IE, adjusting it
  5457. var CFF_CHECKSUM_OFFSET = 16;
  5458. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5459. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5460. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5461. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5462. }
  5463. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5464. checksum = (checksum - XXXX_VALUE +
  5465. int32(loadTestFontId + 'XXX', i)) | 0;
  5466. }
  5467. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5468. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5469. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5470. url + '}';
  5471. FontLoader.insertRule(rule);
  5472. var names = [];
  5473. for (i = 0, ii = fonts.length; i < ii; i++) {
  5474. names.push(fonts[i].loadedName);
  5475. }
  5476. names.push(loadTestFontId);
  5477. var div = document.createElement('div');
  5478. div.setAttribute('style',
  5479. 'visibility: hidden;' +
  5480. 'width: 10px; height: 10px;' +
  5481. 'position: absolute; top: 0px; left: 0px;');
  5482. for (i = 0, ii = names.length; i < ii; ++i) {
  5483. var span = document.createElement('span');
  5484. span.textContent = 'Hi';
  5485. span.style.fontFamily = names[i];
  5486. div.appendChild(span);
  5487. }
  5488. document.body.appendChild(div);
  5489. isFontReady(loadTestFontId, function() {
  5490. document.body.removeChild(div);
  5491. request.complete();
  5492. });
  5493. /** Hack end */
  5494. }
  5495. };
  5496. var FontFace = (function FontFaceClosure() {
  5497. function FontFace(name, file, properties) {
  5498. this.compiledGlyphs = {};
  5499. if (arguments.length === 1) {
  5500. // importing translated data
  5501. var data = arguments[0];
  5502. for (var i in data) {
  5503. this[i] = data[i];
  5504. }
  5505. return;
  5506. }
  5507. }
  5508. FontFace.prototype = {
  5509. bindDOM: function FontFace_bindDOM() {
  5510. if (!this.data) {
  5511. return null;
  5512. }
  5513. if (PDFJS.disableFontFace) {
  5514. this.disableFontFace = true;
  5515. return null;
  5516. }
  5517. var data = bytesToString(new Uint8Array(this.data));
  5518. var fontName = this.loadedName;
  5519. // Add the font-face rule to the document
  5520. var url = ('url(data:' + this.mimetype + ';base64,' +
  5521. window.btoa(data) + ');');
  5522. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5523. FontLoader.insertRule(rule);
  5524. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5525. globalScope['FontInspector'].enabled) {
  5526. globalScope['FontInspector'].fontAdded(this, url);
  5527. }
  5528. return rule;
  5529. },
  5530. getPathGenerator: function (objs, character) {
  5531. if (!(character in this.compiledGlyphs)) {
  5532. var js = objs.get(this.loadedName + '_path_' + character);
  5533. /*jshint -W054 */
  5534. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5535. }
  5536. return this.compiledGlyphs[character];
  5537. }
  5538. };
  5539. return FontFace;
  5540. })();
  5541. var HIGHLIGHT_OFFSET = 4; // px
  5542. var ANNOT_MIN_SIZE = 10; // px
  5543. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5544. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5545. function setTextStyles(element, item, fontObj) {
  5546. var style = element.style;
  5547. style.fontSize = item.fontSize + 'px';
  5548. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5549. if (!fontObj) {
  5550. return;
  5551. }
  5552. style.fontWeight = fontObj.black ?
  5553. (fontObj.bold ? 'bolder' : 'bold') :
  5554. (fontObj.bold ? 'bold' : 'normal');
  5555. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5556. var fontName = fontObj.loadedName;
  5557. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5558. // Use a reasonable default font if the font doesn't specify a fallback
  5559. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5560. style.fontFamily = fontFamily + fallbackName;
  5561. }
  5562. // TODO(mack): Remove this, it's not really that helpful.
  5563. function getEmptyContainer(tagName, rect, borderWidth) {
  5564. var bWidth = borderWidth || 0;
  5565. var element = document.createElement(tagName);
  5566. element.style.borderWidth = bWidth + 'px';
  5567. var width = rect[2] - rect[0] - 2 * bWidth;
  5568. var height = rect[3] - rect[1] - 2 * bWidth;
  5569. element.style.width = width + 'px';
  5570. element.style.height = height + 'px';
  5571. return element;
  5572. }
  5573. function initContainer(item) {
  5574. var container = getEmptyContainer('section', item.rect, item.borderWidth);
  5575. container.style.backgroundColor = item.color;
  5576. var color = item.color;
  5577. var rgb = [];
  5578. for (var i = 0; i < 3; ++i) {
  5579. rgb[i] = Math.round(color[i] * 255);
  5580. }
  5581. item.colorCssRgb = Util.makeCssRgb(rgb);
  5582. var highlight = document.createElement('div');
  5583. highlight.className = 'annotationHighlight';
  5584. highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
  5585. highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
  5586. highlight.setAttribute('hidden', true);
  5587. item.highlightElement = highlight;
  5588. container.appendChild(item.highlightElement);
  5589. return container;
  5590. }
  5591. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5592. var element = getEmptyContainer('div', item.rect, 0);
  5593. element.style.display = 'table';
  5594. var content = document.createElement('div');
  5595. content.textContent = item.fieldValue;
  5596. var textAlignment = item.textAlignment;
  5597. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5598. content.style.verticalAlign = 'middle';
  5599. content.style.display = 'table-cell';
  5600. var fontObj = item.fontRefName ?
  5601. commonObjs.getData(item.fontRefName) : null;
  5602. setTextStyles(content, item, fontObj);
  5603. element.appendChild(content);
  5604. return element;
  5605. }
  5606. function getHtmlElementForTextAnnotation(item) {
  5607. var rect = item.rect;
  5608. // sanity check because of OOo-generated PDFs
  5609. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5610. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5611. }
  5612. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5613. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5614. }
  5615. var container = initContainer(item);
  5616. container.className = 'annotText';
  5617. var image = document.createElement('img');
  5618. image.style.height = container.style.height;
  5619. image.style.width = container.style.width;
  5620. var iconName = item.name;
  5621. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5622. iconName.toLowerCase() + '.svg';
  5623. image.alt = '[{{type}} Annotation]';
  5624. image.dataset.l10nId = 'text_annotation_type';
  5625. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5626. var contentWrapper = document.createElement('div');
  5627. contentWrapper.className = 'annotTextContentWrapper';
  5628. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5629. contentWrapper.style.top = '-10px';
  5630. var content = document.createElement('div');
  5631. content.className = 'annotTextContent';
  5632. content.setAttribute('hidden', true);
  5633. var i, ii;
  5634. if (item.hasBgColor) {
  5635. var color = item.color;
  5636. var rgb = [];
  5637. for (i = 0; i < 3; ++i) {
  5638. // Enlighten the color (70%)
  5639. var c = Math.round(color[i] * 255);
  5640. rgb[i] = Math.round((255 - c) * 0.7) + c;
  5641. }
  5642. content.style.backgroundColor = Util.makeCssRgb(rgb);
  5643. }
  5644. var title = document.createElement('h1');
  5645. var text = document.createElement('p');
  5646. title.textContent = item.title;
  5647. if (!item.content && !item.title) {
  5648. content.setAttribute('hidden', true);
  5649. } else {
  5650. var e = document.createElement('span');
  5651. var lines = item.content.split(/(?:\r\n?|\n)/);
  5652. for (i = 0, ii = lines.length; i < ii; ++i) {
  5653. var line = lines[i];
  5654. e.appendChild(document.createTextNode(line));
  5655. if (i < (ii - 1)) {
  5656. e.appendChild(document.createElement('br'));
  5657. }
  5658. }
  5659. text.appendChild(e);
  5660. var pinned = false;
  5661. var showAnnotation = function showAnnotation(pin) {
  5662. if (pin) {
  5663. pinned = true;
  5664. }
  5665. if (content.hasAttribute('hidden')) {
  5666. container.style.zIndex += 1;
  5667. content.removeAttribute('hidden');
  5668. }
  5669. };
  5670. var hideAnnotation = function hideAnnotation(unpin) {
  5671. if (unpin) {
  5672. pinned = false;
  5673. }
  5674. if (!content.hasAttribute('hidden') && !pinned) {
  5675. container.style.zIndex -= 1;
  5676. content.setAttribute('hidden', true);
  5677. }
  5678. };
  5679. var toggleAnnotation = function toggleAnnotation() {
  5680. if (pinned) {
  5681. hideAnnotation(true);
  5682. } else {
  5683. showAnnotation(true);
  5684. }
  5685. };
  5686. image.addEventListener('click', function image_clickHandler() {
  5687. toggleAnnotation();
  5688. }, false);
  5689. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5690. showAnnotation();
  5691. }, false);
  5692. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5693. hideAnnotation();
  5694. }, false);
  5695. content.addEventListener('click', function content_clickHandler() {
  5696. hideAnnotation(true);
  5697. }, false);
  5698. }
  5699. content.appendChild(title);
  5700. content.appendChild(text);
  5701. contentWrapper.appendChild(content);
  5702. container.appendChild(image);
  5703. container.appendChild(contentWrapper);
  5704. return container;
  5705. }
  5706. function getHtmlElementForLinkAnnotation(item) {
  5707. var container = initContainer(item);
  5708. container.className = 'annotLink';
  5709. container.style.borderColor = item.colorCssRgb;
  5710. container.style.borderStyle = 'solid';
  5711. var link = document.createElement('a');
  5712. link.href = link.title = item.url || '';
  5713. container.appendChild(link);
  5714. return container;
  5715. }
  5716. function getHtmlElement(data, objs) {
  5717. switch (data.annotationType) {
  5718. case AnnotationType.WIDGET:
  5719. return getHtmlElementForTextWidgetAnnotation(data, objs);
  5720. case AnnotationType.TEXT:
  5721. return getHtmlElementForTextAnnotation(data);
  5722. case AnnotationType.LINK:
  5723. return getHtmlElementForLinkAnnotation(data);
  5724. default:
  5725. throw new Error('Unsupported annotationType: ' + data.annotationType);
  5726. }
  5727. }
  5728. return {
  5729. getHtmlElement: getHtmlElement
  5730. };
  5731. })();
  5732. PDFJS.AnnotationUtils = AnnotationUtils;
  5733. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  5734. var PNG_HEADER =
  5735. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  5736. var CHUNK_WRAPPER_SIZE = 12;
  5737. var crcTable = new Int32Array(256);
  5738. for (var i = 0; i < 256; i++) {
  5739. var c = i;
  5740. for (var h = 0; h < 8; h++) {
  5741. if (c & 1) {
  5742. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  5743. } else {
  5744. c = (c >> 1) & 0x7fffffff;
  5745. }
  5746. }
  5747. crcTable[i] = c;
  5748. }
  5749. function crc32(data, start, end) {
  5750. var crc = -1;
  5751. for (var i = start; i < end; i++) {
  5752. var a = (crc ^ data[i]) & 0xff;
  5753. var b = crcTable[a];
  5754. crc = (crc >>> 8) ^ b;
  5755. }
  5756. return crc ^ -1;
  5757. }
  5758. function writePngChunk(type, body, data, offset) {
  5759. var p = offset;
  5760. var len = body.length;
  5761. data[p] = len >> 24 & 0xff;
  5762. data[p + 1] = len >> 16 & 0xff;
  5763. data[p + 2] = len >> 8 & 0xff;
  5764. data[p + 3] = len & 0xff;
  5765. p += 4;
  5766. data[p] = type.charCodeAt(0) & 0xff;
  5767. data[p + 1] = type.charCodeAt(1) & 0xff;
  5768. data[p + 2] = type.charCodeAt(2) & 0xff;
  5769. data[p + 3] = type.charCodeAt(3) & 0xff;
  5770. p += 4;
  5771. data.set(body, p);
  5772. p += body.length;
  5773. var crc = crc32(data, offset + 4, p);
  5774. data[p] = crc >> 24 & 0xff;
  5775. data[p + 1] = crc >> 16 & 0xff;
  5776. data[p + 2] = crc >> 8 & 0xff;
  5777. data[p + 3] = crc & 0xff;
  5778. }
  5779. function adler32(data, start, end) {
  5780. var a = 1;
  5781. var b = 0;
  5782. for (var i = start; i < end; ++i) {
  5783. a = (a + (data[i] & 0xff)) % 65521;
  5784. b = (b + a) % 65521;
  5785. }
  5786. return (b << 16) | a;
  5787. }
  5788. function encode(imgData, kind) {
  5789. var width = imgData.width;
  5790. var height = imgData.height;
  5791. var bitDepth, colorType, lineSize;
  5792. var bytes = imgData.data;
  5793. switch (kind) {
  5794. case ImageKind.GRAYSCALE_1BPP:
  5795. colorType = 0;
  5796. bitDepth = 1;
  5797. lineSize = (width + 7) >> 3;
  5798. break;
  5799. case ImageKind.RGB_24BPP:
  5800. colorType = 2;
  5801. bitDepth = 8;
  5802. lineSize = width * 3;
  5803. break;
  5804. case ImageKind.RGBA_32BPP:
  5805. colorType = 6;
  5806. bitDepth = 8;
  5807. lineSize = width * 4;
  5808. break;
  5809. default:
  5810. throw new Error('invalid format');
  5811. }
  5812. // prefix every row with predictor 0
  5813. var literals = new Uint8Array((1 + lineSize) * height);
  5814. var offsetLiterals = 0, offsetBytes = 0;
  5815. var y, i;
  5816. for (y = 0; y < height; ++y) {
  5817. literals[offsetLiterals++] = 0; // no prediction
  5818. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  5819. offsetLiterals);
  5820. offsetBytes += lineSize;
  5821. offsetLiterals += lineSize;
  5822. }
  5823. if (kind === ImageKind.GRAYSCALE_1BPP) {
  5824. // inverting for B/W
  5825. offsetLiterals = 0;
  5826. for (y = 0; y < height; y++) {
  5827. offsetLiterals++; // skipping predictor
  5828. for (i = 0; i < lineSize; i++) {
  5829. literals[offsetLiterals++] ^= 0xFF;
  5830. }
  5831. }
  5832. }
  5833. var ihdr = new Uint8Array([
  5834. width >> 24 & 0xff,
  5835. width >> 16 & 0xff,
  5836. width >> 8 & 0xff,
  5837. width & 0xff,
  5838. height >> 24 & 0xff,
  5839. height >> 16 & 0xff,
  5840. height >> 8 & 0xff,
  5841. height & 0xff,
  5842. bitDepth, // bit depth
  5843. colorType, // color type
  5844. 0x00, // compression method
  5845. 0x00, // filter method
  5846. 0x00 // interlace method
  5847. ]);
  5848. var len = literals.length;
  5849. var maxBlockLength = 0xFFFF;
  5850. var deflateBlocks = Math.ceil(len / maxBlockLength);
  5851. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  5852. var pi = 0;
  5853. idat[pi++] = 0x78; // compression method and flags
  5854. idat[pi++] = 0x9c; // flags
  5855. var pos = 0;
  5856. while (len > maxBlockLength) {
  5857. // writing non-final DEFLATE blocks type 0 and length of 65535
  5858. idat[pi++] = 0x00;
  5859. idat[pi++] = 0xff;
  5860. idat[pi++] = 0xff;
  5861. idat[pi++] = 0x00;
  5862. idat[pi++] = 0x00;
  5863. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  5864. pi += maxBlockLength;
  5865. pos += maxBlockLength;
  5866. len -= maxBlockLength;
  5867. }
  5868. // writing non-final DEFLATE blocks type 0
  5869. idat[pi++] = 0x01;
  5870. idat[pi++] = len & 0xff;
  5871. idat[pi++] = len >> 8 & 0xff;
  5872. idat[pi++] = (~len & 0xffff) & 0xff;
  5873. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  5874. idat.set(literals.subarray(pos), pi);
  5875. pi += literals.length - pos;
  5876. var adler = adler32(literals, 0, literals.length); // checksum
  5877. idat[pi++] = adler >> 24 & 0xff;
  5878. idat[pi++] = adler >> 16 & 0xff;
  5879. idat[pi++] = adler >> 8 & 0xff;
  5880. idat[pi++] = adler & 0xff;
  5881. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  5882. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  5883. ihdr.length + idat.length;
  5884. var data = new Uint8Array(pngLength);
  5885. var offset = 0;
  5886. data.set(PNG_HEADER, offset);
  5887. offset += PNG_HEADER.length;
  5888. writePngChunk('IHDR', ihdr, data, offset);
  5889. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  5890. writePngChunk('IDATA', idat, data, offset);
  5891. offset += CHUNK_WRAPPER_SIZE + idat.length;
  5892. writePngChunk('IEND', new Uint8Array(0), data, offset);
  5893. return PDFJS.createObjectURL(data, 'image/png');
  5894. }
  5895. return function convertImgDataToPng(imgData) {
  5896. var kind = (imgData.kind === undefined ?
  5897. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  5898. return encode(imgData, kind);
  5899. };
  5900. })();
  5901. var SVGExtraState = (function SVGExtraStateClosure() {
  5902. function SVGExtraState() {
  5903. this.fontSizeScale = 1;
  5904. this.fontWeight = 'normal';
  5905. this.fontSize = 0;
  5906. this.textMatrix = IDENTITY_MATRIX;
  5907. this.fontMatrix = FONT_IDENTITY_MATRIX;
  5908. this.leading = 0;
  5909. // Current point (in user coordinates)
  5910. this.x = 0;
  5911. this.y = 0;
  5912. // Start of text line (in text coordinates)
  5913. this.lineX = 0;
  5914. this.lineY = 0;
  5915. // Character and word spacing
  5916. this.charSpacing = 0;
  5917. this.wordSpacing = 0;
  5918. this.textHScale = 1;
  5919. this.textRise = 0;
  5920. // Default foreground and background colors
  5921. this.fillColor = '#000000';
  5922. this.strokeColor = '#000000';
  5923. this.fillAlpha = 1;
  5924. this.strokeAlpha = 1;
  5925. this.lineWidth = 1;
  5926. this.lineJoin = '';
  5927. this.lineCap = '';
  5928. this.miterLimit = 0;
  5929. this.dashArray = [];
  5930. this.dashPhase = 0;
  5931. this.dependencies = [];
  5932. // Clipping
  5933. this.clipId = '';
  5934. this.pendingClip = false;
  5935. this.maskId = '';
  5936. }
  5937. SVGExtraState.prototype = {
  5938. clone: function SVGExtraState_clone() {
  5939. return Object.create(this);
  5940. },
  5941. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  5942. this.x = x;
  5943. this.y = y;
  5944. }
  5945. };
  5946. return SVGExtraState;
  5947. })();
  5948. var SVGGraphics = (function SVGGraphicsClosure() {
  5949. function createScratchSVG(width, height) {
  5950. var NS = 'http://www.w3.org/2000/svg';
  5951. var svg = document.createElementNS(NS, 'svg:svg');
  5952. svg.setAttributeNS(null, 'version', '1.1');
  5953. svg.setAttributeNS(null, 'width', width + 'px');
  5954. svg.setAttributeNS(null, 'height', height + 'px');
  5955. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  5956. return svg;
  5957. }
  5958. function opListToTree(opList) {
  5959. var opTree = [];
  5960. var tmp = [];
  5961. var opListLen = opList.length;
  5962. for (var x = 0; x < opListLen; x++) {
  5963. if (opList[x].fn === 'save') {
  5964. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  5965. tmp.push(opTree);
  5966. opTree = opTree[opTree.length - 1].items;
  5967. continue;
  5968. }
  5969. if(opList[x].fn === 'restore') {
  5970. opTree = tmp.pop();
  5971. } else {
  5972. opTree.push(opList[x]);
  5973. }
  5974. }
  5975. return opTree;
  5976. }
  5977. /**
  5978. * Formats float number.
  5979. * @param value {number} number to format.
  5980. * @returns {string}
  5981. */
  5982. function pf(value) {
  5983. if (value === (value | 0)) { // integer number
  5984. return value.toString();
  5985. }
  5986. var s = value.toFixed(10);
  5987. var i = s.length - 1;
  5988. if (s[i] !== '0') {
  5989. return s;
  5990. }
  5991. // removing trailing zeros
  5992. do {
  5993. i--;
  5994. } while (s[i] === '0');
  5995. return s.substr(0, s[i] === '.' ? i : i + 1);
  5996. }
  5997. /**
  5998. * Formats transform matrix. The standard rotation, scale and translate
  5999. * matrices are replaced by their shorter forms, and for identity matrix
  6000. * returns empty string to save the memory.
  6001. * @param m {Array} matrix to format.
  6002. * @returns {string}
  6003. */
  6004. function pm(m) {
  6005. if (m[4] === 0 && m[5] === 0) {
  6006. if (m[1] === 0 && m[2] === 0) {
  6007. if (m[0] === 1 && m[3] === 1) {
  6008. return '';
  6009. }
  6010. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6011. }
  6012. if (m[0] === m[3] && m[1] === -m[2]) {
  6013. var a = Math.acos(m[0]) * 180 / Math.PI;
  6014. return 'rotate(' + pf(a) + ')';
  6015. }
  6016. } else {
  6017. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6018. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6019. }
  6020. }
  6021. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6022. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6023. }
  6024. function SVGGraphics(commonObjs, objs) {
  6025. this.current = new SVGExtraState();
  6026. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6027. this.transformStack = [];
  6028. this.extraStack = [];
  6029. this.commonObjs = commonObjs;
  6030. this.objs = objs;
  6031. this.pendingEOFill = false;
  6032. this.embedFonts = false;
  6033. this.embeddedFonts = {};
  6034. this.cssStyle = null;
  6035. }
  6036. var NS = 'http://www.w3.org/2000/svg';
  6037. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6038. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6039. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6040. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6041. var clipCount = 0;
  6042. var maskCount = 0;
  6043. SVGGraphics.prototype = {
  6044. save: function SVGGraphics_save() {
  6045. this.transformStack.push(this.transformMatrix);
  6046. var old = this.current;
  6047. this.extraStack.push(old);
  6048. this.current = old.clone();
  6049. },
  6050. restore: function SVGGraphics_restore() {
  6051. this.transformMatrix = this.transformStack.pop();
  6052. this.current = this.extraStack.pop();
  6053. this.tgrp = document.createElementNS(NS, 'svg:g');
  6054. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6055. this.pgrp.appendChild(this.tgrp);
  6056. },
  6057. group: function SVGGraphics_group(items) {
  6058. this.save();
  6059. this.executeOpTree(items);
  6060. this.restore();
  6061. },
  6062. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6063. var fnArray = operatorList.fnArray;
  6064. var fnArrayLen = fnArray.length;
  6065. var argsArray = operatorList.argsArray;
  6066. var self = this;
  6067. for (var i = 0; i < fnArrayLen; i++) {
  6068. if (OPS.dependency === fnArray[i]) {
  6069. var deps = argsArray[i];
  6070. for (var n = 0, nn = deps.length; n < nn; n++) {
  6071. var obj = deps[n];
  6072. var common = obj.substring(0, 2) === 'g_';
  6073. var promise;
  6074. if (common) {
  6075. promise = new Promise(function(resolve) {
  6076. self.commonObjs.get(obj, resolve);
  6077. });
  6078. } else {
  6079. promise = new Promise(function(resolve) {
  6080. self.objs.get(obj, resolve);
  6081. });
  6082. }
  6083. this.current.dependencies.push(promise);
  6084. }
  6085. }
  6086. }
  6087. return Promise.all(this.current.dependencies);
  6088. },
  6089. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6090. var transformMatrix = [a, b, c, d, e, f];
  6091. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6092. transformMatrix);
  6093. this.tgrp = document.createElementNS(NS, 'svg:g');
  6094. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6095. },
  6096. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6097. this.svg = createScratchSVG(viewport.width, viewport.height);
  6098. this.viewport = viewport;
  6099. return this.loadDependencies(operatorList).then(function () {
  6100. this.transformMatrix = IDENTITY_MATRIX;
  6101. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6102. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6103. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6104. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6105. this.defs = document.createElementNS(NS, 'svg:defs');
  6106. this.pgrp.appendChild(this.defs);
  6107. this.pgrp.appendChild(this.tgrp);
  6108. this.svg.appendChild(this.pgrp);
  6109. var opTree = this.convertOpList(operatorList);
  6110. this.executeOpTree(opTree);
  6111. return this.svg;
  6112. }.bind(this));
  6113. },
  6114. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6115. var argsArray = operatorList.argsArray;
  6116. var fnArray = operatorList.fnArray;
  6117. var fnArrayLen = fnArray.length;
  6118. var REVOPS = [];
  6119. var opList = [];
  6120. for (var op in OPS) {
  6121. REVOPS[OPS[op]] = op;
  6122. }
  6123. for (var x = 0; x < fnArrayLen; x++) {
  6124. var fnId = fnArray[x];
  6125. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6126. }
  6127. return opListToTree(opList);
  6128. },
  6129. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6130. var opTreeLen = opTree.length;
  6131. for(var x = 0; x < opTreeLen; x++) {
  6132. var fn = opTree[x].fn;
  6133. var fnId = opTree[x].fnId;
  6134. var args = opTree[x].args;
  6135. switch (fnId | 0) {
  6136. case OPS.beginText:
  6137. this.beginText();
  6138. break;
  6139. case OPS.setLeading:
  6140. this.setLeading(args);
  6141. break;
  6142. case OPS.setLeadingMoveText:
  6143. this.setLeadingMoveText(args[0], args[1]);
  6144. break;
  6145. case OPS.setFont:
  6146. this.setFont(args);
  6147. break;
  6148. case OPS.showText:
  6149. this.showText(args[0]);
  6150. break;
  6151. case OPS.showSpacedText:
  6152. this.showText(args[0]);
  6153. break;
  6154. case OPS.endText:
  6155. this.endText();
  6156. break;
  6157. case OPS.moveText:
  6158. this.moveText(args[0], args[1]);
  6159. break;
  6160. case OPS.setCharSpacing:
  6161. this.setCharSpacing(args[0]);
  6162. break;
  6163. case OPS.setWordSpacing:
  6164. this.setWordSpacing(args[0]);
  6165. break;
  6166. case OPS.setTextMatrix:
  6167. this.setTextMatrix(args[0], args[1], args[2],
  6168. args[3], args[4], args[5]);
  6169. break;
  6170. case OPS.setLineWidth:
  6171. this.setLineWidth(args[0]);
  6172. break;
  6173. case OPS.setLineJoin:
  6174. this.setLineJoin(args[0]);
  6175. break;
  6176. case OPS.setLineCap:
  6177. this.setLineCap(args[0]);
  6178. break;
  6179. case OPS.setMiterLimit:
  6180. this.setMiterLimit(args[0]);
  6181. break;
  6182. case OPS.setFillRGBColor:
  6183. this.setFillRGBColor(args[0], args[1], args[2]);
  6184. break;
  6185. case OPS.setStrokeRGBColor:
  6186. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6187. break;
  6188. case OPS.setDash:
  6189. this.setDash(args[0], args[1]);
  6190. break;
  6191. case OPS.setGState:
  6192. this.setGState(args[0]);
  6193. break;
  6194. case OPS.fill:
  6195. this.fill();
  6196. break;
  6197. case OPS.eoFill:
  6198. this.eoFill();
  6199. break;
  6200. case OPS.stroke:
  6201. this.stroke();
  6202. break;
  6203. case OPS.fillStroke:
  6204. this.fillStroke();
  6205. break;
  6206. case OPS.eoFillStroke:
  6207. this.eoFillStroke();
  6208. break;
  6209. case OPS.clip:
  6210. this.clip('nonzero');
  6211. break;
  6212. case OPS.eoClip:
  6213. this.clip('evenodd');
  6214. break;
  6215. case OPS.paintSolidColorImageMask:
  6216. this.paintSolidColorImageMask();
  6217. break;
  6218. case OPS.paintJpegXObject:
  6219. this.paintJpegXObject(args[0], args[1], args[2]);
  6220. break;
  6221. case OPS.paintImageXObject:
  6222. this.paintImageXObject(args[0]);
  6223. break;
  6224. case OPS.paintInlineImageXObject:
  6225. this.paintInlineImageXObject(args[0]);
  6226. break;
  6227. case OPS.paintImageMaskXObject:
  6228. this.paintImageMaskXObject(args[0]);
  6229. break;
  6230. case OPS.closePath:
  6231. this.closePath();
  6232. break;
  6233. case OPS.closeStroke:
  6234. this.closeStroke();
  6235. break;
  6236. case OPS.closeFillStroke:
  6237. this.closeFillStroke();
  6238. break;
  6239. case OPS.nextLine:
  6240. this.nextLine();
  6241. break;
  6242. case OPS.transform:
  6243. this.transform(args[0], args[1], args[2], args[3],
  6244. args[4], args[5]);
  6245. break;
  6246. case OPS.constructPath:
  6247. this.constructPath(args[0], args[1]);
  6248. break;
  6249. case OPS.endPath:
  6250. this.endPath();
  6251. break;
  6252. case 92:
  6253. this.group(opTree[x].items);
  6254. break;
  6255. default:
  6256. warn('Unimplemented method '+ fn);
  6257. break;
  6258. }
  6259. }
  6260. },
  6261. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6262. this.current.wordSpacing = wordSpacing;
  6263. },
  6264. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6265. this.current.charSpacing = charSpacing;
  6266. },
  6267. nextLine: function SVGGraphics_nextLine() {
  6268. this.moveText(0, this.current.leading);
  6269. },
  6270. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6271. var current = this.current;
  6272. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6273. this.current.x = this.current.lineX = 0;
  6274. this.current.y = this.current.lineY = 0;
  6275. current.xcoords = [];
  6276. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6277. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6278. current.tspan.setAttributeNS(null, 'font-size',
  6279. pf(current.fontSize) + 'px');
  6280. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6281. current.txtElement = document.createElementNS(NS, 'svg:text');
  6282. current.txtElement.appendChild(current.tspan);
  6283. },
  6284. beginText: function SVGGraphics_beginText() {
  6285. this.current.x = this.current.lineX = 0;
  6286. this.current.y = this.current.lineY = 0;
  6287. this.current.textMatrix = IDENTITY_MATRIX;
  6288. this.current.lineMatrix = IDENTITY_MATRIX;
  6289. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6290. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6291. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6292. this.current.xcoords = [];
  6293. },
  6294. moveText: function SVGGraphics_moveText(x, y) {
  6295. var current = this.current;
  6296. this.current.x = this.current.lineX += x;
  6297. this.current.y = this.current.lineY += y;
  6298. current.xcoords = [];
  6299. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6300. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6301. current.tspan.setAttributeNS(null, 'font-size',
  6302. pf(current.fontSize) + 'px');
  6303. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6304. },
  6305. showText: function SVGGraphics_showText(glyphs) {
  6306. var current = this.current;
  6307. var font = current.font;
  6308. var fontSize = current.fontSize;
  6309. if (fontSize === 0) {
  6310. return;
  6311. }
  6312. var charSpacing = current.charSpacing;
  6313. var wordSpacing = current.wordSpacing;
  6314. var fontDirection = current.fontDirection;
  6315. var textHScale = current.textHScale * fontDirection;
  6316. var glyphsLength = glyphs.length;
  6317. var vertical = font.vertical;
  6318. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6319. var x = 0, i;
  6320. for (i = 0; i < glyphsLength; ++i) {
  6321. var glyph = glyphs[i];
  6322. if (glyph === null) {
  6323. // word break
  6324. x += fontDirection * wordSpacing;
  6325. continue;
  6326. } else if (isNum(glyph)) {
  6327. x += -glyph * fontSize * 0.001;
  6328. continue;
  6329. }
  6330. current.xcoords.push(current.x + x * textHScale);
  6331. var width = glyph.width;
  6332. var character = glyph.fontChar;
  6333. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6334. x += charWidth;
  6335. current.tspan.textContent += character;
  6336. }
  6337. if (vertical) {
  6338. current.y -= x * textHScale;
  6339. } else {
  6340. current.x += x * textHScale;
  6341. }
  6342. current.tspan.setAttributeNS(null, 'x',
  6343. current.xcoords.map(pf).join(' '));
  6344. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6345. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6346. current.tspan.setAttributeNS(null, 'font-size',
  6347. pf(current.fontSize) + 'px');
  6348. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6349. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6350. current.tspan.setAttributeNS(null, 'stroke', 'none');
  6351. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6352. current.txtElement.setAttributeNS(null, 'transform',
  6353. pm(current.textMatrix) +
  6354. ' scale(1, -1)' );
  6355. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6356. current.txtElement.appendChild(current.tspan);
  6357. current.txtgrp.appendChild(current.txtElement);
  6358. this.tgrp.appendChild(current.txtElement);
  6359. },
  6360. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6361. this.setLeading(-y);
  6362. this.moveText(x, y);
  6363. },
  6364. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6365. if (!this.cssStyle) {
  6366. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6367. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6368. this.defs.appendChild(this.cssStyle);
  6369. }
  6370. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6371. this.cssStyle.textContent +=
  6372. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6373. ' src: url(' + url + '); }\n';
  6374. },
  6375. setFont: function SVGGraphics_setFont(details) {
  6376. var current = this.current;
  6377. var fontObj = this.commonObjs.get(details[0]);
  6378. var size = details[1];
  6379. this.current.font = fontObj;
  6380. if (this.embedFonts && fontObj.data &&
  6381. !this.embeddedFonts[fontObj.loadedName]) {
  6382. this.addFontStyle(fontObj);
  6383. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6384. }
  6385. current.fontMatrix = (fontObj.fontMatrix ?
  6386. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6387. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6388. (fontObj.bold ? 'bold' : 'normal');
  6389. var italic = fontObj.italic ? 'italic' : 'normal';
  6390. if (size < 0) {
  6391. size = -size;
  6392. current.fontDirection = -1;
  6393. } else {
  6394. current.fontDirection = 1;
  6395. }
  6396. current.fontSize = size;
  6397. current.fontFamily = fontObj.loadedName;
  6398. current.fontWeight = bold;
  6399. current.fontStyle = italic;
  6400. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6401. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6402. current.xcoords = [];
  6403. },
  6404. endText: function SVGGraphics_endText() {
  6405. if (this.current.pendingClip) {
  6406. this.pgrp.appendChild(this.cgrp);
  6407. } else {
  6408. this.pgrp.appendChild(this.tgrp);
  6409. }
  6410. this.tgrp = document.createElementNS(NS, 'svg:g');
  6411. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6412. },
  6413. // Path properties
  6414. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6415. this.current.lineWidth = width;
  6416. },
  6417. setLineCap: function SVGGraphics_setLineCap(style) {
  6418. this.current.lineCap = LINE_CAP_STYLES[style];
  6419. },
  6420. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6421. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6422. },
  6423. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6424. this.current.miterLimit = limit;
  6425. },
  6426. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6427. var color = Util.makeCssRgb(arguments);
  6428. this.current.strokeColor = color;
  6429. },
  6430. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6431. var color = Util.makeCssRgb(arguments);
  6432. this.current.fillColor = color;
  6433. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6434. this.current.xcoords = [];
  6435. },
  6436. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6437. this.current.dashArray = dashArray;
  6438. this.current.dashPhase = dashPhase;
  6439. },
  6440. constructPath: function SVGGraphics_constructPath(ops, args) {
  6441. var current = this.current;
  6442. var x = current.x, y = current.y;
  6443. current.path = document.createElementNS(NS, 'svg:path');
  6444. var d = [];
  6445. var opLength = ops.length;
  6446. for (var i = 0, j = 0; i < opLength; i++) {
  6447. switch (ops[i] | 0) {
  6448. case OPS.rectangle:
  6449. x = args[j++];
  6450. y = args[j++];
  6451. var width = args[j++];
  6452. var height = args[j++];
  6453. var xw = x + width;
  6454. var yh = y + height;
  6455. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6456. 'L', pf(x), pf(yh), 'Z');
  6457. break;
  6458. case OPS.moveTo:
  6459. x = args[j++];
  6460. y = args[j++];
  6461. d.push('M', pf(x), pf(y));
  6462. break;
  6463. case OPS.lineTo:
  6464. x = args[j++];
  6465. y = args[j++];
  6466. d.push('L', pf(x) , pf(y));
  6467. break;
  6468. case OPS.curveTo:
  6469. x = args[j + 4];
  6470. y = args[j + 5];
  6471. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6472. pf(args[j + 3]), pf(x), pf(y));
  6473. j += 6;
  6474. break;
  6475. case OPS.curveTo2:
  6476. x = args[j + 2];
  6477. y = args[j + 3];
  6478. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6479. pf(args[j + 2]), pf(args[j + 3]));
  6480. j += 4;
  6481. break;
  6482. case OPS.curveTo3:
  6483. x = args[j + 2];
  6484. y = args[j + 3];
  6485. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6486. pf(x), pf(y));
  6487. j += 4;
  6488. break;
  6489. case OPS.closePath:
  6490. d.push('Z');
  6491. break;
  6492. }
  6493. }
  6494. current.path.setAttributeNS(null, 'd', d.join(' '));
  6495. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6496. pf(current.miterLimit));
  6497. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6498. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6499. current.path.setAttributeNS(null, 'stroke-width',
  6500. pf(current.lineWidth) + 'px');
  6501. current.path.setAttributeNS(null, 'stroke-dasharray',
  6502. current.dashArray.map(pf).join(' '));
  6503. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6504. pf(current.dashPhase) + 'px');
  6505. current.path.setAttributeNS(null, 'fill', 'none');
  6506. this.tgrp.appendChild(current.path);
  6507. if (current.pendingClip) {
  6508. this.cgrp.appendChild(this.tgrp);
  6509. this.pgrp.appendChild(this.cgrp);
  6510. } else {
  6511. this.pgrp.appendChild(this.tgrp);
  6512. }
  6513. // Saving a reference in current.element so that it can be addressed
  6514. // in 'fill' and 'stroke'
  6515. current.element = current.path;
  6516. current.setCurrentPoint(x, y);
  6517. },
  6518. endPath: function SVGGraphics_endPath() {
  6519. var current = this.current;
  6520. if (current.pendingClip) {
  6521. this.cgrp.appendChild(this.tgrp);
  6522. this.pgrp.appendChild(this.cgrp);
  6523. } else {
  6524. this.pgrp.appendChild(this.tgrp);
  6525. }
  6526. this.tgrp = document.createElementNS(NS, 'svg:g');
  6527. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6528. },
  6529. clip: function SVGGraphics_clip(type) {
  6530. var current = this.current;
  6531. // Add current path to clipping path
  6532. current.clipId = 'clippath' + clipCount;
  6533. clipCount++;
  6534. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6535. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6536. var clipElement = current.element.cloneNode();
  6537. if (type === 'evenodd') {
  6538. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6539. } else {
  6540. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6541. }
  6542. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6543. this.clippath.appendChild(clipElement);
  6544. this.defs.appendChild(this.clippath);
  6545. // Create a new group with that attribute
  6546. current.pendingClip = true;
  6547. this.cgrp = document.createElementNS(NS, 'svg:g');
  6548. this.cgrp.setAttributeNS(null, 'clip-path',
  6549. 'url(#' + current.clipId + ')');
  6550. this.pgrp.appendChild(this.cgrp);
  6551. },
  6552. closePath: function SVGGraphics_closePath() {
  6553. var current = this.current;
  6554. var d = current.path.getAttributeNS(null, 'd');
  6555. d += 'Z';
  6556. current.path.setAttributeNS(null, 'd', d);
  6557. },
  6558. setLeading: function SVGGraphics_setLeading(leading) {
  6559. this.current.leading = -leading;
  6560. },
  6561. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6562. this.current.textRise = textRise;
  6563. },
  6564. setHScale: function SVGGraphics_setHScale(scale) {
  6565. this.current.textHScale = scale / 100;
  6566. },
  6567. setGState: function SVGGraphics_setGState(states) {
  6568. for (var i = 0, ii = states.length; i < ii; i++) {
  6569. var state = states[i];
  6570. var key = state[0];
  6571. var value = state[1];
  6572. switch (key) {
  6573. case 'LW':
  6574. this.setLineWidth(value);
  6575. break;
  6576. case 'LC':
  6577. this.setLineCap(value);
  6578. break;
  6579. case 'LJ':
  6580. this.setLineJoin(value);
  6581. break;
  6582. case 'ML':
  6583. this.setMiterLimit(value);
  6584. break;
  6585. case 'D':
  6586. this.setDash(value[0], value[1]);
  6587. break;
  6588. case 'RI':
  6589. break;
  6590. case 'FL':
  6591. break;
  6592. case 'Font':
  6593. this.setFont(value);
  6594. break;
  6595. case 'CA':
  6596. break;
  6597. case 'ca':
  6598. break;
  6599. case 'BM':
  6600. break;
  6601. case 'SMask':
  6602. break;
  6603. }
  6604. }
  6605. },
  6606. fill: function SVGGraphics_fill() {
  6607. var current = this.current;
  6608. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6609. },
  6610. stroke: function SVGGraphics_stroke() {
  6611. var current = this.current;
  6612. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6613. current.element.setAttributeNS(null, 'fill', 'none');
  6614. },
  6615. eoFill: function SVGGraphics_eoFill() {
  6616. var current = this.current;
  6617. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6618. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6619. },
  6620. fillStroke: function SVGGraphics_fillStroke() {
  6621. // Order is important since stroke wants fill to be none.
  6622. // First stroke, then if fill needed, it will be overwritten.
  6623. this.stroke();
  6624. this.fill();
  6625. },
  6626. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6627. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6628. this.fillStroke();
  6629. },
  6630. closeStroke: function SVGGraphics_closeStroke() {
  6631. this.closePath();
  6632. this.stroke();
  6633. },
  6634. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6635. this.closePath();
  6636. this.fillStroke();
  6637. },
  6638. paintSolidColorImageMask:
  6639. function SVGGraphics_paintSolidColorImageMask() {
  6640. var current = this.current;
  6641. var rect = document.createElementNS(NS, 'svg:rect');
  6642. rect.setAttributeNS(null, 'x', '0');
  6643. rect.setAttributeNS(null, 'y', '0');
  6644. rect.setAttributeNS(null, 'width', '1px');
  6645. rect.setAttributeNS(null, 'height', '1px');
  6646. rect.setAttributeNS(null, 'fill', current.fillColor);
  6647. this.tgrp.appendChild(rect);
  6648. },
  6649. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6650. var current = this.current;
  6651. var imgObj = this.objs.get(objId);
  6652. var imgEl = document.createElementNS(NS, 'svg:image');
  6653. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6654. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6655. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6656. imgEl.setAttributeNS(null, 'x', '0');
  6657. imgEl.setAttributeNS(null, 'y', pf(-h));
  6658. imgEl.setAttributeNS(null, 'transform',
  6659. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6660. this.tgrp.appendChild(imgEl);
  6661. if (current.pendingClip) {
  6662. this.cgrp.appendChild(this.tgrp);
  6663. this.pgrp.appendChild(this.cgrp);
  6664. } else {
  6665. this.pgrp.appendChild(this.tgrp);
  6666. }
  6667. },
  6668. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6669. var imgData = this.objs.get(objId);
  6670. if (!imgData) {
  6671. warn('Dependent image isn\'t ready yet');
  6672. return;
  6673. }
  6674. this.paintInlineImageXObject(imgData);
  6675. },
  6676. paintInlineImageXObject:
  6677. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6678. var current = this.current;
  6679. var width = imgData.width;
  6680. var height = imgData.height;
  6681. var imgSrc = convertImgDataToPng(imgData);
  6682. var cliprect = document.createElementNS(NS, 'svg:rect');
  6683. cliprect.setAttributeNS(null, 'x', '0');
  6684. cliprect.setAttributeNS(null, 'y', '0');
  6685. cliprect.setAttributeNS(null, 'width', pf(width));
  6686. cliprect.setAttributeNS(null, 'height', pf(height));
  6687. current.element = cliprect;
  6688. this.clip('nonzero');
  6689. var imgEl = document.createElementNS(NS, 'svg:image');
  6690. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  6691. imgEl.setAttributeNS(null, 'x', '0');
  6692. imgEl.setAttributeNS(null, 'y', pf(-height));
  6693. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  6694. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  6695. imgEl.setAttributeNS(null, 'transform',
  6696. 'scale(' + pf(1 / width) + ' ' +
  6697. pf(-1 / height) + ')');
  6698. if (mask) {
  6699. mask.appendChild(imgEl);
  6700. } else {
  6701. this.tgrp.appendChild(imgEl);
  6702. }
  6703. if (current.pendingClip) {
  6704. this.cgrp.appendChild(this.tgrp);
  6705. this.pgrp.appendChild(this.cgrp);
  6706. } else {
  6707. this.pgrp.appendChild(this.tgrp);
  6708. }
  6709. },
  6710. paintImageMaskXObject:
  6711. function SVGGraphics_paintImageMaskXObject(imgData) {
  6712. var current = this.current;
  6713. var width = imgData.width;
  6714. var height = imgData.height;
  6715. var fillColor = current.fillColor;
  6716. current.maskId = 'mask' + maskCount++;
  6717. var mask = document.createElementNS(NS, 'svg:mask');
  6718. mask.setAttributeNS(null, 'id', current.maskId);
  6719. var rect = document.createElementNS(NS, 'svg:rect');
  6720. rect.setAttributeNS(null, 'x', '0');
  6721. rect.setAttributeNS(null, 'y', '0');
  6722. rect.setAttributeNS(null, 'width', pf(width));
  6723. rect.setAttributeNS(null, 'height', pf(height));
  6724. rect.setAttributeNS(null, 'fill', fillColor);
  6725. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  6726. this.defs.appendChild(mask);
  6727. this.tgrp.appendChild(rect);
  6728. this.paintInlineImageXObject(imgData, mask);
  6729. },
  6730. };
  6731. return SVGGraphics;
  6732. })();
  6733. PDFJS.SVGGraphics = SVGGraphics;
  6734. var NetworkManager = (function NetworkManagerClosure() {
  6735. var OK_RESPONSE = 200;
  6736. var PARTIAL_CONTENT_RESPONSE = 206;
  6737. function NetworkManager(url, args) {
  6738. this.url = url;
  6739. args = args || {};
  6740. this.isHttp = /^https?:/i.test(url);
  6741. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  6742. this.withCredentials = args.withCredentials || false;
  6743. this.getXhr = args.getXhr ||
  6744. function NetworkManager_getXhr() {
  6745. return new XMLHttpRequest();
  6746. };
  6747. this.currXhrId = 0;
  6748. this.pendingRequests = {};
  6749. this.loadedRequests = {};
  6750. }
  6751. function getArrayBuffer(xhr) {
  6752. var data = xhr.response;
  6753. if (typeof data !== 'string') {
  6754. return data;
  6755. }
  6756. var length = data.length;
  6757. var buffer = new Uint8Array(length);
  6758. for (var i = 0; i < length; i++) {
  6759. buffer[i] = data.charCodeAt(i) & 0xFF;
  6760. }
  6761. return buffer;
  6762. }
  6763. NetworkManager.prototype = {
  6764. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  6765. var args = {
  6766. begin: begin,
  6767. end: end
  6768. };
  6769. for (var prop in listeners) {
  6770. args[prop] = listeners[prop];
  6771. }
  6772. return this.request(args);
  6773. },
  6774. requestFull: function NetworkManager_requestRange(listeners) {
  6775. return this.request(listeners);
  6776. },
  6777. request: function NetworkManager_requestRange(args) {
  6778. var xhr = this.getXhr();
  6779. var xhrId = this.currXhrId++;
  6780. var pendingRequest = this.pendingRequests[xhrId] = {
  6781. xhr: xhr
  6782. };
  6783. xhr.open('GET', this.url);
  6784. xhr.withCredentials = this.withCredentials;
  6785. for (var property in this.httpHeaders) {
  6786. var value = this.httpHeaders[property];
  6787. if (typeof value === 'undefined') {
  6788. continue;
  6789. }
  6790. xhr.setRequestHeader(property, value);
  6791. }
  6792. if (this.isHttp && 'begin' in args && 'end' in args) {
  6793. var rangeStr = args.begin + '-' + (args.end - 1);
  6794. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  6795. pendingRequest.expectedStatus = 206;
  6796. } else {
  6797. pendingRequest.expectedStatus = 200;
  6798. }
  6799. xhr.responseType = 'arraybuffer';
  6800. if (args.onProgress) {
  6801. xhr.onprogress = args.onProgress;
  6802. }
  6803. if (args.onError) {
  6804. xhr.onerror = function(evt) {
  6805. args.onError(xhr.status);
  6806. };
  6807. }
  6808. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  6809. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  6810. pendingRequest.onDone = args.onDone;
  6811. pendingRequest.onError = args.onError;
  6812. xhr.send(null);
  6813. return xhrId;
  6814. },
  6815. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  6816. var pendingRequest = this.pendingRequests[xhrId];
  6817. if (!pendingRequest) {
  6818. // Maybe abortRequest was called...
  6819. return;
  6820. }
  6821. var xhr = pendingRequest.xhr;
  6822. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  6823. pendingRequest.onHeadersReceived();
  6824. delete pendingRequest.onHeadersReceived;
  6825. }
  6826. if (xhr.readyState !== 4) {
  6827. return;
  6828. }
  6829. if (!(xhrId in this.pendingRequests)) {
  6830. // The XHR request might have been aborted in onHeadersReceived()
  6831. // callback, in which case we should abort request
  6832. return;
  6833. }
  6834. delete this.pendingRequests[xhrId];
  6835. // success status == 0 can be on ftp, file and other protocols
  6836. if (xhr.status === 0 && this.isHttp) {
  6837. if (pendingRequest.onError) {
  6838. pendingRequest.onError(xhr.status);
  6839. }
  6840. return;
  6841. }
  6842. var xhrStatus = xhr.status || OK_RESPONSE;
  6843. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  6844. // "A server MAY ignore the Range header". This means it's possible to
  6845. // get a 200 rather than a 206 response from a range request.
  6846. var ok_response_on_range_request =
  6847. xhrStatus === OK_RESPONSE &&
  6848. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  6849. if (!ok_response_on_range_request &&
  6850. xhrStatus !== pendingRequest.expectedStatus) {
  6851. if (pendingRequest.onError) {
  6852. pendingRequest.onError(xhr.status);
  6853. }
  6854. return;
  6855. }
  6856. this.loadedRequests[xhrId] = true;
  6857. var chunk = getArrayBuffer(xhr);
  6858. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  6859. var rangeHeader = xhr.getResponseHeader('Content-Range');
  6860. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  6861. var begin = parseInt(matches[1], 10);
  6862. pendingRequest.onDone({
  6863. begin: begin,
  6864. chunk: chunk
  6865. });
  6866. } else {
  6867. pendingRequest.onDone({
  6868. begin: 0,
  6869. chunk: chunk
  6870. });
  6871. }
  6872. },
  6873. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  6874. for (var xhrId in this.pendingRequests) {
  6875. return true;
  6876. }
  6877. return false;
  6878. },
  6879. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  6880. return this.pendingRequests[xhrId].xhr;
  6881. },
  6882. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  6883. return xhrId in this.pendingRequests;
  6884. },
  6885. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  6886. return xhrId in this.loadedRequests;
  6887. },
  6888. abortAllRequests: function NetworkManager_abortAllRequests() {
  6889. for (var xhrId in this.pendingRequests) {
  6890. this.abortRequest(xhrId | 0);
  6891. }
  6892. },
  6893. abortRequest: function NetworkManager_abortRequest(xhrId) {
  6894. var xhr = this.pendingRequests[xhrId].xhr;
  6895. delete this.pendingRequests[xhrId];
  6896. xhr.abort();
  6897. }
  6898. };
  6899. return NetworkManager;
  6900. })();
  6901. var ChunkedStream = (function ChunkedStreamClosure() {
  6902. function ChunkedStream(length, chunkSize, manager) {
  6903. this.bytes = new Uint8Array(length);
  6904. this.start = 0;
  6905. this.pos = 0;
  6906. this.end = length;
  6907. this.chunkSize = chunkSize;
  6908. this.loadedChunks = [];
  6909. this.numChunksLoaded = 0;
  6910. this.numChunks = Math.ceil(length / chunkSize);
  6911. this.manager = manager;
  6912. this.initialDataLength = 0;
  6913. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  6914. }
  6915. // required methods for a stream. if a particular stream does not
  6916. // implement these, an error should be thrown
  6917. ChunkedStream.prototype = {
  6918. getMissingChunks: function ChunkedStream_getMissingChunks() {
  6919. var chunks = [];
  6920. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  6921. if (!(chunk in this.loadedChunks)) {
  6922. chunks.push(chunk);
  6923. }
  6924. }
  6925. return chunks;
  6926. },
  6927. getBaseStreams: function ChunkedStream_getBaseStreams() {
  6928. return [this];
  6929. },
  6930. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  6931. return this.numChunksLoaded === this.numChunks;
  6932. },
  6933. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  6934. var end = begin + chunk.byteLength;
  6935. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  6936. // Using this.length is inaccurate here since this.start can be moved
  6937. // See ChunkedStream.moveStart()
  6938. var length = this.bytes.length;
  6939. assert(end % this.chunkSize === 0 || end === length,
  6940. 'Bad end offset: ' + end);
  6941. this.bytes.set(new Uint8Array(chunk), begin);
  6942. var chunkSize = this.chunkSize;
  6943. var beginChunk = Math.floor(begin / chunkSize);
  6944. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  6945. var curChunk;
  6946. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  6947. if (!(curChunk in this.loadedChunks)) {
  6948. this.loadedChunks[curChunk] = true;
  6949. ++this.numChunksLoaded;
  6950. }
  6951. }
  6952. },
  6953. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  6954. this.bytes.set(data);
  6955. this.initialDataLength = data.length;
  6956. var endChunk = (this.end === data.length ?
  6957. this.numChunks : Math.floor(data.length / this.chunkSize));
  6958. for (var i = 0; i < endChunk; i++) {
  6959. this.loadedChunks[i] = true;
  6960. ++this.numChunksLoaded;
  6961. }
  6962. },
  6963. ensureByte: function ChunkedStream_ensureRange(pos) {
  6964. var chunk = Math.floor(pos / this.chunkSize);
  6965. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  6966. return;
  6967. }
  6968. if (!(chunk in this.loadedChunks)) {
  6969. throw new MissingDataException(pos, pos + 1);
  6970. }
  6971. this.lastSuccessfulEnsureByteChunk = chunk;
  6972. },
  6973. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  6974. if (begin >= end) {
  6975. return;
  6976. }
  6977. if (end <= this.initialDataLength) {
  6978. return;
  6979. }
  6980. var chunkSize = this.chunkSize;
  6981. var beginChunk = Math.floor(begin / chunkSize);
  6982. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  6983. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6984. if (!(chunk in this.loadedChunks)) {
  6985. throw new MissingDataException(begin, end);
  6986. }
  6987. }
  6988. },
  6989. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  6990. var chunk, n;
  6991. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  6992. if (!(chunk in this.loadedChunks)) {
  6993. return chunk;
  6994. }
  6995. }
  6996. // Wrap around to beginning
  6997. for (chunk = 0; chunk < beginChunk; ++chunk) {
  6998. if (!(chunk in this.loadedChunks)) {
  6999. return chunk;
  7000. }
  7001. }
  7002. return null;
  7003. },
  7004. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7005. return chunk in this.loadedChunks;
  7006. },
  7007. get length() {
  7008. return this.end - this.start;
  7009. },
  7010. get isEmpty() {
  7011. return this.length === 0;
  7012. },
  7013. getByte: function ChunkedStream_getByte() {
  7014. var pos = this.pos;
  7015. if (pos >= this.end) {
  7016. return -1;
  7017. }
  7018. this.ensureByte(pos);
  7019. return this.bytes[this.pos++];
  7020. },
  7021. getUint16: function ChunkedStream_getUint16() {
  7022. var b0 = this.getByte();
  7023. var b1 = this.getByte();
  7024. return (b0 << 8) + b1;
  7025. },
  7026. getInt32: function ChunkedStream_getInt32() {
  7027. var b0 = this.getByte();
  7028. var b1 = this.getByte();
  7029. var b2 = this.getByte();
  7030. var b3 = this.getByte();
  7031. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7032. },
  7033. // returns subarray of original buffer
  7034. // should only be read
  7035. getBytes: function ChunkedStream_getBytes(length) {
  7036. var bytes = this.bytes;
  7037. var pos = this.pos;
  7038. var strEnd = this.end;
  7039. if (!length) {
  7040. this.ensureRange(pos, strEnd);
  7041. return bytes.subarray(pos, strEnd);
  7042. }
  7043. var end = pos + length;
  7044. if (end > strEnd) {
  7045. end = strEnd;
  7046. }
  7047. this.ensureRange(pos, end);
  7048. this.pos = end;
  7049. return bytes.subarray(pos, end);
  7050. },
  7051. peekBytes: function ChunkedStream_peekBytes(length) {
  7052. var bytes = this.getBytes(length);
  7053. this.pos -= bytes.length;
  7054. return bytes;
  7055. },
  7056. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7057. this.ensureRange(begin, end);
  7058. return this.bytes.subarray(begin, end);
  7059. },
  7060. skip: function ChunkedStream_skip(n) {
  7061. if (!n) {
  7062. n = 1;
  7063. }
  7064. this.pos += n;
  7065. },
  7066. reset: function ChunkedStream_reset() {
  7067. this.pos = this.start;
  7068. },
  7069. moveStart: function ChunkedStream_moveStart() {
  7070. this.start = this.pos;
  7071. },
  7072. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7073. this.ensureRange(start, start + length);
  7074. function ChunkedStreamSubstream() {}
  7075. ChunkedStreamSubstream.prototype = Object.create(this);
  7076. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7077. var chunkSize = this.chunkSize;
  7078. var beginChunk = Math.floor(this.start / chunkSize);
  7079. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7080. var missingChunks = [];
  7081. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7082. if (!(chunk in this.loadedChunks)) {
  7083. missingChunks.push(chunk);
  7084. }
  7085. }
  7086. return missingChunks;
  7087. };
  7088. var subStream = new ChunkedStreamSubstream();
  7089. subStream.pos = subStream.start = start;
  7090. subStream.end = start + length || this.end;
  7091. subStream.dict = dict;
  7092. return subStream;
  7093. },
  7094. isStream: true
  7095. };
  7096. return ChunkedStream;
  7097. })();
  7098. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7099. function ChunkedStreamManager(length, chunkSize, url, args) {
  7100. this.stream = new ChunkedStream(length, chunkSize, this);
  7101. this.length = length;
  7102. this.chunkSize = chunkSize;
  7103. this.url = url;
  7104. this.disableAutoFetch = args.disableAutoFetch;
  7105. var msgHandler = this.msgHandler = args.msgHandler;
  7106. if (args.chunkedViewerLoading) {
  7107. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7108. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7109. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7110. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7111. };
  7112. } else {
  7113. var getXhr = function getXhr() {
  7114. return new XMLHttpRequest();
  7115. };
  7116. this.networkManager = new NetworkManager(this.url, {
  7117. getXhr: getXhr,
  7118. httpHeaders: args.httpHeaders,
  7119. withCredentials: args.withCredentials
  7120. });
  7121. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7122. this.networkManager.requestRange(begin, end, {
  7123. onDone: this.onReceiveData.bind(this),
  7124. onProgress: this.onProgress.bind(this)
  7125. });
  7126. };
  7127. }
  7128. this.currRequestId = 0;
  7129. this.chunksNeededByRequest = {};
  7130. this.requestsByChunk = {};
  7131. this.callbacksByRequest = {};
  7132. this._loadedStreamCapability = createPromiseCapability();
  7133. if (args.initialData) {
  7134. this.setInitialData(args.initialData);
  7135. }
  7136. }
  7137. ChunkedStreamManager.prototype = {
  7138. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  7139. this.stream.onReceiveInitialData(data);
  7140. if (this.stream.allChunksLoaded()) {
  7141. this._loadedStreamCapability.resolve(this.stream);
  7142. } else if (this.msgHandler) {
  7143. this.msgHandler.send('DocProgress', {
  7144. loaded: data.length,
  7145. total: this.length
  7146. });
  7147. }
  7148. },
  7149. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7150. return this._loadedStreamCapability.promise;
  7151. },
  7152. // Get all the chunks that are not yet loaded and groups them into
  7153. // contiguous ranges to load in as few requests as possible
  7154. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7155. var missingChunks = this.stream.getMissingChunks();
  7156. this.requestChunks(missingChunks);
  7157. return this._loadedStreamCapability.promise;
  7158. },
  7159. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7160. callback) {
  7161. var requestId = this.currRequestId++;
  7162. var chunksNeeded;
  7163. var i, ii;
  7164. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7165. for (i = 0, ii = chunks.length; i < ii; i++) {
  7166. if (!this.stream.hasChunk(chunks[i])) {
  7167. chunksNeeded[chunks[i]] = true;
  7168. }
  7169. }
  7170. if (isEmptyObj(chunksNeeded)) {
  7171. if (callback) {
  7172. callback();
  7173. }
  7174. return;
  7175. }
  7176. this.callbacksByRequest[requestId] = callback;
  7177. var chunksToRequest = [];
  7178. for (var chunk in chunksNeeded) {
  7179. chunk = chunk | 0;
  7180. if (!(chunk in this.requestsByChunk)) {
  7181. this.requestsByChunk[chunk] = [];
  7182. chunksToRequest.push(chunk);
  7183. }
  7184. this.requestsByChunk[chunk].push(requestId);
  7185. }
  7186. if (!chunksToRequest.length) {
  7187. return;
  7188. }
  7189. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7190. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7191. var groupedChunk = groupedChunksToRequest[i];
  7192. var begin = groupedChunk.beginChunk * this.chunkSize;
  7193. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7194. this.sendRequest(begin, end);
  7195. }
  7196. },
  7197. getStream: function ChunkedStreamManager_getStream() {
  7198. return this.stream;
  7199. },
  7200. // Loads any chunks in the requested range that are not yet loaded
  7201. requestRange: function ChunkedStreamManager_requestRange(
  7202. begin, end, callback) {
  7203. end = Math.min(end, this.length);
  7204. var beginChunk = this.getBeginChunk(begin);
  7205. var endChunk = this.getEndChunk(end);
  7206. var chunks = [];
  7207. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7208. chunks.push(chunk);
  7209. }
  7210. this.requestChunks(chunks, callback);
  7211. },
  7212. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7213. callback) {
  7214. ranges = ranges || [];
  7215. var chunksToRequest = [];
  7216. for (var i = 0; i < ranges.length; i++) {
  7217. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7218. var endChunk = this.getEndChunk(ranges[i].end);
  7219. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7220. if (chunksToRequest.indexOf(chunk) < 0) {
  7221. chunksToRequest.push(chunk);
  7222. }
  7223. }
  7224. }
  7225. chunksToRequest.sort(function(a, b) { return a - b; });
  7226. this.requestChunks(chunksToRequest, callback);
  7227. },
  7228. // Groups a sorted array of chunks into as few continguous larger
  7229. // chunks as possible
  7230. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7231. var groupedChunks = [];
  7232. var beginChunk = -1;
  7233. var prevChunk = -1;
  7234. for (var i = 0; i < chunks.length; ++i) {
  7235. var chunk = chunks[i];
  7236. if (beginChunk < 0) {
  7237. beginChunk = chunk;
  7238. }
  7239. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7240. groupedChunks.push({ beginChunk: beginChunk,
  7241. endChunk: prevChunk + 1 });
  7242. beginChunk = chunk;
  7243. }
  7244. if (i + 1 === chunks.length) {
  7245. groupedChunks.push({ beginChunk: beginChunk,
  7246. endChunk: chunk + 1 });
  7247. }
  7248. prevChunk = chunk;
  7249. }
  7250. return groupedChunks;
  7251. },
  7252. onProgress: function ChunkedStreamManager_onProgress(args) {
  7253. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7254. args.loaded);
  7255. this.msgHandler.send('DocProgress', {
  7256. loaded: bytesLoaded,
  7257. total: this.length
  7258. });
  7259. },
  7260. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7261. var chunk = args.chunk;
  7262. var begin = args.begin;
  7263. var end = begin + chunk.byteLength;
  7264. var beginChunk = this.getBeginChunk(begin);
  7265. var endChunk = this.getEndChunk(end);
  7266. this.stream.onReceiveData(begin, chunk);
  7267. if (this.stream.allChunksLoaded()) {
  7268. this._loadedStreamCapability.resolve(this.stream);
  7269. }
  7270. var loadedRequests = [];
  7271. var i, requestId;
  7272. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7273. // The server might return more chunks than requested
  7274. var requestIds = this.requestsByChunk[chunk] || [];
  7275. delete this.requestsByChunk[chunk];
  7276. for (i = 0; i < requestIds.length; ++i) {
  7277. requestId = requestIds[i];
  7278. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7279. if (chunk in chunksNeeded) {
  7280. delete chunksNeeded[chunk];
  7281. }
  7282. if (!isEmptyObj(chunksNeeded)) {
  7283. continue;
  7284. }
  7285. loadedRequests.push(requestId);
  7286. }
  7287. }
  7288. // If there are no pending requests, automatically fetch the next
  7289. // unfetched chunk of the PDF
  7290. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7291. var nextEmptyChunk;
  7292. if (this.stream.numChunksLoaded === 1) {
  7293. // This is a special optimization so that after fetching the first
  7294. // chunk, rather than fetching the second chunk, we fetch the last
  7295. // chunk.
  7296. var lastChunk = this.stream.numChunks - 1;
  7297. if (!this.stream.hasChunk(lastChunk)) {
  7298. nextEmptyChunk = lastChunk;
  7299. }
  7300. } else {
  7301. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7302. }
  7303. if (isInt(nextEmptyChunk)) {
  7304. this.requestChunks([nextEmptyChunk]);
  7305. }
  7306. }
  7307. for (i = 0; i < loadedRequests.length; ++i) {
  7308. requestId = loadedRequests[i];
  7309. var callback = this.callbacksByRequest[requestId];
  7310. delete this.callbacksByRequest[requestId];
  7311. if (callback) {
  7312. callback();
  7313. }
  7314. }
  7315. this.msgHandler.send('DocProgress', {
  7316. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7317. total: this.length
  7318. });
  7319. },
  7320. onError: function ChunkedStreamManager_onError(err) {
  7321. this._loadedStreamCapability.reject(err);
  7322. },
  7323. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7324. var chunk = Math.floor(begin / this.chunkSize);
  7325. return chunk;
  7326. },
  7327. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7328. if (end % this.chunkSize === 0) {
  7329. return end / this.chunkSize;
  7330. }
  7331. // 0 -> 0
  7332. // 1 -> 1
  7333. // 99 -> 1
  7334. // 100 -> 1
  7335. // 101 -> 2
  7336. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7337. return chunk;
  7338. }
  7339. };
  7340. return ChunkedStreamManager;
  7341. })();
  7342. // The maximum number of bytes fetched per range request
  7343. var RANGE_CHUNK_SIZE = 65536;
  7344. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7345. var BasePdfManager = (function BasePdfManagerClosure() {
  7346. function BasePdfManager() {
  7347. throw new Error('Cannot initialize BaseManagerManager');
  7348. }
  7349. BasePdfManager.prototype = {
  7350. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7351. throw new NotImplementedException();
  7352. },
  7353. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7354. return this.ensure(this.pdfDocument, prop, args);
  7355. },
  7356. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7357. return this.ensure(this.pdfDocument.xref, prop, args);
  7358. },
  7359. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7360. return this.ensure(this.pdfDocument.catalog, prop, args);
  7361. },
  7362. getPage: function BasePdfManager_pagePage(pageIndex) {
  7363. return this.pdfDocument.getPage(pageIndex);
  7364. },
  7365. cleanup: function BasePdfManager_cleanup() {
  7366. return this.pdfDocument.cleanup();
  7367. },
  7368. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7369. return new NotImplementedException();
  7370. },
  7371. requestRange: function BasePdfManager_ensure(begin, end) {
  7372. return new NotImplementedException();
  7373. },
  7374. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7375. return new NotImplementedException();
  7376. },
  7377. updatePassword: function BasePdfManager_updatePassword(password) {
  7378. this.pdfDocument.xref.password = this.password = password;
  7379. if (this._passwordChangedCapability) {
  7380. this._passwordChangedCapability.resolve();
  7381. }
  7382. },
  7383. passwordChanged: function BasePdfManager_passwordChanged() {
  7384. this._passwordChangedCapability = createPromiseCapability();
  7385. return this._passwordChangedCapability.promise;
  7386. },
  7387. terminate: function BasePdfManager_terminate() {
  7388. return new NotImplementedException();
  7389. }
  7390. };
  7391. return BasePdfManager;
  7392. })();
  7393. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7394. function LocalPdfManager(data, password) {
  7395. var stream = new Stream(data);
  7396. this.pdfDocument = new PDFDocument(this, stream, password);
  7397. this._loadedStreamCapability = createPromiseCapability();
  7398. this._loadedStreamCapability.resolve(stream);
  7399. }
  7400. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7401. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7402. LocalPdfManager.prototype.ensure =
  7403. function LocalPdfManager_ensure(obj, prop, args) {
  7404. return new Promise(function (resolve, reject) {
  7405. try {
  7406. var value = obj[prop];
  7407. var result;
  7408. if (typeof value === 'function') {
  7409. result = value.apply(obj, args);
  7410. } else {
  7411. result = value;
  7412. }
  7413. resolve(result);
  7414. } catch (e) {
  7415. reject(e);
  7416. }
  7417. });
  7418. };
  7419. LocalPdfManager.prototype.requestRange =
  7420. function LocalPdfManager_requestRange(begin, end) {
  7421. return Promise.resolve();
  7422. };
  7423. LocalPdfManager.prototype.requestLoadedStream =
  7424. function LocalPdfManager_requestLoadedStream() {
  7425. };
  7426. LocalPdfManager.prototype.onLoadedStream =
  7427. function LocalPdfManager_getLoadedStream() {
  7428. return this._loadedStreamCapability.promise;
  7429. };
  7430. LocalPdfManager.prototype.terminate =
  7431. function LocalPdfManager_terminate() {
  7432. return;
  7433. };
  7434. return LocalPdfManager;
  7435. })();
  7436. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7437. function NetworkPdfManager(args, msgHandler) {
  7438. this.msgHandler = msgHandler;
  7439. var params = {
  7440. msgHandler: msgHandler,
  7441. httpHeaders: args.httpHeaders,
  7442. withCredentials: args.withCredentials,
  7443. chunkedViewerLoading: args.chunkedViewerLoading,
  7444. disableAutoFetch: args.disableAutoFetch,
  7445. initialData: args.initialData
  7446. };
  7447. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7448. args.url, params);
  7449. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7450. args.password);
  7451. }
  7452. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7453. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7454. NetworkPdfManager.prototype.ensure =
  7455. function NetworkPdfManager_ensure(obj, prop, args) {
  7456. var pdfManager = this;
  7457. return new Promise(function (resolve, reject) {
  7458. function ensureHelper() {
  7459. try {
  7460. var result;
  7461. var value = obj[prop];
  7462. if (typeof value === 'function') {
  7463. result = value.apply(obj, args);
  7464. } else {
  7465. result = value;
  7466. }
  7467. resolve(result);
  7468. } catch(e) {
  7469. if (!(e instanceof MissingDataException)) {
  7470. reject(e);
  7471. return;
  7472. }
  7473. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7474. }
  7475. }
  7476. ensureHelper();
  7477. });
  7478. };
  7479. NetworkPdfManager.prototype.requestRange =
  7480. function NetworkPdfManager_requestRange(begin, end) {
  7481. return new Promise(function (resolve) {
  7482. this.streamManager.requestRange(begin, end, function() {
  7483. resolve();
  7484. });
  7485. }.bind(this));
  7486. };
  7487. NetworkPdfManager.prototype.requestLoadedStream =
  7488. function NetworkPdfManager_requestLoadedStream() {
  7489. this.streamManager.requestAllChunks();
  7490. };
  7491. NetworkPdfManager.prototype.onLoadedStream =
  7492. function NetworkPdfManager_getLoadedStream() {
  7493. return this.streamManager.onLoadedStream();
  7494. };
  7495. NetworkPdfManager.prototype.terminate =
  7496. function NetworkPdfManager_terminate() {
  7497. this.streamManager.networkManager.abortAllRequests();
  7498. };
  7499. return NetworkPdfManager;
  7500. })();
  7501. var Page = (function PageClosure() {
  7502. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7503. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7504. this.pdfManager = pdfManager;
  7505. this.pageIndex = pageIndex;
  7506. this.pageDict = pageDict;
  7507. this.xref = xref;
  7508. this.ref = ref;
  7509. this.fontCache = fontCache;
  7510. this.idCounters = {
  7511. obj: 0
  7512. };
  7513. this.resourcesPromise = null;
  7514. }
  7515. Page.prototype = {
  7516. getPageProp: function Page_getPageProp(key) {
  7517. return this.pageDict.get(key);
  7518. },
  7519. getInheritedPageProp: function Page_inheritPageProp(key) {
  7520. var dict = this.pageDict;
  7521. var value = dict.get(key);
  7522. while (value === undefined) {
  7523. dict = dict.get('Parent');
  7524. if (!dict) {
  7525. break;
  7526. }
  7527. value = dict.get(key);
  7528. }
  7529. return value;
  7530. },
  7531. get content() {
  7532. return this.getPageProp('Contents');
  7533. },
  7534. get resources() {
  7535. var value = this.getInheritedPageProp('Resources');
  7536. // For robustness: The spec states that a \Resources entry has to be
  7537. // present, but can be empty. Some document omit it still. In this case
  7538. // return an empty dictionary:
  7539. if (value === undefined) {
  7540. value = Dict.empty;
  7541. }
  7542. return shadow(this, 'resources', value);
  7543. },
  7544. get mediaBox() {
  7545. var obj = this.getInheritedPageProp('MediaBox');
  7546. // Reset invalid media box to letter size.
  7547. if (!isArray(obj) || obj.length !== 4) {
  7548. obj = LETTER_SIZE_MEDIABOX;
  7549. }
  7550. return shadow(this, 'mediaBox', obj);
  7551. },
  7552. get view() {
  7553. var mediaBox = this.mediaBox;
  7554. var cropBox = this.getInheritedPageProp('CropBox');
  7555. if (!isArray(cropBox) || cropBox.length !== 4) {
  7556. return shadow(this, 'view', mediaBox);
  7557. }
  7558. // From the spec, 6th ed., p.963:
  7559. // "The crop, bleed, trim, and art boxes should not ordinarily
  7560. // extend beyond the boundaries of the media box. If they do, they are
  7561. // effectively reduced to their intersection with the media box."
  7562. cropBox = Util.intersect(cropBox, mediaBox);
  7563. if (!cropBox) {
  7564. return shadow(this, 'view', mediaBox);
  7565. }
  7566. return shadow(this, 'view', cropBox);
  7567. },
  7568. get annotationRefs() {
  7569. return shadow(this, 'annotationRefs',
  7570. this.getInheritedPageProp('Annots'));
  7571. },
  7572. get rotate() {
  7573. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7574. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7575. if (rotate % 90 !== 0) {
  7576. rotate = 0;
  7577. } else if (rotate >= 360) {
  7578. rotate = rotate % 360;
  7579. } else if (rotate < 0) {
  7580. // The spec doesn't cover negatives, assume its counterclockwise
  7581. // rotation. The following is the other implementation of modulo.
  7582. rotate = ((rotate % 360) + 360) % 360;
  7583. }
  7584. return shadow(this, 'rotate', rotate);
  7585. },
  7586. getContentStream: function Page_getContentStream() {
  7587. var content = this.content;
  7588. var stream;
  7589. if (isArray(content)) {
  7590. // fetching items
  7591. var xref = this.xref;
  7592. var i, n = content.length;
  7593. var streams = [];
  7594. for (i = 0; i < n; ++i) {
  7595. streams.push(xref.fetchIfRef(content[i]));
  7596. }
  7597. stream = new StreamsSequenceStream(streams);
  7598. } else if (isStream(content)) {
  7599. stream = content;
  7600. } else {
  7601. // replacing non-existent page content with empty one
  7602. stream = new NullStream();
  7603. }
  7604. return stream;
  7605. },
  7606. loadResources: function Page_loadResources(keys) {
  7607. if (!this.resourcesPromise) {
  7608. // TODO: add async getInheritedPageProp and remove this.
  7609. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  7610. }
  7611. return this.resourcesPromise.then(function resourceSuccess() {
  7612. var objectLoader = new ObjectLoader(this.resources.map,
  7613. keys,
  7614. this.xref);
  7615. return objectLoader.load();
  7616. }.bind(this));
  7617. },
  7618. getOperatorList: function Page_getOperatorList(handler, intent) {
  7619. var self = this;
  7620. var pdfManager = this.pdfManager;
  7621. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7622. []);
  7623. var resourcesPromise = this.loadResources([
  7624. 'ExtGState',
  7625. 'ColorSpace',
  7626. 'Pattern',
  7627. 'Shading',
  7628. 'XObject',
  7629. 'Font'
  7630. // ProcSet
  7631. // Properties
  7632. ]);
  7633. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  7634. handler, this.pageIndex,
  7635. 'p' + this.pageIndex + '_',
  7636. this.idCounters,
  7637. this.fontCache);
  7638. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  7639. var pageListPromise = dataPromises.then(function(data) {
  7640. var contentStream = data[0];
  7641. var opList = new OperatorList(intent, handler, self.pageIndex);
  7642. handler.send('StartRenderPage', {
  7643. transparency: partialEvaluator.hasBlendModes(self.resources),
  7644. pageIndex: self.pageIndex,
  7645. intent: intent
  7646. });
  7647. return partialEvaluator.getOperatorList(contentStream, self.resources,
  7648. opList).then(function () {
  7649. return opList;
  7650. });
  7651. });
  7652. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  7653. return Promise.all([pageListPromise, annotationsPromise]).then(
  7654. function(datas) {
  7655. var pageOpList = datas[0];
  7656. var annotations = datas[1];
  7657. if (annotations.length === 0) {
  7658. pageOpList.flush(true);
  7659. return pageOpList;
  7660. }
  7661. var annotationsReadyPromise = Annotation.appendToOperatorList(
  7662. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  7663. return annotationsReadyPromise.then(function () {
  7664. pageOpList.flush(true);
  7665. return pageOpList;
  7666. });
  7667. });
  7668. },
  7669. extractTextContent: function Page_extractTextContent() {
  7670. var handler = {
  7671. on: function nullHandlerOn() {},
  7672. send: function nullHandlerSend() {}
  7673. };
  7674. var self = this;
  7675. var pdfManager = this.pdfManager;
  7676. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7677. []);
  7678. var resourcesPromise = this.loadResources([
  7679. 'ExtGState',
  7680. 'XObject',
  7681. 'Font'
  7682. ]);
  7683. var dataPromises = Promise.all([contentStreamPromise,
  7684. resourcesPromise]);
  7685. return dataPromises.then(function(data) {
  7686. var contentStream = data[0];
  7687. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  7688. handler, self.pageIndex,
  7689. 'p' + self.pageIndex + '_',
  7690. self.idCounters,
  7691. self.fontCache);
  7692. return partialEvaluator.getTextContent(contentStream,
  7693. self.resources);
  7694. });
  7695. },
  7696. getAnnotationsData: function Page_getAnnotationsData() {
  7697. var annotations = this.annotations;
  7698. var annotationsData = [];
  7699. for (var i = 0, n = annotations.length; i < n; ++i) {
  7700. annotationsData.push(annotations[i].getData());
  7701. }
  7702. return annotationsData;
  7703. },
  7704. get annotations() {
  7705. var annotations = [];
  7706. var annotationRefs = (this.annotationRefs || []);
  7707. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  7708. var annotationRef = annotationRefs[i];
  7709. var annotation = Annotation.fromRef(this.xref, annotationRef);
  7710. if (annotation) {
  7711. annotations.push(annotation);
  7712. }
  7713. }
  7714. return shadow(this, 'annotations', annotations);
  7715. }
  7716. };
  7717. return Page;
  7718. })();
  7719. /**
  7720. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  7721. * `PDFDoc`, this one doesn't have any job management code.
  7722. * Right now there exists one PDFDocument on the main thread + one object
  7723. * for each worker. If there is no worker support enabled, there are two
  7724. * `PDFDocument` objects on the main thread created.
  7725. */
  7726. var PDFDocument = (function PDFDocumentClosure() {
  7727. function PDFDocument(pdfManager, arg, password) {
  7728. if (isStream(arg)) {
  7729. init.call(this, pdfManager, arg, password);
  7730. } else if (isArrayBuffer(arg)) {
  7731. init.call(this, pdfManager, new Stream(arg), password);
  7732. } else {
  7733. error('PDFDocument: Unknown argument type');
  7734. }
  7735. }
  7736. function init(pdfManager, stream, password) {
  7737. assert(stream.length > 0, 'stream must have data');
  7738. this.pdfManager = pdfManager;
  7739. this.stream = stream;
  7740. var xref = new XRef(this.stream, password, pdfManager);
  7741. this.xref = xref;
  7742. }
  7743. function find(stream, needle, limit, backwards) {
  7744. var pos = stream.pos;
  7745. var end = stream.end;
  7746. var strBuf = [];
  7747. if (pos + limit > end) {
  7748. limit = end - pos;
  7749. }
  7750. for (var n = 0; n < limit; ++n) {
  7751. strBuf.push(String.fromCharCode(stream.getByte()));
  7752. }
  7753. var str = strBuf.join('');
  7754. stream.pos = pos;
  7755. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  7756. if (index === -1) {
  7757. return false; /* not found */
  7758. }
  7759. stream.pos += index;
  7760. return true; /* found */
  7761. }
  7762. var DocumentInfoValidators = {
  7763. get entries() {
  7764. // Lazily build this since all the validation functions below are not
  7765. // defined until after this file loads.
  7766. return shadow(this, 'entries', {
  7767. Title: isString,
  7768. Author: isString,
  7769. Subject: isString,
  7770. Keywords: isString,
  7771. Creator: isString,
  7772. Producer: isString,
  7773. CreationDate: isString,
  7774. ModDate: isString,
  7775. Trapped: isName
  7776. });
  7777. }
  7778. };
  7779. PDFDocument.prototype = {
  7780. parse: function PDFDocument_parse(recoveryMode) {
  7781. this.setup(recoveryMode);
  7782. try {
  7783. // checking if AcroForm is present
  7784. this.acroForm = this.catalog.catDict.get('AcroForm');
  7785. if (this.acroForm) {
  7786. this.xfa = this.acroForm.get('XFA');
  7787. var fields = this.acroForm.get('Fields');
  7788. if ((!fields || !isArray(fields) || fields.length === 0) &&
  7789. !this.xfa) {
  7790. // no fields and no XFA -- not a form (?)
  7791. this.acroForm = null;
  7792. }
  7793. }
  7794. } catch (ex) {
  7795. info('Something wrong with AcroForm entry');
  7796. this.acroForm = null;
  7797. }
  7798. },
  7799. get linearization() {
  7800. var linearization = null;
  7801. if (this.stream.length) {
  7802. try {
  7803. linearization = Linearization.create(this.stream);
  7804. } catch (err) {
  7805. if (err instanceof MissingDataException) {
  7806. throw err;
  7807. }
  7808. info(err);
  7809. }
  7810. }
  7811. // shadow the prototype getter with a data property
  7812. return shadow(this, 'linearization', linearization);
  7813. },
  7814. get startXRef() {
  7815. var stream = this.stream;
  7816. var startXRef = 0;
  7817. var linearization = this.linearization;
  7818. if (linearization) {
  7819. // Find end of first obj.
  7820. stream.reset();
  7821. if (find(stream, 'endobj', 1024)) {
  7822. startXRef = stream.pos + 6;
  7823. }
  7824. } else {
  7825. // Find startxref by jumping backward from the end of the file.
  7826. var step = 1024;
  7827. var found = false, pos = stream.end;
  7828. while (!found && pos > 0) {
  7829. pos -= step - 'startxref'.length;
  7830. if (pos < 0) {
  7831. pos = 0;
  7832. }
  7833. stream.pos = pos;
  7834. found = find(stream, 'startxref', step, true);
  7835. }
  7836. if (found) {
  7837. stream.skip(9);
  7838. var ch;
  7839. do {
  7840. ch = stream.getByte();
  7841. } while (Lexer.isSpace(ch));
  7842. var str = '';
  7843. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  7844. str += String.fromCharCode(ch);
  7845. ch = stream.getByte();
  7846. }
  7847. startXRef = parseInt(str, 10);
  7848. if (isNaN(startXRef)) {
  7849. startXRef = 0;
  7850. }
  7851. }
  7852. }
  7853. // shadow the prototype getter with a data property
  7854. return shadow(this, 'startXRef', startXRef);
  7855. },
  7856. get mainXRefEntriesOffset() {
  7857. var mainXRefEntriesOffset = 0;
  7858. var linearization = this.linearization;
  7859. if (linearization) {
  7860. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  7861. }
  7862. // shadow the prototype getter with a data property
  7863. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  7864. },
  7865. // Find the header, remove leading garbage and setup the stream
  7866. // starting from the header.
  7867. checkHeader: function PDFDocument_checkHeader() {
  7868. var stream = this.stream;
  7869. stream.reset();
  7870. if (find(stream, '%PDF-', 1024)) {
  7871. // Found the header, trim off any garbage before it.
  7872. stream.moveStart();
  7873. // Reading file format version
  7874. var MAX_VERSION_LENGTH = 12;
  7875. var version = '', ch;
  7876. while ((ch = stream.getByte()) > 0x20) { // SPACE
  7877. if (version.length >= MAX_VERSION_LENGTH) {
  7878. break;
  7879. }
  7880. version += String.fromCharCode(ch);
  7881. }
  7882. // removing "%PDF-"-prefix
  7883. this.pdfFormatVersion = version.substring(5);
  7884. return;
  7885. }
  7886. // May not be a PDF file, continue anyway.
  7887. },
  7888. parseStartXRef: function PDFDocument_parseStartXRef() {
  7889. var startXRef = this.startXRef;
  7890. this.xref.setStartXRef(startXRef);
  7891. },
  7892. setup: function PDFDocument_setup(recoveryMode) {
  7893. this.xref.parse(recoveryMode);
  7894. this.catalog = new Catalog(this.pdfManager, this.xref);
  7895. },
  7896. get numPages() {
  7897. var linearization = this.linearization;
  7898. var num = linearization ? linearization.numPages : this.catalog.numPages;
  7899. // shadow the prototype getter
  7900. return shadow(this, 'numPages', num);
  7901. },
  7902. get documentInfo() {
  7903. var docInfo = {
  7904. PDFFormatVersion: this.pdfFormatVersion,
  7905. IsAcroFormPresent: !!this.acroForm,
  7906. IsXFAPresent: !!this.xfa
  7907. };
  7908. var infoDict;
  7909. try {
  7910. infoDict = this.xref.trailer.get('Info');
  7911. } catch (err) {
  7912. info('The document information dictionary is invalid.');
  7913. }
  7914. if (infoDict) {
  7915. var validEntries = DocumentInfoValidators.entries;
  7916. // Only fill the document info with valid entries from the spec.
  7917. for (var key in validEntries) {
  7918. if (infoDict.has(key)) {
  7919. var value = infoDict.get(key);
  7920. // Make sure the value conforms to the spec.
  7921. if (validEntries[key](value)) {
  7922. docInfo[key] = (typeof value !== 'string' ?
  7923. value : stringToPDFString(value));
  7924. } else {
  7925. info('Bad value in document info for "' + key + '"');
  7926. }
  7927. }
  7928. }
  7929. }
  7930. return shadow(this, 'documentInfo', docInfo);
  7931. },
  7932. get fingerprint() {
  7933. var xref = this.xref, hash, fileID = '';
  7934. if (xref.trailer.has('ID')) {
  7935. hash = stringToBytes(xref.trailer.get('ID')[0]);
  7936. } else {
  7937. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  7938. }
  7939. for (var i = 0, n = hash.length; i < n; i++) {
  7940. fileID += hash[i].toString(16);
  7941. }
  7942. return shadow(this, 'fingerprint', fileID);
  7943. },
  7944. getPage: function PDFDocument_getPage(pageIndex) {
  7945. return this.catalog.getPage(pageIndex);
  7946. },
  7947. cleanup: function PDFDocument_cleanup() {
  7948. return this.catalog.cleanup();
  7949. }
  7950. };
  7951. return PDFDocument;
  7952. })();
  7953. var Name = (function NameClosure() {
  7954. function Name(name) {
  7955. this.name = name;
  7956. }
  7957. Name.prototype = {};
  7958. var nameCache = {};
  7959. Name.get = function Name_get(name) {
  7960. var nameValue = nameCache[name];
  7961. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  7962. };
  7963. return Name;
  7964. })();
  7965. var Cmd = (function CmdClosure() {
  7966. function Cmd(cmd) {
  7967. this.cmd = cmd;
  7968. }
  7969. Cmd.prototype = {};
  7970. var cmdCache = {};
  7971. Cmd.get = function Cmd_get(cmd) {
  7972. var cmdValue = cmdCache[cmd];
  7973. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  7974. };
  7975. return Cmd;
  7976. })();
  7977. var Dict = (function DictClosure() {
  7978. var nonSerializable = function nonSerializableClosure() {
  7979. return nonSerializable; // creating closure on some variable
  7980. };
  7981. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  7982. 'Background': true,
  7983. 'ExtGState': true,
  7984. 'Halftone': true,
  7985. 'Layout': true,
  7986. 'Mask': true,
  7987. 'Pagination': true,
  7988. 'Printing': true
  7989. };
  7990. function isRecursionAllowedFor(dict) {
  7991. if (!isName(dict.Type)) {
  7992. return true;
  7993. }
  7994. var dictType = dict.Type.name;
  7995. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  7996. }
  7997. // xref is optional
  7998. function Dict(xref) {
  7999. // Map should only be used internally, use functions below to access.
  8000. this.map = Object.create(null);
  8001. this.xref = xref;
  8002. this.objId = null;
  8003. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8004. }
  8005. Dict.prototype = {
  8006. assignXref: function Dict_assignXref(newXref) {
  8007. this.xref = newXref;
  8008. },
  8009. // automatically dereferences Ref objects
  8010. get: function Dict_get(key1, key2, key3) {
  8011. var value;
  8012. var xref = this.xref;
  8013. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8014. typeof key2 === 'undefined') {
  8015. return xref ? xref.fetchIfRef(value) : value;
  8016. }
  8017. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8018. typeof key3 === 'undefined') {
  8019. return xref ? xref.fetchIfRef(value) : value;
  8020. }
  8021. value = this.map[key3] || null;
  8022. return xref ? xref.fetchIfRef(value) : value;
  8023. },
  8024. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8025. getAsync: function Dict_getAsync(key1, key2, key3) {
  8026. var value;
  8027. var xref = this.xref;
  8028. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8029. typeof key2 === 'undefined') {
  8030. if (xref) {
  8031. return xref.fetchIfRefAsync(value);
  8032. }
  8033. return Promise.resolve(value);
  8034. }
  8035. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8036. typeof key3 === 'undefined') {
  8037. if (xref) {
  8038. return xref.fetchIfRefAsync(value);
  8039. }
  8040. return Promise.resolve(value);
  8041. }
  8042. value = this.map[key3] || null;
  8043. if (xref) {
  8044. return xref.fetchIfRefAsync(value);
  8045. }
  8046. return Promise.resolve(value);
  8047. },
  8048. // no dereferencing
  8049. getRaw: function Dict_getRaw(key) {
  8050. return this.map[key];
  8051. },
  8052. // creates new map and dereferences all Refs
  8053. getAll: function Dict_getAll() {
  8054. var all = Object.create(null);
  8055. var queue = null;
  8056. var key, obj;
  8057. for (key in this.map) {
  8058. obj = this.get(key);
  8059. if (obj instanceof Dict) {
  8060. if (isRecursionAllowedFor(obj)) {
  8061. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8062. } else {
  8063. all[key] = this.getRaw(key);
  8064. }
  8065. } else {
  8066. all[key] = obj;
  8067. }
  8068. }
  8069. if (!queue) {
  8070. return all;
  8071. }
  8072. // trying to take cyclic references into the account
  8073. var processed = Object.create(null);
  8074. while (queue.length > 0) {
  8075. var item = queue.shift();
  8076. var itemObj = item.obj;
  8077. var objId = itemObj.objId;
  8078. if (objId && objId in processed) {
  8079. item.target[item.key] = processed[objId];
  8080. continue;
  8081. }
  8082. var dereferenced = Object.create(null);
  8083. for (key in itemObj.map) {
  8084. obj = itemObj.get(key);
  8085. if (obj instanceof Dict) {
  8086. if (isRecursionAllowedFor(obj)) {
  8087. queue.push({target: dereferenced, key: key, obj: obj});
  8088. } else {
  8089. dereferenced[key] = itemObj.getRaw(key);
  8090. }
  8091. } else {
  8092. dereferenced[key] = obj;
  8093. }
  8094. }
  8095. if (objId) {
  8096. processed[objId] = dereferenced;
  8097. }
  8098. item.target[item.key] = dereferenced;
  8099. }
  8100. return all;
  8101. },
  8102. set: function Dict_set(key, value) {
  8103. this.map[key] = value;
  8104. },
  8105. has: function Dict_has(key) {
  8106. return key in this.map;
  8107. },
  8108. forEach: function Dict_forEach(callback) {
  8109. for (var key in this.map) {
  8110. callback(key, this.get(key));
  8111. }
  8112. }
  8113. };
  8114. Dict.empty = new Dict(null);
  8115. return Dict;
  8116. })();
  8117. var Ref = (function RefClosure() {
  8118. function Ref(num, gen) {
  8119. this.num = num;
  8120. this.gen = gen;
  8121. }
  8122. Ref.prototype = {
  8123. toString: function Ref_toString() {
  8124. // This function is hot, so we make the string as compact as possible.
  8125. // |this.gen| is almost always zero, so we treat that case specially.
  8126. var str = this.num + 'R';
  8127. if (this.gen !== 0) {
  8128. str += this.gen;
  8129. }
  8130. return str;
  8131. }
  8132. };
  8133. return Ref;
  8134. })();
  8135. // The reference is identified by number and generation.
  8136. // This structure stores only one instance of the reference.
  8137. var RefSet = (function RefSetClosure() {
  8138. function RefSet() {
  8139. this.dict = {};
  8140. }
  8141. RefSet.prototype = {
  8142. has: function RefSet_has(ref) {
  8143. return ref.toString() in this.dict;
  8144. },
  8145. put: function RefSet_put(ref) {
  8146. this.dict[ref.toString()] = true;
  8147. },
  8148. remove: function RefSet_remove(ref) {
  8149. delete this.dict[ref.toString()];
  8150. }
  8151. };
  8152. return RefSet;
  8153. })();
  8154. var RefSetCache = (function RefSetCacheClosure() {
  8155. function RefSetCache() {
  8156. this.dict = Object.create(null);
  8157. }
  8158. RefSetCache.prototype = {
  8159. get: function RefSetCache_get(ref) {
  8160. return this.dict[ref.toString()];
  8161. },
  8162. has: function RefSetCache_has(ref) {
  8163. return ref.toString() in this.dict;
  8164. },
  8165. put: function RefSetCache_put(ref, obj) {
  8166. this.dict[ref.toString()] = obj;
  8167. },
  8168. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8169. this.dict[ref.toString()] = this.get(aliasRef);
  8170. },
  8171. forEach: function RefSetCache_forEach(fn, thisArg) {
  8172. for (var i in this.dict) {
  8173. fn.call(thisArg, this.dict[i]);
  8174. }
  8175. },
  8176. clear: function RefSetCache_clear() {
  8177. this.dict = Object.create(null);
  8178. }
  8179. };
  8180. return RefSetCache;
  8181. })();
  8182. var Catalog = (function CatalogClosure() {
  8183. function Catalog(pdfManager, xref) {
  8184. this.pdfManager = pdfManager;
  8185. this.xref = xref;
  8186. this.catDict = xref.getCatalogObj();
  8187. this.fontCache = new RefSetCache();
  8188. assert(isDict(this.catDict),
  8189. 'catalog object is not a dictionary');
  8190. this.pagePromises = [];
  8191. }
  8192. Catalog.prototype = {
  8193. get metadata() {
  8194. var streamRef = this.catDict.getRaw('Metadata');
  8195. if (!isRef(streamRef)) {
  8196. return shadow(this, 'metadata', null);
  8197. }
  8198. var encryptMetadata = (!this.xref.encrypt ? false :
  8199. this.xref.encrypt.encryptMetadata);
  8200. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8201. var metadata;
  8202. if (stream && isDict(stream.dict)) {
  8203. var type = stream.dict.get('Type');
  8204. var subtype = stream.dict.get('Subtype');
  8205. if (isName(type) && isName(subtype) &&
  8206. type.name === 'Metadata' && subtype.name === 'XML') {
  8207. // XXX: This should examine the charset the XML document defines,
  8208. // however since there are currently no real means to decode
  8209. // arbitrary charsets, let's just hope that the author of the PDF
  8210. // was reasonable enough to stick with the XML default charset,
  8211. // which is UTF-8.
  8212. try {
  8213. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8214. } catch (e) {
  8215. info('Skipping invalid metadata.');
  8216. }
  8217. }
  8218. }
  8219. return shadow(this, 'metadata', metadata);
  8220. },
  8221. get toplevelPagesDict() {
  8222. var pagesObj = this.catDict.get('Pages');
  8223. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8224. // shadow the prototype getter
  8225. return shadow(this, 'toplevelPagesDict', pagesObj);
  8226. },
  8227. get documentOutline() {
  8228. var obj = null;
  8229. try {
  8230. obj = this.readDocumentOutline();
  8231. } catch (ex) {
  8232. if (ex instanceof MissingDataException) {
  8233. throw ex;
  8234. }
  8235. warn('Unable to read document outline');
  8236. }
  8237. return shadow(this, 'documentOutline', obj);
  8238. },
  8239. readDocumentOutline: function Catalog_readDocumentOutline() {
  8240. var xref = this.xref;
  8241. var obj = this.catDict.get('Outlines');
  8242. var root = { items: [] };
  8243. if (isDict(obj)) {
  8244. obj = obj.getRaw('First');
  8245. var processed = new RefSet();
  8246. if (isRef(obj)) {
  8247. var queue = [{obj: obj, parent: root}];
  8248. // to avoid recursion keeping track of the items
  8249. // in the processed dictionary
  8250. processed.put(obj);
  8251. while (queue.length > 0) {
  8252. var i = queue.shift();
  8253. var outlineDict = xref.fetchIfRef(i.obj);
  8254. if (outlineDict === null) {
  8255. continue;
  8256. }
  8257. if (!outlineDict.has('Title')) {
  8258. error('Invalid outline item');
  8259. }
  8260. var dest = outlineDict.get('A');
  8261. if (dest) {
  8262. dest = dest.get('D');
  8263. } else if (outlineDict.has('Dest')) {
  8264. dest = outlineDict.getRaw('Dest');
  8265. if (isName(dest)) {
  8266. dest = dest.name;
  8267. }
  8268. }
  8269. var title = outlineDict.get('Title');
  8270. var outlineItem = {
  8271. dest: dest,
  8272. title: stringToPDFString(title),
  8273. color: outlineDict.get('C') || [0, 0, 0],
  8274. count: outlineDict.get('Count'),
  8275. bold: !!(outlineDict.get('F') & 2),
  8276. italic: !!(outlineDict.get('F') & 1),
  8277. items: []
  8278. };
  8279. i.parent.items.push(outlineItem);
  8280. obj = outlineDict.getRaw('First');
  8281. if (isRef(obj) && !processed.has(obj)) {
  8282. queue.push({obj: obj, parent: outlineItem});
  8283. processed.put(obj);
  8284. }
  8285. obj = outlineDict.getRaw('Next');
  8286. if (isRef(obj) && !processed.has(obj)) {
  8287. queue.push({obj: obj, parent: i.parent});
  8288. processed.put(obj);
  8289. }
  8290. }
  8291. }
  8292. }
  8293. return (root.items.length > 0 ? root.items : null);
  8294. },
  8295. get numPages() {
  8296. var obj = this.toplevelPagesDict.get('Count');
  8297. assert(
  8298. isInt(obj),
  8299. 'page count in top level pages object is not an integer'
  8300. );
  8301. // shadow the prototype getter
  8302. return shadow(this, 'num', obj);
  8303. },
  8304. get destinations() {
  8305. function fetchDestination(dest) {
  8306. return isDict(dest) ? dest.get('D') : dest;
  8307. }
  8308. var xref = this.xref;
  8309. var dests = {}, nameTreeRef, nameDictionaryRef;
  8310. var obj = this.catDict.get('Names');
  8311. if (obj && obj.has('Dests')) {
  8312. nameTreeRef = obj.getRaw('Dests');
  8313. } else if (this.catDict.has('Dests')) {
  8314. nameDictionaryRef = this.catDict.get('Dests');
  8315. }
  8316. if (nameDictionaryRef) {
  8317. // reading simple destination dictionary
  8318. obj = nameDictionaryRef;
  8319. obj.forEach(function catalogForEach(key, value) {
  8320. if (!value) {
  8321. return;
  8322. }
  8323. dests[key] = fetchDestination(value);
  8324. });
  8325. }
  8326. if (nameTreeRef) {
  8327. var nameTree = new NameTree(nameTreeRef, xref);
  8328. var names = nameTree.getAll();
  8329. for (var name in names) {
  8330. if (!names.hasOwnProperty(name)) {
  8331. continue;
  8332. }
  8333. dests[name] = fetchDestination(names[name]);
  8334. }
  8335. }
  8336. return shadow(this, 'destinations', dests);
  8337. },
  8338. get attachments() {
  8339. var xref = this.xref;
  8340. var attachments = null, nameTreeRef;
  8341. var obj = this.catDict.get('Names');
  8342. if (obj) {
  8343. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8344. }
  8345. if (nameTreeRef) {
  8346. var nameTree = new NameTree(nameTreeRef, xref);
  8347. var names = nameTree.getAll();
  8348. for (var name in names) {
  8349. if (!names.hasOwnProperty(name)) {
  8350. continue;
  8351. }
  8352. var fs = new FileSpec(names[name], xref);
  8353. if (!attachments) {
  8354. attachments = {};
  8355. }
  8356. attachments[stringToPDFString(name)] = fs.serializable;
  8357. }
  8358. }
  8359. return shadow(this, 'attachments', attachments);
  8360. },
  8361. get javaScript() {
  8362. var xref = this.xref;
  8363. var obj = this.catDict.get('Names');
  8364. var javaScript = [];
  8365. if (obj && obj.has('JavaScript')) {
  8366. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8367. var names = nameTree.getAll();
  8368. for (var name in names) {
  8369. if (!names.hasOwnProperty(name)) {
  8370. continue;
  8371. }
  8372. // We don't really use the JavaScript right now. This code is
  8373. // defensive so we don't cause errors on document load.
  8374. var jsDict = names[name];
  8375. if (!isDict(jsDict)) {
  8376. continue;
  8377. }
  8378. var type = jsDict.get('S');
  8379. if (!isName(type) || type.name !== 'JavaScript') {
  8380. continue;
  8381. }
  8382. var js = jsDict.get('JS');
  8383. if (!isString(js) && !isStream(js)) {
  8384. continue;
  8385. }
  8386. if (isStream(js)) {
  8387. js = bytesToString(js.getBytes());
  8388. }
  8389. javaScript.push(stringToPDFString(js));
  8390. }
  8391. }
  8392. // Append OpenAction actions to javaScript array
  8393. var openactionDict = this.catDict.get('OpenAction');
  8394. if (isDict(openactionDict)) {
  8395. var objType = openactionDict.get('Type');
  8396. var actionType = openactionDict.get('S');
  8397. var action = openactionDict.get('N');
  8398. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8399. isName(actionType) && actionType.name === 'Named' &&
  8400. isName(action) && action.name === 'Print');
  8401. if (isPrintAction) {
  8402. javaScript.push('print(true);');
  8403. }
  8404. }
  8405. return shadow(this, 'javaScript', javaScript);
  8406. },
  8407. cleanup: function Catalog_cleanup() {
  8408. var promises = [];
  8409. this.fontCache.forEach(function (promise) {
  8410. promises.push(promise);
  8411. });
  8412. return Promise.all(promises).then(function (translatedFonts) {
  8413. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8414. var font = translatedFonts[i].dict;
  8415. delete font.translated;
  8416. }
  8417. this.fontCache.clear();
  8418. }.bind(this));
  8419. },
  8420. getPage: function Catalog_getPage(pageIndex) {
  8421. if (!(pageIndex in this.pagePromises)) {
  8422. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8423. function (a) {
  8424. var dict = a[0];
  8425. var ref = a[1];
  8426. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8427. this.fontCache);
  8428. }.bind(this)
  8429. );
  8430. }
  8431. return this.pagePromises[pageIndex];
  8432. },
  8433. getPageDict: function Catalog_getPageDict(pageIndex) {
  8434. var capability = createPromiseCapability();
  8435. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8436. var currentPageIndex = 0;
  8437. var xref = this.xref;
  8438. function next() {
  8439. while (nodesToVisit.length) {
  8440. var currentNode = nodesToVisit.pop();
  8441. if (isRef(currentNode)) {
  8442. xref.fetchAsync(currentNode).then(function (obj) {
  8443. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  8444. if (pageIndex === currentPageIndex) {
  8445. capability.resolve([obj, currentNode]);
  8446. } else {
  8447. currentPageIndex++;
  8448. next();
  8449. }
  8450. return;
  8451. }
  8452. nodesToVisit.push(obj);
  8453. next();
  8454. }, capability.reject);
  8455. return;
  8456. }
  8457. // must be a child page dictionary
  8458. assert(
  8459. isDict(currentNode),
  8460. 'page dictionary kid reference points to wrong type of object'
  8461. );
  8462. var count = currentNode.get('Count');
  8463. // Skip nodes where the page can't be.
  8464. if (currentPageIndex + count <= pageIndex) {
  8465. currentPageIndex += count;
  8466. continue;
  8467. }
  8468. var kids = currentNode.get('Kids');
  8469. assert(isArray(kids), 'page dictionary kids object is not an array');
  8470. if (count === kids.length) {
  8471. // Nodes that don't have the page have been skipped and this is the
  8472. // bottom of the tree which means the page requested must be a
  8473. // descendant of this pages node. Ideally we would just resolve the
  8474. // promise with the page ref here, but there is the case where more
  8475. // pages nodes could link to single a page (see issue 3666 pdf). To
  8476. // handle this push it back on the queue so if it is a pages node it
  8477. // will be descended into.
  8478. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8479. currentPageIndex = pageIndex;
  8480. continue;
  8481. } else {
  8482. for (var last = kids.length - 1; last >= 0; last--) {
  8483. nodesToVisit.push(kids[last]);
  8484. }
  8485. }
  8486. }
  8487. capability.reject('Page index ' + pageIndex + ' not found.');
  8488. }
  8489. next();
  8490. return capability.promise;
  8491. },
  8492. getPageIndex: function Catalog_getPageIndex(ref) {
  8493. // The page tree nodes have the count of all the leaves below them. To get
  8494. // how many pages are before we just have to walk up the tree and keep
  8495. // adding the count of siblings to the left of the node.
  8496. var xref = this.xref;
  8497. function pagesBeforeRef(kidRef) {
  8498. var total = 0;
  8499. var parentRef;
  8500. return xref.fetchAsync(kidRef).then(function (node) {
  8501. if (!node) {
  8502. return null;
  8503. }
  8504. parentRef = node.getRaw('Parent');
  8505. return node.getAsync('Parent');
  8506. }).then(function (parent) {
  8507. if (!parent) {
  8508. return null;
  8509. }
  8510. return parent.getAsync('Kids');
  8511. }).then(function (kids) {
  8512. if (!kids) {
  8513. return null;
  8514. }
  8515. var kidPromises = [];
  8516. var found = false;
  8517. for (var i = 0; i < kids.length; i++) {
  8518. var kid = kids[i];
  8519. assert(isRef(kid), 'kids must be a ref');
  8520. if (kid.num === kidRef.num) {
  8521. found = true;
  8522. break;
  8523. }
  8524. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8525. if (kid.has('Count')) {
  8526. var count = kid.get('Count');
  8527. total += count;
  8528. } else { // page leaf node
  8529. total++;
  8530. }
  8531. }));
  8532. }
  8533. if (!found) {
  8534. error('kid ref not found in parents kids');
  8535. }
  8536. return Promise.all(kidPromises).then(function () {
  8537. return [total, parentRef];
  8538. });
  8539. });
  8540. }
  8541. var total = 0;
  8542. function next(ref) {
  8543. return pagesBeforeRef(ref).then(function (args) {
  8544. if (!args) {
  8545. return total;
  8546. }
  8547. var count = args[0];
  8548. var parentRef = args[1];
  8549. total += count;
  8550. return next(parentRef);
  8551. });
  8552. }
  8553. return next(ref);
  8554. }
  8555. };
  8556. return Catalog;
  8557. })();
  8558. var XRef = (function XRefClosure() {
  8559. function XRef(stream, password) {
  8560. this.stream = stream;
  8561. this.entries = [];
  8562. this.xrefstms = {};
  8563. // prepare the XRef cache
  8564. this.cache = [];
  8565. this.password = password;
  8566. this.stats = {
  8567. streamTypes: [],
  8568. fontTypes: []
  8569. };
  8570. }
  8571. XRef.prototype = {
  8572. setStartXRef: function XRef_setStartXRef(startXRef) {
  8573. // Store the starting positions of xref tables as we process them
  8574. // so we can recover from missing data errors
  8575. this.startXRefQueue = [startXRef];
  8576. },
  8577. parse: function XRef_parse(recoveryMode) {
  8578. var trailerDict;
  8579. if (!recoveryMode) {
  8580. trailerDict = this.readXRef();
  8581. } else {
  8582. warn('Indexing all PDF objects');
  8583. trailerDict = this.indexObjects();
  8584. }
  8585. trailerDict.assignXref(this);
  8586. this.trailer = trailerDict;
  8587. var encrypt = trailerDict.get('Encrypt');
  8588. if (encrypt) {
  8589. var ids = trailerDict.get('ID');
  8590. var fileId = (ids && ids.length) ? ids[0] : '';
  8591. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  8592. this.password);
  8593. }
  8594. // get the root dictionary (catalog) object
  8595. if (!(this.root = trailerDict.get('Root'))) {
  8596. error('Invalid root reference');
  8597. }
  8598. },
  8599. processXRefTable: function XRef_processXRefTable(parser) {
  8600. if (!('tableState' in this)) {
  8601. // Stores state of the table as we process it so we can resume
  8602. // from middle of table in case of missing data error
  8603. this.tableState = {
  8604. entryNum: 0,
  8605. streamPos: parser.lexer.stream.pos,
  8606. parserBuf1: parser.buf1,
  8607. parserBuf2: parser.buf2
  8608. };
  8609. }
  8610. var obj = this.readXRefTable(parser);
  8611. // Sanity check
  8612. if (!isCmd(obj, 'trailer')) {
  8613. error('Invalid XRef table: could not find trailer dictionary');
  8614. }
  8615. // Read trailer dictionary, e.g.
  8616. // trailer
  8617. // << /Size 22
  8618. // /Root 20R
  8619. // /Info 10R
  8620. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  8621. // >>
  8622. // The parser goes through the entire stream << ... >> and provides
  8623. // a getter interface for the key-value table
  8624. var dict = parser.getObj();
  8625. // The pdflib PDF generator can generate a nested trailer dictionary
  8626. if (!isDict(dict) && dict.dict) {
  8627. dict = dict.dict;
  8628. }
  8629. if (!isDict(dict)) {
  8630. error('Invalid XRef table: could not parse trailer dictionary');
  8631. }
  8632. delete this.tableState;
  8633. return dict;
  8634. },
  8635. readXRefTable: function XRef_readXRefTable(parser) {
  8636. // Example of cross-reference table:
  8637. // xref
  8638. // 0 1 <-- subsection header (first obj #, obj count)
  8639. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  8640. // 23 2 <-- subsection header ... and so on ...
  8641. // 0000025518 00002 n
  8642. // 0000025635 00000 n
  8643. // trailer
  8644. // ...
  8645. var stream = parser.lexer.stream;
  8646. var tableState = this.tableState;
  8647. stream.pos = tableState.streamPos;
  8648. parser.buf1 = tableState.parserBuf1;
  8649. parser.buf2 = tableState.parserBuf2;
  8650. // Outer loop is over subsection headers
  8651. var obj;
  8652. while (true) {
  8653. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  8654. if (isCmd(obj = parser.getObj(), 'trailer')) {
  8655. break;
  8656. }
  8657. tableState.firstEntryNum = obj;
  8658. tableState.entryCount = parser.getObj();
  8659. }
  8660. var first = tableState.firstEntryNum;
  8661. var count = tableState.entryCount;
  8662. if (!isInt(first) || !isInt(count)) {
  8663. error('Invalid XRef table: wrong types in subsection header');
  8664. }
  8665. // Inner loop is over objects themselves
  8666. for (var i = tableState.entryNum; i < count; i++) {
  8667. tableState.streamPos = stream.pos;
  8668. tableState.entryNum = i;
  8669. tableState.parserBuf1 = parser.buf1;
  8670. tableState.parserBuf2 = parser.buf2;
  8671. var entry = {};
  8672. entry.offset = parser.getObj();
  8673. entry.gen = parser.getObj();
  8674. var type = parser.getObj();
  8675. if (isCmd(type, 'f')) {
  8676. entry.free = true;
  8677. } else if (isCmd(type, 'n')) {
  8678. entry.uncompressed = true;
  8679. }
  8680. // Validate entry obj
  8681. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  8682. !(entry.free || entry.uncompressed)) {
  8683. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  8684. }
  8685. if (!this.entries[i + first]) {
  8686. this.entries[i + first] = entry;
  8687. }
  8688. }
  8689. tableState.entryNum = 0;
  8690. tableState.streamPos = stream.pos;
  8691. tableState.parserBuf1 = parser.buf1;
  8692. tableState.parserBuf2 = parser.buf2;
  8693. delete tableState.firstEntryNum;
  8694. delete tableState.entryCount;
  8695. }
  8696. // Per issue 3248: hp scanners generate bad XRef
  8697. if (first === 1 && this.entries[1] && this.entries[1].free) {
  8698. // shifting the entries
  8699. this.entries.shift();
  8700. }
  8701. // Sanity check: as per spec, first object must be free
  8702. if (this.entries[0] && !this.entries[0].free) {
  8703. error('Invalid XRef table: unexpected first object');
  8704. }
  8705. return obj;
  8706. },
  8707. processXRefStream: function XRef_processXRefStream(stream) {
  8708. if (!('streamState' in this)) {
  8709. // Stores state of the stream as we process it so we can resume
  8710. // from middle of stream in case of missing data error
  8711. var streamParameters = stream.dict;
  8712. var byteWidths = streamParameters.get('W');
  8713. var range = streamParameters.get('Index');
  8714. if (!range) {
  8715. range = [0, streamParameters.get('Size')];
  8716. }
  8717. this.streamState = {
  8718. entryRanges: range,
  8719. byteWidths: byteWidths,
  8720. entryNum: 0,
  8721. streamPos: stream.pos
  8722. };
  8723. }
  8724. this.readXRefStream(stream);
  8725. delete this.streamState;
  8726. return stream.dict;
  8727. },
  8728. readXRefStream: function XRef_readXRefStream(stream) {
  8729. var i, j;
  8730. var streamState = this.streamState;
  8731. stream.pos = streamState.streamPos;
  8732. var byteWidths = streamState.byteWidths;
  8733. var typeFieldWidth = byteWidths[0];
  8734. var offsetFieldWidth = byteWidths[1];
  8735. var generationFieldWidth = byteWidths[2];
  8736. var entryRanges = streamState.entryRanges;
  8737. while (entryRanges.length > 0) {
  8738. var first = entryRanges[0];
  8739. var n = entryRanges[1];
  8740. if (!isInt(first) || !isInt(n)) {
  8741. error('Invalid XRef range fields: ' + first + ', ' + n);
  8742. }
  8743. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  8744. !isInt(generationFieldWidth)) {
  8745. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  8746. }
  8747. for (i = streamState.entryNum; i < n; ++i) {
  8748. streamState.entryNum = i;
  8749. streamState.streamPos = stream.pos;
  8750. var type = 0, offset = 0, generation = 0;
  8751. for (j = 0; j < typeFieldWidth; ++j) {
  8752. type = (type << 8) | stream.getByte();
  8753. }
  8754. // if type field is absent, its default value is 1
  8755. if (typeFieldWidth === 0) {
  8756. type = 1;
  8757. }
  8758. for (j = 0; j < offsetFieldWidth; ++j) {
  8759. offset = (offset << 8) | stream.getByte();
  8760. }
  8761. for (j = 0; j < generationFieldWidth; ++j) {
  8762. generation = (generation << 8) | stream.getByte();
  8763. }
  8764. var entry = {};
  8765. entry.offset = offset;
  8766. entry.gen = generation;
  8767. switch (type) {
  8768. case 0:
  8769. entry.free = true;
  8770. break;
  8771. case 1:
  8772. entry.uncompressed = true;
  8773. break;
  8774. case 2:
  8775. break;
  8776. default:
  8777. error('Invalid XRef entry type: ' + type);
  8778. }
  8779. if (!this.entries[first + i]) {
  8780. this.entries[first + i] = entry;
  8781. }
  8782. }
  8783. streamState.entryNum = 0;
  8784. streamState.streamPos = stream.pos;
  8785. entryRanges.splice(0, 2);
  8786. }
  8787. },
  8788. indexObjects: function XRef_indexObjects() {
  8789. // Simple scan through the PDF content to find objects,
  8790. // trailers and XRef streams.
  8791. function readToken(data, offset) {
  8792. var token = '', ch = data[offset];
  8793. while (ch !== 13 && ch !== 10) {
  8794. if (++offset >= data.length) {
  8795. break;
  8796. }
  8797. token += String.fromCharCode(ch);
  8798. ch = data[offset];
  8799. }
  8800. return token;
  8801. }
  8802. function skipUntil(data, offset, what) {
  8803. var length = what.length, dataLength = data.length;
  8804. var skipped = 0;
  8805. // finding byte sequence
  8806. while (offset < dataLength) {
  8807. var i = 0;
  8808. while (i < length && data[offset + i] === what[i]) {
  8809. ++i;
  8810. }
  8811. if (i >= length) {
  8812. break; // sequence found
  8813. }
  8814. offset++;
  8815. skipped++;
  8816. }
  8817. return skipped;
  8818. }
  8819. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  8820. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  8821. 101, 102]);
  8822. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  8823. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  8824. var stream = this.stream;
  8825. stream.pos = 0;
  8826. var buffer = stream.getBytes();
  8827. var position = stream.start, length = buffer.length;
  8828. var trailers = [], xrefStms = [];
  8829. while (position < length) {
  8830. var ch = buffer[position];
  8831. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  8832. ++position;
  8833. continue;
  8834. }
  8835. if (ch === 37) { // %-comment
  8836. do {
  8837. ++position;
  8838. if (position >= length) {
  8839. break;
  8840. }
  8841. ch = buffer[position];
  8842. } while (ch !== 13 && ch !== 10);
  8843. continue;
  8844. }
  8845. var token = readToken(buffer, position);
  8846. var m;
  8847. if (token === 'xref') {
  8848. position += skipUntil(buffer, position, trailerBytes);
  8849. trailers.push(position);
  8850. position += skipUntil(buffer, position, startxrefBytes);
  8851. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  8852. this.entries[m[1]] = {
  8853. offset: position,
  8854. gen: m[2] | 0,
  8855. uncompressed: true
  8856. };
  8857. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  8858. var content = buffer.subarray(position, position + contentLength);
  8859. // checking XRef stream suspect
  8860. // (it shall have '/XRef' and next char is not a letter)
  8861. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  8862. if (xrefTagOffset < contentLength &&
  8863. content[xrefTagOffset + 5] < 64) {
  8864. xrefStms.push(position);
  8865. this.xrefstms[position] = 1; // don't read it recursively
  8866. }
  8867. position += contentLength;
  8868. } else {
  8869. position += token.length + 1;
  8870. }
  8871. }
  8872. // reading XRef streams
  8873. var i, ii;
  8874. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  8875. this.startXRefQueue.push(xrefStms[i]);
  8876. this.readXRef(/* recoveryMode */ true);
  8877. }
  8878. // finding main trailer
  8879. var dict;
  8880. for (i = 0, ii = trailers.length; i < ii; ++i) {
  8881. stream.pos = trailers[i];
  8882. var parser = new Parser(new Lexer(stream), true, this);
  8883. var obj = parser.getObj();
  8884. if (!isCmd(obj, 'trailer')) {
  8885. continue;
  8886. }
  8887. // read the trailer dictionary
  8888. if (!isDict(dict = parser.getObj())) {
  8889. continue;
  8890. }
  8891. // taking the first one with 'ID'
  8892. if (dict.has('ID')) {
  8893. return dict;
  8894. }
  8895. }
  8896. // no tailer with 'ID', taking last one (if exists)
  8897. if (dict) {
  8898. return dict;
  8899. }
  8900. // nothing helps
  8901. // calling error() would reject worker with an UnknownErrorException.
  8902. throw new InvalidPDFException('Invalid PDF structure');
  8903. },
  8904. readXRef: function XRef_readXRef(recoveryMode) {
  8905. var stream = this.stream;
  8906. try {
  8907. while (this.startXRefQueue.length) {
  8908. var startXRef = this.startXRefQueue[0];
  8909. stream.pos = startXRef + stream.start;
  8910. var parser = new Parser(new Lexer(stream), true, this);
  8911. var obj = parser.getObj();
  8912. var dict;
  8913. // Get dictionary
  8914. if (isCmd(obj, 'xref')) {
  8915. // Parse end-of-file XRef
  8916. dict = this.processXRefTable(parser);
  8917. if (!this.topDict) {
  8918. this.topDict = dict;
  8919. }
  8920. // Recursively get other XRefs 'XRefStm', if any
  8921. obj = dict.get('XRefStm');
  8922. if (isInt(obj)) {
  8923. var pos = obj;
  8924. // ignore previously loaded xref streams
  8925. // (possible infinite recursion)
  8926. if (!(pos in this.xrefstms)) {
  8927. this.xrefstms[pos] = 1;
  8928. this.startXRefQueue.push(pos);
  8929. }
  8930. }
  8931. } else if (isInt(obj)) {
  8932. // Parse in-stream XRef
  8933. if (!isInt(parser.getObj()) ||
  8934. !isCmd(parser.getObj(), 'obj') ||
  8935. !isStream(obj = parser.getObj())) {
  8936. error('Invalid XRef stream');
  8937. }
  8938. dict = this.processXRefStream(obj);
  8939. if (!this.topDict) {
  8940. this.topDict = dict;
  8941. }
  8942. if (!dict) {
  8943. error('Failed to read XRef stream');
  8944. }
  8945. } else {
  8946. error('Invalid XRef stream header');
  8947. }
  8948. // Recursively get previous dictionary, if any
  8949. obj = dict.get('Prev');
  8950. if (isInt(obj)) {
  8951. this.startXRefQueue.push(obj);
  8952. } else if (isRef(obj)) {
  8953. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  8954. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  8955. this.startXRefQueue.push(obj.num);
  8956. }
  8957. this.startXRefQueue.shift();
  8958. }
  8959. return this.topDict;
  8960. } catch (e) {
  8961. if (e instanceof MissingDataException) {
  8962. throw e;
  8963. }
  8964. info('(while reading XRef): ' + e);
  8965. }
  8966. if (recoveryMode) {
  8967. return;
  8968. }
  8969. throw new XRefParseException();
  8970. },
  8971. getEntry: function XRef_getEntry(i) {
  8972. var xrefEntry = this.entries[i];
  8973. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  8974. return xrefEntry;
  8975. }
  8976. return null;
  8977. },
  8978. fetchIfRef: function XRef_fetchIfRef(obj) {
  8979. if (!isRef(obj)) {
  8980. return obj;
  8981. }
  8982. return this.fetch(obj);
  8983. },
  8984. fetch: function XRef_fetch(ref, suppressEncryption) {
  8985. assert(isRef(ref), 'ref object is not a reference');
  8986. var num = ref.num;
  8987. if (num in this.cache) {
  8988. var cacheEntry = this.cache[num];
  8989. return cacheEntry;
  8990. }
  8991. var xrefEntry = this.getEntry(num);
  8992. // the referenced entry can be free
  8993. if (xrefEntry === null) {
  8994. return (this.cache[num] = null);
  8995. }
  8996. if (xrefEntry.uncompressed) {
  8997. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  8998. } else {
  8999. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9000. }
  9001. if (isDict(xrefEntry)){
  9002. xrefEntry.objId = ref.toString();
  9003. } else if (isStream(xrefEntry)) {
  9004. xrefEntry.dict.objId = ref.toString();
  9005. }
  9006. return xrefEntry;
  9007. },
  9008. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9009. suppressEncryption) {
  9010. var gen = ref.gen;
  9011. var num = ref.num;
  9012. if (xrefEntry.gen !== gen) {
  9013. error('inconsistent generation in XRef');
  9014. }
  9015. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9016. this.stream.start);
  9017. var parser = new Parser(new Lexer(stream), true, this);
  9018. var obj1 = parser.getObj();
  9019. var obj2 = parser.getObj();
  9020. var obj3 = parser.getObj();
  9021. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9022. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9023. !isCmd(obj3)) {
  9024. error('bad XRef entry');
  9025. }
  9026. if (!isCmd(obj3, 'obj')) {
  9027. // some bad PDFs use "obj1234" and really mean 1234
  9028. if (obj3.cmd.indexOf('obj') === 0) {
  9029. num = parseInt(obj3.cmd.substring(3), 10);
  9030. if (!isNaN(num)) {
  9031. return num;
  9032. }
  9033. }
  9034. error('bad XRef entry');
  9035. }
  9036. if (this.encrypt && !suppressEncryption) {
  9037. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9038. } else {
  9039. xrefEntry = parser.getObj();
  9040. }
  9041. if (!isStream(xrefEntry)) {
  9042. this.cache[num] = xrefEntry;
  9043. }
  9044. return xrefEntry;
  9045. },
  9046. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9047. suppressEncryption) {
  9048. var tableOffset = xrefEntry.offset;
  9049. var stream = this.fetch(new Ref(tableOffset, 0));
  9050. if (!isStream(stream)) {
  9051. error('bad ObjStm stream');
  9052. }
  9053. var first = stream.dict.get('First');
  9054. var n = stream.dict.get('N');
  9055. if (!isInt(first) || !isInt(n)) {
  9056. error('invalid first and n parameters for ObjStm stream');
  9057. }
  9058. var parser = new Parser(new Lexer(stream), false, this);
  9059. parser.allowStreams = true;
  9060. var i, entries = [], num, nums = [];
  9061. // read the object numbers to populate cache
  9062. for (i = 0; i < n; ++i) {
  9063. num = parser.getObj();
  9064. if (!isInt(num)) {
  9065. error('invalid object number in the ObjStm stream: ' + num);
  9066. }
  9067. nums.push(num);
  9068. var offset = parser.getObj();
  9069. if (!isInt(offset)) {
  9070. error('invalid object offset in the ObjStm stream: ' + offset);
  9071. }
  9072. }
  9073. // read stream objects for cache
  9074. for (i = 0; i < n; ++i) {
  9075. entries.push(parser.getObj());
  9076. num = nums[i];
  9077. var entry = this.entries[num];
  9078. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9079. this.cache[num] = entries[i];
  9080. }
  9081. }
  9082. xrefEntry = entries[xrefEntry.gen];
  9083. if (xrefEntry === undefined) {
  9084. error('bad XRef entry for compressed object');
  9085. }
  9086. return xrefEntry;
  9087. },
  9088. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9089. if (!isRef(obj)) {
  9090. return Promise.resolve(obj);
  9091. }
  9092. return this.fetchAsync(obj);
  9093. },
  9094. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9095. var streamManager = this.stream.manager;
  9096. var xref = this;
  9097. return new Promise(function tryFetch(resolve, reject) {
  9098. try {
  9099. resolve(xref.fetch(ref, suppressEncryption));
  9100. } catch (e) {
  9101. if (e instanceof MissingDataException) {
  9102. streamManager.requestRange(e.begin, e.end, function () {
  9103. tryFetch(resolve, reject);
  9104. });
  9105. return;
  9106. }
  9107. reject(e);
  9108. }
  9109. });
  9110. },
  9111. getCatalogObj: function XRef_getCatalogObj() {
  9112. return this.root;
  9113. }
  9114. };
  9115. return XRef;
  9116. })();
  9117. /**
  9118. * A NameTree is like a Dict but has some advantageous properties, see the
  9119. * spec (7.9.6) for more details.
  9120. * TODO: implement all the Dict functions and make this more efficent.
  9121. */
  9122. var NameTree = (function NameTreeClosure() {
  9123. function NameTree(root, xref) {
  9124. this.root = root;
  9125. this.xref = xref;
  9126. }
  9127. NameTree.prototype = {
  9128. getAll: function NameTree_getAll() {
  9129. var dict = {};
  9130. if (!this.root) {
  9131. return dict;
  9132. }
  9133. var xref = this.xref;
  9134. // reading name tree
  9135. var processed = new RefSet();
  9136. processed.put(this.root);
  9137. var queue = [this.root];
  9138. while (queue.length > 0) {
  9139. var i, n;
  9140. var obj = xref.fetchIfRef(queue.shift());
  9141. if (!isDict(obj)) {
  9142. continue;
  9143. }
  9144. if (obj.has('Kids')) {
  9145. var kids = obj.get('Kids');
  9146. for (i = 0, n = kids.length; i < n; i++) {
  9147. var kid = kids[i];
  9148. if (processed.has(kid)) {
  9149. error('invalid destinations');
  9150. }
  9151. queue.push(kid);
  9152. processed.put(kid);
  9153. }
  9154. continue;
  9155. }
  9156. var names = obj.get('Names');
  9157. if (names) {
  9158. for (i = 0, n = names.length; i < n; i += 2) {
  9159. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9160. }
  9161. }
  9162. }
  9163. return dict;
  9164. }
  9165. };
  9166. return NameTree;
  9167. })();
  9168. /**
  9169. * "A PDF file can refer to the contents of another file by using a File
  9170. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9171. * NOTE: Only embedded files are supported (as part of the attachments support)
  9172. * TODO: support the 'URL' file system (with caching if !/V), portable
  9173. * collections attributes and related files (/RF)
  9174. */
  9175. var FileSpec = (function FileSpecClosure() {
  9176. function FileSpec(root, xref) {
  9177. if (!root || !isDict(root)) {
  9178. return;
  9179. }
  9180. this.xref = xref;
  9181. this.root = root;
  9182. if (root.has('FS')) {
  9183. this.fs = root.get('FS');
  9184. }
  9185. this.description = root.has('Desc') ?
  9186. stringToPDFString(root.get('Desc')) :
  9187. '';
  9188. if (root.has('RF')) {
  9189. warn('Related file specifications are not supported');
  9190. }
  9191. this.contentAvailable = true;
  9192. if (!root.has('EF')) {
  9193. this.contentAvailable = false;
  9194. warn('Non-embedded file specifications are not supported');
  9195. }
  9196. }
  9197. function pickPlatformItem(dict) {
  9198. // Look for the filename in this order:
  9199. // UF, F, Unix, Mac, DOS
  9200. if (dict.has('UF')) {
  9201. return dict.get('UF');
  9202. } else if (dict.has('F')) {
  9203. return dict.get('F');
  9204. } else if (dict.has('Unix')) {
  9205. return dict.get('Unix');
  9206. } else if (dict.has('Mac')) {
  9207. return dict.get('Mac');
  9208. } else if (dict.has('DOS')) {
  9209. return dict.get('DOS');
  9210. } else {
  9211. return null;
  9212. }
  9213. }
  9214. FileSpec.prototype = {
  9215. get filename() {
  9216. if (!this._filename && this.root) {
  9217. var filename = pickPlatformItem(this.root) || 'unnamed';
  9218. this._filename = stringToPDFString(filename).
  9219. replace(/\\\\/g, '\\').
  9220. replace(/\\\//g, '/').
  9221. replace(/\\/g, '/');
  9222. }
  9223. return this._filename;
  9224. },
  9225. get content() {
  9226. if (!this.contentAvailable) {
  9227. return null;
  9228. }
  9229. if (!this.contentRef && this.root) {
  9230. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9231. }
  9232. var content = null;
  9233. if (this.contentRef) {
  9234. var xref = this.xref;
  9235. var fileObj = xref.fetchIfRef(this.contentRef);
  9236. if (fileObj && isStream(fileObj)) {
  9237. content = fileObj.getBytes();
  9238. } else {
  9239. warn('Embedded file specification points to non-existing/invalid ' +
  9240. 'content');
  9241. }
  9242. } else {
  9243. warn('Embedded file specification does not have a content');
  9244. }
  9245. return content;
  9246. },
  9247. get serializable() {
  9248. return {
  9249. filename: this.filename,
  9250. content: this.content
  9251. };
  9252. }
  9253. };
  9254. return FileSpec;
  9255. })();
  9256. /**
  9257. * A helper for loading missing data in object graphs. It traverses the graph
  9258. * depth first and queues up any objects that have missing data. Once it has
  9259. * has traversed as many objects that are available it attempts to bundle the
  9260. * missing data requests and then resume from the nodes that weren't ready.
  9261. *
  9262. * NOTE: It provides protection from circular references by keeping track of
  9263. * of loaded references. However, you must be careful not to load any graphs
  9264. * that have references to the catalog or other pages since that will cause the
  9265. * entire PDF document object graph to be traversed.
  9266. */
  9267. var ObjectLoader = (function() {
  9268. function mayHaveChildren(value) {
  9269. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9270. }
  9271. function addChildren(node, nodesToVisit) {
  9272. var value;
  9273. if (isDict(node) || isStream(node)) {
  9274. var map;
  9275. if (isDict(node)) {
  9276. map = node.map;
  9277. } else {
  9278. map = node.dict.map;
  9279. }
  9280. for (var key in map) {
  9281. value = map[key];
  9282. if (mayHaveChildren(value)) {
  9283. nodesToVisit.push(value);
  9284. }
  9285. }
  9286. } else if (isArray(node)) {
  9287. for (var i = 0, ii = node.length; i < ii; i++) {
  9288. value = node[i];
  9289. if (mayHaveChildren(value)) {
  9290. nodesToVisit.push(value);
  9291. }
  9292. }
  9293. }
  9294. }
  9295. function ObjectLoader(obj, keys, xref) {
  9296. this.obj = obj;
  9297. this.keys = keys;
  9298. this.xref = xref;
  9299. this.refSet = null;
  9300. }
  9301. ObjectLoader.prototype = {
  9302. load: function ObjectLoader_load() {
  9303. var keys = this.keys;
  9304. this.capability = createPromiseCapability();
  9305. // Don't walk the graph if all the data is already loaded.
  9306. if (!(this.xref.stream instanceof ChunkedStream) ||
  9307. this.xref.stream.getMissingChunks().length === 0) {
  9308. this.capability.resolve();
  9309. return this.capability.promise;
  9310. }
  9311. this.refSet = new RefSet();
  9312. // Setup the initial nodes to visit.
  9313. var nodesToVisit = [];
  9314. for (var i = 0; i < keys.length; i++) {
  9315. nodesToVisit.push(this.obj[keys[i]]);
  9316. }
  9317. this.walk(nodesToVisit);
  9318. return this.capability.promise;
  9319. },
  9320. walk: function ObjectLoader_walk(nodesToVisit) {
  9321. var nodesToRevisit = [];
  9322. var pendingRequests = [];
  9323. // DFS walk of the object graph.
  9324. while (nodesToVisit.length) {
  9325. var currentNode = nodesToVisit.pop();
  9326. // Only references or chunked streams can cause missing data exceptions.
  9327. if (isRef(currentNode)) {
  9328. // Skip nodes that have already been visited.
  9329. if (this.refSet.has(currentNode)) {
  9330. continue;
  9331. }
  9332. try {
  9333. var ref = currentNode;
  9334. this.refSet.put(ref);
  9335. currentNode = this.xref.fetch(currentNode);
  9336. } catch (e) {
  9337. if (!(e instanceof MissingDataException)) {
  9338. throw e;
  9339. }
  9340. nodesToRevisit.push(currentNode);
  9341. pendingRequests.push({ begin: e.begin, end: e.end });
  9342. }
  9343. }
  9344. if (currentNode && currentNode.getBaseStreams) {
  9345. var baseStreams = currentNode.getBaseStreams();
  9346. var foundMissingData = false;
  9347. for (var i = 0; i < baseStreams.length; i++) {
  9348. var stream = baseStreams[i];
  9349. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9350. foundMissingData = true;
  9351. pendingRequests.push({
  9352. begin: stream.start,
  9353. end: stream.end
  9354. });
  9355. }
  9356. }
  9357. if (foundMissingData) {
  9358. nodesToRevisit.push(currentNode);
  9359. }
  9360. }
  9361. addChildren(currentNode, nodesToVisit);
  9362. }
  9363. if (pendingRequests.length) {
  9364. this.xref.stream.manager.requestRanges(pendingRequests,
  9365. function pendingRequestCallback() {
  9366. nodesToVisit = nodesToRevisit;
  9367. for (var i = 0; i < nodesToRevisit.length; i++) {
  9368. var node = nodesToRevisit[i];
  9369. // Remove any reference nodes from the currrent refset so they
  9370. // aren't skipped when we revist them.
  9371. if (isRef(node)) {
  9372. this.refSet.remove(node);
  9373. }
  9374. }
  9375. this.walk(nodesToVisit);
  9376. }.bind(this));
  9377. return;
  9378. }
  9379. // Everything is loaded.
  9380. this.refSet = null;
  9381. this.capability.resolve();
  9382. }
  9383. };
  9384. return ObjectLoader;
  9385. })();
  9386. var ISOAdobeCharset = [
  9387. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9388. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9389. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9390. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9391. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9392. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9393. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9394. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9395. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9396. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9397. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9398. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9399. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9400. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9401. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9402. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9403. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9404. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9405. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9406. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9407. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9408. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9409. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9410. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9411. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9412. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9413. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9414. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9415. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9416. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9417. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9418. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9419. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9420. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9421. ];
  9422. var ExpertCharset = [
  9423. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9424. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9425. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9426. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9427. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9428. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9429. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9430. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9431. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9432. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9433. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9434. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9435. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9436. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9437. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9438. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9439. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9440. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9441. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9442. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9443. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9444. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9445. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9446. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9447. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9448. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9449. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9450. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9451. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9452. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9453. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9454. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9455. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9456. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9457. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9458. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9459. 'Ydieresissmall'
  9460. ];
  9461. var ExpertSubsetCharset = [
  9462. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9463. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9464. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9465. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9466. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9467. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9468. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9469. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9470. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9471. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9472. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9473. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9474. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9475. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9476. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9477. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9478. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9479. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9480. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9481. 'periodinferior', 'commainferior'
  9482. ];
  9483. var DEFAULT_ICON_SIZE = 22; // px
  9484. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9485. var Annotation = (function AnnotationClosure() {
  9486. // 12.5.5: Algorithm: Appearance streams
  9487. function getTransformMatrix(rect, bbox, matrix) {
  9488. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9489. var minX = bounds[0];
  9490. var minY = bounds[1];
  9491. var maxX = bounds[2];
  9492. var maxY = bounds[3];
  9493. if (minX === maxX || minY === maxY) {
  9494. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9495. // just apply the transform for rect
  9496. return [1, 0, 0, 1, rect[0], rect[1]];
  9497. }
  9498. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9499. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9500. return [
  9501. xRatio,
  9502. 0,
  9503. 0,
  9504. yRatio,
  9505. rect[0] - minX * xRatio,
  9506. rect[1] - minY * yRatio
  9507. ];
  9508. }
  9509. function getDefaultAppearance(dict) {
  9510. var appearanceState = dict.get('AP');
  9511. if (!isDict(appearanceState)) {
  9512. return;
  9513. }
  9514. var appearance;
  9515. var appearances = appearanceState.get('N');
  9516. if (isDict(appearances)) {
  9517. var as = dict.get('AS');
  9518. if (as && appearances.has(as.name)) {
  9519. appearance = appearances.get(as.name);
  9520. }
  9521. } else {
  9522. appearance = appearances;
  9523. }
  9524. return appearance;
  9525. }
  9526. function Annotation(params) {
  9527. var dict = params.dict;
  9528. var data = this.data = {};
  9529. data.subtype = dict.get('Subtype').name;
  9530. var rect = dict.get('Rect') || [0, 0, 0, 0];
  9531. data.rect = Util.normalizeRect(rect);
  9532. data.annotationFlags = dict.get('F');
  9533. var color = dict.get('C');
  9534. if (isArray(color) && color.length === 3) {
  9535. // TODO(mack): currently only supporting rgb; need support different
  9536. // colorspaces
  9537. data.color = color;
  9538. } else {
  9539. data.color = [0, 0, 0];
  9540. }
  9541. // Some types of annotations have border style dict which has more
  9542. // info than the border array
  9543. if (dict.has('BS')) {
  9544. var borderStyle = dict.get('BS');
  9545. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  9546. } else {
  9547. var borderArray = dict.get('Border') || [0, 0, 1];
  9548. data.borderWidth = borderArray[2] || 0;
  9549. // TODO: implement proper support for annotations with line dash patterns.
  9550. var dashArray = borderArray[3];
  9551. if (data.borderWidth > 0 && dashArray) {
  9552. if (!isArray(dashArray)) {
  9553. // Ignore the border if dashArray is not actually an array,
  9554. // this is consistent with the behaviour in Adobe Reader.
  9555. data.borderWidth = 0;
  9556. } else {
  9557. var dashArrayLength = dashArray.length;
  9558. if (dashArrayLength > 0) {
  9559. // According to the PDF specification: the elements in a dashArray
  9560. // shall be numbers that are nonnegative and not all equal to zero.
  9561. var isInvalid = false;
  9562. var numPositive = 0;
  9563. for (var i = 0; i < dashArrayLength; i++) {
  9564. var validNumber = (+dashArray[i] >= 0);
  9565. if (!validNumber) {
  9566. isInvalid = true;
  9567. break;
  9568. } else if (dashArray[i] > 0) {
  9569. numPositive++;
  9570. }
  9571. }
  9572. if (isInvalid || numPositive === 0) {
  9573. data.borderWidth = 0;
  9574. }
  9575. }
  9576. }
  9577. }
  9578. }
  9579. this.appearance = getDefaultAppearance(dict);
  9580. data.hasAppearance = !!this.appearance;
  9581. data.id = params.ref.num;
  9582. }
  9583. Annotation.prototype = {
  9584. getData: function Annotation_getData() {
  9585. return this.data;
  9586. },
  9587. isInvisible: function Annotation_isInvisible() {
  9588. var data = this.data;
  9589. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  9590. return false;
  9591. } else {
  9592. return !!(data &&
  9593. data.annotationFlags && // Default: not invisible
  9594. data.annotationFlags & 0x1); // Invisible
  9595. }
  9596. },
  9597. isViewable: function Annotation_isViewable() {
  9598. var data = this.data;
  9599. return !!(!this.isInvisible() &&
  9600. data &&
  9601. (!data.annotationFlags ||
  9602. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  9603. data.rect); // rectangle is necessary
  9604. },
  9605. isPrintable: function Annotation_isPrintable() {
  9606. var data = this.data;
  9607. return !!(!this.isInvisible() &&
  9608. data &&
  9609. data.annotationFlags && // Default: not printable
  9610. data.annotationFlags & 0x4 && // Print
  9611. !(data.annotationFlags & 0x2) && // Hidden
  9612. data.rect); // rectangle is necessary
  9613. },
  9614. loadResources: function Annotation_loadResources(keys) {
  9615. return new Promise(function (resolve, reject) {
  9616. this.appearance.dict.getAsync('Resources').then(function (resources) {
  9617. if (!resources) {
  9618. resolve();
  9619. return;
  9620. }
  9621. var objectLoader = new ObjectLoader(resources.map,
  9622. keys,
  9623. resources.xref);
  9624. objectLoader.load().then(function() {
  9625. resolve(resources);
  9626. }, reject);
  9627. }, reject);
  9628. }.bind(this));
  9629. },
  9630. getOperatorList: function Annotation_getOperatorList(evaluator) {
  9631. if (!this.appearance) {
  9632. return Promise.resolve(new OperatorList());
  9633. }
  9634. var data = this.data;
  9635. var appearanceDict = this.appearance.dict;
  9636. var resourcesPromise = this.loadResources([
  9637. 'ExtGState',
  9638. 'ColorSpace',
  9639. 'Pattern',
  9640. 'Shading',
  9641. 'XObject',
  9642. 'Font'
  9643. // ProcSet
  9644. // Properties
  9645. ]);
  9646. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  9647. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  9648. var transform = getTransformMatrix(data.rect, bbox, matrix);
  9649. var self = this;
  9650. return resourcesPromise.then(function(resources) {
  9651. var opList = new OperatorList();
  9652. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  9653. return evaluator.getOperatorList(self.appearance, resources, opList).
  9654. then(function () {
  9655. opList.addOp(OPS.endAnnotation, []);
  9656. self.appearance.reset();
  9657. return opList;
  9658. });
  9659. });
  9660. }
  9661. };
  9662. Annotation.getConstructor =
  9663. function Annotation_getConstructor(subtype, fieldType) {
  9664. if (!subtype) {
  9665. return;
  9666. }
  9667. // TODO(mack): Implement FreeText annotations
  9668. if (subtype === 'Link') {
  9669. return LinkAnnotation;
  9670. } else if (subtype === 'Text') {
  9671. return TextAnnotation;
  9672. } else if (subtype === 'Widget') {
  9673. if (!fieldType) {
  9674. return;
  9675. }
  9676. if (fieldType === 'Tx') {
  9677. return TextWidgetAnnotation;
  9678. } else {
  9679. return WidgetAnnotation;
  9680. }
  9681. } else {
  9682. return Annotation;
  9683. }
  9684. };
  9685. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  9686. var dict = xref.fetchIfRef(ref);
  9687. if (!isDict(dict)) {
  9688. return;
  9689. }
  9690. var subtype = dict.get('Subtype');
  9691. subtype = isName(subtype) ? subtype.name : '';
  9692. if (!subtype) {
  9693. return;
  9694. }
  9695. var fieldType = Util.getInheritableProperty(dict, 'FT');
  9696. fieldType = isName(fieldType) ? fieldType.name : '';
  9697. var Constructor = Annotation.getConstructor(subtype, fieldType);
  9698. if (!Constructor) {
  9699. return;
  9700. }
  9701. var params = {
  9702. dict: dict,
  9703. ref: ref,
  9704. };
  9705. var annotation = new Constructor(params);
  9706. if (annotation.isViewable() || annotation.isPrintable()) {
  9707. return annotation;
  9708. } else {
  9709. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  9710. warn('unimplemented annotation type: ' + subtype);
  9711. }
  9712. }
  9713. };
  9714. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  9715. annotations, opList, pdfManager, partialEvaluator, intent) {
  9716. function reject(e) {
  9717. annotationsReadyCapability.reject(e);
  9718. }
  9719. var annotationsReadyCapability = createPromiseCapability();
  9720. var annotationPromises = [];
  9721. for (var i = 0, n = annotations.length; i < n; ++i) {
  9722. if (intent === 'display' && annotations[i].isViewable() ||
  9723. intent === 'print' && annotations[i].isPrintable()) {
  9724. annotationPromises.push(
  9725. annotations[i].getOperatorList(partialEvaluator));
  9726. }
  9727. }
  9728. Promise.all(annotationPromises).then(function(datas) {
  9729. opList.addOp(OPS.beginAnnotations, []);
  9730. for (var i = 0, n = datas.length; i < n; ++i) {
  9731. var annotOpList = datas[i];
  9732. opList.addOpList(annotOpList);
  9733. }
  9734. opList.addOp(OPS.endAnnotations, []);
  9735. annotationsReadyCapability.resolve();
  9736. }, reject);
  9737. return annotationsReadyCapability.promise;
  9738. };
  9739. return Annotation;
  9740. })();
  9741. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  9742. function WidgetAnnotation(params) {
  9743. Annotation.call(this, params);
  9744. var dict = params.dict;
  9745. var data = this.data;
  9746. data.fieldValue = stringToPDFString(
  9747. Util.getInheritableProperty(dict, 'V') || '');
  9748. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  9749. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  9750. var fieldType = Util.getInheritableProperty(dict, 'FT');
  9751. data.fieldType = isName(fieldType) ? fieldType.name : '';
  9752. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  9753. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  9754. // Building the full field name by collecting the field and
  9755. // its ancestors 'T' data and joining them using '.'.
  9756. var fieldName = [];
  9757. var namedItem = dict;
  9758. var ref = params.ref;
  9759. while (namedItem) {
  9760. var parent = namedItem.get('Parent');
  9761. var parentRef = namedItem.getRaw('Parent');
  9762. var name = namedItem.get('T');
  9763. if (name) {
  9764. fieldName.unshift(stringToPDFString(name));
  9765. } else {
  9766. // The field name is absent, that means more than one field
  9767. // with the same name may exist. Replacing the empty name
  9768. // with the '`' plus index in the parent's 'Kids' array.
  9769. // This is not in the PDF spec but necessary to id the
  9770. // the input controls.
  9771. var kids = parent.get('Kids');
  9772. var j, jj;
  9773. for (j = 0, jj = kids.length; j < jj; j++) {
  9774. var kidRef = kids[j];
  9775. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  9776. break;
  9777. }
  9778. }
  9779. fieldName.unshift('`' + j);
  9780. }
  9781. namedItem = parent;
  9782. ref = parentRef;
  9783. }
  9784. data.fullName = fieldName.join('.');
  9785. }
  9786. var parent = Annotation.prototype;
  9787. Util.inherit(WidgetAnnotation, Annotation, {
  9788. isViewable: function WidgetAnnotation_isViewable() {
  9789. if (this.data.fieldType === 'Sig') {
  9790. warn('unimplemented annotation type: Widget signature');
  9791. return false;
  9792. }
  9793. return parent.isViewable.call(this);
  9794. }
  9795. });
  9796. return WidgetAnnotation;
  9797. })();
  9798. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  9799. function TextWidgetAnnotation(params) {
  9800. WidgetAnnotation.call(this, params);
  9801. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  9802. this.data.annotationType = AnnotationType.WIDGET;
  9803. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  9804. }
  9805. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  9806. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  9807. if (this.appearance) {
  9808. return Annotation.prototype.getOperatorList.call(this, evaluator);
  9809. }
  9810. var opList = new OperatorList();
  9811. var data = this.data;
  9812. // Even if there is an appearance stream, ignore it. This is the
  9813. // behaviour used by Adobe Reader.
  9814. if (!data.defaultAppearance) {
  9815. return Promise.resolve(opList);
  9816. }
  9817. var stream = new Stream(stringToBytes(data.defaultAppearance));
  9818. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  9819. then(function () {
  9820. return opList;
  9821. });
  9822. }
  9823. });
  9824. return TextWidgetAnnotation;
  9825. })();
  9826. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  9827. function InteractiveAnnotation(params) {
  9828. Annotation.call(this, params);
  9829. this.data.hasHtml = true;
  9830. }
  9831. Util.inherit(InteractiveAnnotation, Annotation, { });
  9832. return InteractiveAnnotation;
  9833. })();
  9834. var TextAnnotation = (function TextAnnotationClosure() {
  9835. function TextAnnotation(params) {
  9836. InteractiveAnnotation.call(this, params);
  9837. var dict = params.dict;
  9838. var data = this.data;
  9839. var content = dict.get('Contents');
  9840. var title = dict.get('T');
  9841. data.annotationType = AnnotationType.TEXT;
  9842. data.content = stringToPDFString(content || '');
  9843. data.title = stringToPDFString(title || '');
  9844. if (data.hasAppearance) {
  9845. data.name = 'NoIcon';
  9846. } else {
  9847. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  9848. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  9849. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  9850. }
  9851. if (dict.has('C')) {
  9852. data.hasBgColor = true;
  9853. }
  9854. }
  9855. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  9856. return TextAnnotation;
  9857. })();
  9858. var LinkAnnotation = (function LinkAnnotationClosure() {
  9859. function LinkAnnotation(params) {
  9860. InteractiveAnnotation.call(this, params);
  9861. var dict = params.dict;
  9862. var data = this.data;
  9863. data.annotationType = AnnotationType.LINK;
  9864. var action = dict.get('A');
  9865. if (action) {
  9866. var linkType = action.get('S').name;
  9867. if (linkType === 'URI') {
  9868. var url = action.get('URI');
  9869. if (isName(url)) {
  9870. // Some bad PDFs do not put parentheses around relative URLs.
  9871. url = '/' + url.name;
  9872. } else if (url) {
  9873. url = addDefaultProtocolToUrl(url);
  9874. }
  9875. // TODO: pdf spec mentions urls can be relative to a Base
  9876. // entry in the dictionary.
  9877. if (!isValidUrl(url, false)) {
  9878. url = '';
  9879. }
  9880. data.url = url;
  9881. } else if (linkType === 'GoTo') {
  9882. data.dest = action.get('D');
  9883. } else if (linkType === 'GoToR') {
  9884. var urlDict = action.get('F');
  9885. if (isDict(urlDict)) {
  9886. // We assume that the 'url' is a Filspec dictionary
  9887. // and fetch the url without checking any further
  9888. url = urlDict.get('F') || '';
  9889. }
  9890. // TODO: pdf reference says that GoToR
  9891. // can also have 'NewWindow' attribute
  9892. if (!isValidUrl(url, false)) {
  9893. url = '';
  9894. }
  9895. data.url = url;
  9896. data.dest = action.get('D');
  9897. } else if (linkType === 'Named') {
  9898. data.action = action.get('N').name;
  9899. } else {
  9900. warn('unrecognized link type: ' + linkType);
  9901. }
  9902. } else if (dict.has('Dest')) {
  9903. // simple destination link
  9904. var dest = dict.get('Dest');
  9905. data.dest = isName(dest) ? dest.name : dest;
  9906. }
  9907. }
  9908. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  9909. function addDefaultProtocolToUrl(url) {
  9910. if (url && url.indexOf('www.') === 0) {
  9911. return ('http://' + url);
  9912. }
  9913. return url;
  9914. }
  9915. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  9916. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  9917. return false;
  9918. }
  9919. });
  9920. return LinkAnnotation;
  9921. })();
  9922. var PDFFunction = (function PDFFunctionClosure() {
  9923. var CONSTRUCT_SAMPLED = 0;
  9924. var CONSTRUCT_INTERPOLATED = 2;
  9925. var CONSTRUCT_STICHED = 3;
  9926. var CONSTRUCT_POSTSCRIPT = 4;
  9927. return {
  9928. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  9929. str) {
  9930. var i, ii;
  9931. var length = 1;
  9932. for (i = 0, ii = size.length; i < ii; i++) {
  9933. length *= size[i];
  9934. }
  9935. length *= outputSize;
  9936. var array = new Array(length);
  9937. var codeSize = 0;
  9938. var codeBuf = 0;
  9939. // 32 is a valid bps so shifting won't work
  9940. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  9941. var strBytes = str.getBytes((length * bps + 7) / 8);
  9942. var strIdx = 0;
  9943. for (i = 0; i < length; i++) {
  9944. while (codeSize < bps) {
  9945. codeBuf <<= 8;
  9946. codeBuf |= strBytes[strIdx++];
  9947. codeSize += 8;
  9948. }
  9949. codeSize -= bps;
  9950. array[i] = (codeBuf >> codeSize) * sampleMul;
  9951. codeBuf &= (1 << codeSize) - 1;
  9952. }
  9953. return array;
  9954. },
  9955. getIR: function PDFFunction_getIR(xref, fn) {
  9956. var dict = fn.dict;
  9957. if (!dict) {
  9958. dict = fn;
  9959. }
  9960. var types = [this.constructSampled,
  9961. null,
  9962. this.constructInterpolated,
  9963. this.constructStiched,
  9964. this.constructPostScript];
  9965. var typeNum = dict.get('FunctionType');
  9966. var typeFn = types[typeNum];
  9967. if (!typeFn) {
  9968. error('Unknown type of function');
  9969. }
  9970. return typeFn.call(this, fn, dict, xref);
  9971. },
  9972. fromIR: function PDFFunction_fromIR(IR) {
  9973. var type = IR[0];
  9974. switch (type) {
  9975. case CONSTRUCT_SAMPLED:
  9976. return this.constructSampledFromIR(IR);
  9977. case CONSTRUCT_INTERPOLATED:
  9978. return this.constructInterpolatedFromIR(IR);
  9979. case CONSTRUCT_STICHED:
  9980. return this.constructStichedFromIR(IR);
  9981. //case CONSTRUCT_POSTSCRIPT:
  9982. default:
  9983. return this.constructPostScriptFromIR(IR);
  9984. }
  9985. },
  9986. parse: function PDFFunction_parse(xref, fn) {
  9987. var IR = this.getIR(xref, fn);
  9988. return this.fromIR(IR);
  9989. },
  9990. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  9991. if (!isArray(fnObj)) {
  9992. // not an array -- parsing as regular function
  9993. return this.parse(xref, fnObj);
  9994. }
  9995. var fnArray = [];
  9996. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  9997. var obj = xref.fetchIfRef(fnObj[j]);
  9998. fnArray.push(PDFFunction.parse(xref, obj));
  9999. }
  10000. return function (src, srcOffset, dest, destOffset) {
  10001. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10002. fnArray[i](src, srcOffset, dest, destOffset + i);
  10003. }
  10004. };
  10005. },
  10006. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10007. function toMultiArray(arr) {
  10008. var inputLength = arr.length;
  10009. var out = [];
  10010. var index = 0;
  10011. for (var i = 0; i < inputLength; i += 2) {
  10012. out[index] = [arr[i], arr[i + 1]];
  10013. ++index;
  10014. }
  10015. return out;
  10016. }
  10017. var domain = dict.get('Domain');
  10018. var range = dict.get('Range');
  10019. if (!domain || !range) {
  10020. error('No domain or range');
  10021. }
  10022. var inputSize = domain.length / 2;
  10023. var outputSize = range.length / 2;
  10024. domain = toMultiArray(domain);
  10025. range = toMultiArray(range);
  10026. var size = dict.get('Size');
  10027. var bps = dict.get('BitsPerSample');
  10028. var order = dict.get('Order') || 1;
  10029. if (order !== 1) {
  10030. // No description how cubic spline interpolation works in PDF32000:2008
  10031. // As in poppler, ignoring order, linear interpolation may work as good
  10032. info('No support for cubic spline interpolation: ' + order);
  10033. }
  10034. var encode = dict.get('Encode');
  10035. if (!encode) {
  10036. encode = [];
  10037. for (var i = 0; i < inputSize; ++i) {
  10038. encode.push(0);
  10039. encode.push(size[i] - 1);
  10040. }
  10041. }
  10042. encode = toMultiArray(encode);
  10043. var decode = dict.get('Decode');
  10044. if (!decode) {
  10045. decode = range;
  10046. } else {
  10047. decode = toMultiArray(decode);
  10048. }
  10049. var samples = this.getSampleArray(size, outputSize, bps, str);
  10050. return [
  10051. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10052. outputSize, Math.pow(2, bps) - 1, range
  10053. ];
  10054. },
  10055. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10056. // See chapter 3, page 109 of the PDF reference
  10057. function interpolate(x, xmin, xmax, ymin, ymax) {
  10058. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10059. }
  10060. return function constructSampledFromIRResult(src, srcOffset,
  10061. dest, destOffset) {
  10062. // See chapter 3, page 110 of the PDF reference.
  10063. var m = IR[1];
  10064. var domain = IR[2];
  10065. var encode = IR[3];
  10066. var decode = IR[4];
  10067. var samples = IR[5];
  10068. var size = IR[6];
  10069. var n = IR[7];
  10070. //var mask = IR[8];
  10071. var range = IR[9];
  10072. // Building the cube vertices: its part and sample index
  10073. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10074. var cubeVertices = 1 << m;
  10075. var cubeN = new Float64Array(cubeVertices);
  10076. var cubeVertex = new Uint32Array(cubeVertices);
  10077. var i, j;
  10078. for (j = 0; j < cubeVertices; j++) {
  10079. cubeN[j] = 1;
  10080. }
  10081. var k = n, pos = 1;
  10082. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10083. for (i = 0; i < m; ++i) {
  10084. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10085. var domain_2i = domain[i][0];
  10086. var domain_2i_1 = domain[i][1];
  10087. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10088. domain_2i_1);
  10089. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10090. // Encode_2i, Encode_2i+1)
  10091. var e = interpolate(xi, domain_2i, domain_2i_1,
  10092. encode[i][0], encode[i][1]);
  10093. // e_i' = min(max(e_i, 0), Size_i - 1)
  10094. var size_i = size[i];
  10095. e = Math.min(Math.max(e, 0), size_i - 1);
  10096. // Adjusting the cube: N and vertex sample index
  10097. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10098. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10099. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10100. var offset0 = e0 * k;
  10101. var offset1 = offset0 + k; // e1 * k
  10102. for (j = 0; j < cubeVertices; j++) {
  10103. if (j & pos) {
  10104. cubeN[j] *= n1;
  10105. cubeVertex[j] += offset1;
  10106. } else {
  10107. cubeN[j] *= n0;
  10108. cubeVertex[j] += offset0;
  10109. }
  10110. }
  10111. k *= size_i;
  10112. pos <<= 1;
  10113. }
  10114. for (j = 0; j < n; ++j) {
  10115. // Sum all cube vertices' samples portions
  10116. var rj = 0;
  10117. for (i = 0; i < cubeVertices; i++) {
  10118. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10119. }
  10120. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10121. // Decode_2j, Decode_2j+1)
  10122. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10123. // y_j = min(max(r_j, range_2j), range_2j+1)
  10124. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10125. range[j][1]);
  10126. }
  10127. };
  10128. },
  10129. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10130. dict) {
  10131. var c0 = dict.get('C0') || [0];
  10132. var c1 = dict.get('C1') || [1];
  10133. var n = dict.get('N');
  10134. if (!isArray(c0) || !isArray(c1)) {
  10135. error('Illegal dictionary for interpolated function');
  10136. }
  10137. var length = c0.length;
  10138. var diff = [];
  10139. for (var i = 0; i < length; ++i) {
  10140. diff.push(c1[i] - c0[i]);
  10141. }
  10142. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10143. },
  10144. constructInterpolatedFromIR:
  10145. function PDFFunction_constructInterpolatedFromIR(IR) {
  10146. var c0 = IR[1];
  10147. var diff = IR[2];
  10148. var n = IR[3];
  10149. var length = diff.length;
  10150. return function constructInterpolatedFromIRResult(src, srcOffset,
  10151. dest, destOffset) {
  10152. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10153. for (var j = 0; j < length; ++j) {
  10154. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10155. }
  10156. };
  10157. },
  10158. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10159. var domain = dict.get('Domain');
  10160. if (!domain) {
  10161. error('No domain');
  10162. }
  10163. var inputSize = domain.length / 2;
  10164. if (inputSize !== 1) {
  10165. error('Bad domain for stiched function');
  10166. }
  10167. var fnRefs = dict.get('Functions');
  10168. var fns = [];
  10169. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10170. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10171. }
  10172. var bounds = dict.get('Bounds');
  10173. var encode = dict.get('Encode');
  10174. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10175. },
  10176. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10177. var domain = IR[1];
  10178. var bounds = IR[2];
  10179. var encode = IR[3];
  10180. var fnsIR = IR[4];
  10181. var fns = [];
  10182. var tmpBuf = new Float32Array(1);
  10183. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10184. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10185. }
  10186. return function constructStichedFromIRResult(src, srcOffset,
  10187. dest, destOffset) {
  10188. var clip = function constructStichedFromIRClip(v, min, max) {
  10189. if (v > max) {
  10190. v = max;
  10191. } else if (v < min) {
  10192. v = min;
  10193. }
  10194. return v;
  10195. };
  10196. // clip to domain
  10197. var v = clip(src[srcOffset], domain[0], domain[1]);
  10198. // calulate which bound the value is in
  10199. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10200. if (v < bounds[i]) {
  10201. break;
  10202. }
  10203. }
  10204. // encode value into domain of function
  10205. var dmin = domain[0];
  10206. if (i > 0) {
  10207. dmin = bounds[i - 1];
  10208. }
  10209. var dmax = domain[1];
  10210. if (i < bounds.length) {
  10211. dmax = bounds[i];
  10212. }
  10213. var rmin = encode[2 * i];
  10214. var rmax = encode[2 * i + 1];
  10215. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10216. // call the appropriate function
  10217. fns[i](tmpBuf, 0, dest, destOffset);
  10218. };
  10219. },
  10220. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10221. xref) {
  10222. var domain = dict.get('Domain');
  10223. var range = dict.get('Range');
  10224. if (!domain) {
  10225. error('No domain.');
  10226. }
  10227. if (!range) {
  10228. error('No range.');
  10229. }
  10230. var lexer = new PostScriptLexer(fn);
  10231. var parser = new PostScriptParser(lexer);
  10232. var code = parser.parse();
  10233. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10234. },
  10235. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10236. IR) {
  10237. var domain = IR[1];
  10238. var range = IR[2];
  10239. var code = IR[3];
  10240. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10241. if (compiled) {
  10242. // Compiled function consists of simple expressions such as addition,
  10243. // subtraction, Math.max, and also contains 'var' and 'return'
  10244. // statements. See the generation in the PostScriptCompiler below.
  10245. /*jshint -W054 */
  10246. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10247. }
  10248. info('Unable to compile PS function');
  10249. var numOutputs = range.length >> 1;
  10250. var numInputs = domain.length >> 1;
  10251. var evaluator = new PostScriptEvaluator(code);
  10252. // Cache the values for a big speed up, the cache size is limited though
  10253. // since the number of possible values can be huge from a PS function.
  10254. var cache = {};
  10255. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10256. // seen in our tests.
  10257. var MAX_CACHE_SIZE = 2048 * 4;
  10258. var cache_available = MAX_CACHE_SIZE;
  10259. var tmpBuf = new Float32Array(numInputs);
  10260. return function constructPostScriptFromIRResult(src, srcOffset,
  10261. dest, destOffset) {
  10262. var i, value;
  10263. var key = '';
  10264. var input = tmpBuf;
  10265. for (i = 0; i < numInputs; i++) {
  10266. value = src[srcOffset + i];
  10267. input[i] = value;
  10268. key += value + '_';
  10269. }
  10270. var cachedValue = cache[key];
  10271. if (cachedValue !== undefined) {
  10272. cachedValue.set(dest, destOffset);
  10273. return;
  10274. }
  10275. var output = new Float32Array(numOutputs);
  10276. var stack = evaluator.execute(input);
  10277. var stackIndex = stack.length - numOutputs;
  10278. for (i = 0; i < numOutputs; i++) {
  10279. value = stack[stackIndex + i];
  10280. var bound = range[i * 2];
  10281. if (value < bound) {
  10282. value = bound;
  10283. } else {
  10284. bound = range[i * 2 +1];
  10285. if (value > bound) {
  10286. value = bound;
  10287. }
  10288. }
  10289. output[i] = value;
  10290. }
  10291. if (cache_available > 0) {
  10292. cache_available--;
  10293. cache[key] = output;
  10294. }
  10295. output.set(dest, destOffset);
  10296. };
  10297. }
  10298. };
  10299. })();
  10300. function isPDFFunction(v) {
  10301. var fnDict;
  10302. if (typeof v !== 'object') {
  10303. return false;
  10304. } else if (isDict(v)) {
  10305. fnDict = v;
  10306. } else if (isStream(v)) {
  10307. fnDict = v.dict;
  10308. } else {
  10309. return false;
  10310. }
  10311. return fnDict.has('FunctionType');
  10312. }
  10313. var PostScriptStack = (function PostScriptStackClosure() {
  10314. var MAX_STACK_SIZE = 100;
  10315. function PostScriptStack(initialStack) {
  10316. this.stack = !initialStack ? [] :
  10317. Array.prototype.slice.call(initialStack, 0);
  10318. }
  10319. PostScriptStack.prototype = {
  10320. push: function PostScriptStack_push(value) {
  10321. if (this.stack.length >= MAX_STACK_SIZE) {
  10322. error('PostScript function stack overflow.');
  10323. }
  10324. this.stack.push(value);
  10325. },
  10326. pop: function PostScriptStack_pop() {
  10327. if (this.stack.length <= 0) {
  10328. error('PostScript function stack underflow.');
  10329. }
  10330. return this.stack.pop();
  10331. },
  10332. copy: function PostScriptStack_copy(n) {
  10333. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10334. error('PostScript function stack overflow.');
  10335. }
  10336. var stack = this.stack;
  10337. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10338. stack.push(stack[i]);
  10339. }
  10340. },
  10341. index: function PostScriptStack_index(n) {
  10342. this.push(this.stack[this.stack.length - n - 1]);
  10343. },
  10344. // rotate the last n stack elements p times
  10345. roll: function PostScriptStack_roll(n, p) {
  10346. var stack = this.stack;
  10347. var l = stack.length - n;
  10348. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10349. for (i = l, j = r; i < j; i++, j--) {
  10350. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10351. }
  10352. for (i = l, j = c - 1; i < j; i++, j--) {
  10353. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10354. }
  10355. for (i = c, j = r; i < j; i++, j--) {
  10356. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10357. }
  10358. }
  10359. };
  10360. return PostScriptStack;
  10361. })();
  10362. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10363. function PostScriptEvaluator(operators) {
  10364. this.operators = operators;
  10365. }
  10366. PostScriptEvaluator.prototype = {
  10367. execute: function PostScriptEvaluator_execute(initialStack) {
  10368. var stack = new PostScriptStack(initialStack);
  10369. var counter = 0;
  10370. var operators = this.operators;
  10371. var length = operators.length;
  10372. var operator, a, b;
  10373. while (counter < length) {
  10374. operator = operators[counter++];
  10375. if (typeof operator === 'number') {
  10376. // Operator is really an operand and should be pushed to the stack.
  10377. stack.push(operator);
  10378. continue;
  10379. }
  10380. switch (operator) {
  10381. // non standard ps operators
  10382. case 'jz': // jump if false
  10383. b = stack.pop();
  10384. a = stack.pop();
  10385. if (!a) {
  10386. counter = b;
  10387. }
  10388. break;
  10389. case 'j': // jump
  10390. a = stack.pop();
  10391. counter = a;
  10392. break;
  10393. // all ps operators in alphabetical order (excluding if/ifelse)
  10394. case 'abs':
  10395. a = stack.pop();
  10396. stack.push(Math.abs(a));
  10397. break;
  10398. case 'add':
  10399. b = stack.pop();
  10400. a = stack.pop();
  10401. stack.push(a + b);
  10402. break;
  10403. case 'and':
  10404. b = stack.pop();
  10405. a = stack.pop();
  10406. if (isBool(a) && isBool(b)) {
  10407. stack.push(a && b);
  10408. } else {
  10409. stack.push(a & b);
  10410. }
  10411. break;
  10412. case 'atan':
  10413. a = stack.pop();
  10414. stack.push(Math.atan(a));
  10415. break;
  10416. case 'bitshift':
  10417. b = stack.pop();
  10418. a = stack.pop();
  10419. if (a > 0) {
  10420. stack.push(a << b);
  10421. } else {
  10422. stack.push(a >> b);
  10423. }
  10424. break;
  10425. case 'ceiling':
  10426. a = stack.pop();
  10427. stack.push(Math.ceil(a));
  10428. break;
  10429. case 'copy':
  10430. a = stack.pop();
  10431. stack.copy(a);
  10432. break;
  10433. case 'cos':
  10434. a = stack.pop();
  10435. stack.push(Math.cos(a));
  10436. break;
  10437. case 'cvi':
  10438. a = stack.pop() | 0;
  10439. stack.push(a);
  10440. break;
  10441. case 'cvr':
  10442. // noop
  10443. break;
  10444. case 'div':
  10445. b = stack.pop();
  10446. a = stack.pop();
  10447. stack.push(a / b);
  10448. break;
  10449. case 'dup':
  10450. stack.copy(1);
  10451. break;
  10452. case 'eq':
  10453. b = stack.pop();
  10454. a = stack.pop();
  10455. stack.push(a === b);
  10456. break;
  10457. case 'exch':
  10458. stack.roll(2, 1);
  10459. break;
  10460. case 'exp':
  10461. b = stack.pop();
  10462. a = stack.pop();
  10463. stack.push(Math.pow(a, b));
  10464. break;
  10465. case 'false':
  10466. stack.push(false);
  10467. break;
  10468. case 'floor':
  10469. a = stack.pop();
  10470. stack.push(Math.floor(a));
  10471. break;
  10472. case 'ge':
  10473. b = stack.pop();
  10474. a = stack.pop();
  10475. stack.push(a >= b);
  10476. break;
  10477. case 'gt':
  10478. b = stack.pop();
  10479. a = stack.pop();
  10480. stack.push(a > b);
  10481. break;
  10482. case 'idiv':
  10483. b = stack.pop();
  10484. a = stack.pop();
  10485. stack.push((a / b) | 0);
  10486. break;
  10487. case 'index':
  10488. a = stack.pop();
  10489. stack.index(a);
  10490. break;
  10491. case 'le':
  10492. b = stack.pop();
  10493. a = stack.pop();
  10494. stack.push(a <= b);
  10495. break;
  10496. case 'ln':
  10497. a = stack.pop();
  10498. stack.push(Math.log(a));
  10499. break;
  10500. case 'log':
  10501. a = stack.pop();
  10502. stack.push(Math.log(a) / Math.LN10);
  10503. break;
  10504. case 'lt':
  10505. b = stack.pop();
  10506. a = stack.pop();
  10507. stack.push(a < b);
  10508. break;
  10509. case 'mod':
  10510. b = stack.pop();
  10511. a = stack.pop();
  10512. stack.push(a % b);
  10513. break;
  10514. case 'mul':
  10515. b = stack.pop();
  10516. a = stack.pop();
  10517. stack.push(a * b);
  10518. break;
  10519. case 'ne':
  10520. b = stack.pop();
  10521. a = stack.pop();
  10522. stack.push(a !== b);
  10523. break;
  10524. case 'neg':
  10525. a = stack.pop();
  10526. stack.push(-a);
  10527. break;
  10528. case 'not':
  10529. a = stack.pop();
  10530. if (isBool(a)) {
  10531. stack.push(!a);
  10532. } else {
  10533. stack.push(~a);
  10534. }
  10535. break;
  10536. case 'or':
  10537. b = stack.pop();
  10538. a = stack.pop();
  10539. if (isBool(a) && isBool(b)) {
  10540. stack.push(a || b);
  10541. } else {
  10542. stack.push(a | b);
  10543. }
  10544. break;
  10545. case 'pop':
  10546. stack.pop();
  10547. break;
  10548. case 'roll':
  10549. b = stack.pop();
  10550. a = stack.pop();
  10551. stack.roll(a, b);
  10552. break;
  10553. case 'round':
  10554. a = stack.pop();
  10555. stack.push(Math.round(a));
  10556. break;
  10557. case 'sin':
  10558. a = stack.pop();
  10559. stack.push(Math.sin(a));
  10560. break;
  10561. case 'sqrt':
  10562. a = stack.pop();
  10563. stack.push(Math.sqrt(a));
  10564. break;
  10565. case 'sub':
  10566. b = stack.pop();
  10567. a = stack.pop();
  10568. stack.push(a - b);
  10569. break;
  10570. case 'true':
  10571. stack.push(true);
  10572. break;
  10573. case 'truncate':
  10574. a = stack.pop();
  10575. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  10576. stack.push(a);
  10577. break;
  10578. case 'xor':
  10579. b = stack.pop();
  10580. a = stack.pop();
  10581. if (isBool(a) && isBool(b)) {
  10582. stack.push(a !== b);
  10583. } else {
  10584. stack.push(a ^ b);
  10585. }
  10586. break;
  10587. default:
  10588. error('Unknown operator ' + operator);
  10589. break;
  10590. }
  10591. }
  10592. return stack.stack;
  10593. }
  10594. };
  10595. return PostScriptEvaluator;
  10596. })();
  10597. // Most of the PDFs functions consist of simple operations such as:
  10598. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  10599. //
  10600. // We can compile most of such programs, and at the same moment, we can
  10601. // optimize some expressions using basic math properties. Keeping track of
  10602. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  10603. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  10604. function AstNode(type) {
  10605. this.type = type;
  10606. }
  10607. AstNode.prototype.visit = function (visitor) {
  10608. throw new Error('abstract method');
  10609. };
  10610. function AstArgument(index, min, max) {
  10611. AstNode.call(this, 'args');
  10612. this.index = index;
  10613. this.min = min;
  10614. this.max = max;
  10615. }
  10616. AstArgument.prototype = Object.create(AstNode.prototype);
  10617. AstArgument.prototype.visit = function (visitor) {
  10618. visitor.visitArgument(this);
  10619. };
  10620. function AstLiteral(number) {
  10621. AstNode.call(this, 'literal');
  10622. this.number = number;
  10623. this.min = number;
  10624. this.max = number;
  10625. }
  10626. AstLiteral.prototype = Object.create(AstNode.prototype);
  10627. AstLiteral.prototype.visit = function (visitor) {
  10628. visitor.visitLiteral(this);
  10629. };
  10630. function AstBinaryOperation(op, arg1, arg2, min, max) {
  10631. AstNode.call(this, 'binary');
  10632. this.op = op;
  10633. this.arg1 = arg1;
  10634. this.arg2 = arg2;
  10635. this.min = min;
  10636. this.max = max;
  10637. }
  10638. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  10639. AstBinaryOperation.prototype.visit = function (visitor) {
  10640. visitor.visitBinaryOperation(this);
  10641. };
  10642. function AstMin(arg, max) {
  10643. AstNode.call(this, 'max');
  10644. this.arg = arg;
  10645. this.min = arg.min;
  10646. this.max = max;
  10647. }
  10648. AstMin.prototype = Object.create(AstNode.prototype);
  10649. AstMin.prototype.visit = function (visitor) {
  10650. visitor.visitMin(this);
  10651. };
  10652. function AstVariable(index, min, max) {
  10653. AstNode.call(this, 'var');
  10654. this.index = index;
  10655. this.min = min;
  10656. this.max = max;
  10657. }
  10658. AstVariable.prototype = Object.create(AstNode.prototype);
  10659. AstVariable.prototype.visit = function (visitor) {
  10660. visitor.visitVariable(this);
  10661. };
  10662. function AstVariableDefinition(variable, arg) {
  10663. AstNode.call(this, 'definition');
  10664. this.variable = variable;
  10665. this.arg = arg;
  10666. }
  10667. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  10668. AstVariableDefinition.prototype.visit = function (visitor) {
  10669. visitor.visitVariableDefinition(this);
  10670. };
  10671. function ExpressionBuilderVisitor() {
  10672. this.parts = [];
  10673. }
  10674. ExpressionBuilderVisitor.prototype = {
  10675. visitArgument: function (arg) {
  10676. this.parts.push('Math.max(', arg.min, ', Math.min(',
  10677. arg.max, ', src[srcOffset + ', arg.index, ']))');
  10678. },
  10679. visitVariable: function (variable) {
  10680. this.parts.push('v', variable.index);
  10681. },
  10682. visitLiteral: function (literal) {
  10683. this.parts.push(literal.number);
  10684. },
  10685. visitBinaryOperation: function (operation) {
  10686. this.parts.push('(');
  10687. operation.arg1.visit(this);
  10688. this.parts.push(' ', operation.op, ' ');
  10689. operation.arg2.visit(this);
  10690. this.parts.push(')');
  10691. },
  10692. visitVariableDefinition: function (definition) {
  10693. this.parts.push('var ');
  10694. definition.variable.visit(this);
  10695. this.parts.push(' = ');
  10696. definition.arg.visit(this);
  10697. this.parts.push(';');
  10698. },
  10699. visitMin: function (max) {
  10700. this.parts.push('Math.min(');
  10701. max.arg.visit(this);
  10702. this.parts.push(', ', max.max, ')');
  10703. },
  10704. toString: function () {
  10705. return this.parts.join('');
  10706. }
  10707. };
  10708. function buildAddOperation(num1, num2) {
  10709. if (num2.type === 'literal' && num2.number === 0) {
  10710. // optimization: second operand is 0
  10711. return num1;
  10712. }
  10713. if (num1.type === 'literal' && num1.number === 0) {
  10714. // optimization: first operand is 0
  10715. return num2;
  10716. }
  10717. if (num2.type === 'literal' && num1.type === 'literal') {
  10718. // optimization: operands operand are literals
  10719. return new AstLiteral(num1.number + num2.number);
  10720. }
  10721. return new AstBinaryOperation('+', num1, num2,
  10722. num1.min + num2.min, num1.max + num2.max);
  10723. }
  10724. function buildMulOperation(num1, num2) {
  10725. if (num2.type === 'literal') {
  10726. // optimization: second operands is a literal...
  10727. if (num2.number === 0) {
  10728. return new AstLiteral(0); // and it's 0
  10729. } else if (num2.number === 1) {
  10730. return num1; // and it's 1
  10731. } else if (num1.type === 'literal') {
  10732. // ... and first operands is a literal too
  10733. return new AstLiteral(num1.number * num2.number);
  10734. }
  10735. }
  10736. if (num1.type === 'literal') {
  10737. // optimization: first operands is a literal...
  10738. if (num1.number === 0) {
  10739. return new AstLiteral(0); // and it's 0
  10740. } else if (num1.number === 1) {
  10741. return num2; // and it's 1
  10742. }
  10743. }
  10744. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  10745. num1.max * num2.min, num1.max * num2.max);
  10746. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  10747. num1.max * num2.min, num1.max * num2.max);
  10748. return new AstBinaryOperation('*', num1, num2, min, max);
  10749. }
  10750. function buildSubOperation(num1, num2) {
  10751. if (num2.type === 'literal') {
  10752. // optimization: second operands is a literal...
  10753. if (num2.number === 0) {
  10754. return num1; // ... and it's 0
  10755. } else if (num1.type === 'literal') {
  10756. // ... and first operands is a literal too
  10757. return new AstLiteral(num1.number - num2.number);
  10758. }
  10759. }
  10760. if (num2.type === 'binary' && num2.op === '-' &&
  10761. num1.type === 'literal' && num1.number === 1 &&
  10762. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  10763. // optimization for case: 1 - (1 - x)
  10764. return num2.arg2;
  10765. }
  10766. return new AstBinaryOperation('-', num1, num2,
  10767. num1.min - num2.max, num1.max - num2.min);
  10768. }
  10769. function buildMinOperation(num1, max) {
  10770. if (num1.min >= max) {
  10771. // optimization: num1 min value is not less than required max
  10772. return new AstLiteral(max); // just returning max
  10773. } else if (num1.max <= max) {
  10774. // optimization: num1 max value is not greater than required max
  10775. return num1; // just returning an argument
  10776. }
  10777. return new AstMin(num1, max);
  10778. }
  10779. function PostScriptCompiler() {}
  10780. PostScriptCompiler.prototype = {
  10781. compile: function PostScriptCompiler_compile(code, domain, range) {
  10782. var stack = [];
  10783. var i, ii;
  10784. var instructions = [];
  10785. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  10786. var lastRegister = 0;
  10787. var n, j, min, max;
  10788. var num1, num2, ast1, ast2, tmpVar, item;
  10789. for (i = 0; i < inputSize; i++) {
  10790. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  10791. }
  10792. for (i = 0, ii = code.length; i < ii; i++) {
  10793. item = code[i];
  10794. if (typeof item === 'number') {
  10795. stack.push(new AstLiteral(item));
  10796. continue;
  10797. }
  10798. switch (item) {
  10799. case 'add':
  10800. if (stack.length < 2) {
  10801. return null;
  10802. }
  10803. num2 = stack.pop();
  10804. num1 = stack.pop();
  10805. stack.push(buildAddOperation(num1, num2));
  10806. break;
  10807. case 'cvr':
  10808. if (stack.length < 1) {
  10809. return null;
  10810. }
  10811. break;
  10812. case 'mul':
  10813. if (stack.length < 2) {
  10814. return null;
  10815. }
  10816. num2 = stack.pop();
  10817. num1 = stack.pop();
  10818. stack.push(buildMulOperation(num1, num2));
  10819. break;
  10820. case 'sub':
  10821. if (stack.length < 2) {
  10822. return null;
  10823. }
  10824. num2 = stack.pop();
  10825. num1 = stack.pop();
  10826. stack.push(buildSubOperation(num1, num2));
  10827. break;
  10828. case 'exch':
  10829. if (stack.length < 2) {
  10830. return null;
  10831. }
  10832. ast1 = stack.pop(); ast2 = stack.pop();
  10833. stack.push(ast1, ast2);
  10834. break;
  10835. case 'pop':
  10836. if (stack.length < 1) {
  10837. return null;
  10838. }
  10839. stack.pop();
  10840. break;
  10841. case 'index':
  10842. if (stack.length < 1) {
  10843. return null;
  10844. }
  10845. num1 = stack.pop();
  10846. if (num1.type !== 'literal') {
  10847. return null;
  10848. }
  10849. n = num1.number;
  10850. if (n < 0 || (n|0) !== n || stack.length < n) {
  10851. return null;
  10852. }
  10853. ast1 = stack[stack.length - n - 1];
  10854. if (ast1.type === 'literal' || ast1.type === 'var') {
  10855. stack.push(ast1);
  10856. break;
  10857. }
  10858. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  10859. stack[stack.length - n - 1] = tmpVar;
  10860. stack.push(tmpVar);
  10861. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  10862. break;
  10863. case 'dup':
  10864. if (stack.length < 1) {
  10865. return null;
  10866. }
  10867. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  10868. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  10869. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  10870. // special case of the commands sequence for the min operation
  10871. num1 = stack.pop();
  10872. stack.push(buildMinOperation(num1, code[i + 1]));
  10873. i += 6;
  10874. break;
  10875. }
  10876. ast1 = stack[stack.length - 1];
  10877. if (ast1.type === 'literal' || ast1.type === 'var') {
  10878. // we don't have to save into intermediate variable a literal or
  10879. // variable.
  10880. stack.push(ast1);
  10881. break;
  10882. }
  10883. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  10884. stack[stack.length - 1] = tmpVar;
  10885. stack.push(tmpVar);
  10886. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  10887. break;
  10888. case 'roll':
  10889. if (stack.length < 2) {
  10890. return null;
  10891. }
  10892. num2 = stack.pop();
  10893. num1 = stack.pop();
  10894. if (num2.type !== 'literal' || num1.type !== 'literal') {
  10895. // both roll operands must be numbers
  10896. return null;
  10897. }
  10898. j = num2.number;
  10899. n = num1.number;
  10900. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  10901. // ... and integers
  10902. return null;
  10903. }
  10904. j = ((j % n) + n) % n;
  10905. if (j === 0) {
  10906. break; // just skipping -- there are nothing to rotate
  10907. }
  10908. Array.prototype.push.apply(stack,
  10909. stack.splice(stack.length - n, n - j));
  10910. break;
  10911. default:
  10912. return null; // unsupported operator
  10913. }
  10914. }
  10915. if (stack.length !== outputSize) {
  10916. return null;
  10917. }
  10918. var result = [];
  10919. instructions.forEach(function (instruction) {
  10920. var statementBuilder = new ExpressionBuilderVisitor();
  10921. instruction.visit(statementBuilder);
  10922. result.push(statementBuilder.toString());
  10923. });
  10924. stack.forEach(function (expr, i) {
  10925. var statementBuilder = new ExpressionBuilderVisitor();
  10926. expr.visit(statementBuilder);
  10927. var min = range[i * 2], max = range[i * 2 + 1];
  10928. var out = [statementBuilder.toString()];
  10929. if (min > expr.min) {
  10930. out.unshift('Math.max(', min, ', ');
  10931. out.push(')');
  10932. }
  10933. if (max < expr.max) {
  10934. out.unshift('Math.min(', max, ', ');
  10935. out.push(')');
  10936. }
  10937. out.unshift('dest[destOffset + ', i, '] = ');
  10938. out.push(';');
  10939. result.push(out.join(''));
  10940. });
  10941. return result.join('\n');
  10942. }
  10943. };
  10944. return PostScriptCompiler;
  10945. })();
  10946. var ColorSpace = (function ColorSpaceClosure() {
  10947. // Constructor should define this.numComps, this.defaultColor, this.name
  10948. function ColorSpace() {
  10949. error('should not call ColorSpace constructor');
  10950. }
  10951. ColorSpace.prototype = {
  10952. /**
  10953. * Converts the color value to the RGB color. The color components are
  10954. * located in the src array starting from the srcOffset. Returns the array
  10955. * of the rgb components, each value ranging from [0,255].
  10956. */
  10957. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  10958. var rgb = new Uint8Array(3);
  10959. this.getRgbItem(src, srcOffset, rgb, 0);
  10960. return rgb;
  10961. },
  10962. /**
  10963. * Converts the color value to the RGB color, similar to the getRgb method.
  10964. * The result placed into the dest array starting from the destOffset.
  10965. */
  10966. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  10967. dest, destOffset) {
  10968. error('Should not call ColorSpace.getRgbItem');
  10969. },
  10970. /**
  10971. * Converts the specified number of the color values to the RGB colors.
  10972. * The colors are located in the src array starting from the srcOffset.
  10973. * The result is placed into the dest array starting from the destOffset.
  10974. * The src array items shall be in [0,2^bits) range, the dest array items
  10975. * will be in [0,255] range. alpha01 indicates how many alpha components
  10976. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  10977. * array).
  10978. */
  10979. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  10980. dest, destOffset, bits,
  10981. alpha01) {
  10982. error('Should not call ColorSpace.getRgbBuffer');
  10983. },
  10984. /**
  10985. * Determines the number of bytes required to store the result of the
  10986. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  10987. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  10988. */
  10989. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  10990. alpha01) {
  10991. error('Should not call ColorSpace.getOutputLength');
  10992. },
  10993. /**
  10994. * Returns true if source data will be equal the result/output data.
  10995. */
  10996. isPassthrough: function ColorSpace_isPassthrough(bits) {
  10997. return false;
  10998. },
  10999. /**
  11000. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11001. * how many alpha components there are in the dest array; it will be either
  11002. * 0 (RGB array) or 1 (RGBA array).
  11003. */
  11004. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11005. originalHeight, width, height,
  11006. actualHeight, bpc, comps, alpha01) {
  11007. var count = originalWidth * originalHeight;
  11008. var rgbBuf = null;
  11009. var numComponentColors = 1 << bpc;
  11010. var needsResizing = originalHeight !== height || originalWidth !== width;
  11011. var i, ii;
  11012. if (this.isPassthrough(bpc)) {
  11013. rgbBuf = comps;
  11014. } else if (this.numComps === 1 && count > numComponentColors &&
  11015. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11016. // Optimization: create a color map when there is just one component and
  11017. // we are converting more colors than the size of the color map. We
  11018. // don't build the map if the colorspace is gray or rgb since those
  11019. // methods are faster than building a map. This mainly offers big speed
  11020. // ups for indexed and alternate colorspaces.
  11021. //
  11022. // TODO it may be worth while to cache the color map. While running
  11023. // testing I never hit a cache so I will leave that out for now (perhaps
  11024. // we are reparsing colorspaces too much?).
  11025. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11026. new Uint16Array(numComponentColors);
  11027. var key;
  11028. for (i = 0; i < numComponentColors; i++) {
  11029. allColors[i] = i;
  11030. }
  11031. var colorMap = new Uint8Array(numComponentColors * 3);
  11032. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11033. /* alpha01 = */ 0);
  11034. var destPos, rgbPos;
  11035. if (!needsResizing) {
  11036. // Fill in the RGB values directly into |dest|.
  11037. destPos = 0;
  11038. for (i = 0; i < count; ++i) {
  11039. key = comps[i] * 3;
  11040. dest[destPos++] = colorMap[key];
  11041. dest[destPos++] = colorMap[key + 1];
  11042. dest[destPos++] = colorMap[key + 2];
  11043. destPos += alpha01;
  11044. }
  11045. } else {
  11046. rgbBuf = new Uint8Array(count * 3);
  11047. rgbPos = 0;
  11048. for (i = 0; i < count; ++i) {
  11049. key = comps[i] * 3;
  11050. rgbBuf[rgbPos++] = colorMap[key];
  11051. rgbBuf[rgbPos++] = colorMap[key + 1];
  11052. rgbBuf[rgbPos++] = colorMap[key + 2];
  11053. }
  11054. }
  11055. } else {
  11056. if (!needsResizing) {
  11057. // Fill in the RGB values directly into |dest|.
  11058. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11059. alpha01);
  11060. } else {
  11061. rgbBuf = new Uint8Array(count * 3);
  11062. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11063. /* alpha01 = */ 0);
  11064. }
  11065. }
  11066. if (rgbBuf) {
  11067. if (needsResizing) {
  11068. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11069. height, dest, alpha01);
  11070. } else {
  11071. rgbPos = 0;
  11072. destPos = 0;
  11073. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11074. dest[destPos++] = rgbBuf[rgbPos++];
  11075. dest[destPos++] = rgbBuf[rgbPos++];
  11076. dest[destPos++] = rgbBuf[rgbPos++];
  11077. destPos += alpha01;
  11078. }
  11079. }
  11080. }
  11081. },
  11082. /**
  11083. * True if the colorspace has components in the default range of [0, 1].
  11084. * This should be true for all colorspaces except for lab color spaces
  11085. * which are [0,100], [-128, 127], [-128, 127].
  11086. */
  11087. usesZeroToOneRange: true
  11088. };
  11089. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11090. var IR = ColorSpace.parseToIR(cs, xref, res);
  11091. if (IR instanceof AlternateCS) {
  11092. return IR;
  11093. }
  11094. return ColorSpace.fromIR(IR);
  11095. };
  11096. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11097. var name = isArray(IR) ? IR[0] : IR;
  11098. var whitePoint, blackPoint;
  11099. switch (name) {
  11100. case 'DeviceGrayCS':
  11101. return this.singletons.gray;
  11102. case 'DeviceRgbCS':
  11103. return this.singletons.rgb;
  11104. case 'DeviceCmykCS':
  11105. return this.singletons.cmyk;
  11106. case 'CalGrayCS':
  11107. whitePoint = IR[1].WhitePoint;
  11108. blackPoint = IR[1].BlackPoint;
  11109. var gamma = IR[1].Gamma;
  11110. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11111. case 'PatternCS':
  11112. var basePatternCS = IR[1];
  11113. if (basePatternCS) {
  11114. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11115. }
  11116. return new PatternCS(basePatternCS);
  11117. case 'IndexedCS':
  11118. var baseIndexedCS = IR[1];
  11119. var hiVal = IR[2];
  11120. var lookup = IR[3];
  11121. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11122. case 'AlternateCS':
  11123. var numComps = IR[1];
  11124. var alt = IR[2];
  11125. var tintFnIR = IR[3];
  11126. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11127. PDFFunction.fromIR(tintFnIR));
  11128. case 'LabCS':
  11129. whitePoint = IR[1].WhitePoint;
  11130. blackPoint = IR[1].BlackPoint;
  11131. var range = IR[1].Range;
  11132. return new LabCS(whitePoint, blackPoint, range);
  11133. default:
  11134. error('Unknown name ' + name);
  11135. }
  11136. return null;
  11137. };
  11138. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11139. if (isName(cs)) {
  11140. var colorSpaces = res.get('ColorSpace');
  11141. if (isDict(colorSpaces)) {
  11142. var refcs = colorSpaces.get(cs.name);
  11143. if (refcs) {
  11144. cs = refcs;
  11145. }
  11146. }
  11147. }
  11148. cs = xref.fetchIfRef(cs);
  11149. var mode;
  11150. if (isName(cs)) {
  11151. mode = cs.name;
  11152. this.mode = mode;
  11153. switch (mode) {
  11154. case 'DeviceGray':
  11155. case 'G':
  11156. return 'DeviceGrayCS';
  11157. case 'DeviceRGB':
  11158. case 'RGB':
  11159. return 'DeviceRgbCS';
  11160. case 'DeviceCMYK':
  11161. case 'CMYK':
  11162. return 'DeviceCmykCS';
  11163. case 'Pattern':
  11164. return ['PatternCS', null];
  11165. default:
  11166. error('unrecognized colorspace ' + mode);
  11167. }
  11168. } else if (isArray(cs)) {
  11169. mode = cs[0].name;
  11170. this.mode = mode;
  11171. var numComps, params;
  11172. switch (mode) {
  11173. case 'DeviceGray':
  11174. case 'G':
  11175. return 'DeviceGrayCS';
  11176. case 'DeviceRGB':
  11177. case 'RGB':
  11178. return 'DeviceRgbCS';
  11179. case 'DeviceCMYK':
  11180. case 'CMYK':
  11181. return 'DeviceCmykCS';
  11182. case 'CalGray':
  11183. params = cs[1].getAll();
  11184. return ['CalGrayCS', params];
  11185. case 'CalRGB':
  11186. return 'DeviceRgbCS';
  11187. case 'ICCBased':
  11188. var stream = xref.fetchIfRef(cs[1]);
  11189. var dict = stream.dict;
  11190. numComps = dict.get('N');
  11191. if (numComps === 1) {
  11192. return 'DeviceGrayCS';
  11193. } else if (numComps === 3) {
  11194. return 'DeviceRgbCS';
  11195. } else if (numComps === 4) {
  11196. return 'DeviceCmykCS';
  11197. }
  11198. break;
  11199. case 'Pattern':
  11200. var basePatternCS = cs[1];
  11201. if (basePatternCS) {
  11202. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11203. }
  11204. return ['PatternCS', basePatternCS];
  11205. case 'Indexed':
  11206. case 'I':
  11207. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11208. var hiVal = cs[2] + 1;
  11209. var lookup = xref.fetchIfRef(cs[3]);
  11210. if (isStream(lookup)) {
  11211. lookup = lookup.getBytes();
  11212. }
  11213. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11214. case 'Separation':
  11215. case 'DeviceN':
  11216. var name = cs[1];
  11217. numComps = 1;
  11218. if (isName(name)) {
  11219. numComps = 1;
  11220. } else if (isArray(name)) {
  11221. numComps = name.length;
  11222. }
  11223. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11224. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11225. return ['AlternateCS', numComps, alt, tintFnIR];
  11226. case 'Lab':
  11227. params = cs[1].getAll();
  11228. return ['LabCS', params];
  11229. default:
  11230. error('unimplemented color space object "' + mode + '"');
  11231. }
  11232. } else {
  11233. error('unrecognized color space object: "' + cs + '"');
  11234. }
  11235. return null;
  11236. };
  11237. /**
  11238. * Checks if a decode map matches the default decode map for a color space.
  11239. * This handles the general decode maps where there are two values per
  11240. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11241. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11242. * slightly different.
  11243. * @param {Array} decode Decode map (usually from an image).
  11244. * @param {Number} n Number of components the color space has.
  11245. */
  11246. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11247. if (!decode) {
  11248. return true;
  11249. }
  11250. if (n * 2 !== decode.length) {
  11251. warn('The decode map is not the correct length');
  11252. return true;
  11253. }
  11254. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11255. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11256. return false;
  11257. }
  11258. }
  11259. return true;
  11260. };
  11261. ColorSpace.singletons = {
  11262. get gray() {
  11263. return shadow(this, 'gray', new DeviceGrayCS());
  11264. },
  11265. get rgb() {
  11266. return shadow(this, 'rgb', new DeviceRgbCS());
  11267. },
  11268. get cmyk() {
  11269. return shadow(this, 'cmyk', new DeviceCmykCS());
  11270. }
  11271. };
  11272. return ColorSpace;
  11273. })();
  11274. /**
  11275. * Alternate color space handles both Separation and DeviceN color spaces. A
  11276. * Separation color space is actually just a DeviceN with one color component.
  11277. * Both color spaces use a tinting function to convert colors to a base color
  11278. * space.
  11279. */
  11280. var AlternateCS = (function AlternateCSClosure() {
  11281. function AlternateCS(numComps, base, tintFn) {
  11282. this.name = 'Alternate';
  11283. this.numComps = numComps;
  11284. this.defaultColor = new Float32Array(numComps);
  11285. for (var i = 0; i < numComps; ++i) {
  11286. this.defaultColor[i] = 1;
  11287. }
  11288. this.base = base;
  11289. this.tintFn = tintFn;
  11290. this.tmpBuf = new Float32Array(base.numComps);
  11291. }
  11292. AlternateCS.prototype = {
  11293. getRgb: ColorSpace.prototype.getRgb,
  11294. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11295. dest, destOffset) {
  11296. var tmpBuf = this.tmpBuf;
  11297. this.tintFn(src, srcOffset, tmpBuf, 0);
  11298. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11299. },
  11300. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11301. dest, destOffset, bits,
  11302. alpha01) {
  11303. var tintFn = this.tintFn;
  11304. var base = this.base;
  11305. var scale = 1 / ((1 << bits) - 1);
  11306. var baseNumComps = base.numComps;
  11307. var usesZeroToOneRange = base.usesZeroToOneRange;
  11308. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11309. alpha01 === 0;
  11310. var pos = isPassthrough ? destOffset : 0;
  11311. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11312. var numComps = this.numComps;
  11313. var scaled = new Float32Array(numComps);
  11314. var tinted = new Float32Array(baseNumComps);
  11315. var i, j;
  11316. if (usesZeroToOneRange) {
  11317. for (i = 0; i < count; i++) {
  11318. for (j = 0; j < numComps; j++) {
  11319. scaled[j] = src[srcOffset++] * scale;
  11320. }
  11321. tintFn(scaled, 0, tinted, 0);
  11322. for (j = 0; j < baseNumComps; j++) {
  11323. baseBuf[pos++] = tinted[j] * 255;
  11324. }
  11325. }
  11326. } else {
  11327. for (i = 0; i < count; i++) {
  11328. for (j = 0; j < numComps; j++) {
  11329. scaled[j] = src[srcOffset++] * scale;
  11330. }
  11331. tintFn(scaled, 0, tinted, 0);
  11332. base.getRgbItem(tinted, 0, baseBuf, pos);
  11333. pos += baseNumComps;
  11334. }
  11335. }
  11336. if (!isPassthrough) {
  11337. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11338. }
  11339. },
  11340. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11341. alpha01) {
  11342. return this.base.getOutputLength(inputLength *
  11343. this.base.numComps / this.numComps,
  11344. alpha01);
  11345. },
  11346. isPassthrough: ColorSpace.prototype.isPassthrough,
  11347. fillRgb: ColorSpace.prototype.fillRgb,
  11348. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11349. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11350. },
  11351. usesZeroToOneRange: true
  11352. };
  11353. return AlternateCS;
  11354. })();
  11355. var PatternCS = (function PatternCSClosure() {
  11356. function PatternCS(baseCS) {
  11357. this.name = 'Pattern';
  11358. this.base = baseCS;
  11359. }
  11360. PatternCS.prototype = {};
  11361. return PatternCS;
  11362. })();
  11363. var IndexedCS = (function IndexedCSClosure() {
  11364. function IndexedCS(base, highVal, lookup) {
  11365. this.name = 'Indexed';
  11366. this.numComps = 1;
  11367. this.defaultColor = new Uint8Array([0]);
  11368. this.base = base;
  11369. this.highVal = highVal;
  11370. var baseNumComps = base.numComps;
  11371. var length = baseNumComps * highVal;
  11372. var lookupArray;
  11373. if (isStream(lookup)) {
  11374. lookupArray = new Uint8Array(length);
  11375. var bytes = lookup.getBytes(length);
  11376. lookupArray.set(bytes);
  11377. } else if (isString(lookup)) {
  11378. lookupArray = new Uint8Array(length);
  11379. for (var i = 0; i < length; ++i) {
  11380. lookupArray[i] = lookup.charCodeAt(i);
  11381. }
  11382. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11383. lookupArray = lookup;
  11384. } else {
  11385. error('Unrecognized lookup table: ' + lookup);
  11386. }
  11387. this.lookup = lookupArray;
  11388. }
  11389. IndexedCS.prototype = {
  11390. getRgb: ColorSpace.prototype.getRgb,
  11391. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11392. dest, destOffset) {
  11393. var numComps = this.base.numComps;
  11394. var start = src[srcOffset] * numComps;
  11395. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11396. },
  11397. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11398. dest, destOffset, bits,
  11399. alpha01) {
  11400. var base = this.base;
  11401. var numComps = base.numComps;
  11402. var outputDelta = base.getOutputLength(numComps, alpha01);
  11403. var lookup = this.lookup;
  11404. for (var i = 0; i < count; ++i) {
  11405. var lookupPos = src[srcOffset++] * numComps;
  11406. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11407. destOffset += outputDelta;
  11408. }
  11409. },
  11410. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11411. return this.base.getOutputLength(inputLength * this.base.numComps,
  11412. alpha01);
  11413. },
  11414. isPassthrough: ColorSpace.prototype.isPassthrough,
  11415. fillRgb: ColorSpace.prototype.fillRgb,
  11416. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11417. // indexed color maps shouldn't be changed
  11418. return true;
  11419. },
  11420. usesZeroToOneRange: true
  11421. };
  11422. return IndexedCS;
  11423. })();
  11424. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11425. function DeviceGrayCS() {
  11426. this.name = 'DeviceGray';
  11427. this.numComps = 1;
  11428. this.defaultColor = new Float32Array([0]);
  11429. }
  11430. DeviceGrayCS.prototype = {
  11431. getRgb: ColorSpace.prototype.getRgb,
  11432. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11433. dest, destOffset) {
  11434. var c = (src[srcOffset] * 255) | 0;
  11435. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11436. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11437. },
  11438. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11439. dest, destOffset, bits,
  11440. alpha01) {
  11441. var scale = 255 / ((1 << bits) - 1);
  11442. var j = srcOffset, q = destOffset;
  11443. for (var i = 0; i < count; ++i) {
  11444. var c = (scale * src[j++]) | 0;
  11445. dest[q++] = c;
  11446. dest[q++] = c;
  11447. dest[q++] = c;
  11448. q += alpha01;
  11449. }
  11450. },
  11451. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11452. alpha01) {
  11453. return inputLength * (3 + alpha01);
  11454. },
  11455. isPassthrough: ColorSpace.prototype.isPassthrough,
  11456. fillRgb: ColorSpace.prototype.fillRgb,
  11457. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11458. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11459. },
  11460. usesZeroToOneRange: true
  11461. };
  11462. return DeviceGrayCS;
  11463. })();
  11464. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11465. function DeviceRgbCS() {
  11466. this.name = 'DeviceRGB';
  11467. this.numComps = 3;
  11468. this.defaultColor = new Float32Array([0, 0, 0]);
  11469. }
  11470. DeviceRgbCS.prototype = {
  11471. getRgb: ColorSpace.prototype.getRgb,
  11472. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11473. dest, destOffset) {
  11474. var r = (src[srcOffset] * 255) | 0;
  11475. var g = (src[srcOffset + 1] * 255) | 0;
  11476. var b = (src[srcOffset + 2] * 255) | 0;
  11477. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11478. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11479. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11480. },
  11481. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11482. dest, destOffset, bits,
  11483. alpha01) {
  11484. if (bits === 8 && alpha01 === 0) {
  11485. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  11486. return;
  11487. }
  11488. var scale = 255 / ((1 << bits) - 1);
  11489. var j = srcOffset, q = destOffset;
  11490. for (var i = 0; i < count; ++i) {
  11491. dest[q++] = (scale * src[j++]) | 0;
  11492. dest[q++] = (scale * src[j++]) | 0;
  11493. dest[q++] = (scale * src[j++]) | 0;
  11494. q += alpha01;
  11495. }
  11496. },
  11497. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  11498. alpha01) {
  11499. return (inputLength * (3 + alpha01) / 3) | 0;
  11500. },
  11501. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  11502. return bits === 8;
  11503. },
  11504. fillRgb: ColorSpace.prototype.fillRgb,
  11505. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  11506. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11507. },
  11508. usesZeroToOneRange: true
  11509. };
  11510. return DeviceRgbCS;
  11511. })();
  11512. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  11513. // The coefficients below was found using numerical analysis: the method of
  11514. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  11515. // where color_value is the tabular value from the table of sampled RGB colors
  11516. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  11517. // CMYK color conversion using the estimation below:
  11518. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  11519. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  11520. var c = src[srcOffset + 0] * srcScale;
  11521. var m = src[srcOffset + 1] * srcScale;
  11522. var y = src[srcOffset + 2] * srcScale;
  11523. var k = src[srcOffset + 3] * srcScale;
  11524. var r =
  11525. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11526. 18.82290502165302 * y + 212.25662451639585 * k +
  11527. -285.2331026137004) +
  11528. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  11529. -17.873870861415444 * k - 5.497006427196366) +
  11530. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11531. 17.5119270841813) +
  11532. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  11533. var g =
  11534. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  11535. 6.871425592049007 * y + 31.159100130055922 * k +
  11536. -79.2970844816548) +
  11537. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11538. 131.35250912493976 * k - 190.9453302588951) +
  11539. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  11540. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  11541. var b =
  11542. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11543. 30.89978309703729 * y - 0.23883238689178934 * k +
  11544. -14.183576799673286) +
  11545. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11546. 50.606957656360734 * k - 112.23884253719248) +
  11547. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  11548. -193.58209356861505) +
  11549. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  11550. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  11551. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  11552. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  11553. }
  11554. function DeviceCmykCS() {
  11555. this.name = 'DeviceCMYK';
  11556. this.numComps = 4;
  11557. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  11558. }
  11559. DeviceCmykCS.prototype = {
  11560. getRgb: ColorSpace.prototype.getRgb,
  11561. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  11562. dest, destOffset) {
  11563. convertToRgb(src, srcOffset, 1, dest, destOffset);
  11564. },
  11565. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  11566. dest, destOffset, bits,
  11567. alpha01) {
  11568. var scale = 1 / ((1 << bits) - 1);
  11569. for (var i = 0; i < count; i++) {
  11570. convertToRgb(src, srcOffset, scale, dest, destOffset);
  11571. srcOffset += 4;
  11572. destOffset += 3 + alpha01;
  11573. }
  11574. },
  11575. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  11576. alpha01) {
  11577. return (inputLength / 4 * (3 + alpha01)) | 0;
  11578. },
  11579. isPassthrough: ColorSpace.prototype.isPassthrough,
  11580. fillRgb: ColorSpace.prototype.fillRgb,
  11581. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  11582. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11583. },
  11584. usesZeroToOneRange: true
  11585. };
  11586. return DeviceCmykCS;
  11587. })();
  11588. //
  11589. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  11590. //
  11591. var CalGrayCS = (function CalGrayCSClosure() {
  11592. function CalGrayCS(whitePoint, blackPoint, gamma) {
  11593. this.name = 'CalGray';
  11594. this.numComps = 1;
  11595. this.defaultColor = new Float32Array([0]);
  11596. if (!whitePoint) {
  11597. error('WhitePoint missing - required for color space CalGray');
  11598. }
  11599. blackPoint = blackPoint || [0, 0, 0];
  11600. gamma = gamma || 1;
  11601. // Translate arguments to spec variables.
  11602. this.XW = whitePoint[0];
  11603. this.YW = whitePoint[1];
  11604. this.ZW = whitePoint[2];
  11605. this.XB = blackPoint[0];
  11606. this.YB = blackPoint[1];
  11607. this.ZB = blackPoint[2];
  11608. this.G = gamma;
  11609. // Validate variables as per spec.
  11610. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  11611. error('Invalid WhitePoint components for ' + this.name +
  11612. ', no fallback available');
  11613. }
  11614. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  11615. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  11616. this.XB = this.YB = this.ZB = 0;
  11617. }
  11618. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  11619. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  11620. ', ZB: ' + this.ZB + ', only default values are supported.');
  11621. }
  11622. if (this.G < 1) {
  11623. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  11624. ', falling back to default');
  11625. this.G = 1;
  11626. }
  11627. }
  11628. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  11629. // A represents a gray component of a calibrated gray space.
  11630. // A <---> AG in the spec
  11631. var A = src[srcOffset] * scale;
  11632. var AG = Math.pow(A, cs.G);
  11633. // Computes L as per spec. ( = cs.YW * AG )
  11634. // Except if other than default BlackPoint values are used.
  11635. var L = cs.YW * AG;
  11636. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  11637. // Convert values to rgb range [0, 255].
  11638. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  11639. dest[destOffset] = val;
  11640. dest[destOffset + 1] = val;
  11641. dest[destOffset + 2] = val;
  11642. }
  11643. CalGrayCS.prototype = {
  11644. getRgb: ColorSpace.prototype.getRgb,
  11645. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  11646. dest, destOffset) {
  11647. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  11648. },
  11649. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  11650. dest, destOffset, bits,
  11651. alpha01) {
  11652. var scale = 1 / ((1 << bits) - 1);
  11653. for (var i = 0; i < count; ++i) {
  11654. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  11655. srcOffset += 1;
  11656. destOffset += 3 + alpha01;
  11657. }
  11658. },
  11659. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  11660. return inputLength * (3 + alpha01);
  11661. },
  11662. isPassthrough: ColorSpace.prototype.isPassthrough,
  11663. fillRgb: ColorSpace.prototype.fillRgb,
  11664. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  11665. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11666. },
  11667. usesZeroToOneRange: true
  11668. };
  11669. return CalGrayCS;
  11670. })();
  11671. //
  11672. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  11673. //
  11674. var LabCS = (function LabCSClosure() {
  11675. function LabCS(whitePoint, blackPoint, range) {
  11676. this.name = 'Lab';
  11677. this.numComps = 3;
  11678. this.defaultColor = new Float32Array([0, 0, 0]);
  11679. if (!whitePoint) {
  11680. error('WhitePoint missing - required for color space Lab');
  11681. }
  11682. blackPoint = blackPoint || [0, 0, 0];
  11683. range = range || [-100, 100, -100, 100];
  11684. // Translate args to spec variables
  11685. this.XW = whitePoint[0];
  11686. this.YW = whitePoint[1];
  11687. this.ZW = whitePoint[2];
  11688. this.amin = range[0];
  11689. this.amax = range[1];
  11690. this.bmin = range[2];
  11691. this.bmax = range[3];
  11692. // These are here just for completeness - the spec doesn't offer any
  11693. // formulas that use BlackPoint in Lab
  11694. this.XB = blackPoint[0];
  11695. this.YB = blackPoint[1];
  11696. this.ZB = blackPoint[2];
  11697. // Validate vars as per spec
  11698. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  11699. error('Invalid WhitePoint components, no fallback available');
  11700. }
  11701. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  11702. info('Invalid BlackPoint, falling back to default');
  11703. this.XB = this.YB = this.ZB = 0;
  11704. }
  11705. if (this.amin > this.amax || this.bmin > this.bmax) {
  11706. info('Invalid Range, falling back to defaults');
  11707. this.amin = -100;
  11708. this.amax = 100;
  11709. this.bmin = -100;
  11710. this.bmax = 100;
  11711. }
  11712. }
  11713. // Function g(x) from spec
  11714. function fn_g(x) {
  11715. if (x >= 6 / 29) {
  11716. return x * x * x;
  11717. } else {
  11718. return (108 / 841) * (x - 4 / 29);
  11719. }
  11720. }
  11721. function decode(value, high1, low2, high2) {
  11722. return low2 + (value) * (high2 - low2) / (high1);
  11723. }
  11724. // If decoding is needed maxVal should be 2^bits per component - 1.
  11725. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  11726. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  11727. // not the usual [0, 1]. If a command like setFillColor is used the src
  11728. // values will already be within the correct range. However, if we are
  11729. // converting an image we have to map the values to the correct range given
  11730. // above.
  11731. // Ls,as,bs <---> L*,a*,b* in the spec
  11732. var Ls = src[srcOffset];
  11733. var as = src[srcOffset + 1];
  11734. var bs = src[srcOffset + 2];
  11735. if (maxVal !== false) {
  11736. Ls = decode(Ls, maxVal, 0, 100);
  11737. as = decode(as, maxVal, cs.amin, cs.amax);
  11738. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  11739. }
  11740. // Adjust limits of 'as' and 'bs'
  11741. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  11742. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  11743. // Computes intermediate variables X,Y,Z as per spec
  11744. var M = (Ls + 16) / 116;
  11745. var L = M + (as / 500);
  11746. var N = M - (bs / 200);
  11747. var X = cs.XW * fn_g(L);
  11748. var Y = cs.YW * fn_g(M);
  11749. var Z = cs.ZW * fn_g(N);
  11750. var r, g, b;
  11751. // Using different conversions for D50 and D65 white points,
  11752. // per http://www.color.org/srgb.pdf
  11753. if (cs.ZW < 1) {
  11754. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  11755. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  11756. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  11757. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  11758. } else {
  11759. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  11760. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  11761. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  11762. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  11763. }
  11764. // clamp color values to [0,1] range then convert to [0,255] range.
  11765. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  11766. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  11767. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  11768. }
  11769. LabCS.prototype = {
  11770. getRgb: ColorSpace.prototype.getRgb,
  11771. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  11772. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  11773. },
  11774. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  11775. dest, destOffset, bits,
  11776. alpha01) {
  11777. var maxVal = (1 << bits) - 1;
  11778. for (var i = 0; i < count; i++) {
  11779. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  11780. srcOffset += 3;
  11781. destOffset += 3 + alpha01;
  11782. }
  11783. },
  11784. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  11785. return (inputLength * (3 + alpha01) / 3) | 0;
  11786. },
  11787. isPassthrough: ColorSpace.prototype.isPassthrough,
  11788. fillRgb: ColorSpace.prototype.fillRgb,
  11789. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  11790. // XXX: Decoding is handled with the lab conversion because of the strange
  11791. // ranges that are used.
  11792. return true;
  11793. },
  11794. usesZeroToOneRange: false
  11795. };
  11796. return LabCS;
  11797. })();
  11798. var ARCFourCipher = (function ARCFourCipherClosure() {
  11799. function ARCFourCipher(key) {
  11800. this.a = 0;
  11801. this.b = 0;
  11802. var s = new Uint8Array(256);
  11803. var i, j = 0, tmp, keyLength = key.length;
  11804. for (i = 0; i < 256; ++i) {
  11805. s[i] = i;
  11806. }
  11807. for (i = 0; i < 256; ++i) {
  11808. tmp = s[i];
  11809. j = (j + tmp + key[i % keyLength]) & 0xFF;
  11810. s[i] = s[j];
  11811. s[j] = tmp;
  11812. }
  11813. this.s = s;
  11814. }
  11815. ARCFourCipher.prototype = {
  11816. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  11817. var i, n = data.length, tmp, tmp2;
  11818. var a = this.a, b = this.b, s = this.s;
  11819. var output = new Uint8Array(n);
  11820. for (i = 0; i < n; ++i) {
  11821. a = (a + 1) & 0xFF;
  11822. tmp = s[a];
  11823. b = (b + tmp) & 0xFF;
  11824. tmp2 = s[b];
  11825. s[a] = tmp2;
  11826. s[b] = tmp;
  11827. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  11828. }
  11829. this.a = a;
  11830. this.b = b;
  11831. return output;
  11832. }
  11833. };
  11834. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  11835. return ARCFourCipher;
  11836. })();
  11837. var calculateMD5 = (function calculateMD5Closure() {
  11838. var r = new Uint8Array([
  11839. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  11840. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  11841. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  11842. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  11843. var k = new Int32Array([
  11844. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  11845. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  11846. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  11847. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  11848. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  11849. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  11850. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  11851. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  11852. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  11853. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  11854. -145523070, -1120210379, 718787259, -343485551]);
  11855. function hash(data, offset, length) {
  11856. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  11857. // pre-processing
  11858. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  11859. var padded = new Uint8Array(paddedLength);
  11860. var i, j, n;
  11861. for (i = 0; i < length; ++i) {
  11862. padded[i] = data[offset++];
  11863. }
  11864. padded[i++] = 0x80;
  11865. n = paddedLength - 8;
  11866. while (i < n) {
  11867. padded[i++] = 0;
  11868. }
  11869. padded[i++] = (length << 3) & 0xFF;
  11870. padded[i++] = (length >> 5) & 0xFF;
  11871. padded[i++] = (length >> 13) & 0xFF;
  11872. padded[i++] = (length >> 21) & 0xFF;
  11873. padded[i++] = (length >>> 29) & 0xFF;
  11874. padded[i++] = 0;
  11875. padded[i++] = 0;
  11876. padded[i++] = 0;
  11877. var w = new Int32Array(16);
  11878. for (i = 0; i < paddedLength;) {
  11879. for (j = 0; j < 16; ++j, i += 4) {
  11880. w[j] = (padded[i] | (padded[i + 1] << 8) |
  11881. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  11882. }
  11883. var a = h0, b = h1, c = h2, d = h3, f, g;
  11884. for (j = 0; j < 64; ++j) {
  11885. if (j < 16) {
  11886. f = (b & c) | ((~b) & d);
  11887. g = j;
  11888. } else if (j < 32) {
  11889. f = (d & b) | ((~d) & c);
  11890. g = (5 * j + 1) & 15;
  11891. } else if (j < 48) {
  11892. f = b ^ c ^ d;
  11893. g = (3 * j + 5) & 15;
  11894. } else {
  11895. f = c ^ (b | (~d));
  11896. g = (7 * j) & 15;
  11897. }
  11898. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  11899. d = c;
  11900. c = b;
  11901. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  11902. a = tmp;
  11903. }
  11904. h0 = (h0 + a) | 0;
  11905. h1 = (h1 + b) | 0;
  11906. h2 = (h2 + c) | 0;
  11907. h3 = (h3 + d) | 0;
  11908. }
  11909. return new Uint8Array([
  11910. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  11911. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  11912. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  11913. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  11914. ]);
  11915. }
  11916. return hash;
  11917. })();
  11918. var Word64 = (function Word64Closure() {
  11919. function Word64(highInteger, lowInteger) {
  11920. this.high = highInteger | 0;
  11921. this.low = lowInteger | 0;
  11922. }
  11923. Word64.prototype = {
  11924. and: function Word64_and(word) {
  11925. this.high &= word.high;
  11926. this.low &= word.low;
  11927. },
  11928. xor: function Word64_xor(word) {
  11929. this.high ^= word.high;
  11930. this.low ^= word.low;
  11931. },
  11932. or: function Word64_or(word) {
  11933. this.high |= word.high;
  11934. this.low |= word.low;
  11935. },
  11936. shiftRight: function Word64_shiftRight(places) {
  11937. if (places >= 32) {
  11938. this.low = (this.high >>> (places - 32)) | 0;
  11939. this.high = 0;
  11940. } else {
  11941. this.low = (this.low >>> places) | (this.high << (32 - places));
  11942. this.high = (this.high >>> places) | 0;
  11943. }
  11944. },
  11945. shiftLeft: function Word64_shiftLeft(places) {
  11946. if (places >= 32) {
  11947. this.high = this.low << (places - 32);
  11948. this.low = 0;
  11949. } else {
  11950. this.high = (this.high << places) | (this.low >>> (32 - places));
  11951. this.low = this.low << places;
  11952. }
  11953. },
  11954. rotateRight: function Word64_rotateRight(places) {
  11955. var low, high;
  11956. if (places & 32) {
  11957. high = this.low;
  11958. low = this.high;
  11959. } else {
  11960. low = this.low;
  11961. high = this.high;
  11962. }
  11963. places &= 31;
  11964. this.low = (low >>> places) | (high << (32 - places));
  11965. this.high = (high >>> places) | (low << (32 - places));
  11966. },
  11967. not: function Word64_not() {
  11968. this.high = ~this.high;
  11969. this.low = ~this.low;
  11970. },
  11971. add: function Word64_add(word) {
  11972. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  11973. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  11974. if (lowAdd > 0xFFFFFFFF) {
  11975. highAdd += 1;
  11976. }
  11977. this.low = lowAdd | 0;
  11978. this.high = highAdd | 0;
  11979. },
  11980. copyTo: function Word64_copyTo(bytes, offset) {
  11981. bytes[offset] = (this.high >>> 24) & 0xFF;
  11982. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  11983. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  11984. bytes[offset + 3] = this.high & 0xFF;
  11985. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  11986. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  11987. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  11988. bytes[offset + 7] = this.low & 0xFF;
  11989. },
  11990. assign: function Word64_assign(word) {
  11991. this.high = word.high;
  11992. this.low = word.low;
  11993. }
  11994. };
  11995. return Word64;
  11996. })();
  11997. var calculateSHA256 = (function calculateSHA256Closure() {
  11998. function rotr(x, n) {
  11999. return (x >>> n) | (x << 32 - n);
  12000. }
  12001. function ch(x, y, z) {
  12002. return (x & y) ^ (~x & z);
  12003. }
  12004. function maj(x, y, z) {
  12005. return (x & y) ^ (x & z) ^ (y & z);
  12006. }
  12007. function sigma(x) {
  12008. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12009. }
  12010. function sigmaPrime(x) {
  12011. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12012. }
  12013. function littleSigma(x) {
  12014. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12015. }
  12016. function littleSigmaPrime(x) {
  12017. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12018. }
  12019. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12020. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12021. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12022. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12023. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12024. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12025. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12026. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12027. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12028. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12029. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12030. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12031. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12032. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12033. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12034. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12035. function hash(data, offset, length) {
  12036. // initial hash values
  12037. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12038. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12039. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12040. // pre-processing
  12041. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12042. var padded = new Uint8Array(paddedLength);
  12043. var i, j, n;
  12044. for (i = 0; i < length; ++i) {
  12045. padded[i] = data[offset++];
  12046. }
  12047. padded[i++] = 0x80;
  12048. n = paddedLength - 8;
  12049. while (i < n) {
  12050. padded[i++] = 0;
  12051. }
  12052. padded[i++] = 0;
  12053. padded[i++] = 0;
  12054. padded[i++] = 0;
  12055. padded[i++] = (length >>> 29) & 0xFF;
  12056. padded[i++] = (length >> 21) & 0xFF;
  12057. padded[i++] = (length >> 13) & 0xFF;
  12058. padded[i++] = (length >> 5) & 0xFF;
  12059. padded[i++] = (length << 3) & 0xFF;
  12060. var w = new Uint32Array(64);
  12061. // for each 512 bit block
  12062. for (i = 0; i < paddedLength;) {
  12063. for (j = 0; j < 16; ++j) {
  12064. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12065. (padded[i + 2] << 8) | (padded[i + 3]));
  12066. i += 4;
  12067. }
  12068. for (j = 16; j < 64; ++j) {
  12069. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12070. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12071. }
  12072. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12073. f = h5, g = h6, h = h7, t1, t2;
  12074. for (j = 0; j < 64; ++j) {
  12075. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12076. t2 = sigma(a) + maj(a, b, c);
  12077. h = g;
  12078. g = f;
  12079. f = e;
  12080. e = (d + t1) | 0;
  12081. d = c;
  12082. c = b;
  12083. b = a;
  12084. a = (t1 + t2) | 0;
  12085. }
  12086. h0 = (h0 + a) | 0;
  12087. h1 = (h1 + b) | 0;
  12088. h2 = (h2 + c) | 0;
  12089. h3 = (h3 + d) | 0;
  12090. h4 = (h4 + e) | 0;
  12091. h5 = (h5 + f) | 0;
  12092. h6 = (h6 + g) | 0;
  12093. h7 = (h7 + h) | 0;
  12094. }
  12095. return new Uint8Array([
  12096. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12097. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12098. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12099. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12100. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12101. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12102. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12103. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12104. ]);
  12105. }
  12106. return hash;
  12107. })();
  12108. var calculateSHA512 = (function calculateSHA512Closure() {
  12109. function ch(result, x, y, z, tmp) {
  12110. result.assign(x);
  12111. result.and(y);
  12112. tmp.assign(x);
  12113. tmp.not();
  12114. tmp.and(z);
  12115. result.xor(tmp);
  12116. }
  12117. function maj(result, x, y, z, tmp) {
  12118. result.assign(x);
  12119. result.and(y);
  12120. tmp.assign(x);
  12121. tmp.and(z);
  12122. result.xor(tmp);
  12123. tmp.assign(y);
  12124. tmp.and(z);
  12125. result.xor(tmp);
  12126. }
  12127. function sigma(result, x, tmp) {
  12128. result.assign(x);
  12129. result.rotateRight(28);
  12130. tmp.assign(x);
  12131. tmp.rotateRight(34);
  12132. result.xor(tmp);
  12133. tmp.assign(x);
  12134. tmp.rotateRight(39);
  12135. result.xor(tmp);
  12136. }
  12137. function sigmaPrime(result, x, tmp) {
  12138. result.assign(x);
  12139. result.rotateRight(14);
  12140. tmp.assign(x);
  12141. tmp.rotateRight(18);
  12142. result.xor(tmp);
  12143. tmp.assign(x);
  12144. tmp.rotateRight(41);
  12145. result.xor(tmp);
  12146. }
  12147. function littleSigma(result, x, tmp) {
  12148. result.assign(x);
  12149. result.rotateRight(1);
  12150. tmp.assign(x);
  12151. tmp.rotateRight(8);
  12152. result.xor(tmp);
  12153. tmp.assign(x);
  12154. tmp.shiftRight(7);
  12155. result.xor(tmp);
  12156. }
  12157. function littleSigmaPrime(result, x, tmp) {
  12158. result.assign(x);
  12159. result.rotateRight(19);
  12160. tmp.assign(x);
  12161. tmp.rotateRight(61);
  12162. result.xor(tmp);
  12163. tmp.assign(x);
  12164. tmp.shiftRight(6);
  12165. result.xor(tmp);
  12166. }
  12167. var k = [
  12168. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12169. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12170. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12171. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12172. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12173. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12174. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12175. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12176. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12177. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12178. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12179. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12180. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12181. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12182. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12183. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12184. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12185. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12186. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12187. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12188. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12189. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12190. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12191. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12192. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12193. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12194. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12195. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12196. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12197. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12198. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12199. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12200. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12201. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12202. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12203. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12204. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12205. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12206. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12207. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12208. function hash(data, offset, length, mode384) {
  12209. mode384 = !!mode384;
  12210. // initial hash values
  12211. var h0, h1, h2, h3, h4, h5, h6, h7;
  12212. if (!mode384) {
  12213. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12214. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12215. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12216. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12217. h4 = new Word64(0x510e527f, 0xade682d1);
  12218. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12219. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12220. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12221. }
  12222. else {
  12223. // SHA384 is exactly the same
  12224. // except with different starting values and a trimmed result
  12225. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12226. h1 = new Word64(0x629a292a, 0x367cd507);
  12227. h2 = new Word64(0x9159015a, 0x3070dd17);
  12228. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12229. h4 = new Word64(0x67332667, 0xffc00b31);
  12230. h5 = new Word64(0x8eb44a87, 0x68581511);
  12231. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12232. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12233. }
  12234. // pre-processing
  12235. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12236. var padded = new Uint8Array(paddedLength);
  12237. var i, j, n;
  12238. for (i = 0; i < length; ++i) {
  12239. padded[i] = data[offset++];
  12240. }
  12241. padded[i++] = 0x80;
  12242. n = paddedLength - 16;
  12243. while (i < n) {
  12244. padded[i++] = 0;
  12245. }
  12246. padded[i++] = 0;
  12247. padded[i++] = 0;
  12248. padded[i++] = 0;
  12249. padded[i++] = 0;
  12250. padded[i++] = 0;
  12251. padded[i++] = 0;
  12252. padded[i++] = 0;
  12253. padded[i++] = 0;
  12254. padded[i++] = 0;
  12255. padded[i++] = 0;
  12256. padded[i++] = 0;
  12257. padded[i++] = (length >>> 29) & 0xFF;
  12258. padded[i++] = (length >> 21) & 0xFF;
  12259. padded[i++] = (length >> 13) & 0xFF;
  12260. padded[i++] = (length >> 5) & 0xFF;
  12261. padded[i++] = (length << 3) & 0xFF;
  12262. var w = new Array(80);
  12263. for (i = 0; i < 80; i++) {
  12264. w[i] = new Word64(0, 0);
  12265. }
  12266. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  12267. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  12268. var g = new Word64(0, 0), h = new Word64(0, 0);
  12269. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  12270. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  12271. // for each 1024 bit block
  12272. for (i = 0; i < paddedLength;) {
  12273. for (j = 0; j < 16; ++j) {
  12274. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  12275. (padded[i + 2] << 8) | (padded[i + 3]);
  12276. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  12277. (padded[i + 6]) << 8 | (padded[i + 7]);
  12278. i += 8;
  12279. }
  12280. for (j = 16; j < 80; ++j) {
  12281. tmp3 = w[j];
  12282. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  12283. tmp3.add(w[j - 7]);
  12284. littleSigma(tmp1, w[j - 15], tmp2);
  12285. tmp3.add(tmp1);
  12286. tmp3.add(w[j - 16]);
  12287. }
  12288. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  12289. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  12290. for (j = 0; j < 80; ++j) {
  12291. t1.assign(h);
  12292. sigmaPrime(tmp1, e, tmp2);
  12293. t1.add(tmp1);
  12294. ch(tmp1, e, f, g, tmp2);
  12295. t1.add(tmp1);
  12296. t1.add(k[j]);
  12297. t1.add(w[j]);
  12298. sigma(t2, a, tmp2);
  12299. maj(tmp1, a, b, c, tmp2);
  12300. t2.add(tmp1);
  12301. tmp3 = h;
  12302. h = g;
  12303. g = f;
  12304. f = e;
  12305. d.add(t1);
  12306. e = d;
  12307. d = c;
  12308. c = b;
  12309. b = a;
  12310. tmp3.assign(t1);
  12311. tmp3.add(t2);
  12312. a = tmp3;
  12313. }
  12314. h0.add(a);
  12315. h1.add(b);
  12316. h2.add(c);
  12317. h3.add(d);
  12318. h4.add(e);
  12319. h5.add(f);
  12320. h6.add(g);
  12321. h7.add(h);
  12322. }
  12323. var result;
  12324. if (!mode384) {
  12325. result = new Uint8Array(64);
  12326. h0.copyTo(result,0);
  12327. h1.copyTo(result,8);
  12328. h2.copyTo(result,16);
  12329. h3.copyTo(result,24);
  12330. h4.copyTo(result,32);
  12331. h5.copyTo(result,40);
  12332. h6.copyTo(result,48);
  12333. h7.copyTo(result,56);
  12334. }
  12335. else {
  12336. result = new Uint8Array(48);
  12337. h0.copyTo(result,0);
  12338. h1.copyTo(result,8);
  12339. h2.copyTo(result,16);
  12340. h3.copyTo(result,24);
  12341. h4.copyTo(result,32);
  12342. h5.copyTo(result,40);
  12343. }
  12344. return result;
  12345. }
  12346. return hash;
  12347. })();
  12348. var calculateSHA384 = (function calculateSHA384Closure() {
  12349. function hash(data, offset, length) {
  12350. return calculateSHA512(data, offset, length, true);
  12351. }
  12352. return hash;
  12353. })();
  12354. var NullCipher = (function NullCipherClosure() {
  12355. function NullCipher() {
  12356. }
  12357. NullCipher.prototype = {
  12358. decryptBlock: function NullCipher_decryptBlock(data) {
  12359. return data;
  12360. }
  12361. };
  12362. return NullCipher;
  12363. })();
  12364. var AES128Cipher = (function AES128CipherClosure() {
  12365. var rcon = new Uint8Array([
  12366. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12367. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12368. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12369. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12370. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  12371. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  12372. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  12373. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  12374. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  12375. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  12376. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  12377. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  12378. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  12379. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  12380. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  12381. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  12382. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  12383. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12384. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12385. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12386. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12387. 0x74, 0xe8, 0xcb, 0x8d]);
  12388. var s = new Uint8Array([
  12389. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  12390. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  12391. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  12392. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  12393. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  12394. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  12395. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  12396. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  12397. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  12398. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  12399. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  12400. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  12401. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  12402. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  12403. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  12404. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  12405. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  12406. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  12407. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  12408. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  12409. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  12410. 0xb0, 0x54, 0xbb, 0x16]);
  12411. var inv_s = new Uint8Array([
  12412. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  12413. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  12414. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  12415. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  12416. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  12417. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  12418. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  12419. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  12420. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  12421. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  12422. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  12423. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  12424. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  12425. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  12426. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  12427. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  12428. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  12429. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  12430. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  12431. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  12432. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  12433. 0x55, 0x21, 0x0c, 0x7d]);
  12434. var mixCol = new Uint8Array(256);
  12435. for (var i = 0; i < 256; i++) {
  12436. if (i < 128) {
  12437. mixCol[i] = i << 1;
  12438. } else {
  12439. mixCol[i] = (i << 1) ^ 0x1b;
  12440. }
  12441. }
  12442. var mix = new Uint32Array([
  12443. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  12444. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  12445. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  12446. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  12447. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  12448. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  12449. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  12450. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  12451. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  12452. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  12453. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  12454. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  12455. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  12456. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  12457. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  12458. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  12459. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  12460. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  12461. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  12462. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  12463. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  12464. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  12465. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  12466. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  12467. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  12468. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  12469. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  12470. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  12471. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  12472. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  12473. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  12474. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  12475. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  12476. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  12477. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  12478. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  12479. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  12480. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  12481. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  12482. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  12483. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  12484. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  12485. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  12486. function expandKey128(cipherKey) {
  12487. var b = 176, result = new Uint8Array(b);
  12488. result.set(cipherKey);
  12489. for (var j = 16, i = 1; j < b; ++i) {
  12490. // RotWord
  12491. var t1 = result[j - 3], t2 = result[j - 2],
  12492. t3 = result[j - 1], t4 = result[j - 4];
  12493. // SubWord
  12494. t1 = s[t1];
  12495. t2 = s[t2];
  12496. t3 = s[t3];
  12497. t4 = s[t4];
  12498. // Rcon
  12499. t1 = t1 ^ rcon[i];
  12500. for (var n = 0; n < 4; ++n) {
  12501. result[j] = (t1 ^= result[j - 16]);
  12502. j++;
  12503. result[j] = (t2 ^= result[j - 16]);
  12504. j++;
  12505. result[j] = (t3 ^= result[j - 16]);
  12506. j++;
  12507. result[j] = (t4 ^= result[j - 16]);
  12508. j++;
  12509. }
  12510. }
  12511. return result;
  12512. }
  12513. function decrypt128(input, key) {
  12514. var state = new Uint8Array(16);
  12515. state.set(input);
  12516. var i, j, k;
  12517. var t, u, v;
  12518. // AddRoundKey
  12519. for (j = 0, k = 160; j < 16; ++j, ++k) {
  12520. state[j] ^= key[k];
  12521. }
  12522. for (i = 9; i >= 1; --i) {
  12523. // InvShiftRows
  12524. t = state[13];
  12525. state[13] = state[9];
  12526. state[9] = state[5];
  12527. state[5] = state[1];
  12528. state[1] = t;
  12529. t = state[14];
  12530. u = state[10];
  12531. state[14] = state[6];
  12532. state[10] = state[2];
  12533. state[6] = t;
  12534. state[2] = u;
  12535. t = state[15];
  12536. u = state[11];
  12537. v = state[7];
  12538. state[15] = state[3];
  12539. state[11] = t;
  12540. state[7] = u;
  12541. state[3] = v;
  12542. // InvSubBytes
  12543. for (j = 0; j < 16; ++j) {
  12544. state[j] = inv_s[state[j]];
  12545. }
  12546. // AddRoundKey
  12547. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  12548. state[j] ^= key[k];
  12549. }
  12550. // InvMixColumns
  12551. for (j = 0; j < 16; j += 4) {
  12552. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  12553. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  12554. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  12555. (s3 >>> 24) ^ (s3 << 8));
  12556. state[j] = (t >>> 24) & 0xFF;
  12557. state[j + 1] = (t >> 16) & 0xFF;
  12558. state[j + 2] = (t >> 8) & 0xFF;
  12559. state[j + 3] = t & 0xFF;
  12560. }
  12561. }
  12562. // InvShiftRows
  12563. t = state[13];
  12564. state[13] = state[9];
  12565. state[9] = state[5];
  12566. state[5] = state[1];
  12567. state[1] = t;
  12568. t = state[14];
  12569. u = state[10];
  12570. state[14] = state[6];
  12571. state[10] = state[2];
  12572. state[6] = t;
  12573. state[2] = u;
  12574. t = state[15];
  12575. u = state[11];
  12576. v = state[7];
  12577. state[15] = state[3];
  12578. state[11] = t;
  12579. state[7] = u;
  12580. state[3] = v;
  12581. for (j = 0; j < 16; ++j) {
  12582. // InvSubBytes
  12583. state[j] = inv_s[state[j]];
  12584. // AddRoundKey
  12585. state[j] ^= key[j];
  12586. }
  12587. return state;
  12588. }
  12589. function encrypt128(input, key) {
  12590. var t, u, v, k;
  12591. var state = new Uint8Array(16);
  12592. state.set(input);
  12593. for (j = 0; j < 16; ++j) {
  12594. // AddRoundKey
  12595. state[j] ^= key[j];
  12596. }
  12597. for (i = 1; i < 10; i++) {
  12598. //SubBytes
  12599. for (j = 0; j < 16; ++j) {
  12600. state[j] = s[state[j]];
  12601. }
  12602. //ShiftRows
  12603. v = state[1];
  12604. state[1] = state[5];
  12605. state[5] = state[9];
  12606. state[9] = state[13];
  12607. state[13] = v;
  12608. v = state[2];
  12609. u = state[6];
  12610. state[2] = state[10];
  12611. state[6] = state[14];
  12612. state[10] = v;
  12613. state[14] = u;
  12614. v = state[3];
  12615. u = state[7];
  12616. t = state[11];
  12617. state[3] = state[15];
  12618. state[7] = v;
  12619. state[11] = u;
  12620. state[15] = t;
  12621. //MixColumns
  12622. for (var j = 0; j < 16; j += 4) {
  12623. var s0 = state[j + 0], s1 = state[j + 1];
  12624. var s2 = state[j + 2], s3 = state[j + 3];
  12625. t = s0 ^ s1 ^ s2 ^ s3;
  12626. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  12627. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  12628. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  12629. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  12630. }
  12631. //AddRoundKey
  12632. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  12633. state[j] ^= key[k];
  12634. }
  12635. }
  12636. //SubBytes
  12637. for (j = 0; j < 16; ++j) {
  12638. state[j] = s[state[j]];
  12639. }
  12640. //ShiftRows
  12641. v = state[1];
  12642. state[1] = state[5];
  12643. state[5] = state[9];
  12644. state[9] = state[13];
  12645. state[13] = v;
  12646. v = state[2];
  12647. u = state[6];
  12648. state[2] = state[10];
  12649. state[6] = state[14];
  12650. state[10] = v;
  12651. state[14] = u;
  12652. v = state[3];
  12653. u = state[7];
  12654. t = state[11];
  12655. state[3] = state[15];
  12656. state[7] = v;
  12657. state[11] = u;
  12658. state[15] = t;
  12659. //AddRoundKey
  12660. for (j = 0, k = 160; j < 16; ++j, ++k) {
  12661. state[j] ^= key[k];
  12662. }
  12663. return state;
  12664. }
  12665. function AES128Cipher(key) {
  12666. this.key = expandKey128(key);
  12667. this.buffer = new Uint8Array(16);
  12668. this.bufferPosition = 0;
  12669. }
  12670. function decryptBlock2(data, finalize) {
  12671. var i, j, ii, sourceLength = data.length,
  12672. buffer = this.buffer, bufferLength = this.bufferPosition,
  12673. result = [], iv = this.iv;
  12674. for (i = 0; i < sourceLength; ++i) {
  12675. buffer[bufferLength] = data[i];
  12676. ++bufferLength;
  12677. if (bufferLength < 16) {
  12678. continue;
  12679. }
  12680. // buffer is full, decrypting
  12681. var plain = decrypt128(buffer, this.key);
  12682. // xor-ing the IV vector to get plain text
  12683. for (j = 0; j < 16; ++j) {
  12684. plain[j] ^= iv[j];
  12685. }
  12686. iv = buffer;
  12687. result.push(plain);
  12688. buffer = new Uint8Array(16);
  12689. bufferLength = 0;
  12690. }
  12691. // saving incomplete buffer
  12692. this.buffer = buffer;
  12693. this.bufferLength = bufferLength;
  12694. this.iv = iv;
  12695. if (result.length === 0) {
  12696. return new Uint8Array([]);
  12697. }
  12698. // combining plain text blocks into one
  12699. var outputLength = 16 * result.length;
  12700. if (finalize) {
  12701. // undo a padding that is described in RFC 2898
  12702. var lastBlock = result[result.length - 1];
  12703. var psLen = lastBlock[15];
  12704. if (psLen <= 16) {
  12705. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  12706. if (lastBlock[i] !== psLen) {
  12707. // Invalid padding, assume that the block has no padding.
  12708. psLen = 0;
  12709. break;
  12710. }
  12711. }
  12712. outputLength -= psLen;
  12713. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  12714. }
  12715. }
  12716. var output = new Uint8Array(outputLength);
  12717. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12718. output.set(result[i], j);
  12719. }
  12720. return output;
  12721. }
  12722. AES128Cipher.prototype = {
  12723. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  12724. var i, sourceLength = data.length;
  12725. var buffer = this.buffer, bufferLength = this.bufferPosition;
  12726. // waiting for IV values -- they are at the start of the stream
  12727. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  12728. buffer[bufferLength] = data[i];
  12729. }
  12730. if (bufferLength < 16) {
  12731. // need more data
  12732. this.bufferLength = bufferLength;
  12733. return new Uint8Array([]);
  12734. }
  12735. this.iv = buffer;
  12736. this.buffer = new Uint8Array(16);
  12737. this.bufferLength = 0;
  12738. // starting decryption
  12739. this.decryptBlock = decryptBlock2;
  12740. return this.decryptBlock(data.subarray(16), finalize);
  12741. },
  12742. encrypt: function AES128Cipher_encrypt(data, iv) {
  12743. var i, j, ii, sourceLength = data.length,
  12744. buffer = this.buffer, bufferLength = this.bufferPosition,
  12745. result = [];
  12746. if (!iv) {
  12747. iv = new Uint8Array(16);
  12748. }
  12749. for (i = 0; i < sourceLength; ++i) {
  12750. buffer[bufferLength] = data[i];
  12751. ++bufferLength;
  12752. if (bufferLength < 16) {
  12753. continue;
  12754. }
  12755. for (j = 0; j < 16; ++j) {
  12756. buffer[j] ^= iv[j];
  12757. }
  12758. // buffer is full, encrypting
  12759. var cipher = encrypt128(buffer, this.key);
  12760. iv = cipher;
  12761. result.push(cipher);
  12762. buffer = new Uint8Array(16);
  12763. bufferLength = 0;
  12764. }
  12765. // saving incomplete buffer
  12766. this.buffer = buffer;
  12767. this.bufferLength = bufferLength;
  12768. this.iv = iv;
  12769. if (result.length === 0) {
  12770. return new Uint8Array([]);
  12771. }
  12772. // combining plain text blocks into one
  12773. var outputLength = 16 * result.length;
  12774. var output = new Uint8Array(outputLength);
  12775. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12776. output.set(result[i], j);
  12777. }
  12778. return output;
  12779. }
  12780. };
  12781. return AES128Cipher;
  12782. })();
  12783. var AES256Cipher = (function AES256CipherClosure() {
  12784. var rcon = new Uint8Array([
  12785. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12786. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12787. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12788. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12789. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  12790. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  12791. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  12792. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  12793. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  12794. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  12795. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  12796. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  12797. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  12798. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  12799. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  12800. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  12801. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  12802. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  12803. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  12804. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  12805. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  12806. 0x74, 0xe8, 0xcb, 0x8d]);
  12807. var s = new Uint8Array([
  12808. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  12809. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  12810. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  12811. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  12812. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  12813. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  12814. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  12815. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  12816. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  12817. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  12818. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  12819. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  12820. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  12821. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  12822. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  12823. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  12824. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  12825. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  12826. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  12827. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  12828. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  12829. 0xb0, 0x54, 0xbb, 0x16]);
  12830. var inv_s = new Uint8Array([
  12831. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  12832. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  12833. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  12834. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  12835. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  12836. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  12837. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  12838. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  12839. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  12840. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  12841. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  12842. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  12843. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  12844. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  12845. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  12846. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  12847. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  12848. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  12849. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  12850. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  12851. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  12852. 0x55, 0x21, 0x0c, 0x7d]);
  12853. var mixCol = new Uint8Array(256);
  12854. for (var i = 0; i < 256; i++) {
  12855. if (i < 128) {
  12856. mixCol[i] = i << 1;
  12857. } else {
  12858. mixCol[i] = (i << 1) ^ 0x1b;
  12859. }
  12860. }
  12861. var mix = new Uint32Array([
  12862. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  12863. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  12864. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  12865. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  12866. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  12867. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  12868. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  12869. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  12870. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  12871. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  12872. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  12873. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  12874. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  12875. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  12876. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  12877. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  12878. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  12879. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  12880. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  12881. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  12882. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  12883. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  12884. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  12885. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  12886. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  12887. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  12888. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  12889. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  12890. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  12891. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  12892. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  12893. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  12894. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  12895. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  12896. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  12897. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  12898. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  12899. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  12900. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  12901. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  12902. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  12903. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  12904. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  12905. function expandKey256(cipherKey) {
  12906. var b = 240, result = new Uint8Array(b);
  12907. var r = 1;
  12908. result.set(cipherKey);
  12909. for (var j = 32, i = 1; j < b; ++i) {
  12910. if (j % 32 === 16) {
  12911. t1 = s[t1];
  12912. t2 = s[t2];
  12913. t3 = s[t3];
  12914. t4 = s[t4];
  12915. } else if (j % 32 === 0) {
  12916. // RotWord
  12917. var t1 = result[j - 3], t2 = result[j - 2],
  12918. t3 = result[j - 1], t4 = result[j - 4];
  12919. // SubWord
  12920. t1 = s[t1];
  12921. t2 = s[t2];
  12922. t3 = s[t3];
  12923. t4 = s[t4];
  12924. // Rcon
  12925. t1 = t1 ^ r;
  12926. if ((r <<= 1) >= 256) {
  12927. r = (r ^ 0x1b) & 0xFF;
  12928. }
  12929. }
  12930. for (var n = 0; n < 4; ++n) {
  12931. result[j] = (t1 ^= result[j - 32]);
  12932. j++;
  12933. result[j] = (t2 ^= result[j - 32]);
  12934. j++;
  12935. result[j] = (t3 ^= result[j - 32]);
  12936. j++;
  12937. result[j] = (t4 ^= result[j - 32]);
  12938. j++;
  12939. }
  12940. }
  12941. return result;
  12942. }
  12943. function decrypt256(input, key) {
  12944. var state = new Uint8Array(16);
  12945. state.set(input);
  12946. var i, j, k;
  12947. var t, u, v;
  12948. // AddRoundKey
  12949. for (j = 0, k = 224; j < 16; ++j, ++k) {
  12950. state[j] ^= key[k];
  12951. }
  12952. for (i = 13; i >= 1; --i) {
  12953. // InvShiftRows
  12954. t = state[13];
  12955. state[13] = state[9];
  12956. state[9] = state[5];
  12957. state[5] = state[1];
  12958. state[1] = t;
  12959. t = state[14];
  12960. u = state[10];
  12961. state[14] = state[6];
  12962. state[10] = state[2];
  12963. state[6] = t;
  12964. state[2] = u;
  12965. t = state[15];
  12966. u = state[11];
  12967. v = state[7];
  12968. state[15] = state[3];
  12969. state[11] = t;
  12970. state[7] = u;
  12971. state[3] = v;
  12972. // InvSubBytes
  12973. for (j = 0; j < 16; ++j) {
  12974. state[j] = inv_s[state[j]];
  12975. }
  12976. // AddRoundKey
  12977. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  12978. state[j] ^= key[k];
  12979. }
  12980. // InvMixColumns
  12981. for (j = 0; j < 16; j += 4) {
  12982. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  12983. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  12984. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  12985. (s3 >>> 24) ^ (s3 << 8));
  12986. state[j] = (t >>> 24) & 0xFF;
  12987. state[j + 1] = (t >> 16) & 0xFF;
  12988. state[j + 2] = (t >> 8) & 0xFF;
  12989. state[j + 3] = t & 0xFF;
  12990. }
  12991. }
  12992. // InvShiftRows
  12993. t = state[13];
  12994. state[13] = state[9];
  12995. state[9] = state[5];
  12996. state[5] = state[1];
  12997. state[1] = t;
  12998. t = state[14];
  12999. u = state[10];
  13000. state[14] = state[6];
  13001. state[10] = state[2];
  13002. state[6] = t;
  13003. state[2] = u;
  13004. t = state[15];
  13005. u = state[11];
  13006. v = state[7];
  13007. state[15] = state[3];
  13008. state[11] = t;
  13009. state[7] = u;
  13010. state[3] = v;
  13011. for (j = 0; j < 16; ++j) {
  13012. // InvSubBytes
  13013. state[j] = inv_s[state[j]];
  13014. // AddRoundKey
  13015. state[j] ^= key[j];
  13016. }
  13017. return state;
  13018. }
  13019. function encrypt256(input, key) {
  13020. var t, u, v, k;
  13021. var state = new Uint8Array(16);
  13022. state.set(input);
  13023. for (j = 0; j < 16; ++j) {
  13024. // AddRoundKey
  13025. state[j] ^= key[j];
  13026. }
  13027. for (i = 1; i < 14; i++) {
  13028. //SubBytes
  13029. for (j = 0; j < 16; ++j) {
  13030. state[j] = s[state[j]];
  13031. }
  13032. //ShiftRows
  13033. v = state[1];
  13034. state[1] = state[5];
  13035. state[5] = state[9];
  13036. state[9] = state[13];
  13037. state[13] = v;
  13038. v = state[2];
  13039. u = state[6];
  13040. state[2] = state[10];
  13041. state[6] = state[14];
  13042. state[10] = v;
  13043. state[14] = u;
  13044. v = state[3];
  13045. u = state[7];
  13046. t = state[11];
  13047. state[3] = state[15];
  13048. state[7] = v;
  13049. state[11] = u;
  13050. state[15] = t;
  13051. //MixColumns
  13052. for (var j = 0; j < 16; j += 4) {
  13053. var s0 = state[j + 0], s1 = state[j + 1];
  13054. var s2 = state[j + 2], s3 = state[j + 3];
  13055. t = s0 ^ s1 ^ s2 ^ s3;
  13056. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13057. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13058. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13059. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13060. }
  13061. //AddRoundKey
  13062. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13063. state[j] ^= key[k];
  13064. }
  13065. }
  13066. //SubBytes
  13067. for (j = 0; j < 16; ++j) {
  13068. state[j] = s[state[j]];
  13069. }
  13070. //ShiftRows
  13071. v = state[1];
  13072. state[1] = state[5];
  13073. state[5] = state[9];
  13074. state[9] = state[13];
  13075. state[13] = v;
  13076. v = state[2];
  13077. u = state[6];
  13078. state[2] = state[10];
  13079. state[6] = state[14];
  13080. state[10] = v;
  13081. state[14] = u;
  13082. v = state[3];
  13083. u = state[7];
  13084. t = state[11];
  13085. state[3] = state[15];
  13086. state[7] = v;
  13087. state[11] = u;
  13088. state[15] = t;
  13089. //AddRoundKey
  13090. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13091. state[j] ^= key[k];
  13092. }
  13093. return state;
  13094. }
  13095. function AES256Cipher(key) {
  13096. this.key = expandKey256(key);
  13097. this.buffer = new Uint8Array(16);
  13098. this.bufferPosition = 0;
  13099. }
  13100. function decryptBlock2(data, finalize) {
  13101. var i, j, ii, sourceLength = data.length,
  13102. buffer = this.buffer, bufferLength = this.bufferPosition,
  13103. result = [], iv = this.iv;
  13104. for (i = 0; i < sourceLength; ++i) {
  13105. buffer[bufferLength] = data[i];
  13106. ++bufferLength;
  13107. if (bufferLength < 16) {
  13108. continue;
  13109. }
  13110. // buffer is full, decrypting
  13111. var plain = decrypt256(buffer, this.key);
  13112. // xor-ing the IV vector to get plain text
  13113. for (j = 0; j < 16; ++j) {
  13114. plain[j] ^= iv[j];
  13115. }
  13116. iv = buffer;
  13117. result.push(plain);
  13118. buffer = new Uint8Array(16);
  13119. bufferLength = 0;
  13120. }
  13121. // saving incomplete buffer
  13122. this.buffer = buffer;
  13123. this.bufferLength = bufferLength;
  13124. this.iv = iv;
  13125. if (result.length === 0) {
  13126. return new Uint8Array([]);
  13127. }
  13128. // combining plain text blocks into one
  13129. var outputLength = 16 * result.length;
  13130. if (finalize) {
  13131. // undo a padding that is described in RFC 2898
  13132. var lastBlock = result[result.length - 1];
  13133. var psLen = lastBlock[15];
  13134. if (psLen <= 16) {
  13135. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13136. if (lastBlock[i] !== psLen) {
  13137. // Invalid padding, assume that the block has no padding.
  13138. psLen = 0;
  13139. break;
  13140. }
  13141. }
  13142. outputLength -= psLen;
  13143. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13144. }
  13145. }
  13146. var output = new Uint8Array(outputLength);
  13147. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13148. output.set(result[i], j);
  13149. }
  13150. return output;
  13151. }
  13152. AES256Cipher.prototype = {
  13153. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13154. var i, sourceLength = data.length;
  13155. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13156. // if not supplied an IV wait for IV values
  13157. // they are at the start of the stream
  13158. if (iv) {
  13159. this.iv = iv;
  13160. } else {
  13161. for (i = 0; bufferLength < 16 &&
  13162. i < sourceLength; ++i, ++bufferLength) {
  13163. buffer[bufferLength] = data[i];
  13164. }
  13165. if (bufferLength < 16) {
  13166. //need more data
  13167. this.bufferLength = bufferLength;
  13168. return new Uint8Array([]);
  13169. }
  13170. this.iv = buffer;
  13171. data = data.subarray(16);
  13172. }
  13173. this.buffer = new Uint8Array(16);
  13174. this.bufferLength = 0;
  13175. // starting decryption
  13176. this.decryptBlock = decryptBlock2;
  13177. return this.decryptBlock(data, finalize);
  13178. },
  13179. encrypt: function AES256Cipher_encrypt(data, iv) {
  13180. var i, j, ii, sourceLength = data.length,
  13181. buffer = this.buffer, bufferLength = this.bufferPosition,
  13182. result = [];
  13183. if (!iv) {
  13184. iv = new Uint8Array(16);
  13185. }
  13186. for (i = 0; i < sourceLength; ++i) {
  13187. buffer[bufferLength] = data[i];
  13188. ++bufferLength;
  13189. if (bufferLength < 16) {
  13190. continue;
  13191. }
  13192. for (j = 0; j < 16; ++j) {
  13193. buffer[j] ^= iv[j];
  13194. }
  13195. // buffer is full, encrypting
  13196. var cipher = encrypt256(buffer, this.key);
  13197. this.iv = cipher;
  13198. result.push(cipher);
  13199. buffer = new Uint8Array(16);
  13200. bufferLength = 0;
  13201. }
  13202. // saving incomplete buffer
  13203. this.buffer = buffer;
  13204. this.bufferLength = bufferLength;
  13205. this.iv = iv;
  13206. if (result.length === 0) {
  13207. return new Uint8Array([]);
  13208. }
  13209. // combining plain text blocks into one
  13210. var outputLength = 16 * result.length;
  13211. var output = new Uint8Array(outputLength);
  13212. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13213. output.set(result[i], j);
  13214. }
  13215. return output;
  13216. }
  13217. };
  13218. return AES256Cipher;
  13219. })();
  13220. var PDF17 = (function PDF17Closure() {
  13221. function compareByteArrays(array1, array2) {
  13222. if (array1.length !== array2.length) {
  13223. return false;
  13224. }
  13225. for (var i = 0; i < array1.length; i++) {
  13226. if (array1[i] !== array2[i]) {
  13227. return false;
  13228. }
  13229. }
  13230. return true;
  13231. }
  13232. function PDF17() {
  13233. }
  13234. PDF17.prototype = {
  13235. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13236. ownerValidationSalt,
  13237. userBytes,
  13238. ownerPassword) {
  13239. var hashData = new Uint8Array(password.length + 56);
  13240. hashData.set(password, 0);
  13241. hashData.set(ownerValidationSalt, password.length);
  13242. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13243. var result = calculateSHA256(hashData, 0, hashData.length);
  13244. return compareByteArrays(result, ownerPassword);
  13245. },
  13246. checkUserPassword: function PDF17_checkUserPassword(password,
  13247. userValidationSalt,
  13248. userPassword) {
  13249. var hashData = new Uint8Array(password.length + 8);
  13250. hashData.set(password, 0);
  13251. hashData.set(userValidationSalt, password.length);
  13252. var result = calculateSHA256(hashData, 0, hashData.length);
  13253. return compareByteArrays(result, userPassword);
  13254. },
  13255. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  13256. ownerEncryption) {
  13257. var hashData = new Uint8Array(password.length + 56);
  13258. hashData.set(password, 0);
  13259. hashData.set(ownerKeySalt, password.length);
  13260. hashData.set(userBytes, password.length + ownerKeySalt.length);
  13261. var key = calculateSHA256(hashData, 0, hashData.length);
  13262. var cipher = new AES256Cipher(key);
  13263. return cipher.decryptBlock(ownerEncryption,
  13264. false,
  13265. new Uint8Array(16));
  13266. },
  13267. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  13268. userEncryption) {
  13269. var hashData = new Uint8Array(password.length + 8);
  13270. hashData.set(password, 0);
  13271. hashData.set(userKeySalt, password.length);
  13272. //key is the decryption key for the UE string
  13273. var key = calculateSHA256(hashData, 0, hashData.length);
  13274. var cipher = new AES256Cipher(key);
  13275. return cipher.decryptBlock(userEncryption,
  13276. false,
  13277. new Uint8Array(16));
  13278. }
  13279. };
  13280. return PDF17;
  13281. })();
  13282. var PDF20 = (function PDF20Closure() {
  13283. function concatArrays(array1, array2) {
  13284. var t = new Uint8Array(array1.length + array2.length);
  13285. t.set(array1, 0);
  13286. t.set(array2, array1.length);
  13287. return t;
  13288. }
  13289. function calculatePDF20Hash(password, input, userBytes) {
  13290. //This refers to Algorithm 2.B as defined in ISO 32000-2
  13291. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  13292. var e = [0];
  13293. var i = 0;
  13294. while (i < 64 || e[e.length - 1] > i - 32) {
  13295. var arrayLength = password.length + k.length + userBytes.length;
  13296. var k1 = new Uint8Array(arrayLength * 64);
  13297. var array = concatArrays(password, k);
  13298. array = concatArrays(array, userBytes);
  13299. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  13300. k1.set(array, pos);
  13301. }
  13302. //AES128 CBC NO PADDING with
  13303. //first 16 bytes of k as the key and the second 16 as the iv.
  13304. var cipher = new AES128Cipher(k.subarray(0, 16));
  13305. e = cipher.encrypt(k1, k.subarray(16, 32));
  13306. //Now we have to take the first 16 bytes of an unsigned
  13307. //big endian integer... and compute the remainder
  13308. //modulo 3.... That is a fairly large number and
  13309. //JavaScript isn't going to handle that well...
  13310. //So we're using a trick that allows us to perform
  13311. //modulo math byte by byte
  13312. var remainder = 0;
  13313. for (var z = 0; z < 16; z++) {
  13314. remainder *= (256 % 3);
  13315. remainder %= 3;
  13316. remainder += ((e[z] >>> 0) % 3);
  13317. remainder %= 3;
  13318. }
  13319. if (remainder === 0) {
  13320. k = calculateSHA256(e, 0, e.length);
  13321. }
  13322. else if (remainder === 1) {
  13323. k = calculateSHA384(e, 0, e.length);
  13324. }
  13325. else if (remainder === 2) {
  13326. k = calculateSHA512(e, 0, e.length);
  13327. }
  13328. i++;
  13329. }
  13330. return k.subarray(0, 32);
  13331. }
  13332. function PDF20() {
  13333. }
  13334. function compareByteArrays(array1, array2) {
  13335. if (array1.length !== array2.length) {
  13336. return false;
  13337. }
  13338. for (var i = 0; i < array1.length; i++) {
  13339. if (array1[i] !== array2[i]) {
  13340. return false;
  13341. }
  13342. }
  13343. return true;
  13344. }
  13345. PDF20.prototype = {
  13346. hash: function PDF20_hash(password, concatBytes, userBytes) {
  13347. return calculatePDF20Hash(password, concatBytes, userBytes);
  13348. },
  13349. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  13350. ownerValidationSalt,
  13351. userBytes,
  13352. ownerPassword) {
  13353. var hashData = new Uint8Array(password.length + 56);
  13354. hashData.set(password, 0);
  13355. hashData.set(ownerValidationSalt, password.length);
  13356. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13357. var result = calculatePDF20Hash(password, hashData, userBytes);
  13358. return compareByteArrays(result, ownerPassword);
  13359. },
  13360. checkUserPassword: function PDF20_checkUserPassword(password,
  13361. userValidationSalt,
  13362. userPassword) {
  13363. var hashData = new Uint8Array(password.length + 8);
  13364. hashData.set(password, 0);
  13365. hashData.set(userValidationSalt, password.length);
  13366. var result = calculatePDF20Hash(password, hashData, []);
  13367. return compareByteArrays(result, userPassword);
  13368. },
  13369. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  13370. ownerEncryption) {
  13371. var hashData = new Uint8Array(password.length + 56);
  13372. hashData.set(password, 0);
  13373. hashData.set(ownerKeySalt, password.length);
  13374. hashData.set(userBytes, password.length + ownerKeySalt.length);
  13375. var key = calculatePDF20Hash(password, hashData, userBytes);
  13376. var cipher = new AES256Cipher(key);
  13377. return cipher.decryptBlock(ownerEncryption,
  13378. false,
  13379. new Uint8Array(16));
  13380. },
  13381. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  13382. userEncryption) {
  13383. var hashData = new Uint8Array(password.length + 8);
  13384. hashData.set(password, 0);
  13385. hashData.set(userKeySalt, password.length);
  13386. //key is the decryption key for the UE string
  13387. var key = calculatePDF20Hash(password, hashData, []);
  13388. var cipher = new AES256Cipher(key);
  13389. return cipher.decryptBlock(userEncryption,
  13390. false,
  13391. new Uint8Array(16));
  13392. }
  13393. };
  13394. return PDF20;
  13395. })();
  13396. var CipherTransform = (function CipherTransformClosure() {
  13397. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  13398. this.stringCipherConstructor = stringCipherConstructor;
  13399. this.streamCipherConstructor = streamCipherConstructor;
  13400. }
  13401. CipherTransform.prototype = {
  13402. createStream: function CipherTransform_createStream(stream, length) {
  13403. var cipher = new this.streamCipherConstructor();
  13404. return new DecryptStream(stream, length,
  13405. function cipherTransformDecryptStream(data, finalize) {
  13406. return cipher.decryptBlock(data, finalize);
  13407. }
  13408. );
  13409. },
  13410. decryptString: function CipherTransform_decryptString(s) {
  13411. var cipher = new this.stringCipherConstructor();
  13412. var data = stringToBytes(s);
  13413. data = cipher.decryptBlock(data, true);
  13414. return bytesToString(data);
  13415. }
  13416. };
  13417. return CipherTransform;
  13418. })();
  13419. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  13420. var defaultPasswordBytes = new Uint8Array([
  13421. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  13422. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  13423. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  13424. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  13425. function createEncryptionKey20(revision, password, ownerPassword,
  13426. ownerValidationSalt, ownerKeySalt, uBytes,
  13427. userPassword, userValidationSalt, userKeySalt,
  13428. ownerEncryption, userEncryption, perms) {
  13429. if (password) {
  13430. var passwordLength = Math.min(127, password.length);
  13431. password = password.subarray(0, passwordLength);
  13432. } else {
  13433. password = [];
  13434. }
  13435. var pdfAlgorithm;
  13436. if (revision === 6) {
  13437. pdfAlgorithm = new PDF20();
  13438. } else {
  13439. pdfAlgorithm = new PDF17();
  13440. }
  13441. if (pdfAlgorithm) {
  13442. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  13443. userPassword)) {
  13444. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  13445. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  13446. uBytes,
  13447. ownerPassword)) {
  13448. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  13449. ownerEncryption);
  13450. }
  13451. }
  13452. return null;
  13453. }
  13454. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  13455. flags, revision, keyLength, encryptMetadata) {
  13456. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  13457. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  13458. if (password) {
  13459. n = Math.min(32, password.length);
  13460. for (; i < n; ++i) {
  13461. hashData[i] = password[i];
  13462. }
  13463. }
  13464. j = 0;
  13465. while (i < 32) {
  13466. hashData[i++] = defaultPasswordBytes[j++];
  13467. }
  13468. // as now the padded password in the hashData[0..i]
  13469. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  13470. hashData[i++] = ownerPassword[j];
  13471. }
  13472. hashData[i++] = flags & 0xFF;
  13473. hashData[i++] = (flags >> 8) & 0xFF;
  13474. hashData[i++] = (flags >> 16) & 0xFF;
  13475. hashData[i++] = (flags >>> 24) & 0xFF;
  13476. for (j = 0, n = fileId.length; j < n; ++j) {
  13477. hashData[i++] = fileId[j];
  13478. }
  13479. if (revision >= 4 && !encryptMetadata) {
  13480. hashData[i++] = 0xFF;
  13481. hashData[i++] = 0xFF;
  13482. hashData[i++] = 0xFF;
  13483. hashData[i++] = 0xFF;
  13484. }
  13485. var hash = calculateMD5(hashData, 0, i);
  13486. var keyLengthInBytes = keyLength >> 3;
  13487. if (revision >= 3) {
  13488. for (j = 0; j < 50; ++j) {
  13489. hash = calculateMD5(hash, 0, keyLengthInBytes);
  13490. }
  13491. }
  13492. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  13493. var cipher, checkData;
  13494. if (revision >= 3) {
  13495. for (i = 0; i < 32; ++i) {
  13496. hashData[i] = defaultPasswordBytes[i];
  13497. }
  13498. for (j = 0, n = fileId.length; j < n; ++j) {
  13499. hashData[i++] = fileId[j];
  13500. }
  13501. cipher = new ARCFourCipher(encryptionKey);
  13502. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  13503. n = encryptionKey.length;
  13504. var derivedKey = new Uint8Array(n), k;
  13505. for (j = 1; j <= 19; ++j) {
  13506. for (k = 0; k < n; ++k) {
  13507. derivedKey[k] = encryptionKey[k] ^ j;
  13508. }
  13509. cipher = new ARCFourCipher(derivedKey);
  13510. checkData = cipher.encryptBlock(checkData);
  13511. }
  13512. for (j = 0, n = checkData.length; j < n; ++j) {
  13513. if (userPassword[j] !== checkData[j]) {
  13514. return null;
  13515. }
  13516. }
  13517. } else {
  13518. cipher = new ARCFourCipher(encryptionKey);
  13519. checkData = cipher.encryptBlock(defaultPasswordBytes);
  13520. for (j = 0, n = checkData.length; j < n; ++j) {
  13521. if (userPassword[j] !== checkData[j]) {
  13522. return null;
  13523. }
  13524. }
  13525. }
  13526. return encryptionKey;
  13527. }
  13528. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  13529. var hashData = new Uint8Array(32), i = 0, j, n;
  13530. n = Math.min(32, password.length);
  13531. for (; i < n; ++i) {
  13532. hashData[i] = password[i];
  13533. }
  13534. j = 0;
  13535. while (i < 32) {
  13536. hashData[i++] = defaultPasswordBytes[j++];
  13537. }
  13538. var hash = calculateMD5(hashData, 0, i);
  13539. var keyLengthInBytes = keyLength >> 3;
  13540. if (revision >= 3) {
  13541. for (j = 0; j < 50; ++j) {
  13542. hash = calculateMD5(hash, 0, hash.length);
  13543. }
  13544. }
  13545. var cipher, userPassword;
  13546. if (revision >= 3) {
  13547. userPassword = ownerPassword;
  13548. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  13549. for (j = 19; j >= 0; j--) {
  13550. for (k = 0; k < keyLengthInBytes; ++k) {
  13551. derivedKey[k] = hash[k] ^ j;
  13552. }
  13553. cipher = new ARCFourCipher(derivedKey);
  13554. userPassword = cipher.encryptBlock(userPassword);
  13555. }
  13556. } else {
  13557. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  13558. userPassword = cipher.encryptBlock(ownerPassword);
  13559. }
  13560. return userPassword;
  13561. }
  13562. var identityName = Name.get('Identity');
  13563. function CipherTransformFactory(dict, fileId, password) {
  13564. var filter = dict.get('Filter');
  13565. if (!isName(filter) || filter.name !== 'Standard') {
  13566. error('unknown encryption method');
  13567. }
  13568. this.dict = dict;
  13569. var algorithm = dict.get('V');
  13570. if (!isInt(algorithm) ||
  13571. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  13572. algorithm !== 5)) {
  13573. error('unsupported encryption algorithm');
  13574. }
  13575. this.algorithm = algorithm;
  13576. var keyLength = dict.get('Length') || 40;
  13577. if (!isInt(keyLength) ||
  13578. keyLength < 40 || (keyLength % 8) !== 0) {
  13579. error('invalid key length');
  13580. }
  13581. // prepare keys
  13582. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  13583. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  13584. var flags = dict.get('P');
  13585. var revision = dict.get('R');
  13586. // meaningful when V is 4 or 5
  13587. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  13588. dict.get('EncryptMetadata') !== false);
  13589. this.encryptMetadata = encryptMetadata;
  13590. var fileIdBytes = stringToBytes(fileId);
  13591. var passwordBytes;
  13592. if (password) {
  13593. passwordBytes = stringToBytes(password);
  13594. }
  13595. var encryptionKey;
  13596. if (algorithm !== 5) {
  13597. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  13598. ownerPassword, userPassword, flags,
  13599. revision, keyLength, encryptMetadata);
  13600. }
  13601. else {
  13602. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  13603. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  13604. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  13605. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  13606. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  13607. var ownerEncryption = stringToBytes(dict.get('OE'));
  13608. var userEncryption = stringToBytes(dict.get('UE'));
  13609. var perms = stringToBytes(dict.get('Perms'));
  13610. encryptionKey =
  13611. createEncryptionKey20(revision, passwordBytes,
  13612. ownerPassword, ownerValidationSalt,
  13613. ownerKeySalt, uBytes,
  13614. userPassword, userValidationSalt,
  13615. userKeySalt, ownerEncryption,
  13616. userEncryption, perms);
  13617. }
  13618. if (!encryptionKey && !password) {
  13619. throw new PasswordException('No password given',
  13620. PasswordResponses.NEED_PASSWORD);
  13621. } else if (!encryptionKey && password) {
  13622. // Attempting use the password as an owner password
  13623. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  13624. revision, keyLength);
  13625. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  13626. ownerPassword, userPassword, flags,
  13627. revision, keyLength, encryptMetadata);
  13628. }
  13629. if (!encryptionKey) {
  13630. throw new PasswordException('Incorrect Password',
  13631. PasswordResponses.INCORRECT_PASSWORD);
  13632. }
  13633. this.encryptionKey = encryptionKey;
  13634. if (algorithm >= 4) {
  13635. this.cf = dict.get('CF');
  13636. this.stmf = dict.get('StmF') || identityName;
  13637. this.strf = dict.get('StrF') || identityName;
  13638. this.eff = dict.get('EFF') || this.strf;
  13639. }
  13640. }
  13641. function buildObjectKey(num, gen, encryptionKey, isAes) {
  13642. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  13643. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  13644. key[i] = encryptionKey[i];
  13645. }
  13646. key[i++] = num & 0xFF;
  13647. key[i++] = (num >> 8) & 0xFF;
  13648. key[i++] = (num >> 16) & 0xFF;
  13649. key[i++] = gen & 0xFF;
  13650. key[i++] = (gen >> 8) & 0xFF;
  13651. if (isAes) {
  13652. key[i++] = 0x73;
  13653. key[i++] = 0x41;
  13654. key[i++] = 0x6C;
  13655. key[i++] = 0x54;
  13656. }
  13657. var hash = calculateMD5(key, 0, i);
  13658. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  13659. }
  13660. function buildCipherConstructor(cf, name, num, gen, key) {
  13661. var cryptFilter = cf.get(name.name);
  13662. var cfm;
  13663. if (cryptFilter !== null && cryptFilter !== undefined) {
  13664. cfm = cryptFilter.get('CFM');
  13665. }
  13666. if (!cfm || cfm.name === 'None') {
  13667. return function cipherTransformFactoryBuildCipherConstructorNone() {
  13668. return new NullCipher();
  13669. };
  13670. }
  13671. if ('V2' === cfm.name) {
  13672. return function cipherTransformFactoryBuildCipherConstructorV2() {
  13673. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  13674. };
  13675. }
  13676. if ('AESV2' === cfm.name) {
  13677. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  13678. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  13679. };
  13680. }
  13681. if ('AESV3' === cfm.name) {
  13682. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  13683. return new AES256Cipher(key);
  13684. };
  13685. }
  13686. error('Unknown crypto method');
  13687. }
  13688. CipherTransformFactory.prototype = {
  13689. createCipherTransform:
  13690. function CipherTransformFactory_createCipherTransform(num, gen) {
  13691. if (this.algorithm === 4 || this.algorithm === 5) {
  13692. return new CipherTransform(
  13693. buildCipherConstructor(this.cf, this.stmf,
  13694. num, gen, this.encryptionKey),
  13695. buildCipherConstructor(this.cf, this.strf,
  13696. num, gen, this.encryptionKey));
  13697. }
  13698. // algorithms 1 and 2
  13699. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  13700. var cipherConstructor = function buildCipherCipherConstructor() {
  13701. return new ARCFourCipher(key);
  13702. };
  13703. return new CipherTransform(cipherConstructor, cipherConstructor);
  13704. }
  13705. };
  13706. return CipherTransformFactory;
  13707. })();
  13708. var PatternType = {
  13709. FUNCTION_BASED: 1,
  13710. AXIAL: 2,
  13711. RADIAL: 3,
  13712. FREE_FORM_MESH: 4,
  13713. LATTICE_FORM_MESH: 5,
  13714. COONS_PATCH_MESH: 6,
  13715. TENSOR_PATCH_MESH: 7
  13716. };
  13717. var Pattern = (function PatternClosure() {
  13718. // Constructor should define this.getPattern
  13719. function Pattern() {
  13720. error('should not call Pattern constructor');
  13721. }
  13722. Pattern.prototype = {
  13723. // Input: current Canvas context
  13724. // Output: the appropriate fillStyle or strokeStyle
  13725. getPattern: function Pattern_getPattern(ctx) {
  13726. error('Should not call Pattern.getStyle: ' + ctx);
  13727. }
  13728. };
  13729. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  13730. res) {
  13731. var dict = isStream(shading) ? shading.dict : shading;
  13732. var type = dict.get('ShadingType');
  13733. switch (type) {
  13734. case PatternType.AXIAL:
  13735. case PatternType.RADIAL:
  13736. // Both radial and axial shadings are handled by RadialAxial shading.
  13737. return new Shadings.RadialAxial(dict, matrix, xref, res);
  13738. case PatternType.FREE_FORM_MESH:
  13739. case PatternType.LATTICE_FORM_MESH:
  13740. case PatternType.COONS_PATCH_MESH:
  13741. case PatternType.TENSOR_PATCH_MESH:
  13742. return new Shadings.Mesh(shading, matrix, xref, res);
  13743. default:
  13744. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  13745. return new Shadings.Dummy();
  13746. }
  13747. };
  13748. return Pattern;
  13749. })();
  13750. var Shadings = {};
  13751. // A small number to offset the first/last color stops so we can insert ones to
  13752. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  13753. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  13754. // internally so we have to go bigger.
  13755. Shadings.SMALL_NUMBER = 1e-2;
  13756. // Radial and axial shading have very similar implementations
  13757. // If needed, the implementations can be broken into two classes
  13758. Shadings.RadialAxial = (function RadialAxialClosure() {
  13759. function RadialAxial(dict, matrix, xref, res) {
  13760. this.matrix = matrix;
  13761. this.coordsArr = dict.get('Coords');
  13762. this.shadingType = dict.get('ShadingType');
  13763. this.type = 'Pattern';
  13764. var cs = dict.get('ColorSpace', 'CS');
  13765. cs = ColorSpace.parse(cs, xref, res);
  13766. this.cs = cs;
  13767. var t0 = 0.0, t1 = 1.0;
  13768. if (dict.has('Domain')) {
  13769. var domainArr = dict.get('Domain');
  13770. t0 = domainArr[0];
  13771. t1 = domainArr[1];
  13772. }
  13773. var extendStart = false, extendEnd = false;
  13774. if (dict.has('Extend')) {
  13775. var extendArr = dict.get('Extend');
  13776. extendStart = extendArr[0];
  13777. extendEnd = extendArr[1];
  13778. }
  13779. if (this.shadingType === PatternType.RADIAL &&
  13780. (!extendStart || !extendEnd)) {
  13781. // Radial gradient only currently works if either circle is fully within
  13782. // the other circle.
  13783. var x1 = this.coordsArr[0];
  13784. var y1 = this.coordsArr[1];
  13785. var r1 = this.coordsArr[2];
  13786. var x2 = this.coordsArr[3];
  13787. var y2 = this.coordsArr[4];
  13788. var r2 = this.coordsArr[5];
  13789. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  13790. if (r1 <= r2 + distance &&
  13791. r2 <= r1 + distance) {
  13792. warn('Unsupported radial gradient.');
  13793. }
  13794. }
  13795. this.extendStart = extendStart;
  13796. this.extendEnd = extendEnd;
  13797. var fnObj = dict.get('Function');
  13798. var fn = PDFFunction.parseArray(xref, fnObj);
  13799. // 10 samples seems good enough for now, but probably won't work
  13800. // if there are sharp color changes. Ideally, we would implement
  13801. // the spec faithfully and add lossless optimizations.
  13802. var diff = t1 - t0;
  13803. var step = diff / 10;
  13804. var colorStops = this.colorStops = [];
  13805. // Protect against bad domains so we don't end up in an infinte loop below.
  13806. if (t0 >= t1 || step <= 0) {
  13807. // Acrobat doesn't seem to handle these cases so we'll ignore for
  13808. // now.
  13809. info('Bad shading domain.');
  13810. return;
  13811. }
  13812. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  13813. var rgbColor;
  13814. for (var i = t0; i <= t1; i += step) {
  13815. ratio[0] = i;
  13816. fn(ratio, 0, color, 0);
  13817. rgbColor = cs.getRgb(color, 0);
  13818. var cssColor = Util.makeCssRgb(rgbColor);
  13819. colorStops.push([(i - t0) / diff, cssColor]);
  13820. }
  13821. var background = 'transparent';
  13822. if (dict.has('Background')) {
  13823. rgbColor = cs.getRgb(dict.get('Background'), 0);
  13824. background = Util.makeCssRgb(rgbColor);
  13825. }
  13826. if (!extendStart) {
  13827. // Insert a color stop at the front and offset the first real color stop
  13828. // so it doesn't conflict with the one we insert.
  13829. colorStops.unshift([0, background]);
  13830. colorStops[1][0] += Shadings.SMALL_NUMBER;
  13831. }
  13832. if (!extendEnd) {
  13833. // Same idea as above in extendStart but for the end.
  13834. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  13835. colorStops.push([1, background]);
  13836. }
  13837. this.colorStops = colorStops;
  13838. }
  13839. RadialAxial.prototype = {
  13840. getIR: function RadialAxial_getIR() {
  13841. var coordsArr = this.coordsArr;
  13842. var shadingType = this.shadingType;
  13843. var type, p0, p1, r0, r1;
  13844. if (shadingType === PatternType.AXIAL) {
  13845. p0 = [coordsArr[0], coordsArr[1]];
  13846. p1 = [coordsArr[2], coordsArr[3]];
  13847. r0 = null;
  13848. r1 = null;
  13849. type = 'axial';
  13850. } else if (shadingType === PatternType.RADIAL) {
  13851. p0 = [coordsArr[0], coordsArr[1]];
  13852. p1 = [coordsArr[3], coordsArr[4]];
  13853. r0 = coordsArr[2];
  13854. r1 = coordsArr[5];
  13855. type = 'radial';
  13856. } else {
  13857. error('getPattern type unknown: ' + shadingType);
  13858. }
  13859. var matrix = this.matrix;
  13860. if (matrix) {
  13861. p0 = Util.applyTransform(p0, matrix);
  13862. p1 = Util.applyTransform(p1, matrix);
  13863. }
  13864. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  13865. }
  13866. };
  13867. return RadialAxial;
  13868. })();
  13869. // All mesh shading. For now, they will be presented as set of the triangles
  13870. // to be drawn on the canvas and rgb color for each vertex.
  13871. Shadings.Mesh = (function MeshClosure() {
  13872. function MeshStreamReader(stream, context) {
  13873. this.stream = stream;
  13874. this.context = context;
  13875. this.buffer = 0;
  13876. this.bufferLength = 0;
  13877. var numComps = context.numComps;
  13878. this.tmpCompsBuf = new Float32Array(numComps);
  13879. var csNumComps = context.colorSpace;
  13880. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  13881. this.tmpCompsBuf;
  13882. }
  13883. MeshStreamReader.prototype = {
  13884. get hasData() {
  13885. if (this.stream.end) {
  13886. return this.stream.pos < this.stream.end;
  13887. }
  13888. if (this.bufferLength > 0) {
  13889. return true;
  13890. }
  13891. var nextByte = this.stream.getByte();
  13892. if (nextByte < 0) {
  13893. return false;
  13894. }
  13895. this.buffer = nextByte;
  13896. this.bufferLength = 8;
  13897. return true;
  13898. },
  13899. readBits: function MeshStreamReader_readBits(n) {
  13900. var buffer = this.buffer;
  13901. var bufferLength = this.bufferLength;
  13902. if (n === 32) {
  13903. if (bufferLength === 0) {
  13904. return ((this.stream.getByte() << 24) |
  13905. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  13906. this.stream.getByte()) >>> 0;
  13907. }
  13908. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  13909. (this.stream.getByte() << 8) | this.stream.getByte();
  13910. var nextByte = this.stream.getByte();
  13911. this.buffer = nextByte & ((1 << bufferLength) - 1);
  13912. return ((buffer << (8 - bufferLength)) |
  13913. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  13914. }
  13915. if (n === 8 && bufferLength === 0) {
  13916. return this.stream.getByte();
  13917. }
  13918. while (bufferLength < n) {
  13919. buffer = (buffer << 8) | this.stream.getByte();
  13920. bufferLength += 8;
  13921. }
  13922. bufferLength -= n;
  13923. this.bufferLength = bufferLength;
  13924. this.buffer = buffer & ((1 << bufferLength) - 1);
  13925. return buffer >> bufferLength;
  13926. },
  13927. align: function MeshStreamReader_align() {
  13928. this.buffer = 0;
  13929. this.bufferLength = 0;
  13930. },
  13931. readFlag: function MeshStreamReader_readFlag() {
  13932. return this.readBits(this.context.bitsPerFlag);
  13933. },
  13934. readCoordinate: function MeshStreamReader_readCoordinate() {
  13935. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  13936. var xi = this.readBits(bitsPerCoordinate);
  13937. var yi = this.readBits(bitsPerCoordinate);
  13938. var decode = this.context.decode;
  13939. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  13940. 2.3283064365386963e-10; // 2 ^ -32
  13941. return [
  13942. xi * scale * (decode[1] - decode[0]) + decode[0],
  13943. yi * scale * (decode[3] - decode[2]) + decode[2]
  13944. ];
  13945. },
  13946. readComponents: function MeshStreamReader_readComponents() {
  13947. var numComps = this.context.numComps;
  13948. var bitsPerComponent = this.context.bitsPerComponent;
  13949. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  13950. 2.3283064365386963e-10; // 2 ^ -32
  13951. var decode = this.context.decode;
  13952. var components = this.tmpCompsBuf;
  13953. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  13954. var ci = this.readBits(bitsPerComponent);
  13955. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  13956. }
  13957. var color = this.tmpCsCompsBuf;
  13958. if (this.context.colorFn) {
  13959. this.context.colorFn(components, 0, color, 0);
  13960. }
  13961. return this.context.colorSpace.getRgb(color, 0);
  13962. }
  13963. };
  13964. function decodeType4Shading(mesh, reader) {
  13965. var coords = mesh.coords;
  13966. var colors = mesh.colors;
  13967. var operators = [];
  13968. var ps = []; // not maintaining cs since that will match ps
  13969. var verticesLeft = 0; // assuming we have all data to start a new triangle
  13970. while (reader.hasData) {
  13971. var f = reader.readFlag();
  13972. var coord = reader.readCoordinate();
  13973. var color = reader.readComponents();
  13974. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  13975. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  13976. switch (f) {
  13977. case 0:
  13978. verticesLeft = 3;
  13979. break;
  13980. case 1:
  13981. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  13982. verticesLeft = 1;
  13983. break;
  13984. case 2:
  13985. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  13986. verticesLeft = 1;
  13987. break;
  13988. }
  13989. operators.push(f);
  13990. }
  13991. ps.push(coords.length);
  13992. coords.push(coord);
  13993. colors.push(color);
  13994. verticesLeft--;
  13995. reader.align();
  13996. }
  13997. var psPacked = new Int32Array(ps);
  13998. mesh.figures.push({
  13999. type: 'triangles',
  14000. coords: psPacked,
  14001. colors: psPacked
  14002. });
  14003. }
  14004. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14005. var coords = mesh.coords;
  14006. var colors = mesh.colors;
  14007. var ps = []; // not maintaining cs since that will match ps
  14008. while (reader.hasData) {
  14009. var coord = reader.readCoordinate();
  14010. var color = reader.readComponents();
  14011. ps.push(coords.length);
  14012. coords.push(coord);
  14013. colors.push(color);
  14014. }
  14015. var psPacked = new Int32Array(ps);
  14016. mesh.figures.push({
  14017. type: 'lattice',
  14018. coords: psPacked,
  14019. colors: psPacked,
  14020. verticesPerRow: verticesPerRow
  14021. });
  14022. }
  14023. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14024. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14025. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14026. var getB = (function getBClosure() {
  14027. function buildB(count) {
  14028. var lut = [];
  14029. for (var i = 0; i <= count; i++) {
  14030. var t = i / count, t_ = 1 - t;
  14031. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14032. 3 * t * t * t_, t * t * t]));
  14033. }
  14034. return lut;
  14035. }
  14036. var cache = [];
  14037. return function getB(count) {
  14038. if (!cache[count]) {
  14039. cache[count] = buildB(count);
  14040. }
  14041. return cache[count];
  14042. };
  14043. })();
  14044. function buildFigureFromPatch(mesh, index) {
  14045. var figure = mesh.figures[index];
  14046. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14047. var coords = mesh.coords, colors = mesh.colors;
  14048. var pi = figure.coords;
  14049. var ci = figure.colors;
  14050. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14051. coords[pi[12]][0], coords[pi[15]][0]);
  14052. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14053. coords[pi[12]][1], coords[pi[15]][1]);
  14054. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14055. coords[pi[12]][0], coords[pi[15]][0]);
  14056. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14057. coords[pi[12]][1], coords[pi[15]][1]);
  14058. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14059. (mesh.bounds[2] - mesh.bounds[0]));
  14060. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14061. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14062. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14063. (mesh.bounds[3] - mesh.bounds[1]));
  14064. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14065. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14066. var verticesPerRow = splitXBy + 1;
  14067. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14068. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14069. var k = 0;
  14070. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14071. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14072. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14073. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14074. for (var row = 0; row <= splitYBy; row++) {
  14075. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14076. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14077. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14078. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14079. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14080. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14081. for (var col = 0; col <= splitXBy; col++, k++) {
  14082. if ((row === 0 || row === splitYBy) &&
  14083. (col === 0 || col === splitXBy)) {
  14084. continue;
  14085. }
  14086. var x = 0, y = 0;
  14087. var q = 0;
  14088. for (var i = 0; i <= 3; i++) {
  14089. for (var j = 0; j <= 3; j++, q++) {
  14090. var m = bRow[row][i] * bCol[col][j];
  14091. x += coords[pi[q]][0] * m;
  14092. y += coords[pi[q]][1] * m;
  14093. }
  14094. }
  14095. figureCoords[k] = coords.length;
  14096. coords.push([x, y]);
  14097. figureColors[k] = colors.length;
  14098. var newColor = new Uint8Array(3);
  14099. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14100. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14101. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14102. colors.push(newColor);
  14103. }
  14104. }
  14105. figureCoords[0] = pi[0];
  14106. figureColors[0] = ci[0];
  14107. figureCoords[splitXBy] = pi[3];
  14108. figureColors[splitXBy] = ci[1];
  14109. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14110. figureColors[verticesPerRow * splitYBy] = ci[2];
  14111. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14112. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14113. mesh.figures[index] = {
  14114. type: 'lattice',
  14115. coords: figureCoords,
  14116. colors: figureColors,
  14117. verticesPerRow: verticesPerRow
  14118. };
  14119. }
  14120. function decodeType6Shading(mesh, reader) {
  14121. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14122. var coords = mesh.coords;
  14123. var colors = mesh.colors;
  14124. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14125. var cs = new Int32Array(4); // c00, c30, c03, c33
  14126. while (reader.hasData) {
  14127. var f = reader.readFlag();
  14128. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14129. var i, ii;
  14130. var pi = coords.length;
  14131. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14132. coords.push(reader.readCoordinate());
  14133. }
  14134. var ci = colors.length;
  14135. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14136. colors.push(reader.readComponents());
  14137. }
  14138. var tmp1, tmp2, tmp3, tmp4;
  14139. switch (f) {
  14140. case 0:
  14141. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14142. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14143. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14144. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14145. cs[2] = ci + 1; cs[3] = ci + 2;
  14146. cs[0] = ci; cs[1] = ci + 3;
  14147. break;
  14148. case 1:
  14149. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14150. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14151. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14152. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14153. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14154. tmp1 = cs[2]; tmp2 = cs[3];
  14155. cs[2] = ci + 1; cs[3] = ci;
  14156. cs[0] = tmp1; cs[1] = tmp2;
  14157. break;
  14158. case 2:
  14159. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14160. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14161. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14162. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14163. cs[2] = cs[3]; cs[3] = ci + 1;
  14164. cs[0] = cs[1]; cs[1] = ci;
  14165. break;
  14166. case 3:
  14167. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14168. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14169. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14170. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14171. cs[2] = cs[0]; cs[3] = cs[1];
  14172. cs[0] = ci; cs[1] = ci + 1;
  14173. break;
  14174. }
  14175. // set p11, p12, p21, p22
  14176. ps[5] = coords.length;
  14177. coords.push([
  14178. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14179. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14180. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14181. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14182. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14183. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14184. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14185. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14186. ]);
  14187. ps[6] = coords.length;
  14188. coords.push([
  14189. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14190. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14191. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14192. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14193. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14194. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14195. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14196. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14197. ]);
  14198. ps[9] = coords.length;
  14199. coords.push([
  14200. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14201. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14202. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14203. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14204. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14205. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14206. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14207. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14208. ]);
  14209. ps[10] = coords.length;
  14210. coords.push([
  14211. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14212. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14213. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14214. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14215. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14216. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14217. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14218. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14219. ]);
  14220. mesh.figures.push({
  14221. type: 'patch',
  14222. coords: new Int32Array(ps), // making copies of ps and cs
  14223. colors: new Int32Array(cs)
  14224. });
  14225. }
  14226. }
  14227. function decodeType7Shading(mesh, reader) {
  14228. var coords = mesh.coords;
  14229. var colors = mesh.colors;
  14230. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14231. var cs = new Int32Array(4); // c00, c30, c03, c33
  14232. while (reader.hasData) {
  14233. var f = reader.readFlag();
  14234. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  14235. var i, ii;
  14236. var pi = coords.length;
  14237. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  14238. coords.push(reader.readCoordinate());
  14239. }
  14240. var ci = colors.length;
  14241. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14242. colors.push(reader.readComponents());
  14243. }
  14244. var tmp1, tmp2, tmp3, tmp4;
  14245. switch (f) {
  14246. case 0:
  14247. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14248. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  14249. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  14250. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14251. cs[2] = ci + 1; cs[3] = ci + 2;
  14252. cs[0] = ci; cs[1] = ci + 3;
  14253. break;
  14254. case 1:
  14255. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14256. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14257. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  14258. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  14259. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14260. tmp1 = cs[2]; tmp2 = cs[3];
  14261. cs[2] = ci + 1; cs[3] = ci;
  14262. cs[0] = tmp1; cs[1] = tmp2;
  14263. break;
  14264. case 2:
  14265. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14266. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  14267. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  14268. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14269. cs[2] = cs[3]; cs[3] = ci + 1;
  14270. cs[0] = cs[1]; cs[1] = ci;
  14271. break;
  14272. case 3:
  14273. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14274. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  14275. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  14276. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14277. cs[2] = cs[0]; cs[3] = cs[1];
  14278. cs[0] = ci; cs[1] = ci + 1;
  14279. break;
  14280. }
  14281. mesh.figures.push({
  14282. type: 'patch',
  14283. coords: new Int32Array(ps), // making copies of ps and cs
  14284. colors: new Int32Array(cs)
  14285. });
  14286. }
  14287. }
  14288. function updateBounds(mesh) {
  14289. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  14290. maxX = minX, maxY = minY;
  14291. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  14292. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  14293. minX = minX > x ? x : minX;
  14294. minY = minY > y ? y : minY;
  14295. maxX = maxX < x ? x : maxX;
  14296. maxY = maxY < y ? y : maxY;
  14297. }
  14298. mesh.bounds = [minX, minY, maxX, maxY];
  14299. }
  14300. function packData(mesh) {
  14301. var i, ii, j, jj;
  14302. var coords = mesh.coords;
  14303. var coordsPacked = new Float32Array(coords.length * 2);
  14304. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  14305. var xy = coords[i];
  14306. coordsPacked[j++] = xy[0];
  14307. coordsPacked[j++] = xy[1];
  14308. }
  14309. mesh.coords = coordsPacked;
  14310. var colors = mesh.colors;
  14311. var colorsPacked = new Uint8Array(colors.length * 3);
  14312. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  14313. var c = colors[i];
  14314. colorsPacked[j++] = c[0];
  14315. colorsPacked[j++] = c[1];
  14316. colorsPacked[j++] = c[2];
  14317. }
  14318. mesh.colors = colorsPacked;
  14319. var figures = mesh.figures;
  14320. for (i = 0, ii = figures.length; i < ii; i++) {
  14321. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  14322. for (j = 0, jj = ps.length; j < jj; j++) {
  14323. ps[j] *= 2;
  14324. cs[j] *= 3;
  14325. }
  14326. }
  14327. }
  14328. function Mesh(stream, matrix, xref, res) {
  14329. assert(isStream(stream), 'Mesh data is not a stream');
  14330. var dict = stream.dict;
  14331. this.matrix = matrix;
  14332. this.shadingType = dict.get('ShadingType');
  14333. this.type = 'Pattern';
  14334. this.bbox = dict.get('BBox');
  14335. var cs = dict.get('ColorSpace', 'CS');
  14336. cs = ColorSpace.parse(cs, xref, res);
  14337. this.cs = cs;
  14338. this.background = dict.has('Background') ?
  14339. cs.getRgb(dict.get('Background'), 0) : null;
  14340. var fnObj = dict.get('Function');
  14341. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  14342. this.coords = [];
  14343. this.colors = [];
  14344. this.figures = [];
  14345. var decodeContext = {
  14346. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  14347. bitsPerComponent: dict.get('BitsPerComponent'),
  14348. bitsPerFlag: dict.get('BitsPerFlag'),
  14349. decode: dict.get('Decode'),
  14350. colorFn: fn,
  14351. colorSpace: cs,
  14352. numComps: fn ? 1 : cs.numComps
  14353. };
  14354. var reader = new MeshStreamReader(stream, decodeContext);
  14355. var patchMesh = false;
  14356. switch (this.shadingType) {
  14357. case PatternType.FREE_FORM_MESH:
  14358. decodeType4Shading(this, reader);
  14359. break;
  14360. case PatternType.LATTICE_FORM_MESH:
  14361. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  14362. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  14363. decodeType5Shading(this, reader, verticesPerRow);
  14364. break;
  14365. case PatternType.COONS_PATCH_MESH:
  14366. decodeType6Shading(this, reader);
  14367. patchMesh = true;
  14368. break;
  14369. case PatternType.TENSOR_PATCH_MESH:
  14370. decodeType7Shading(this, reader);
  14371. patchMesh = true;
  14372. break;
  14373. default:
  14374. error('Unsupported mesh type.');
  14375. break;
  14376. }
  14377. if (patchMesh) {
  14378. // dirty bounds calculation for determining, how dense shall be triangles
  14379. updateBounds(this);
  14380. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  14381. buildFigureFromPatch(this, i);
  14382. }
  14383. }
  14384. // calculate bounds
  14385. updateBounds(this);
  14386. packData(this);
  14387. }
  14388. Mesh.prototype = {
  14389. getIR: function Mesh_getIR() {
  14390. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  14391. this.bounds, this.matrix, this.bbox, this.background];
  14392. }
  14393. };
  14394. return Mesh;
  14395. })();
  14396. Shadings.Dummy = (function DummyClosure() {
  14397. function Dummy() {
  14398. this.type = 'Pattern';
  14399. }
  14400. Dummy.prototype = {
  14401. getIR: function Dummy_getIR() {
  14402. return ['Dummy'];
  14403. }
  14404. };
  14405. return Dummy;
  14406. })();
  14407. function getTilingPatternIR(operatorList, dict, args) {
  14408. var matrix = dict.get('Matrix');
  14409. var bbox = dict.get('BBox');
  14410. var xstep = dict.get('XStep');
  14411. var ystep = dict.get('YStep');
  14412. var paintType = dict.get('PaintType');
  14413. var tilingType = dict.get('TilingType');
  14414. return [
  14415. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  14416. paintType, tilingType
  14417. ];
  14418. }
  14419. var PartialEvaluator = (function PartialEvaluatorClosure() {
  14420. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  14421. uniquePrefix, idCounters, fontCache) {
  14422. this.pdfManager = pdfManager;
  14423. this.xref = xref;
  14424. this.handler = handler;
  14425. this.pageIndex = pageIndex;
  14426. this.uniquePrefix = uniquePrefix;
  14427. this.idCounters = idCounters;
  14428. this.fontCache = fontCache;
  14429. }
  14430. // Trying to minimize Date.now() usage and check every 100 time
  14431. var TIME_SLOT_DURATION_MS = 20;
  14432. var CHECK_TIME_EVERY = 100;
  14433. function TimeSlotManager() {
  14434. this.reset();
  14435. }
  14436. TimeSlotManager.prototype = {
  14437. check: function TimeSlotManager_check() {
  14438. if (++this.checked < CHECK_TIME_EVERY) {
  14439. return false;
  14440. }
  14441. this.checked = 0;
  14442. return this.endTime <= Date.now();
  14443. },
  14444. reset: function TimeSlotManager_reset() {
  14445. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  14446. this.checked = 0;
  14447. }
  14448. };
  14449. var deferred = Promise.resolve();
  14450. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  14451. PartialEvaluator.prototype = {
  14452. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  14453. if (!isDict(resources)) {
  14454. return false;
  14455. }
  14456. var processed = Object.create(null);
  14457. if (resources.objId) {
  14458. processed[resources.objId] = true;
  14459. }
  14460. var nodes = [resources];
  14461. while (nodes.length) {
  14462. var key;
  14463. var node = nodes.shift();
  14464. // First check the current resources for blend modes.
  14465. var graphicStates = node.get('ExtGState');
  14466. if (isDict(graphicStates)) {
  14467. graphicStates = graphicStates.getAll();
  14468. for (key in graphicStates) {
  14469. var graphicState = graphicStates[key];
  14470. var bm = graphicState['BM'];
  14471. if (isName(bm) && bm.name !== 'Normal') {
  14472. return true;
  14473. }
  14474. }
  14475. }
  14476. // Descend into the XObjects to look for more resources and blend modes.
  14477. var xObjects = node.get('XObject');
  14478. if (!isDict(xObjects)) {
  14479. continue;
  14480. }
  14481. xObjects = xObjects.getAll();
  14482. for (key in xObjects) {
  14483. var xObject = xObjects[key];
  14484. if (!isStream(xObject)) {
  14485. continue;
  14486. }
  14487. if (xObject.dict.objId) {
  14488. if (processed[xObject.dict.objId]) {
  14489. // stream has objId and is processed already
  14490. continue;
  14491. }
  14492. processed[xObject.dict.objId] = true;
  14493. }
  14494. var xResources = xObject.dict.get('Resources');
  14495. // Checking objId to detect an infinite loop.
  14496. if (isDict(xResources) &&
  14497. (!xResources.objId || !processed[xResources.objId])) {
  14498. nodes.push(xResources);
  14499. if (xResources.objId) {
  14500. processed[xResources.objId] = true;
  14501. }
  14502. }
  14503. }
  14504. }
  14505. return false;
  14506. },
  14507. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  14508. xobj, smask,
  14509. operatorList,
  14510. initialState) {
  14511. var matrix = xobj.dict.get('Matrix');
  14512. var bbox = xobj.dict.get('BBox');
  14513. var group = xobj.dict.get('Group');
  14514. if (group) {
  14515. var groupOptions = {
  14516. matrix: matrix,
  14517. bbox: bbox,
  14518. smask: smask,
  14519. isolated: false,
  14520. knockout: false
  14521. };
  14522. var groupSubtype = group.get('S');
  14523. var colorSpace;
  14524. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  14525. groupOptions.isolated = (group.get('I') || false);
  14526. groupOptions.knockout = (group.get('K') || false);
  14527. colorSpace = (group.has('CS') ?
  14528. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  14529. }
  14530. if (smask && smask.backdrop) {
  14531. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  14532. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  14533. }
  14534. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  14535. }
  14536. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  14537. return this.getOperatorList(xobj,
  14538. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  14539. then(function () {
  14540. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  14541. if (group) {
  14542. operatorList.addOp(OPS.endGroup, [groupOptions]);
  14543. }
  14544. });
  14545. },
  14546. buildPaintImageXObject:
  14547. function PartialEvaluator_buildPaintImageXObject(resources, image,
  14548. inline, operatorList,
  14549. cacheKey, cache) {
  14550. var self = this;
  14551. var dict = image.dict;
  14552. var w = dict.get('Width', 'W');
  14553. var h = dict.get('Height', 'H');
  14554. if (!(w && isNum(w)) || !(h && isNum(h))) {
  14555. warn('Image dimensions are missing, or not numbers.');
  14556. return;
  14557. }
  14558. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  14559. warn('Image exceeded maximum allowed size and was removed.');
  14560. return;
  14561. }
  14562. var imageMask = (dict.get('ImageMask', 'IM') || false);
  14563. var imgData, args;
  14564. if (imageMask) {
  14565. // This depends on a tmpCanvas being filled with the
  14566. // current fillStyle, such that processing the pixel
  14567. // data can't be done here. Instead of creating a
  14568. // complete PDFImage, only read the information needed
  14569. // for later.
  14570. var width = dict.get('Width', 'W');
  14571. var height = dict.get('Height', 'H');
  14572. var bitStrideLength = (width + 7) >> 3;
  14573. var imgArray = image.getBytes(bitStrideLength * height);
  14574. var decode = dict.get('Decode', 'D');
  14575. var inverseDecode = (!!decode && decode[0] > 0);
  14576. imgData = PDFImage.createMask(imgArray, width, height,
  14577. image instanceof DecodeStream,
  14578. inverseDecode);
  14579. imgData.cached = true;
  14580. args = [imgData];
  14581. operatorList.addOp(OPS.paintImageMaskXObject, args);
  14582. if (cacheKey) {
  14583. cache.key = cacheKey;
  14584. cache.fn = OPS.paintImageMaskXObject;
  14585. cache.args = args;
  14586. }
  14587. return;
  14588. }
  14589. var softMask = (dict.get('SMask', 'SM') || false);
  14590. var mask = (dict.get('Mask') || false);
  14591. var SMALL_IMAGE_DIMENSIONS = 200;
  14592. // Inlining small images into the queue as RGB data
  14593. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  14594. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  14595. var imageObj = new PDFImage(this.xref, resources, image,
  14596. inline, null, null);
  14597. // We force the use of RGBA_32BPP images here, because we can't handle
  14598. // any other kind.
  14599. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  14600. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  14601. return;
  14602. }
  14603. // If there is no imageMask, create the PDFImage and a lot
  14604. // of image processing can be done here.
  14605. var uniquePrefix = (this.uniquePrefix || '');
  14606. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  14607. operatorList.addDependency(objId);
  14608. args = [objId, w, h];
  14609. if (!softMask && !mask && image instanceof JpegStream &&
  14610. image.isNativelySupported(this.xref, resources)) {
  14611. // These JPEGs don't need any more processing so we can just send it.
  14612. operatorList.addOp(OPS.paintJpegXObject, args);
  14613. this.handler.send('obj',
  14614. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  14615. return;
  14616. }
  14617. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  14618. then(function(imageObj) {
  14619. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  14620. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  14621. [imgData.data.buffer]);
  14622. }).then(null, function (reason) {
  14623. warn('Unable to decode image: ' + reason);
  14624. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  14625. });
  14626. operatorList.addOp(OPS.paintImageXObject, args);
  14627. if (cacheKey) {
  14628. cache.key = cacheKey;
  14629. cache.fn = OPS.paintImageXObject;
  14630. cache.args = args;
  14631. }
  14632. },
  14633. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  14634. operatorList,
  14635. stateManager) {
  14636. var smaskContent = smask.get('G');
  14637. var smaskOptions = {
  14638. subtype: smask.get('S').name,
  14639. backdrop: smask.get('BC')
  14640. };
  14641. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  14642. operatorList, stateManager.state.clone());
  14643. },
  14644. handleTilingType:
  14645. function PartialEvaluator_handleTilingType(fn, args, resources,
  14646. pattern, patternDict,
  14647. operatorList) {
  14648. // Create an IR of the pattern code.
  14649. var tilingOpList = new OperatorList();
  14650. return this.getOperatorList(pattern,
  14651. (patternDict.get('Resources') || resources), tilingOpList).
  14652. then(function () {
  14653. // Add the dependencies to the parent operator list so they are
  14654. // resolved before sub operator list is executed synchronously.
  14655. operatorList.addDependencies(tilingOpList.dependencies);
  14656. operatorList.addOp(fn, getTilingPatternIR({
  14657. fnArray: tilingOpList.fnArray,
  14658. argsArray: tilingOpList.argsArray
  14659. }, patternDict, args));
  14660. });
  14661. },
  14662. handleSetFont:
  14663. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  14664. operatorList, state) {
  14665. // TODO(mack): Not needed?
  14666. var fontName;
  14667. if (fontArgs) {
  14668. fontArgs = fontArgs.slice();
  14669. fontName = fontArgs[0].name;
  14670. }
  14671. var self = this;
  14672. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  14673. function (translated) {
  14674. if (!translated.font.isType3Font) {
  14675. return translated;
  14676. }
  14677. return translated.loadType3Data(self, resources, operatorList).then(
  14678. function () {
  14679. return translated;
  14680. });
  14681. }).then(function (translated) {
  14682. state.font = translated.font;
  14683. translated.send(self.handler);
  14684. return translated.loadedName;
  14685. });
  14686. },
  14687. handleText: function PartialEvaluator_handleText(chars, state) {
  14688. var font = state.font;
  14689. var glyphs = font.charsToGlyphs(chars);
  14690. var isAddToPathSet = !!(state.textRenderingMode &
  14691. TextRenderingMode.ADD_TO_PATH_FLAG);
  14692. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  14693. var buildPath = function (fontChar) {
  14694. if (!font.renderer.hasBuiltPath(fontChar)) {
  14695. var path = font.renderer.getPathJs(fontChar);
  14696. this.handler.send('commonobj', [
  14697. font.loadedName + '_path_' + fontChar,
  14698. 'FontPath',
  14699. path
  14700. ]);
  14701. }
  14702. }.bind(this);
  14703. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  14704. var glyph = glyphs[i];
  14705. if (glyph === null) {
  14706. continue;
  14707. }
  14708. buildPath(glyph.fontChar);
  14709. // If the glyph has an accent we need to build a path for its
  14710. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  14711. var accent = glyph.accent;
  14712. if (accent && accent.fontChar) {
  14713. buildPath(accent.fontChar);
  14714. }
  14715. }
  14716. }
  14717. return glyphs;
  14718. },
  14719. setGState: function PartialEvaluator_setGState(resources, gState,
  14720. operatorList, xref,
  14721. stateManager) {
  14722. // TODO(mack): This should be rewritten so that this function returns
  14723. // what should be added to the queue during each iteration
  14724. function setGStateForKey(gStateObj, key, value) {
  14725. switch (key) {
  14726. case 'Type':
  14727. break;
  14728. case 'LW':
  14729. case 'LC':
  14730. case 'LJ':
  14731. case 'ML':
  14732. case 'D':
  14733. case 'RI':
  14734. case 'FL':
  14735. case 'CA':
  14736. case 'ca':
  14737. gStateObj.push([key, value]);
  14738. break;
  14739. case 'Font':
  14740. promise = promise.then(function () {
  14741. return self.handleSetFont(resources, null, value[0],
  14742. operatorList, stateManager.state).
  14743. then(function (loadedName) {
  14744. operatorList.addDependency(loadedName);
  14745. gStateObj.push([key, [loadedName, value[1]]]);
  14746. });
  14747. });
  14748. break;
  14749. case 'BM':
  14750. gStateObj.push([key, value]);
  14751. break;
  14752. case 'SMask':
  14753. if (isName(value) && value.name === 'None') {
  14754. gStateObj.push([key, false]);
  14755. break;
  14756. }
  14757. var dict = xref.fetchIfRef(value);
  14758. if (isDict(dict)) {
  14759. promise = promise.then(function () {
  14760. return self.handleSMask(dict, resources, operatorList,
  14761. stateManager);
  14762. });
  14763. gStateObj.push([key, true]);
  14764. } else {
  14765. warn('Unsupported SMask type');
  14766. }
  14767. break;
  14768. // Only generate info log messages for the following since
  14769. // they are unlikey to have a big impact on the rendering.
  14770. case 'OP':
  14771. case 'op':
  14772. case 'OPM':
  14773. case 'BG':
  14774. case 'BG2':
  14775. case 'UCR':
  14776. case 'UCR2':
  14777. case 'TR':
  14778. case 'TR2':
  14779. case 'HT':
  14780. case 'SM':
  14781. case 'SA':
  14782. case 'AIS':
  14783. case 'TK':
  14784. // TODO implement these operators.
  14785. info('graphic state operator ' + key);
  14786. break;
  14787. default:
  14788. info('Unknown graphic state operator ' + key);
  14789. break;
  14790. }
  14791. }
  14792. // This array holds the converted/processed state data.
  14793. var gStateObj = [];
  14794. var gStateMap = gState.map;
  14795. var self = this;
  14796. var promise = Promise.resolve();
  14797. for (var key in gStateMap) {
  14798. var value = gStateMap[key];
  14799. setGStateForKey(gStateObj, key, value);
  14800. }
  14801. return promise.then(function () {
  14802. operatorList.addOp(OPS.setGState, [gStateObj]);
  14803. });
  14804. },
  14805. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  14806. resources) {
  14807. function errorFont() {
  14808. return Promise.resolve(new TranslatedFont('g_font_error',
  14809. new ErrorFont('Font ' + fontName + ' is not available'), font));
  14810. }
  14811. var fontRef;
  14812. if (font) { // Loading by ref.
  14813. assert(isRef(font));
  14814. fontRef = font;
  14815. } else { // Loading by name.
  14816. var fontRes = resources.get('Font');
  14817. if (fontRes) {
  14818. fontRef = fontRes.getRaw(fontName);
  14819. } else {
  14820. warn('fontRes not available');
  14821. return errorFont();
  14822. }
  14823. }
  14824. if (!fontRef) {
  14825. warn('fontRef not available');
  14826. return errorFont();
  14827. }
  14828. if (this.fontCache.has(fontRef)) {
  14829. return this.fontCache.get(fontRef);
  14830. }
  14831. font = xref.fetchIfRef(fontRef);
  14832. if (!isDict(font)) {
  14833. return errorFont();
  14834. }
  14835. // We are holding font.translated references just for fontRef that are not
  14836. // dictionaries (Dict). See explanation below.
  14837. if (font.translated) {
  14838. return font.translated;
  14839. }
  14840. var fontCapability = createPromiseCapability();
  14841. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  14842. var descriptor = preEvaluatedFont.descriptor;
  14843. var fontID = fontRef.num + '_' + fontRef.gen;
  14844. if (isDict(descriptor)) {
  14845. if (!descriptor.fontAliases) {
  14846. descriptor.fontAliases = Object.create(null);
  14847. }
  14848. var fontAliases = descriptor.fontAliases;
  14849. var hash = preEvaluatedFont.hash;
  14850. if (fontAliases[hash]) {
  14851. var aliasFontRef = fontAliases[hash].aliasRef;
  14852. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  14853. this.fontCache.putAlias(fontRef, aliasFontRef);
  14854. return this.fontCache.get(fontRef);
  14855. }
  14856. }
  14857. if (!fontAliases[hash]) {
  14858. fontAliases[hash] = {
  14859. fontID: Font.getFontID()
  14860. };
  14861. }
  14862. fontAliases[hash].aliasRef = fontRef;
  14863. fontID = fontAliases[hash].fontID;
  14864. }
  14865. // Workaround for bad PDF generators that don't reference fonts
  14866. // properly, i.e. by not using an object identifier.
  14867. // Check if the fontRef is a Dict (as opposed to a standard object),
  14868. // in which case we don't cache the font and instead reference it by
  14869. // fontName in font.loadedName below.
  14870. var fontRefIsDict = isDict(fontRef);
  14871. if (!fontRefIsDict) {
  14872. this.fontCache.put(fontRef, fontCapability.promise);
  14873. }
  14874. // Keep track of each font we translated so the caller can
  14875. // load them asynchronously before calling display on a page.
  14876. font.loadedName = 'g_font_' + (fontRefIsDict ?
  14877. fontName.replace(/\W/g, '') : fontID);
  14878. font.translated = fontCapability.promise;
  14879. // TODO move promises into translate font
  14880. var translatedPromise;
  14881. try {
  14882. translatedPromise = Promise.resolve(
  14883. this.translateFont(preEvaluatedFont, xref));
  14884. } catch (e) {
  14885. translatedPromise = Promise.reject(e);
  14886. }
  14887. translatedPromise.then(function (translatedFont) {
  14888. if (translatedFont.fontType !== undefined) {
  14889. var xrefFontStats = xref.stats.fontTypes;
  14890. xrefFontStats[translatedFont.fontType] = true;
  14891. }
  14892. fontCapability.resolve(new TranslatedFont(font.loadedName,
  14893. translatedFont, font));
  14894. }, function (reason) {
  14895. // TODO fontCapability.reject?
  14896. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  14897. try {
  14898. // error, but it's still nice to have font type reported
  14899. var descriptor = preEvaluatedFont.descriptor;
  14900. var fontFile3 = descriptor && descriptor.get('FontFile3');
  14901. var subtype = fontFile3 && fontFile3.get('Subtype');
  14902. var fontType = getFontType(preEvaluatedFont.type,
  14903. subtype && subtype.name);
  14904. var xrefFontStats = xref.stats.fontTypes;
  14905. xrefFontStats[fontType] = true;
  14906. } catch (ex) { }
  14907. fontCapability.resolve(new TranslatedFont(font.loadedName,
  14908. new ErrorFont(reason instanceof Error ? reason.message : reason),
  14909. font));
  14910. });
  14911. return fontCapability.promise;
  14912. },
  14913. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  14914. var lastIndex = operatorList.length - 1;
  14915. if (!args) {
  14916. args = [];
  14917. }
  14918. if (lastIndex < 0 ||
  14919. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  14920. operatorList.addOp(OPS.constructPath, [[fn], args]);
  14921. } else {
  14922. var opArgs = operatorList.argsArray[lastIndex];
  14923. opArgs[0].push(fn);
  14924. Array.prototype.push.apply(opArgs[1], args);
  14925. }
  14926. },
  14927. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  14928. cs, patterns, resources, xref) {
  14929. // compile tiling patterns
  14930. var patternName = args[args.length - 1];
  14931. // SCN/scn applies patterns along with normal colors
  14932. var pattern;
  14933. if (isName(patternName) &&
  14934. (pattern = patterns.get(patternName.name))) {
  14935. var dict = (isStream(pattern) ? pattern.dict : pattern);
  14936. var typeNum = dict.get('PatternType');
  14937. if (typeNum === TILING_PATTERN) {
  14938. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  14939. return this.handleTilingType(fn, color, resources, pattern,
  14940. dict, operatorList);
  14941. } else if (typeNum === SHADING_PATTERN) {
  14942. var shading = dict.get('Shading');
  14943. var matrix = dict.get('Matrix');
  14944. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  14945. operatorList.addOp(fn, pattern.getIR());
  14946. return Promise.resolve();
  14947. } else {
  14948. return Promise.reject('Unknown PatternType: ' + typeNum);
  14949. }
  14950. }
  14951. // TODO shall we fail here?
  14952. operatorList.addOp(fn, args);
  14953. return Promise.resolve();
  14954. },
  14955. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  14956. resources,
  14957. operatorList,
  14958. initialState) {
  14959. var self = this;
  14960. var xref = this.xref;
  14961. var imageCache = {};
  14962. assert(operatorList);
  14963. resources = (resources || Dict.empty);
  14964. var xobjs = (resources.get('XObject') || Dict.empty);
  14965. var patterns = (resources.get('Pattern') || Dict.empty);
  14966. var stateManager = new StateManager(initialState || new EvalState());
  14967. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  14968. var timeSlotManager = new TimeSlotManager();
  14969. return new Promise(function next(resolve, reject) {
  14970. timeSlotManager.reset();
  14971. var stop, operation = {}, i, ii, cs;
  14972. while (!(stop = timeSlotManager.check())) {
  14973. // The arguments parsed by read() are used beyond this loop, so we
  14974. // cannot reuse the same array on each iteration. Therefore we pass
  14975. // in |null| as the initial value (see the comment on
  14976. // EvaluatorPreprocessor_read() for why).
  14977. operation.args = null;
  14978. if (!(preprocessor.read(operation))) {
  14979. break;
  14980. }
  14981. var args = operation.args;
  14982. var fn = operation.fn;
  14983. switch (fn | 0) {
  14984. case OPS.paintXObject:
  14985. if (args[0].code) {
  14986. break;
  14987. }
  14988. // eagerly compile XForm objects
  14989. var name = args[0].name;
  14990. if (imageCache.key === name) {
  14991. operatorList.addOp(imageCache.fn, imageCache.args);
  14992. args = null;
  14993. continue;
  14994. }
  14995. var xobj = xobjs.get(name);
  14996. if (xobj) {
  14997. assert(isStream(xobj), 'XObject should be a stream');
  14998. var type = xobj.dict.get('Subtype');
  14999. assert(isName(type),
  15000. 'XObject should have a Name subtype');
  15001. if (type.name === 'Form') {
  15002. stateManager.save();
  15003. return self.buildFormXObject(resources, xobj, null,
  15004. operatorList,
  15005. stateManager.state.clone()).
  15006. then(function () {
  15007. stateManager.restore();
  15008. next(resolve, reject);
  15009. }, reject);
  15010. } else if (type.name === 'Image') {
  15011. self.buildPaintImageXObject(resources, xobj, false,
  15012. operatorList, name, imageCache);
  15013. args = null;
  15014. continue;
  15015. } else if (type.name === 'PS') {
  15016. // PostScript XObjects are unused when viewing documents.
  15017. // See section 4.7.1 of Adobe's PDF reference.
  15018. info('Ignored XObject subtype PS');
  15019. continue;
  15020. } else {
  15021. error('Unhandled XObject subtype ' + type.name);
  15022. }
  15023. }
  15024. break;
  15025. case OPS.setFont:
  15026. var fontSize = args[1];
  15027. // eagerly collect all fonts
  15028. return self.handleSetFont(resources, args, null,
  15029. operatorList, stateManager.state).
  15030. then(function (loadedName) {
  15031. operatorList.addDependency(loadedName);
  15032. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15033. next(resolve, reject);
  15034. }, reject);
  15035. case OPS.endInlineImage:
  15036. var cacheKey = args[0].cacheKey;
  15037. if (cacheKey && imageCache.key === cacheKey) {
  15038. operatorList.addOp(imageCache.fn, imageCache.args);
  15039. args = null;
  15040. continue;
  15041. }
  15042. self.buildPaintImageXObject(resources, args[0], true,
  15043. operatorList, cacheKey, imageCache);
  15044. args = null;
  15045. continue;
  15046. case OPS.showText:
  15047. args[0] = self.handleText(args[0], stateManager.state);
  15048. break;
  15049. case OPS.showSpacedText:
  15050. var arr = args[0];
  15051. var combinedGlyphs = [];
  15052. var arrLength = arr.length;
  15053. for (i = 0; i < arrLength; ++i) {
  15054. var arrItem = arr[i];
  15055. if (isString(arrItem)) {
  15056. Array.prototype.push.apply(combinedGlyphs,
  15057. self.handleText(arrItem, stateManager.state));
  15058. } else if (isNum(arrItem)) {
  15059. combinedGlyphs.push(arrItem);
  15060. }
  15061. }
  15062. args[0] = combinedGlyphs;
  15063. fn = OPS.showText;
  15064. break;
  15065. case OPS.nextLineShowText:
  15066. operatorList.addOp(OPS.nextLine);
  15067. args[0] = self.handleText(args[0], stateManager.state);
  15068. fn = OPS.showText;
  15069. break;
  15070. case OPS.nextLineSetSpacingShowText:
  15071. operatorList.addOp(OPS.nextLine);
  15072. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15073. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15074. args[0] = self.handleText(args[0], stateManager.state);
  15075. fn = OPS.showText;
  15076. break;
  15077. case OPS.setTextRenderingMode:
  15078. stateManager.state.textRenderingMode = args[0];
  15079. break;
  15080. case OPS.setFillColorSpace:
  15081. stateManager.state.fillColorSpace =
  15082. ColorSpace.parse(args[0], xref, resources);
  15083. continue;
  15084. case OPS.setStrokeColorSpace:
  15085. stateManager.state.strokeColorSpace =
  15086. ColorSpace.parse(args[0], xref, resources);
  15087. continue;
  15088. case OPS.setFillColor:
  15089. cs = stateManager.state.fillColorSpace;
  15090. args = cs.getRgb(args, 0);
  15091. fn = OPS.setFillRGBColor;
  15092. break;
  15093. case OPS.setStrokeColor:
  15094. cs = stateManager.state.strokeColorSpace;
  15095. args = cs.getRgb(args, 0);
  15096. fn = OPS.setStrokeRGBColor;
  15097. break;
  15098. case OPS.setFillGray:
  15099. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15100. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15101. fn = OPS.setFillRGBColor;
  15102. break;
  15103. case OPS.setStrokeGray:
  15104. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15105. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15106. fn = OPS.setStrokeRGBColor;
  15107. break;
  15108. case OPS.setFillCMYKColor:
  15109. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15110. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15111. fn = OPS.setFillRGBColor;
  15112. break;
  15113. case OPS.setStrokeCMYKColor:
  15114. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15115. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15116. fn = OPS.setStrokeRGBColor;
  15117. break;
  15118. case OPS.setFillRGBColor:
  15119. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15120. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15121. break;
  15122. case OPS.setStrokeRGBColor:
  15123. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15124. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15125. break;
  15126. case OPS.setFillColorN:
  15127. cs = stateManager.state.fillColorSpace;
  15128. if (cs.name === 'Pattern') {
  15129. return self.handleColorN(operatorList, OPS.setFillColorN,
  15130. args, cs, patterns, resources, xref).then(function() {
  15131. next(resolve, reject);
  15132. }, reject);
  15133. }
  15134. args = cs.getRgb(args, 0);
  15135. fn = OPS.setFillRGBColor;
  15136. break;
  15137. case OPS.setStrokeColorN:
  15138. cs = stateManager.state.strokeColorSpace;
  15139. if (cs.name === 'Pattern') {
  15140. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15141. args, cs, patterns, resources, xref).then(function() {
  15142. next(resolve, reject);
  15143. }, reject);
  15144. }
  15145. args = cs.getRgb(args, 0);
  15146. fn = OPS.setStrokeRGBColor;
  15147. break;
  15148. case OPS.shadingFill:
  15149. var shadingRes = resources.get('Shading');
  15150. if (!shadingRes) {
  15151. error('No shading resource found');
  15152. }
  15153. var shading = shadingRes.get(args[0].name);
  15154. if (!shading) {
  15155. error('No shading object found');
  15156. }
  15157. var shadingFill = Pattern.parseShading(shading, null, xref,
  15158. resources);
  15159. var patternIR = shadingFill.getIR();
  15160. args = [patternIR];
  15161. fn = OPS.shadingFill;
  15162. break;
  15163. case OPS.setGState:
  15164. var dictName = args[0];
  15165. var extGState = resources.get('ExtGState');
  15166. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15167. break;
  15168. }
  15169. var gState = extGState.get(dictName.name);
  15170. return self.setGState(resources, gState, operatorList, xref,
  15171. stateManager).then(function() {
  15172. next(resolve, reject);
  15173. }, reject);
  15174. case OPS.moveTo:
  15175. case OPS.lineTo:
  15176. case OPS.curveTo:
  15177. case OPS.curveTo2:
  15178. case OPS.curveTo3:
  15179. case OPS.closePath:
  15180. self.buildPath(operatorList, fn, args);
  15181. continue;
  15182. case OPS.rectangle:
  15183. self.buildPath(operatorList, fn, args);
  15184. continue;
  15185. }
  15186. operatorList.addOp(fn, args);
  15187. }
  15188. if (stop) {
  15189. deferred.then(function () {
  15190. next(resolve, reject);
  15191. });
  15192. return;
  15193. }
  15194. // Some PDFs don't close all restores inside object/form.
  15195. // Closing those for them.
  15196. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15197. operatorList.addOp(OPS.restore, []);
  15198. }
  15199. resolve();
  15200. });
  15201. },
  15202. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15203. stateManager) {
  15204. stateManager = (stateManager || new StateManager(new TextState()));
  15205. var textContent = {
  15206. items: [],
  15207. styles: Object.create(null)
  15208. };
  15209. var bidiTexts = textContent.items;
  15210. var SPACE_FACTOR = 0.35;
  15211. var MULTI_SPACE_FACTOR = 1.5;
  15212. var self = this;
  15213. var xref = this.xref;
  15214. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15215. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15216. var xobjs = null;
  15217. var xobjsCache = {};
  15218. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15219. var textState;
  15220. function newTextChunk() {
  15221. var font = textState.font;
  15222. if (!(font.loadedName in textContent.styles)) {
  15223. textContent.styles[font.loadedName] = {
  15224. fontFamily: font.fallbackName,
  15225. ascent: font.ascent,
  15226. descent: font.descent,
  15227. vertical: font.vertical
  15228. };
  15229. }
  15230. return {
  15231. // |str| is initially an array which we push individual chars to, and
  15232. // then runBidi() overwrites it with the final string.
  15233. str: [],
  15234. dir: null,
  15235. width: 0,
  15236. height: 0,
  15237. transform: null,
  15238. fontName: font.loadedName
  15239. };
  15240. }
  15241. function runBidi(textChunk) {
  15242. var str = textChunk.str.join('');
  15243. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  15244. textChunk.str = bidiResult.str;
  15245. textChunk.dir = bidiResult.dir;
  15246. return textChunk;
  15247. }
  15248. function handleSetFont(fontName, fontRef) {
  15249. return self.loadFont(fontName, fontRef, xref, resources).
  15250. then(function (translated) {
  15251. textState.font = translated.font;
  15252. textState.fontMatrix = translated.font.fontMatrix ||
  15253. FONT_IDENTITY_MATRIX;
  15254. });
  15255. }
  15256. function buildTextGeometry(chars, textChunk) {
  15257. var font = textState.font;
  15258. textChunk = textChunk || newTextChunk();
  15259. if (!textChunk.transform) {
  15260. // 9.4.4 Text Space Details
  15261. var tsm = [textState.fontSize * textState.textHScale, 0,
  15262. 0, textState.fontSize,
  15263. 0, textState.textRise];
  15264. var trm = textChunk.transform = Util.transform(textState.ctm,
  15265. Util.transform(textState.textMatrix, tsm));
  15266. if (!font.vertical) {
  15267. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  15268. } else {
  15269. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  15270. }
  15271. }
  15272. var width = 0;
  15273. var height = 0;
  15274. var glyphs = font.charsToGlyphs(chars);
  15275. var defaultVMetrics = font.defaultVMetrics;
  15276. for (var i = 0; i < glyphs.length; i++) {
  15277. var glyph = glyphs[i];
  15278. if (!glyph) { // Previous glyph was a space.
  15279. width += textState.wordSpacing * textState.textHScale;
  15280. continue;
  15281. }
  15282. var vMetricX = null;
  15283. var vMetricY = null;
  15284. var glyphWidth = null;
  15285. if (font.vertical) {
  15286. if (glyph.vmetric) {
  15287. glyphWidth = glyph.vmetric[0];
  15288. vMetricX = glyph.vmetric[1];
  15289. vMetricY = glyph.vmetric[2];
  15290. } else {
  15291. glyphWidth = glyph.width;
  15292. vMetricX = glyph.width * 0.5;
  15293. vMetricY = defaultVMetrics[2];
  15294. }
  15295. } else {
  15296. glyphWidth = glyph.width;
  15297. }
  15298. var glyphUnicode = glyph.unicode;
  15299. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  15300. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  15301. }
  15302. glyphUnicode = reverseIfRtl(glyphUnicode);
  15303. // The following will calculate the x and y of the individual glyphs.
  15304. // if (font.vertical) {
  15305. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  15306. // textState.fontMatrix[0];
  15307. // tsm[5] -= vMetricY * textState.fontSize *
  15308. // textState.fontMatrix[0];
  15309. // }
  15310. // var trm = Util.transform(textState.textMatrix, tsm);
  15311. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  15312. // var x = pt[0];
  15313. // var y = pt[1];
  15314. var tx = 0;
  15315. var ty = 0;
  15316. if (!font.vertical) {
  15317. var w0 = glyphWidth * textState.fontMatrix[0];
  15318. tx = (w0 * textState.fontSize + textState.charSpacing) *
  15319. textState.textHScale;
  15320. width += tx;
  15321. } else {
  15322. var w1 = glyphWidth * textState.fontMatrix[0];
  15323. ty = w1 * textState.fontSize + textState.charSpacing;
  15324. height += ty;
  15325. }
  15326. textState.translateTextMatrix(tx, ty);
  15327. textChunk.str.push(glyphUnicode);
  15328. }
  15329. var a = textState.textLineMatrix[0];
  15330. var b = textState.textLineMatrix[1];
  15331. var scaleLineX = Math.sqrt(a * a + b * b);
  15332. a = textState.ctm[0];
  15333. b = textState.ctm[1];
  15334. var scaleCtmX = Math.sqrt(a * a + b * b);
  15335. if (!font.vertical) {
  15336. textChunk.width += width * scaleCtmX * scaleLineX;
  15337. } else {
  15338. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  15339. }
  15340. return textChunk;
  15341. }
  15342. var timeSlotManager = new TimeSlotManager();
  15343. return new Promise(function next(resolve, reject) {
  15344. timeSlotManager.reset();
  15345. var stop, operation = {}, args = [];
  15346. while (!(stop = timeSlotManager.check())) {
  15347. // The arguments parsed by read() are not used beyond this loop, so
  15348. // we can reuse the same array on every iteration, thus avoiding
  15349. // unnecessary allocations.
  15350. args.length = 0;
  15351. operation.args = args;
  15352. if (!(preprocessor.read(operation))) {
  15353. break;
  15354. }
  15355. textState = stateManager.state;
  15356. var fn = operation.fn;
  15357. args = operation.args;
  15358. switch (fn | 0) {
  15359. case OPS.setFont:
  15360. textState.fontSize = args[1];
  15361. return handleSetFont(args[0].name).then(function() {
  15362. next(resolve, reject);
  15363. }, reject);
  15364. case OPS.setTextRise:
  15365. textState.textRise = args[0];
  15366. break;
  15367. case OPS.setHScale:
  15368. textState.textHScale = args[0] / 100;
  15369. break;
  15370. case OPS.setLeading:
  15371. textState.leading = args[0];
  15372. break;
  15373. case OPS.moveText:
  15374. textState.translateTextLineMatrix(args[0], args[1]);
  15375. textState.textMatrix = textState.textLineMatrix.slice();
  15376. break;
  15377. case OPS.setLeadingMoveText:
  15378. textState.leading = -args[1];
  15379. textState.translateTextLineMatrix(args[0], args[1]);
  15380. textState.textMatrix = textState.textLineMatrix.slice();
  15381. break;
  15382. case OPS.nextLine:
  15383. textState.carriageReturn();
  15384. break;
  15385. case OPS.setTextMatrix:
  15386. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  15387. args[4], args[5]);
  15388. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  15389. args[4], args[5]);
  15390. break;
  15391. case OPS.setCharSpacing:
  15392. textState.charSpacing = args[0];
  15393. break;
  15394. case OPS.setWordSpacing:
  15395. textState.wordSpacing = args[0];
  15396. break;
  15397. case OPS.beginText:
  15398. textState.textMatrix = IDENTITY_MATRIX.slice();
  15399. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  15400. break;
  15401. case OPS.showSpacedText:
  15402. var items = args[0];
  15403. var textChunk = newTextChunk();
  15404. var offset;
  15405. for (var j = 0, jj = items.length; j < jj; j++) {
  15406. if (typeof items[j] === 'string') {
  15407. buildTextGeometry(items[j], textChunk);
  15408. } else {
  15409. var val = items[j] / 1000;
  15410. if (!textState.font.vertical) {
  15411. offset = -val * textState.fontSize * textState.textHScale *
  15412. textState.textMatrix[0];
  15413. textState.translateTextMatrix(offset, 0);
  15414. textChunk.width += offset;
  15415. } else {
  15416. offset = -val * textState.fontSize *
  15417. textState.textMatrix[3];
  15418. textState.translateTextMatrix(0, offset);
  15419. textChunk.height += offset;
  15420. }
  15421. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  15422. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  15423. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  15424. fakeSpaces = Math.round(fakeSpaces);
  15425. while (fakeSpaces--) {
  15426. textChunk.str.push(' ');
  15427. }
  15428. } else if (fakeSpaces > SPACE_FACTOR) {
  15429. textChunk.str.push(' ');
  15430. }
  15431. }
  15432. }
  15433. }
  15434. bidiTexts.push(runBidi(textChunk));
  15435. break;
  15436. case OPS.showText:
  15437. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  15438. break;
  15439. case OPS.nextLineShowText:
  15440. textState.carriageReturn();
  15441. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  15442. break;
  15443. case OPS.nextLineSetSpacingShowText:
  15444. textState.wordSpacing = args[0];
  15445. textState.charSpacing = args[1];
  15446. textState.carriageReturn();
  15447. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  15448. break;
  15449. case OPS.paintXObject:
  15450. if (args[0].code) {
  15451. break;
  15452. }
  15453. if (!xobjs) {
  15454. xobjs = (resources.get('XObject') || Dict.empty);
  15455. }
  15456. var name = args[0].name;
  15457. if (xobjsCache.key === name) {
  15458. if (xobjsCache.texts) {
  15459. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  15460. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  15461. }
  15462. break;
  15463. }
  15464. var xobj = xobjs.get(name);
  15465. if (!xobj) {
  15466. break;
  15467. }
  15468. assert(isStream(xobj), 'XObject should be a stream');
  15469. var type = xobj.dict.get('Subtype');
  15470. assert(isName(type),
  15471. 'XObject should have a Name subtype');
  15472. if ('Form' !== type.name) {
  15473. xobjsCache.key = name;
  15474. xobjsCache.texts = null;
  15475. break;
  15476. }
  15477. stateManager.save();
  15478. var matrix = xobj.dict.get('Matrix');
  15479. if (isArray(matrix) && matrix.length === 6) {
  15480. stateManager.transform(matrix);
  15481. }
  15482. return self.getTextContent(xobj,
  15483. xobj.dict.get('Resources') || resources, stateManager).
  15484. then(function (formTextContent) {
  15485. Util.appendToArray(bidiTexts, formTextContent.items);
  15486. Util.extendObj(textContent.styles, formTextContent.styles);
  15487. stateManager.restore();
  15488. xobjsCache.key = name;
  15489. xobjsCache.texts = formTextContent;
  15490. next(resolve, reject);
  15491. }, reject);
  15492. case OPS.setGState:
  15493. var dictName = args[0];
  15494. var extGState = resources.get('ExtGState');
  15495. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15496. break;
  15497. }
  15498. var gsStateMap = extGState.get(dictName.name);
  15499. var gsStateFont = null;
  15500. for (var key in gsStateMap) {
  15501. if (key === 'Font') {
  15502. assert(!gsStateFont);
  15503. gsStateFont = gsStateMap[key];
  15504. }
  15505. }
  15506. if (gsStateFont) {
  15507. textState.fontSize = gsStateFont[1];
  15508. return handleSetFont(gsStateFont[0]).then(function() {
  15509. next(resolve, reject);
  15510. }, reject);
  15511. }
  15512. break;
  15513. } // switch
  15514. } // while
  15515. if (stop) {
  15516. deferred.then(function () {
  15517. next(resolve, reject);
  15518. });
  15519. return;
  15520. }
  15521. resolve(textContent);
  15522. });
  15523. },
  15524. extractDataStructures: function
  15525. partialEvaluatorExtractDataStructures(dict, baseDict,
  15526. xref, properties) {
  15527. // 9.10.2
  15528. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  15529. if (toUnicode) {
  15530. properties.toUnicode = this.readToUnicode(toUnicode);
  15531. }
  15532. if (properties.composite) {
  15533. // CIDSystemInfo helps to match CID to glyphs
  15534. var cidSystemInfo = dict.get('CIDSystemInfo');
  15535. if (isDict(cidSystemInfo)) {
  15536. properties.cidSystemInfo = {
  15537. registry: cidSystemInfo.get('Registry'),
  15538. ordering: cidSystemInfo.get('Ordering'),
  15539. supplement: cidSystemInfo.get('Supplement')
  15540. };
  15541. }
  15542. var cidToGidMap = dict.get('CIDToGIDMap');
  15543. if (isStream(cidToGidMap)) {
  15544. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  15545. }
  15546. }
  15547. // Based on 9.6.6 of the spec the encoding can come from multiple places
  15548. // and depends on the font type. The base encoding and differences are
  15549. // read here, but the encoding that is actually used is chosen during
  15550. // glyph mapping in the font.
  15551. // TODO: Loading the built in encoding in the font would allow the
  15552. // differences to be merged in here not require us to hold on to it.
  15553. var differences = [];
  15554. var baseEncodingName = null;
  15555. var encoding;
  15556. if (dict.has('Encoding')) {
  15557. encoding = dict.get('Encoding');
  15558. if (isDict(encoding)) {
  15559. baseEncodingName = encoding.get('BaseEncoding');
  15560. baseEncodingName = (isName(baseEncodingName) ?
  15561. baseEncodingName.name : null);
  15562. // Load the differences between the base and original
  15563. if (encoding.has('Differences')) {
  15564. var diffEncoding = encoding.get('Differences');
  15565. var index = 0;
  15566. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  15567. var data = diffEncoding[j];
  15568. if (isNum(data)) {
  15569. index = data;
  15570. } else {
  15571. differences[index++] = data.name;
  15572. }
  15573. }
  15574. }
  15575. } else if (isName(encoding)) {
  15576. baseEncodingName = encoding.name;
  15577. } else {
  15578. error('Encoding is not a Name nor a Dict');
  15579. }
  15580. // According to table 114 if the encoding is a named encoding it must be
  15581. // one of these predefined encodings.
  15582. if ((baseEncodingName !== 'MacRomanEncoding' &&
  15583. baseEncodingName !== 'MacExpertEncoding' &&
  15584. baseEncodingName !== 'WinAnsiEncoding')) {
  15585. baseEncodingName = null;
  15586. }
  15587. }
  15588. if (baseEncodingName) {
  15589. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  15590. } else {
  15591. encoding = (properties.type === 'TrueType' ?
  15592. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  15593. // The Symbolic attribute can be misused for regular fonts
  15594. // Heuristic: we have to check if the font is a standard one also
  15595. if (!!(properties.flags & FontFlags.Symbolic)) {
  15596. encoding = (!properties.file && /Symbol/i.test(properties.name) ?
  15597. Encodings.SymbolSetEncoding :
  15598. Encodings.MacRomanEncoding);
  15599. }
  15600. properties.defaultEncoding = encoding;
  15601. }
  15602. properties.differences = differences;
  15603. properties.baseEncodingName = baseEncodingName;
  15604. properties.dict = dict;
  15605. },
  15606. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  15607. var cmap, cmapObj = toUnicode;
  15608. if (isName(cmapObj)) {
  15609. cmap = CMapFactory.create(cmapObj,
  15610. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  15611. return new ToUnicodeMap(cmap);
  15612. } else if (isStream(cmapObj)) {
  15613. cmap = CMapFactory.create(cmapObj,
  15614. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  15615. // Convert UTF-16BE
  15616. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  15617. // to iterate over all keys.
  15618. cmap.forEach(function(token, i) {
  15619. var str = [];
  15620. for (var k = 0; k < token.length; k += 2) {
  15621. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  15622. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  15623. str.push(w1);
  15624. continue;
  15625. }
  15626. k += 2;
  15627. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  15628. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  15629. }
  15630. cmap[i] = String.fromCharCode.apply(String, str);
  15631. });
  15632. return new ToUnicodeMap(cmap);
  15633. }
  15634. return null;
  15635. },
  15636. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  15637. // Extract the encoding from the CIDToGIDMap
  15638. var glyphsData = cidToGidStream.getBytes();
  15639. // Set encoding 0 to later verify the font has an encoding
  15640. var result = [];
  15641. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  15642. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  15643. if (glyphID === 0) {
  15644. continue;
  15645. }
  15646. var code = j >> 1;
  15647. result[code] = glyphID;
  15648. }
  15649. return result;
  15650. },
  15651. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  15652. descriptor,
  15653. properties) {
  15654. var glyphsWidths = [];
  15655. var defaultWidth = 0;
  15656. var glyphsVMetrics = [];
  15657. var defaultVMetrics;
  15658. var i, ii, j, jj, start, code, widths;
  15659. if (properties.composite) {
  15660. defaultWidth = dict.get('DW') || 1000;
  15661. widths = dict.get('W');
  15662. if (widths) {
  15663. for (i = 0, ii = widths.length; i < ii; i++) {
  15664. start = widths[i++];
  15665. code = xref.fetchIfRef(widths[i]);
  15666. if (isArray(code)) {
  15667. for (j = 0, jj = code.length; j < jj; j++) {
  15668. glyphsWidths[start++] = code[j];
  15669. }
  15670. } else {
  15671. var width = widths[++i];
  15672. for (j = start; j <= code; j++) {
  15673. glyphsWidths[j] = width;
  15674. }
  15675. }
  15676. }
  15677. }
  15678. if (properties.vertical) {
  15679. var vmetrics = (dict.get('DW2') || [880, -1000]);
  15680. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  15681. vmetrics = dict.get('W2');
  15682. if (vmetrics) {
  15683. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  15684. start = vmetrics[i++];
  15685. code = xref.fetchIfRef(vmetrics[i]);
  15686. if (isArray(code)) {
  15687. for (j = 0, jj = code.length; j < jj; j++) {
  15688. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  15689. }
  15690. } else {
  15691. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  15692. for (j = start; j <= code; j++) {
  15693. glyphsVMetrics[j] = vmetric;
  15694. }
  15695. }
  15696. }
  15697. }
  15698. }
  15699. } else {
  15700. var firstChar = properties.firstChar;
  15701. widths = dict.get('Widths');
  15702. if (widths) {
  15703. j = firstChar;
  15704. for (i = 0, ii = widths.length; i < ii; i++) {
  15705. glyphsWidths[j++] = widths[i];
  15706. }
  15707. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  15708. } else {
  15709. // Trying get the BaseFont metrics (see comment above).
  15710. var baseFontName = dict.get('BaseFont');
  15711. if (isName(baseFontName)) {
  15712. var metrics = this.getBaseFontMetrics(baseFontName.name);
  15713. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  15714. properties);
  15715. defaultWidth = metrics.defaultWidth;
  15716. }
  15717. }
  15718. }
  15719. // Heuristic: detection of monospace font by checking all non-zero widths
  15720. var isMonospace = true;
  15721. var firstWidth = defaultWidth;
  15722. for (var glyph in glyphsWidths) {
  15723. var glyphWidth = glyphsWidths[glyph];
  15724. if (!glyphWidth) {
  15725. continue;
  15726. }
  15727. if (!firstWidth) {
  15728. firstWidth = glyphWidth;
  15729. continue;
  15730. }
  15731. if (firstWidth !== glyphWidth) {
  15732. isMonospace = false;
  15733. break;
  15734. }
  15735. }
  15736. if (isMonospace) {
  15737. properties.flags |= FontFlags.FixedPitch;
  15738. }
  15739. properties.defaultWidth = defaultWidth;
  15740. properties.widths = glyphsWidths;
  15741. properties.defaultVMetrics = defaultVMetrics;
  15742. properties.vmetrics = glyphsVMetrics;
  15743. },
  15744. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  15745. // Simulating descriptor flags attribute
  15746. var fontNameWoStyle = baseFontName.split('-')[0];
  15747. return (fontNameWoStyle in serifFonts) ||
  15748. (fontNameWoStyle.search(/serif/gi) !== -1);
  15749. },
  15750. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  15751. var defaultWidth = 0;
  15752. var widths = [];
  15753. var monospace = false;
  15754. var lookupName = (stdFontMap[name] || name);
  15755. if (!(lookupName in Metrics)) {
  15756. // Use default fonts for looking up font metrics if the passed
  15757. // font is not a base font
  15758. if (this.isSerifFont(name)) {
  15759. lookupName = 'Times-Roman';
  15760. } else {
  15761. lookupName = 'Helvetica';
  15762. }
  15763. }
  15764. var glyphWidths = Metrics[lookupName];
  15765. if (isNum(glyphWidths)) {
  15766. defaultWidth = glyphWidths;
  15767. monospace = true;
  15768. } else {
  15769. widths = glyphWidths;
  15770. }
  15771. return {
  15772. defaultWidth: defaultWidth,
  15773. monospace: monospace,
  15774. widths: widths
  15775. };
  15776. },
  15777. buildCharCodeToWidth:
  15778. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  15779. properties) {
  15780. var widths = Object.create(null);
  15781. var differences = properties.differences;
  15782. var encoding = properties.defaultEncoding;
  15783. for (var charCode = 0; charCode < 256; charCode++) {
  15784. if (charCode in differences &&
  15785. widthsByGlyphName[differences[charCode]]) {
  15786. widths[charCode] = widthsByGlyphName[differences[charCode]];
  15787. continue;
  15788. }
  15789. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  15790. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  15791. continue;
  15792. }
  15793. }
  15794. return widths;
  15795. },
  15796. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  15797. var baseDict = dict;
  15798. var type = dict.get('Subtype');
  15799. assert(isName(type), 'invalid font Subtype');
  15800. var composite = false;
  15801. var uint8array;
  15802. if (type.name === 'Type0') {
  15803. // If font is a composite
  15804. // - get the descendant font
  15805. // - set the type according to the descendant font
  15806. // - get the FontDescriptor from the descendant font
  15807. var df = dict.get('DescendantFonts');
  15808. if (!df) {
  15809. error('Descendant fonts are not specified');
  15810. }
  15811. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  15812. type = dict.get('Subtype');
  15813. assert(isName(type), 'invalid font Subtype');
  15814. composite = true;
  15815. }
  15816. var descriptor = dict.get('FontDescriptor');
  15817. if (descriptor) {
  15818. var hash = new MurmurHash3_64();
  15819. var encoding = baseDict.getRaw('Encoding');
  15820. if (isName(encoding)) {
  15821. hash.update(encoding.name);
  15822. } else if (isRef(encoding)) {
  15823. hash.update(encoding.num + '_' + encoding.gen);
  15824. }
  15825. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  15826. if (isStream(toUnicode)) {
  15827. var stream = toUnicode.str || toUnicode;
  15828. uint8array = stream.buffer ?
  15829. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  15830. new Uint8Array(stream.bytes.buffer,
  15831. stream.start, stream.end - stream.start);
  15832. hash.update(uint8array);
  15833. } else if (isName(toUnicode)) {
  15834. hash.update(toUnicode.name);
  15835. }
  15836. var widths = dict.get('Widths') || baseDict.get('Widths');
  15837. if (widths) {
  15838. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  15839. hash.update(uint8array);
  15840. }
  15841. }
  15842. return {
  15843. descriptor: descriptor,
  15844. dict: dict,
  15845. baseDict: baseDict,
  15846. composite: composite,
  15847. type: type.name,
  15848. hash: hash ? hash.hexdigest() : ''
  15849. };
  15850. },
  15851. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  15852. xref) {
  15853. var baseDict = preEvaluatedFont.baseDict;
  15854. var dict = preEvaluatedFont.dict;
  15855. var composite = preEvaluatedFont.composite;
  15856. var descriptor = preEvaluatedFont.descriptor;
  15857. var type = preEvaluatedFont.type;
  15858. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  15859. var properties;
  15860. if (!descriptor) {
  15861. if (type === 'Type3') {
  15862. // FontDescriptor is only required for Type3 fonts when the document
  15863. // is a tagged pdf. Create a barbebones one to get by.
  15864. descriptor = new Dict(null);
  15865. descriptor.set('FontName', Name.get(type));
  15866. } else {
  15867. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  15868. // FontDescriptor was not required.
  15869. // This case is here for compatibility.
  15870. var baseFontName = dict.get('BaseFont');
  15871. if (!isName(baseFontName)) {
  15872. error('Base font is not specified');
  15873. }
  15874. // Using base font name as a font name.
  15875. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  15876. var metrics = this.getBaseFontMetrics(baseFontName);
  15877. // Simulating descriptor flags attribute
  15878. var fontNameWoStyle = baseFontName.split('-')[0];
  15879. var flags =
  15880. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  15881. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  15882. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  15883. FontFlags.Nonsymbolic);
  15884. properties = {
  15885. type: type,
  15886. name: baseFontName,
  15887. widths: metrics.widths,
  15888. defaultWidth: metrics.defaultWidth,
  15889. flags: flags,
  15890. firstChar: 0,
  15891. lastChar: maxCharIndex
  15892. };
  15893. this.extractDataStructures(dict, dict, xref, properties);
  15894. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  15895. properties);
  15896. return new Font(baseFontName, null, properties);
  15897. }
  15898. }
  15899. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  15900. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  15901. // to ignore this rule when a variant of a standart font is used.
  15902. // TODO Fill the width array depending on which of the base font this is
  15903. // a variant.
  15904. var firstChar = (dict.get('FirstChar') || 0);
  15905. var lastChar = (dict.get('LastChar') || maxCharIndex);
  15906. var fontName = descriptor.get('FontName');
  15907. var baseFont = dict.get('BaseFont');
  15908. // Some bad PDFs have a string as the font name.
  15909. if (isString(fontName)) {
  15910. fontName = Name.get(fontName);
  15911. }
  15912. if (isString(baseFont)) {
  15913. baseFont = Name.get(baseFont);
  15914. }
  15915. if (type !== 'Type3') {
  15916. var fontNameStr = fontName && fontName.name;
  15917. var baseFontStr = baseFont && baseFont.name;
  15918. if (fontNameStr !== baseFontStr) {
  15919. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  15920. '" but should be the same as the Font\'s BaseFont "' +
  15921. baseFontStr + '"');
  15922. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  15923. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  15924. if (fontNameStr && baseFontStr &&
  15925. baseFontStr.indexOf(fontNameStr) === 0) {
  15926. fontName = baseFont;
  15927. }
  15928. }
  15929. }
  15930. fontName = (fontName || baseFont);
  15931. assert(isName(fontName), 'invalid font name');
  15932. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  15933. if (fontFile) {
  15934. if (fontFile.dict) {
  15935. var subtype = fontFile.dict.get('Subtype');
  15936. if (subtype) {
  15937. subtype = subtype.name;
  15938. }
  15939. var length1 = fontFile.dict.get('Length1');
  15940. var length2 = fontFile.dict.get('Length2');
  15941. }
  15942. }
  15943. properties = {
  15944. type: type,
  15945. name: fontName.name,
  15946. subtype: subtype,
  15947. file: fontFile,
  15948. length1: length1,
  15949. length2: length2,
  15950. loadedName: baseDict.loadedName,
  15951. composite: composite,
  15952. wideChars: composite,
  15953. fixedPitch: false,
  15954. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  15955. firstChar: firstChar || 0,
  15956. lastChar: (lastChar || maxCharIndex),
  15957. bbox: descriptor.get('FontBBox'),
  15958. ascent: descriptor.get('Ascent'),
  15959. descent: descriptor.get('Descent'),
  15960. xHeight: descriptor.get('XHeight'),
  15961. capHeight: descriptor.get('CapHeight'),
  15962. flags: descriptor.get('Flags'),
  15963. italicAngle: descriptor.get('ItalicAngle'),
  15964. coded: false
  15965. };
  15966. if (composite) {
  15967. var cidEncoding = baseDict.get('Encoding');
  15968. if (isName(cidEncoding)) {
  15969. properties.cidEncoding = cidEncoding.name;
  15970. }
  15971. properties.cMap = CMapFactory.create(cidEncoding,
  15972. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  15973. properties.vertical = properties.cMap.vertical;
  15974. }
  15975. this.extractDataStructures(dict, baseDict, xref, properties);
  15976. this.extractWidths(dict, xref, descriptor, properties);
  15977. if (type === 'Type3') {
  15978. properties.isType3Font = true;
  15979. }
  15980. return new Font(fontName.name, fontFile, properties);
  15981. }
  15982. };
  15983. return PartialEvaluator;
  15984. })();
  15985. var TranslatedFont = (function TranslatedFontClosure() {
  15986. function TranslatedFont(loadedName, font, dict) {
  15987. this.loadedName = loadedName;
  15988. this.font = font;
  15989. this.dict = dict;
  15990. this.type3Loaded = null;
  15991. this.sent = false;
  15992. }
  15993. TranslatedFont.prototype = {
  15994. send: function (handler) {
  15995. if (this.sent) {
  15996. return;
  15997. }
  15998. var fontData = this.font.exportData();
  15999. handler.send('commonobj', [
  16000. this.loadedName,
  16001. 'Font',
  16002. fontData
  16003. ]);
  16004. this.sent = true;
  16005. },
  16006. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16007. assert(this.font.isType3Font);
  16008. if (this.type3Loaded) {
  16009. return this.type3Loaded;
  16010. }
  16011. var translatedFont = this.font;
  16012. var loadCharProcsPromise = Promise.resolve();
  16013. var charProcs = this.dict.get('CharProcs').getAll();
  16014. var fontResources = this.dict.get('Resources') || resources;
  16015. var charProcKeys = Object.keys(charProcs);
  16016. var charProcOperatorList = {};
  16017. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16018. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16019. var glyphStream = charProcs[key];
  16020. var operatorList = new OperatorList();
  16021. return evaluator.getOperatorList(glyphStream, fontResources,
  16022. operatorList).then(function () {
  16023. charProcOperatorList[key] = operatorList.getIR();
  16024. // Add the dependencies to the parent operator list so they are
  16025. // resolved before sub operator list is executed synchronously.
  16026. parentOperatorList.addDependencies(operatorList.dependencies);
  16027. }, function (reason) {
  16028. warn('Type3 font resource \"' + key + '\" is not available');
  16029. var operatorList = new OperatorList();
  16030. charProcOperatorList[key] = operatorList.getIR();
  16031. });
  16032. }.bind(this, charProcKeys[i]));
  16033. }
  16034. this.type3Loaded = loadCharProcsPromise.then(function () {
  16035. translatedFont.charProcOperatorList = charProcOperatorList;
  16036. });
  16037. return this.type3Loaded;
  16038. }
  16039. };
  16040. return TranslatedFont;
  16041. })();
  16042. var OperatorList = (function OperatorListClosure() {
  16043. var CHUNK_SIZE = 1000;
  16044. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16045. function getTransfers(queue) {
  16046. var transfers = [];
  16047. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16048. for (var i = 0, ii = queue.length; i < ii; i++) {
  16049. switch (fnArray[i]) {
  16050. case OPS.paintInlineImageXObject:
  16051. case OPS.paintInlineImageXObjectGroup:
  16052. case OPS.paintImageMaskXObject:
  16053. var arg = argsArray[i][0]; // first param in imgData
  16054. if (!arg.cached) {
  16055. transfers.push(arg.data.buffer);
  16056. }
  16057. break;
  16058. }
  16059. }
  16060. return transfers;
  16061. }
  16062. function OperatorList(intent, messageHandler, pageIndex) {
  16063. this.messageHandler = messageHandler;
  16064. this.fnArray = [];
  16065. this.argsArray = [];
  16066. this.dependencies = {};
  16067. this.pageIndex = pageIndex;
  16068. this.intent = intent;
  16069. }
  16070. OperatorList.prototype = {
  16071. get length() {
  16072. return this.argsArray.length;
  16073. },
  16074. addOp: function(fn, args) {
  16075. this.fnArray.push(fn);
  16076. this.argsArray.push(args);
  16077. if (this.messageHandler) {
  16078. if (this.fnArray.length >= CHUNK_SIZE) {
  16079. this.flush();
  16080. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16081. (fn === OPS.restore || fn === OPS.endText)) {
  16082. // heuristic to flush on boundary of restore or endText
  16083. this.flush();
  16084. }
  16085. }
  16086. },
  16087. addDependency: function(dependency) {
  16088. if (dependency in this.dependencies) {
  16089. return;
  16090. }
  16091. this.dependencies[dependency] = true;
  16092. this.addOp(OPS.dependency, [dependency]);
  16093. },
  16094. addDependencies: function(dependencies) {
  16095. for (var key in dependencies) {
  16096. this.addDependency(key);
  16097. }
  16098. },
  16099. addOpList: function(opList) {
  16100. Util.extendObj(this.dependencies, opList.dependencies);
  16101. for (var i = 0, ii = opList.length; i < ii; i++) {
  16102. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16103. }
  16104. },
  16105. getIR: function() {
  16106. return {
  16107. fnArray: this.fnArray,
  16108. argsArray: this.argsArray,
  16109. length: this.length
  16110. };
  16111. },
  16112. flush: function(lastChunk) {
  16113. if (this.intent !== 'oplist') {
  16114. new QueueOptimizer().optimize(this);
  16115. }
  16116. var transfers = getTransfers(this);
  16117. this.messageHandler.send('RenderPageChunk', {
  16118. operatorList: {
  16119. fnArray: this.fnArray,
  16120. argsArray: this.argsArray,
  16121. lastChunk: lastChunk,
  16122. length: this.length
  16123. },
  16124. pageIndex: this.pageIndex,
  16125. intent: this.intent
  16126. }, transfers);
  16127. this.dependencies = {};
  16128. this.fnArray.length = 0;
  16129. this.argsArray.length = 0;
  16130. }
  16131. };
  16132. return OperatorList;
  16133. })();
  16134. var StateManager = (function StateManagerClosure() {
  16135. function StateManager(initialState) {
  16136. this.state = initialState;
  16137. this.stateStack = [];
  16138. }
  16139. StateManager.prototype = {
  16140. save: function () {
  16141. var old = this.state;
  16142. this.stateStack.push(this.state);
  16143. this.state = old.clone();
  16144. },
  16145. restore: function () {
  16146. var prev = this.stateStack.pop();
  16147. if (prev) {
  16148. this.state = prev;
  16149. }
  16150. },
  16151. transform: function (args) {
  16152. this.state.ctm = Util.transform(this.state.ctm, args);
  16153. }
  16154. };
  16155. return StateManager;
  16156. })();
  16157. var TextState = (function TextStateClosure() {
  16158. function TextState() {
  16159. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16160. this.fontSize = 0;
  16161. this.font = null;
  16162. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16163. this.textMatrix = IDENTITY_MATRIX.slice();
  16164. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16165. this.charSpacing = 0;
  16166. this.wordSpacing = 0;
  16167. this.leading = 0;
  16168. this.textHScale = 1;
  16169. this.textRise = 0;
  16170. }
  16171. TextState.prototype = {
  16172. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16173. var m = this.textMatrix;
  16174. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16175. },
  16176. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16177. var m = this.textLineMatrix;
  16178. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16179. },
  16180. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16181. var m = this.textMatrix;
  16182. m[4] = m[0] * x + m[2] * y + m[4];
  16183. m[5] = m[1] * x + m[3] * y + m[5];
  16184. },
  16185. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16186. var m = this.textLineMatrix;
  16187. m[4] = m[0] * x + m[2] * y + m[4];
  16188. m[5] = m[1] * x + m[3] * y + m[5];
  16189. },
  16190. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16191. // 9.4.4 Text Space Details
  16192. var tsm = [this.fontSize * this.textHScale, 0,
  16193. 0, this.fontSize,
  16194. 0, this.textRise];
  16195. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16196. },
  16197. carriageReturn: function TextState_carriageReturn() {
  16198. this.translateTextLineMatrix(0, -this.leading);
  16199. this.textMatrix = this.textLineMatrix.slice();
  16200. },
  16201. clone: function TextState_clone() {
  16202. var clone = Object.create(this);
  16203. clone.textMatrix = this.textMatrix.slice();
  16204. clone.textLineMatrix = this.textLineMatrix.slice();
  16205. clone.fontMatrix = this.fontMatrix.slice();
  16206. return clone;
  16207. }
  16208. };
  16209. return TextState;
  16210. })();
  16211. var EvalState = (function EvalStateClosure() {
  16212. function EvalState() {
  16213. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16214. this.font = null;
  16215. this.textRenderingMode = TextRenderingMode.FILL;
  16216. this.fillColorSpace = ColorSpace.singletons.gray;
  16217. this.strokeColorSpace = ColorSpace.singletons.gray;
  16218. }
  16219. EvalState.prototype = {
  16220. clone: function CanvasExtraState_clone() {
  16221. return Object.create(this);
  16222. },
  16223. };
  16224. return EvalState;
  16225. })();
  16226. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  16227. // Specifies properties for each command
  16228. //
  16229. // If variableArgs === true: [0, `numArgs`] expected
  16230. // If variableArgs === false: exactly `numArgs` expected
  16231. var OP_MAP = {
  16232. // Graphic state
  16233. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  16234. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  16235. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  16236. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  16237. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  16238. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  16239. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  16240. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  16241. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  16242. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  16243. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  16244. // Path
  16245. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  16246. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  16247. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  16248. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  16249. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  16250. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  16251. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  16252. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  16253. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  16254. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  16255. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  16256. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  16257. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  16258. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  16259. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  16260. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  16261. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  16262. // Clipping
  16263. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  16264. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  16265. // Text
  16266. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  16267. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  16268. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  16269. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  16270. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  16271. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  16272. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  16273. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  16274. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  16275. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  16276. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  16277. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  16278. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  16279. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  16280. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  16281. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  16282. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  16283. variableArgs: false },
  16284. // Type3 fonts
  16285. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  16286. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  16287. // Color
  16288. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  16289. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  16290. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  16291. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  16292. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  16293. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  16294. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  16295. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  16296. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  16297. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  16298. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  16299. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  16300. // Shading
  16301. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  16302. // Images
  16303. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  16304. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  16305. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  16306. // XObjects
  16307. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  16308. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  16309. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  16310. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  16311. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  16312. variableArgs: false },
  16313. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  16314. // Compatibility
  16315. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  16316. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  16317. // (reserved partial commands for the lexer)
  16318. BM: null,
  16319. BD: null,
  16320. 'true': null,
  16321. fa: null,
  16322. fal: null,
  16323. fals: null,
  16324. 'false': null,
  16325. nu: null,
  16326. nul: null,
  16327. 'null': null
  16328. };
  16329. function EvaluatorPreprocessor(stream, xref, stateManager) {
  16330. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  16331. // dictionary
  16332. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  16333. this.stateManager = stateManager;
  16334. this.nonProcessedArgs = [];
  16335. }
  16336. EvaluatorPreprocessor.prototype = {
  16337. get savedStatesDepth() {
  16338. return this.stateManager.stateStack.length;
  16339. },
  16340. // |operation| is an object with two fields:
  16341. //
  16342. // - |fn| is an out param.
  16343. //
  16344. // - |args| is an inout param. On entry, it should have one of two values.
  16345. //
  16346. // - An empty array. This indicates that the caller is providing the
  16347. // array in which the args will be stored in. The caller should use
  16348. // this value if it can reuse a single array for each call to read().
  16349. //
  16350. // - |null|. This indicates that the caller needs this function to create
  16351. // the array in which any args are stored in. If there are zero args,
  16352. // this function will leave |operation.args| as |null| (thus avoiding
  16353. // allocations that would occur if we used an empty array to represent
  16354. // zero arguments). Otherwise, it will replace |null| with a new array
  16355. // containing the arguments. The caller should use this value if it
  16356. // cannot reuse an array for each call to read().
  16357. //
  16358. // These two modes are present because this function is very hot and so
  16359. // avoiding allocations where possible is worthwhile.
  16360. //
  16361. read: function EvaluatorPreprocessor_read(operation) {
  16362. var args = operation.args;
  16363. while (true) {
  16364. var obj = this.parser.getObj();
  16365. if (isCmd(obj)) {
  16366. var cmd = obj.cmd;
  16367. // Check that the command is valid
  16368. var opSpec = OP_MAP[cmd];
  16369. if (!opSpec) {
  16370. warn('Unknown command "' + cmd + '"');
  16371. continue;
  16372. }
  16373. var fn = opSpec.id;
  16374. var numArgs = opSpec.numArgs;
  16375. var argsLength = args !== null ? args.length : 0;
  16376. if (!opSpec.variableArgs) {
  16377. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  16378. if (argsLength !== numArgs) {
  16379. var nonProcessedArgs = this.nonProcessedArgs;
  16380. while (argsLength > numArgs) {
  16381. nonProcessedArgs.push(args.shift());
  16382. argsLength--;
  16383. }
  16384. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  16385. if (!args) {
  16386. args = [];
  16387. }
  16388. args.unshift(nonProcessedArgs.pop());
  16389. argsLength++;
  16390. }
  16391. }
  16392. if (argsLength < numArgs) {
  16393. // If we receive too few args, it's not possible to possible
  16394. // to execute the command, so skip the command
  16395. info('Command ' + fn + ': because expected ' +
  16396. numArgs + ' args, but received ' + argsLength +
  16397. ' args; skipping');
  16398. args = null;
  16399. continue;
  16400. }
  16401. } else if (argsLength > numArgs) {
  16402. info('Command ' + fn + ': expected [0,' + numArgs +
  16403. '] args, but received ' + argsLength + ' args');
  16404. }
  16405. // TODO figure out how to type-check vararg functions
  16406. this.preprocessCommand(fn, args);
  16407. operation.fn = fn;
  16408. operation.args = args;
  16409. return true;
  16410. } else {
  16411. if (isEOF(obj)) {
  16412. return false; // no more commands
  16413. }
  16414. // argument
  16415. if (obj !== null) {
  16416. if (!args) {
  16417. args = [];
  16418. }
  16419. args.push((obj instanceof Dict ? obj.getAll() : obj));
  16420. assert(args.length <= 33, 'Too many arguments');
  16421. }
  16422. }
  16423. }
  16424. },
  16425. preprocessCommand:
  16426. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  16427. switch (fn | 0) {
  16428. case OPS.save:
  16429. this.stateManager.save();
  16430. break;
  16431. case OPS.restore:
  16432. this.stateManager.restore();
  16433. break;
  16434. case OPS.transform:
  16435. this.stateManager.transform(args);
  16436. break;
  16437. }
  16438. }
  16439. };
  16440. return EvaluatorPreprocessor;
  16441. })();
  16442. var QueueOptimizer = (function QueueOptimizerClosure() {
  16443. function addState(parentState, pattern, fn) {
  16444. var state = parentState;
  16445. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  16446. var item = pattern[i];
  16447. state = (state[item] || (state[item] = []));
  16448. }
  16449. state[pattern[pattern.length - 1]] = fn;
  16450. }
  16451. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  16452. argsArray) {
  16453. // Handles special case of mainly LaTeX documents which use image masks to
  16454. // draw lines with the current fill style.
  16455. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  16456. // have been found at iFirstSave.
  16457. var iFirstPIMXO = iFirstSave + 2;
  16458. for (var i = 0; i < count; i++) {
  16459. var arg = argsArray[iFirstPIMXO + 4 * i];
  16460. var imageMask = arg.length === 1 && arg[0];
  16461. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  16462. (!imageMask.data.length ||
  16463. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  16464. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  16465. continue;
  16466. }
  16467. break;
  16468. }
  16469. return count - i;
  16470. }
  16471. var InitialState = [];
  16472. // This replaces (save, transform, paintInlineImageXObject, restore)+
  16473. // sequences with one |paintInlineImageXObjectGroup| operation.
  16474. addState(InitialState,
  16475. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  16476. function foundInlineImageGroup(context) {
  16477. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  16478. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  16479. var MAX_WIDTH = 1000;
  16480. var IMAGE_PADDING = 1;
  16481. var fnArray = context.fnArray, argsArray = context.argsArray;
  16482. var curr = context.iCurr;
  16483. var iFirstSave = curr - 3;
  16484. var iFirstTransform = curr - 2;
  16485. var iFirstPIIXO = curr - 1;
  16486. // Look for the quartets.
  16487. var i = iFirstSave + 4;
  16488. var ii = fnArray.length;
  16489. while (i + 3 < ii) {
  16490. if (fnArray[i] !== OPS.save ||
  16491. fnArray[i + 1] !== OPS.transform ||
  16492. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  16493. fnArray[i + 3] !== OPS.restore) {
  16494. break; // ops don't match
  16495. }
  16496. i += 4;
  16497. }
  16498. // At this point, i is the index of the first op past the last valid
  16499. // quartet.
  16500. var count = Math.min((i - iFirstSave) / 4,
  16501. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  16502. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  16503. return i;
  16504. }
  16505. // assuming that heights of those image is too small (~1 pixel)
  16506. // packing as much as possible by lines
  16507. var maxX = 0;
  16508. var map = [], maxLineHeight = 0;
  16509. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  16510. var q;
  16511. for (q = 0; q < count; q++) {
  16512. var transform = argsArray[iFirstTransform + (q << 2)];
  16513. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  16514. if (currentX + img.width > MAX_WIDTH) {
  16515. // starting new line
  16516. maxX = Math.max(maxX, currentX);
  16517. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  16518. currentX = 0;
  16519. maxLineHeight = 0;
  16520. }
  16521. map.push({
  16522. transform: transform,
  16523. x: currentX, y: currentY,
  16524. w: img.width, h: img.height
  16525. });
  16526. currentX += img.width + 2 * IMAGE_PADDING;
  16527. maxLineHeight = Math.max(maxLineHeight, img.height);
  16528. }
  16529. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  16530. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  16531. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  16532. var imgRowSize = imgWidth << 2;
  16533. for (q = 0; q < count; q++) {
  16534. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  16535. // Copy image by lines and extends pixels into padding.
  16536. var rowSize = map[q].w << 2;
  16537. var dataOffset = 0;
  16538. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  16539. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  16540. for (var k = 0, kk = map[q].h; k < kk; k++) {
  16541. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  16542. dataOffset += rowSize;
  16543. offset += imgRowSize;
  16544. }
  16545. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  16546. while (offset >= 0) {
  16547. data[offset - 4] = data[offset];
  16548. data[offset - 3] = data[offset + 1];
  16549. data[offset - 2] = data[offset + 2];
  16550. data[offset - 1] = data[offset + 3];
  16551. data[offset + rowSize] = data[offset + rowSize - 4];
  16552. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  16553. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  16554. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  16555. offset -= imgRowSize;
  16556. }
  16557. }
  16558. // Replace queue items.
  16559. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  16560. argsArray.splice(iFirstSave, count * 4,
  16561. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  16562. data: imgData }, map]);
  16563. return iFirstSave + 1;
  16564. });
  16565. // This replaces (save, transform, paintImageMaskXObject, restore)+
  16566. // sequences with one |paintImageMaskXObjectGroup| or one
  16567. // |paintImageMaskXObjectRepeat| operation.
  16568. addState(InitialState,
  16569. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  16570. function foundImageMaskGroup(context) {
  16571. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  16572. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  16573. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  16574. var fnArray = context.fnArray, argsArray = context.argsArray;
  16575. var curr = context.iCurr;
  16576. var iFirstSave = curr - 3;
  16577. var iFirstTransform = curr - 2;
  16578. var iFirstPIMXO = curr - 1;
  16579. // Look for the quartets.
  16580. var i = iFirstSave + 4;
  16581. var ii = fnArray.length;
  16582. while (i + 3 < ii) {
  16583. if (fnArray[i] !== OPS.save ||
  16584. fnArray[i + 1] !== OPS.transform ||
  16585. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  16586. fnArray[i + 3] !== OPS.restore) {
  16587. break; // ops don't match
  16588. }
  16589. i += 4;
  16590. }
  16591. // At this point, i is the index of the first op past the last valid
  16592. // quartet.
  16593. var count = (i - iFirstSave) / 4;
  16594. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  16595. argsArray);
  16596. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  16597. return i;
  16598. }
  16599. var q;
  16600. var isSameImage = false;
  16601. var iTransform, transformArgs;
  16602. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  16603. if (argsArray[iFirstTransform][1] === 0 &&
  16604. argsArray[iFirstTransform][2] === 0) {
  16605. isSameImage = true;
  16606. var firstTransformArg0 = argsArray[iFirstTransform][0];
  16607. var firstTransformArg3 = argsArray[iFirstTransform][3];
  16608. iTransform = iFirstTransform + 4;
  16609. var iPIMXO = iFirstPIMXO + 4;
  16610. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  16611. transformArgs = argsArray[iTransform];
  16612. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  16613. transformArgs[0] !== firstTransformArg0 ||
  16614. transformArgs[1] !== 0 ||
  16615. transformArgs[2] !== 0 ||
  16616. transformArgs[3] !== firstTransformArg3) {
  16617. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  16618. isSameImage = false;
  16619. } else {
  16620. count = q;
  16621. }
  16622. break; // different image or transform
  16623. }
  16624. }
  16625. }
  16626. if (isSameImage) {
  16627. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  16628. var positions = new Float32Array(count * 2);
  16629. iTransform = iFirstTransform;
  16630. for (q = 0; q < count; q++, iTransform += 4) {
  16631. transformArgs = argsArray[iTransform];
  16632. positions[(q << 1)] = transformArgs[4];
  16633. positions[(q << 1) + 1] = transformArgs[5];
  16634. }
  16635. // Replace queue items.
  16636. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  16637. argsArray.splice(iFirstSave, count * 4,
  16638. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  16639. } else {
  16640. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  16641. var images = [];
  16642. for (q = 0; q < count; q++) {
  16643. transformArgs = argsArray[iFirstTransform + (q << 2)];
  16644. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  16645. images.push({ data: maskParams.data, width: maskParams.width,
  16646. height: maskParams.height,
  16647. transform: transformArgs });
  16648. }
  16649. // Replace queue items.
  16650. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  16651. argsArray.splice(iFirstSave, count * 4, [images]);
  16652. }
  16653. return iFirstSave + 1;
  16654. });
  16655. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  16656. // with one paintImageXObjectRepeat operation, if the |transform| and
  16657. // |paintImageXObjectRepeat| ops are appropriate.
  16658. addState(InitialState,
  16659. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  16660. function (context) {
  16661. var MIN_IMAGES_IN_BLOCK = 3;
  16662. var MAX_IMAGES_IN_BLOCK = 1000;
  16663. var fnArray = context.fnArray, argsArray = context.argsArray;
  16664. var curr = context.iCurr;
  16665. var iFirstSave = curr - 3;
  16666. var iFirstTransform = curr - 2;
  16667. var iFirstPIXO = curr - 1;
  16668. var iFirstRestore = curr;
  16669. if (argsArray[iFirstTransform][1] !== 0 ||
  16670. argsArray[iFirstTransform][2] !== 0) {
  16671. return iFirstRestore + 1; // transform has the wrong form
  16672. }
  16673. // Look for the quartets.
  16674. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  16675. var firstTransformArg0 = argsArray[iFirstTransform][0];
  16676. var firstTransformArg3 = argsArray[iFirstTransform][3];
  16677. var i = iFirstSave + 4;
  16678. var ii = fnArray.length;
  16679. while (i + 3 < ii) {
  16680. if (fnArray[i] !== OPS.save ||
  16681. fnArray[i + 1] !== OPS.transform ||
  16682. fnArray[i + 2] !== OPS.paintImageXObject ||
  16683. fnArray[i + 3] !== OPS.restore) {
  16684. break; // ops don't match
  16685. }
  16686. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  16687. argsArray[i + 1][1] !== 0 ||
  16688. argsArray[i + 1][2] !== 0 ||
  16689. argsArray[i + 1][3] !== firstTransformArg3) {
  16690. break; // transforms don't match
  16691. }
  16692. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  16693. break; // images don't match
  16694. }
  16695. i += 4;
  16696. }
  16697. // At this point, i is the index of the first op past the last valid
  16698. // quartet.
  16699. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  16700. if (count < MIN_IMAGES_IN_BLOCK) {
  16701. return i;
  16702. }
  16703. // Extract the (x,y) positions from all of the matching transforms.
  16704. var positions = new Float32Array(count * 2);
  16705. var iTransform = iFirstTransform;
  16706. for (var q = 0; q < count; q++, iTransform += 4) {
  16707. var transformArgs = argsArray[iTransform];
  16708. positions[(q << 1)] = transformArgs[4];
  16709. positions[(q << 1) + 1] = transformArgs[5];
  16710. }
  16711. // Replace queue items.
  16712. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  16713. positions];
  16714. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  16715. argsArray.splice(iFirstSave, count * 4, args);
  16716. return iFirstSave + 1;
  16717. });
  16718. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  16719. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  16720. // sequences, if the font for each one is the same.
  16721. addState(InitialState,
  16722. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  16723. function (context) {
  16724. var MIN_CHARS_IN_BLOCK = 3;
  16725. var MAX_CHARS_IN_BLOCK = 1000;
  16726. var fnArray = context.fnArray, argsArray = context.argsArray;
  16727. var curr = context.iCurr;
  16728. var iFirstBeginText = curr - 4;
  16729. var iFirstSetFont = curr - 3;
  16730. var iFirstSetTextMatrix = curr - 2;
  16731. var iFirstShowText = curr - 1;
  16732. var iFirstEndText = curr;
  16733. // Look for the quintets.
  16734. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  16735. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  16736. var i = iFirstBeginText + 5;
  16737. var ii = fnArray.length;
  16738. while (i + 4 < ii) {
  16739. if (fnArray[i] !== OPS.beginText ||
  16740. fnArray[i + 1] !== OPS.setFont ||
  16741. fnArray[i + 2] !== OPS.setTextMatrix ||
  16742. fnArray[i + 3] !== OPS.showText ||
  16743. fnArray[i + 4] !== OPS.endText) {
  16744. break; // ops don't match
  16745. }
  16746. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  16747. argsArray[i + 1][1] !== firstSetFontArg1) {
  16748. break; // fonts don't match
  16749. }
  16750. i += 5;
  16751. }
  16752. // At this point, i is the index of the first op past the last valid
  16753. // quintet.
  16754. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  16755. if (count < MIN_CHARS_IN_BLOCK) {
  16756. return i;
  16757. }
  16758. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  16759. // showText, endText), include that as well. (E.g. <something> might be
  16760. // |dependency|.)
  16761. var iFirst = iFirstBeginText;
  16762. if (iFirstBeginText >= 4 &&
  16763. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  16764. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  16765. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  16766. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  16767. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  16768. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  16769. count++;
  16770. iFirst -= 5;
  16771. }
  16772. // Remove (endText, beginText, setFont) trios.
  16773. var iEndText = iFirst + 4;
  16774. for (var q = 1; q < count; q++) {
  16775. fnArray.splice(iEndText, 3);
  16776. argsArray.splice(iEndText, 3);
  16777. iEndText += 2;
  16778. }
  16779. return iEndText + 1;
  16780. });
  16781. function QueueOptimizer() {}
  16782. QueueOptimizer.prototype = {
  16783. optimize: function QueueOptimizer_optimize(queue) {
  16784. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16785. var context = {
  16786. iCurr: 0,
  16787. fnArray: fnArray,
  16788. argsArray: argsArray
  16789. };
  16790. var state;
  16791. var i = 0, ii = fnArray.length;
  16792. while (i < ii) {
  16793. state = (state || InitialState)[fnArray[i]];
  16794. if (typeof state === 'function') { // we found some handler
  16795. context.iCurr = i;
  16796. // state() returns the index of the first non-matching op (if we
  16797. // didn't match) or the first op past the modified ops (if we did
  16798. // match and replace).
  16799. i = state(context);
  16800. state = undefined; // reset the state machine
  16801. ii = context.fnArray.length;
  16802. } else {
  16803. i++;
  16804. }
  16805. }
  16806. }
  16807. };
  16808. return QueueOptimizer;
  16809. })();
  16810. var BUILT_IN_CMAPS = [
  16811. // << Start unicode maps.
  16812. 'Adobe-GB1-UCS2',
  16813. 'Adobe-CNS1-UCS2',
  16814. 'Adobe-Japan1-UCS2',
  16815. 'Adobe-Korea1-UCS2',
  16816. // >> End unicode maps.
  16817. '78-EUC-H',
  16818. '78-EUC-V',
  16819. '78-H',
  16820. '78-RKSJ-H',
  16821. '78-RKSJ-V',
  16822. '78-V',
  16823. '78ms-RKSJ-H',
  16824. '78ms-RKSJ-V',
  16825. '83pv-RKSJ-H',
  16826. '90ms-RKSJ-H',
  16827. '90ms-RKSJ-V',
  16828. '90msp-RKSJ-H',
  16829. '90msp-RKSJ-V',
  16830. '90pv-RKSJ-H',
  16831. '90pv-RKSJ-V',
  16832. 'Add-H',
  16833. 'Add-RKSJ-H',
  16834. 'Add-RKSJ-V',
  16835. 'Add-V',
  16836. 'Adobe-CNS1-0',
  16837. 'Adobe-CNS1-1',
  16838. 'Adobe-CNS1-2',
  16839. 'Adobe-CNS1-3',
  16840. 'Adobe-CNS1-4',
  16841. 'Adobe-CNS1-5',
  16842. 'Adobe-CNS1-6',
  16843. 'Adobe-GB1-0',
  16844. 'Adobe-GB1-1',
  16845. 'Adobe-GB1-2',
  16846. 'Adobe-GB1-3',
  16847. 'Adobe-GB1-4',
  16848. 'Adobe-GB1-5',
  16849. 'Adobe-Japan1-0',
  16850. 'Adobe-Japan1-1',
  16851. 'Adobe-Japan1-2',
  16852. 'Adobe-Japan1-3',
  16853. 'Adobe-Japan1-4',
  16854. 'Adobe-Japan1-5',
  16855. 'Adobe-Japan1-6',
  16856. 'Adobe-Korea1-0',
  16857. 'Adobe-Korea1-1',
  16858. 'Adobe-Korea1-2',
  16859. 'B5-H',
  16860. 'B5-V',
  16861. 'B5pc-H',
  16862. 'B5pc-V',
  16863. 'CNS-EUC-H',
  16864. 'CNS-EUC-V',
  16865. 'CNS1-H',
  16866. 'CNS1-V',
  16867. 'CNS2-H',
  16868. 'CNS2-V',
  16869. 'ETHK-B5-H',
  16870. 'ETHK-B5-V',
  16871. 'ETen-B5-H',
  16872. 'ETen-B5-V',
  16873. 'ETenms-B5-H',
  16874. 'ETenms-B5-V',
  16875. 'EUC-H',
  16876. 'EUC-V',
  16877. 'Ext-H',
  16878. 'Ext-RKSJ-H',
  16879. 'Ext-RKSJ-V',
  16880. 'Ext-V',
  16881. 'GB-EUC-H',
  16882. 'GB-EUC-V',
  16883. 'GB-H',
  16884. 'GB-V',
  16885. 'GBK-EUC-H',
  16886. 'GBK-EUC-V',
  16887. 'GBK2K-H',
  16888. 'GBK2K-V',
  16889. 'GBKp-EUC-H',
  16890. 'GBKp-EUC-V',
  16891. 'GBT-EUC-H',
  16892. 'GBT-EUC-V',
  16893. 'GBT-H',
  16894. 'GBT-V',
  16895. 'GBTpc-EUC-H',
  16896. 'GBTpc-EUC-V',
  16897. 'GBpc-EUC-H',
  16898. 'GBpc-EUC-V',
  16899. 'H',
  16900. 'HKdla-B5-H',
  16901. 'HKdla-B5-V',
  16902. 'HKdlb-B5-H',
  16903. 'HKdlb-B5-V',
  16904. 'HKgccs-B5-H',
  16905. 'HKgccs-B5-V',
  16906. 'HKm314-B5-H',
  16907. 'HKm314-B5-V',
  16908. 'HKm471-B5-H',
  16909. 'HKm471-B5-V',
  16910. 'HKscs-B5-H',
  16911. 'HKscs-B5-V',
  16912. 'Hankaku',
  16913. 'Hiragana',
  16914. 'KSC-EUC-H',
  16915. 'KSC-EUC-V',
  16916. 'KSC-H',
  16917. 'KSC-Johab-H',
  16918. 'KSC-Johab-V',
  16919. 'KSC-V',
  16920. 'KSCms-UHC-H',
  16921. 'KSCms-UHC-HW-H',
  16922. 'KSCms-UHC-HW-V',
  16923. 'KSCms-UHC-V',
  16924. 'KSCpc-EUC-H',
  16925. 'KSCpc-EUC-V',
  16926. 'Katakana',
  16927. 'NWP-H',
  16928. 'NWP-V',
  16929. 'RKSJ-H',
  16930. 'RKSJ-V',
  16931. 'Roman',
  16932. 'UniCNS-UCS2-H',
  16933. 'UniCNS-UCS2-V',
  16934. 'UniCNS-UTF16-H',
  16935. 'UniCNS-UTF16-V',
  16936. 'UniCNS-UTF32-H',
  16937. 'UniCNS-UTF32-V',
  16938. 'UniCNS-UTF8-H',
  16939. 'UniCNS-UTF8-V',
  16940. 'UniGB-UCS2-H',
  16941. 'UniGB-UCS2-V',
  16942. 'UniGB-UTF16-H',
  16943. 'UniGB-UTF16-V',
  16944. 'UniGB-UTF32-H',
  16945. 'UniGB-UTF32-V',
  16946. 'UniGB-UTF8-H',
  16947. 'UniGB-UTF8-V',
  16948. 'UniJIS-UCS2-H',
  16949. 'UniJIS-UCS2-HW-H',
  16950. 'UniJIS-UCS2-HW-V',
  16951. 'UniJIS-UCS2-V',
  16952. 'UniJIS-UTF16-H',
  16953. 'UniJIS-UTF16-V',
  16954. 'UniJIS-UTF32-H',
  16955. 'UniJIS-UTF32-V',
  16956. 'UniJIS-UTF8-H',
  16957. 'UniJIS-UTF8-V',
  16958. 'UniJIS2004-UTF16-H',
  16959. 'UniJIS2004-UTF16-V',
  16960. 'UniJIS2004-UTF32-H',
  16961. 'UniJIS2004-UTF32-V',
  16962. 'UniJIS2004-UTF8-H',
  16963. 'UniJIS2004-UTF8-V',
  16964. 'UniJISPro-UCS2-HW-V',
  16965. 'UniJISPro-UCS2-V',
  16966. 'UniJISPro-UTF8-V',
  16967. 'UniJISX0213-UTF32-H',
  16968. 'UniJISX0213-UTF32-V',
  16969. 'UniJISX02132004-UTF32-H',
  16970. 'UniJISX02132004-UTF32-V',
  16971. 'UniKS-UCS2-H',
  16972. 'UniKS-UCS2-V',
  16973. 'UniKS-UTF16-H',
  16974. 'UniKS-UTF16-V',
  16975. 'UniKS-UTF32-H',
  16976. 'UniKS-UTF32-V',
  16977. 'UniKS-UTF8-H',
  16978. 'UniKS-UTF8-V',
  16979. 'V',
  16980. 'WP-Symbol'];
  16981. // CMap, not to be confused with TrueType's cmap.
  16982. var CMap = (function CMapClosure() {
  16983. function CMap(builtInCMap) {
  16984. // Codespace ranges are stored as follows:
  16985. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  16986. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  16987. this.codespaceRanges = [[], [], [], []];
  16988. this.numCodespaceRanges = 0;
  16989. // Map entries have one of two forms.
  16990. // - cid chars are 16-bit unsigned integers, stored as integers.
  16991. // - bf chars are variable-length byte sequences, stored as strings, with
  16992. // one byte per character.
  16993. this._map = [];
  16994. this.vertical = false;
  16995. this.useCMap = null;
  16996. this.builtInCMap = builtInCMap;
  16997. }
  16998. CMap.prototype = {
  16999. addCodespaceRange: function(n, low, high) {
  17000. this.codespaceRanges[n - 1].push(low, high);
  17001. this.numCodespaceRanges++;
  17002. },
  17003. mapCidRange: function(low, high, dstLow) {
  17004. while (low <= high) {
  17005. this._map[low++] = dstLow++;
  17006. }
  17007. },
  17008. mapBfRange: function(low, high, dstLow) {
  17009. var lastByte = dstLow.length - 1;
  17010. while (low <= high) {
  17011. this._map[low++] = dstLow;
  17012. // Only the last byte has to be incremented.
  17013. dstLow = dstLow.substr(0, lastByte) +
  17014. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17015. }
  17016. },
  17017. mapBfRangeToArray: function(low, high, array) {
  17018. var i = 0, ii = array.length;
  17019. while (low <= high && i < ii) {
  17020. this._map[low] = array[i++];
  17021. ++low;
  17022. }
  17023. },
  17024. // This is used for both bf and cid chars.
  17025. mapOne: function(src, dst) {
  17026. this._map[src] = dst;
  17027. },
  17028. lookup: function(code) {
  17029. return this._map[code];
  17030. },
  17031. contains: function(code) {
  17032. return this._map[code] !== undefined;
  17033. },
  17034. forEach: function(callback) {
  17035. // Most maps have fewer than 65536 entries, and for those we use normal
  17036. // array iteration. But really sparse tables are possible -- e.g. with
  17037. // indices in the *billions*. For such tables we use for..in, which isn't
  17038. // ideal because it stringifies the indices for all present elements, but
  17039. // it does avoid iterating over every undefined entry.
  17040. var map = this._map;
  17041. var length = map.length;
  17042. var i;
  17043. if (length <= 0x10000) {
  17044. for (i = 0; i < length; i++) {
  17045. if (map[i] !== undefined) {
  17046. callback(i, map[i]);
  17047. }
  17048. }
  17049. } else {
  17050. for (i in this._map) {
  17051. callback(i, map[i]);
  17052. }
  17053. }
  17054. },
  17055. charCodeOf: function(value) {
  17056. return this._map.indexOf(value);
  17057. },
  17058. getMap: function() {
  17059. return this._map;
  17060. },
  17061. readCharCode: function(str, offset, out) {
  17062. var c = 0;
  17063. var codespaceRanges = this.codespaceRanges;
  17064. var codespaceRangesLen = this.codespaceRanges.length;
  17065. // 9.7.6.2 CMap Mapping
  17066. // The code length is at most 4.
  17067. for (var n = 0; n < codespaceRangesLen; n++) {
  17068. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17069. // Check each codespace range to see if it falls within.
  17070. var codespaceRange = codespaceRanges[n];
  17071. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17072. var low = codespaceRange[k++];
  17073. var high = codespaceRange[k++];
  17074. if (c >= low && c <= high) {
  17075. out.charcode = c;
  17076. out.length = n + 1;
  17077. return;
  17078. }
  17079. }
  17080. }
  17081. out.charcode = 0;
  17082. out.length = 1;
  17083. }
  17084. };
  17085. return CMap;
  17086. })();
  17087. // A special case of CMap, where the _map array implicitly has a length of
  17088. // 65535 and each element is equal to its index.
  17089. var IdentityCMap = (function IdentityCMapClosure() {
  17090. function IdentityCMap(vertical, n) {
  17091. CMap.call(this);
  17092. this.vertical = vertical;
  17093. this.addCodespaceRange(n, 0, 0xffff);
  17094. }
  17095. Util.inherit(IdentityCMap, CMap, {});
  17096. IdentityCMap.prototype = {
  17097. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17098. mapCidRange: function(low, high, dstLow) {
  17099. error('should not call mapCidRange');
  17100. },
  17101. mapBfRange: function(low, high, dstLow) {
  17102. error('should not call mapBfRange');
  17103. },
  17104. mapBfRangeToArray: function(low, high, array) {
  17105. error('should not call mapBfRangeToArray');
  17106. },
  17107. mapOne: function(src, dst) {
  17108. error('should not call mapCidOne');
  17109. },
  17110. lookup: function(code) {
  17111. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17112. },
  17113. contains: function(code) {
  17114. return isInt(code) && code <= 0xffff;
  17115. },
  17116. forEach: function(callback) {
  17117. for (var i = 0; i <= 0xffff; i++) {
  17118. callback(i, i);
  17119. }
  17120. },
  17121. charCodeOf: function(value) {
  17122. return (isInt(value) && value <= 0xffff) ? value : -1;
  17123. },
  17124. getMap: function() {
  17125. // Sometimes identity maps must be instantiated, but it's rare.
  17126. var map = new Array(0x10000);
  17127. for (var i = 0; i <= 0xffff; i++) {
  17128. map[i] = i;
  17129. }
  17130. return map;
  17131. },
  17132. readCharCode: CMap.prototype.readCharCode
  17133. };
  17134. return IdentityCMap;
  17135. })();
  17136. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17137. function fetchBinaryData(url) {
  17138. var nonBinaryRequest = PDFJS.disableWorker;
  17139. var request = new XMLHttpRequest();
  17140. request.open('GET', url, false);
  17141. if (!nonBinaryRequest) {
  17142. try {
  17143. request.responseType = 'arraybuffer';
  17144. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17145. } catch (e) {
  17146. nonBinaryRequest = true;
  17147. }
  17148. }
  17149. if (nonBinaryRequest && request.overrideMimeType) {
  17150. request.overrideMimeType('text/plain; charset=x-user-defined');
  17151. }
  17152. request.send(null);
  17153. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17154. error('Unable to get binary cMap at: ' + url);
  17155. }
  17156. if (nonBinaryRequest) {
  17157. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17158. return ch.charCodeAt(0) & 255;
  17159. });
  17160. return new Uint8Array(data);
  17161. }
  17162. return new Uint8Array(request.response);
  17163. }
  17164. function hexToInt(a, size) {
  17165. var n = 0;
  17166. for (var i = 0; i <= size; i++) {
  17167. n = (n << 8) | a[i];
  17168. }
  17169. return n >>> 0;
  17170. }
  17171. function hexToStr(a, size) {
  17172. // This code is hot. Special-case some common values to avoid creating an
  17173. // object with subarray().
  17174. if (size === 1) {
  17175. return String.fromCharCode(a[0], a[1]);
  17176. }
  17177. if (size === 3) {
  17178. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17179. }
  17180. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17181. }
  17182. function addHex(a, b, size) {
  17183. var c = 0;
  17184. for (var i = size; i >= 0; i--) {
  17185. c += a[i] + b[i];
  17186. a[i] = c & 255;
  17187. c >>= 8;
  17188. }
  17189. }
  17190. function incHex(a, size) {
  17191. var c = 1;
  17192. for (var i = size; i >= 0 && c > 0; i--) {
  17193. c += a[i];
  17194. a[i] = c & 255;
  17195. c >>= 8;
  17196. }
  17197. }
  17198. var MAX_NUM_SIZE = 16;
  17199. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17200. function BinaryCMapStream(data) {
  17201. this.buffer = data;
  17202. this.pos = 0;
  17203. this.end = data.length;
  17204. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  17205. }
  17206. BinaryCMapStream.prototype = {
  17207. readByte: function () {
  17208. if (this.pos >= this.end) {
  17209. return -1;
  17210. }
  17211. return this.buffer[this.pos++];
  17212. },
  17213. readNumber: function () {
  17214. var n = 0;
  17215. var last;
  17216. do {
  17217. var b = this.readByte();
  17218. if (b < 0) {
  17219. error('unexpected EOF in bcmap');
  17220. }
  17221. last = !(b & 0x80);
  17222. n = (n << 7) | (b & 0x7F);
  17223. } while (!last);
  17224. return n;
  17225. },
  17226. readSigned: function () {
  17227. var n = this.readNumber();
  17228. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  17229. },
  17230. readHex: function (num, size) {
  17231. num.set(this.buffer.subarray(this.pos,
  17232. this.pos + size + 1));
  17233. this.pos += size + 1;
  17234. },
  17235. readHexNumber: function (num, size) {
  17236. var last;
  17237. var stack = this.tmpBuf, sp = 0;
  17238. do {
  17239. var b = this.readByte();
  17240. if (b < 0) {
  17241. error('unexpected EOF in bcmap');
  17242. }
  17243. last = !(b & 0x80);
  17244. stack[sp++] = b & 0x7F;
  17245. } while (!last);
  17246. var i = size, buffer = 0, bufferSize = 0;
  17247. while (i >= 0) {
  17248. while (bufferSize < 8 && stack.length > 0) {
  17249. buffer = (stack[--sp] << bufferSize) | buffer;
  17250. bufferSize += 7;
  17251. }
  17252. num[i] = buffer & 255;
  17253. i--;
  17254. buffer >>= 8;
  17255. bufferSize -= 8;
  17256. }
  17257. },
  17258. readHexSigned: function (num, size) {
  17259. this.readHexNumber(num, size);
  17260. var sign = num[size] & 1 ? 255 : 0;
  17261. var c = 0;
  17262. for (var i = 0; i <= size; i++) {
  17263. c = ((c & 1) << 8) | num[i];
  17264. num[i] = (c >> 1) ^ sign;
  17265. }
  17266. },
  17267. readString: function () {
  17268. var len = this.readNumber();
  17269. var s = '';
  17270. for (var i = 0; i < len; i++) {
  17271. s += String.fromCharCode(this.readNumber());
  17272. }
  17273. return s;
  17274. }
  17275. };
  17276. function processBinaryCMap(url, cMap, extend) {
  17277. var data = fetchBinaryData(url);
  17278. var stream = new BinaryCMapStream(data);
  17279. var header = stream.readByte();
  17280. cMap.vertical = !!(header & 1);
  17281. var useCMap = null;
  17282. var start = new Uint8Array(MAX_NUM_SIZE);
  17283. var end = new Uint8Array(MAX_NUM_SIZE);
  17284. var char = new Uint8Array(MAX_NUM_SIZE);
  17285. var charCode = new Uint8Array(MAX_NUM_SIZE);
  17286. var tmp = new Uint8Array(MAX_NUM_SIZE);
  17287. var code;
  17288. var b;
  17289. while ((b = stream.readByte()) >= 0) {
  17290. var type = b >> 5;
  17291. if (type === 7) { // metadata, e.g. comment or usecmap
  17292. switch (b & 0x1F) {
  17293. case 0:
  17294. stream.readString(); // skipping comment
  17295. break;
  17296. case 1:
  17297. useCMap = stream.readString();
  17298. break;
  17299. }
  17300. continue;
  17301. }
  17302. var sequence = !!(b & 0x10);
  17303. var dataSize = b & 15;
  17304. assert(dataSize + 1 <= MAX_NUM_SIZE);
  17305. var ucs2DataSize = 1;
  17306. var subitemsCount = stream.readNumber();
  17307. var i;
  17308. switch (type) {
  17309. case 0: // codespacerange
  17310. stream.readHex(start, dataSize);
  17311. stream.readHexNumber(end, dataSize);
  17312. addHex(end, start, dataSize);
  17313. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  17314. hexToInt(end, dataSize));
  17315. for (i = 1; i < subitemsCount; i++) {
  17316. incHex(end, dataSize);
  17317. stream.readHexNumber(start, dataSize);
  17318. addHex(start, end, dataSize);
  17319. stream.readHexNumber(end, dataSize);
  17320. addHex(end, start, dataSize);
  17321. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  17322. hexToInt(end, dataSize));
  17323. }
  17324. break;
  17325. case 1: // notdefrange
  17326. stream.readHex(start, dataSize);
  17327. stream.readHexNumber(end, dataSize);
  17328. addHex(end, start, dataSize);
  17329. code = stream.readNumber();
  17330. // undefined range, skipping
  17331. for (i = 1; i < subitemsCount; i++) {
  17332. incHex(end, dataSize);
  17333. stream.readHexNumber(start, dataSize);
  17334. addHex(start, end, dataSize);
  17335. stream.readHexNumber(end, dataSize);
  17336. addHex(end, start, dataSize);
  17337. code = stream.readNumber();
  17338. // nop
  17339. }
  17340. break;
  17341. case 2: // cidchar
  17342. stream.readHex(char, dataSize);
  17343. code = stream.readNumber();
  17344. cMap.mapOne(hexToInt(char, dataSize), code);
  17345. for (i = 1; i < subitemsCount; i++) {
  17346. incHex(char, dataSize);
  17347. if (!sequence) {
  17348. stream.readHexNumber(tmp, dataSize);
  17349. addHex(char, tmp, dataSize);
  17350. }
  17351. code = stream.readSigned() + (code + 1);
  17352. cMap.mapOne(hexToInt(char, dataSize), code);
  17353. }
  17354. break;
  17355. case 3: // cidrange
  17356. stream.readHex(start, dataSize);
  17357. stream.readHexNumber(end, dataSize);
  17358. addHex(end, start, dataSize);
  17359. code = stream.readNumber();
  17360. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  17361. code);
  17362. for (i = 1; i < subitemsCount; i++) {
  17363. incHex(end, dataSize);
  17364. if (!sequence) {
  17365. stream.readHexNumber(start, dataSize);
  17366. addHex(start, end, dataSize);
  17367. } else {
  17368. start.set(end);
  17369. }
  17370. stream.readHexNumber(end, dataSize);
  17371. addHex(end, start, dataSize);
  17372. code = stream.readNumber();
  17373. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  17374. code);
  17375. }
  17376. break;
  17377. case 4: // bfchar
  17378. stream.readHex(char, ucs2DataSize);
  17379. stream.readHex(charCode, dataSize);
  17380. cMap.mapOne(hexToInt(char, ucs2DataSize),
  17381. hexToStr(charCode, dataSize));
  17382. for (i = 1; i < subitemsCount; i++) {
  17383. incHex(char, ucs2DataSize);
  17384. if (!sequence) {
  17385. stream.readHexNumber(tmp, ucs2DataSize);
  17386. addHex(char, tmp, ucs2DataSize);
  17387. }
  17388. incHex(charCode, dataSize);
  17389. stream.readHexSigned(tmp, dataSize);
  17390. addHex(charCode, tmp, dataSize);
  17391. cMap.mapOne(hexToInt(char, ucs2DataSize),
  17392. hexToStr(charCode, dataSize));
  17393. }
  17394. break;
  17395. case 5: // bfrange
  17396. stream.readHex(start, ucs2DataSize);
  17397. stream.readHexNumber(end, ucs2DataSize);
  17398. addHex(end, start, ucs2DataSize);
  17399. stream.readHex(charCode, dataSize);
  17400. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  17401. hexToInt(end, ucs2DataSize),
  17402. hexToStr(charCode, dataSize));
  17403. for (i = 1; i < subitemsCount; i++) {
  17404. incHex(end, ucs2DataSize);
  17405. if (!sequence) {
  17406. stream.readHexNumber(start, ucs2DataSize);
  17407. addHex(start, end, ucs2DataSize);
  17408. } else {
  17409. start.set(end);
  17410. }
  17411. stream.readHexNumber(end, ucs2DataSize);
  17412. addHex(end, start, ucs2DataSize);
  17413. stream.readHex(charCode, dataSize);
  17414. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  17415. hexToInt(end, ucs2DataSize),
  17416. hexToStr(charCode, dataSize));
  17417. }
  17418. break;
  17419. default:
  17420. error('Unknown type: ' + type);
  17421. break;
  17422. }
  17423. }
  17424. if (useCMap) {
  17425. extend(useCMap);
  17426. }
  17427. return cMap;
  17428. }
  17429. function BinaryCMapReader() {}
  17430. BinaryCMapReader.prototype = {
  17431. read: processBinaryCMap
  17432. };
  17433. return BinaryCMapReader;
  17434. })();
  17435. var CMapFactory = (function CMapFactoryClosure() {
  17436. function strToInt(str) {
  17437. var a = 0;
  17438. for (var i = 0; i < str.length; i++) {
  17439. a = (a << 8) | str.charCodeAt(i);
  17440. }
  17441. return a >>> 0;
  17442. }
  17443. function expectString(obj) {
  17444. if (!isString(obj)) {
  17445. error('Malformed CMap: expected string.');
  17446. }
  17447. }
  17448. function expectInt(obj) {
  17449. if (!isInt(obj)) {
  17450. error('Malformed CMap: expected int.');
  17451. }
  17452. }
  17453. function parseBfChar(cMap, lexer) {
  17454. while (true) {
  17455. var obj = lexer.getObj();
  17456. if (isEOF(obj)) {
  17457. break;
  17458. }
  17459. if (isCmd(obj, 'endbfchar')) {
  17460. return;
  17461. }
  17462. expectString(obj);
  17463. var src = strToInt(obj);
  17464. obj = lexer.getObj();
  17465. // TODO are /dstName used?
  17466. expectString(obj);
  17467. var dst = obj;
  17468. cMap.mapOne(src, dst);
  17469. }
  17470. }
  17471. function parseBfRange(cMap, lexer) {
  17472. while (true) {
  17473. var obj = lexer.getObj();
  17474. if (isEOF(obj)) {
  17475. break;
  17476. }
  17477. if (isCmd(obj, 'endbfrange')) {
  17478. return;
  17479. }
  17480. expectString(obj);
  17481. var low = strToInt(obj);
  17482. obj = lexer.getObj();
  17483. expectString(obj);
  17484. var high = strToInt(obj);
  17485. obj = lexer.getObj();
  17486. if (isInt(obj) || isString(obj)) {
  17487. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  17488. cMap.mapBfRange(low, high, dstLow);
  17489. } else if (isCmd(obj, '[')) {
  17490. obj = lexer.getObj();
  17491. var array = [];
  17492. while (!isCmd(obj, ']') && !isEOF(obj)) {
  17493. array.push(obj);
  17494. obj = lexer.getObj();
  17495. }
  17496. cMap.mapBfRangeToArray(low, high, array);
  17497. } else {
  17498. break;
  17499. }
  17500. }
  17501. error('Invalid bf range.');
  17502. }
  17503. function parseCidChar(cMap, lexer) {
  17504. while (true) {
  17505. var obj = lexer.getObj();
  17506. if (isEOF(obj)) {
  17507. break;
  17508. }
  17509. if (isCmd(obj, 'endcidchar')) {
  17510. return;
  17511. }
  17512. expectString(obj);
  17513. var src = strToInt(obj);
  17514. obj = lexer.getObj();
  17515. expectInt(obj);
  17516. var dst = obj;
  17517. cMap.mapOne(src, dst);
  17518. }
  17519. }
  17520. function parseCidRange(cMap, lexer) {
  17521. while (true) {
  17522. var obj = lexer.getObj();
  17523. if (isEOF(obj)) {
  17524. break;
  17525. }
  17526. if (isCmd(obj, 'endcidrange')) {
  17527. return;
  17528. }
  17529. expectString(obj);
  17530. var low = strToInt(obj);
  17531. obj = lexer.getObj();
  17532. expectString(obj);
  17533. var high = strToInt(obj);
  17534. obj = lexer.getObj();
  17535. expectInt(obj);
  17536. var dstLow = obj;
  17537. cMap.mapCidRange(low, high, dstLow);
  17538. }
  17539. }
  17540. function parseCodespaceRange(cMap, lexer) {
  17541. while (true) {
  17542. var obj = lexer.getObj();
  17543. if (isEOF(obj)) {
  17544. break;
  17545. }
  17546. if (isCmd(obj, 'endcodespacerange')) {
  17547. return;
  17548. }
  17549. if (!isString(obj)) {
  17550. break;
  17551. }
  17552. var low = strToInt(obj);
  17553. obj = lexer.getObj();
  17554. if (!isString(obj)) {
  17555. break;
  17556. }
  17557. var high = strToInt(obj);
  17558. cMap.addCodespaceRange(obj.length, low, high);
  17559. }
  17560. error('Invalid codespace range.');
  17561. }
  17562. function parseWMode(cMap, lexer) {
  17563. var obj = lexer.getObj();
  17564. if (isInt(obj)) {
  17565. cMap.vertical = !!obj;
  17566. }
  17567. }
  17568. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  17569. var previous;
  17570. var embededUseCMap;
  17571. objLoop: while (true) {
  17572. var obj = lexer.getObj();
  17573. if (isEOF(obj)) {
  17574. break;
  17575. } else if (isName(obj)) {
  17576. if (obj.name === 'WMode') {
  17577. parseWMode(cMap, lexer);
  17578. }
  17579. previous = obj;
  17580. } else if (isCmd(obj)) {
  17581. switch (obj.cmd) {
  17582. case 'endcmap':
  17583. break objLoop;
  17584. case 'usecmap':
  17585. if (isName(previous)) {
  17586. embededUseCMap = previous.name;
  17587. }
  17588. break;
  17589. case 'begincodespacerange':
  17590. parseCodespaceRange(cMap, lexer);
  17591. break;
  17592. case 'beginbfchar':
  17593. parseBfChar(cMap, lexer);
  17594. break;
  17595. case 'begincidchar':
  17596. parseCidChar(cMap, lexer);
  17597. break;
  17598. case 'beginbfrange':
  17599. parseBfRange(cMap, lexer);
  17600. break;
  17601. case 'begincidrange':
  17602. parseCidRange(cMap, lexer);
  17603. break;
  17604. }
  17605. }
  17606. }
  17607. if (!useCMap && embededUseCMap) {
  17608. // Load the usecmap definition from the file only if there wasn't one
  17609. // specified.
  17610. useCMap = embededUseCMap;
  17611. }
  17612. if (useCMap) {
  17613. extendCMap(cMap, builtInCMapParams, useCMap);
  17614. }
  17615. }
  17616. function extendCMap(cMap, builtInCMapParams, useCMap) {
  17617. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  17618. // If there aren't any code space ranges defined clone all the parent ones
  17619. // into this cMap.
  17620. if (cMap.numCodespaceRanges === 0) {
  17621. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  17622. for (var i = 0; i < useCodespaceRanges.length; i++) {
  17623. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  17624. }
  17625. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  17626. }
  17627. // Merge the map into the current one, making sure not to override
  17628. // any previously defined entries.
  17629. cMap.useCMap.forEach(function(key, value) {
  17630. if (!cMap.contains(key)) {
  17631. cMap.mapOne(key, cMap.useCMap.lookup(key));
  17632. }
  17633. });
  17634. }
  17635. function parseBinaryCMap(name, builtInCMapParams) {
  17636. var url = builtInCMapParams.url + name + '.bcmap';
  17637. var cMap = new CMap(true);
  17638. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  17639. extendCMap(cMap, builtInCMapParams, useCMap);
  17640. });
  17641. return cMap;
  17642. }
  17643. function createBuiltInCMap(name, builtInCMapParams) {
  17644. if (name === 'Identity-H') {
  17645. return new IdentityCMap(false, 2);
  17646. } else if (name === 'Identity-V') {
  17647. return new IdentityCMap(true, 2);
  17648. }
  17649. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  17650. error('Unknown cMap name: ' + name);
  17651. }
  17652. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  17653. if (builtInCMapParams.packed) {
  17654. return parseBinaryCMap(name, builtInCMapParams);
  17655. }
  17656. var request = new XMLHttpRequest();
  17657. var url = builtInCMapParams.url + name;
  17658. request.open('GET', url, false);
  17659. request.send(null);
  17660. if (!request.responseText) {
  17661. error('Unable to get cMap at: ' + url);
  17662. }
  17663. var cMap = new CMap(true);
  17664. var lexer = new Lexer(new StringStream(request.responseText));
  17665. parseCMap(cMap, lexer, builtInCMapParams, null);
  17666. return cMap;
  17667. }
  17668. return {
  17669. create: function (encoding, builtInCMapParams, useCMap) {
  17670. if (isName(encoding)) {
  17671. return createBuiltInCMap(encoding.name, builtInCMapParams);
  17672. } else if (isStream(encoding)) {
  17673. var cMap = new CMap();
  17674. var lexer = new Lexer(encoding);
  17675. try {
  17676. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  17677. } catch (e) {
  17678. warn('Invalid CMap data. ' + e);
  17679. }
  17680. return cMap;
  17681. }
  17682. error('Encoding required.');
  17683. }
  17684. };
  17685. })();
  17686. // Unicode Private Use Area
  17687. var PRIVATE_USE_OFFSET_START = 0xE000;
  17688. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  17689. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  17690. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  17691. // except for Type 3 fonts
  17692. var PDF_GLYPH_SPACE_UNITS = 1000;
  17693. // Hinting is currently disabled due to unknown problems on windows
  17694. // in tracemonkey and various other pdfs with type1 fonts.
  17695. var HINTING_ENABLED = false;
  17696. // Accented charactars are not displayed properly on windows, using this flag
  17697. // to control analysis of seac charstrings.
  17698. var SEAC_ANALYSIS_ENABLED = false;
  17699. var FontFlags = {
  17700. FixedPitch: 1,
  17701. Serif: 2,
  17702. Symbolic: 4,
  17703. Script: 8,
  17704. Nonsymbolic: 32,
  17705. Italic: 64,
  17706. AllCap: 65536,
  17707. SmallCap: 131072,
  17708. ForceBold: 262144
  17709. };
  17710. var Encodings = {
  17711. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17712. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17713. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  17714. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  17715. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  17716. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  17717. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  17718. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  17719. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  17720. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  17721. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  17722. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  17723. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  17724. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  17725. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  17726. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  17727. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  17728. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  17729. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  17730. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17731. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  17732. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  17733. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  17734. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  17735. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  17736. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  17737. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  17738. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  17739. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  17740. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  17741. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  17742. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  17743. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  17744. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  17745. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  17746. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  17747. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  17748. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  17749. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  17750. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  17751. 'Ydieresissmall'],
  17752. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17753. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17754. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  17755. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  17756. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17757. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  17758. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  17759. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  17760. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  17761. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  17762. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  17763. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  17764. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  17765. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  17766. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  17767. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  17768. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  17769. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  17770. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  17771. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  17772. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  17773. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  17774. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  17775. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  17776. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  17777. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  17778. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  17779. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  17780. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  17781. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  17782. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  17783. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  17784. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  17785. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  17786. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  17787. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  17788. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  17789. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  17790. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  17791. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  17792. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17793. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17794. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17795. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  17796. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  17797. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  17798. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  17799. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  17800. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  17801. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  17802. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  17803. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  17804. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  17805. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  17806. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  17807. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  17808. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  17809. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  17810. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  17811. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  17812. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  17813. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  17814. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  17815. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  17816. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  17817. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  17818. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  17819. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  17820. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  17821. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  17822. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  17823. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  17824. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  17825. 'ogonek', 'caron'],
  17826. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17827. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17828. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17829. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17830. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  17831. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  17832. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  17833. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  17834. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  17835. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  17836. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  17837. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  17838. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17839. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  17840. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17841. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17842. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  17843. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  17844. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  17845. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  17846. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  17847. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  17848. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  17849. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  17850. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  17851. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17852. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17853. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17854. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  17855. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  17856. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  17857. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  17858. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  17859. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  17860. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  17861. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  17862. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  17863. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  17864. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  17865. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  17866. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  17867. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  17868. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  17869. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  17870. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  17871. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  17872. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  17873. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  17874. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  17875. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  17876. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  17877. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  17878. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  17879. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  17880. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  17881. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  17882. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  17883. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  17884. 'ydieresis'],
  17885. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17886. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17887. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  17888. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  17889. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17890. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17891. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  17892. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  17893. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  17894. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  17895. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  17896. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  17897. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  17898. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  17899. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  17900. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17901. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  17902. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  17903. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  17904. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  17905. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  17906. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  17907. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  17908. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  17909. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  17910. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  17911. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  17912. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  17913. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  17914. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  17915. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  17916. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  17917. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  17918. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  17919. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  17920. 'bracerightbt'],
  17921. zapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17922. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17923. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  17924. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  17925. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  17926. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  17927. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  17928. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  17929. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  17930. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  17931. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  17932. 'a98', 'a99', 'a100', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17933. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  17934. '', '', 'a101', 'a102', 'a103', 'a104', 'a106', 'a107', 'a108', 'a112',
  17935. 'a111', 'a110', 'a109', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125',
  17936. 'a126', 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134',
  17937. 'a135', 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143',
  17938. 'a144', 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152',
  17939. 'a153', 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161',
  17940. 'a163', 'a164', 'a196', 'a165', 'a192', 'a166', 'a167', 'a168', 'a169',
  17941. 'a170', 'a171', 'a172', 'a173', 'a162', 'a174', 'a175', 'a176', 'a177',
  17942. 'a178', 'a179', 'a193', 'a180', 'a199', 'a181', 'a200', 'a182', '', 'a201',
  17943. 'a183', 'a184', 'a197', 'a185', 'a194', 'a198', 'a186', 'a195', 'a187',
  17944. 'a188', 'a189', 'a190', 'a191']
  17945. };
  17946. /**
  17947. * Hold a map of decoded fonts and of the standard fourteen Type1
  17948. * fonts and their acronyms.
  17949. */
  17950. var stdFontMap = {
  17951. 'ArialNarrow': 'Helvetica',
  17952. 'ArialNarrow-Bold': 'Helvetica-Bold',
  17953. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  17954. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  17955. 'ArialBlack': 'Helvetica',
  17956. 'ArialBlack-Bold': 'Helvetica-Bold',
  17957. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  17958. 'ArialBlack-Italic': 'Helvetica-Oblique',
  17959. 'Arial': 'Helvetica',
  17960. 'Arial-Bold': 'Helvetica-Bold',
  17961. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  17962. 'Arial-Italic': 'Helvetica-Oblique',
  17963. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  17964. 'Arial-BoldMT': 'Helvetica-Bold',
  17965. 'Arial-ItalicMT': 'Helvetica-Oblique',
  17966. 'ArialMT': 'Helvetica',
  17967. 'Courier-Bold': 'Courier-Bold',
  17968. 'Courier-BoldItalic': 'Courier-BoldOblique',
  17969. 'Courier-Italic': 'Courier-Oblique',
  17970. 'CourierNew': 'Courier',
  17971. 'CourierNew-Bold': 'Courier-Bold',
  17972. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  17973. 'CourierNew-Italic': 'Courier-Oblique',
  17974. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  17975. 'CourierNewPS-BoldMT': 'Courier-Bold',
  17976. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  17977. 'CourierNewPSMT': 'Courier',
  17978. 'Helvetica-Bold': 'Helvetica-Bold',
  17979. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  17980. 'Helvetica-Italic': 'Helvetica-Oblique',
  17981. 'Symbol-Bold': 'Symbol',
  17982. 'Symbol-BoldItalic': 'Symbol',
  17983. 'Symbol-Italic': 'Symbol',
  17984. 'TimesNewRoman': 'Times-Roman',
  17985. 'TimesNewRoman-Bold': 'Times-Bold',
  17986. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  17987. 'TimesNewRoman-Italic': 'Times-Italic',
  17988. 'TimesNewRomanPS': 'Times-Roman',
  17989. 'TimesNewRomanPS-Bold': 'Times-Bold',
  17990. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  17991. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  17992. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  17993. 'TimesNewRomanPS-Italic': 'Times-Italic',
  17994. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  17995. 'TimesNewRomanPSMT': 'Times-Roman',
  17996. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  17997. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  17998. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  17999. };
  18000. /**
  18001. * Holds the map of the non-standard fonts that might be included as a standard
  18002. * fonts without glyph data.
  18003. */
  18004. var nonStdFontMap = {
  18005. 'ComicSansMS': 'Comic Sans MS',
  18006. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18007. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18008. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18009. 'LucidaConsole': 'Courier',
  18010. 'LucidaConsole-Bold': 'Courier-Bold',
  18011. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18012. 'LucidaConsole-Italic': 'Courier-Oblique',
  18013. 'MS-Gothic': 'MS Gothic',
  18014. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18015. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18016. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18017. 'MS-Mincho': 'MS Mincho',
  18018. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18019. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18020. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18021. 'MS-PGothic': 'MS PGothic',
  18022. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18023. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18024. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18025. 'MS-PMincho': 'MS PMincho',
  18026. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18027. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18028. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  18029. };
  18030. var serifFonts = {
  18031. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18032. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18033. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18034. 'Arno': true, 'Aster': true, 'Aurora': true,
  18035. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18036. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18037. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18038. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18039. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18040. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18041. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18042. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18043. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18044. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18045. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18046. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18047. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18048. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18049. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18050. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18051. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18052. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18053. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18054. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18055. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18056. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18057. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18058. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18059. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18060. 'Miller': true, 'Minion': true, 'Modern': true,
  18061. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18062. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18063. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18064. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18065. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18066. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18067. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18068. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18069. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18070. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18071. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18072. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18073. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18074. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18075. };
  18076. var symbolsFonts = {
  18077. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18078. };
  18079. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18080. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18081. // glyphs, but common for some set of the standard fonts.
  18082. var GlyphMapForStandardFonts = {
  18083. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18084. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18085. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18086. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18087. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18088. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18089. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18090. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18091. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18092. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18093. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18094. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18095. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18096. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18097. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18098. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18099. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18100. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18101. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18102. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18103. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18104. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18105. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18106. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18107. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18108. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18109. '227': 353, '229': 382, '234': 253, '253': 268, '254': 269, '258': 258,
  18110. '268': 283, '269': 313, '278': 328, '284': 345, '292': 367, '305': 963,
  18111. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18112. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18113. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18114. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18115. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18116. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18117. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18118. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18119. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18120. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18121. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18122. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18123. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18124. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18125. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18126. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18127. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18128. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18129. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18130. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18131. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18132. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18133. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18134. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18135. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18136. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18137. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18138. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18139. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18140. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18141. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18142. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18143. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18144. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18145. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18146. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18147. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18148. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18149. };
  18150. // Some characters, e.g. copyrightserif, mapped to the private use area and
  18151. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18152. // to the similar equivalents in the normal characters range.
  18153. function mapSpecialUnicodeValues(code) {
  18154. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  18155. return 0;
  18156. }
  18157. switch (code) {
  18158. case 0xF8E9: // copyrightsans
  18159. case 0xF6D9: // copyrightserif
  18160. return 0x00A9; // copyright
  18161. case 0xF8E8: // registersans
  18162. case 0xF6DA: // registerserif
  18163. return 0x00AE; // registered
  18164. case 0xF8EA: // trademarksans
  18165. case 0xF6DB: // trademarkserif
  18166. return 0x2122; // trademark
  18167. default:
  18168. return code;
  18169. }
  18170. }
  18171. var UnicodeRanges = [
  18172. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  18173. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  18174. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  18175. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  18176. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  18177. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  18178. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  18179. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  18180. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  18181. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  18182. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  18183. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  18184. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  18185. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  18186. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  18187. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  18188. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  18189. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  18190. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  18191. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  18192. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  18193. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  18194. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  18195. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  18196. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  18197. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  18198. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  18199. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  18200. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  18201. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  18202. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  18203. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  18204. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  18205. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  18206. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  18207. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  18208. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  18209. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  18210. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  18211. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  18212. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  18213. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  18214. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  18215. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  18216. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  18217. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  18218. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  18219. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  18220. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  18221. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  18222. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  18223. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  18224. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  18225. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  18226. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  18227. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  18228. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  18229. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  18230. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  18231. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  18232. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  18233. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  18234. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  18235. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  18236. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  18237. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  18238. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  18239. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  18240. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  18241. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  18242. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  18243. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  18244. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  18245. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  18246. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  18247. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  18248. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  18249. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  18250. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  18251. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  18252. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  18253. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  18254. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  18255. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  18256. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  18257. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  18258. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  18259. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  18260. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  18261. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  18262. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  18263. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  18264. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  18265. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  18266. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  18267. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  18268. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  18269. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  18270. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  18271. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  18272. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  18273. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  18274. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  18275. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  18276. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  18277. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  18278. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  18279. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  18280. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  18281. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  18282. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  18283. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  18284. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  18285. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  18286. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  18287. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  18288. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  18289. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  18290. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  18291. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  18292. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  18293. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  18294. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  18295. ];
  18296. var MacStandardGlyphOrdering = [
  18297. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  18298. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  18299. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  18300. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  18301. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  18302. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  18303. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  18304. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  18305. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  18306. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  18307. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  18308. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  18309. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18310. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  18311. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  18312. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  18313. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  18314. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  18315. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  18316. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  18317. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  18318. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  18319. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  18320. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  18321. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  18322. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  18323. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  18324. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  18325. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  18326. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  18327. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  18328. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  18329. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  18330. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  18331. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  18332. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  18333. function getUnicodeRangeFor(value) {
  18334. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  18335. var range = UnicodeRanges[i];
  18336. if (value >= range.begin && value < range.end) {
  18337. return i;
  18338. }
  18339. }
  18340. return -1;
  18341. }
  18342. function isRTLRangeFor(value) {
  18343. var range = UnicodeRanges[13];
  18344. if (value >= range.begin && value < range.end) {
  18345. return true;
  18346. }
  18347. range = UnicodeRanges[11];
  18348. if (value >= range.begin && value < range.end) {
  18349. return true;
  18350. }
  18351. return false;
  18352. }
  18353. // The normalization table is obtained by filtering the Unicode characters
  18354. // database with <compat> entries.
  18355. var NormalizedUnicodes = {
  18356. '\u00A8': '\u0020\u0308',
  18357. '\u00AF': '\u0020\u0304',
  18358. '\u00B4': '\u0020\u0301',
  18359. '\u00B5': '\u03BC',
  18360. '\u00B8': '\u0020\u0327',
  18361. '\u0132': '\u0049\u004A',
  18362. '\u0133': '\u0069\u006A',
  18363. '\u013F': '\u004C\u00B7',
  18364. '\u0140': '\u006C\u00B7',
  18365. '\u0149': '\u02BC\u006E',
  18366. '\u017F': '\u0073',
  18367. '\u01C4': '\u0044\u017D',
  18368. '\u01C5': '\u0044\u017E',
  18369. '\u01C6': '\u0064\u017E',
  18370. '\u01C7': '\u004C\u004A',
  18371. '\u01C8': '\u004C\u006A',
  18372. '\u01C9': '\u006C\u006A',
  18373. '\u01CA': '\u004E\u004A',
  18374. '\u01CB': '\u004E\u006A',
  18375. '\u01CC': '\u006E\u006A',
  18376. '\u01F1': '\u0044\u005A',
  18377. '\u01F2': '\u0044\u007A',
  18378. '\u01F3': '\u0064\u007A',
  18379. '\u02D8': '\u0020\u0306',
  18380. '\u02D9': '\u0020\u0307',
  18381. '\u02DA': '\u0020\u030A',
  18382. '\u02DB': '\u0020\u0328',
  18383. '\u02DC': '\u0020\u0303',
  18384. '\u02DD': '\u0020\u030B',
  18385. '\u037A': '\u0020\u0345',
  18386. '\u0384': '\u0020\u0301',
  18387. '\u03D0': '\u03B2',
  18388. '\u03D1': '\u03B8',
  18389. '\u03D2': '\u03A5',
  18390. '\u03D5': '\u03C6',
  18391. '\u03D6': '\u03C0',
  18392. '\u03F0': '\u03BA',
  18393. '\u03F1': '\u03C1',
  18394. '\u03F2': '\u03C2',
  18395. '\u03F4': '\u0398',
  18396. '\u03F5': '\u03B5',
  18397. '\u03F9': '\u03A3',
  18398. '\u0587': '\u0565\u0582',
  18399. '\u0675': '\u0627\u0674',
  18400. '\u0676': '\u0648\u0674',
  18401. '\u0677': '\u06C7\u0674',
  18402. '\u0678': '\u064A\u0674',
  18403. '\u0E33': '\u0E4D\u0E32',
  18404. '\u0EB3': '\u0ECD\u0EB2',
  18405. '\u0EDC': '\u0EAB\u0E99',
  18406. '\u0EDD': '\u0EAB\u0EA1',
  18407. '\u0F77': '\u0FB2\u0F81',
  18408. '\u0F79': '\u0FB3\u0F81',
  18409. '\u1E9A': '\u0061\u02BE',
  18410. '\u1FBD': '\u0020\u0313',
  18411. '\u1FBF': '\u0020\u0313',
  18412. '\u1FC0': '\u0020\u0342',
  18413. '\u1FFE': '\u0020\u0314',
  18414. '\u2002': '\u0020',
  18415. '\u2003': '\u0020',
  18416. '\u2004': '\u0020',
  18417. '\u2005': '\u0020',
  18418. '\u2006': '\u0020',
  18419. '\u2008': '\u0020',
  18420. '\u2009': '\u0020',
  18421. '\u200A': '\u0020',
  18422. '\u2017': '\u0020\u0333',
  18423. '\u2024': '\u002E',
  18424. '\u2025': '\u002E\u002E',
  18425. '\u2026': '\u002E\u002E\u002E',
  18426. '\u2033': '\u2032\u2032',
  18427. '\u2034': '\u2032\u2032\u2032',
  18428. '\u2036': '\u2035\u2035',
  18429. '\u2037': '\u2035\u2035\u2035',
  18430. '\u203C': '\u0021\u0021',
  18431. '\u203E': '\u0020\u0305',
  18432. '\u2047': '\u003F\u003F',
  18433. '\u2048': '\u003F\u0021',
  18434. '\u2049': '\u0021\u003F',
  18435. '\u2057': '\u2032\u2032\u2032\u2032',
  18436. '\u205F': '\u0020',
  18437. '\u20A8': '\u0052\u0073',
  18438. '\u2100': '\u0061\u002F\u0063',
  18439. '\u2101': '\u0061\u002F\u0073',
  18440. '\u2103': '\u00B0\u0043',
  18441. '\u2105': '\u0063\u002F\u006F',
  18442. '\u2106': '\u0063\u002F\u0075',
  18443. '\u2107': '\u0190',
  18444. '\u2109': '\u00B0\u0046',
  18445. '\u2116': '\u004E\u006F',
  18446. '\u2121': '\u0054\u0045\u004C',
  18447. '\u2135': '\u05D0',
  18448. '\u2136': '\u05D1',
  18449. '\u2137': '\u05D2',
  18450. '\u2138': '\u05D3',
  18451. '\u213B': '\u0046\u0041\u0058',
  18452. '\u2160': '\u0049',
  18453. '\u2161': '\u0049\u0049',
  18454. '\u2162': '\u0049\u0049\u0049',
  18455. '\u2163': '\u0049\u0056',
  18456. '\u2164': '\u0056',
  18457. '\u2165': '\u0056\u0049',
  18458. '\u2166': '\u0056\u0049\u0049',
  18459. '\u2167': '\u0056\u0049\u0049\u0049',
  18460. '\u2168': '\u0049\u0058',
  18461. '\u2169': '\u0058',
  18462. '\u216A': '\u0058\u0049',
  18463. '\u216B': '\u0058\u0049\u0049',
  18464. '\u216C': '\u004C',
  18465. '\u216D': '\u0043',
  18466. '\u216E': '\u0044',
  18467. '\u216F': '\u004D',
  18468. '\u2170': '\u0069',
  18469. '\u2171': '\u0069\u0069',
  18470. '\u2172': '\u0069\u0069\u0069',
  18471. '\u2173': '\u0069\u0076',
  18472. '\u2174': '\u0076',
  18473. '\u2175': '\u0076\u0069',
  18474. '\u2176': '\u0076\u0069\u0069',
  18475. '\u2177': '\u0076\u0069\u0069\u0069',
  18476. '\u2178': '\u0069\u0078',
  18477. '\u2179': '\u0078',
  18478. '\u217A': '\u0078\u0069',
  18479. '\u217B': '\u0078\u0069\u0069',
  18480. '\u217C': '\u006C',
  18481. '\u217D': '\u0063',
  18482. '\u217E': '\u0064',
  18483. '\u217F': '\u006D',
  18484. '\u222C': '\u222B\u222B',
  18485. '\u222D': '\u222B\u222B\u222B',
  18486. '\u222F': '\u222E\u222E',
  18487. '\u2230': '\u222E\u222E\u222E',
  18488. '\u2474': '\u0028\u0031\u0029',
  18489. '\u2475': '\u0028\u0032\u0029',
  18490. '\u2476': '\u0028\u0033\u0029',
  18491. '\u2477': '\u0028\u0034\u0029',
  18492. '\u2478': '\u0028\u0035\u0029',
  18493. '\u2479': '\u0028\u0036\u0029',
  18494. '\u247A': '\u0028\u0037\u0029',
  18495. '\u247B': '\u0028\u0038\u0029',
  18496. '\u247C': '\u0028\u0039\u0029',
  18497. '\u247D': '\u0028\u0031\u0030\u0029',
  18498. '\u247E': '\u0028\u0031\u0031\u0029',
  18499. '\u247F': '\u0028\u0031\u0032\u0029',
  18500. '\u2480': '\u0028\u0031\u0033\u0029',
  18501. '\u2481': '\u0028\u0031\u0034\u0029',
  18502. '\u2482': '\u0028\u0031\u0035\u0029',
  18503. '\u2483': '\u0028\u0031\u0036\u0029',
  18504. '\u2484': '\u0028\u0031\u0037\u0029',
  18505. '\u2485': '\u0028\u0031\u0038\u0029',
  18506. '\u2486': '\u0028\u0031\u0039\u0029',
  18507. '\u2487': '\u0028\u0032\u0030\u0029',
  18508. '\u2488': '\u0031\u002E',
  18509. '\u2489': '\u0032\u002E',
  18510. '\u248A': '\u0033\u002E',
  18511. '\u248B': '\u0034\u002E',
  18512. '\u248C': '\u0035\u002E',
  18513. '\u248D': '\u0036\u002E',
  18514. '\u248E': '\u0037\u002E',
  18515. '\u248F': '\u0038\u002E',
  18516. '\u2490': '\u0039\u002E',
  18517. '\u2491': '\u0031\u0030\u002E',
  18518. '\u2492': '\u0031\u0031\u002E',
  18519. '\u2493': '\u0031\u0032\u002E',
  18520. '\u2494': '\u0031\u0033\u002E',
  18521. '\u2495': '\u0031\u0034\u002E',
  18522. '\u2496': '\u0031\u0035\u002E',
  18523. '\u2497': '\u0031\u0036\u002E',
  18524. '\u2498': '\u0031\u0037\u002E',
  18525. '\u2499': '\u0031\u0038\u002E',
  18526. '\u249A': '\u0031\u0039\u002E',
  18527. '\u249B': '\u0032\u0030\u002E',
  18528. '\u249C': '\u0028\u0061\u0029',
  18529. '\u249D': '\u0028\u0062\u0029',
  18530. '\u249E': '\u0028\u0063\u0029',
  18531. '\u249F': '\u0028\u0064\u0029',
  18532. '\u24A0': '\u0028\u0065\u0029',
  18533. '\u24A1': '\u0028\u0066\u0029',
  18534. '\u24A2': '\u0028\u0067\u0029',
  18535. '\u24A3': '\u0028\u0068\u0029',
  18536. '\u24A4': '\u0028\u0069\u0029',
  18537. '\u24A5': '\u0028\u006A\u0029',
  18538. '\u24A6': '\u0028\u006B\u0029',
  18539. '\u24A7': '\u0028\u006C\u0029',
  18540. '\u24A8': '\u0028\u006D\u0029',
  18541. '\u24A9': '\u0028\u006E\u0029',
  18542. '\u24AA': '\u0028\u006F\u0029',
  18543. '\u24AB': '\u0028\u0070\u0029',
  18544. '\u24AC': '\u0028\u0071\u0029',
  18545. '\u24AD': '\u0028\u0072\u0029',
  18546. '\u24AE': '\u0028\u0073\u0029',
  18547. '\u24AF': '\u0028\u0074\u0029',
  18548. '\u24B0': '\u0028\u0075\u0029',
  18549. '\u24B1': '\u0028\u0076\u0029',
  18550. '\u24B2': '\u0028\u0077\u0029',
  18551. '\u24B3': '\u0028\u0078\u0029',
  18552. '\u24B4': '\u0028\u0079\u0029',
  18553. '\u24B5': '\u0028\u007A\u0029',
  18554. '\u2A0C': '\u222B\u222B\u222B\u222B',
  18555. '\u2A74': '\u003A\u003A\u003D',
  18556. '\u2A75': '\u003D\u003D',
  18557. '\u2A76': '\u003D\u003D\u003D',
  18558. '\u2E9F': '\u6BCD',
  18559. '\u2EF3': '\u9F9F',
  18560. '\u2F00': '\u4E00',
  18561. '\u2F01': '\u4E28',
  18562. '\u2F02': '\u4E36',
  18563. '\u2F03': '\u4E3F',
  18564. '\u2F04': '\u4E59',
  18565. '\u2F05': '\u4E85',
  18566. '\u2F06': '\u4E8C',
  18567. '\u2F07': '\u4EA0',
  18568. '\u2F08': '\u4EBA',
  18569. '\u2F09': '\u513F',
  18570. '\u2F0A': '\u5165',
  18571. '\u2F0B': '\u516B',
  18572. '\u2F0C': '\u5182',
  18573. '\u2F0D': '\u5196',
  18574. '\u2F0E': '\u51AB',
  18575. '\u2F0F': '\u51E0',
  18576. '\u2F10': '\u51F5',
  18577. '\u2F11': '\u5200',
  18578. '\u2F12': '\u529B',
  18579. '\u2F13': '\u52F9',
  18580. '\u2F14': '\u5315',
  18581. '\u2F15': '\u531A',
  18582. '\u2F16': '\u5338',
  18583. '\u2F17': '\u5341',
  18584. '\u2F18': '\u535C',
  18585. '\u2F19': '\u5369',
  18586. '\u2F1A': '\u5382',
  18587. '\u2F1B': '\u53B6',
  18588. '\u2F1C': '\u53C8',
  18589. '\u2F1D': '\u53E3',
  18590. '\u2F1E': '\u56D7',
  18591. '\u2F1F': '\u571F',
  18592. '\u2F20': '\u58EB',
  18593. '\u2F21': '\u5902',
  18594. '\u2F22': '\u590A',
  18595. '\u2F23': '\u5915',
  18596. '\u2F24': '\u5927',
  18597. '\u2F25': '\u5973',
  18598. '\u2F26': '\u5B50',
  18599. '\u2F27': '\u5B80',
  18600. '\u2F28': '\u5BF8',
  18601. '\u2F29': '\u5C0F',
  18602. '\u2F2A': '\u5C22',
  18603. '\u2F2B': '\u5C38',
  18604. '\u2F2C': '\u5C6E',
  18605. '\u2F2D': '\u5C71',
  18606. '\u2F2E': '\u5DDB',
  18607. '\u2F2F': '\u5DE5',
  18608. '\u2F30': '\u5DF1',
  18609. '\u2F31': '\u5DFE',
  18610. '\u2F32': '\u5E72',
  18611. '\u2F33': '\u5E7A',
  18612. '\u2F34': '\u5E7F',
  18613. '\u2F35': '\u5EF4',
  18614. '\u2F36': '\u5EFE',
  18615. '\u2F37': '\u5F0B',
  18616. '\u2F38': '\u5F13',
  18617. '\u2F39': '\u5F50',
  18618. '\u2F3A': '\u5F61',
  18619. '\u2F3B': '\u5F73',
  18620. '\u2F3C': '\u5FC3',
  18621. '\u2F3D': '\u6208',
  18622. '\u2F3E': '\u6236',
  18623. '\u2F3F': '\u624B',
  18624. '\u2F40': '\u652F',
  18625. '\u2F41': '\u6534',
  18626. '\u2F42': '\u6587',
  18627. '\u2F43': '\u6597',
  18628. '\u2F44': '\u65A4',
  18629. '\u2F45': '\u65B9',
  18630. '\u2F46': '\u65E0',
  18631. '\u2F47': '\u65E5',
  18632. '\u2F48': '\u66F0',
  18633. '\u2F49': '\u6708',
  18634. '\u2F4A': '\u6728',
  18635. '\u2F4B': '\u6B20',
  18636. '\u2F4C': '\u6B62',
  18637. '\u2F4D': '\u6B79',
  18638. '\u2F4E': '\u6BB3',
  18639. '\u2F4F': '\u6BCB',
  18640. '\u2F50': '\u6BD4',
  18641. '\u2F51': '\u6BDB',
  18642. '\u2F52': '\u6C0F',
  18643. '\u2F53': '\u6C14',
  18644. '\u2F54': '\u6C34',
  18645. '\u2F55': '\u706B',
  18646. '\u2F56': '\u722A',
  18647. '\u2F57': '\u7236',
  18648. '\u2F58': '\u723B',
  18649. '\u2F59': '\u723F',
  18650. '\u2F5A': '\u7247',
  18651. '\u2F5B': '\u7259',
  18652. '\u2F5C': '\u725B',
  18653. '\u2F5D': '\u72AC',
  18654. '\u2F5E': '\u7384',
  18655. '\u2F5F': '\u7389',
  18656. '\u2F60': '\u74DC',
  18657. '\u2F61': '\u74E6',
  18658. '\u2F62': '\u7518',
  18659. '\u2F63': '\u751F',
  18660. '\u2F64': '\u7528',
  18661. '\u2F65': '\u7530',
  18662. '\u2F66': '\u758B',
  18663. '\u2F67': '\u7592',
  18664. '\u2F68': '\u7676',
  18665. '\u2F69': '\u767D',
  18666. '\u2F6A': '\u76AE',
  18667. '\u2F6B': '\u76BF',
  18668. '\u2F6C': '\u76EE',
  18669. '\u2F6D': '\u77DB',
  18670. '\u2F6E': '\u77E2',
  18671. '\u2F6F': '\u77F3',
  18672. '\u2F70': '\u793A',
  18673. '\u2F71': '\u79B8',
  18674. '\u2F72': '\u79BE',
  18675. '\u2F73': '\u7A74',
  18676. '\u2F74': '\u7ACB',
  18677. '\u2F75': '\u7AF9',
  18678. '\u2F76': '\u7C73',
  18679. '\u2F77': '\u7CF8',
  18680. '\u2F78': '\u7F36',
  18681. '\u2F79': '\u7F51',
  18682. '\u2F7A': '\u7F8A',
  18683. '\u2F7B': '\u7FBD',
  18684. '\u2F7C': '\u8001',
  18685. '\u2F7D': '\u800C',
  18686. '\u2F7E': '\u8012',
  18687. '\u2F7F': '\u8033',
  18688. '\u2F80': '\u807F',
  18689. '\u2F81': '\u8089',
  18690. '\u2F82': '\u81E3',
  18691. '\u2F83': '\u81EA',
  18692. '\u2F84': '\u81F3',
  18693. '\u2F85': '\u81FC',
  18694. '\u2F86': '\u820C',
  18695. '\u2F87': '\u821B',
  18696. '\u2F88': '\u821F',
  18697. '\u2F89': '\u826E',
  18698. '\u2F8A': '\u8272',
  18699. '\u2F8B': '\u8278',
  18700. '\u2F8C': '\u864D',
  18701. '\u2F8D': '\u866B',
  18702. '\u2F8E': '\u8840',
  18703. '\u2F8F': '\u884C',
  18704. '\u2F90': '\u8863',
  18705. '\u2F91': '\u897E',
  18706. '\u2F92': '\u898B',
  18707. '\u2F93': '\u89D2',
  18708. '\u2F94': '\u8A00',
  18709. '\u2F95': '\u8C37',
  18710. '\u2F96': '\u8C46',
  18711. '\u2F97': '\u8C55',
  18712. '\u2F98': '\u8C78',
  18713. '\u2F99': '\u8C9D',
  18714. '\u2F9A': '\u8D64',
  18715. '\u2F9B': '\u8D70',
  18716. '\u2F9C': '\u8DB3',
  18717. '\u2F9D': '\u8EAB',
  18718. '\u2F9E': '\u8ECA',
  18719. '\u2F9F': '\u8F9B',
  18720. '\u2FA0': '\u8FB0',
  18721. '\u2FA1': '\u8FB5',
  18722. '\u2FA2': '\u9091',
  18723. '\u2FA3': '\u9149',
  18724. '\u2FA4': '\u91C6',
  18725. '\u2FA5': '\u91CC',
  18726. '\u2FA6': '\u91D1',
  18727. '\u2FA7': '\u9577',
  18728. '\u2FA8': '\u9580',
  18729. '\u2FA9': '\u961C',
  18730. '\u2FAA': '\u96B6',
  18731. '\u2FAB': '\u96B9',
  18732. '\u2FAC': '\u96E8',
  18733. '\u2FAD': '\u9751',
  18734. '\u2FAE': '\u975E',
  18735. '\u2FAF': '\u9762',
  18736. '\u2FB0': '\u9769',
  18737. '\u2FB1': '\u97CB',
  18738. '\u2FB2': '\u97ED',
  18739. '\u2FB3': '\u97F3',
  18740. '\u2FB4': '\u9801',
  18741. '\u2FB5': '\u98A8',
  18742. '\u2FB6': '\u98DB',
  18743. '\u2FB7': '\u98DF',
  18744. '\u2FB8': '\u9996',
  18745. '\u2FB9': '\u9999',
  18746. '\u2FBA': '\u99AC',
  18747. '\u2FBB': '\u9AA8',
  18748. '\u2FBC': '\u9AD8',
  18749. '\u2FBD': '\u9ADF',
  18750. '\u2FBE': '\u9B25',
  18751. '\u2FBF': '\u9B2F',
  18752. '\u2FC0': '\u9B32',
  18753. '\u2FC1': '\u9B3C',
  18754. '\u2FC2': '\u9B5A',
  18755. '\u2FC3': '\u9CE5',
  18756. '\u2FC4': '\u9E75',
  18757. '\u2FC5': '\u9E7F',
  18758. '\u2FC6': '\u9EA5',
  18759. '\u2FC7': '\u9EBB',
  18760. '\u2FC8': '\u9EC3',
  18761. '\u2FC9': '\u9ECD',
  18762. '\u2FCA': '\u9ED1',
  18763. '\u2FCB': '\u9EF9',
  18764. '\u2FCC': '\u9EFD',
  18765. '\u2FCD': '\u9F0E',
  18766. '\u2FCE': '\u9F13',
  18767. '\u2FCF': '\u9F20',
  18768. '\u2FD0': '\u9F3B',
  18769. '\u2FD1': '\u9F4A',
  18770. '\u2FD2': '\u9F52',
  18771. '\u2FD3': '\u9F8D',
  18772. '\u2FD4': '\u9F9C',
  18773. '\u2FD5': '\u9FA0',
  18774. '\u3036': '\u3012',
  18775. '\u3038': '\u5341',
  18776. '\u3039': '\u5344',
  18777. '\u303A': '\u5345',
  18778. '\u309B': '\u0020\u3099',
  18779. '\u309C': '\u0020\u309A',
  18780. '\u3131': '\u1100',
  18781. '\u3132': '\u1101',
  18782. '\u3133': '\u11AA',
  18783. '\u3134': '\u1102',
  18784. '\u3135': '\u11AC',
  18785. '\u3136': '\u11AD',
  18786. '\u3137': '\u1103',
  18787. '\u3138': '\u1104',
  18788. '\u3139': '\u1105',
  18789. '\u313A': '\u11B0',
  18790. '\u313B': '\u11B1',
  18791. '\u313C': '\u11B2',
  18792. '\u313D': '\u11B3',
  18793. '\u313E': '\u11B4',
  18794. '\u313F': '\u11B5',
  18795. '\u3140': '\u111A',
  18796. '\u3141': '\u1106',
  18797. '\u3142': '\u1107',
  18798. '\u3143': '\u1108',
  18799. '\u3144': '\u1121',
  18800. '\u3145': '\u1109',
  18801. '\u3146': '\u110A',
  18802. '\u3147': '\u110B',
  18803. '\u3148': '\u110C',
  18804. '\u3149': '\u110D',
  18805. '\u314A': '\u110E',
  18806. '\u314B': '\u110F',
  18807. '\u314C': '\u1110',
  18808. '\u314D': '\u1111',
  18809. '\u314E': '\u1112',
  18810. '\u314F': '\u1161',
  18811. '\u3150': '\u1162',
  18812. '\u3151': '\u1163',
  18813. '\u3152': '\u1164',
  18814. '\u3153': '\u1165',
  18815. '\u3154': '\u1166',
  18816. '\u3155': '\u1167',
  18817. '\u3156': '\u1168',
  18818. '\u3157': '\u1169',
  18819. '\u3158': '\u116A',
  18820. '\u3159': '\u116B',
  18821. '\u315A': '\u116C',
  18822. '\u315B': '\u116D',
  18823. '\u315C': '\u116E',
  18824. '\u315D': '\u116F',
  18825. '\u315E': '\u1170',
  18826. '\u315F': '\u1171',
  18827. '\u3160': '\u1172',
  18828. '\u3161': '\u1173',
  18829. '\u3162': '\u1174',
  18830. '\u3163': '\u1175',
  18831. '\u3164': '\u1160',
  18832. '\u3165': '\u1114',
  18833. '\u3166': '\u1115',
  18834. '\u3167': '\u11C7',
  18835. '\u3168': '\u11C8',
  18836. '\u3169': '\u11CC',
  18837. '\u316A': '\u11CE',
  18838. '\u316B': '\u11D3',
  18839. '\u316C': '\u11D7',
  18840. '\u316D': '\u11D9',
  18841. '\u316E': '\u111C',
  18842. '\u316F': '\u11DD',
  18843. '\u3170': '\u11DF',
  18844. '\u3171': '\u111D',
  18845. '\u3172': '\u111E',
  18846. '\u3173': '\u1120',
  18847. '\u3174': '\u1122',
  18848. '\u3175': '\u1123',
  18849. '\u3176': '\u1127',
  18850. '\u3177': '\u1129',
  18851. '\u3178': '\u112B',
  18852. '\u3179': '\u112C',
  18853. '\u317A': '\u112D',
  18854. '\u317B': '\u112E',
  18855. '\u317C': '\u112F',
  18856. '\u317D': '\u1132',
  18857. '\u317E': '\u1136',
  18858. '\u317F': '\u1140',
  18859. '\u3180': '\u1147',
  18860. '\u3181': '\u114C',
  18861. '\u3182': '\u11F1',
  18862. '\u3183': '\u11F2',
  18863. '\u3184': '\u1157',
  18864. '\u3185': '\u1158',
  18865. '\u3186': '\u1159',
  18866. '\u3187': '\u1184',
  18867. '\u3188': '\u1185',
  18868. '\u3189': '\u1188',
  18869. '\u318A': '\u1191',
  18870. '\u318B': '\u1192',
  18871. '\u318C': '\u1194',
  18872. '\u318D': '\u119E',
  18873. '\u318E': '\u11A1',
  18874. '\u3200': '\u0028\u1100\u0029',
  18875. '\u3201': '\u0028\u1102\u0029',
  18876. '\u3202': '\u0028\u1103\u0029',
  18877. '\u3203': '\u0028\u1105\u0029',
  18878. '\u3204': '\u0028\u1106\u0029',
  18879. '\u3205': '\u0028\u1107\u0029',
  18880. '\u3206': '\u0028\u1109\u0029',
  18881. '\u3207': '\u0028\u110B\u0029',
  18882. '\u3208': '\u0028\u110C\u0029',
  18883. '\u3209': '\u0028\u110E\u0029',
  18884. '\u320A': '\u0028\u110F\u0029',
  18885. '\u320B': '\u0028\u1110\u0029',
  18886. '\u320C': '\u0028\u1111\u0029',
  18887. '\u320D': '\u0028\u1112\u0029',
  18888. '\u320E': '\u0028\u1100\u1161\u0029',
  18889. '\u320F': '\u0028\u1102\u1161\u0029',
  18890. '\u3210': '\u0028\u1103\u1161\u0029',
  18891. '\u3211': '\u0028\u1105\u1161\u0029',
  18892. '\u3212': '\u0028\u1106\u1161\u0029',
  18893. '\u3213': '\u0028\u1107\u1161\u0029',
  18894. '\u3214': '\u0028\u1109\u1161\u0029',
  18895. '\u3215': '\u0028\u110B\u1161\u0029',
  18896. '\u3216': '\u0028\u110C\u1161\u0029',
  18897. '\u3217': '\u0028\u110E\u1161\u0029',
  18898. '\u3218': '\u0028\u110F\u1161\u0029',
  18899. '\u3219': '\u0028\u1110\u1161\u0029',
  18900. '\u321A': '\u0028\u1111\u1161\u0029',
  18901. '\u321B': '\u0028\u1112\u1161\u0029',
  18902. '\u321C': '\u0028\u110C\u116E\u0029',
  18903. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  18904. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  18905. '\u3220': '\u0028\u4E00\u0029',
  18906. '\u3221': '\u0028\u4E8C\u0029',
  18907. '\u3222': '\u0028\u4E09\u0029',
  18908. '\u3223': '\u0028\u56DB\u0029',
  18909. '\u3224': '\u0028\u4E94\u0029',
  18910. '\u3225': '\u0028\u516D\u0029',
  18911. '\u3226': '\u0028\u4E03\u0029',
  18912. '\u3227': '\u0028\u516B\u0029',
  18913. '\u3228': '\u0028\u4E5D\u0029',
  18914. '\u3229': '\u0028\u5341\u0029',
  18915. '\u322A': '\u0028\u6708\u0029',
  18916. '\u322B': '\u0028\u706B\u0029',
  18917. '\u322C': '\u0028\u6C34\u0029',
  18918. '\u322D': '\u0028\u6728\u0029',
  18919. '\u322E': '\u0028\u91D1\u0029',
  18920. '\u322F': '\u0028\u571F\u0029',
  18921. '\u3230': '\u0028\u65E5\u0029',
  18922. '\u3231': '\u0028\u682A\u0029',
  18923. '\u3232': '\u0028\u6709\u0029',
  18924. '\u3233': '\u0028\u793E\u0029',
  18925. '\u3234': '\u0028\u540D\u0029',
  18926. '\u3235': '\u0028\u7279\u0029',
  18927. '\u3236': '\u0028\u8CA1\u0029',
  18928. '\u3237': '\u0028\u795D\u0029',
  18929. '\u3238': '\u0028\u52B4\u0029',
  18930. '\u3239': '\u0028\u4EE3\u0029',
  18931. '\u323A': '\u0028\u547C\u0029',
  18932. '\u323B': '\u0028\u5B66\u0029',
  18933. '\u323C': '\u0028\u76E3\u0029',
  18934. '\u323D': '\u0028\u4F01\u0029',
  18935. '\u323E': '\u0028\u8CC7\u0029',
  18936. '\u323F': '\u0028\u5354\u0029',
  18937. '\u3240': '\u0028\u796D\u0029',
  18938. '\u3241': '\u0028\u4F11\u0029',
  18939. '\u3242': '\u0028\u81EA\u0029',
  18940. '\u3243': '\u0028\u81F3\u0029',
  18941. '\u32C0': '\u0031\u6708',
  18942. '\u32C1': '\u0032\u6708',
  18943. '\u32C2': '\u0033\u6708',
  18944. '\u32C3': '\u0034\u6708',
  18945. '\u32C4': '\u0035\u6708',
  18946. '\u32C5': '\u0036\u6708',
  18947. '\u32C6': '\u0037\u6708',
  18948. '\u32C7': '\u0038\u6708',
  18949. '\u32C8': '\u0039\u6708',
  18950. '\u32C9': '\u0031\u0030\u6708',
  18951. '\u32CA': '\u0031\u0031\u6708',
  18952. '\u32CB': '\u0031\u0032\u6708',
  18953. '\u3358': '\u0030\u70B9',
  18954. '\u3359': '\u0031\u70B9',
  18955. '\u335A': '\u0032\u70B9',
  18956. '\u335B': '\u0033\u70B9',
  18957. '\u335C': '\u0034\u70B9',
  18958. '\u335D': '\u0035\u70B9',
  18959. '\u335E': '\u0036\u70B9',
  18960. '\u335F': '\u0037\u70B9',
  18961. '\u3360': '\u0038\u70B9',
  18962. '\u3361': '\u0039\u70B9',
  18963. '\u3362': '\u0031\u0030\u70B9',
  18964. '\u3363': '\u0031\u0031\u70B9',
  18965. '\u3364': '\u0031\u0032\u70B9',
  18966. '\u3365': '\u0031\u0033\u70B9',
  18967. '\u3366': '\u0031\u0034\u70B9',
  18968. '\u3367': '\u0031\u0035\u70B9',
  18969. '\u3368': '\u0031\u0036\u70B9',
  18970. '\u3369': '\u0031\u0037\u70B9',
  18971. '\u336A': '\u0031\u0038\u70B9',
  18972. '\u336B': '\u0031\u0039\u70B9',
  18973. '\u336C': '\u0032\u0030\u70B9',
  18974. '\u336D': '\u0032\u0031\u70B9',
  18975. '\u336E': '\u0032\u0032\u70B9',
  18976. '\u336F': '\u0032\u0033\u70B9',
  18977. '\u3370': '\u0032\u0034\u70B9',
  18978. '\u33E0': '\u0031\u65E5',
  18979. '\u33E1': '\u0032\u65E5',
  18980. '\u33E2': '\u0033\u65E5',
  18981. '\u33E3': '\u0034\u65E5',
  18982. '\u33E4': '\u0035\u65E5',
  18983. '\u33E5': '\u0036\u65E5',
  18984. '\u33E6': '\u0037\u65E5',
  18985. '\u33E7': '\u0038\u65E5',
  18986. '\u33E8': '\u0039\u65E5',
  18987. '\u33E9': '\u0031\u0030\u65E5',
  18988. '\u33EA': '\u0031\u0031\u65E5',
  18989. '\u33EB': '\u0031\u0032\u65E5',
  18990. '\u33EC': '\u0031\u0033\u65E5',
  18991. '\u33ED': '\u0031\u0034\u65E5',
  18992. '\u33EE': '\u0031\u0035\u65E5',
  18993. '\u33EF': '\u0031\u0036\u65E5',
  18994. '\u33F0': '\u0031\u0037\u65E5',
  18995. '\u33F1': '\u0031\u0038\u65E5',
  18996. '\u33F2': '\u0031\u0039\u65E5',
  18997. '\u33F3': '\u0032\u0030\u65E5',
  18998. '\u33F4': '\u0032\u0031\u65E5',
  18999. '\u33F5': '\u0032\u0032\u65E5',
  19000. '\u33F6': '\u0032\u0033\u65E5',
  19001. '\u33F7': '\u0032\u0034\u65E5',
  19002. '\u33F8': '\u0032\u0035\u65E5',
  19003. '\u33F9': '\u0032\u0036\u65E5',
  19004. '\u33FA': '\u0032\u0037\u65E5',
  19005. '\u33FB': '\u0032\u0038\u65E5',
  19006. '\u33FC': '\u0032\u0039\u65E5',
  19007. '\u33FD': '\u0033\u0030\u65E5',
  19008. '\u33FE': '\u0033\u0031\u65E5',
  19009. '\uFB00': '\u0066\u0066',
  19010. '\uFB01': '\u0066\u0069',
  19011. '\uFB02': '\u0066\u006C',
  19012. '\uFB03': '\u0066\u0066\u0069',
  19013. '\uFB04': '\u0066\u0066\u006C',
  19014. '\uFB05': '\u017F\u0074',
  19015. '\uFB06': '\u0073\u0074',
  19016. '\uFB13': '\u0574\u0576',
  19017. '\uFB14': '\u0574\u0565',
  19018. '\uFB15': '\u0574\u056B',
  19019. '\uFB16': '\u057E\u0576',
  19020. '\uFB17': '\u0574\u056D',
  19021. '\uFB4F': '\u05D0\u05DC',
  19022. '\uFB50': '\u0671',
  19023. '\uFB51': '\u0671',
  19024. '\uFB52': '\u067B',
  19025. '\uFB53': '\u067B',
  19026. '\uFB54': '\u067B',
  19027. '\uFB55': '\u067B',
  19028. '\uFB56': '\u067E',
  19029. '\uFB57': '\u067E',
  19030. '\uFB58': '\u067E',
  19031. '\uFB59': '\u067E',
  19032. '\uFB5A': '\u0680',
  19033. '\uFB5B': '\u0680',
  19034. '\uFB5C': '\u0680',
  19035. '\uFB5D': '\u0680',
  19036. '\uFB5E': '\u067A',
  19037. '\uFB5F': '\u067A',
  19038. '\uFB60': '\u067A',
  19039. '\uFB61': '\u067A',
  19040. '\uFB62': '\u067F',
  19041. '\uFB63': '\u067F',
  19042. '\uFB64': '\u067F',
  19043. '\uFB65': '\u067F',
  19044. '\uFB66': '\u0679',
  19045. '\uFB67': '\u0679',
  19046. '\uFB68': '\u0679',
  19047. '\uFB69': '\u0679',
  19048. '\uFB6A': '\u06A4',
  19049. '\uFB6B': '\u06A4',
  19050. '\uFB6C': '\u06A4',
  19051. '\uFB6D': '\u06A4',
  19052. '\uFB6E': '\u06A6',
  19053. '\uFB6F': '\u06A6',
  19054. '\uFB70': '\u06A6',
  19055. '\uFB71': '\u06A6',
  19056. '\uFB72': '\u0684',
  19057. '\uFB73': '\u0684',
  19058. '\uFB74': '\u0684',
  19059. '\uFB75': '\u0684',
  19060. '\uFB76': '\u0683',
  19061. '\uFB77': '\u0683',
  19062. '\uFB78': '\u0683',
  19063. '\uFB79': '\u0683',
  19064. '\uFB7A': '\u0686',
  19065. '\uFB7B': '\u0686',
  19066. '\uFB7C': '\u0686',
  19067. '\uFB7D': '\u0686',
  19068. '\uFB7E': '\u0687',
  19069. '\uFB7F': '\u0687',
  19070. '\uFB80': '\u0687',
  19071. '\uFB81': '\u0687',
  19072. '\uFB82': '\u068D',
  19073. '\uFB83': '\u068D',
  19074. '\uFB84': '\u068C',
  19075. '\uFB85': '\u068C',
  19076. '\uFB86': '\u068E',
  19077. '\uFB87': '\u068E',
  19078. '\uFB88': '\u0688',
  19079. '\uFB89': '\u0688',
  19080. '\uFB8A': '\u0698',
  19081. '\uFB8B': '\u0698',
  19082. '\uFB8C': '\u0691',
  19083. '\uFB8D': '\u0691',
  19084. '\uFB8E': '\u06A9',
  19085. '\uFB8F': '\u06A9',
  19086. '\uFB90': '\u06A9',
  19087. '\uFB91': '\u06A9',
  19088. '\uFB92': '\u06AF',
  19089. '\uFB93': '\u06AF',
  19090. '\uFB94': '\u06AF',
  19091. '\uFB95': '\u06AF',
  19092. '\uFB96': '\u06B3',
  19093. '\uFB97': '\u06B3',
  19094. '\uFB98': '\u06B3',
  19095. '\uFB99': '\u06B3',
  19096. '\uFB9A': '\u06B1',
  19097. '\uFB9B': '\u06B1',
  19098. '\uFB9C': '\u06B1',
  19099. '\uFB9D': '\u06B1',
  19100. '\uFB9E': '\u06BA',
  19101. '\uFB9F': '\u06BA',
  19102. '\uFBA0': '\u06BB',
  19103. '\uFBA1': '\u06BB',
  19104. '\uFBA2': '\u06BB',
  19105. '\uFBA3': '\u06BB',
  19106. '\uFBA4': '\u06C0',
  19107. '\uFBA5': '\u06C0',
  19108. '\uFBA6': '\u06C1',
  19109. '\uFBA7': '\u06C1',
  19110. '\uFBA8': '\u06C1',
  19111. '\uFBA9': '\u06C1',
  19112. '\uFBAA': '\u06BE',
  19113. '\uFBAB': '\u06BE',
  19114. '\uFBAC': '\u06BE',
  19115. '\uFBAD': '\u06BE',
  19116. '\uFBAE': '\u06D2',
  19117. '\uFBAF': '\u06D2',
  19118. '\uFBB0': '\u06D3',
  19119. '\uFBB1': '\u06D3',
  19120. '\uFBD3': '\u06AD',
  19121. '\uFBD4': '\u06AD',
  19122. '\uFBD5': '\u06AD',
  19123. '\uFBD6': '\u06AD',
  19124. '\uFBD7': '\u06C7',
  19125. '\uFBD8': '\u06C7',
  19126. '\uFBD9': '\u06C6',
  19127. '\uFBDA': '\u06C6',
  19128. '\uFBDB': '\u06C8',
  19129. '\uFBDC': '\u06C8',
  19130. '\uFBDD': '\u0677',
  19131. '\uFBDE': '\u06CB',
  19132. '\uFBDF': '\u06CB',
  19133. '\uFBE0': '\u06C5',
  19134. '\uFBE1': '\u06C5',
  19135. '\uFBE2': '\u06C9',
  19136. '\uFBE3': '\u06C9',
  19137. '\uFBE4': '\u06D0',
  19138. '\uFBE5': '\u06D0',
  19139. '\uFBE6': '\u06D0',
  19140. '\uFBE7': '\u06D0',
  19141. '\uFBE8': '\u0649',
  19142. '\uFBE9': '\u0649',
  19143. '\uFBEA': '\u0626\u0627',
  19144. '\uFBEB': '\u0626\u0627',
  19145. '\uFBEC': '\u0626\u06D5',
  19146. '\uFBED': '\u0626\u06D5',
  19147. '\uFBEE': '\u0626\u0648',
  19148. '\uFBEF': '\u0626\u0648',
  19149. '\uFBF0': '\u0626\u06C7',
  19150. '\uFBF1': '\u0626\u06C7',
  19151. '\uFBF2': '\u0626\u06C6',
  19152. '\uFBF3': '\u0626\u06C6',
  19153. '\uFBF4': '\u0626\u06C8',
  19154. '\uFBF5': '\u0626\u06C8',
  19155. '\uFBF6': '\u0626\u06D0',
  19156. '\uFBF7': '\u0626\u06D0',
  19157. '\uFBF8': '\u0626\u06D0',
  19158. '\uFBF9': '\u0626\u0649',
  19159. '\uFBFA': '\u0626\u0649',
  19160. '\uFBFB': '\u0626\u0649',
  19161. '\uFBFC': '\u06CC',
  19162. '\uFBFD': '\u06CC',
  19163. '\uFBFE': '\u06CC',
  19164. '\uFBFF': '\u06CC',
  19165. '\uFC00': '\u0626\u062C',
  19166. '\uFC01': '\u0626\u062D',
  19167. '\uFC02': '\u0626\u0645',
  19168. '\uFC03': '\u0626\u0649',
  19169. '\uFC04': '\u0626\u064A',
  19170. '\uFC05': '\u0628\u062C',
  19171. '\uFC06': '\u0628\u062D',
  19172. '\uFC07': '\u0628\u062E',
  19173. '\uFC08': '\u0628\u0645',
  19174. '\uFC09': '\u0628\u0649',
  19175. '\uFC0A': '\u0628\u064A',
  19176. '\uFC0B': '\u062A\u062C',
  19177. '\uFC0C': '\u062A\u062D',
  19178. '\uFC0D': '\u062A\u062E',
  19179. '\uFC0E': '\u062A\u0645',
  19180. '\uFC0F': '\u062A\u0649',
  19181. '\uFC10': '\u062A\u064A',
  19182. '\uFC11': '\u062B\u062C',
  19183. '\uFC12': '\u062B\u0645',
  19184. '\uFC13': '\u062B\u0649',
  19185. '\uFC14': '\u062B\u064A',
  19186. '\uFC15': '\u062C\u062D',
  19187. '\uFC16': '\u062C\u0645',
  19188. '\uFC17': '\u062D\u062C',
  19189. '\uFC18': '\u062D\u0645',
  19190. '\uFC19': '\u062E\u062C',
  19191. '\uFC1A': '\u062E\u062D',
  19192. '\uFC1B': '\u062E\u0645',
  19193. '\uFC1C': '\u0633\u062C',
  19194. '\uFC1D': '\u0633\u062D',
  19195. '\uFC1E': '\u0633\u062E',
  19196. '\uFC1F': '\u0633\u0645',
  19197. '\uFC20': '\u0635\u062D',
  19198. '\uFC21': '\u0635\u0645',
  19199. '\uFC22': '\u0636\u062C',
  19200. '\uFC23': '\u0636\u062D',
  19201. '\uFC24': '\u0636\u062E',
  19202. '\uFC25': '\u0636\u0645',
  19203. '\uFC26': '\u0637\u062D',
  19204. '\uFC27': '\u0637\u0645',
  19205. '\uFC28': '\u0638\u0645',
  19206. '\uFC29': '\u0639\u062C',
  19207. '\uFC2A': '\u0639\u0645',
  19208. '\uFC2B': '\u063A\u062C',
  19209. '\uFC2C': '\u063A\u0645',
  19210. '\uFC2D': '\u0641\u062C',
  19211. '\uFC2E': '\u0641\u062D',
  19212. '\uFC2F': '\u0641\u062E',
  19213. '\uFC30': '\u0641\u0645',
  19214. '\uFC31': '\u0641\u0649',
  19215. '\uFC32': '\u0641\u064A',
  19216. '\uFC33': '\u0642\u062D',
  19217. '\uFC34': '\u0642\u0645',
  19218. '\uFC35': '\u0642\u0649',
  19219. '\uFC36': '\u0642\u064A',
  19220. '\uFC37': '\u0643\u0627',
  19221. '\uFC38': '\u0643\u062C',
  19222. '\uFC39': '\u0643\u062D',
  19223. '\uFC3A': '\u0643\u062E',
  19224. '\uFC3B': '\u0643\u0644',
  19225. '\uFC3C': '\u0643\u0645',
  19226. '\uFC3D': '\u0643\u0649',
  19227. '\uFC3E': '\u0643\u064A',
  19228. '\uFC3F': '\u0644\u062C',
  19229. '\uFC40': '\u0644\u062D',
  19230. '\uFC41': '\u0644\u062E',
  19231. '\uFC42': '\u0644\u0645',
  19232. '\uFC43': '\u0644\u0649',
  19233. '\uFC44': '\u0644\u064A',
  19234. '\uFC45': '\u0645\u062C',
  19235. '\uFC46': '\u0645\u062D',
  19236. '\uFC47': '\u0645\u062E',
  19237. '\uFC48': '\u0645\u0645',
  19238. '\uFC49': '\u0645\u0649',
  19239. '\uFC4A': '\u0645\u064A',
  19240. '\uFC4B': '\u0646\u062C',
  19241. '\uFC4C': '\u0646\u062D',
  19242. '\uFC4D': '\u0646\u062E',
  19243. '\uFC4E': '\u0646\u0645',
  19244. '\uFC4F': '\u0646\u0649',
  19245. '\uFC50': '\u0646\u064A',
  19246. '\uFC51': '\u0647\u062C',
  19247. '\uFC52': '\u0647\u0645',
  19248. '\uFC53': '\u0647\u0649',
  19249. '\uFC54': '\u0647\u064A',
  19250. '\uFC55': '\u064A\u062C',
  19251. '\uFC56': '\u064A\u062D',
  19252. '\uFC57': '\u064A\u062E',
  19253. '\uFC58': '\u064A\u0645',
  19254. '\uFC59': '\u064A\u0649',
  19255. '\uFC5A': '\u064A\u064A',
  19256. '\uFC5B': '\u0630\u0670',
  19257. '\uFC5C': '\u0631\u0670',
  19258. '\uFC5D': '\u0649\u0670',
  19259. '\uFC5E': '\u0020\u064C\u0651',
  19260. '\uFC5F': '\u0020\u064D\u0651',
  19261. '\uFC60': '\u0020\u064E\u0651',
  19262. '\uFC61': '\u0020\u064F\u0651',
  19263. '\uFC62': '\u0020\u0650\u0651',
  19264. '\uFC63': '\u0020\u0651\u0670',
  19265. '\uFC64': '\u0626\u0631',
  19266. '\uFC65': '\u0626\u0632',
  19267. '\uFC66': '\u0626\u0645',
  19268. '\uFC67': '\u0626\u0646',
  19269. '\uFC68': '\u0626\u0649',
  19270. '\uFC69': '\u0626\u064A',
  19271. '\uFC6A': '\u0628\u0631',
  19272. '\uFC6B': '\u0628\u0632',
  19273. '\uFC6C': '\u0628\u0645',
  19274. '\uFC6D': '\u0628\u0646',
  19275. '\uFC6E': '\u0628\u0649',
  19276. '\uFC6F': '\u0628\u064A',
  19277. '\uFC70': '\u062A\u0631',
  19278. '\uFC71': '\u062A\u0632',
  19279. '\uFC72': '\u062A\u0645',
  19280. '\uFC73': '\u062A\u0646',
  19281. '\uFC74': '\u062A\u0649',
  19282. '\uFC75': '\u062A\u064A',
  19283. '\uFC76': '\u062B\u0631',
  19284. '\uFC77': '\u062B\u0632',
  19285. '\uFC78': '\u062B\u0645',
  19286. '\uFC79': '\u062B\u0646',
  19287. '\uFC7A': '\u062B\u0649',
  19288. '\uFC7B': '\u062B\u064A',
  19289. '\uFC7C': '\u0641\u0649',
  19290. '\uFC7D': '\u0641\u064A',
  19291. '\uFC7E': '\u0642\u0649',
  19292. '\uFC7F': '\u0642\u064A',
  19293. '\uFC80': '\u0643\u0627',
  19294. '\uFC81': '\u0643\u0644',
  19295. '\uFC82': '\u0643\u0645',
  19296. '\uFC83': '\u0643\u0649',
  19297. '\uFC84': '\u0643\u064A',
  19298. '\uFC85': '\u0644\u0645',
  19299. '\uFC86': '\u0644\u0649',
  19300. '\uFC87': '\u0644\u064A',
  19301. '\uFC88': '\u0645\u0627',
  19302. '\uFC89': '\u0645\u0645',
  19303. '\uFC8A': '\u0646\u0631',
  19304. '\uFC8B': '\u0646\u0632',
  19305. '\uFC8C': '\u0646\u0645',
  19306. '\uFC8D': '\u0646\u0646',
  19307. '\uFC8E': '\u0646\u0649',
  19308. '\uFC8F': '\u0646\u064A',
  19309. '\uFC90': '\u0649\u0670',
  19310. '\uFC91': '\u064A\u0631',
  19311. '\uFC92': '\u064A\u0632',
  19312. '\uFC93': '\u064A\u0645',
  19313. '\uFC94': '\u064A\u0646',
  19314. '\uFC95': '\u064A\u0649',
  19315. '\uFC96': '\u064A\u064A',
  19316. '\uFC97': '\u0626\u062C',
  19317. '\uFC98': '\u0626\u062D',
  19318. '\uFC99': '\u0626\u062E',
  19319. '\uFC9A': '\u0626\u0645',
  19320. '\uFC9B': '\u0626\u0647',
  19321. '\uFC9C': '\u0628\u062C',
  19322. '\uFC9D': '\u0628\u062D',
  19323. '\uFC9E': '\u0628\u062E',
  19324. '\uFC9F': '\u0628\u0645',
  19325. '\uFCA0': '\u0628\u0647',
  19326. '\uFCA1': '\u062A\u062C',
  19327. '\uFCA2': '\u062A\u062D',
  19328. '\uFCA3': '\u062A\u062E',
  19329. '\uFCA4': '\u062A\u0645',
  19330. '\uFCA5': '\u062A\u0647',
  19331. '\uFCA6': '\u062B\u0645',
  19332. '\uFCA7': '\u062C\u062D',
  19333. '\uFCA8': '\u062C\u0645',
  19334. '\uFCA9': '\u062D\u062C',
  19335. '\uFCAA': '\u062D\u0645',
  19336. '\uFCAB': '\u062E\u062C',
  19337. '\uFCAC': '\u062E\u0645',
  19338. '\uFCAD': '\u0633\u062C',
  19339. '\uFCAE': '\u0633\u062D',
  19340. '\uFCAF': '\u0633\u062E',
  19341. '\uFCB0': '\u0633\u0645',
  19342. '\uFCB1': '\u0635\u062D',
  19343. '\uFCB2': '\u0635\u062E',
  19344. '\uFCB3': '\u0635\u0645',
  19345. '\uFCB4': '\u0636\u062C',
  19346. '\uFCB5': '\u0636\u062D',
  19347. '\uFCB6': '\u0636\u062E',
  19348. '\uFCB7': '\u0636\u0645',
  19349. '\uFCB8': '\u0637\u062D',
  19350. '\uFCB9': '\u0638\u0645',
  19351. '\uFCBA': '\u0639\u062C',
  19352. '\uFCBB': '\u0639\u0645',
  19353. '\uFCBC': '\u063A\u062C',
  19354. '\uFCBD': '\u063A\u0645',
  19355. '\uFCBE': '\u0641\u062C',
  19356. '\uFCBF': '\u0641\u062D',
  19357. '\uFCC0': '\u0641\u062E',
  19358. '\uFCC1': '\u0641\u0645',
  19359. '\uFCC2': '\u0642\u062D',
  19360. '\uFCC3': '\u0642\u0645',
  19361. '\uFCC4': '\u0643\u062C',
  19362. '\uFCC5': '\u0643\u062D',
  19363. '\uFCC6': '\u0643\u062E',
  19364. '\uFCC7': '\u0643\u0644',
  19365. '\uFCC8': '\u0643\u0645',
  19366. '\uFCC9': '\u0644\u062C',
  19367. '\uFCCA': '\u0644\u062D',
  19368. '\uFCCB': '\u0644\u062E',
  19369. '\uFCCC': '\u0644\u0645',
  19370. '\uFCCD': '\u0644\u0647',
  19371. '\uFCCE': '\u0645\u062C',
  19372. '\uFCCF': '\u0645\u062D',
  19373. '\uFCD0': '\u0645\u062E',
  19374. '\uFCD1': '\u0645\u0645',
  19375. '\uFCD2': '\u0646\u062C',
  19376. '\uFCD3': '\u0646\u062D',
  19377. '\uFCD4': '\u0646\u062E',
  19378. '\uFCD5': '\u0646\u0645',
  19379. '\uFCD6': '\u0646\u0647',
  19380. '\uFCD7': '\u0647\u062C',
  19381. '\uFCD8': '\u0647\u0645',
  19382. '\uFCD9': '\u0647\u0670',
  19383. '\uFCDA': '\u064A\u062C',
  19384. '\uFCDB': '\u064A\u062D',
  19385. '\uFCDC': '\u064A\u062E',
  19386. '\uFCDD': '\u064A\u0645',
  19387. '\uFCDE': '\u064A\u0647',
  19388. '\uFCDF': '\u0626\u0645',
  19389. '\uFCE0': '\u0626\u0647',
  19390. '\uFCE1': '\u0628\u0645',
  19391. '\uFCE2': '\u0628\u0647',
  19392. '\uFCE3': '\u062A\u0645',
  19393. '\uFCE4': '\u062A\u0647',
  19394. '\uFCE5': '\u062B\u0645',
  19395. '\uFCE6': '\u062B\u0647',
  19396. '\uFCE7': '\u0633\u0645',
  19397. '\uFCE8': '\u0633\u0647',
  19398. '\uFCE9': '\u0634\u0645',
  19399. '\uFCEA': '\u0634\u0647',
  19400. '\uFCEB': '\u0643\u0644',
  19401. '\uFCEC': '\u0643\u0645',
  19402. '\uFCED': '\u0644\u0645',
  19403. '\uFCEE': '\u0646\u0645',
  19404. '\uFCEF': '\u0646\u0647',
  19405. '\uFCF0': '\u064A\u0645',
  19406. '\uFCF1': '\u064A\u0647',
  19407. '\uFCF2': '\u0640\u064E\u0651',
  19408. '\uFCF3': '\u0640\u064F\u0651',
  19409. '\uFCF4': '\u0640\u0650\u0651',
  19410. '\uFCF5': '\u0637\u0649',
  19411. '\uFCF6': '\u0637\u064A',
  19412. '\uFCF7': '\u0639\u0649',
  19413. '\uFCF8': '\u0639\u064A',
  19414. '\uFCF9': '\u063A\u0649',
  19415. '\uFCFA': '\u063A\u064A',
  19416. '\uFCFB': '\u0633\u0649',
  19417. '\uFCFC': '\u0633\u064A',
  19418. '\uFCFD': '\u0634\u0649',
  19419. '\uFCFE': '\u0634\u064A',
  19420. '\uFCFF': '\u062D\u0649',
  19421. '\uFD00': '\u062D\u064A',
  19422. '\uFD01': '\u062C\u0649',
  19423. '\uFD02': '\u062C\u064A',
  19424. '\uFD03': '\u062E\u0649',
  19425. '\uFD04': '\u062E\u064A',
  19426. '\uFD05': '\u0635\u0649',
  19427. '\uFD06': '\u0635\u064A',
  19428. '\uFD07': '\u0636\u0649',
  19429. '\uFD08': '\u0636\u064A',
  19430. '\uFD09': '\u0634\u062C',
  19431. '\uFD0A': '\u0634\u062D',
  19432. '\uFD0B': '\u0634\u062E',
  19433. '\uFD0C': '\u0634\u0645',
  19434. '\uFD0D': '\u0634\u0631',
  19435. '\uFD0E': '\u0633\u0631',
  19436. '\uFD0F': '\u0635\u0631',
  19437. '\uFD10': '\u0636\u0631',
  19438. '\uFD11': '\u0637\u0649',
  19439. '\uFD12': '\u0637\u064A',
  19440. '\uFD13': '\u0639\u0649',
  19441. '\uFD14': '\u0639\u064A',
  19442. '\uFD15': '\u063A\u0649',
  19443. '\uFD16': '\u063A\u064A',
  19444. '\uFD17': '\u0633\u0649',
  19445. '\uFD18': '\u0633\u064A',
  19446. '\uFD19': '\u0634\u0649',
  19447. '\uFD1A': '\u0634\u064A',
  19448. '\uFD1B': '\u062D\u0649',
  19449. '\uFD1C': '\u062D\u064A',
  19450. '\uFD1D': '\u062C\u0649',
  19451. '\uFD1E': '\u062C\u064A',
  19452. '\uFD1F': '\u062E\u0649',
  19453. '\uFD20': '\u062E\u064A',
  19454. '\uFD21': '\u0635\u0649',
  19455. '\uFD22': '\u0635\u064A',
  19456. '\uFD23': '\u0636\u0649',
  19457. '\uFD24': '\u0636\u064A',
  19458. '\uFD25': '\u0634\u062C',
  19459. '\uFD26': '\u0634\u062D',
  19460. '\uFD27': '\u0634\u062E',
  19461. '\uFD28': '\u0634\u0645',
  19462. '\uFD29': '\u0634\u0631',
  19463. '\uFD2A': '\u0633\u0631',
  19464. '\uFD2B': '\u0635\u0631',
  19465. '\uFD2C': '\u0636\u0631',
  19466. '\uFD2D': '\u0634\u062C',
  19467. '\uFD2E': '\u0634\u062D',
  19468. '\uFD2F': '\u0634\u062E',
  19469. '\uFD30': '\u0634\u0645',
  19470. '\uFD31': '\u0633\u0647',
  19471. '\uFD32': '\u0634\u0647',
  19472. '\uFD33': '\u0637\u0645',
  19473. '\uFD34': '\u0633\u062C',
  19474. '\uFD35': '\u0633\u062D',
  19475. '\uFD36': '\u0633\u062E',
  19476. '\uFD37': '\u0634\u062C',
  19477. '\uFD38': '\u0634\u062D',
  19478. '\uFD39': '\u0634\u062E',
  19479. '\uFD3A': '\u0637\u0645',
  19480. '\uFD3B': '\u0638\u0645',
  19481. '\uFD3C': '\u0627\u064B',
  19482. '\uFD3D': '\u0627\u064B',
  19483. '\uFD50': '\u062A\u062C\u0645',
  19484. '\uFD51': '\u062A\u062D\u062C',
  19485. '\uFD52': '\u062A\u062D\u062C',
  19486. '\uFD53': '\u062A\u062D\u0645',
  19487. '\uFD54': '\u062A\u062E\u0645',
  19488. '\uFD55': '\u062A\u0645\u062C',
  19489. '\uFD56': '\u062A\u0645\u062D',
  19490. '\uFD57': '\u062A\u0645\u062E',
  19491. '\uFD58': '\u062C\u0645\u062D',
  19492. '\uFD59': '\u062C\u0645\u062D',
  19493. '\uFD5A': '\u062D\u0645\u064A',
  19494. '\uFD5B': '\u062D\u0645\u0649',
  19495. '\uFD5C': '\u0633\u062D\u062C',
  19496. '\uFD5D': '\u0633\u062C\u062D',
  19497. '\uFD5E': '\u0633\u062C\u0649',
  19498. '\uFD5F': '\u0633\u0645\u062D',
  19499. '\uFD60': '\u0633\u0645\u062D',
  19500. '\uFD61': '\u0633\u0645\u062C',
  19501. '\uFD62': '\u0633\u0645\u0645',
  19502. '\uFD63': '\u0633\u0645\u0645',
  19503. '\uFD64': '\u0635\u062D\u062D',
  19504. '\uFD65': '\u0635\u062D\u062D',
  19505. '\uFD66': '\u0635\u0645\u0645',
  19506. '\uFD67': '\u0634\u062D\u0645',
  19507. '\uFD68': '\u0634\u062D\u0645',
  19508. '\uFD69': '\u0634\u062C\u064A',
  19509. '\uFD6A': '\u0634\u0645\u062E',
  19510. '\uFD6B': '\u0634\u0645\u062E',
  19511. '\uFD6C': '\u0634\u0645\u0645',
  19512. '\uFD6D': '\u0634\u0645\u0645',
  19513. '\uFD6E': '\u0636\u062D\u0649',
  19514. '\uFD6F': '\u0636\u062E\u0645',
  19515. '\uFD70': '\u0636\u062E\u0645',
  19516. '\uFD71': '\u0637\u0645\u062D',
  19517. '\uFD72': '\u0637\u0645\u062D',
  19518. '\uFD73': '\u0637\u0645\u0645',
  19519. '\uFD74': '\u0637\u0645\u064A',
  19520. '\uFD75': '\u0639\u062C\u0645',
  19521. '\uFD76': '\u0639\u0645\u0645',
  19522. '\uFD77': '\u0639\u0645\u0645',
  19523. '\uFD78': '\u0639\u0645\u0649',
  19524. '\uFD79': '\u063A\u0645\u0645',
  19525. '\uFD7A': '\u063A\u0645\u064A',
  19526. '\uFD7B': '\u063A\u0645\u0649',
  19527. '\uFD7C': '\u0641\u062E\u0645',
  19528. '\uFD7D': '\u0641\u062E\u0645',
  19529. '\uFD7E': '\u0642\u0645\u062D',
  19530. '\uFD7F': '\u0642\u0645\u0645',
  19531. '\uFD80': '\u0644\u062D\u0645',
  19532. '\uFD81': '\u0644\u062D\u064A',
  19533. '\uFD82': '\u0644\u062D\u0649',
  19534. '\uFD83': '\u0644\u062C\u062C',
  19535. '\uFD84': '\u0644\u062C\u062C',
  19536. '\uFD85': '\u0644\u062E\u0645',
  19537. '\uFD86': '\u0644\u062E\u0645',
  19538. '\uFD87': '\u0644\u0645\u062D',
  19539. '\uFD88': '\u0644\u0645\u062D',
  19540. '\uFD89': '\u0645\u062D\u062C',
  19541. '\uFD8A': '\u0645\u062D\u0645',
  19542. '\uFD8B': '\u0645\u062D\u064A',
  19543. '\uFD8C': '\u0645\u062C\u062D',
  19544. '\uFD8D': '\u0645\u062C\u0645',
  19545. '\uFD8E': '\u0645\u062E\u062C',
  19546. '\uFD8F': '\u0645\u062E\u0645',
  19547. '\uFD92': '\u0645\u062C\u062E',
  19548. '\uFD93': '\u0647\u0645\u062C',
  19549. '\uFD94': '\u0647\u0645\u0645',
  19550. '\uFD95': '\u0646\u062D\u0645',
  19551. '\uFD96': '\u0646\u062D\u0649',
  19552. '\uFD97': '\u0646\u062C\u0645',
  19553. '\uFD98': '\u0646\u062C\u0645',
  19554. '\uFD99': '\u0646\u062C\u0649',
  19555. '\uFD9A': '\u0646\u0645\u064A',
  19556. '\uFD9B': '\u0646\u0645\u0649',
  19557. '\uFD9C': '\u064A\u0645\u0645',
  19558. '\uFD9D': '\u064A\u0645\u0645',
  19559. '\uFD9E': '\u0628\u062E\u064A',
  19560. '\uFD9F': '\u062A\u062C\u064A',
  19561. '\uFDA0': '\u062A\u062C\u0649',
  19562. '\uFDA1': '\u062A\u062E\u064A',
  19563. '\uFDA2': '\u062A\u062E\u0649',
  19564. '\uFDA3': '\u062A\u0645\u064A',
  19565. '\uFDA4': '\u062A\u0645\u0649',
  19566. '\uFDA5': '\u062C\u0645\u064A',
  19567. '\uFDA6': '\u062C\u062D\u0649',
  19568. '\uFDA7': '\u062C\u0645\u0649',
  19569. '\uFDA8': '\u0633\u062E\u0649',
  19570. '\uFDA9': '\u0635\u062D\u064A',
  19571. '\uFDAA': '\u0634\u062D\u064A',
  19572. '\uFDAB': '\u0636\u062D\u064A',
  19573. '\uFDAC': '\u0644\u062C\u064A',
  19574. '\uFDAD': '\u0644\u0645\u064A',
  19575. '\uFDAE': '\u064A\u062D\u064A',
  19576. '\uFDAF': '\u064A\u062C\u064A',
  19577. '\uFDB0': '\u064A\u0645\u064A',
  19578. '\uFDB1': '\u0645\u0645\u064A',
  19579. '\uFDB2': '\u0642\u0645\u064A',
  19580. '\uFDB3': '\u0646\u062D\u064A',
  19581. '\uFDB4': '\u0642\u0645\u062D',
  19582. '\uFDB5': '\u0644\u062D\u0645',
  19583. '\uFDB6': '\u0639\u0645\u064A',
  19584. '\uFDB7': '\u0643\u0645\u064A',
  19585. '\uFDB8': '\u0646\u062C\u062D',
  19586. '\uFDB9': '\u0645\u062E\u064A',
  19587. '\uFDBA': '\u0644\u062C\u0645',
  19588. '\uFDBB': '\u0643\u0645\u0645',
  19589. '\uFDBC': '\u0644\u062C\u0645',
  19590. '\uFDBD': '\u0646\u062C\u062D',
  19591. '\uFDBE': '\u062C\u062D\u064A',
  19592. '\uFDBF': '\u062D\u062C\u064A',
  19593. '\uFDC0': '\u0645\u062C\u064A',
  19594. '\uFDC1': '\u0641\u0645\u064A',
  19595. '\uFDC2': '\u0628\u062D\u064A',
  19596. '\uFDC3': '\u0643\u0645\u0645',
  19597. '\uFDC4': '\u0639\u062C\u0645',
  19598. '\uFDC5': '\u0635\u0645\u0645',
  19599. '\uFDC6': '\u0633\u062E\u064A',
  19600. '\uFDC7': '\u0646\u062C\u064A',
  19601. '\uFE49': '\u203E',
  19602. '\uFE4A': '\u203E',
  19603. '\uFE4B': '\u203E',
  19604. '\uFE4C': '\u203E',
  19605. '\uFE4D': '\u005F',
  19606. '\uFE4E': '\u005F',
  19607. '\uFE4F': '\u005F',
  19608. '\uFE80': '\u0621',
  19609. '\uFE81': '\u0622',
  19610. '\uFE82': '\u0622',
  19611. '\uFE83': '\u0623',
  19612. '\uFE84': '\u0623',
  19613. '\uFE85': '\u0624',
  19614. '\uFE86': '\u0624',
  19615. '\uFE87': '\u0625',
  19616. '\uFE88': '\u0625',
  19617. '\uFE89': '\u0626',
  19618. '\uFE8A': '\u0626',
  19619. '\uFE8B': '\u0626',
  19620. '\uFE8C': '\u0626',
  19621. '\uFE8D': '\u0627',
  19622. '\uFE8E': '\u0627',
  19623. '\uFE8F': '\u0628',
  19624. '\uFE90': '\u0628',
  19625. '\uFE91': '\u0628',
  19626. '\uFE92': '\u0628',
  19627. '\uFE93': '\u0629',
  19628. '\uFE94': '\u0629',
  19629. '\uFE95': '\u062A',
  19630. '\uFE96': '\u062A',
  19631. '\uFE97': '\u062A',
  19632. '\uFE98': '\u062A',
  19633. '\uFE99': '\u062B',
  19634. '\uFE9A': '\u062B',
  19635. '\uFE9B': '\u062B',
  19636. '\uFE9C': '\u062B',
  19637. '\uFE9D': '\u062C',
  19638. '\uFE9E': '\u062C',
  19639. '\uFE9F': '\u062C',
  19640. '\uFEA0': '\u062C',
  19641. '\uFEA1': '\u062D',
  19642. '\uFEA2': '\u062D',
  19643. '\uFEA3': '\u062D',
  19644. '\uFEA4': '\u062D',
  19645. '\uFEA5': '\u062E',
  19646. '\uFEA6': '\u062E',
  19647. '\uFEA7': '\u062E',
  19648. '\uFEA8': '\u062E',
  19649. '\uFEA9': '\u062F',
  19650. '\uFEAA': '\u062F',
  19651. '\uFEAB': '\u0630',
  19652. '\uFEAC': '\u0630',
  19653. '\uFEAD': '\u0631',
  19654. '\uFEAE': '\u0631',
  19655. '\uFEAF': '\u0632',
  19656. '\uFEB0': '\u0632',
  19657. '\uFEB1': '\u0633',
  19658. '\uFEB2': '\u0633',
  19659. '\uFEB3': '\u0633',
  19660. '\uFEB4': '\u0633',
  19661. '\uFEB5': '\u0634',
  19662. '\uFEB6': '\u0634',
  19663. '\uFEB7': '\u0634',
  19664. '\uFEB8': '\u0634',
  19665. '\uFEB9': '\u0635',
  19666. '\uFEBA': '\u0635',
  19667. '\uFEBB': '\u0635',
  19668. '\uFEBC': '\u0635',
  19669. '\uFEBD': '\u0636',
  19670. '\uFEBE': '\u0636',
  19671. '\uFEBF': '\u0636',
  19672. '\uFEC0': '\u0636',
  19673. '\uFEC1': '\u0637',
  19674. '\uFEC2': '\u0637',
  19675. '\uFEC3': '\u0637',
  19676. '\uFEC4': '\u0637',
  19677. '\uFEC5': '\u0638',
  19678. '\uFEC6': '\u0638',
  19679. '\uFEC7': '\u0638',
  19680. '\uFEC8': '\u0638',
  19681. '\uFEC9': '\u0639',
  19682. '\uFECA': '\u0639',
  19683. '\uFECB': '\u0639',
  19684. '\uFECC': '\u0639',
  19685. '\uFECD': '\u063A',
  19686. '\uFECE': '\u063A',
  19687. '\uFECF': '\u063A',
  19688. '\uFED0': '\u063A',
  19689. '\uFED1': '\u0641',
  19690. '\uFED2': '\u0641',
  19691. '\uFED3': '\u0641',
  19692. '\uFED4': '\u0641',
  19693. '\uFED5': '\u0642',
  19694. '\uFED6': '\u0642',
  19695. '\uFED7': '\u0642',
  19696. '\uFED8': '\u0642',
  19697. '\uFED9': '\u0643',
  19698. '\uFEDA': '\u0643',
  19699. '\uFEDB': '\u0643',
  19700. '\uFEDC': '\u0643',
  19701. '\uFEDD': '\u0644',
  19702. '\uFEDE': '\u0644',
  19703. '\uFEDF': '\u0644',
  19704. '\uFEE0': '\u0644',
  19705. '\uFEE1': '\u0645',
  19706. '\uFEE2': '\u0645',
  19707. '\uFEE3': '\u0645',
  19708. '\uFEE4': '\u0645',
  19709. '\uFEE5': '\u0646',
  19710. '\uFEE6': '\u0646',
  19711. '\uFEE7': '\u0646',
  19712. '\uFEE8': '\u0646',
  19713. '\uFEE9': '\u0647',
  19714. '\uFEEA': '\u0647',
  19715. '\uFEEB': '\u0647',
  19716. '\uFEEC': '\u0647',
  19717. '\uFEED': '\u0648',
  19718. '\uFEEE': '\u0648',
  19719. '\uFEEF': '\u0649',
  19720. '\uFEF0': '\u0649',
  19721. '\uFEF1': '\u064A',
  19722. '\uFEF2': '\u064A',
  19723. '\uFEF3': '\u064A',
  19724. '\uFEF4': '\u064A',
  19725. '\uFEF5': '\u0644\u0622',
  19726. '\uFEF6': '\u0644\u0622',
  19727. '\uFEF7': '\u0644\u0623',
  19728. '\uFEF8': '\u0644\u0623',
  19729. '\uFEF9': '\u0644\u0625',
  19730. '\uFEFA': '\u0644\u0625',
  19731. '\uFEFB': '\u0644\u0627',
  19732. '\uFEFC': '\u0644\u0627'
  19733. };
  19734. function reverseIfRtl(chars) {
  19735. var charsLength = chars.length;
  19736. //reverse an arabic ligature
  19737. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  19738. return chars;
  19739. }
  19740. var s = '';
  19741. for (var ii = charsLength - 1; ii >= 0; ii--) {
  19742. s += chars[ii];
  19743. }
  19744. return s;
  19745. }
  19746. function adjustWidths(properties) {
  19747. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  19748. return;
  19749. }
  19750. // adjusting width to fontMatrix scale
  19751. var scale = 0.001 / properties.fontMatrix[0];
  19752. var glyphsWidths = properties.widths;
  19753. for (var glyph in glyphsWidths) {
  19754. glyphsWidths[glyph] *= scale;
  19755. }
  19756. properties.defaultWidth *= scale;
  19757. }
  19758. function getFontType(type, subtype) {
  19759. switch (type) {
  19760. case 'Type1':
  19761. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  19762. case 'CIDFontType0':
  19763. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  19764. FontType.CIDFONTTYPE0;
  19765. case 'OpenType':
  19766. return FontType.OPENTYPE;
  19767. case 'TrueType':
  19768. return FontType.TRUETYPE;
  19769. case 'CIDFontType2':
  19770. return FontType.CIDFONTTYPE2;
  19771. case 'MMType1':
  19772. return FontType.MMTYPE1;
  19773. case 'Type0':
  19774. return FontType.TYPE0;
  19775. default:
  19776. return FontType.UNKNOWN;
  19777. }
  19778. }
  19779. var Glyph = (function GlyphClosure() {
  19780. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  19781. this.fontChar = fontChar;
  19782. this.unicode = unicode;
  19783. this.accent = accent;
  19784. this.width = width;
  19785. this.vmetric = vmetric;
  19786. this.operatorListId = operatorListId;
  19787. }
  19788. Glyph.prototype.matchesForCache =
  19789. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  19790. return this.fontChar === fontChar &&
  19791. this.unicode === unicode &&
  19792. this.accent === accent &&
  19793. this.width === width &&
  19794. this.vmetric === vmetric &&
  19795. this.operatorListId === operatorListId;
  19796. };
  19797. return Glyph;
  19798. })();
  19799. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  19800. function ToUnicodeMap(cmap) {
  19801. // The elements of this._map can be integers or strings, depending on how
  19802. // |cmap| was created.
  19803. this._map = cmap;
  19804. }
  19805. ToUnicodeMap.prototype = {
  19806. get length() {
  19807. return this._map.length;
  19808. },
  19809. forEach: function(callback) {
  19810. for (var charCode in this._map) {
  19811. callback(charCode, this._map[charCode].charCodeAt(0));
  19812. }
  19813. },
  19814. get: function(i) {
  19815. return this._map[i];
  19816. },
  19817. charCodeOf: function(v) {
  19818. return this._map.indexOf(v);
  19819. }
  19820. };
  19821. return ToUnicodeMap;
  19822. })();
  19823. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  19824. function IdentityToUnicodeMap(firstChar, lastChar) {
  19825. this.firstChar = firstChar;
  19826. this.lastChar = lastChar;
  19827. }
  19828. IdentityToUnicodeMap.prototype = {
  19829. get length() {
  19830. error('should not access .length');
  19831. },
  19832. forEach: function (callback) {
  19833. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  19834. callback(i, i);
  19835. }
  19836. },
  19837. get: function (i) {
  19838. if (this.firstChar <= i && i <= this.lastChar) {
  19839. return String.fromCharCode(i);
  19840. }
  19841. return undefined;
  19842. },
  19843. charCodeOf: function (v) {
  19844. error('should not call .charCodeOf');
  19845. }
  19846. };
  19847. return IdentityToUnicodeMap;
  19848. })();
  19849. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  19850. function writeInt16(dest, offset, num) {
  19851. dest[offset] = (num >> 8) & 0xFF;
  19852. dest[offset + 1] = num & 0xFF;
  19853. }
  19854. function writeInt32(dest, offset, num) {
  19855. dest[offset] = (num >> 24) & 0xFF;
  19856. dest[offset + 1] = (num >> 16) & 0xFF;
  19857. dest[offset + 2] = (num >> 8) & 0xFF;
  19858. dest[offset + 3] = num & 0xFF;
  19859. }
  19860. function writeData(dest, offset, data) {
  19861. var i, ii;
  19862. if (data instanceof Uint8Array) {
  19863. dest.set(data, offset);
  19864. } else if (typeof data === 'string') {
  19865. for (i = 0, ii = data.length; i < ii; i++) {
  19866. dest[offset++] = data.charCodeAt(i) & 0xFF;
  19867. }
  19868. } else {
  19869. // treating everything else as array
  19870. for (i = 0, ii = data.length; i < ii; i++) {
  19871. dest[offset++] = data[i] & 0xFF;
  19872. }
  19873. }
  19874. }
  19875. function OpenTypeFileBuilder(sfnt) {
  19876. this.sfnt = sfnt;
  19877. this.tables = Object.create(null);
  19878. }
  19879. OpenTypeFileBuilder.getSearchParams =
  19880. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  19881. var maxPower2 = 1, log2 = 0;
  19882. while ((maxPower2 ^ entriesCount) > maxPower2) {
  19883. maxPower2 <<= 1;
  19884. log2++;
  19885. }
  19886. var searchRange = maxPower2 * entrySize;
  19887. return {
  19888. range: searchRange,
  19889. entry: log2,
  19890. rangeShift: entrySize * entriesCount - searchRange
  19891. };
  19892. };
  19893. var OTF_HEADER_SIZE = 12;
  19894. var OTF_TABLE_ENTRY_SIZE = 16;
  19895. OpenTypeFileBuilder.prototype = {
  19896. toArray: function OpenTypeFileBuilder_toArray() {
  19897. var sfnt = this.sfnt;
  19898. // Tables needs to be written by ascendant alphabetic order
  19899. var tables = this.tables;
  19900. var tablesNames = Object.keys(tables);
  19901. tablesNames.sort();
  19902. var numTables = tablesNames.length;
  19903. var i, j, jj, table, tableName;
  19904. // layout the tables data
  19905. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  19906. var tableOffsets = [offset];
  19907. for (i = 0; i < numTables; i++) {
  19908. table = tables[tablesNames[i]];
  19909. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  19910. offset += paddedLength;
  19911. tableOffsets.push(offset);
  19912. }
  19913. var file = new Uint8Array(offset);
  19914. // write the table data first (mostly for checksum)
  19915. for (i = 0; i < numTables; i++) {
  19916. table = tables[tablesNames[i]];
  19917. writeData(file, tableOffsets[i], table);
  19918. }
  19919. // sfnt version (4 bytes)
  19920. if (sfnt === 'true') {
  19921. // Windows hates the Mac TrueType sfnt version number
  19922. sfnt = string32(0x00010000);
  19923. }
  19924. file[0] = sfnt.charCodeAt(0) & 0xFF;
  19925. file[1] = sfnt.charCodeAt(1) & 0xFF;
  19926. file[2] = sfnt.charCodeAt(2) & 0xFF;
  19927. file[3] = sfnt.charCodeAt(3) & 0xFF;
  19928. // numTables (2 bytes)
  19929. writeInt16(file, 4, numTables);
  19930. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  19931. // searchRange (2 bytes)
  19932. writeInt16(file, 6, searchParams.range);
  19933. // entrySelector (2 bytes)
  19934. writeInt16(file, 8, searchParams.entry);
  19935. // rangeShift (2 bytes)
  19936. writeInt16(file, 10, searchParams.rangeShift);
  19937. offset = OTF_HEADER_SIZE;
  19938. // writing table entries
  19939. for (i = 0; i < numTables; i++) {
  19940. tableName = tablesNames[i];
  19941. file[offset] = tableName.charCodeAt(0) & 0xFF;
  19942. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  19943. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  19944. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  19945. // checksum
  19946. var checksum = 0;
  19947. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  19948. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  19949. (file[j + 2] << 8) + file[j + 3];
  19950. checksum = (checksum + quad) | 0;
  19951. }
  19952. writeInt32(file, offset + 4, checksum);
  19953. // offset
  19954. writeInt32(file, offset + 8, tableOffsets[i]);
  19955. // length
  19956. writeInt32(file, offset + 12, tables[tableName].length);
  19957. offset += OTF_TABLE_ENTRY_SIZE;
  19958. }
  19959. return file;
  19960. },
  19961. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  19962. if (tag in this.tables) {
  19963. throw new Error('Table ' + tag + ' already exists');
  19964. }
  19965. this.tables[tag] = data;
  19966. }
  19967. };
  19968. return OpenTypeFileBuilder;
  19969. })();
  19970. /**
  19971. * 'Font' is the class the outside world should use, it encapsulate all the font
  19972. * decoding logics whatever type it is (assuming the font type is supported).
  19973. *
  19974. * For example to read a Type1 font and to attach it to the document:
  19975. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  19976. * type1Font.bind();
  19977. */
  19978. var Font = (function FontClosure() {
  19979. function Font(name, file, properties) {
  19980. var charCode, glyphName;
  19981. this.name = name;
  19982. this.loadedName = properties.loadedName;
  19983. this.isType3Font = properties.isType3Font;
  19984. this.sizes = [];
  19985. this.glyphCache = {};
  19986. var names = name.split('+');
  19987. names = names.length > 1 ? names[1] : names[0];
  19988. names = names.split(/[-,_]/g)[0];
  19989. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  19990. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  19991. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  19992. var type = properties.type;
  19993. var subtype = properties.subtype;
  19994. this.type = type;
  19995. this.fallbackName = (this.isMonospace ? 'monospace' :
  19996. (this.isSerifFont ? 'serif' : 'sans-serif'));
  19997. this.differences = properties.differences;
  19998. this.widths = properties.widths;
  19999. this.defaultWidth = properties.defaultWidth;
  20000. this.composite = properties.composite;
  20001. this.wideChars = properties.wideChars;
  20002. this.cMap = properties.cMap;
  20003. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20004. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20005. this.fontMatrix = properties.fontMatrix;
  20006. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20007. this.toFontChar = [];
  20008. if (properties.type === 'Type3') {
  20009. for (charCode = 0; charCode < 256; charCode++) {
  20010. this.toFontChar[charCode] = (this.differences[charCode] ||
  20011. properties.defaultEncoding[charCode]);
  20012. }
  20013. this.fontType = FontType.TYPE3;
  20014. return;
  20015. }
  20016. this.cidEncoding = properties.cidEncoding;
  20017. this.vertical = properties.vertical;
  20018. if (this.vertical) {
  20019. this.vmetrics = properties.vmetrics;
  20020. this.defaultVMetrics = properties.defaultVMetrics;
  20021. }
  20022. if (!file || file.isEmpty) {
  20023. if (file) {
  20024. // Some bad PDF generators will include empty font files,
  20025. // attempting to recover by assuming that no file exists.
  20026. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20027. }
  20028. this.missingFile = true;
  20029. // The file data is not specified. Trying to fix the font name
  20030. // to be used with the canvas.font.
  20031. var fontName = name.replace(/[,_]/g, '-');
  20032. var isStandardFont = fontName in stdFontMap;
  20033. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20034. this.bold = (fontName.search(/bold/gi) !== -1);
  20035. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20036. (fontName.search(/italic/gi) !== -1));
  20037. // Use 'name' instead of 'fontName' here because the original
  20038. // name ArialBlack for example will be replaced by Helvetica.
  20039. this.black = (name.search(/Black/g) !== -1);
  20040. // if at least one width is present, remeasure all chars when exists
  20041. this.remeasure = Object.keys(this.widths).length > 0;
  20042. if (isStandardFont && type === 'CIDFontType2' &&
  20043. properties.cidEncoding.indexOf('Identity-') === 0) {
  20044. // Standard fonts might be embedded as CID font without glyph mapping.
  20045. // Building one based on GlyphMapForStandardFonts.
  20046. var map = [];
  20047. for (var code in GlyphMapForStandardFonts) {
  20048. map[+code] = GlyphMapForStandardFonts[code];
  20049. }
  20050. this.toFontChar = map;
  20051. this.toUnicode = new ToUnicodeMap(map);
  20052. } else if (/Symbol/i.test(fontName)) {
  20053. var symbols = Encodings.SymbolSetEncoding;
  20054. for (charCode in symbols) {
  20055. var fontChar = GlyphsUnicode[symbols[charCode]];
  20056. if (!fontChar) {
  20057. continue;
  20058. }
  20059. this.toFontChar[charCode] = fontChar;
  20060. }
  20061. } else if (isStandardFont) {
  20062. this.toFontChar = [];
  20063. for (charCode in properties.defaultEncoding) {
  20064. glyphName = (properties.differences[charCode] ||
  20065. properties.defaultEncoding[charCode]);
  20066. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20067. }
  20068. } else {
  20069. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20070. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20071. if (notCidFont) {
  20072. glyphName = (properties.differences[charCode] ||
  20073. properties.defaultEncoding[charCode]);
  20074. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20075. }
  20076. this.toFontChar[charCode] = unicodeCharCode;
  20077. }.bind(this));
  20078. }
  20079. this.loadedName = fontName.split('-')[0];
  20080. this.loading = false;
  20081. this.fontType = getFontType(type, subtype);
  20082. return;
  20083. }
  20084. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20085. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20086. // Some TrueType fonts by mistake claim Type1C
  20087. if (isTrueTypeFile(file)) {
  20088. subtype = 'TrueType';
  20089. } else {
  20090. type = 'Type1';
  20091. }
  20092. }
  20093. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20094. type = 'CIDFontType0';
  20095. }
  20096. // XXX: Temporarily change the type for open type so we trigger a warning.
  20097. // This should be removed when we add support for open type.
  20098. if (subtype === 'OpenType') {
  20099. type = 'OpenType';
  20100. }
  20101. var data;
  20102. switch (type) {
  20103. case 'Type1':
  20104. case 'CIDFontType0':
  20105. this.mimetype = 'font/opentype';
  20106. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20107. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20108. adjustWidths(properties);
  20109. // Wrap the CFF data inside an OTF font file
  20110. data = this.convert(name, cff, properties);
  20111. break;
  20112. case 'OpenType':
  20113. case 'TrueType':
  20114. case 'CIDFontType2':
  20115. this.mimetype = 'font/opentype';
  20116. // Repair the TrueType file. It is can be damaged in the point of
  20117. // view of the sanitizer
  20118. data = this.checkAndRepair(name, file, properties);
  20119. if (this.isOpenType) {
  20120. type = 'OpenType';
  20121. }
  20122. break;
  20123. default:
  20124. error('Font ' + type + ' is not supported');
  20125. break;
  20126. }
  20127. this.data = data;
  20128. this.fontType = getFontType(type, subtype);
  20129. // Transfer some properties again that could change during font conversion
  20130. this.fontMatrix = properties.fontMatrix;
  20131. this.widths = properties.widths;
  20132. this.defaultWidth = properties.defaultWidth;
  20133. this.encoding = properties.baseEncoding;
  20134. this.seacMap = properties.seacMap;
  20135. this.loading = true;
  20136. }
  20137. Font.getFontID = (function () {
  20138. var ID = 1;
  20139. return function Font_getFontID() {
  20140. return String(ID++);
  20141. };
  20142. })();
  20143. function int16(b0, b1) {
  20144. return (b0 << 8) + b1;
  20145. }
  20146. function int32(b0, b1, b2, b3) {
  20147. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20148. }
  20149. function string16(value) {
  20150. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20151. }
  20152. function safeString16(value) {
  20153. // clamp value to the 16-bit int range
  20154. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  20155. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20156. }
  20157. function isTrueTypeFile(file) {
  20158. var header = file.peekBytes(4);
  20159. return readUint32(header, 0) === 0x00010000;
  20160. }
  20161. /**
  20162. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  20163. * with their unicode value. It also moves char codes that are in known
  20164. * problematic locations.
  20165. * @return {Object} Two properties:
  20166. * 'toFontChar' - maps original char codes(the value that will be read
  20167. * from commands such as show text) to the char codes that will be used in the
  20168. * font that we build
  20169. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  20170. */
  20171. function adjustMapping(charCodeToGlyphId, properties) {
  20172. var toUnicode = properties.toUnicode;
  20173. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  20174. var isIdentityUnicode =
  20175. properties.toUnicode instanceof IdentityToUnicodeMap;
  20176. var isCidFontType2 = (properties.type === 'CIDFontType2');
  20177. var newMap = Object.create(null);
  20178. var toFontChar = [];
  20179. var usedFontCharCodes = [];
  20180. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  20181. for (var originalCharCode in charCodeToGlyphId) {
  20182. originalCharCode |= 0;
  20183. var glyphId = charCodeToGlyphId[originalCharCode];
  20184. var fontCharCode = originalCharCode;
  20185. // First try to map the value to a unicode position if a non identity map
  20186. // was created.
  20187. if (!isIdentityUnicode) {
  20188. if (toUnicode.get(originalCharCode) !== undefined) {
  20189. var unicode = toUnicode.get(fontCharCode);
  20190. // TODO: Try to map ligatures to the correct spot.
  20191. if (unicode.length === 1) {
  20192. fontCharCode = unicode.charCodeAt(0);
  20193. }
  20194. } else if (isCidFontType2) {
  20195. // For CIDFontType2, move characters not present in toUnicode
  20196. // to the private use area (fixes bug 1028735 and issue 4881).
  20197. fontCharCode = nextAvailableFontCharCode;
  20198. }
  20199. }
  20200. // Try to move control characters, special characters and already mapped
  20201. // characters to the private use area since they will not be drawn by
  20202. // canvas if left in their current position. Also, move characters if the
  20203. // font was symbolic and there is only an identity unicode map since the
  20204. // characters probably aren't in the correct position (fixes an issue
  20205. // with firefox and thuluthfont).
  20206. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  20207. fontCharCode <= 0x1f || // Control chars
  20208. fontCharCode === 0x7F || // Control char
  20209. fontCharCode === 0xAD || // Soft hyphen
  20210. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  20211. // Prevent drawing characters in the specials unicode block.
  20212. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  20213. (isSymbolic && isIdentityUnicode)) &&
  20214. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  20215. // Loop to try and find a free spot in the private use area.
  20216. do {
  20217. fontCharCode = nextAvailableFontCharCode++;
  20218. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  20219. fontCharCode = 0xF020;
  20220. nextAvailableFontCharCode = fontCharCode + 1;
  20221. }
  20222. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  20223. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  20224. }
  20225. newMap[fontCharCode] = glyphId;
  20226. toFontChar[originalCharCode] = fontCharCode;
  20227. usedFontCharCodes[fontCharCode] = true;
  20228. }
  20229. return {
  20230. toFontChar: toFontChar,
  20231. charCodeToGlyphId: newMap,
  20232. nextAvailableFontCharCode: nextAvailableFontCharCode
  20233. };
  20234. }
  20235. function getRanges(glyphs) {
  20236. // Array.sort() sorts by characters, not numerically, so convert to an
  20237. // array of characters.
  20238. var codes = [];
  20239. for (var charCode in glyphs) {
  20240. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  20241. }
  20242. codes.sort(function fontGetRangesSort(a, b) {
  20243. return a.fontCharCode - b.fontCharCode;
  20244. });
  20245. // Split the sorted codes into ranges.
  20246. var ranges = [];
  20247. var length = codes.length;
  20248. for (var n = 0; n < length; ) {
  20249. var start = codes[n].fontCharCode;
  20250. var codeIndices = [codes[n].glyphId];
  20251. ++n;
  20252. var end = start;
  20253. while (n < length && end + 1 === codes[n].fontCharCode) {
  20254. codeIndices.push(codes[n].glyphId);
  20255. ++end;
  20256. ++n;
  20257. if (end === 0xFFFF) {
  20258. break;
  20259. }
  20260. }
  20261. ranges.push([start, end, codeIndices]);
  20262. }
  20263. return ranges;
  20264. }
  20265. function createCmapTable(glyphs) {
  20266. var ranges = getRanges(glyphs);
  20267. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  20268. var cmap = '\x00\x00' + // version
  20269. string16(numTables) + // numTables
  20270. '\x00\x03' + // platformID
  20271. '\x00\x01' + // encodingID
  20272. string32(4 + numTables * 8); // start of the table record
  20273. var i, ii, j, jj;
  20274. for (i = ranges.length - 1; i >= 0; --i) {
  20275. if (ranges[i][0] <= 0xFFFF) { break; }
  20276. }
  20277. var bmpLength = i + 1;
  20278. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  20279. ranges[i][1] = 0xFFFE;
  20280. }
  20281. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  20282. var segCount = bmpLength + trailingRangesCount;
  20283. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  20284. // Fill up the 4 parallel arrays describing the segments.
  20285. var startCount = '';
  20286. var endCount = '';
  20287. var idDeltas = '';
  20288. var idRangeOffsets = '';
  20289. var glyphsIds = '';
  20290. var bias = 0;
  20291. var range, start, end, codes;
  20292. for (i = 0, ii = bmpLength; i < ii; i++) {
  20293. range = ranges[i];
  20294. start = range[0];
  20295. end = range[1];
  20296. startCount += string16(start);
  20297. endCount += string16(end);
  20298. codes = range[2];
  20299. var contiguous = true;
  20300. for (j = 1, jj = codes.length; j < jj; ++j) {
  20301. if (codes[j] !== codes[j - 1] + 1) {
  20302. contiguous = false;
  20303. break;
  20304. }
  20305. }
  20306. if (!contiguous) {
  20307. var offset = (segCount - i) * 2 + bias * 2;
  20308. bias += (end - start + 1);
  20309. idDeltas += string16(0);
  20310. idRangeOffsets += string16(offset);
  20311. for (j = 0, jj = codes.length; j < jj; ++j) {
  20312. glyphsIds += string16(codes[j]);
  20313. }
  20314. } else {
  20315. var startCode = codes[0];
  20316. idDeltas += string16((startCode - start) & 0xFFFF);
  20317. idRangeOffsets += string16(0);
  20318. }
  20319. }
  20320. if (trailingRangesCount > 0) {
  20321. endCount += '\xFF\xFF';
  20322. startCount += '\xFF\xFF';
  20323. idDeltas += '\x00\x01';
  20324. idRangeOffsets += '\x00\x00';
  20325. }
  20326. var format314 = '\x00\x00' + // language
  20327. string16(2 * segCount) +
  20328. string16(searchParams.range) +
  20329. string16(searchParams.entry) +
  20330. string16(searchParams.rangeShift) +
  20331. endCount + '\x00\x00' + startCount +
  20332. idDeltas + idRangeOffsets + glyphsIds;
  20333. var format31012 = '';
  20334. var header31012 = '';
  20335. if (numTables > 1) {
  20336. cmap += '\x00\x03' + // platformID
  20337. '\x00\x0A' + // encodingID
  20338. string32(4 + numTables * 8 +
  20339. 4 + format314.length); // start of the table record
  20340. format31012 = '';
  20341. for (i = 0, ii = ranges.length; i < ii; i++) {
  20342. range = ranges[i];
  20343. start = range[0];
  20344. codes = range[2];
  20345. var code = codes[0];
  20346. for (j = 1, jj = codes.length; j < jj; ++j) {
  20347. if (codes[j] !== codes[j - 1] + 1) {
  20348. end = range[0] + j - 1;
  20349. format31012 += string32(start) + // startCharCode
  20350. string32(end) + // endCharCode
  20351. string32(code); // startGlyphID
  20352. start = end + 1;
  20353. code = codes[j];
  20354. }
  20355. }
  20356. format31012 += string32(start) + // startCharCode
  20357. string32(range[1]) + // endCharCode
  20358. string32(code); // startGlyphID
  20359. }
  20360. header31012 = '\x00\x0C' + // format
  20361. '\x00\x00' + // reserved
  20362. string32(format31012.length + 16) + // length
  20363. '\x00\x00\x00\x00' + // language
  20364. string32(format31012.length / 12); // nGroups
  20365. }
  20366. return cmap + '\x00\x04' + // format
  20367. string16(format314.length + 4) + // length
  20368. format314 + header31012 + format31012;
  20369. }
  20370. function validateOS2Table(os2) {
  20371. var stream = new Stream(os2.data);
  20372. var version = stream.getUint16();
  20373. // TODO verify all OS/2 tables fields, but currently we validate only those
  20374. // that give us issues
  20375. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  20376. var selection = stream.getUint16();
  20377. if (version < 4 && (selection & 0x0300)) {
  20378. return false;
  20379. }
  20380. var firstChar = stream.getUint16();
  20381. var lastChar = stream.getUint16();
  20382. if (firstChar > lastChar) {
  20383. return false;
  20384. }
  20385. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  20386. var usWinAscent = stream.getUint16();
  20387. if (usWinAscent === 0) { // makes font unreadable by windows
  20388. return false;
  20389. }
  20390. // OS/2 appears to be valid, resetting some fields
  20391. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  20392. return true;
  20393. }
  20394. function createOS2Table(properties, charstrings, override) {
  20395. override = override || {
  20396. unitsPerEm: 0,
  20397. yMax: 0,
  20398. yMin: 0,
  20399. ascent: 0,
  20400. descent: 0
  20401. };
  20402. var ulUnicodeRange1 = 0;
  20403. var ulUnicodeRange2 = 0;
  20404. var ulUnicodeRange3 = 0;
  20405. var ulUnicodeRange4 = 0;
  20406. var firstCharIndex = null;
  20407. var lastCharIndex = 0;
  20408. if (charstrings) {
  20409. for (var code in charstrings) {
  20410. code |= 0;
  20411. if (firstCharIndex > code || !firstCharIndex) {
  20412. firstCharIndex = code;
  20413. }
  20414. if (lastCharIndex < code) {
  20415. lastCharIndex = code;
  20416. }
  20417. var position = getUnicodeRangeFor(code);
  20418. if (position < 32) {
  20419. ulUnicodeRange1 |= 1 << position;
  20420. } else if (position < 64) {
  20421. ulUnicodeRange2 |= 1 << position - 32;
  20422. } else if (position < 96) {
  20423. ulUnicodeRange3 |= 1 << position - 64;
  20424. } else if (position < 123) {
  20425. ulUnicodeRange4 |= 1 << position - 96;
  20426. } else {
  20427. error('Unicode ranges Bits > 123 are reserved for internal usage');
  20428. }
  20429. }
  20430. } else {
  20431. // TODO
  20432. firstCharIndex = 0;
  20433. lastCharIndex = 255;
  20434. }
  20435. var bbox = properties.bbox || [0, 0, 0, 0];
  20436. var unitsPerEm = (override.unitsPerEm ||
  20437. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  20438. // if the font units differ to the PDF glyph space units
  20439. // then scale up the values
  20440. var scale = (properties.ascentScaled ? 1.0 :
  20441. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  20442. var typoAscent = (override.ascent ||
  20443. Math.round(scale * (properties.ascent || bbox[3])));
  20444. var typoDescent = (override.descent ||
  20445. Math.round(scale * (properties.descent || bbox[1])));
  20446. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  20447. typoDescent = -typoDescent; // fixing incorrect descent
  20448. }
  20449. var winAscent = override.yMax || typoAscent;
  20450. var winDescent = -override.yMin || -typoDescent;
  20451. return '\x00\x03' + // version
  20452. '\x02\x24' + // xAvgCharWidth
  20453. '\x01\xF4' + // usWeightClass
  20454. '\x00\x05' + // usWidthClass
  20455. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  20456. '\x02\x8A' + // ySubscriptXSize
  20457. '\x02\xBB' + // ySubscriptYSize
  20458. '\x00\x00' + // ySubscriptXOffset
  20459. '\x00\x8C' + // ySubscriptYOffset
  20460. '\x02\x8A' + // ySuperScriptXSize
  20461. '\x02\xBB' + // ySuperScriptYSize
  20462. '\x00\x00' + // ySuperScriptXOffset
  20463. '\x01\xDF' + // ySuperScriptYOffset
  20464. '\x00\x31' + // yStrikeOutSize
  20465. '\x01\x02' + // yStrikeOutPosition
  20466. '\x00\x00' + // sFamilyClass
  20467. '\x00\x00\x06' +
  20468. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  20469. '\x00\x00\x00\x00\x00\x00' + // Panose
  20470. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  20471. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  20472. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  20473. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  20474. '\x2A\x32\x31\x2A' + // achVendID
  20475. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  20476. string16(firstCharIndex ||
  20477. properties.firstChar) + // usFirstCharIndex
  20478. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  20479. string16(typoAscent) + // sTypoAscender
  20480. string16(typoDescent) + // sTypoDescender
  20481. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  20482. string16(winAscent) + // usWinAscent
  20483. string16(winDescent) + // usWinDescent
  20484. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  20485. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  20486. string16(properties.xHeight) + // sxHeight
  20487. string16(properties.capHeight) + // sCapHeight
  20488. string16(0) + // usDefaultChar
  20489. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  20490. '\x00\x03'; // usMaxContext
  20491. }
  20492. function createPostTable(properties) {
  20493. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  20494. return ('\x00\x03\x00\x00' + // Version number
  20495. string32(angle) + // italicAngle
  20496. '\x00\x00' + // underlinePosition
  20497. '\x00\x00' + // underlineThickness
  20498. string32(properties.fixedPitch) + // isFixedPitch
  20499. '\x00\x00\x00\x00' + // minMemType42
  20500. '\x00\x00\x00\x00' + // maxMemType42
  20501. '\x00\x00\x00\x00' + // minMemType1
  20502. '\x00\x00\x00\x00'); // maxMemType1
  20503. }
  20504. function createNameTable(name, proto) {
  20505. if (!proto) {
  20506. proto = [[], []]; // no strings and unicode strings
  20507. }
  20508. var strings = [
  20509. proto[0][0] || 'Original licence', // 0.Copyright
  20510. proto[0][1] || name, // 1.Font family
  20511. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  20512. proto[0][3] || 'uniqueID', // 3.Unique ID
  20513. proto[0][4] || name, // 4.Full font name
  20514. proto[0][5] || 'Version 0.11', // 5.Version
  20515. proto[0][6] || '', // 6.Postscript name
  20516. proto[0][7] || 'Unknown', // 7.Trademark
  20517. proto[0][8] || 'Unknown', // 8.Manufacturer
  20518. proto[0][9] || 'Unknown' // 9.Designer
  20519. ];
  20520. // Mac want 1-byte per character strings while Windows want
  20521. // 2-bytes per character, so duplicate the names table
  20522. var stringsUnicode = [];
  20523. var i, ii, j, jj, str;
  20524. for (i = 0, ii = strings.length; i < ii; i++) {
  20525. str = proto[1][i] || strings[i];
  20526. var strBufUnicode = [];
  20527. for (j = 0, jj = str.length; j < jj; j++) {
  20528. strBufUnicode.push(string16(str.charCodeAt(j)));
  20529. }
  20530. stringsUnicode.push(strBufUnicode.join(''));
  20531. }
  20532. var names = [strings, stringsUnicode];
  20533. var platforms = ['\x00\x01', '\x00\x03'];
  20534. var encodings = ['\x00\x00', '\x00\x01'];
  20535. var languages = ['\x00\x00', '\x04\x09'];
  20536. var namesRecordCount = strings.length * platforms.length;
  20537. var nameTable =
  20538. '\x00\x00' + // format
  20539. string16(namesRecordCount) + // Number of names Record
  20540. string16(namesRecordCount * 12 + 6); // Storage
  20541. // Build the name records field
  20542. var strOffset = 0;
  20543. for (i = 0, ii = platforms.length; i < ii; i++) {
  20544. var strs = names[i];
  20545. for (j = 0, jj = strs.length; j < jj; j++) {
  20546. str = strs[j];
  20547. var nameRecord =
  20548. platforms[i] + // platform ID
  20549. encodings[i] + // encoding ID
  20550. languages[i] + // language ID
  20551. string16(j) + // name ID
  20552. string16(str.length) +
  20553. string16(strOffset);
  20554. nameTable += nameRecord;
  20555. strOffset += str.length;
  20556. }
  20557. }
  20558. nameTable += strings.join('') + stringsUnicode.join('');
  20559. return nameTable;
  20560. }
  20561. Font.prototype = {
  20562. name: null,
  20563. font: null,
  20564. mimetype: null,
  20565. encoding: null,
  20566. get renderer() {
  20567. var renderer = FontRendererFactory.create(this);
  20568. return shadow(this, 'renderer', renderer);
  20569. },
  20570. exportData: function Font_exportData() {
  20571. var data = {};
  20572. for (var i in this) {
  20573. if (this.hasOwnProperty(i)) {
  20574. data[i] = this[i];
  20575. }
  20576. }
  20577. return data;
  20578. },
  20579. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  20580. function readTableEntry(file) {
  20581. var tag = bytesToString(file.getBytes(4));
  20582. var checksum = file.getInt32();
  20583. var offset = file.getInt32() >>> 0;
  20584. var length = file.getInt32() >>> 0;
  20585. // Read the table associated data
  20586. var previousPosition = file.pos;
  20587. file.pos = file.start ? file.start : 0;
  20588. file.skip(offset);
  20589. var data = file.getBytes(length);
  20590. file.pos = previousPosition;
  20591. if (tag === 'head') {
  20592. // clearing checksum adjustment
  20593. data[8] = data[9] = data[10] = data[11] = 0;
  20594. data[17] |= 0x20; //Set font optimized for cleartype flag
  20595. }
  20596. return {
  20597. tag: tag,
  20598. checksum: checksum,
  20599. length: length,
  20600. offset: offset,
  20601. data: data
  20602. };
  20603. }
  20604. function readOpenTypeHeader(ttf) {
  20605. return {
  20606. version: bytesToString(ttf.getBytes(4)),
  20607. numTables: ttf.getUint16(),
  20608. searchRange: ttf.getUint16(),
  20609. entrySelector: ttf.getUint16(),
  20610. rangeShift: ttf.getUint16()
  20611. };
  20612. }
  20613. /**
  20614. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  20615. * PDF spec
  20616. */
  20617. function readCmapTable(cmap, font, isSymbolicFont) {
  20618. var segment;
  20619. var start = (font.start ? font.start : 0) + cmap.offset;
  20620. font.pos = start;
  20621. var version = font.getUint16();
  20622. var numTables = font.getUint16();
  20623. var potentialTable;
  20624. var canBreak = false;
  20625. // There's an order of preference in terms of which cmap subtable to
  20626. // use:
  20627. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  20628. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  20629. // The following takes advantage of the fact that the tables are sorted
  20630. // to work.
  20631. for (var i = 0; i < numTables; i++) {
  20632. var platformId = font.getUint16();
  20633. var encodingId = font.getUint16();
  20634. var offset = font.getInt32() >>> 0;
  20635. var useTable = false;
  20636. if (platformId === 1 && encodingId === 0) {
  20637. useTable = true;
  20638. // Continue the loop since there still may be a higher priority
  20639. // table.
  20640. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  20641. useTable = true;
  20642. canBreak = true;
  20643. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  20644. useTable = true;
  20645. canBreak = true;
  20646. }
  20647. if (useTable) {
  20648. potentialTable = {
  20649. platformId: platformId,
  20650. encodingId: encodingId,
  20651. offset: offset
  20652. };
  20653. }
  20654. if (canBreak) {
  20655. break;
  20656. }
  20657. }
  20658. if (!potentialTable) {
  20659. warn('Could not find a preferred cmap table.');
  20660. return {
  20661. platformId: -1,
  20662. encodingId: -1,
  20663. mappings: [],
  20664. hasShortCmap: false
  20665. };
  20666. }
  20667. font.pos = start + potentialTable.offset;
  20668. var format = font.getUint16();
  20669. var length = font.getUint16();
  20670. var language = font.getUint16();
  20671. var hasShortCmap = false;
  20672. var mappings = [];
  20673. var j, glyphId;
  20674. // TODO(mack): refactor this cmap subtable reading logic out
  20675. if (format === 0) {
  20676. for (j = 0; j < 256; j++) {
  20677. var index = font.getByte();
  20678. if (!index) {
  20679. continue;
  20680. }
  20681. mappings.push({
  20682. charCode: j,
  20683. glyphId: index
  20684. });
  20685. }
  20686. hasShortCmap = true;
  20687. } else if (format === 4) {
  20688. // re-creating the table in format 4 since the encoding
  20689. // might be changed
  20690. var segCount = (font.getUint16() >> 1);
  20691. font.getBytes(6); // skipping range fields
  20692. var segIndex, segments = [];
  20693. for (segIndex = 0; segIndex < segCount; segIndex++) {
  20694. segments.push({ end: font.getUint16() });
  20695. }
  20696. font.getUint16();
  20697. for (segIndex = 0; segIndex < segCount; segIndex++) {
  20698. segments[segIndex].start = font.getUint16();
  20699. }
  20700. for (segIndex = 0; segIndex < segCount; segIndex++) {
  20701. segments[segIndex].delta = font.getUint16();
  20702. }
  20703. var offsetsCount = 0;
  20704. for (segIndex = 0; segIndex < segCount; segIndex++) {
  20705. segment = segments[segIndex];
  20706. var rangeOffset = font.getUint16();
  20707. if (!rangeOffset) {
  20708. segment.offsetIndex = -1;
  20709. continue;
  20710. }
  20711. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  20712. segment.offsetIndex = offsetIndex;
  20713. offsetsCount = Math.max(offsetsCount, offsetIndex +
  20714. segment.end - segment.start + 1);
  20715. }
  20716. var offsets = [];
  20717. for (j = 0; j < offsetsCount; j++) {
  20718. offsets.push(font.getUint16());
  20719. }
  20720. for (segIndex = 0; segIndex < segCount; segIndex++) {
  20721. segment = segments[segIndex];
  20722. start = segment.start;
  20723. var end = segment.end;
  20724. var delta = segment.delta;
  20725. offsetIndex = segment.offsetIndex;
  20726. for (j = start; j <= end; j++) {
  20727. if (j === 0xFFFF) {
  20728. continue;
  20729. }
  20730. glyphId = (offsetIndex < 0 ?
  20731. j : offsets[offsetIndex + j - start]);
  20732. glyphId = (glyphId + delta) & 0xFFFF;
  20733. if (glyphId === 0) {
  20734. continue;
  20735. }
  20736. mappings.push({
  20737. charCode: j,
  20738. glyphId: glyphId
  20739. });
  20740. }
  20741. }
  20742. } else if (format === 6) {
  20743. // Format 6 is a 2-bytes dense mapping, which means the font data
  20744. // lives glue together even if they are pretty far in the unicode
  20745. // table. (This looks weird, so I can have missed something), this
  20746. // works on Linux but seems to fails on Mac so let's rewrite the
  20747. // cmap table to a 3-1-4 style
  20748. var firstCode = font.getUint16();
  20749. var entryCount = font.getUint16();
  20750. for (j = 0; j < entryCount; j++) {
  20751. glyphId = font.getUint16();
  20752. var charCode = firstCode + j;
  20753. mappings.push({
  20754. charCode: charCode,
  20755. glyphId: glyphId
  20756. });
  20757. }
  20758. } else {
  20759. error('cmap table has unsupported format: ' + format);
  20760. }
  20761. // removing duplicate entries
  20762. mappings.sort(function (a, b) {
  20763. return a.charCode - b.charCode;
  20764. });
  20765. for (i = 1; i < mappings.length; i++) {
  20766. if (mappings[i - 1].charCode === mappings[i].charCode) {
  20767. mappings.splice(i, 1);
  20768. i--;
  20769. }
  20770. }
  20771. return {
  20772. platformId: potentialTable.platformId,
  20773. encodingId: potentialTable.encodingId,
  20774. mappings: mappings,
  20775. hasShortCmap: hasShortCmap
  20776. };
  20777. }
  20778. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  20779. if (!header) {
  20780. if (metrics) {
  20781. metrics.data = null;
  20782. }
  20783. return;
  20784. }
  20785. font.pos = (font.start ? font.start : 0) + header.offset;
  20786. font.pos += header.length - 2;
  20787. var numOfMetrics = font.getUint16();
  20788. if (numOfMetrics > numGlyphs) {
  20789. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  20790. 'greater than the numGlyphs (' + numGlyphs + ')');
  20791. // Reduce numOfMetrics if it is greater than numGlyphs
  20792. numOfMetrics = numGlyphs;
  20793. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  20794. header.data[35] = numOfMetrics & 0x00ff;
  20795. }
  20796. var numOfSidebearings = numGlyphs - numOfMetrics;
  20797. var numMissing = numOfSidebearings -
  20798. ((metrics.length - numOfMetrics * 4) >> 1);
  20799. var i, ii;
  20800. if (numMissing > 0) {
  20801. font.pos = (font.start ? font.start : 0) + metrics.offset;
  20802. var entries = '';
  20803. for (i = 0, ii = metrics.length; i < ii; i++) {
  20804. entries += String.fromCharCode(font.getByte());
  20805. }
  20806. for (i = 0; i < numMissing; i++) {
  20807. entries += '\x00\x00';
  20808. }
  20809. metrics.data = entries;
  20810. }
  20811. }
  20812. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  20813. hintsValid) {
  20814. if (sourceEnd - sourceStart <= 12) {
  20815. // glyph with data less than 12 is invalid one
  20816. return 0;
  20817. }
  20818. var glyf = source.subarray(sourceStart, sourceEnd);
  20819. var contoursCount = (glyf[0] << 8) | glyf[1];
  20820. if (contoursCount & 0x8000) {
  20821. // complex glyph, writing as is
  20822. dest.set(glyf, destStart);
  20823. return glyf.length;
  20824. }
  20825. var i, j = 10, flagsCount = 0;
  20826. for (i = 0; i < contoursCount; i++) {
  20827. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  20828. flagsCount = endPoint + 1;
  20829. j += 2;
  20830. }
  20831. // skipping instructions
  20832. var instructionsStart = j;
  20833. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  20834. j += 2 + instructionsLength;
  20835. var instructionsEnd = j;
  20836. // validating flags
  20837. var coordinatesLength = 0;
  20838. for (i = 0; i < flagsCount; i++) {
  20839. var flag = glyf[j++];
  20840. if (flag & 0xC0) {
  20841. // reserved flags must be zero, cleaning up
  20842. glyf[j - 1] = flag & 0x3F;
  20843. }
  20844. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  20845. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  20846. coordinatesLength += xyLength;
  20847. if (flag & 8) {
  20848. var repeat = glyf[j++];
  20849. i += repeat;
  20850. coordinatesLength += repeat * xyLength;
  20851. }
  20852. }
  20853. // glyph without coordinates will be rejected
  20854. if (coordinatesLength === 0) {
  20855. return 0;
  20856. }
  20857. var glyphDataLength = j + coordinatesLength;
  20858. if (glyphDataLength > glyf.length) {
  20859. // not enough data for coordinates
  20860. return 0;
  20861. }
  20862. if (!hintsValid && instructionsLength > 0) {
  20863. dest.set(glyf.subarray(0, instructionsStart), destStart);
  20864. dest.set([0, 0], destStart + instructionsStart);
  20865. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  20866. destStart + instructionsStart + 2);
  20867. glyphDataLength -= instructionsLength;
  20868. if (glyf.length - glyphDataLength > 3) {
  20869. glyphDataLength = (glyphDataLength + 3) & ~3;
  20870. }
  20871. return glyphDataLength;
  20872. }
  20873. if (glyf.length - glyphDataLength > 3) {
  20874. // truncating and aligning to 4 bytes the long glyph data
  20875. glyphDataLength = (glyphDataLength + 3) & ~3;
  20876. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  20877. return glyphDataLength;
  20878. }
  20879. // glyph data is fine
  20880. dest.set(glyf, destStart);
  20881. return glyf.length;
  20882. }
  20883. function sanitizeHead(head, numGlyphs, locaLength) {
  20884. var data = head.data;
  20885. // Validate version:
  20886. // Should always be 0x00010000
  20887. var version = int32(data[0], data[1], data[2], data[3]);
  20888. if (version >> 16 !== 1) {
  20889. info('Attempting to fix invalid version in head table: ' + version);
  20890. data[0] = 0;
  20891. data[1] = 1;
  20892. data[2] = 0;
  20893. data[3] = 0;
  20894. }
  20895. var indexToLocFormat = int16(data[50], data[51]);
  20896. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  20897. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  20898. indexToLocFormat);
  20899. // The value of indexToLocFormat should be 0 if the loca table
  20900. // consists of short offsets, and should be 1 if the loca table
  20901. // consists of long offsets.
  20902. //
  20903. // The number of entries in the loca table should be numGlyphs + 1.
  20904. //
  20905. // Using this information, we can work backwards to deduce if the
  20906. // size of each offset in the loca table, and thus figure out the
  20907. // appropriate value for indexToLocFormat.
  20908. var numGlyphsPlusOne = numGlyphs + 1;
  20909. if (locaLength === numGlyphsPlusOne << 1) {
  20910. // 0x0000 indicates the loca table consists of short offsets
  20911. data[50] = 0;
  20912. data[51] = 0;
  20913. } else if (locaLength === numGlyphsPlusOne << 2) {
  20914. // 0x0001 indicates the loca table consists of long offsets
  20915. data[50] = 0;
  20916. data[51] = 1;
  20917. } else {
  20918. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  20919. }
  20920. }
  20921. }
  20922. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  20923. isGlyphLocationsLong, hintsValid,
  20924. dupFirstEntry) {
  20925. var itemSize, itemDecode, itemEncode;
  20926. if (isGlyphLocationsLong) {
  20927. itemSize = 4;
  20928. itemDecode = function fontItemDecodeLong(data, offset) {
  20929. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20930. (data[offset + 2] << 8) | data[offset + 3];
  20931. };
  20932. itemEncode = function fontItemEncodeLong(data, offset, value) {
  20933. data[offset] = (value >>> 24) & 0xFF;
  20934. data[offset + 1] = (value >> 16) & 0xFF;
  20935. data[offset + 2] = (value >> 8) & 0xFF;
  20936. data[offset + 3] = value & 0xFF;
  20937. };
  20938. } else {
  20939. itemSize = 2;
  20940. itemDecode = function fontItemDecode(data, offset) {
  20941. return (data[offset] << 9) | (data[offset + 1] << 1);
  20942. };
  20943. itemEncode = function fontItemEncode(data, offset, value) {
  20944. data[offset] = (value >> 9) & 0xFF;
  20945. data[offset + 1] = (value >> 1) & 0xFF;
  20946. };
  20947. }
  20948. var locaData = loca.data;
  20949. var locaDataSize = itemSize * (1 + numGlyphs);
  20950. // is loca.data too short or long?
  20951. if (locaData.length !== locaDataSize) {
  20952. locaData = new Uint8Array(locaDataSize);
  20953. locaData.set(loca.data.subarray(0, locaDataSize));
  20954. loca.data = locaData;
  20955. }
  20956. // removing the invalid glyphs
  20957. var oldGlyfData = glyf.data;
  20958. var oldGlyfDataLength = oldGlyfData.length;
  20959. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  20960. var startOffset = itemDecode(locaData, 0);
  20961. var writeOffset = 0;
  20962. itemEncode(locaData, 0, writeOffset);
  20963. var i, j;
  20964. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  20965. var endOffset = itemDecode(locaData, j);
  20966. if (endOffset > oldGlyfDataLength &&
  20967. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  20968. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  20969. // the glyf table size, which makes last glyph out of range.
  20970. endOffset = oldGlyfDataLength;
  20971. }
  20972. if (endOffset > oldGlyfDataLength) {
  20973. // glyph end offset points outside glyf data, rejecting the glyph
  20974. itemEncode(locaData, j, writeOffset);
  20975. startOffset = endOffset;
  20976. continue;
  20977. }
  20978. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  20979. newGlyfData, writeOffset, hintsValid);
  20980. writeOffset += newLength;
  20981. itemEncode(locaData, j, writeOffset);
  20982. startOffset = endOffset;
  20983. }
  20984. if (writeOffset === 0) {
  20985. // glyf table cannot be empty -- redoing the glyf and loca tables
  20986. // to have single glyph with one point
  20987. var simpleGlyph = new Uint8Array(
  20988. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  20989. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  20990. itemEncode(locaData, j, simpleGlyph.length);
  20991. }
  20992. glyf.data = simpleGlyph;
  20993. return;
  20994. }
  20995. if (dupFirstEntry) {
  20996. var firstEntryLength = itemDecode(locaData, itemSize);
  20997. if (newGlyfData.length > firstEntryLength + writeOffset) {
  20998. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  20999. } else {
  21000. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21001. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21002. }
  21003. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21004. itemEncode(loca.data, locaData.length - itemSize,
  21005. writeOffset + firstEntryLength);
  21006. } else {
  21007. glyf.data = newGlyfData.subarray(0, writeOffset);
  21008. }
  21009. }
  21010. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21011. var start = (font.start ? font.start : 0) + post.offset;
  21012. font.pos = start;
  21013. var length = post.length, end = start + length;
  21014. var version = font.getInt32();
  21015. // skip rest to the tables
  21016. font.getBytes(28);
  21017. var glyphNames;
  21018. var valid = true;
  21019. var i;
  21020. switch (version) {
  21021. case 0x00010000:
  21022. glyphNames = MacStandardGlyphOrdering;
  21023. break;
  21024. case 0x00020000:
  21025. var numGlyphs = font.getUint16();
  21026. if (numGlyphs !== maxpNumGlyphs) {
  21027. valid = false;
  21028. break;
  21029. }
  21030. var glyphNameIndexes = [];
  21031. for (i = 0; i < numGlyphs; ++i) {
  21032. var index = font.getUint16();
  21033. if (index >= 32768) {
  21034. valid = false;
  21035. break;
  21036. }
  21037. glyphNameIndexes.push(index);
  21038. }
  21039. if (!valid) {
  21040. break;
  21041. }
  21042. var customNames = [];
  21043. var strBuf = [];
  21044. while (font.pos < end) {
  21045. var stringLength = font.getByte();
  21046. strBuf.length = stringLength;
  21047. for (i = 0; i < stringLength; ++i) {
  21048. strBuf[i] = String.fromCharCode(font.getByte());
  21049. }
  21050. customNames.push(strBuf.join(''));
  21051. }
  21052. glyphNames = [];
  21053. for (i = 0; i < numGlyphs; ++i) {
  21054. var j = glyphNameIndexes[i];
  21055. if (j < 258) {
  21056. glyphNames.push(MacStandardGlyphOrdering[j]);
  21057. continue;
  21058. }
  21059. glyphNames.push(customNames[j - 258]);
  21060. }
  21061. break;
  21062. case 0x00030000:
  21063. break;
  21064. default:
  21065. warn('Unknown/unsupported post table version ' + version);
  21066. valid = false;
  21067. break;
  21068. }
  21069. properties.glyphNames = glyphNames;
  21070. return valid;
  21071. }
  21072. function readNameTable(nameTable) {
  21073. var start = (font.start ? font.start : 0) + nameTable.offset;
  21074. font.pos = start;
  21075. var names = [[], []];
  21076. var length = nameTable.length, end = start + length;
  21077. var format = font.getUint16();
  21078. var FORMAT_0_HEADER_LENGTH = 6;
  21079. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  21080. // unsupported name table format or table "too" small
  21081. return names;
  21082. }
  21083. var numRecords = font.getUint16();
  21084. var stringsStart = font.getUint16();
  21085. var records = [];
  21086. var NAME_RECORD_LENGTH = 12;
  21087. var i, ii;
  21088. for (i = 0; i < numRecords &&
  21089. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  21090. var r = {
  21091. platform: font.getUint16(),
  21092. encoding: font.getUint16(),
  21093. language: font.getUint16(),
  21094. name: font.getUint16(),
  21095. length: font.getUint16(),
  21096. offset: font.getUint16()
  21097. };
  21098. // using only Macintosh and Windows platform/encoding names
  21099. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  21100. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  21101. records.push(r);
  21102. }
  21103. }
  21104. for (i = 0, ii = records.length; i < ii; i++) {
  21105. var record = records[i];
  21106. var pos = start + stringsStart + record.offset;
  21107. if (pos + record.length > end) {
  21108. continue; // outside of name table, ignoring
  21109. }
  21110. font.pos = pos;
  21111. var nameIndex = record.name;
  21112. if (record.encoding) {
  21113. // unicode
  21114. var str = '';
  21115. for (var j = 0, jj = record.length; j < jj; j += 2) {
  21116. str += String.fromCharCode(font.getUint16());
  21117. }
  21118. names[1][nameIndex] = str;
  21119. } else {
  21120. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  21121. }
  21122. }
  21123. return names;
  21124. }
  21125. var TTOpsStackDeltas = [
  21126. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  21127. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  21128. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  21129. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  21130. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  21131. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  21132. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21133. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  21134. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  21135. // 0xC0-DF == -1 and 0xE0-FF == -2
  21136. function sanitizeTTProgram(table, ttContext) {
  21137. var data = table.data;
  21138. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  21139. var stack = [];
  21140. var callstack = [];
  21141. var functionsCalled = [];
  21142. var tooComplexToFollowFunctions =
  21143. ttContext.tooComplexToFollowFunctions;
  21144. var inFDEF = false, ifLevel = 0, inELSE = 0;
  21145. for (var ii = data.length; i < ii;) {
  21146. var op = data[i++];
  21147. // The TrueType instruction set docs can be found at
  21148. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  21149. if (op === 0x40) { // NPUSHB - pushes n bytes
  21150. n = data[i++];
  21151. if (inFDEF || inELSE) {
  21152. i += n;
  21153. } else {
  21154. for (j = 0; j < n; j++) {
  21155. stack.push(data[i++]);
  21156. }
  21157. }
  21158. } else if (op === 0x41) { // NPUSHW - pushes n words
  21159. n = data[i++];
  21160. if (inFDEF || inELSE) {
  21161. i += n * 2;
  21162. } else {
  21163. for (j = 0; j < n; j++) {
  21164. b = data[i++];
  21165. stack.push((b << 8) | data[i++]);
  21166. }
  21167. }
  21168. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  21169. n = op - 0xB0 + 1;
  21170. if (inFDEF || inELSE) {
  21171. i += n;
  21172. } else {
  21173. for (j = 0; j < n; j++) {
  21174. stack.push(data[i++]);
  21175. }
  21176. }
  21177. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  21178. n = op - 0xB8 + 1;
  21179. if (inFDEF || inELSE) {
  21180. i += n * 2;
  21181. } else {
  21182. for (j = 0; j < n; j++) {
  21183. b = data[i++];
  21184. stack.push((b << 8) | data[i++]);
  21185. }
  21186. }
  21187. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  21188. if (!inFDEF && !inELSE) {
  21189. // collecting inforamtion about which functions are used
  21190. funcId = stack[stack.length - 1];
  21191. ttContext.functionsUsed[funcId] = true;
  21192. if (funcId in ttContext.functionsStackDeltas) {
  21193. stack.length += ttContext.functionsStackDeltas[funcId];
  21194. } else if (funcId in ttContext.functionsDefined &&
  21195. functionsCalled.indexOf(funcId) < 0) {
  21196. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  21197. functionsCalled.push(funcId);
  21198. pc = ttContext.functionsDefined[funcId];
  21199. if (!pc) {
  21200. warn('TT: CALL non-existent function');
  21201. ttContext.hintsValid = false;
  21202. return;
  21203. }
  21204. data = pc.data;
  21205. i = pc.i;
  21206. }
  21207. }
  21208. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  21209. if (inFDEF || inELSE) {
  21210. warn('TT: nested FDEFs not allowed');
  21211. tooComplexToFollowFunctions = true;
  21212. }
  21213. inFDEF = true;
  21214. // collecting inforamtion about which functions are defined
  21215. lastDeff = i;
  21216. funcId = stack.pop();
  21217. ttContext.functionsDefined[funcId] = {data: data, i: i};
  21218. } else if (op === 0x2D) { // ENDF - end of function
  21219. if (inFDEF) {
  21220. inFDEF = false;
  21221. lastEndf = i;
  21222. } else {
  21223. pc = callstack.pop();
  21224. if (!pc) {
  21225. warn('TT: ENDF bad stack');
  21226. ttContext.hintsValid = false;
  21227. return;
  21228. }
  21229. funcId = functionsCalled.pop();
  21230. data = pc.data;
  21231. i = pc.i;
  21232. ttContext.functionsStackDeltas[funcId] =
  21233. stack.length - pc.stackTop;
  21234. }
  21235. } else if (op === 0x89) { // IDEF - instruction definition
  21236. if (inFDEF || inELSE) {
  21237. warn('TT: nested IDEFs not allowed');
  21238. tooComplexToFollowFunctions = true;
  21239. }
  21240. inFDEF = true;
  21241. // recording it as a function to track ENDF
  21242. lastDeff = i;
  21243. } else if (op === 0x58) { // IF
  21244. ++ifLevel;
  21245. } else if (op === 0x1B) { // ELSE
  21246. inELSE = ifLevel;
  21247. } else if (op === 0x59) { // EIF
  21248. if (inELSE === ifLevel) {
  21249. inELSE = 0;
  21250. }
  21251. --ifLevel;
  21252. } else if (op === 0x1C) { // JMPR
  21253. if (!inFDEF && !inELSE) {
  21254. var offset = stack[stack.length - 1];
  21255. // only jumping forward to prevent infinite loop
  21256. if (offset > 0) {
  21257. i += offset - 1;
  21258. }
  21259. }
  21260. }
  21261. // Adjusting stack not extactly, but just enough to get function id
  21262. if (!inFDEF && !inELSE) {
  21263. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  21264. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  21265. if (op >= 0x71 && op <= 0x75) {
  21266. n = stack.pop();
  21267. if (n === n) {
  21268. stackDelta = -n * 2;
  21269. }
  21270. }
  21271. while (stackDelta < 0 && stack.length > 0) {
  21272. stack.pop();
  21273. stackDelta++;
  21274. }
  21275. while (stackDelta > 0) {
  21276. stack.push(NaN); // pushing any number into stack
  21277. stackDelta--;
  21278. }
  21279. }
  21280. }
  21281. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  21282. var content = [data];
  21283. if (i > data.length) {
  21284. content.push(new Uint8Array(i - data.length));
  21285. }
  21286. if (lastDeff > lastEndf) {
  21287. warn('TT: complementing a missing function tail');
  21288. // new function definition started, but not finished
  21289. // complete function by [CLEAR, ENDF]
  21290. content.push(new Uint8Array([0x22, 0x2D]));
  21291. }
  21292. foldTTTable(table, content);
  21293. }
  21294. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  21295. if (ttContext.tooComplexToFollowFunctions) {
  21296. return;
  21297. }
  21298. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  21299. warn('TT: more functions defined than expected');
  21300. ttContext.hintsValid = false;
  21301. return;
  21302. }
  21303. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  21304. if (j > maxFunctionDefs) {
  21305. warn('TT: invalid function id: ' + j);
  21306. ttContext.hintsValid = false;
  21307. return;
  21308. }
  21309. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  21310. warn('TT: undefined function: ' + j);
  21311. ttContext.hintsValid = false;
  21312. return;
  21313. }
  21314. }
  21315. }
  21316. function foldTTTable(table, content) {
  21317. if (content.length > 1) {
  21318. // concatenating the content items
  21319. var newLength = 0;
  21320. var j, jj;
  21321. for (j = 0, jj = content.length; j < jj; j++) {
  21322. newLength += content[j].length;
  21323. }
  21324. newLength = (newLength + 3) & ~3;
  21325. var result = new Uint8Array(newLength);
  21326. var pos = 0;
  21327. for (j = 0, jj = content.length; j < jj; j++) {
  21328. result.set(content[j], pos);
  21329. pos += content[j].length;
  21330. }
  21331. table.data = result;
  21332. table.length = newLength;
  21333. }
  21334. }
  21335. function sanitizeTTPrograms(fpgm, prep, cvt) {
  21336. var ttContext = {
  21337. functionsDefined: [],
  21338. functionsUsed: [],
  21339. functionsStackDeltas: [],
  21340. tooComplexToFollowFunctions: false,
  21341. hintsValid: true
  21342. };
  21343. if (fpgm) {
  21344. sanitizeTTProgram(fpgm, ttContext);
  21345. }
  21346. if (prep) {
  21347. sanitizeTTProgram(prep, ttContext);
  21348. }
  21349. if (fpgm) {
  21350. checkInvalidFunctions(ttContext, maxFunctionDefs);
  21351. }
  21352. if (cvt && (cvt.length & 1)) {
  21353. var cvtData = new Uint8Array(cvt.length + 1);
  21354. cvtData.set(cvt.data);
  21355. cvt.data = cvtData;
  21356. }
  21357. return ttContext.hintsValid;
  21358. }
  21359. // The following steps modify the original font data, making copy
  21360. font = new Stream(new Uint8Array(font.getBytes()));
  21361. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  21362. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  21363. var header = readOpenTypeHeader(font);
  21364. var numTables = header.numTables;
  21365. var cff, cffFile;
  21366. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  21367. hmtx: null, maxp: null, name: null, post: null };
  21368. var table;
  21369. for (var i = 0; i < numTables; i++) {
  21370. table = readTableEntry(font);
  21371. if (VALID_TABLES.indexOf(table.tag) < 0) {
  21372. continue; // skipping table if it's not a required or optional table
  21373. }
  21374. if (table.length === 0) {
  21375. continue; // skipping empty tables
  21376. }
  21377. tables[table.tag] = table;
  21378. }
  21379. var isTrueType = !tables['CFF '];
  21380. if (!isTrueType) {
  21381. // OpenType font
  21382. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  21383. // no major tables: throwing everything at CFFFont
  21384. cffFile = new Stream(tables['CFF '].data);
  21385. cff = new CFFFont(cffFile, properties);
  21386. return this.convert(name, cff, properties);
  21387. }
  21388. delete tables.glyf;
  21389. delete tables.loca;
  21390. delete tables.fpgm;
  21391. delete tables.prep;
  21392. delete tables['cvt '];
  21393. this.isOpenType = true;
  21394. } else {
  21395. if (!tables.glyf || !tables.loca) {
  21396. error('Required "glyf" or "loca" tables are not found');
  21397. }
  21398. this.isOpenType = false;
  21399. }
  21400. if (!tables.maxp) {
  21401. error('Required "maxp" table is not found');
  21402. }
  21403. font.pos = (font.start || 0) + tables.maxp.offset;
  21404. var version = font.getInt32();
  21405. var numGlyphs = font.getUint16();
  21406. var maxFunctionDefs = 0;
  21407. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  21408. // maxZones can be invalid
  21409. font.pos += 8;
  21410. var maxZones = font.getUint16();
  21411. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  21412. tables.maxp.data[14] = 0;
  21413. tables.maxp.data[15] = 2;
  21414. }
  21415. font.pos += 4;
  21416. maxFunctionDefs = font.getUint16();
  21417. }
  21418. var dupFirstEntry = false;
  21419. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  21420. properties.toUnicode.get(0) > '\u0000') {
  21421. // oracle's defect (see 3427), duplicating first entry
  21422. dupFirstEntry = true;
  21423. numGlyphs++;
  21424. tables.maxp.data[4] = numGlyphs >> 8;
  21425. tables.maxp.data[5] = numGlyphs & 255;
  21426. }
  21427. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  21428. tables['cvt '], maxFunctionDefs);
  21429. if (!hintsValid) {
  21430. delete tables.fpgm;
  21431. delete tables.prep;
  21432. delete tables['cvt '];
  21433. }
  21434. // Ensure the hmtx table contains the advance width and
  21435. // sidebearings information for numGlyphs in the maxp table
  21436. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  21437. if (!tables.head) {
  21438. error('Required "head" table is not found');
  21439. }
  21440. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  21441. if (isTrueType) {
  21442. var isGlyphLocationsLong = int16(tables.head.data[50],
  21443. tables.head.data[51]);
  21444. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  21445. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  21446. }
  21447. if (!tables.hhea) {
  21448. error('Required "hhea" table is not found');
  21449. }
  21450. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  21451. // Sometimes it's 0. That needs to be fixed
  21452. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  21453. tables.hhea.data[10] = 0xFF;
  21454. tables.hhea.data[11] = 0xFF;
  21455. }
  21456. // The 'post' table has glyphs names.
  21457. if (tables.post) {
  21458. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  21459. if (!valid) {
  21460. tables.post = null;
  21461. }
  21462. }
  21463. var charCodeToGlyphId = [], charCode;
  21464. if (properties.type === 'CIDFontType2') {
  21465. var cidToGidMap = properties.cidToGidMap || [];
  21466. var cidToGidMapLength = cidToGidMap.length;
  21467. properties.cMap.forEach(function(charCode, cid) {
  21468. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  21469. var glyphId = -1;
  21470. if (cidToGidMapLength === 0) {
  21471. glyphId = charCode;
  21472. } else if (cidToGidMap[cid] !== undefined) {
  21473. glyphId = cidToGidMap[cid];
  21474. }
  21475. if (glyphId >= 0 && glyphId < numGlyphs) {
  21476. charCodeToGlyphId[charCode] = glyphId;
  21477. }
  21478. });
  21479. if (dupFirstEntry) {
  21480. charCodeToGlyphId[0] = numGlyphs - 1;
  21481. }
  21482. } else {
  21483. // Most of the following logic in this code branch is based on the
  21484. // 9.6.6.4 of the PDF spec.
  21485. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  21486. var cmapPlatformId = cmapTable.platformId;
  21487. var cmapEncodingId = cmapTable.encodingId;
  21488. var cmapMappings = cmapTable.mappings;
  21489. var cmapMappingsLength = cmapMappings.length;
  21490. var hasEncoding = properties.differences.length ||
  21491. !!properties.baseEncodingName;
  21492. // The spec seems to imply that if the font is symbolic the encoding
  21493. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  21494. // where the the font is symbolic and it has an encoding.
  21495. if (hasEncoding &&
  21496. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  21497. cmapPlatformId === 1 && cmapEncodingId === 0)) {
  21498. var baseEncoding = [];
  21499. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  21500. properties.baseEncodingName === 'WinAnsiEncoding') {
  21501. baseEncoding = Encodings[properties.baseEncodingName];
  21502. }
  21503. for (charCode = 0; charCode < 256; charCode++) {
  21504. var glyphName;
  21505. if (this.differences && charCode in this.differences) {
  21506. glyphName = this.differences[charCode];
  21507. } else if (charCode in baseEncoding &&
  21508. baseEncoding[charCode] !== '') {
  21509. glyphName = baseEncoding[charCode];
  21510. } else {
  21511. glyphName = Encodings.StandardEncoding[charCode];
  21512. }
  21513. if (!glyphName) {
  21514. continue;
  21515. }
  21516. var unicodeOrCharCode;
  21517. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  21518. unicodeOrCharCode = GlyphsUnicode[glyphName];
  21519. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  21520. // TODO: the encoding needs to be updated with mac os table.
  21521. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  21522. }
  21523. var found = false;
  21524. for (i = 0; i < cmapMappingsLength; ++i) {
  21525. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  21526. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  21527. found = true;
  21528. break;
  21529. }
  21530. }
  21531. if (!found && properties.glyphNames) {
  21532. // Try to map using the post table. There are currently no known
  21533. // pdfs that this fixes.
  21534. var glyphId = properties.glyphNames.indexOf(glyphName);
  21535. if (glyphId > 0) {
  21536. charCodeToGlyphId[charCode] = glyphId;
  21537. }
  21538. }
  21539. }
  21540. } else {
  21541. // For (3, 0) cmap tables:
  21542. // The charcode key being stored in charCodeToGlyphId is the lower
  21543. // byte of the two-byte charcodes of the cmap table since according to
  21544. // the spec: 'each byte from the string shall be prepended with the
  21545. // high byte of the range [of charcodes in the cmap table], to form
  21546. // a two-byte character, which shall be used to select the
  21547. // associated glyph description from the subtable'.
  21548. //
  21549. // For (1, 0) cmap tables:
  21550. // 'single bytes from the string shall be used to look up the
  21551. // associated glyph descriptions from the subtable'. This means
  21552. // charcodes in the cmap will be single bytes, so no-op since
  21553. // glyph.charCode & 0xFF === glyph.charCode
  21554. for (i = 0; i < cmapMappingsLength; ++i) {
  21555. charCode = cmapMappings[i].charCode & 0xFF;
  21556. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  21557. }
  21558. }
  21559. }
  21560. if (charCodeToGlyphId.length === 0) {
  21561. // defines at least one glyph
  21562. charCodeToGlyphId[0] = 0;
  21563. }
  21564. // Converting glyphs and ids into font's cmap table
  21565. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  21566. this.toFontChar = newMapping.toFontChar;
  21567. tables.cmap = {
  21568. tag: 'cmap',
  21569. data: createCmapTable(newMapping.charCodeToGlyphId)
  21570. };
  21571. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  21572. // extract some more font properties from the OpenType head and
  21573. // hhea tables; yMin and descent value are always negative
  21574. var override = {
  21575. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  21576. yMax: int16(tables.head.data[42], tables.head.data[43]),
  21577. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  21578. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  21579. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  21580. };
  21581. tables['OS/2'] = {
  21582. tag: 'OS/2',
  21583. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  21584. override)
  21585. };
  21586. }
  21587. // Rewrite the 'post' table if needed
  21588. if (!tables.post) {
  21589. tables.post = {
  21590. tag: 'post',
  21591. data: createPostTable(properties)
  21592. };
  21593. }
  21594. if (!isTrueType) {
  21595. try {
  21596. // Trying to repair CFF file
  21597. cffFile = new Stream(tables['CFF '].data);
  21598. var parser = new CFFParser(cffFile, properties);
  21599. cff = parser.parse();
  21600. var compiler = new CFFCompiler(cff);
  21601. tables['CFF '].data = compiler.compile();
  21602. } catch (e) {
  21603. warn('Failed to compile font ' + properties.loadedName);
  21604. }
  21605. }
  21606. // Re-creating 'name' table
  21607. if (!tables.name) {
  21608. tables.name = {
  21609. tag: 'name',
  21610. data: createNameTable(this.name)
  21611. };
  21612. } else {
  21613. // ... using existing 'name' table as prototype
  21614. var namePrototype = readNameTable(tables.name);
  21615. tables.name.data = createNameTable(name, namePrototype);
  21616. }
  21617. var builder = new OpenTypeFileBuilder(header.version);
  21618. for (var tableTag in tables) {
  21619. builder.addTable(tableTag, tables[tableTag].data);
  21620. }
  21621. return builder.toArray();
  21622. },
  21623. convert: function Font_convert(fontName, font, properties) {
  21624. // TODO: Check the charstring widths to determine this.
  21625. properties.fixedPitch = false;
  21626. var mapping = font.getGlyphMapping(properties);
  21627. var newMapping = adjustMapping(mapping, properties);
  21628. this.toFontChar = newMapping.toFontChar;
  21629. var numGlyphs = font.numGlyphs;
  21630. function getCharCodes(charCodeToGlyphId, glyphId) {
  21631. var charCodes = null;
  21632. for (var charCode in charCodeToGlyphId) {
  21633. if (glyphId === charCodeToGlyphId[charCode]) {
  21634. if (!charCodes) {
  21635. charCodes = [];
  21636. }
  21637. charCodes.push(charCode | 0);
  21638. }
  21639. }
  21640. return charCodes;
  21641. }
  21642. function createCharCode(charCodeToGlyphId, glyphId) {
  21643. for (var charCode in charCodeToGlyphId) {
  21644. if (glyphId === charCodeToGlyphId[charCode]) {
  21645. return charCode | 0;
  21646. }
  21647. }
  21648. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  21649. glyphId;
  21650. return newMapping.nextAvailableFontCharCode++;
  21651. }
  21652. var seacs = font.seacs;
  21653. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  21654. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  21655. var charset = font.getCharset();
  21656. var seacMap = Object.create(null);
  21657. for (var glyphId in seacs) {
  21658. glyphId |= 0;
  21659. var seac = seacs[glyphId];
  21660. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  21661. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  21662. var baseGlyphId = charset.indexOf(baseGlyphName);
  21663. var accentGlyphId = charset.indexOf(accentGlyphName);
  21664. if (baseGlyphId < 0 || accentGlyphId < 0) {
  21665. continue;
  21666. }
  21667. var accentOffset = {
  21668. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  21669. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  21670. };
  21671. var charCodes = getCharCodes(mapping, glyphId);
  21672. if (!charCodes) {
  21673. // There's no point in mapping it if the char code was never mapped
  21674. // to begin with.
  21675. continue;
  21676. }
  21677. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  21678. var charCode = charCodes[i];
  21679. // Find a fontCharCode that maps to the base and accent glyphs.
  21680. // If one doesn't exists, create it.
  21681. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  21682. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  21683. baseGlyphId);
  21684. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  21685. accentGlyphId);
  21686. seacMap[charCode] = {
  21687. baseFontCharCode: baseFontCharCode,
  21688. accentFontCharCode: accentFontCharCode,
  21689. accentOffset: accentOffset
  21690. };
  21691. }
  21692. }
  21693. properties.seacMap = seacMap;
  21694. }
  21695. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  21696. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  21697. // PostScript Font Program
  21698. builder.addTable('CFF ', font.data);
  21699. // OS/2 and Windows Specific metrics
  21700. builder.addTable('OS/2', createOS2Table(properties,
  21701. newMapping.charCodeToGlyphId));
  21702. // Character to glyphs mapping
  21703. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  21704. // Font header
  21705. builder.addTable('head',
  21706. '\x00\x01\x00\x00' + // Version number
  21707. '\x00\x00\x10\x00' + // fontRevision
  21708. '\x00\x00\x00\x00' + // checksumAdjustement
  21709. '\x5F\x0F\x3C\xF5' + // magicNumber
  21710. '\x00\x00' + // Flags
  21711. safeString16(unitsPerEm) + // unitsPerEM
  21712. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  21713. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  21714. '\x00\x00' + // xMin
  21715. safeString16(properties.descent) + // yMin
  21716. '\x0F\xFF' + // xMax
  21717. safeString16(properties.ascent) + // yMax
  21718. string16(properties.italicAngle ? 2 : 0) + // macStyle
  21719. '\x00\x11' + // lowestRecPPEM
  21720. '\x00\x00' + // fontDirectionHint
  21721. '\x00\x00' + // indexToLocFormat
  21722. '\x00\x00'); // glyphDataFormat
  21723. // Horizontal header
  21724. builder.addTable('hhea',
  21725. '\x00\x01\x00\x00' + // Version number
  21726. safeString16(properties.ascent) + // Typographic Ascent
  21727. safeString16(properties.descent) + // Typographic Descent
  21728. '\x00\x00' + // Line Gap
  21729. '\xFF\xFF' + // advanceWidthMax
  21730. '\x00\x00' + // minLeftSidebearing
  21731. '\x00\x00' + // minRightSidebearing
  21732. '\x00\x00' + // xMaxExtent
  21733. safeString16(properties.capHeight) + // caretSlopeRise
  21734. safeString16(Math.tan(properties.italicAngle) *
  21735. properties.xHeight) + // caretSlopeRun
  21736. '\x00\x00' + // caretOffset
  21737. '\x00\x00' + // -reserved-
  21738. '\x00\x00' + // -reserved-
  21739. '\x00\x00' + // -reserved-
  21740. '\x00\x00' + // -reserved-
  21741. '\x00\x00' + // metricDataFormat
  21742. string16(numGlyphs)); // Number of HMetrics
  21743. // Horizontal metrics
  21744. builder.addTable('hmtx', (function fontFieldsHmtx() {
  21745. var charstrings = font.charstrings;
  21746. var cffWidths = font.cff ? font.cff.widths : null;
  21747. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  21748. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  21749. var width = 0;
  21750. if (charstrings) {
  21751. var charstring = charstrings[i - 1];
  21752. width = 'width' in charstring ? charstring.width : 0;
  21753. } else if (cffWidths) {
  21754. width = Math.ceil(cffWidths[i] || 0);
  21755. }
  21756. hmtx += string16(width) + string16(0);
  21757. }
  21758. return hmtx;
  21759. })());
  21760. // Maximum profile
  21761. builder.addTable('maxp',
  21762. '\x00\x00\x50\x00' + // Version number
  21763. string16(numGlyphs)); // Num of glyphs
  21764. // Naming tables
  21765. builder.addTable('name', createNameTable(fontName));
  21766. // PostScript informations
  21767. builder.addTable('post', createPostTable(properties));
  21768. return builder.toArray();
  21769. },
  21770. /**
  21771. * Builds a char code to unicode map based on section 9.10 of the spec.
  21772. * @param {Object} properties Font properties object.
  21773. * @return {Object} A ToUnicodeMap object.
  21774. */
  21775. buildToUnicode: function Font_buildToUnicode(properties) {
  21776. // Section 9.10.2 Mapping Character Codes to Unicode Values
  21777. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  21778. return properties.toUnicode;
  21779. }
  21780. // According to the spec if the font is a simple font we should only map
  21781. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  21782. // the differences array only contains adobe standard or symbol set names,
  21783. // in pratice it seems better to always try to create a toUnicode
  21784. // map based of the default encoding.
  21785. var toUnicode, charcode;
  21786. if (!properties.composite /* is simple font */) {
  21787. toUnicode = [];
  21788. var encoding = properties.defaultEncoding.slice();
  21789. var baseEncodingName = properties.baseEncodingName;
  21790. // Merge in the differences array.
  21791. var differences = properties.differences;
  21792. for (charcode in differences) {
  21793. encoding[charcode] = differences[charcode];
  21794. }
  21795. for (charcode in encoding) {
  21796. // a) Map the character code to a character name.
  21797. var glyphName = encoding[charcode];
  21798. // b) Look up the character name in the Adobe Glyph List (see the
  21799. // Bibliography) to obtain the corresponding Unicode value.
  21800. if (glyphName === '') {
  21801. continue;
  21802. } else if (GlyphsUnicode[glyphName] === undefined) {
  21803. // (undocumented) c) Few heuristics to recognize unknown glyphs
  21804. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  21805. var code = 0;
  21806. switch (glyphName[0]) {
  21807. case 'G': // Gxx glyph
  21808. if (glyphName.length === 3) {
  21809. code = parseInt(glyphName.substr(1), 16);
  21810. }
  21811. break;
  21812. case 'g': // g00xx glyph
  21813. if (glyphName.length === 5) {
  21814. code = parseInt(glyphName.substr(1), 16);
  21815. }
  21816. break;
  21817. case 'C': // Cddd glyph
  21818. case 'c': // cddd glyph
  21819. if (glyphName.length >= 3) {
  21820. code = +glyphName.substr(1);
  21821. }
  21822. break;
  21823. }
  21824. if (code) {
  21825. // If |baseEncodingName| is one the predefined encodings,
  21826. // and |code| equals |charcode|, using the glyph defined in the
  21827. // baseEncoding seems to yield a better |toUnicode| mapping
  21828. // (fixes issue 5070).
  21829. if (baseEncodingName && code === +charcode) {
  21830. var baseEncoding = Encodings[baseEncodingName];
  21831. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  21832. toUnicode[charcode] =
  21833. String.fromCharCode(GlyphsUnicode[glyphName]);
  21834. continue;
  21835. }
  21836. }
  21837. toUnicode[charcode] = String.fromCharCode(code);
  21838. }
  21839. continue;
  21840. }
  21841. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  21842. }
  21843. return new ToUnicodeMap(toUnicode);
  21844. }
  21845. // If the font is a composite font that uses one of the predefined CMaps
  21846. // listed in Table 118 (except Identity–H and Identity–V) or whose
  21847. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  21848. // Adobe-Korea1 character collection:
  21849. if (properties.composite && (
  21850. (properties.cMap.builtInCMap &&
  21851. !(properties.cMap instanceof IdentityCMap)) ||
  21852. (properties.cidSystemInfo.registry === 'Adobe' &&
  21853. (properties.cidSystemInfo.ordering === 'GB1' ||
  21854. properties.cidSystemInfo.ordering === 'CNS1' ||
  21855. properties.cidSystemInfo.ordering === 'Japan1' ||
  21856. properties.cidSystemInfo.ordering === 'Korea1')))) {
  21857. // Then:
  21858. // a) Map the character code to a character identifier (CID) according
  21859. // to the font’s CMap.
  21860. // b) Obtain the registry and ordering of the character collection used
  21861. // by the font’s CMap (for example, Adobe and Japan1) from its
  21862. // CIDSystemInfo dictionary.
  21863. var registry = properties.cidSystemInfo.registry;
  21864. var ordering = properties.cidSystemInfo.ordering;
  21865. // c) Construct a second CMap name by concatenating the registry and
  21866. // ordering obtained in step (b) in the format registry–ordering–UCS2
  21867. // (for example, Adobe–Japan1–UCS2).
  21868. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  21869. // d) Obtain the CMap with the name constructed in step (c) (available
  21870. // from the ASN Web site; see the Bibliography).
  21871. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  21872. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  21873. var cMap = properties.cMap;
  21874. toUnicode = [];
  21875. cMap.forEach(function(charcode, cid) {
  21876. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  21877. // e) Map the CID obtained in step (a) according to the CMap obtained
  21878. // in step (d), producing a Unicode value.
  21879. var ucs2 = ucs2CMap.lookup(cid);
  21880. if (ucs2) {
  21881. toUnicode[charcode] =
  21882. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  21883. ucs2.charCodeAt(1));
  21884. }
  21885. });
  21886. return new ToUnicodeMap(toUnicode);
  21887. }
  21888. // The viewer's choice, just use an identity map.
  21889. return new IdentityToUnicodeMap(properties.firstChar,
  21890. properties.lastChar);
  21891. },
  21892. get spaceWidth() {
  21893. if ('_shadowWidth' in this) {
  21894. return this._shadowWidth;
  21895. }
  21896. // trying to estimate space character width
  21897. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  21898. var width;
  21899. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  21900. var glyphName = possibleSpaceReplacements[i];
  21901. // if possible, getting width by glyph name
  21902. if (glyphName in this.widths) {
  21903. width = this.widths[glyphName];
  21904. break;
  21905. }
  21906. var glyphUnicode = GlyphsUnicode[glyphName];
  21907. // finding the charcode via unicodeToCID map
  21908. var charcode = 0;
  21909. if (this.composite) {
  21910. if (this.cMap.contains(glyphUnicode)) {
  21911. charcode = this.cMap.lookup(glyphUnicode);
  21912. }
  21913. }
  21914. // ... via toUnicode map
  21915. if (!charcode && 'toUnicode' in this) {
  21916. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  21917. }
  21918. // setting it to unicode if negative or undefined
  21919. if (charcode <= 0) {
  21920. charcode = glyphUnicode;
  21921. }
  21922. // trying to get width via charcode
  21923. width = this.widths[charcode];
  21924. if (width) {
  21925. break; // the non-zero width found
  21926. }
  21927. }
  21928. width = width || this.defaultWidth;
  21929. // Do not shadow the property here. See discussion:
  21930. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  21931. this._shadowWidth = width;
  21932. return width;
  21933. },
  21934. charToGlyph: function Font_charToGlyph(charcode) {
  21935. var fontCharCode, width, operatorListId;
  21936. var widthCode = charcode;
  21937. if (this.cMap && this.cMap.contains(charcode)) {
  21938. widthCode = this.cMap.lookup(charcode);
  21939. }
  21940. width = this.widths[widthCode];
  21941. width = isNum(width) ? width : this.defaultWidth;
  21942. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  21943. var unicode = this.toUnicode.get(charcode) || charcode;
  21944. if (typeof unicode === 'number') {
  21945. unicode = String.fromCharCode(unicode);
  21946. }
  21947. // First try the toFontChar map, if it's not there then try falling
  21948. // back to the char code.
  21949. fontCharCode = this.toFontChar[charcode] || charcode;
  21950. if (this.missingFile) {
  21951. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  21952. }
  21953. if (this.isType3Font) {
  21954. // Font char code in this case is actually a glyph name.
  21955. operatorListId = fontCharCode;
  21956. }
  21957. var accent = null;
  21958. if (this.seacMap && this.seacMap[charcode]) {
  21959. var seac = this.seacMap[charcode];
  21960. fontCharCode = seac.baseFontCharCode;
  21961. accent = {
  21962. fontChar: String.fromCharCode(seac.accentFontCharCode),
  21963. offset: seac.accentOffset
  21964. };
  21965. }
  21966. var fontChar = String.fromCharCode(fontCharCode);
  21967. var glyph = this.glyphCache[charcode];
  21968. if (!glyph ||
  21969. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  21970. operatorListId)) {
  21971. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  21972. operatorListId);
  21973. this.glyphCache[charcode] = glyph;
  21974. }
  21975. return glyph;
  21976. },
  21977. charsToGlyphs: function Font_charsToGlyphs(chars) {
  21978. var charsCache = this.charsCache;
  21979. var glyphs, glyph, charcode;
  21980. // if we translated this string before, just grab it from the cache
  21981. if (charsCache) {
  21982. glyphs = charsCache[chars];
  21983. if (glyphs) {
  21984. return glyphs;
  21985. }
  21986. }
  21987. // lazily create the translation cache
  21988. if (!charsCache) {
  21989. charsCache = this.charsCache = Object.create(null);
  21990. }
  21991. glyphs = [];
  21992. var charsCacheKey = chars;
  21993. var i = 0, ii;
  21994. if (this.cMap) {
  21995. // composite fonts have multi-byte strings convert the string from
  21996. // single-byte to multi-byte
  21997. var c = {};
  21998. while (i < chars.length) {
  21999. this.cMap.readCharCode(chars, i, c);
  22000. charcode = c.charcode;
  22001. var length = c.length;
  22002. i += length;
  22003. glyph = this.charToGlyph(charcode);
  22004. glyphs.push(glyph);
  22005. // placing null after each word break charcode (ASCII SPACE)
  22006. // Ignore occurences of 0x20 in multiple-byte codes.
  22007. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22008. glyphs.push(null);
  22009. }
  22010. }
  22011. } else {
  22012. for (i = 0, ii = chars.length; i < ii; ++i) {
  22013. charcode = chars.charCodeAt(i);
  22014. glyph = this.charToGlyph(charcode);
  22015. glyphs.push(glyph);
  22016. if (charcode === 0x20) {
  22017. glyphs.push(null);
  22018. }
  22019. }
  22020. }
  22021. // Enter the translated string into the cache
  22022. return (charsCache[charsCacheKey] = glyphs);
  22023. }
  22024. };
  22025. return Font;
  22026. })();
  22027. var ErrorFont = (function ErrorFontClosure() {
  22028. function ErrorFont(error) {
  22029. this.error = error;
  22030. this.loadedName = 'g_font_error';
  22031. this.loading = false;
  22032. }
  22033. ErrorFont.prototype = {
  22034. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22035. return [];
  22036. },
  22037. exportData: function ErrorFont_exportData() {
  22038. return {error: this.error};
  22039. }
  22040. };
  22041. return ErrorFont;
  22042. })();
  22043. /**
  22044. * Shared logic for building a char code to glyph id mapping for Type1 and
  22045. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22046. * @param {Object} properties Font properties object.
  22047. * @param {Object} builtInEncoding The encoding contained within the actual font
  22048. * data.
  22049. * @param {Array} Array of glyph names where the index is the glyph ID.
  22050. * @returns {Object} A char code to glyph ID map.
  22051. */
  22052. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  22053. var charCodeToGlyphId = Object.create(null);
  22054. var glyphId, charCode, baseEncoding;
  22055. if (properties.baseEncodingName) {
  22056. // If a valid base encoding name was used, the mapping is initialized with
  22057. // that.
  22058. baseEncoding = Encodings[properties.baseEncodingName];
  22059. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22060. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22061. if (glyphId >= 0) {
  22062. charCodeToGlyphId[charCode] = glyphId;
  22063. }
  22064. }
  22065. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  22066. // For a symbolic font the encoding should be the fonts built-in
  22067. // encoding.
  22068. for (charCode in builtInEncoding) {
  22069. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  22070. }
  22071. } else {
  22072. // For non-symbolic fonts that don't have a base encoding the standard
  22073. // encoding should be used.
  22074. baseEncoding = Encodings.StandardEncoding;
  22075. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22076. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22077. if (glyphId >= 0) {
  22078. charCodeToGlyphId[charCode] = glyphId;
  22079. }
  22080. }
  22081. }
  22082. // Lastly, merge in the differences.
  22083. var differences = properties.differences;
  22084. if (differences) {
  22085. for (charCode in differences) {
  22086. var glyphName = differences[charCode];
  22087. glyphId = glyphNames.indexOf(glyphName);
  22088. if (glyphId >= 0) {
  22089. charCodeToGlyphId[charCode] = glyphId;
  22090. }
  22091. }
  22092. }
  22093. return charCodeToGlyphId;
  22094. }
  22095. /*
  22096. * CharStrings are encoded following the the CharString Encoding sequence
  22097. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  22098. * The value in a byte indicates a command, a number, or subsequent bytes
  22099. * that are to be interpreted in a special way.
  22100. *
  22101. * CharString Number Encoding:
  22102. * A CharString byte containing the values from 32 through 255 inclusive
  22103. * indicate an integer. These values are decoded in four ranges.
  22104. *
  22105. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  22106. * indicate the integer v - 139. Thus, the integer values from -107 through
  22107. * 107 inclusive may be encoded in single byte.
  22108. *
  22109. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  22110. * indicates an integer involving the next byte, w, according to the formula:
  22111. * [(v - 247) x 256] + w + 108
  22112. *
  22113. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  22114. * indicates an integer involving the next byte, w, according to the formula:
  22115. * -[(v - 251) * 256] - w - 108
  22116. *
  22117. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  22118. * are a two complement signed integer. The first of these bytes contains the
  22119. * highest order bits, the second byte contains the next higher order bits
  22120. * and the fourth byte contain the lowest order bits.
  22121. *
  22122. *
  22123. * CharString Command Encoding:
  22124. * CharStrings commands are encoded in 1 or 2 bytes.
  22125. *
  22126. * Single byte commands are encoded in 1 byte that contains a value between
  22127. * 0 and 31 inclusive.
  22128. * If a command byte contains the value 12, then the value in the next byte
  22129. * indicates a command. This "escape" mechanism allows many extra commands
  22130. * to be encoded and this encoding technique helps to minimize the length of
  22131. * the charStrings.
  22132. */
  22133. var Type1CharString = (function Type1CharStringClosure() {
  22134. var COMMAND_MAP = {
  22135. 'hstem': [1],
  22136. 'vstem': [3],
  22137. 'vmoveto': [4],
  22138. 'rlineto': [5],
  22139. 'hlineto': [6],
  22140. 'vlineto': [7],
  22141. 'rrcurveto': [8],
  22142. 'callsubr': [10],
  22143. 'flex': [12, 35],
  22144. 'drop' : [12, 18],
  22145. 'endchar': [14],
  22146. 'rmoveto': [21],
  22147. 'hmoveto': [22],
  22148. 'vhcurveto': [30],
  22149. 'hvcurveto': [31]
  22150. };
  22151. function Type1CharString() {
  22152. this.width = 0;
  22153. this.lsb = 0;
  22154. this.flexing = false;
  22155. this.output = [];
  22156. this.stack = [];
  22157. }
  22158. Type1CharString.prototype = {
  22159. convert: function Type1CharString_convert(encoded, subrs) {
  22160. var count = encoded.length;
  22161. var error = false;
  22162. var wx, sbx, subrNumber;
  22163. for (var i = 0; i < count; i++) {
  22164. var value = encoded[i];
  22165. if (value < 32) {
  22166. if (value === 12) {
  22167. value = (value << 8) + encoded[++i];
  22168. }
  22169. switch (value) {
  22170. case 1: // hstem
  22171. if (!HINTING_ENABLED) {
  22172. this.stack = [];
  22173. break;
  22174. }
  22175. error = this.executeCommand(2, COMMAND_MAP.hstem);
  22176. break;
  22177. case 3: // vstem
  22178. if (!HINTING_ENABLED) {
  22179. this.stack = [];
  22180. break;
  22181. }
  22182. error = this.executeCommand(2, COMMAND_MAP.vstem);
  22183. break;
  22184. case 4: // vmoveto
  22185. if (this.flexing) {
  22186. if (this.stack.length < 1) {
  22187. error = true;
  22188. break;
  22189. }
  22190. // Add the dx for flex and but also swap the values so they are
  22191. // the right order.
  22192. var dy = this.stack.pop();
  22193. this.stack.push(0, dy);
  22194. break;
  22195. }
  22196. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  22197. break;
  22198. case 5: // rlineto
  22199. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  22200. break;
  22201. case 6: // hlineto
  22202. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  22203. break;
  22204. case 7: // vlineto
  22205. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  22206. break;
  22207. case 8: // rrcurveto
  22208. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  22209. break;
  22210. case 9: // closepath
  22211. // closepath is a Type1 command that does not take argument and is
  22212. // useless in Type2 and it can simply be ignored.
  22213. this.stack = [];
  22214. break;
  22215. case 10: // callsubr
  22216. if (this.stack.length < 1) {
  22217. error = true;
  22218. break;
  22219. }
  22220. subrNumber = this.stack.pop();
  22221. error = this.convert(subrs[subrNumber], subrs);
  22222. break;
  22223. case 11: // return
  22224. return error;
  22225. case 13: // hsbw
  22226. if (this.stack.length < 2) {
  22227. error = true;
  22228. break;
  22229. }
  22230. // To convert to type2 we have to move the width value to the
  22231. // first part of the charstring and then use hmoveto with lsb.
  22232. wx = this.stack.pop();
  22233. sbx = this.stack.pop();
  22234. this.lsb = sbx;
  22235. this.width = wx;
  22236. this.stack.push(wx, sbx);
  22237. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  22238. break;
  22239. case 14: // endchar
  22240. this.output.push(COMMAND_MAP.endchar[0]);
  22241. break;
  22242. case 21: // rmoveto
  22243. if (this.flexing) {
  22244. break;
  22245. }
  22246. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  22247. break;
  22248. case 22: // hmoveto
  22249. if (this.flexing) {
  22250. // Add the dy for flex.
  22251. this.stack.push(0);
  22252. break;
  22253. }
  22254. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  22255. break;
  22256. case 30: // vhcurveto
  22257. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  22258. break;
  22259. case 31: // hvcurveto
  22260. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  22261. break;
  22262. case (12 << 8) + 0: // dotsection
  22263. // dotsection is a Type1 command to specify some hinting feature
  22264. // for dots that do not take a parameter and it can safely be
  22265. // ignored for Type2.
  22266. this.stack = [];
  22267. break;
  22268. case (12 << 8) + 1: // vstem3
  22269. if (!HINTING_ENABLED) {
  22270. this.stack = [];
  22271. break;
  22272. }
  22273. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  22274. // multiple parameters, so instead of returning [vh]stem3 take a
  22275. // shortcut and return [vhstem] instead.
  22276. error = this.executeCommand(2, COMMAND_MAP.vstem);
  22277. break;
  22278. case (12 << 8) + 2: // hstem3
  22279. if (!HINTING_ENABLED) {
  22280. this.stack = [];
  22281. break;
  22282. }
  22283. // See vstem3.
  22284. error = this.executeCommand(2, COMMAND_MAP.hstem);
  22285. break;
  22286. case (12 << 8) + 6: // seac
  22287. // seac is like type 2's special endchar but it doesn't use the
  22288. // first argument asb, so remove it.
  22289. if (SEAC_ANALYSIS_ENABLED) {
  22290. this.seac = this.stack.splice(-4, 4);
  22291. error = this.executeCommand(0, COMMAND_MAP.endchar);
  22292. } else {
  22293. error = this.executeCommand(4, COMMAND_MAP.endchar);
  22294. }
  22295. break;
  22296. case (12 << 8) + 7: // sbw
  22297. if (this.stack.length < 4) {
  22298. error = true;
  22299. break;
  22300. }
  22301. // To convert to type2 we have to move the width value to the
  22302. // first part of the charstring and then use rmoveto with
  22303. // (dx, dy). The height argument will not be used for vmtx and
  22304. // vhea tables reconstruction -- ignoring it.
  22305. var wy = this.stack.pop();
  22306. wx = this.stack.pop();
  22307. var sby = this.stack.pop();
  22308. sbx = this.stack.pop();
  22309. this.lsb = sbx;
  22310. this.width = wx;
  22311. this.stack.push(wx, sbx, sby);
  22312. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  22313. break;
  22314. case (12 << 8) + 12: // div
  22315. if (this.stack.length < 2) {
  22316. error = true;
  22317. break;
  22318. }
  22319. var num2 = this.stack.pop();
  22320. var num1 = this.stack.pop();
  22321. this.stack.push(num1 / num2);
  22322. break;
  22323. case (12 << 8) + 16: // callothersubr
  22324. if (this.stack.length < 2) {
  22325. error = true;
  22326. break;
  22327. }
  22328. subrNumber = this.stack.pop();
  22329. var numArgs = this.stack.pop();
  22330. if (subrNumber === 0 && numArgs === 3) {
  22331. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  22332. this.stack.push(
  22333. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  22334. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  22335. flexArgs[4], // bcp2x
  22336. flexArgs[5], // bcp2y
  22337. flexArgs[6], // p2x
  22338. flexArgs[7], // p2y
  22339. flexArgs[8], // bcp3x
  22340. flexArgs[9], // bcp3y
  22341. flexArgs[10], // bcp4x
  22342. flexArgs[11], // bcp4y
  22343. flexArgs[12], // p3x
  22344. flexArgs[13], // p3y
  22345. flexArgs[14] // flexDepth
  22346. // 15 = finalx unused by flex
  22347. // 16 = finaly unused by flex
  22348. );
  22349. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  22350. this.flexing = false;
  22351. this.stack.push(flexArgs[15], flexArgs[16]);
  22352. } else if (subrNumber === 1 && numArgs === 0) {
  22353. this.flexing = true;
  22354. }
  22355. break;
  22356. case (12 << 8) + 17: // pop
  22357. // Ignore this since it is only used with othersubr.
  22358. break;
  22359. case (12 << 8) + 33: // setcurrentpoint
  22360. // Ignore for now.
  22361. this.stack = [];
  22362. break;
  22363. default:
  22364. warn('Unknown type 1 charstring command of "' + value + '"');
  22365. break;
  22366. }
  22367. if (error) {
  22368. break;
  22369. }
  22370. continue;
  22371. } else if (value <= 246) {
  22372. value = value - 139;
  22373. } else if (value <= 250) {
  22374. value = ((value - 247) * 256) + encoded[++i] + 108;
  22375. } else if (value <= 254) {
  22376. value = -((value - 251) * 256) - encoded[++i] - 108;
  22377. } else {
  22378. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  22379. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  22380. }
  22381. this.stack.push(value);
  22382. }
  22383. return error;
  22384. },
  22385. executeCommand: function(howManyArgs, command, keepStack) {
  22386. var stackLength = this.stack.length;
  22387. if (howManyArgs > stackLength) {
  22388. return true;
  22389. }
  22390. var start = stackLength - howManyArgs;
  22391. for (var i = start; i < stackLength; i++) {
  22392. var value = this.stack[i];
  22393. if (value === (value | 0)) { // int
  22394. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  22395. } else { // fixed point
  22396. value = (65536 * value) | 0;
  22397. this.output.push(255,
  22398. (value >> 24) & 0xFF,
  22399. (value >> 16) & 0xFF,
  22400. (value >> 8) & 0xFF,
  22401. value & 0xFF);
  22402. }
  22403. }
  22404. this.output.push.apply(this.output, command);
  22405. if (keepStack) {
  22406. this.stack.splice(start, howManyArgs);
  22407. } else {
  22408. this.stack.length = 0;
  22409. }
  22410. return false;
  22411. }
  22412. };
  22413. return Type1CharString;
  22414. })();
  22415. /*
  22416. * Type1Parser encapsulate the needed code for parsing a Type1 font
  22417. * program. Some of its logic depends on the Type2 charstrings
  22418. * structure.
  22419. * Note: this doesn't really parse the font since that would require evaluation
  22420. * of PostScript, but it is possible in most cases to extract what we need
  22421. * without a full parse.
  22422. */
  22423. var Type1Parser = (function Type1ParserClosure() {
  22424. /*
  22425. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  22426. * of Plaintext Bytes. The function took a key as a parameter which can be
  22427. * for decrypting the eexec block of for decoding charStrings.
  22428. */
  22429. var EEXEC_ENCRYPT_KEY = 55665;
  22430. var CHAR_STRS_ENCRYPT_KEY = 4330;
  22431. function isHexDigit(code) {
  22432. return code >= 48 && code <= 57 || // '0'-'9'
  22433. code >= 65 && code <= 70 || // 'A'-'F'
  22434. code >= 97 && code <= 102; // 'a'-'f'
  22435. }
  22436. function decrypt(data, key, discardNumber) {
  22437. var r = key | 0, c1 = 52845, c2 = 22719;
  22438. var count = data.length;
  22439. var decrypted = new Uint8Array(count);
  22440. for (var i = 0; i < count; i++) {
  22441. var value = data[i];
  22442. decrypted[i] = value ^ (r >> 8);
  22443. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  22444. }
  22445. return Array.prototype.slice.call(decrypted, discardNumber);
  22446. }
  22447. function decryptAscii(data, key, discardNumber) {
  22448. var r = key | 0, c1 = 52845, c2 = 22719;
  22449. var count = data.length, maybeLength = count >>> 1;
  22450. var decrypted = new Uint8Array(maybeLength);
  22451. var i, j;
  22452. for (i = 0, j = 0; i < count; i++) {
  22453. var digit1 = data[i];
  22454. if (!isHexDigit(digit1)) {
  22455. continue;
  22456. }
  22457. i++;
  22458. var digit2;
  22459. while (i < count && !isHexDigit(digit2 = data[i])) {
  22460. i++;
  22461. }
  22462. if (i < count) {
  22463. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  22464. decrypted[j++] = value ^ (r >> 8);
  22465. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  22466. }
  22467. }
  22468. return Array.prototype.slice.call(decrypted, discardNumber, j);
  22469. }
  22470. function isSpecial(c) {
  22471. return c === 0x2F || // '/'
  22472. c === 0x5B || c === 0x5D || // '[', ']'
  22473. c === 0x7B || c === 0x7D || // '{', '}'
  22474. c === 0x28 || c === 0x29; // '(', ')'
  22475. }
  22476. function Type1Parser(stream, encrypted) {
  22477. if (encrypted) {
  22478. var data = stream.getBytes();
  22479. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  22480. isHexDigit(data[2]) && isHexDigit(data[3]));
  22481. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  22482. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  22483. }
  22484. this.stream = stream;
  22485. this.nextChar();
  22486. }
  22487. Type1Parser.prototype = {
  22488. readNumberArray: function Type1Parser_readNumberArray() {
  22489. this.getToken(); // read '[' or '{' (arrays can start with either)
  22490. var array = [];
  22491. while (true) {
  22492. var token = this.getToken();
  22493. if (token === null || token === ']' || token === '}') {
  22494. break;
  22495. }
  22496. array.push(parseFloat(token || 0));
  22497. }
  22498. return array;
  22499. },
  22500. readNumber: function Type1Parser_readNumber() {
  22501. var token = this.getToken();
  22502. return parseFloat(token || 0);
  22503. },
  22504. readInt: function Type1Parser_readInt() {
  22505. // Use '| 0' to prevent setting a double into length such as the double
  22506. // does not flow into the loop variable.
  22507. var token = this.getToken();
  22508. return parseInt(token || 0, 10) | 0;
  22509. },
  22510. readBoolean: function Type1Parser_readBoolean() {
  22511. var token = this.getToken();
  22512. // Use 1 and 0 since that's what type2 charstrings use.
  22513. return token === 'true' ? 1 : 0;
  22514. },
  22515. nextChar : function Type1_nextChar() {
  22516. return (this.currentChar = this.stream.getByte());
  22517. },
  22518. getToken: function Type1Parser_getToken() {
  22519. // Eat whitespace and comments.
  22520. var comment = false;
  22521. var ch = this.currentChar;
  22522. while (true) {
  22523. if (ch === -1) {
  22524. return null;
  22525. }
  22526. if (comment) {
  22527. if (ch === 0x0A || ch === 0x0D) {
  22528. comment = false;
  22529. }
  22530. } else if (ch === 0x25) { // '%'
  22531. comment = true;
  22532. } else if (!Lexer.isSpace(ch)) {
  22533. break;
  22534. }
  22535. ch = this.nextChar();
  22536. }
  22537. if (isSpecial(ch)) {
  22538. this.nextChar();
  22539. return String.fromCharCode(ch);
  22540. }
  22541. var token = '';
  22542. do {
  22543. token += String.fromCharCode(ch);
  22544. ch = this.nextChar();
  22545. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  22546. return token;
  22547. },
  22548. /*
  22549. * Returns an object containing a Subrs array and a CharStrings
  22550. * array extracted from and eexec encrypted block of data
  22551. */
  22552. extractFontProgram: function Type1Parser_extractFontProgram() {
  22553. var stream = this.stream;
  22554. var subrs = [], charstrings = [];
  22555. var program = {
  22556. subrs: [],
  22557. charstrings: [],
  22558. properties: {
  22559. 'privateData': {
  22560. 'lenIV': 4
  22561. }
  22562. }
  22563. };
  22564. var token, length, data, lenIV, encoded;
  22565. while ((token = this.getToken()) !== null) {
  22566. if (token !== '/') {
  22567. continue;
  22568. }
  22569. token = this.getToken();
  22570. switch (token) {
  22571. case 'CharStrings':
  22572. // The number immediately following CharStrings must be greater or
  22573. // equal to the number of CharStrings.
  22574. this.getToken();
  22575. this.getToken(); // read in 'dict'
  22576. this.getToken(); // read in 'dup'
  22577. this.getToken(); // read in 'begin'
  22578. while(true) {
  22579. token = this.getToken();
  22580. if (token === null || token === 'end') {
  22581. break;
  22582. }
  22583. if (token !== '/') {
  22584. continue;
  22585. }
  22586. var glyph = this.getToken();
  22587. length = this.readInt();
  22588. this.getToken(); // read in 'RD' or '-|'
  22589. data = stream.makeSubStream(stream.pos, length);
  22590. lenIV = program.properties.privateData['lenIV'];
  22591. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  22592. // Skip past the required space and binary data.
  22593. stream.skip(length);
  22594. this.nextChar();
  22595. token = this.getToken(); // read in 'ND' or '|-'
  22596. if (token === 'noaccess') {
  22597. this.getToken(); // read in 'def'
  22598. }
  22599. charstrings.push({
  22600. glyph: glyph,
  22601. encoded: encoded
  22602. });
  22603. }
  22604. break;
  22605. case 'Subrs':
  22606. var num = this.readInt();
  22607. this.getToken(); // read in 'array'
  22608. while ((token = this.getToken()) === 'dup') {
  22609. var index = this.readInt();
  22610. length = this.readInt();
  22611. this.getToken(); // read in 'RD' or '-|'
  22612. data = stream.makeSubStream(stream.pos, length);
  22613. lenIV = program.properties.privateData['lenIV'];
  22614. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  22615. // Skip past the required space and binary data.
  22616. stream.skip(length);
  22617. this.nextChar();
  22618. token = this.getToken(); // read in 'NP' or '|'
  22619. if (token === 'noaccess') {
  22620. this.getToken(); // read in 'put'
  22621. }
  22622. subrs[index] = encoded;
  22623. }
  22624. break;
  22625. case 'BlueValues':
  22626. case 'OtherBlues':
  22627. case 'FamilyBlues':
  22628. case 'FamilyOtherBlues':
  22629. var blueArray = this.readNumberArray();
  22630. // *Blue* values may contain invalid data: disables reading of
  22631. // those values when hinting is disabled.
  22632. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  22633. HINTING_ENABLED) {
  22634. program.properties.privateData[token] = blueArray;
  22635. }
  22636. break;
  22637. case 'StemSnapH':
  22638. case 'StemSnapV':
  22639. program.properties.privateData[token] = this.readNumberArray();
  22640. break;
  22641. case 'StdHW':
  22642. case 'StdVW':
  22643. program.properties.privateData[token] =
  22644. this.readNumberArray()[0];
  22645. break;
  22646. case 'BlueShift':
  22647. case 'lenIV':
  22648. case 'BlueFuzz':
  22649. case 'BlueScale':
  22650. case 'LanguageGroup':
  22651. case 'ExpansionFactor':
  22652. program.properties.privateData[token] = this.readNumber();
  22653. break;
  22654. case 'ForceBold':
  22655. program.properties.privateData[token] = this.readBoolean();
  22656. break;
  22657. }
  22658. }
  22659. for (var i = 0; i < charstrings.length; i++) {
  22660. glyph = charstrings[i].glyph;
  22661. encoded = charstrings[i].encoded;
  22662. var charString = new Type1CharString();
  22663. var error = charString.convert(encoded, subrs);
  22664. var output = charString.output;
  22665. if (error) {
  22666. // It seems when FreeType encounters an error while evaluating a glyph
  22667. // that it completely ignores the glyph so we'll mimic that behaviour
  22668. // here and put an endchar to make the validator happy.
  22669. output = [14];
  22670. }
  22671. program.charstrings.push({
  22672. glyphName: glyph,
  22673. charstring: output,
  22674. width: charString.width,
  22675. lsb: charString.lsb,
  22676. seac: charString.seac
  22677. });
  22678. }
  22679. return program;
  22680. },
  22681. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  22682. var token;
  22683. while ((token = this.getToken()) !== null) {
  22684. if (token !== '/') {
  22685. continue;
  22686. }
  22687. token = this.getToken();
  22688. switch (token) {
  22689. case 'FontMatrix':
  22690. var matrix = this.readNumberArray();
  22691. properties.fontMatrix = matrix;
  22692. break;
  22693. case 'Encoding':
  22694. var encodingArg = this.getToken();
  22695. var encoding;
  22696. if (!/^\d+$/.test(encodingArg)) {
  22697. // encoding name is specified
  22698. encoding = Encodings[encodingArg];
  22699. } else {
  22700. encoding = [];
  22701. var size = parseInt(encodingArg, 10) | 0;
  22702. this.getToken(); // read in 'array'
  22703. for (var j = 0; j < size; j++) {
  22704. token = this.getToken();
  22705. // skipping till first dup or def (e.g. ignoring for statement)
  22706. while (token !== 'dup' && token !== 'def') {
  22707. token = this.getToken();
  22708. if (token === null) {
  22709. return; // invalid header
  22710. }
  22711. }
  22712. if (token === 'def') {
  22713. break; // read all array data
  22714. }
  22715. var index = this.readInt();
  22716. this.getToken(); // read in '/'
  22717. var glyph = this.getToken();
  22718. encoding[index] = glyph;
  22719. this.getToken(); // read the in 'put'
  22720. }
  22721. }
  22722. properties.builtInEncoding = encoding;
  22723. break;
  22724. case 'FontBBox':
  22725. var fontBBox = this.readNumberArray();
  22726. // adjusting ascent/descent
  22727. properties.ascent = fontBBox[3];
  22728. properties.descent = fontBBox[1];
  22729. properties.ascentScaled = true;
  22730. break;
  22731. }
  22732. }
  22733. }
  22734. };
  22735. return Type1Parser;
  22736. })();
  22737. /**
  22738. * The CFF class takes a Type1 file and wrap it into a
  22739. * 'Compact Font Format' which itself embed Type2 charstrings.
  22740. */
  22741. var CFFStandardStrings = [
  22742. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  22743. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  22744. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  22745. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  22746. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  22747. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  22748. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  22749. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  22750. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  22751. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  22752. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  22753. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  22754. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  22755. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  22756. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  22757. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  22758. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  22759. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  22760. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  22761. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  22762. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  22763. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  22764. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  22765. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  22766. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  22767. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  22768. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  22769. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  22770. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  22771. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  22772. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  22773. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  22774. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  22775. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  22776. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  22777. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  22778. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  22779. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  22780. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  22781. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  22782. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  22783. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  22784. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  22785. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  22786. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  22787. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  22788. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  22789. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  22790. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  22791. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  22792. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  22793. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  22794. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  22795. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  22796. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  22797. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  22798. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  22799. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  22800. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  22801. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  22802. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  22803. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  22804. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  22805. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  22806. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  22807. ];
  22808. // Type1Font is also a CIDFontType0.
  22809. var Type1Font = function Type1Font(name, file, properties) {
  22810. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  22811. // Also, length1 and length2 might be off by 6 bytes as well.
  22812. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  22813. var PFB_HEADER_SIZE = 6;
  22814. var headerBlockLength = properties.length1;
  22815. var eexecBlockLength = properties.length2;
  22816. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  22817. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  22818. if (pfbHeaderPresent) {
  22819. file.skip(PFB_HEADER_SIZE);
  22820. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  22821. (pfbHeader[3] << 8) | pfbHeader[2];
  22822. }
  22823. // Get the data block containing glyphs and subrs informations
  22824. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  22825. var headerBlockParser = new Type1Parser(headerBlock);
  22826. headerBlockParser.extractFontHeader(properties);
  22827. if (pfbHeaderPresent) {
  22828. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  22829. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  22830. (pfbHeader[3] << 8) | pfbHeader[2];
  22831. }
  22832. // Decrypt the data blocks and retrieve it's content
  22833. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  22834. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  22835. var data = eexecBlockParser.extractFontProgram();
  22836. for (var info in data.properties) {
  22837. properties[info] = data.properties[info];
  22838. }
  22839. var charstrings = data.charstrings;
  22840. var type2Charstrings = this.getType2Charstrings(charstrings);
  22841. var subrs = this.getType2Subrs(data.subrs);
  22842. this.charstrings = charstrings;
  22843. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  22844. subrs, properties);
  22845. this.seacs = this.getSeacs(data.charstrings);
  22846. };
  22847. Type1Font.prototype = {
  22848. get numGlyphs() {
  22849. return this.charstrings.length + 1;
  22850. },
  22851. getCharset: function Type1Font_getCharset() {
  22852. var charset = ['.notdef'];
  22853. var charstrings = this.charstrings;
  22854. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  22855. charset.push(charstrings[glyphId].glyphName);
  22856. }
  22857. return charset;
  22858. },
  22859. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  22860. var charstrings = this.charstrings;
  22861. var glyphNames = ['.notdef'], glyphId;
  22862. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  22863. glyphNames.push(charstrings[glyphId].glyphName);
  22864. }
  22865. var encoding = properties.builtInEncoding;
  22866. if (encoding) {
  22867. var builtInEncoding = {};
  22868. for (var charCode in encoding) {
  22869. glyphId = glyphNames.indexOf(encoding[charCode]);
  22870. if (glyphId >= 0) {
  22871. builtInEncoding[charCode] = glyphId;
  22872. }
  22873. }
  22874. }
  22875. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  22876. },
  22877. getSeacs: function Type1Font_getSeacs(charstrings) {
  22878. var i, ii;
  22879. var seacMap = [];
  22880. for (i = 0, ii = charstrings.length; i < ii; i++) {
  22881. var charstring = charstrings[i];
  22882. if (charstring.seac) {
  22883. // Offset by 1 for .notdef
  22884. seacMap[i + 1] = charstring.seac;
  22885. }
  22886. }
  22887. return seacMap;
  22888. },
  22889. getType2Charstrings: function Type1Font_getType2Charstrings(
  22890. type1Charstrings) {
  22891. var type2Charstrings = [];
  22892. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  22893. type2Charstrings.push(type1Charstrings[i].charstring);
  22894. }
  22895. return type2Charstrings;
  22896. },
  22897. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  22898. var bias = 0;
  22899. var count = type1Subrs.length;
  22900. if (count < 1133) {
  22901. bias = 107;
  22902. } else if (count < 33769) {
  22903. bias = 1131;
  22904. } else {
  22905. bias = 32768;
  22906. }
  22907. // Add a bunch of empty subrs to deal with the Type2 bias
  22908. var type2Subrs = [];
  22909. var i;
  22910. for (i = 0; i < bias; i++) {
  22911. type2Subrs.push([0x0B]);
  22912. }
  22913. for (i = 0; i < count; i++) {
  22914. type2Subrs.push(type1Subrs[i]);
  22915. }
  22916. return type2Subrs;
  22917. },
  22918. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  22919. var cff = new CFF();
  22920. cff.header = new CFFHeader(1, 0, 4, 4);
  22921. cff.names = [name];
  22922. var topDict = new CFFTopDict();
  22923. // CFF strings IDs 0...390 are predefined names, so refering
  22924. // to entries in our own String INDEX starts at SID 391.
  22925. topDict.setByName('version', 391);
  22926. topDict.setByName('Notice', 392);
  22927. topDict.setByName('FullName', 393);
  22928. topDict.setByName('FamilyName', 394);
  22929. topDict.setByName('Weight', 395);
  22930. topDict.setByName('Encoding', null); // placeholder
  22931. topDict.setByName('FontMatrix', properties.fontMatrix);
  22932. topDict.setByName('FontBBox', properties.bbox);
  22933. topDict.setByName('charset', null); // placeholder
  22934. topDict.setByName('CharStrings', null); // placeholder
  22935. topDict.setByName('Private', null); // placeholder
  22936. cff.topDict = topDict;
  22937. var strings = new CFFStrings();
  22938. strings.add('Version 0.11'); // Version
  22939. strings.add('See original notice'); // Notice
  22940. strings.add(name); // FullName
  22941. strings.add(name); // FamilyName
  22942. strings.add('Medium'); // Weight
  22943. cff.strings = strings;
  22944. cff.globalSubrIndex = new CFFIndex();
  22945. var count = glyphs.length;
  22946. var charsetArray = [0];
  22947. var i, ii;
  22948. for (i = 0; i < count; i++) {
  22949. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  22950. // TODO: Insert the string and correctly map it. Previously it was
  22951. // thought mapping names that aren't in the standard strings to .notdef
  22952. // was fine, however in issue818 when mapping them all to .notdef the
  22953. // adieresis glyph no longer worked.
  22954. if (index === -1) {
  22955. index = 0;
  22956. }
  22957. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  22958. }
  22959. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  22960. var charStringsIndex = new CFFIndex();
  22961. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  22962. for (i = 0; i < count; i++) {
  22963. charStringsIndex.add(glyphs[i]);
  22964. }
  22965. cff.charStrings = charStringsIndex;
  22966. var privateDict = new CFFPrivateDict();
  22967. privateDict.setByName('Subrs', null); // placeholder
  22968. var fields = [
  22969. 'BlueValues',
  22970. 'OtherBlues',
  22971. 'FamilyBlues',
  22972. 'FamilyOtherBlues',
  22973. 'StemSnapH',
  22974. 'StemSnapV',
  22975. 'BlueShift',
  22976. 'BlueFuzz',
  22977. 'BlueScale',
  22978. 'LanguageGroup',
  22979. 'ExpansionFactor',
  22980. 'ForceBold',
  22981. 'StdHW',
  22982. 'StdVW'
  22983. ];
  22984. for (i = 0, ii = fields.length; i < ii; i++) {
  22985. var field = fields[i];
  22986. if (!properties.privateData.hasOwnProperty(field)) {
  22987. continue;
  22988. }
  22989. var value = properties.privateData[field];
  22990. if (isArray(value)) {
  22991. // All of the private dictionary array data in CFF must be stored as
  22992. // "delta-encoded" numbers.
  22993. for (var j = value.length - 1; j > 0; j--) {
  22994. value[j] -= value[j - 1]; // ... difference from previous value
  22995. }
  22996. }
  22997. privateDict.setByName(field, value);
  22998. }
  22999. cff.topDict.privateDict = privateDict;
  23000. var subrIndex = new CFFIndex();
  23001. for (i = 0, ii = subrs.length; i < ii; i++) {
  23002. subrIndex.add(subrs[i]);
  23003. }
  23004. privateDict.subrsIndex = subrIndex;
  23005. var compiler = new CFFCompiler(cff);
  23006. return compiler.compile();
  23007. }
  23008. };
  23009. var CFFFont = (function CFFFontClosure() {
  23010. function CFFFont(file, properties) {
  23011. this.properties = properties;
  23012. var parser = new CFFParser(file, properties);
  23013. this.cff = parser.parse();
  23014. var compiler = new CFFCompiler(this.cff);
  23015. this.seacs = this.cff.seacs;
  23016. try {
  23017. this.data = compiler.compile();
  23018. } catch (e) {
  23019. warn('Failed to compile font ' + properties.loadedName);
  23020. // There may have just been an issue with the compiler, set the data
  23021. // anyway and hope the font loaded.
  23022. this.data = file;
  23023. }
  23024. }
  23025. CFFFont.prototype = {
  23026. get numGlyphs() {
  23027. return this.cff.charStrings.count;
  23028. },
  23029. getCharset: function CFFFont_getCharset() {
  23030. return this.cff.charset.charset;
  23031. },
  23032. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23033. var cff = this.cff;
  23034. var properties = this.properties;
  23035. var charsets = cff.charset.charset;
  23036. var charCodeToGlyphId;
  23037. var glyphId;
  23038. if (properties.composite) {
  23039. charCodeToGlyphId = Object.create(null);
  23040. if (cff.isCIDFont) {
  23041. // If the font is actually a CID font then we should use the charset
  23042. // to map CIDs to GIDs.
  23043. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23044. var cid = charsets[glyphId];
  23045. var charCode = properties.cMap.charCodeOf(cid);
  23046. charCodeToGlyphId[charCode] = glyphId;
  23047. }
  23048. } else {
  23049. // If it is NOT actually a CID font then CIDs should be mapped
  23050. // directly to GIDs.
  23051. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  23052. charCodeToGlyphId[glyphId] = glyphId;
  23053. }
  23054. }
  23055. return charCodeToGlyphId;
  23056. }
  23057. var encoding = cff.encoding ? cff.encoding.encoding : null;
  23058. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  23059. return charCodeToGlyphId;
  23060. }
  23061. };
  23062. return CFFFont;
  23063. })();
  23064. var CFFParser = (function CFFParserClosure() {
  23065. var CharstringValidationData = [
  23066. null,
  23067. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  23068. null,
  23069. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  23070. { id: 'vmoveto', min: 1, stackClearing: true },
  23071. { id: 'rlineto', min: 2, resetStack: true },
  23072. { id: 'hlineto', min: 1, resetStack: true },
  23073. { id: 'vlineto', min: 1, resetStack: true },
  23074. { id: 'rrcurveto', min: 6, resetStack: true },
  23075. null,
  23076. { id: 'callsubr', min: 1, undefStack: true },
  23077. { id: 'return', min: 0, undefStack: true },
  23078. null, // 12
  23079. null,
  23080. { id: 'endchar', min: 0, stackClearing: true },
  23081. null,
  23082. null,
  23083. null,
  23084. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  23085. { id: 'hintmask', min: 0, stackClearing: true },
  23086. { id: 'cntrmask', min: 0, stackClearing: true },
  23087. { id: 'rmoveto', min: 2, stackClearing: true },
  23088. { id: 'hmoveto', min: 1, stackClearing: true },
  23089. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  23090. { id: 'rcurveline', min: 8, resetStack: true },
  23091. { id: 'rlinecurve', min: 8, resetStack: true },
  23092. { id: 'vvcurveto', min: 4, resetStack: true },
  23093. { id: 'hhcurveto', min: 4, resetStack: true },
  23094. null, // shortint
  23095. { id: 'callgsubr', min: 1, undefStack: true },
  23096. { id: 'vhcurveto', min: 4, resetStack: true },
  23097. { id: 'hvcurveto', min: 4, resetStack: true }
  23098. ];
  23099. var CharstringValidationData12 = [
  23100. null,
  23101. null,
  23102. null,
  23103. { id: 'and', min: 2, stackDelta: -1 },
  23104. { id: 'or', min: 2, stackDelta: -1 },
  23105. { id: 'not', min: 1, stackDelta: 0 },
  23106. null,
  23107. null,
  23108. null,
  23109. { id: 'abs', min: 1, stackDelta: 0 },
  23110. { id: 'add', min: 2, stackDelta: -1,
  23111. stackFn: function stack_div(stack, index) {
  23112. stack[index - 2] = stack[index - 2] + stack[index - 1];
  23113. }
  23114. },
  23115. { id: 'sub', min: 2, stackDelta: -1,
  23116. stackFn: function stack_div(stack, index) {
  23117. stack[index - 2] = stack[index - 2] - stack[index - 1];
  23118. }
  23119. },
  23120. { id: 'div', min: 2, stackDelta: -1,
  23121. stackFn: function stack_div(stack, index) {
  23122. stack[index - 2] = stack[index - 2] / stack[index - 1];
  23123. }
  23124. },
  23125. null,
  23126. { id: 'neg', min: 1, stackDelta: 0,
  23127. stackFn: function stack_div(stack, index) {
  23128. stack[index - 1] = -stack[index - 1];
  23129. }
  23130. },
  23131. { id: 'eq', min: 2, stackDelta: -1 },
  23132. null,
  23133. null,
  23134. { id: 'drop', min: 1, stackDelta: -1 },
  23135. null,
  23136. { id: 'put', min: 2, stackDelta: -2 },
  23137. { id: 'get', min: 1, stackDelta: 0 },
  23138. { id: 'ifelse', min: 4, stackDelta: -3 },
  23139. { id: 'random', min: 0, stackDelta: 1 },
  23140. { id: 'mul', min: 2, stackDelta: -1,
  23141. stackFn: function stack_div(stack, index) {
  23142. stack[index - 2] = stack[index - 2] * stack[index - 1];
  23143. }
  23144. },
  23145. null,
  23146. { id: 'sqrt', min: 1, stackDelta: 0 },
  23147. { id: 'dup', min: 1, stackDelta: 1 },
  23148. { id: 'exch', min: 2, stackDelta: 0 },
  23149. { id: 'index', min: 2, stackDelta: 0 },
  23150. { id: 'roll', min: 3, stackDelta: -2 },
  23151. null,
  23152. null,
  23153. null,
  23154. { id: 'hflex', min: 7, resetStack: true },
  23155. { id: 'flex', min: 13, resetStack: true },
  23156. { id: 'hflex1', min: 9, resetStack: true },
  23157. { id: 'flex1', min: 11, resetStack: true }
  23158. ];
  23159. function CFFParser(file, properties) {
  23160. this.bytes = file.getBytes();
  23161. this.properties = properties;
  23162. }
  23163. CFFParser.prototype = {
  23164. parse: function CFFParser_parse() {
  23165. var properties = this.properties;
  23166. var cff = new CFF();
  23167. this.cff = cff;
  23168. // The first five sections must be in order, all the others are reached
  23169. // via offsets contained in one of the below.
  23170. var header = this.parseHeader();
  23171. var nameIndex = this.parseIndex(header.endPos);
  23172. var topDictIndex = this.parseIndex(nameIndex.endPos);
  23173. var stringIndex = this.parseIndex(topDictIndex.endPos);
  23174. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  23175. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  23176. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  23177. cff.header = header.obj;
  23178. cff.names = this.parseNameIndex(nameIndex.obj);
  23179. cff.strings = this.parseStringIndex(stringIndex.obj);
  23180. cff.topDict = topDict;
  23181. cff.globalSubrIndex = globalSubrIndex.obj;
  23182. this.parsePrivateDict(cff.topDict);
  23183. cff.isCIDFont = topDict.hasName('ROS');
  23184. var charStringOffset = topDict.getByName('CharStrings');
  23185. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  23186. cff.charStrings = charStringsAndSeacs.charStrings;
  23187. cff.seacs = charStringsAndSeacs.seacs;
  23188. cff.widths = charStringsAndSeacs.widths;
  23189. var fontMatrix = topDict.getByName('FontMatrix');
  23190. if (fontMatrix) {
  23191. properties.fontMatrix = fontMatrix;
  23192. }
  23193. var fontBBox = topDict.getByName('FontBBox');
  23194. if (fontBBox) {
  23195. // adjusting ascent/descent
  23196. properties.ascent = fontBBox[3];
  23197. properties.descent = fontBBox[1];
  23198. properties.ascentScaled = true;
  23199. }
  23200. var charset, encoding;
  23201. if (cff.isCIDFont) {
  23202. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  23203. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  23204. var dictRaw = fdArrayIndex.get(i);
  23205. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  23206. cff.strings);
  23207. this.parsePrivateDict(fontDict);
  23208. cff.fdArray.push(fontDict);
  23209. }
  23210. // cid fonts don't have an encoding
  23211. encoding = null;
  23212. charset = this.parseCharsets(topDict.getByName('charset'),
  23213. cff.charStrings.count, cff.strings, true);
  23214. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  23215. cff.charStrings.count);
  23216. } else {
  23217. charset = this.parseCharsets(topDict.getByName('charset'),
  23218. cff.charStrings.count, cff.strings, false);
  23219. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  23220. properties,
  23221. cff.strings, charset.charset);
  23222. }
  23223. cff.charset = charset;
  23224. cff.encoding = encoding;
  23225. return cff;
  23226. },
  23227. parseHeader: function CFFParser_parseHeader() {
  23228. var bytes = this.bytes;
  23229. var bytesLength = bytes.length;
  23230. var offset = 0;
  23231. // Prevent an infinite loop, by checking that the offset is within the
  23232. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  23233. while (offset < bytesLength && bytes[offset] !== 1) {
  23234. ++offset;
  23235. }
  23236. if (offset >= bytesLength) {
  23237. error('Invalid CFF header');
  23238. } else if (offset !== 0) {
  23239. info('cff data is shifted');
  23240. bytes = bytes.subarray(offset);
  23241. this.bytes = bytes;
  23242. }
  23243. var major = bytes[0];
  23244. var minor = bytes[1];
  23245. var hdrSize = bytes[2];
  23246. var offSize = bytes[3];
  23247. var header = new CFFHeader(major, minor, hdrSize, offSize);
  23248. return { obj: header, endPos: hdrSize };
  23249. },
  23250. parseDict: function CFFParser_parseDict(dict) {
  23251. var pos = 0;
  23252. function parseOperand() {
  23253. var value = dict[pos++];
  23254. if (value === 30) {
  23255. return parseFloatOperand(pos);
  23256. } else if (value === 28) {
  23257. value = dict[pos++];
  23258. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  23259. return value;
  23260. } else if (value === 29) {
  23261. value = dict[pos++];
  23262. value = (value << 8) | dict[pos++];
  23263. value = (value << 8) | dict[pos++];
  23264. value = (value << 8) | dict[pos++];
  23265. return value;
  23266. } else if (value >= 32 && value <= 246) {
  23267. return value - 139;
  23268. } else if (value >= 247 && value <= 250) {
  23269. return ((value - 247) * 256) + dict[pos++] + 108;
  23270. } else if (value >= 251 && value <= 254) {
  23271. return -((value - 251) * 256) - dict[pos++] - 108;
  23272. } else {
  23273. error('255 is not a valid DICT command');
  23274. }
  23275. return -1;
  23276. }
  23277. function parseFloatOperand() {
  23278. var str = '';
  23279. var eof = 15;
  23280. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  23281. '9', '.', 'E', 'E-', null, '-'];
  23282. var length = dict.length;
  23283. while (pos < length) {
  23284. var b = dict[pos++];
  23285. var b1 = b >> 4;
  23286. var b2 = b & 15;
  23287. if (b1 === eof) {
  23288. break;
  23289. }
  23290. str += lookup[b1];
  23291. if (b2 === eof) {
  23292. break;
  23293. }
  23294. str += lookup[b2];
  23295. }
  23296. return parseFloat(str);
  23297. }
  23298. var operands = [];
  23299. var entries = [];
  23300. pos = 0;
  23301. var end = dict.length;
  23302. while (pos < end) {
  23303. var b = dict[pos];
  23304. if (b <= 21) {
  23305. if (b === 12) {
  23306. b = (b << 8) | dict[++pos];
  23307. }
  23308. entries.push([b, operands]);
  23309. operands = [];
  23310. ++pos;
  23311. } else {
  23312. operands.push(parseOperand());
  23313. }
  23314. }
  23315. return entries;
  23316. },
  23317. parseIndex: function CFFParser_parseIndex(pos) {
  23318. var cffIndex = new CFFIndex();
  23319. var bytes = this.bytes;
  23320. var count = (bytes[pos++] << 8) | bytes[pos++];
  23321. var offsets = [];
  23322. var end = pos;
  23323. var i, ii;
  23324. if (count !== 0) {
  23325. var offsetSize = bytes[pos++];
  23326. // add 1 for offset to determine size of last object
  23327. var startPos = pos + ((count + 1) * offsetSize) - 1;
  23328. for (i = 0, ii = count + 1; i < ii; ++i) {
  23329. var offset = 0;
  23330. for (var j = 0; j < offsetSize; ++j) {
  23331. offset <<= 8;
  23332. offset += bytes[pos++];
  23333. }
  23334. offsets.push(startPos + offset);
  23335. }
  23336. end = offsets[count];
  23337. }
  23338. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  23339. var offsetStart = offsets[i];
  23340. var offsetEnd = offsets[i + 1];
  23341. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  23342. }
  23343. return {obj: cffIndex, endPos: end};
  23344. },
  23345. parseNameIndex: function CFFParser_parseNameIndex(index) {
  23346. var names = [];
  23347. for (var i = 0, ii = index.count; i < ii; ++i) {
  23348. var name = index.get(i);
  23349. // OTS doesn't allow names to be over 127 characters.
  23350. var length = Math.min(name.length, 127);
  23351. var data = [];
  23352. // OTS also only permits certain characters in the name.
  23353. for (var j = 0; j < length; ++j) {
  23354. var c = name[j];
  23355. if (j === 0 && c === 0) {
  23356. data[j] = c;
  23357. continue;
  23358. }
  23359. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  23360. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  23361. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  23362. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  23363. data[j] = 95;
  23364. continue;
  23365. }
  23366. data[j] = c;
  23367. }
  23368. names.push(bytesToString(data));
  23369. }
  23370. return names;
  23371. },
  23372. parseStringIndex: function CFFParser_parseStringIndex(index) {
  23373. var strings = new CFFStrings();
  23374. for (var i = 0, ii = index.count; i < ii; ++i) {
  23375. var data = index.get(i);
  23376. strings.add(bytesToString(data));
  23377. }
  23378. return strings;
  23379. },
  23380. createDict: function CFFParser_createDict(Type, dict, strings) {
  23381. var cffDict = new Type(strings);
  23382. for (var i = 0, ii = dict.length; i < ii; ++i) {
  23383. var pair = dict[i];
  23384. var key = pair[0];
  23385. var value = pair[1];
  23386. cffDict.setByKey(key, value);
  23387. }
  23388. return cffDict;
  23389. },
  23390. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  23391. var charStrings = this.parseIndex(charStringOffset).obj;
  23392. var seacs = [];
  23393. var widths = [];
  23394. var count = charStrings.count;
  23395. for (var i = 0; i < count; i++) {
  23396. var charstring = charStrings.get(i);
  23397. var stackSize = 0;
  23398. var stack = [];
  23399. var undefStack = true;
  23400. var hints = 0;
  23401. var valid = true;
  23402. var data = charstring;
  23403. var length = data.length;
  23404. var firstStackClearing = true;
  23405. for (var j = 0; j < length;) {
  23406. var value = data[j++];
  23407. var validationCommand = null;
  23408. if (value === 12) {
  23409. var q = data[j++];
  23410. if (q === 0) {
  23411. // The CFF specification state that the 'dotsection' command
  23412. // (12, 0) is deprecated and treated as a no-op, but all Type2
  23413. // charstrings processors should support them. Unfortunately
  23414. // the font sanitizer don't. As a workaround the sequence (12, 0)
  23415. // is replaced by a useless (0, hmoveto).
  23416. data[j - 2] = 139;
  23417. data[j - 1] = 22;
  23418. stackSize = 0;
  23419. } else {
  23420. validationCommand = CharstringValidationData12[q];
  23421. }
  23422. } else if (value === 28) { // number (16 bit)
  23423. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  23424. j += 2;
  23425. stackSize++;
  23426. } else if (value === 14) {
  23427. if (stackSize >= 4) {
  23428. stackSize -= 4;
  23429. if (SEAC_ANALYSIS_ENABLED) {
  23430. seacs[i] = stack.slice(stackSize, stackSize + 4);
  23431. valid = false;
  23432. }
  23433. }
  23434. validationCommand = CharstringValidationData[value];
  23435. } else if (value >= 32 && value <= 246) { // number
  23436. stack[stackSize] = value - 139;
  23437. stackSize++;
  23438. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  23439. stack[stackSize] = (value < 251 ?
  23440. ((value - 247) << 8) + data[j] + 108 :
  23441. -((value - 251) << 8) - data[j] - 108);
  23442. j++;
  23443. stackSize++;
  23444. } else if (value === 255) { // number (32 bit)
  23445. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  23446. (data[j + 2] << 8) | data[j + 3]) / 65536;
  23447. j += 4;
  23448. stackSize++;
  23449. } else if (value === 19 || value === 20) {
  23450. hints += stackSize >> 1;
  23451. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  23452. stackSize %= 2;
  23453. validationCommand = CharstringValidationData[value];
  23454. } else {
  23455. validationCommand = CharstringValidationData[value];
  23456. }
  23457. if (validationCommand) {
  23458. if (validationCommand.stem) {
  23459. hints += stackSize >> 1;
  23460. }
  23461. if ('min' in validationCommand) {
  23462. if (!undefStack && stackSize < validationCommand.min) {
  23463. warn('Not enough parameters for ' + validationCommand.id +
  23464. '; actual: ' + stackSize +
  23465. ', expected: ' + validationCommand.min);
  23466. valid = false;
  23467. break;
  23468. }
  23469. }
  23470. if (firstStackClearing && validationCommand.stackClearing) {
  23471. firstStackClearing = false;
  23472. // the optional character width can be found before the first
  23473. // stack-clearing command arguments
  23474. stackSize -= validationCommand.min;
  23475. if (stackSize >= 2 && validationCommand.stem) {
  23476. // there are even amount of arguments for stem commands
  23477. stackSize %= 2;
  23478. } else if (stackSize > 1) {
  23479. warn('Found too many parameters for stack-clearing command');
  23480. }
  23481. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  23482. widths[i] = stack[stackSize - 1];
  23483. }
  23484. }
  23485. if ('stackDelta' in validationCommand) {
  23486. if ('stackFn' in validationCommand) {
  23487. validationCommand.stackFn(stack, stackSize);
  23488. }
  23489. stackSize += validationCommand.stackDelta;
  23490. } else if (validationCommand.stackClearing) {
  23491. stackSize = 0;
  23492. } else if (validationCommand.resetStack) {
  23493. stackSize = 0;
  23494. undefStack = false;
  23495. } else if (validationCommand.undefStack) {
  23496. stackSize = 0;
  23497. undefStack = true;
  23498. firstStackClearing = false;
  23499. }
  23500. }
  23501. }
  23502. if (!valid) {
  23503. // resetting invalid charstring to single 'endchar'
  23504. charStrings.set(i, new Uint8Array([14]));
  23505. }
  23506. }
  23507. return { charStrings: charStrings, seacs: seacs, widths: widths };
  23508. },
  23509. emptyPrivateDictionary:
  23510. function CFFParser_emptyPrivateDictionary(parentDict) {
  23511. var privateDict = this.createDict(CFFPrivateDict, [],
  23512. parentDict.strings);
  23513. parentDict.setByKey(18, [0, 0]);
  23514. parentDict.privateDict = privateDict;
  23515. },
  23516. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  23517. // no private dict, do nothing
  23518. if (!parentDict.hasName('Private')) {
  23519. this.emptyPrivateDictionary(parentDict);
  23520. return;
  23521. }
  23522. var privateOffset = parentDict.getByName('Private');
  23523. // make sure the params are formatted correctly
  23524. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  23525. parentDict.removeByName('Private');
  23526. return;
  23527. }
  23528. var size = privateOffset[0];
  23529. var offset = privateOffset[1];
  23530. // remove empty dicts or ones that refer to invalid location
  23531. if (size === 0 || offset >= this.bytes.length) {
  23532. this.emptyPrivateDictionary(parentDict);
  23533. return;
  23534. }
  23535. var privateDictEnd = offset + size;
  23536. var dictData = this.bytes.subarray(offset, privateDictEnd);
  23537. var dict = this.parseDict(dictData);
  23538. var privateDict = this.createDict(CFFPrivateDict, dict,
  23539. parentDict.strings);
  23540. parentDict.privateDict = privateDict;
  23541. // Parse the Subrs index also since it's relative to the private dict.
  23542. if (!privateDict.getByName('Subrs')) {
  23543. return;
  23544. }
  23545. var subrsOffset = privateDict.getByName('Subrs');
  23546. var relativeOffset = offset + subrsOffset;
  23547. // Validate the offset.
  23548. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  23549. this.emptyPrivateDictionary(parentDict);
  23550. return;
  23551. }
  23552. var subrsIndex = this.parseIndex(relativeOffset);
  23553. privateDict.subrsIndex = subrsIndex.obj;
  23554. },
  23555. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  23556. if (pos === 0) {
  23557. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  23558. ISOAdobeCharset);
  23559. } else if (pos === 1) {
  23560. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  23561. ExpertCharset);
  23562. } else if (pos === 2) {
  23563. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  23564. ExpertSubsetCharset);
  23565. }
  23566. var bytes = this.bytes;
  23567. var start = pos;
  23568. var format = bytes[pos++];
  23569. var charset = ['.notdef'];
  23570. var id, count, i;
  23571. // subtract 1 for the .notdef glyph
  23572. length -= 1;
  23573. switch (format) {
  23574. case 0:
  23575. for (i = 0; i < length; i++) {
  23576. id = (bytes[pos++] << 8) | bytes[pos++];
  23577. charset.push(cid ? id : strings.get(id));
  23578. }
  23579. break;
  23580. case 1:
  23581. while (charset.length <= length) {
  23582. id = (bytes[pos++] << 8) | bytes[pos++];
  23583. count = bytes[pos++];
  23584. for (i = 0; i <= count; i++) {
  23585. charset.push(cid ? id++ : strings.get(id++));
  23586. }
  23587. }
  23588. break;
  23589. case 2:
  23590. while (charset.length <= length) {
  23591. id = (bytes[pos++] << 8) | bytes[pos++];
  23592. count = (bytes[pos++] << 8) | bytes[pos++];
  23593. for (i = 0; i <= count; i++) {
  23594. charset.push(cid ? id++ : strings.get(id++));
  23595. }
  23596. }
  23597. break;
  23598. default:
  23599. error('Unknown charset format');
  23600. }
  23601. // Raw won't be needed if we actually compile the charset.
  23602. var end = pos;
  23603. var raw = bytes.subarray(start, end);
  23604. return new CFFCharset(false, format, charset, raw);
  23605. },
  23606. parseEncoding: function CFFParser_parseEncoding(pos,
  23607. properties,
  23608. strings,
  23609. charset) {
  23610. var encoding = {};
  23611. var bytes = this.bytes;
  23612. var predefined = false;
  23613. var hasSupplement = false;
  23614. var format, i, ii;
  23615. var raw = null;
  23616. function readSupplement() {
  23617. var supplementsCount = bytes[pos++];
  23618. for (i = 0; i < supplementsCount; i++) {
  23619. var code = bytes[pos++];
  23620. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  23621. encoding[code] = charset.indexOf(strings.get(sid));
  23622. }
  23623. }
  23624. if (pos === 0 || pos === 1) {
  23625. predefined = true;
  23626. format = pos;
  23627. var baseEncoding = pos ? Encodings.ExpertEncoding :
  23628. Encodings.StandardEncoding;
  23629. for (i = 0, ii = charset.length; i < ii; i++) {
  23630. var index = baseEncoding.indexOf(charset[i]);
  23631. if (index !== -1) {
  23632. encoding[index] = i;
  23633. }
  23634. }
  23635. } else {
  23636. var dataStart = pos;
  23637. format = bytes[pos++];
  23638. switch (format & 0x7f) {
  23639. case 0:
  23640. var glyphsCount = bytes[pos++];
  23641. for (i = 1; i <= glyphsCount; i++) {
  23642. encoding[bytes[pos++]] = i;
  23643. }
  23644. break;
  23645. case 1:
  23646. var rangesCount = bytes[pos++];
  23647. var gid = 1;
  23648. for (i = 0; i < rangesCount; i++) {
  23649. var start = bytes[pos++];
  23650. var left = bytes[pos++];
  23651. for (var j = start; j <= start + left; j++) {
  23652. encoding[j] = gid++;
  23653. }
  23654. }
  23655. break;
  23656. default:
  23657. error('Unknow encoding format: ' + format + ' in CFF');
  23658. break;
  23659. }
  23660. var dataEnd = pos;
  23661. if (format & 0x80) {
  23662. // The font sanitizer does not support CFF encoding with a
  23663. // supplement, since the encoding is not really used to map
  23664. // between gid to glyph, let's overwrite what is declared in
  23665. // the top dictionary to let the sanitizer think the font use
  23666. // StandardEncoding, that's a lie but that's ok.
  23667. bytes[dataStart] &= 0x7f;
  23668. readSupplement();
  23669. hasSupplement = true;
  23670. }
  23671. raw = bytes.subarray(dataStart, dataEnd);
  23672. }
  23673. format = format & 0x7f;
  23674. return new CFFEncoding(predefined, format, encoding, raw);
  23675. },
  23676. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  23677. var start = pos;
  23678. var bytes = this.bytes;
  23679. var format = bytes[pos++];
  23680. var fdSelect = [];
  23681. var i;
  23682. switch (format) {
  23683. case 0:
  23684. for (i = 0; i < length; ++i) {
  23685. var id = bytes[pos++];
  23686. fdSelect.push(id);
  23687. }
  23688. break;
  23689. case 3:
  23690. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  23691. for (i = 0; i < rangesCount; ++i) {
  23692. var first = (bytes[pos++] << 8) | bytes[pos++];
  23693. var fdIndex = bytes[pos++];
  23694. var next = (bytes[pos] << 8) | bytes[pos + 1];
  23695. for (var j = first; j < next; ++j) {
  23696. fdSelect.push(fdIndex);
  23697. }
  23698. }
  23699. // Advance past the sentinel(next).
  23700. pos += 2;
  23701. break;
  23702. default:
  23703. error('Unknown fdselect format ' + format);
  23704. break;
  23705. }
  23706. var end = pos;
  23707. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  23708. }
  23709. };
  23710. return CFFParser;
  23711. })();
  23712. // Compact Font Format
  23713. var CFF = (function CFFClosure() {
  23714. function CFF() {
  23715. this.header = null;
  23716. this.names = [];
  23717. this.topDict = null;
  23718. this.strings = new CFFStrings();
  23719. this.globalSubrIndex = null;
  23720. // The following could really be per font, but since we only have one font
  23721. // store them here.
  23722. this.encoding = null;
  23723. this.charset = null;
  23724. this.charStrings = null;
  23725. this.fdArray = [];
  23726. this.fdSelect = null;
  23727. this.isCIDFont = false;
  23728. }
  23729. return CFF;
  23730. })();
  23731. var CFFHeader = (function CFFHeaderClosure() {
  23732. function CFFHeader(major, minor, hdrSize, offSize) {
  23733. this.major = major;
  23734. this.minor = minor;
  23735. this.hdrSize = hdrSize;
  23736. this.offSize = offSize;
  23737. }
  23738. return CFFHeader;
  23739. })();
  23740. var CFFStrings = (function CFFStringsClosure() {
  23741. function CFFStrings() {
  23742. this.strings = [];
  23743. }
  23744. CFFStrings.prototype = {
  23745. get: function CFFStrings_get(index) {
  23746. if (index >= 0 && index <= 390) {
  23747. return CFFStandardStrings[index];
  23748. }
  23749. if (index - 391 <= this.strings.length) {
  23750. return this.strings[index - 391];
  23751. }
  23752. return CFFStandardStrings[0];
  23753. },
  23754. add: function CFFStrings_add(value) {
  23755. this.strings.push(value);
  23756. },
  23757. get count() {
  23758. return this.strings.length;
  23759. }
  23760. };
  23761. return CFFStrings;
  23762. })();
  23763. var CFFIndex = (function CFFIndexClosure() {
  23764. function CFFIndex() {
  23765. this.objects = [];
  23766. this.length = 0;
  23767. }
  23768. CFFIndex.prototype = {
  23769. add: function CFFIndex_add(data) {
  23770. this.length += data.length;
  23771. this.objects.push(data);
  23772. },
  23773. set: function CFFIndex_set(index, data) {
  23774. this.length += data.length - this.objects[index].length;
  23775. this.objects[index] = data;
  23776. },
  23777. get: function CFFIndex_get(index) {
  23778. return this.objects[index];
  23779. },
  23780. get count() {
  23781. return this.objects.length;
  23782. }
  23783. };
  23784. return CFFIndex;
  23785. })();
  23786. var CFFDict = (function CFFDictClosure() {
  23787. function CFFDict(tables, strings) {
  23788. this.keyToNameMap = tables.keyToNameMap;
  23789. this.nameToKeyMap = tables.nameToKeyMap;
  23790. this.defaults = tables.defaults;
  23791. this.types = tables.types;
  23792. this.opcodes = tables.opcodes;
  23793. this.order = tables.order;
  23794. this.strings = strings;
  23795. this.values = {};
  23796. }
  23797. CFFDict.prototype = {
  23798. // value should always be an array
  23799. setByKey: function CFFDict_setByKey(key, value) {
  23800. if (!(key in this.keyToNameMap)) {
  23801. return false;
  23802. }
  23803. // ignore empty values
  23804. if (value.length === 0) {
  23805. return true;
  23806. }
  23807. var type = this.types[key];
  23808. // remove the array wrapping these types of values
  23809. if (type === 'num' || type === 'sid' || type === 'offset') {
  23810. value = value[0];
  23811. }
  23812. this.values[key] = value;
  23813. return true;
  23814. },
  23815. setByName: function CFFDict_setByName(name, value) {
  23816. if (!(name in this.nameToKeyMap)) {
  23817. error('Invalid dictionary name "' + name + '"');
  23818. }
  23819. this.values[this.nameToKeyMap[name]] = value;
  23820. },
  23821. hasName: function CFFDict_hasName(name) {
  23822. return this.nameToKeyMap[name] in this.values;
  23823. },
  23824. getByName: function CFFDict_getByName(name) {
  23825. if (!(name in this.nameToKeyMap)) {
  23826. error('Invalid dictionary name "' + name + '"');
  23827. }
  23828. var key = this.nameToKeyMap[name];
  23829. if (!(key in this.values)) {
  23830. return this.defaults[key];
  23831. }
  23832. return this.values[key];
  23833. },
  23834. removeByName: function CFFDict_removeByName(name) {
  23835. delete this.values[this.nameToKeyMap[name]];
  23836. }
  23837. };
  23838. CFFDict.createTables = function CFFDict_createTables(layout) {
  23839. var tables = {
  23840. keyToNameMap: {},
  23841. nameToKeyMap: {},
  23842. defaults: {},
  23843. types: {},
  23844. opcodes: {},
  23845. order: []
  23846. };
  23847. for (var i = 0, ii = layout.length; i < ii; ++i) {
  23848. var entry = layout[i];
  23849. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  23850. tables.keyToNameMap[key] = entry[1];
  23851. tables.nameToKeyMap[entry[1]] = key;
  23852. tables.types[key] = entry[2];
  23853. tables.defaults[key] = entry[3];
  23854. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  23855. tables.order.push(key);
  23856. }
  23857. return tables;
  23858. };
  23859. return CFFDict;
  23860. })();
  23861. var CFFTopDict = (function CFFTopDictClosure() {
  23862. var layout = [
  23863. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  23864. [[12, 20], 'SyntheticBase', 'num', null],
  23865. [0, 'version', 'sid', null],
  23866. [1, 'Notice', 'sid', null],
  23867. [[12, 0], 'Copyright', 'sid', null],
  23868. [2, 'FullName', 'sid', null],
  23869. [3, 'FamilyName', 'sid', null],
  23870. [4, 'Weight', 'sid', null],
  23871. [[12, 1], 'isFixedPitch', 'num', 0],
  23872. [[12, 2], 'ItalicAngle', 'num', 0],
  23873. [[12, 3], 'UnderlinePosition', 'num', -100],
  23874. [[12, 4], 'UnderlineThickness', 'num', 50],
  23875. [[12, 5], 'PaintType', 'num', 0],
  23876. [[12, 6], 'CharstringType', 'num', 2],
  23877. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  23878. [0.001, 0, 0, 0.001, 0, 0]],
  23879. [13, 'UniqueID', 'num', null],
  23880. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  23881. [[12, 8], 'StrokeWidth', 'num', 0],
  23882. [14, 'XUID', 'array', null],
  23883. [15, 'charset', 'offset', 0],
  23884. [16, 'Encoding', 'offset', 0],
  23885. [17, 'CharStrings', 'offset', 0],
  23886. [18, 'Private', ['offset', 'offset'], null],
  23887. [[12, 21], 'PostScript', 'sid', null],
  23888. [[12, 22], 'BaseFontName', 'sid', null],
  23889. [[12, 23], 'BaseFontBlend', 'delta', null],
  23890. [[12, 31], 'CIDFontVersion', 'num', 0],
  23891. [[12, 32], 'CIDFontRevision', 'num', 0],
  23892. [[12, 33], 'CIDFontType', 'num', 0],
  23893. [[12, 34], 'CIDCount', 'num', 8720],
  23894. [[12, 35], 'UIDBase', 'num', null],
  23895. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  23896. // before FDArray.
  23897. [[12, 37], 'FDSelect', 'offset', null],
  23898. [[12, 36], 'FDArray', 'offset', null],
  23899. [[12, 38], 'FontName', 'sid', null]
  23900. ];
  23901. var tables = null;
  23902. function CFFTopDict(strings) {
  23903. if (tables === null) {
  23904. tables = CFFDict.createTables(layout);
  23905. }
  23906. CFFDict.call(this, tables, strings);
  23907. this.privateDict = null;
  23908. }
  23909. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  23910. return CFFTopDict;
  23911. })();
  23912. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  23913. var layout = [
  23914. [6, 'BlueValues', 'delta', null],
  23915. [7, 'OtherBlues', 'delta', null],
  23916. [8, 'FamilyBlues', 'delta', null],
  23917. [9, 'FamilyOtherBlues', 'delta', null],
  23918. [[12, 9], 'BlueScale', 'num', 0.039625],
  23919. [[12, 10], 'BlueShift', 'num', 7],
  23920. [[12, 11], 'BlueFuzz', 'num', 1],
  23921. [10, 'StdHW', 'num', null],
  23922. [11, 'StdVW', 'num', null],
  23923. [[12, 12], 'StemSnapH', 'delta', null],
  23924. [[12, 13], 'StemSnapV', 'delta', null],
  23925. [[12, 14], 'ForceBold', 'num', 0],
  23926. [[12, 17], 'LanguageGroup', 'num', 0],
  23927. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  23928. [[12, 19], 'initialRandomSeed', 'num', 0],
  23929. [20, 'defaultWidthX', 'num', 0],
  23930. [21, 'nominalWidthX', 'num', 0],
  23931. [19, 'Subrs', 'offset', null]
  23932. ];
  23933. var tables = null;
  23934. function CFFPrivateDict(strings) {
  23935. if (tables === null) {
  23936. tables = CFFDict.createTables(layout);
  23937. }
  23938. CFFDict.call(this, tables, strings);
  23939. this.subrsIndex = null;
  23940. }
  23941. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  23942. return CFFPrivateDict;
  23943. })();
  23944. var CFFCharsetPredefinedTypes = {
  23945. ISO_ADOBE: 0,
  23946. EXPERT: 1,
  23947. EXPERT_SUBSET: 2
  23948. };
  23949. var CFFCharset = (function CFFCharsetClosure() {
  23950. function CFFCharset(predefined, format, charset, raw) {
  23951. this.predefined = predefined;
  23952. this.format = format;
  23953. this.charset = charset;
  23954. this.raw = raw;
  23955. }
  23956. return CFFCharset;
  23957. })();
  23958. var CFFEncoding = (function CFFEncodingClosure() {
  23959. function CFFEncoding(predefined, format, encoding, raw) {
  23960. this.predefined = predefined;
  23961. this.format = format;
  23962. this.encoding = encoding;
  23963. this.raw = raw;
  23964. }
  23965. return CFFEncoding;
  23966. })();
  23967. var CFFFDSelect = (function CFFFDSelectClosure() {
  23968. function CFFFDSelect(fdSelect, raw) {
  23969. this.fdSelect = fdSelect;
  23970. this.raw = raw;
  23971. }
  23972. return CFFFDSelect;
  23973. })();
  23974. // Helper class to keep track of where an offset is within the data and helps
  23975. // filling in that offset once it's known.
  23976. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  23977. function CFFOffsetTracker() {
  23978. this.offsets = {};
  23979. }
  23980. CFFOffsetTracker.prototype = {
  23981. isTracking: function CFFOffsetTracker_isTracking(key) {
  23982. return key in this.offsets;
  23983. },
  23984. track: function CFFOffsetTracker_track(key, location) {
  23985. if (key in this.offsets) {
  23986. error('Already tracking location of ' + key);
  23987. }
  23988. this.offsets[key] = location;
  23989. },
  23990. offset: function CFFOffsetTracker_offset(value) {
  23991. for (var key in this.offsets) {
  23992. this.offsets[key] += value;
  23993. }
  23994. },
  23995. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  23996. values,
  23997. output) {
  23998. if (!(key in this.offsets)) {
  23999. error('Not tracking location of ' + key);
  24000. }
  24001. var data = output.data;
  24002. var dataOffset = this.offsets[key];
  24003. var size = 5;
  24004. for (var i = 0, ii = values.length; i < ii; ++i) {
  24005. var offset0 = i * size + dataOffset;
  24006. var offset1 = offset0 + 1;
  24007. var offset2 = offset0 + 2;
  24008. var offset3 = offset0 + 3;
  24009. var offset4 = offset0 + 4;
  24010. // It's easy to screw up offsets so perform this sanity check.
  24011. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24012. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24013. error('writing to an offset that is not empty');
  24014. }
  24015. var value = values[i];
  24016. data[offset0] = 0x1d;
  24017. data[offset1] = (value >> 24) & 0xFF;
  24018. data[offset2] = (value >> 16) & 0xFF;
  24019. data[offset3] = (value >> 8) & 0xFF;
  24020. data[offset4] = value & 0xFF;
  24021. }
  24022. }
  24023. };
  24024. return CFFOffsetTracker;
  24025. })();
  24026. // Takes a CFF and converts it to the binary representation.
  24027. var CFFCompiler = (function CFFCompilerClosure() {
  24028. function CFFCompiler(cff) {
  24029. this.cff = cff;
  24030. }
  24031. CFFCompiler.prototype = {
  24032. compile: function CFFCompiler_compile() {
  24033. var cff = this.cff;
  24034. var output = {
  24035. data: [],
  24036. length: 0,
  24037. add: function CFFCompiler_add(data) {
  24038. this.data = this.data.concat(data);
  24039. this.length = this.data.length;
  24040. }
  24041. };
  24042. // Compile the five entries that must be in order.
  24043. var header = this.compileHeader(cff.header);
  24044. output.add(header);
  24045. var nameIndex = this.compileNameIndex(cff.names);
  24046. output.add(nameIndex);
  24047. if (cff.isCIDFont) {
  24048. // The spec is unclear on how font matrices should relate to each other
  24049. // when there is one in the main top dict and the sub top dicts.
  24050. // Windows handles this differently than linux and osx so we have to
  24051. // normalize to work on all.
  24052. // Rules based off of some mailing list discussions:
  24053. // - If main font has a matrix and subfont doesn't, use the main matrix.
  24054. // - If no main font matrix and there is a subfont matrix, use the
  24055. // subfont matrix.
  24056. // - If both have matrices, concat together.
  24057. // - If neither have matrices, use default.
  24058. // To make this work on all platforms we move the top matrix into each
  24059. // sub top dict and concat if necessary.
  24060. if (cff.topDict.hasName('FontMatrix')) {
  24061. var base = cff.topDict.getByName('FontMatrix');
  24062. cff.topDict.removeByName('FontMatrix');
  24063. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  24064. var subDict = cff.fdArray[i];
  24065. var matrix = base.slice(0);
  24066. if (subDict.hasName('FontMatrix')) {
  24067. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  24068. }
  24069. subDict.setByName('FontMatrix', matrix);
  24070. }
  24071. }
  24072. }
  24073. var compiled = this.compileTopDicts([cff.topDict],
  24074. output.length,
  24075. cff.isCIDFont);
  24076. output.add(compiled.output);
  24077. var topDictTracker = compiled.trackers[0];
  24078. var stringIndex = this.compileStringIndex(cff.strings.strings);
  24079. output.add(stringIndex);
  24080. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  24081. output.add(globalSubrIndex);
  24082. // Now start on the other entries that have no specfic order.
  24083. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  24084. if (cff.encoding.predefined) {
  24085. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  24086. output);
  24087. } else {
  24088. var encoding = this.compileEncoding(cff.encoding);
  24089. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  24090. output.add(encoding);
  24091. }
  24092. }
  24093. if (cff.charset && cff.topDict.hasName('charset')) {
  24094. if (cff.charset.predefined) {
  24095. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  24096. output);
  24097. } else {
  24098. var charset = this.compileCharset(cff.charset);
  24099. topDictTracker.setEntryLocation('charset', [output.length], output);
  24100. output.add(charset);
  24101. }
  24102. }
  24103. var charStrings = this.compileCharStrings(cff.charStrings);
  24104. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  24105. output.add(charStrings);
  24106. if (cff.isCIDFont) {
  24107. // For some reason FDSelect must be in front of FDArray on windows. OSX
  24108. // and linux don't seem to care.
  24109. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  24110. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  24111. output.add(fdSelect);
  24112. // It is unclear if the sub font dictionary can have CID related
  24113. // dictionary keys, but the sanitizer doesn't like them so remove them.
  24114. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  24115. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  24116. output.add(compiled.output);
  24117. var fontDictTrackers = compiled.trackers;
  24118. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  24119. }
  24120. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  24121. // If the font data ends with INDEX whose object data is zero-length,
  24122. // the sanitizer will bail out. Add a dummy byte to avoid that.
  24123. output.add([0]);
  24124. return output.data;
  24125. },
  24126. encodeNumber: function CFFCompiler_encodeNumber(value) {
  24127. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  24128. return this.encodeInteger(value);
  24129. } else {
  24130. return this.encodeFloat(value);
  24131. }
  24132. },
  24133. encodeFloat: function CFFCompiler_encodeFloat(num) {
  24134. var value = num.toString();
  24135. // rounding inaccurate doubles
  24136. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  24137. if (m) {
  24138. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  24139. value = (Math.round(num * epsilon) / epsilon).toString();
  24140. }
  24141. var nibbles = '';
  24142. var i, ii;
  24143. for (i = 0, ii = value.length; i < ii; ++i) {
  24144. var a = value[i];
  24145. if (a === 'e') {
  24146. nibbles += value[++i] === '-' ? 'c' : 'b';
  24147. } else if (a === '.') {
  24148. nibbles += 'a';
  24149. } else if (a === '-') {
  24150. nibbles += 'e';
  24151. } else {
  24152. nibbles += a;
  24153. }
  24154. }
  24155. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  24156. var out = [30];
  24157. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  24158. out.push(parseInt(nibbles.substr(i, 2), 16));
  24159. }
  24160. return out;
  24161. },
  24162. encodeInteger: function CFFCompiler_encodeInteger(value) {
  24163. var code;
  24164. if (value >= -107 && value <= 107) {
  24165. code = [value + 139];
  24166. } else if (value >= 108 && value <= 1131) {
  24167. value = [value - 108];
  24168. code = [(value >> 8) + 247, value & 0xFF];
  24169. } else if (value >= -1131 && value <= -108) {
  24170. value = -value - 108;
  24171. code = [(value >> 8) + 251, value & 0xFF];
  24172. } else if (value >= -32768 && value <= 32767) {
  24173. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  24174. } else {
  24175. code = [0x1d,
  24176. (value >> 24) & 0xFF,
  24177. (value >> 16) & 0xFF,
  24178. (value >> 8) & 0xFF,
  24179. value & 0xFF];
  24180. }
  24181. return code;
  24182. },
  24183. compileHeader: function CFFCompiler_compileHeader(header) {
  24184. return [
  24185. header.major,
  24186. header.minor,
  24187. header.hdrSize,
  24188. header.offSize
  24189. ];
  24190. },
  24191. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  24192. var nameIndex = new CFFIndex();
  24193. for (var i = 0, ii = names.length; i < ii; ++i) {
  24194. nameIndex.add(stringToBytes(names[i]));
  24195. }
  24196. return this.compileIndex(nameIndex);
  24197. },
  24198. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  24199. length,
  24200. removeCidKeys) {
  24201. var fontDictTrackers = [];
  24202. var fdArrayIndex = new CFFIndex();
  24203. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  24204. var fontDict = dicts[i];
  24205. if (removeCidKeys) {
  24206. fontDict.removeByName('CIDFontVersion');
  24207. fontDict.removeByName('CIDFontRevision');
  24208. fontDict.removeByName('CIDFontType');
  24209. fontDict.removeByName('CIDCount');
  24210. fontDict.removeByName('UIDBase');
  24211. }
  24212. var fontDictTracker = new CFFOffsetTracker();
  24213. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  24214. fontDictTrackers.push(fontDictTracker);
  24215. fdArrayIndex.add(fontDictData);
  24216. fontDictTracker.offset(length);
  24217. }
  24218. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  24219. return {
  24220. trackers: fontDictTrackers,
  24221. output: fdArrayIndex
  24222. };
  24223. },
  24224. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  24225. trackers,
  24226. output) {
  24227. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  24228. var fontDict = dicts[i];
  24229. assert(fontDict.privateDict && fontDict.hasName('Private'),
  24230. 'There must be an private dictionary.');
  24231. var privateDict = fontDict.privateDict;
  24232. var privateDictTracker = new CFFOffsetTracker();
  24233. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  24234. var outputLength = output.length;
  24235. privateDictTracker.offset(outputLength);
  24236. if (!privateDictData.length) {
  24237. // The private dictionary was empty, set the output length to zero to
  24238. // ensure the offset length isn't out of bounds in the eyes of the
  24239. // sanitizer.
  24240. outputLength = 0;
  24241. }
  24242. trackers[i].setEntryLocation('Private',
  24243. [privateDictData.length, outputLength],
  24244. output);
  24245. output.add(privateDictData);
  24246. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  24247. var subrs = this.compileIndex(privateDict.subrsIndex);
  24248. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  24249. output);
  24250. output.add(subrs);
  24251. }
  24252. }
  24253. },
  24254. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  24255. var out = [];
  24256. // The dictionary keys must be in a certain order.
  24257. var order = dict.order;
  24258. for (var i = 0; i < order.length; ++i) {
  24259. var key = order[i];
  24260. if (!(key in dict.values)) {
  24261. continue;
  24262. }
  24263. var values = dict.values[key];
  24264. var types = dict.types[key];
  24265. if (!isArray(types)) {
  24266. types = [types];
  24267. }
  24268. if (!isArray(values)) {
  24269. values = [values];
  24270. }
  24271. // Remove any empty dict values.
  24272. if (values.length === 0) {
  24273. continue;
  24274. }
  24275. for (var j = 0, jj = types.length; j < jj; ++j) {
  24276. var type = types[j];
  24277. var value = values[j];
  24278. switch (type) {
  24279. case 'num':
  24280. case 'sid':
  24281. out = out.concat(this.encodeNumber(value));
  24282. break;
  24283. case 'offset':
  24284. // For offsets we just insert a 32bit integer so we don't have to
  24285. // deal with figuring out the length of the offset when it gets
  24286. // replaced later on by the compiler.
  24287. var name = dict.keyToNameMap[key];
  24288. // Some offsets have the offset and the length, so just record the
  24289. // position of the first one.
  24290. if (!offsetTracker.isTracking(name)) {
  24291. offsetTracker.track(name, out.length);
  24292. }
  24293. out = out.concat([0x1d, 0, 0, 0, 0]);
  24294. break;
  24295. case 'array':
  24296. case 'delta':
  24297. out = out.concat(this.encodeNumber(value));
  24298. for (var k = 1, kk = values.length; k < kk; ++k) {
  24299. out = out.concat(this.encodeNumber(values[k]));
  24300. }
  24301. break;
  24302. default:
  24303. error('Unknown data type of ' + type);
  24304. break;
  24305. }
  24306. }
  24307. out = out.concat(dict.opcodes[key]);
  24308. }
  24309. return out;
  24310. },
  24311. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  24312. var stringIndex = new CFFIndex();
  24313. for (var i = 0, ii = strings.length; i < ii; ++i) {
  24314. stringIndex.add(stringToBytes(strings[i]));
  24315. }
  24316. return this.compileIndex(stringIndex);
  24317. },
  24318. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  24319. var globalSubrIndex = this.cff.globalSubrIndex;
  24320. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  24321. },
  24322. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  24323. return this.compileIndex(charStrings);
  24324. },
  24325. compileCharset: function CFFCompiler_compileCharset(charset) {
  24326. return this.compileTypedArray(charset.raw);
  24327. },
  24328. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  24329. return this.compileTypedArray(encoding.raw);
  24330. },
  24331. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  24332. return this.compileTypedArray(fdSelect);
  24333. },
  24334. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  24335. var out = [];
  24336. for (var i = 0, ii = data.length; i < ii; ++i) {
  24337. out[i] = data[i];
  24338. }
  24339. return out;
  24340. },
  24341. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  24342. trackers = trackers || [];
  24343. var objects = index.objects;
  24344. // First 2 bytes contains the number of objects contained into this index
  24345. var count = objects.length;
  24346. // If there is no object, just create an index. This technically
  24347. // should just be [0, 0] but OTS has an issue with that.
  24348. if (count === 0) {
  24349. return [0, 0, 0];
  24350. }
  24351. var data = [(count >> 8) & 0xFF, count & 0xff];
  24352. var lastOffset = 1, i;
  24353. for (i = 0; i < count; ++i) {
  24354. lastOffset += objects[i].length;
  24355. }
  24356. var offsetSize;
  24357. if (lastOffset < 0x100) {
  24358. offsetSize = 1;
  24359. } else if (lastOffset < 0x10000) {
  24360. offsetSize = 2;
  24361. } else if (lastOffset < 0x1000000) {
  24362. offsetSize = 3;
  24363. } else {
  24364. offsetSize = 4;
  24365. }
  24366. // Next byte contains the offset size use to reference object in the file
  24367. data.push(offsetSize);
  24368. // Add another offset after this one because we need a new offset
  24369. var relativeOffset = 1;
  24370. for (i = 0; i < count + 1; i++) {
  24371. if (offsetSize === 1) {
  24372. data.push(relativeOffset & 0xFF);
  24373. } else if (offsetSize === 2) {
  24374. data.push((relativeOffset >> 8) & 0xFF,
  24375. relativeOffset & 0xFF);
  24376. } else if (offsetSize === 3) {
  24377. data.push((relativeOffset >> 16) & 0xFF,
  24378. (relativeOffset >> 8) & 0xFF,
  24379. relativeOffset & 0xFF);
  24380. } else {
  24381. data.push((relativeOffset >>> 24) & 0xFF,
  24382. (relativeOffset >> 16) & 0xFF,
  24383. (relativeOffset >> 8) & 0xFF,
  24384. relativeOffset & 0xFF);
  24385. }
  24386. if (objects[i]) {
  24387. relativeOffset += objects[i].length;
  24388. }
  24389. }
  24390. for (i = 0; i < count; i++) {
  24391. // Notify the tracker where the object will be offset in the data.
  24392. if (trackers[i]) {
  24393. trackers[i].offset(data.length);
  24394. }
  24395. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  24396. data.push(objects[i][j]);
  24397. }
  24398. }
  24399. return data;
  24400. }
  24401. };
  24402. return CFFCompiler;
  24403. })();
  24404. // Workaround for seac on Windows.
  24405. (function checkSeacSupport() {
  24406. if (/Windows/.test(navigator.userAgent)) {
  24407. SEAC_ANALYSIS_ENABLED = true;
  24408. }
  24409. })();
  24410. // Workaround for Private Use Area characters in Chrome on Windows
  24411. // http://code.google.com/p/chromium/issues/detail?id=122465
  24412. // https://github.com/mozilla/pdf.js/issues/1689
  24413. (function checkChromeWindows() {
  24414. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  24415. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  24416. }
  24417. })();
  24418. var FontRendererFactory = (function FontRendererFactoryClosure() {
  24419. function getLong(data, offset) {
  24420. return (data[offset] << 24) | (data[offset + 1] << 16) |
  24421. (data[offset + 2] << 8) | data[offset + 3];
  24422. }
  24423. function getUshort(data, offset) {
  24424. return (data[offset] << 8) | data[offset + 1];
  24425. }
  24426. function parseCmap(data, start, end) {
  24427. var offset = (getUshort(data, start + 2) === 1 ?
  24428. getLong(data, start + 8) : getLong(data, start + 16));
  24429. var format = getUshort(data, start + offset);
  24430. var length, ranges, p, i;
  24431. if (format === 4) {
  24432. length = getUshort(data, start + offset + 2);
  24433. var segCount = getUshort(data, start + offset + 6) >> 1;
  24434. p = start + offset + 14;
  24435. ranges = [];
  24436. for (i = 0; i < segCount; i++, p += 2) {
  24437. ranges[i] = {end: getUshort(data, p)};
  24438. }
  24439. p += 2;
  24440. for (i = 0; i < segCount; i++, p += 2) {
  24441. ranges[i].start = getUshort(data, p);
  24442. }
  24443. for (i = 0; i < segCount; i++, p += 2) {
  24444. ranges[i].idDelta = getUshort(data, p);
  24445. }
  24446. for (i = 0; i < segCount; i++, p += 2) {
  24447. var idOffset = getUshort(data, p);
  24448. if (idOffset === 0) {
  24449. continue;
  24450. }
  24451. ranges[i].ids = [];
  24452. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  24453. ranges[i].ids[j] = getUshort(data, p + idOffset);
  24454. idOffset += 2;
  24455. }
  24456. }
  24457. return ranges;
  24458. } else if (format === 12) {
  24459. length = getLong(data, start + offset + 4);
  24460. var groups = getLong(data, start + offset + 12);
  24461. p = start + offset + 16;
  24462. ranges = [];
  24463. for (i = 0; i < groups; i++) {
  24464. ranges.push({
  24465. start: getLong(data, p),
  24466. end: getLong(data, p + 4),
  24467. idDelta: getLong(data, p + 8) - getLong(data, p)
  24468. });
  24469. p += 12;
  24470. }
  24471. return ranges;
  24472. }
  24473. error('not supported cmap: ' + format);
  24474. }
  24475. function parseCff(data, start, end) {
  24476. var properties = {};
  24477. var parser = new CFFParser(new Stream(data, start, end - start),
  24478. properties);
  24479. var cff = parser.parse();
  24480. return {
  24481. glyphs: cff.charStrings.objects,
  24482. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  24483. cff.topDict.privateDict.subrsIndex.objects),
  24484. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  24485. };
  24486. }
  24487. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  24488. var itemSize, itemDecode;
  24489. if (isGlyphLocationsLong) {
  24490. itemSize = 4;
  24491. itemDecode = function fontItemDecodeLong(data, offset) {
  24492. return (data[offset] << 24) | (data[offset + 1] << 16) |
  24493. (data[offset + 2] << 8) | data[offset + 3];
  24494. };
  24495. } else {
  24496. itemSize = 2;
  24497. itemDecode = function fontItemDecode(data, offset) {
  24498. return (data[offset] << 9) | (data[offset + 1] << 1);
  24499. };
  24500. }
  24501. var glyphs = [];
  24502. var startOffset = itemDecode(loca, 0);
  24503. for (var j = itemSize; j < loca.length; j += itemSize) {
  24504. var endOffset = itemDecode(loca, j);
  24505. glyphs.push(glyf.subarray(startOffset, endOffset));
  24506. startOffset = endOffset;
  24507. }
  24508. return glyphs;
  24509. }
  24510. function lookupCmap(ranges, unicode) {
  24511. var code = unicode.charCodeAt(0);
  24512. var l = 0, r = ranges.length - 1;
  24513. while (l < r) {
  24514. var c = (l + r + 1) >> 1;
  24515. if (code < ranges[c].start) {
  24516. r = c - 1;
  24517. } else {
  24518. l = c;
  24519. }
  24520. }
  24521. if (ranges[l].start <= code && code <= ranges[l].end) {
  24522. return (ranges[l].idDelta + (ranges[l].ids ?
  24523. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  24524. }
  24525. return 0;
  24526. }
  24527. function compileGlyf(code, js, font) {
  24528. function moveTo(x, y) {
  24529. js.push('c.moveTo(' + x + ',' + y + ');');
  24530. }
  24531. function lineTo(x, y) {
  24532. js.push('c.lineTo(' + x + ',' + y + ');');
  24533. }
  24534. function quadraticCurveTo(xa, ya, x, y) {
  24535. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  24536. x + ',' + y + ');');
  24537. }
  24538. var i = 0;
  24539. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  24540. var flags;
  24541. var x = 0, y = 0;
  24542. i += 10;
  24543. if (numberOfContours < 0) {
  24544. // composite glyph
  24545. do {
  24546. flags = (code[i] << 8) | code[i + 1];
  24547. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  24548. i += 4;
  24549. var arg1, arg2;
  24550. if ((flags & 0x01)) {
  24551. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  24552. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  24553. i += 4;
  24554. } else {
  24555. arg1 = code[i++]; arg2 = code[i++];
  24556. }
  24557. if ((flags & 0x02)) {
  24558. x = arg1;
  24559. y = arg2;
  24560. } else {
  24561. x = 0; y = 0; // TODO "they are points" ?
  24562. }
  24563. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  24564. if ((flags & 0x08)) {
  24565. scaleX =
  24566. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  24567. i += 2;
  24568. } else if ((flags & 0x40)) {
  24569. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  24570. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  24571. i += 4;
  24572. } else if ((flags & 0x80)) {
  24573. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  24574. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  24575. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  24576. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  24577. i += 8;
  24578. }
  24579. var subglyph = font.glyphs[glyphIndex];
  24580. if (subglyph) {
  24581. js.push('c.save();');
  24582. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  24583. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  24584. compileGlyf(subglyph, js, font);
  24585. js.push('c.restore();');
  24586. }
  24587. } while ((flags & 0x20));
  24588. } else {
  24589. // simple glyph
  24590. var endPtsOfContours = [];
  24591. var j, jj;
  24592. for (j = 0; j < numberOfContours; j++) {
  24593. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  24594. i += 2;
  24595. }
  24596. var instructionLength = (code[i] << 8) | code[i + 1];
  24597. i += 2 + instructionLength; // skipping the instructions
  24598. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  24599. var points = [];
  24600. while (points.length < numberOfPoints) {
  24601. flags = code[i++];
  24602. var repeat = 1;
  24603. if ((flags & 0x08)) {
  24604. repeat += code[i++];
  24605. }
  24606. while (repeat-- > 0) {
  24607. points.push({flags: flags});
  24608. }
  24609. }
  24610. for (j = 0; j < numberOfPoints; j++) {
  24611. switch (points[j].flags & 0x12) {
  24612. case 0x00:
  24613. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  24614. i += 2;
  24615. break;
  24616. case 0x02:
  24617. x -= code[i++];
  24618. break;
  24619. case 0x12:
  24620. x += code[i++];
  24621. break;
  24622. }
  24623. points[j].x = x;
  24624. }
  24625. for (j = 0; j < numberOfPoints; j++) {
  24626. switch (points[j].flags & 0x24) {
  24627. case 0x00:
  24628. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  24629. i += 2;
  24630. break;
  24631. case 0x04:
  24632. y -= code[i++];
  24633. break;
  24634. case 0x24:
  24635. y += code[i++];
  24636. break;
  24637. }
  24638. points[j].y = y;
  24639. }
  24640. var startPoint = 0;
  24641. for (i = 0; i < numberOfContours; i++) {
  24642. var endPoint = endPtsOfContours[i];
  24643. // contours might have implicit points, which is located in the middle
  24644. // between two neighboring off-curve points
  24645. var contour = points.slice(startPoint, endPoint + 1);
  24646. if ((contour[0].flags & 1)) {
  24647. contour.push(contour[0]); // using start point at the contour end
  24648. } else if ((contour[contour.length - 1].flags & 1)) {
  24649. // first is off-curve point, trying to use one from the end
  24650. contour.unshift(contour[contour.length - 1]);
  24651. } else {
  24652. // start and end are off-curve points, creating implicit one
  24653. var p = {
  24654. flags: 1,
  24655. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  24656. y: (contour[0].y + contour[contour.length - 1].y) / 2
  24657. };
  24658. contour.unshift(p);
  24659. contour.push(p);
  24660. }
  24661. moveTo(contour[0].x, contour[0].y);
  24662. for (j = 1, jj = contour.length; j < jj; j++) {
  24663. if ((contour[j].flags & 1)) {
  24664. lineTo(contour[j].x, contour[j].y);
  24665. } else if ((contour[j + 1].flags & 1)){
  24666. quadraticCurveTo(contour[j].x, contour[j].y,
  24667. contour[j + 1].x, contour[j + 1].y);
  24668. j++;
  24669. } else {
  24670. quadraticCurveTo(contour[j].x, contour[j].y,
  24671. (contour[j].x + contour[j + 1].x) / 2,
  24672. (contour[j].y + contour[j + 1].y) / 2);
  24673. }
  24674. }
  24675. startPoint = endPoint + 1;
  24676. }
  24677. }
  24678. }
  24679. function compileCharString(code, js, font) {
  24680. var stack = [];
  24681. var x = 0, y = 0;
  24682. var stems = 0;
  24683. function moveTo(x, y) {
  24684. js.push('c.moveTo(' + x + ',' + y + ');');
  24685. }
  24686. function lineTo(x, y) {
  24687. js.push('c.lineTo(' + x + ',' + y + ');');
  24688. }
  24689. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  24690. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  24691. x + ',' + y + ');');
  24692. }
  24693. function parse(code) {
  24694. var i = 0;
  24695. while (i < code.length) {
  24696. var stackClean = false;
  24697. var v = code[i++];
  24698. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  24699. switch (v) {
  24700. case 1: // hstem
  24701. stems += stack.length >> 1;
  24702. stackClean = true;
  24703. break;
  24704. case 3: // vstem
  24705. stems += stack.length >> 1;
  24706. stackClean = true;
  24707. break;
  24708. case 4: // vmoveto
  24709. y += stack.pop();
  24710. moveTo(x, y);
  24711. stackClean = true;
  24712. break;
  24713. case 5: // rlineto
  24714. while (stack.length > 0) {
  24715. x += stack.shift();
  24716. y += stack.shift();
  24717. lineTo(x, y);
  24718. }
  24719. break;
  24720. case 6: // hlineto
  24721. while (stack.length > 0) {
  24722. x += stack.shift();
  24723. lineTo(x, y);
  24724. if (stack.length === 0) {
  24725. break;
  24726. }
  24727. y += stack.shift();
  24728. lineTo(x, y);
  24729. }
  24730. break;
  24731. case 7: // vlineto
  24732. while (stack.length > 0) {
  24733. y += stack.shift();
  24734. lineTo(x, y);
  24735. if (stack.length === 0) {
  24736. break;
  24737. }
  24738. x += stack.shift();
  24739. lineTo(x, y);
  24740. }
  24741. break;
  24742. case 8: // rrcurveto
  24743. while (stack.length > 0) {
  24744. xa = x + stack.shift(); ya = y + stack.shift();
  24745. xb = xa + stack.shift(); yb = ya + stack.shift();
  24746. x = xb + stack.shift(); y = yb + stack.shift();
  24747. bezierCurveTo(xa, ya, xb, yb, x, y);
  24748. }
  24749. break;
  24750. case 10: // callsubr
  24751. n = stack.pop() + font.subrsBias;
  24752. subrCode = font.subrs[n];
  24753. if (subrCode) {
  24754. parse(subrCode);
  24755. }
  24756. break;
  24757. case 11: // return
  24758. return;
  24759. case 12:
  24760. v = code[i++];
  24761. switch (v) {
  24762. case 34: // flex
  24763. xa = x + stack.shift();
  24764. xb = xa + stack.shift(); y1 = y + stack.shift();
  24765. x = xb + stack.shift();
  24766. bezierCurveTo(xa, y, xb, y1, x, y1);
  24767. xa = x + stack.shift();
  24768. xb = xa + stack.shift();
  24769. x = xb + stack.shift();
  24770. bezierCurveTo(xa, y1, xb, y, x, y);
  24771. break;
  24772. case 35: // flex
  24773. xa = x + stack.shift(); ya = y + stack.shift();
  24774. xb = xa + stack.shift(); yb = ya + stack.shift();
  24775. x = xb + stack.shift(); y = yb + stack.shift();
  24776. bezierCurveTo(xa, ya, xb, yb, x, y);
  24777. xa = x + stack.shift(); ya = y + stack.shift();
  24778. xb = xa + stack.shift(); yb = ya + stack.shift();
  24779. x = xb + stack.shift(); y = yb + stack.shift();
  24780. bezierCurveTo(xa, ya, xb, yb, x, y);
  24781. stack.pop(); // fd
  24782. break;
  24783. case 36: // hflex1
  24784. xa = x + stack.shift(); y1 = y + stack.shift();
  24785. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  24786. x = xb + stack.shift();
  24787. bezierCurveTo(xa, y1, xb, y2, x, y2);
  24788. xa = x + stack.shift();
  24789. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  24790. x = xb + stack.shift();
  24791. bezierCurveTo(xa, y2, xb, y3, x, y);
  24792. break;
  24793. case 37: // flex1
  24794. var x0 = x, y0 = y;
  24795. xa = x + stack.shift(); ya = y + stack.shift();
  24796. xb = xa + stack.shift(); yb = ya + stack.shift();
  24797. x = xb + stack.shift(); y = yb + stack.shift();
  24798. bezierCurveTo(xa, ya, xb, yb, x, y);
  24799. xa = x + stack.shift(); ya = y + stack.shift();
  24800. xb = xa + stack.shift(); yb = ya + stack.shift();
  24801. x = xb; y = yb;
  24802. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  24803. x += stack.shift();
  24804. } else {
  24805. y += stack.shift();
  24806. }
  24807. bezierCurveTo(xa, ya, xb, yb, x, y);
  24808. break;
  24809. default:
  24810. error('unknown operator: 12 ' + v);
  24811. }
  24812. break;
  24813. case 14: // endchar
  24814. if (stack.length >= 4) {
  24815. var achar = stack.pop();
  24816. var bchar = stack.pop();
  24817. y = stack.pop();
  24818. x = stack.pop();
  24819. js.push('c.save();');
  24820. js.push('c.translate('+ x + ',' + y + ');');
  24821. var gid = lookupCmap(font.cmap, String.fromCharCode(
  24822. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  24823. compileCharString(font.glyphs[gid], js, font);
  24824. js.push('c.restore();');
  24825. gid = lookupCmap(font.cmap, String.fromCharCode(
  24826. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  24827. compileCharString(font.glyphs[gid], js, font);
  24828. }
  24829. return;
  24830. case 18: // hstemhm
  24831. stems += stack.length >> 1;
  24832. stackClean = true;
  24833. break;
  24834. case 19: // hintmask
  24835. stems += stack.length >> 1;
  24836. i += (stems + 7) >> 3;
  24837. stackClean = true;
  24838. break;
  24839. case 20: // cntrmask
  24840. stems += stack.length >> 1;
  24841. i += (stems + 7) >> 3;
  24842. stackClean = true;
  24843. break;
  24844. case 21: // rmoveto
  24845. y += stack.pop();
  24846. x += stack.pop();
  24847. moveTo(x, y);
  24848. stackClean = true;
  24849. break;
  24850. case 22: // hmoveto
  24851. x += stack.pop();
  24852. moveTo(x, y);
  24853. stackClean = true;
  24854. break;
  24855. case 23: // vstemhm
  24856. stems += stack.length >> 1;
  24857. stackClean = true;
  24858. break;
  24859. case 24: // rcurveline
  24860. while (stack.length > 2) {
  24861. xa = x + stack.shift(); ya = y + stack.shift();
  24862. xb = xa + stack.shift(); yb = ya + stack.shift();
  24863. x = xb + stack.shift(); y = yb + stack.shift();
  24864. bezierCurveTo(xa, ya, xb, yb, x, y);
  24865. }
  24866. x += stack.shift();
  24867. y += stack.shift();
  24868. lineTo(x, y);
  24869. break;
  24870. case 25: // rlinecurve
  24871. while (stack.length > 6) {
  24872. x += stack.shift();
  24873. y += stack.shift();
  24874. lineTo(x, y);
  24875. }
  24876. xa = x + stack.shift(); ya = y + stack.shift();
  24877. xb = xa + stack.shift(); yb = ya + stack.shift();
  24878. x = xb + stack.shift(); y = yb + stack.shift();
  24879. bezierCurveTo(xa, ya, xb, yb, x, y);
  24880. break;
  24881. case 26: // vvcurveto
  24882. if (stack.length % 2) {
  24883. x += stack.shift();
  24884. }
  24885. while (stack.length > 0) {
  24886. xa = x; ya = y + stack.shift();
  24887. xb = xa + stack.shift(); yb = ya + stack.shift();
  24888. x = xb; y = yb + stack.shift();
  24889. bezierCurveTo(xa, ya, xb, yb, x, y);
  24890. }
  24891. break;
  24892. case 27: // hhcurveto
  24893. if (stack.length % 2) {
  24894. y += stack.shift();
  24895. }
  24896. while (stack.length > 0) {
  24897. xa = x + stack.shift(); ya = y;
  24898. xb = xa + stack.shift(); yb = ya + stack.shift();
  24899. x = xb + stack.shift(); y = yb;
  24900. bezierCurveTo(xa, ya, xb, yb, x, y);
  24901. }
  24902. break;
  24903. case 28:
  24904. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  24905. i += 2;
  24906. break;
  24907. case 29: // callgsubr
  24908. n = stack.pop() + font.gsubrsBias;
  24909. subrCode = font.gsubrs[n];
  24910. if (subrCode) {
  24911. parse(subrCode);
  24912. }
  24913. break;
  24914. case 30: // vhcurveto
  24915. while (stack.length > 0) {
  24916. xa = x; ya = y + stack.shift();
  24917. xb = xa + stack.shift(); yb = ya + stack.shift();
  24918. x = xb + stack.shift();
  24919. y = yb + (stack.length === 1 ? stack.shift() : 0);
  24920. bezierCurveTo(xa, ya, xb, yb, x, y);
  24921. if (stack.length === 0) {
  24922. break;
  24923. }
  24924. xa = x + stack.shift(); ya = y;
  24925. xb = xa + stack.shift(); yb = ya + stack.shift();
  24926. y = yb + stack.shift();
  24927. x = xb + (stack.length === 1 ? stack.shift() : 0);
  24928. bezierCurveTo(xa, ya, xb, yb, x, y);
  24929. }
  24930. break;
  24931. case 31: // hvcurveto
  24932. while (stack.length > 0) {
  24933. xa = x + stack.shift(); ya = y;
  24934. xb = xa + stack.shift(); yb = ya + stack.shift();
  24935. y = yb + stack.shift();
  24936. x = xb + (stack.length === 1 ? stack.shift() : 0);
  24937. bezierCurveTo(xa, ya, xb, yb, x, y);
  24938. if (stack.length === 0) {
  24939. break;
  24940. }
  24941. xa = x; ya = y + stack.shift();
  24942. xb = xa + stack.shift(); yb = ya + stack.shift();
  24943. x = xb + stack.shift();
  24944. y = yb + (stack.length === 1 ? stack.shift() : 0);
  24945. bezierCurveTo(xa, ya, xb, yb, x, y);
  24946. }
  24947. break;
  24948. default:
  24949. if (v < 32) {
  24950. error('unknown operator: ' + v);
  24951. }
  24952. if (v < 247) {
  24953. stack.push(v - 139);
  24954. } else if (v < 251) {
  24955. stack.push((v - 247) * 256 + code[i++] + 108);
  24956. } else if (v < 255) {
  24957. stack.push(-(v - 251) * 256 - code[i++] - 108);
  24958. } else {
  24959. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  24960. (code[i + 2] << 8) | code[i + 3]) / 65536);
  24961. i += 4;
  24962. }
  24963. break;
  24964. }
  24965. if (stackClean) {
  24966. stack.length = 0;
  24967. }
  24968. }
  24969. }
  24970. parse(code);
  24971. }
  24972. var noop = '';
  24973. function CompiledFont(fontMatrix) {
  24974. this.compiledGlyphs = {};
  24975. this.fontMatrix = fontMatrix;
  24976. }
  24977. CompiledFont.prototype = {
  24978. getPathJs: function (unicode) {
  24979. var gid = lookupCmap(this.cmap, unicode);
  24980. var fn = this.compiledGlyphs[gid];
  24981. if (!fn) {
  24982. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  24983. }
  24984. return fn;
  24985. },
  24986. compileGlyph: function (code) {
  24987. if (!code || code.length === 0 || code[0] === 14) {
  24988. return noop;
  24989. }
  24990. var js = [];
  24991. js.push('c.save();');
  24992. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  24993. js.push('c.scale(size, -size);');
  24994. this.compileGlyphImpl(code, js);
  24995. js.push('c.restore();');
  24996. return js.join('\n');
  24997. },
  24998. compileGlyphImpl: function () {
  24999. error('Children classes should implement this.');
  25000. },
  25001. hasBuiltPath: function (unicode) {
  25002. var gid = lookupCmap(this.cmap, unicode);
  25003. return gid in this.compiledGlyphs;
  25004. }
  25005. };
  25006. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25007. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25008. CompiledFont.call(this, fontMatrix);
  25009. this.glyphs = glyphs;
  25010. this.cmap = cmap;
  25011. this.compiledGlyphs = [];
  25012. }
  25013. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25014. compileGlyphImpl: function (code, js) {
  25015. compileGlyf(code, js, this);
  25016. }
  25017. });
  25018. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25019. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25020. CompiledFont.call(this, fontMatrix);
  25021. this.glyphs = cffInfo.glyphs;
  25022. this.gsubrs = cffInfo.gsubrs || [];
  25023. this.subrs = cffInfo.subrs || [];
  25024. this.cmap = cmap;
  25025. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25026. this.compiledGlyphs = [];
  25027. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25028. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25029. this.subrsBias = (this.subrs.length < 1240 ?
  25030. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25031. }
  25032. Util.inherit(Type2Compiled, CompiledFont, {
  25033. compileGlyphImpl: function (code, js) {
  25034. compileCharString(code, js, this);
  25035. }
  25036. });
  25037. return {
  25038. create: function FontRendererFactory_create(font) {
  25039. var data = new Uint8Array(font.data);
  25040. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25041. var numTables = getUshort(data, 4);
  25042. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25043. var tag = bytesToString(data.subarray(p, p + 4));
  25044. var offset = getLong(data, p + 8);
  25045. var length = getLong(data, p + 12);
  25046. switch (tag) {
  25047. case 'cmap':
  25048. cmap = parseCmap(data, offset, offset + length);
  25049. break;
  25050. case 'glyf':
  25051. glyf = data.subarray(offset, offset + length);
  25052. break;
  25053. case 'loca':
  25054. loca = data.subarray(offset, offset + length);
  25055. break;
  25056. case 'head':
  25057. unitsPerEm = getUshort(data, offset + 18);
  25058. indexToLocFormat = getUshort(data, offset + 50);
  25059. break;
  25060. case 'CFF ':
  25061. cff = parseCff(data, offset, offset + length);
  25062. break;
  25063. }
  25064. }
  25065. if (glyf) {
  25066. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25067. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25068. return new TrueTypeCompiled(
  25069. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25070. } else {
  25071. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25072. }
  25073. }
  25074. };
  25075. })();
  25076. var GlyphsUnicode = {
  25077. A: 0x0041,
  25078. AE: 0x00C6,
  25079. AEacute: 0x01FC,
  25080. AEmacron: 0x01E2,
  25081. AEsmall: 0xF7E6,
  25082. Aacute: 0x00C1,
  25083. Aacutesmall: 0xF7E1,
  25084. Abreve: 0x0102,
  25085. Abreveacute: 0x1EAE,
  25086. Abrevecyrillic: 0x04D0,
  25087. Abrevedotbelow: 0x1EB6,
  25088. Abrevegrave: 0x1EB0,
  25089. Abrevehookabove: 0x1EB2,
  25090. Abrevetilde: 0x1EB4,
  25091. Acaron: 0x01CD,
  25092. Acircle: 0x24B6,
  25093. Acircumflex: 0x00C2,
  25094. Acircumflexacute: 0x1EA4,
  25095. Acircumflexdotbelow: 0x1EAC,
  25096. Acircumflexgrave: 0x1EA6,
  25097. Acircumflexhookabove: 0x1EA8,
  25098. Acircumflexsmall: 0xF7E2,
  25099. Acircumflextilde: 0x1EAA,
  25100. Acute: 0xF6C9,
  25101. Acutesmall: 0xF7B4,
  25102. Acyrillic: 0x0410,
  25103. Adblgrave: 0x0200,
  25104. Adieresis: 0x00C4,
  25105. Adieresiscyrillic: 0x04D2,
  25106. Adieresismacron: 0x01DE,
  25107. Adieresissmall: 0xF7E4,
  25108. Adotbelow: 0x1EA0,
  25109. Adotmacron: 0x01E0,
  25110. Agrave: 0x00C0,
  25111. Agravesmall: 0xF7E0,
  25112. Ahookabove: 0x1EA2,
  25113. Aiecyrillic: 0x04D4,
  25114. Ainvertedbreve: 0x0202,
  25115. Alpha: 0x0391,
  25116. Alphatonos: 0x0386,
  25117. Amacron: 0x0100,
  25118. Amonospace: 0xFF21,
  25119. Aogonek: 0x0104,
  25120. Aring: 0x00C5,
  25121. Aringacute: 0x01FA,
  25122. Aringbelow: 0x1E00,
  25123. Aringsmall: 0xF7E5,
  25124. Asmall: 0xF761,
  25125. Atilde: 0x00C3,
  25126. Atildesmall: 0xF7E3,
  25127. Aybarmenian: 0x0531,
  25128. B: 0x0042,
  25129. Bcircle: 0x24B7,
  25130. Bdotaccent: 0x1E02,
  25131. Bdotbelow: 0x1E04,
  25132. Becyrillic: 0x0411,
  25133. Benarmenian: 0x0532,
  25134. Beta: 0x0392,
  25135. Bhook: 0x0181,
  25136. Blinebelow: 0x1E06,
  25137. Bmonospace: 0xFF22,
  25138. Brevesmall: 0xF6F4,
  25139. Bsmall: 0xF762,
  25140. Btopbar: 0x0182,
  25141. C: 0x0043,
  25142. Caarmenian: 0x053E,
  25143. Cacute: 0x0106,
  25144. Caron: 0xF6CA,
  25145. Caronsmall: 0xF6F5,
  25146. Ccaron: 0x010C,
  25147. Ccedilla: 0x00C7,
  25148. Ccedillaacute: 0x1E08,
  25149. Ccedillasmall: 0xF7E7,
  25150. Ccircle: 0x24B8,
  25151. Ccircumflex: 0x0108,
  25152. Cdot: 0x010A,
  25153. Cdotaccent: 0x010A,
  25154. Cedillasmall: 0xF7B8,
  25155. Chaarmenian: 0x0549,
  25156. Cheabkhasiancyrillic: 0x04BC,
  25157. Checyrillic: 0x0427,
  25158. Chedescenderabkhasiancyrillic: 0x04BE,
  25159. Chedescendercyrillic: 0x04B6,
  25160. Chedieresiscyrillic: 0x04F4,
  25161. Cheharmenian: 0x0543,
  25162. Chekhakassiancyrillic: 0x04CB,
  25163. Cheverticalstrokecyrillic: 0x04B8,
  25164. Chi: 0x03A7,
  25165. Chook: 0x0187,
  25166. Circumflexsmall: 0xF6F6,
  25167. Cmonospace: 0xFF23,
  25168. Coarmenian: 0x0551,
  25169. Csmall: 0xF763,
  25170. D: 0x0044,
  25171. DZ: 0x01F1,
  25172. DZcaron: 0x01C4,
  25173. Daarmenian: 0x0534,
  25174. Dafrican: 0x0189,
  25175. Dcaron: 0x010E,
  25176. Dcedilla: 0x1E10,
  25177. Dcircle: 0x24B9,
  25178. Dcircumflexbelow: 0x1E12,
  25179. Dcroat: 0x0110,
  25180. Ddotaccent: 0x1E0A,
  25181. Ddotbelow: 0x1E0C,
  25182. Decyrillic: 0x0414,
  25183. Deicoptic: 0x03EE,
  25184. Delta: 0x2206,
  25185. Deltagreek: 0x0394,
  25186. Dhook: 0x018A,
  25187. Dieresis: 0xF6CB,
  25188. DieresisAcute: 0xF6CC,
  25189. DieresisGrave: 0xF6CD,
  25190. Dieresissmall: 0xF7A8,
  25191. Digammagreek: 0x03DC,
  25192. Djecyrillic: 0x0402,
  25193. Dlinebelow: 0x1E0E,
  25194. Dmonospace: 0xFF24,
  25195. Dotaccentsmall: 0xF6F7,
  25196. Dslash: 0x0110,
  25197. Dsmall: 0xF764,
  25198. Dtopbar: 0x018B,
  25199. Dz: 0x01F2,
  25200. Dzcaron: 0x01C5,
  25201. Dzeabkhasiancyrillic: 0x04E0,
  25202. Dzecyrillic: 0x0405,
  25203. Dzhecyrillic: 0x040F,
  25204. E: 0x0045,
  25205. Eacute: 0x00C9,
  25206. Eacutesmall: 0xF7E9,
  25207. Ebreve: 0x0114,
  25208. Ecaron: 0x011A,
  25209. Ecedillabreve: 0x1E1C,
  25210. Echarmenian: 0x0535,
  25211. Ecircle: 0x24BA,
  25212. Ecircumflex: 0x00CA,
  25213. Ecircumflexacute: 0x1EBE,
  25214. Ecircumflexbelow: 0x1E18,
  25215. Ecircumflexdotbelow: 0x1EC6,
  25216. Ecircumflexgrave: 0x1EC0,
  25217. Ecircumflexhookabove: 0x1EC2,
  25218. Ecircumflexsmall: 0xF7EA,
  25219. Ecircumflextilde: 0x1EC4,
  25220. Ecyrillic: 0x0404,
  25221. Edblgrave: 0x0204,
  25222. Edieresis: 0x00CB,
  25223. Edieresissmall: 0xF7EB,
  25224. Edot: 0x0116,
  25225. Edotaccent: 0x0116,
  25226. Edotbelow: 0x1EB8,
  25227. Efcyrillic: 0x0424,
  25228. Egrave: 0x00C8,
  25229. Egravesmall: 0xF7E8,
  25230. Eharmenian: 0x0537,
  25231. Ehookabove: 0x1EBA,
  25232. Eightroman: 0x2167,
  25233. Einvertedbreve: 0x0206,
  25234. Eiotifiedcyrillic: 0x0464,
  25235. Elcyrillic: 0x041B,
  25236. Elevenroman: 0x216A,
  25237. Emacron: 0x0112,
  25238. Emacronacute: 0x1E16,
  25239. Emacrongrave: 0x1E14,
  25240. Emcyrillic: 0x041C,
  25241. Emonospace: 0xFF25,
  25242. Encyrillic: 0x041D,
  25243. Endescendercyrillic: 0x04A2,
  25244. Eng: 0x014A,
  25245. Enghecyrillic: 0x04A4,
  25246. Enhookcyrillic: 0x04C7,
  25247. Eogonek: 0x0118,
  25248. Eopen: 0x0190,
  25249. Epsilon: 0x0395,
  25250. Epsilontonos: 0x0388,
  25251. Ercyrillic: 0x0420,
  25252. Ereversed: 0x018E,
  25253. Ereversedcyrillic: 0x042D,
  25254. Escyrillic: 0x0421,
  25255. Esdescendercyrillic: 0x04AA,
  25256. Esh: 0x01A9,
  25257. Esmall: 0xF765,
  25258. Eta: 0x0397,
  25259. Etarmenian: 0x0538,
  25260. Etatonos: 0x0389,
  25261. Eth: 0x00D0,
  25262. Ethsmall: 0xF7F0,
  25263. Etilde: 0x1EBC,
  25264. Etildebelow: 0x1E1A,
  25265. Euro: 0x20AC,
  25266. Ezh: 0x01B7,
  25267. Ezhcaron: 0x01EE,
  25268. Ezhreversed: 0x01B8,
  25269. F: 0x0046,
  25270. Fcircle: 0x24BB,
  25271. Fdotaccent: 0x1E1E,
  25272. Feharmenian: 0x0556,
  25273. Feicoptic: 0x03E4,
  25274. Fhook: 0x0191,
  25275. Fitacyrillic: 0x0472,
  25276. Fiveroman: 0x2164,
  25277. Fmonospace: 0xFF26,
  25278. Fourroman: 0x2163,
  25279. Fsmall: 0xF766,
  25280. G: 0x0047,
  25281. GBsquare: 0x3387,
  25282. Gacute: 0x01F4,
  25283. Gamma: 0x0393,
  25284. Gammaafrican: 0x0194,
  25285. Gangiacoptic: 0x03EA,
  25286. Gbreve: 0x011E,
  25287. Gcaron: 0x01E6,
  25288. Gcedilla: 0x0122,
  25289. Gcircle: 0x24BC,
  25290. Gcircumflex: 0x011C,
  25291. Gcommaaccent: 0x0122,
  25292. Gdot: 0x0120,
  25293. Gdotaccent: 0x0120,
  25294. Gecyrillic: 0x0413,
  25295. Ghadarmenian: 0x0542,
  25296. Ghemiddlehookcyrillic: 0x0494,
  25297. Ghestrokecyrillic: 0x0492,
  25298. Gheupturncyrillic: 0x0490,
  25299. Ghook: 0x0193,
  25300. Gimarmenian: 0x0533,
  25301. Gjecyrillic: 0x0403,
  25302. Gmacron: 0x1E20,
  25303. Gmonospace: 0xFF27,
  25304. Grave: 0xF6CE,
  25305. Gravesmall: 0xF760,
  25306. Gsmall: 0xF767,
  25307. Gsmallhook: 0x029B,
  25308. Gstroke: 0x01E4,
  25309. H: 0x0048,
  25310. H18533: 0x25CF,
  25311. H18543: 0x25AA,
  25312. H18551: 0x25AB,
  25313. H22073: 0x25A1,
  25314. HPsquare: 0x33CB,
  25315. Haabkhasiancyrillic: 0x04A8,
  25316. Hadescendercyrillic: 0x04B2,
  25317. Hardsigncyrillic: 0x042A,
  25318. Hbar: 0x0126,
  25319. Hbrevebelow: 0x1E2A,
  25320. Hcedilla: 0x1E28,
  25321. Hcircle: 0x24BD,
  25322. Hcircumflex: 0x0124,
  25323. Hdieresis: 0x1E26,
  25324. Hdotaccent: 0x1E22,
  25325. Hdotbelow: 0x1E24,
  25326. Hmonospace: 0xFF28,
  25327. Hoarmenian: 0x0540,
  25328. Horicoptic: 0x03E8,
  25329. Hsmall: 0xF768,
  25330. Hungarumlaut: 0xF6CF,
  25331. Hungarumlautsmall: 0xF6F8,
  25332. Hzsquare: 0x3390,
  25333. I: 0x0049,
  25334. IAcyrillic: 0x042F,
  25335. IJ: 0x0132,
  25336. IUcyrillic: 0x042E,
  25337. Iacute: 0x00CD,
  25338. Iacutesmall: 0xF7ED,
  25339. Ibreve: 0x012C,
  25340. Icaron: 0x01CF,
  25341. Icircle: 0x24BE,
  25342. Icircumflex: 0x00CE,
  25343. Icircumflexsmall: 0xF7EE,
  25344. Icyrillic: 0x0406,
  25345. Idblgrave: 0x0208,
  25346. Idieresis: 0x00CF,
  25347. Idieresisacute: 0x1E2E,
  25348. Idieresiscyrillic: 0x04E4,
  25349. Idieresissmall: 0xF7EF,
  25350. Idot: 0x0130,
  25351. Idotaccent: 0x0130,
  25352. Idotbelow: 0x1ECA,
  25353. Iebrevecyrillic: 0x04D6,
  25354. Iecyrillic: 0x0415,
  25355. Ifraktur: 0x2111,
  25356. Igrave: 0x00CC,
  25357. Igravesmall: 0xF7EC,
  25358. Ihookabove: 0x1EC8,
  25359. Iicyrillic: 0x0418,
  25360. Iinvertedbreve: 0x020A,
  25361. Iishortcyrillic: 0x0419,
  25362. Imacron: 0x012A,
  25363. Imacroncyrillic: 0x04E2,
  25364. Imonospace: 0xFF29,
  25365. Iniarmenian: 0x053B,
  25366. Iocyrillic: 0x0401,
  25367. Iogonek: 0x012E,
  25368. Iota: 0x0399,
  25369. Iotaafrican: 0x0196,
  25370. Iotadieresis: 0x03AA,
  25371. Iotatonos: 0x038A,
  25372. Ismall: 0xF769,
  25373. Istroke: 0x0197,
  25374. Itilde: 0x0128,
  25375. Itildebelow: 0x1E2C,
  25376. Izhitsacyrillic: 0x0474,
  25377. Izhitsadblgravecyrillic: 0x0476,
  25378. J: 0x004A,
  25379. Jaarmenian: 0x0541,
  25380. Jcircle: 0x24BF,
  25381. Jcircumflex: 0x0134,
  25382. Jecyrillic: 0x0408,
  25383. Jheharmenian: 0x054B,
  25384. Jmonospace: 0xFF2A,
  25385. Jsmall: 0xF76A,
  25386. K: 0x004B,
  25387. KBsquare: 0x3385,
  25388. KKsquare: 0x33CD,
  25389. Kabashkircyrillic: 0x04A0,
  25390. Kacute: 0x1E30,
  25391. Kacyrillic: 0x041A,
  25392. Kadescendercyrillic: 0x049A,
  25393. Kahookcyrillic: 0x04C3,
  25394. Kappa: 0x039A,
  25395. Kastrokecyrillic: 0x049E,
  25396. Kaverticalstrokecyrillic: 0x049C,
  25397. Kcaron: 0x01E8,
  25398. Kcedilla: 0x0136,
  25399. Kcircle: 0x24C0,
  25400. Kcommaaccent: 0x0136,
  25401. Kdotbelow: 0x1E32,
  25402. Keharmenian: 0x0554,
  25403. Kenarmenian: 0x053F,
  25404. Khacyrillic: 0x0425,
  25405. Kheicoptic: 0x03E6,
  25406. Khook: 0x0198,
  25407. Kjecyrillic: 0x040C,
  25408. Klinebelow: 0x1E34,
  25409. Kmonospace: 0xFF2B,
  25410. Koppacyrillic: 0x0480,
  25411. Koppagreek: 0x03DE,
  25412. Ksicyrillic: 0x046E,
  25413. Ksmall: 0xF76B,
  25414. L: 0x004C,
  25415. LJ: 0x01C7,
  25416. LL: 0xF6BF,
  25417. Lacute: 0x0139,
  25418. Lambda: 0x039B,
  25419. Lcaron: 0x013D,
  25420. Lcedilla: 0x013B,
  25421. Lcircle: 0x24C1,
  25422. Lcircumflexbelow: 0x1E3C,
  25423. Lcommaaccent: 0x013B,
  25424. Ldot: 0x013F,
  25425. Ldotaccent: 0x013F,
  25426. Ldotbelow: 0x1E36,
  25427. Ldotbelowmacron: 0x1E38,
  25428. Liwnarmenian: 0x053C,
  25429. Lj: 0x01C8,
  25430. Ljecyrillic: 0x0409,
  25431. Llinebelow: 0x1E3A,
  25432. Lmonospace: 0xFF2C,
  25433. Lslash: 0x0141,
  25434. Lslashsmall: 0xF6F9,
  25435. Lsmall: 0xF76C,
  25436. M: 0x004D,
  25437. MBsquare: 0x3386,
  25438. Macron: 0xF6D0,
  25439. Macronsmall: 0xF7AF,
  25440. Macute: 0x1E3E,
  25441. Mcircle: 0x24C2,
  25442. Mdotaccent: 0x1E40,
  25443. Mdotbelow: 0x1E42,
  25444. Menarmenian: 0x0544,
  25445. Mmonospace: 0xFF2D,
  25446. Msmall: 0xF76D,
  25447. Mturned: 0x019C,
  25448. Mu: 0x039C,
  25449. N: 0x004E,
  25450. NJ: 0x01CA,
  25451. Nacute: 0x0143,
  25452. Ncaron: 0x0147,
  25453. Ncedilla: 0x0145,
  25454. Ncircle: 0x24C3,
  25455. Ncircumflexbelow: 0x1E4A,
  25456. Ncommaaccent: 0x0145,
  25457. Ndotaccent: 0x1E44,
  25458. Ndotbelow: 0x1E46,
  25459. Nhookleft: 0x019D,
  25460. Nineroman: 0x2168,
  25461. Nj: 0x01CB,
  25462. Njecyrillic: 0x040A,
  25463. Nlinebelow: 0x1E48,
  25464. Nmonospace: 0xFF2E,
  25465. Nowarmenian: 0x0546,
  25466. Nsmall: 0xF76E,
  25467. Ntilde: 0x00D1,
  25468. Ntildesmall: 0xF7F1,
  25469. Nu: 0x039D,
  25470. O: 0x004F,
  25471. OE: 0x0152,
  25472. OEsmall: 0xF6FA,
  25473. Oacute: 0x00D3,
  25474. Oacutesmall: 0xF7F3,
  25475. Obarredcyrillic: 0x04E8,
  25476. Obarreddieresiscyrillic: 0x04EA,
  25477. Obreve: 0x014E,
  25478. Ocaron: 0x01D1,
  25479. Ocenteredtilde: 0x019F,
  25480. Ocircle: 0x24C4,
  25481. Ocircumflex: 0x00D4,
  25482. Ocircumflexacute: 0x1ED0,
  25483. Ocircumflexdotbelow: 0x1ED8,
  25484. Ocircumflexgrave: 0x1ED2,
  25485. Ocircumflexhookabove: 0x1ED4,
  25486. Ocircumflexsmall: 0xF7F4,
  25487. Ocircumflextilde: 0x1ED6,
  25488. Ocyrillic: 0x041E,
  25489. Odblacute: 0x0150,
  25490. Odblgrave: 0x020C,
  25491. Odieresis: 0x00D6,
  25492. Odieresiscyrillic: 0x04E6,
  25493. Odieresissmall: 0xF7F6,
  25494. Odotbelow: 0x1ECC,
  25495. Ogoneksmall: 0xF6FB,
  25496. Ograve: 0x00D2,
  25497. Ogravesmall: 0xF7F2,
  25498. Oharmenian: 0x0555,
  25499. Ohm: 0x2126,
  25500. Ohookabove: 0x1ECE,
  25501. Ohorn: 0x01A0,
  25502. Ohornacute: 0x1EDA,
  25503. Ohorndotbelow: 0x1EE2,
  25504. Ohorngrave: 0x1EDC,
  25505. Ohornhookabove: 0x1EDE,
  25506. Ohorntilde: 0x1EE0,
  25507. Ohungarumlaut: 0x0150,
  25508. Oi: 0x01A2,
  25509. Oinvertedbreve: 0x020E,
  25510. Omacron: 0x014C,
  25511. Omacronacute: 0x1E52,
  25512. Omacrongrave: 0x1E50,
  25513. Omega: 0x2126,
  25514. Omegacyrillic: 0x0460,
  25515. Omegagreek: 0x03A9,
  25516. Omegaroundcyrillic: 0x047A,
  25517. Omegatitlocyrillic: 0x047C,
  25518. Omegatonos: 0x038F,
  25519. Omicron: 0x039F,
  25520. Omicrontonos: 0x038C,
  25521. Omonospace: 0xFF2F,
  25522. Oneroman: 0x2160,
  25523. Oogonek: 0x01EA,
  25524. Oogonekmacron: 0x01EC,
  25525. Oopen: 0x0186,
  25526. Oslash: 0x00D8,
  25527. Oslashacute: 0x01FE,
  25528. Oslashsmall: 0xF7F8,
  25529. Osmall: 0xF76F,
  25530. Ostrokeacute: 0x01FE,
  25531. Otcyrillic: 0x047E,
  25532. Otilde: 0x00D5,
  25533. Otildeacute: 0x1E4C,
  25534. Otildedieresis: 0x1E4E,
  25535. Otildesmall: 0xF7F5,
  25536. P: 0x0050,
  25537. Pacute: 0x1E54,
  25538. Pcircle: 0x24C5,
  25539. Pdotaccent: 0x1E56,
  25540. Pecyrillic: 0x041F,
  25541. Peharmenian: 0x054A,
  25542. Pemiddlehookcyrillic: 0x04A6,
  25543. Phi: 0x03A6,
  25544. Phook: 0x01A4,
  25545. Pi: 0x03A0,
  25546. Piwrarmenian: 0x0553,
  25547. Pmonospace: 0xFF30,
  25548. Psi: 0x03A8,
  25549. Psicyrillic: 0x0470,
  25550. Psmall: 0xF770,
  25551. Q: 0x0051,
  25552. Qcircle: 0x24C6,
  25553. Qmonospace: 0xFF31,
  25554. Qsmall: 0xF771,
  25555. R: 0x0052,
  25556. Raarmenian: 0x054C,
  25557. Racute: 0x0154,
  25558. Rcaron: 0x0158,
  25559. Rcedilla: 0x0156,
  25560. Rcircle: 0x24C7,
  25561. Rcommaaccent: 0x0156,
  25562. Rdblgrave: 0x0210,
  25563. Rdotaccent: 0x1E58,
  25564. Rdotbelow: 0x1E5A,
  25565. Rdotbelowmacron: 0x1E5C,
  25566. Reharmenian: 0x0550,
  25567. Rfraktur: 0x211C,
  25568. Rho: 0x03A1,
  25569. Ringsmall: 0xF6FC,
  25570. Rinvertedbreve: 0x0212,
  25571. Rlinebelow: 0x1E5E,
  25572. Rmonospace: 0xFF32,
  25573. Rsmall: 0xF772,
  25574. Rsmallinverted: 0x0281,
  25575. Rsmallinvertedsuperior: 0x02B6,
  25576. S: 0x0053,
  25577. SF010000: 0x250C,
  25578. SF020000: 0x2514,
  25579. SF030000: 0x2510,
  25580. SF040000: 0x2518,
  25581. SF050000: 0x253C,
  25582. SF060000: 0x252C,
  25583. SF070000: 0x2534,
  25584. SF080000: 0x251C,
  25585. SF090000: 0x2524,
  25586. SF100000: 0x2500,
  25587. SF110000: 0x2502,
  25588. SF190000: 0x2561,
  25589. SF200000: 0x2562,
  25590. SF210000: 0x2556,
  25591. SF220000: 0x2555,
  25592. SF230000: 0x2563,
  25593. SF240000: 0x2551,
  25594. SF250000: 0x2557,
  25595. SF260000: 0x255D,
  25596. SF270000: 0x255C,
  25597. SF280000: 0x255B,
  25598. SF360000: 0x255E,
  25599. SF370000: 0x255F,
  25600. SF380000: 0x255A,
  25601. SF390000: 0x2554,
  25602. SF400000: 0x2569,
  25603. SF410000: 0x2566,
  25604. SF420000: 0x2560,
  25605. SF430000: 0x2550,
  25606. SF440000: 0x256C,
  25607. SF450000: 0x2567,
  25608. SF460000: 0x2568,
  25609. SF470000: 0x2564,
  25610. SF480000: 0x2565,
  25611. SF490000: 0x2559,
  25612. SF500000: 0x2558,
  25613. SF510000: 0x2552,
  25614. SF520000: 0x2553,
  25615. SF530000: 0x256B,
  25616. SF540000: 0x256A,
  25617. Sacute: 0x015A,
  25618. Sacutedotaccent: 0x1E64,
  25619. Sampigreek: 0x03E0,
  25620. Scaron: 0x0160,
  25621. Scarondotaccent: 0x1E66,
  25622. Scaronsmall: 0xF6FD,
  25623. Scedilla: 0x015E,
  25624. Schwa: 0x018F,
  25625. Schwacyrillic: 0x04D8,
  25626. Schwadieresiscyrillic: 0x04DA,
  25627. Scircle: 0x24C8,
  25628. Scircumflex: 0x015C,
  25629. Scommaaccent: 0x0218,
  25630. Sdotaccent: 0x1E60,
  25631. Sdotbelow: 0x1E62,
  25632. Sdotbelowdotaccent: 0x1E68,
  25633. Seharmenian: 0x054D,
  25634. Sevenroman: 0x2166,
  25635. Shaarmenian: 0x0547,
  25636. Shacyrillic: 0x0428,
  25637. Shchacyrillic: 0x0429,
  25638. Sheicoptic: 0x03E2,
  25639. Shhacyrillic: 0x04BA,
  25640. Shimacoptic: 0x03EC,
  25641. Sigma: 0x03A3,
  25642. Sixroman: 0x2165,
  25643. Smonospace: 0xFF33,
  25644. Softsigncyrillic: 0x042C,
  25645. Ssmall: 0xF773,
  25646. Stigmagreek: 0x03DA,
  25647. T: 0x0054,
  25648. Tau: 0x03A4,
  25649. Tbar: 0x0166,
  25650. Tcaron: 0x0164,
  25651. Tcedilla: 0x0162,
  25652. Tcircle: 0x24C9,
  25653. Tcircumflexbelow: 0x1E70,
  25654. Tcommaaccent: 0x0162,
  25655. Tdotaccent: 0x1E6A,
  25656. Tdotbelow: 0x1E6C,
  25657. Tecyrillic: 0x0422,
  25658. Tedescendercyrillic: 0x04AC,
  25659. Tenroman: 0x2169,
  25660. Tetsecyrillic: 0x04B4,
  25661. Theta: 0x0398,
  25662. Thook: 0x01AC,
  25663. Thorn: 0x00DE,
  25664. Thornsmall: 0xF7FE,
  25665. Threeroman: 0x2162,
  25666. Tildesmall: 0xF6FE,
  25667. Tiwnarmenian: 0x054F,
  25668. Tlinebelow: 0x1E6E,
  25669. Tmonospace: 0xFF34,
  25670. Toarmenian: 0x0539,
  25671. Tonefive: 0x01BC,
  25672. Tonesix: 0x0184,
  25673. Tonetwo: 0x01A7,
  25674. Tretroflexhook: 0x01AE,
  25675. Tsecyrillic: 0x0426,
  25676. Tshecyrillic: 0x040B,
  25677. Tsmall: 0xF774,
  25678. Twelveroman: 0x216B,
  25679. Tworoman: 0x2161,
  25680. U: 0x0055,
  25681. Uacute: 0x00DA,
  25682. Uacutesmall: 0xF7FA,
  25683. Ubreve: 0x016C,
  25684. Ucaron: 0x01D3,
  25685. Ucircle: 0x24CA,
  25686. Ucircumflex: 0x00DB,
  25687. Ucircumflexbelow: 0x1E76,
  25688. Ucircumflexsmall: 0xF7FB,
  25689. Ucyrillic: 0x0423,
  25690. Udblacute: 0x0170,
  25691. Udblgrave: 0x0214,
  25692. Udieresis: 0x00DC,
  25693. Udieresisacute: 0x01D7,
  25694. Udieresisbelow: 0x1E72,
  25695. Udieresiscaron: 0x01D9,
  25696. Udieresiscyrillic: 0x04F0,
  25697. Udieresisgrave: 0x01DB,
  25698. Udieresismacron: 0x01D5,
  25699. Udieresissmall: 0xF7FC,
  25700. Udotbelow: 0x1EE4,
  25701. Ugrave: 0x00D9,
  25702. Ugravesmall: 0xF7F9,
  25703. Uhookabove: 0x1EE6,
  25704. Uhorn: 0x01AF,
  25705. Uhornacute: 0x1EE8,
  25706. Uhorndotbelow: 0x1EF0,
  25707. Uhorngrave: 0x1EEA,
  25708. Uhornhookabove: 0x1EEC,
  25709. Uhorntilde: 0x1EEE,
  25710. Uhungarumlaut: 0x0170,
  25711. Uhungarumlautcyrillic: 0x04F2,
  25712. Uinvertedbreve: 0x0216,
  25713. Ukcyrillic: 0x0478,
  25714. Umacron: 0x016A,
  25715. Umacroncyrillic: 0x04EE,
  25716. Umacrondieresis: 0x1E7A,
  25717. Umonospace: 0xFF35,
  25718. Uogonek: 0x0172,
  25719. Upsilon: 0x03A5,
  25720. Upsilon1: 0x03D2,
  25721. Upsilonacutehooksymbolgreek: 0x03D3,
  25722. Upsilonafrican: 0x01B1,
  25723. Upsilondieresis: 0x03AB,
  25724. Upsilondieresishooksymbolgreek: 0x03D4,
  25725. Upsilonhooksymbol: 0x03D2,
  25726. Upsilontonos: 0x038E,
  25727. Uring: 0x016E,
  25728. Ushortcyrillic: 0x040E,
  25729. Usmall: 0xF775,
  25730. Ustraightcyrillic: 0x04AE,
  25731. Ustraightstrokecyrillic: 0x04B0,
  25732. Utilde: 0x0168,
  25733. Utildeacute: 0x1E78,
  25734. Utildebelow: 0x1E74,
  25735. V: 0x0056,
  25736. Vcircle: 0x24CB,
  25737. Vdotbelow: 0x1E7E,
  25738. Vecyrillic: 0x0412,
  25739. Vewarmenian: 0x054E,
  25740. Vhook: 0x01B2,
  25741. Vmonospace: 0xFF36,
  25742. Voarmenian: 0x0548,
  25743. Vsmall: 0xF776,
  25744. Vtilde: 0x1E7C,
  25745. W: 0x0057,
  25746. Wacute: 0x1E82,
  25747. Wcircle: 0x24CC,
  25748. Wcircumflex: 0x0174,
  25749. Wdieresis: 0x1E84,
  25750. Wdotaccent: 0x1E86,
  25751. Wdotbelow: 0x1E88,
  25752. Wgrave: 0x1E80,
  25753. Wmonospace: 0xFF37,
  25754. Wsmall: 0xF777,
  25755. X: 0x0058,
  25756. Xcircle: 0x24CD,
  25757. Xdieresis: 0x1E8C,
  25758. Xdotaccent: 0x1E8A,
  25759. Xeharmenian: 0x053D,
  25760. Xi: 0x039E,
  25761. Xmonospace: 0xFF38,
  25762. Xsmall: 0xF778,
  25763. Y: 0x0059,
  25764. Yacute: 0x00DD,
  25765. Yacutesmall: 0xF7FD,
  25766. Yatcyrillic: 0x0462,
  25767. Ycircle: 0x24CE,
  25768. Ycircumflex: 0x0176,
  25769. Ydieresis: 0x0178,
  25770. Ydieresissmall: 0xF7FF,
  25771. Ydotaccent: 0x1E8E,
  25772. Ydotbelow: 0x1EF4,
  25773. Yericyrillic: 0x042B,
  25774. Yerudieresiscyrillic: 0x04F8,
  25775. Ygrave: 0x1EF2,
  25776. Yhook: 0x01B3,
  25777. Yhookabove: 0x1EF6,
  25778. Yiarmenian: 0x0545,
  25779. Yicyrillic: 0x0407,
  25780. Yiwnarmenian: 0x0552,
  25781. Ymonospace: 0xFF39,
  25782. Ysmall: 0xF779,
  25783. Ytilde: 0x1EF8,
  25784. Yusbigcyrillic: 0x046A,
  25785. Yusbigiotifiedcyrillic: 0x046C,
  25786. Yuslittlecyrillic: 0x0466,
  25787. Yuslittleiotifiedcyrillic: 0x0468,
  25788. Z: 0x005A,
  25789. Zaarmenian: 0x0536,
  25790. Zacute: 0x0179,
  25791. Zcaron: 0x017D,
  25792. Zcaronsmall: 0xF6FF,
  25793. Zcircle: 0x24CF,
  25794. Zcircumflex: 0x1E90,
  25795. Zdot: 0x017B,
  25796. Zdotaccent: 0x017B,
  25797. Zdotbelow: 0x1E92,
  25798. Zecyrillic: 0x0417,
  25799. Zedescendercyrillic: 0x0498,
  25800. Zedieresiscyrillic: 0x04DE,
  25801. Zeta: 0x0396,
  25802. Zhearmenian: 0x053A,
  25803. Zhebrevecyrillic: 0x04C1,
  25804. Zhecyrillic: 0x0416,
  25805. Zhedescendercyrillic: 0x0496,
  25806. Zhedieresiscyrillic: 0x04DC,
  25807. Zlinebelow: 0x1E94,
  25808. Zmonospace: 0xFF3A,
  25809. Zsmall: 0xF77A,
  25810. Zstroke: 0x01B5,
  25811. a: 0x0061,
  25812. aabengali: 0x0986,
  25813. aacute: 0x00E1,
  25814. aadeva: 0x0906,
  25815. aagujarati: 0x0A86,
  25816. aagurmukhi: 0x0A06,
  25817. aamatragurmukhi: 0x0A3E,
  25818. aarusquare: 0x3303,
  25819. aavowelsignbengali: 0x09BE,
  25820. aavowelsigndeva: 0x093E,
  25821. aavowelsigngujarati: 0x0ABE,
  25822. abbreviationmarkarmenian: 0x055F,
  25823. abbreviationsigndeva: 0x0970,
  25824. abengali: 0x0985,
  25825. abopomofo: 0x311A,
  25826. abreve: 0x0103,
  25827. abreveacute: 0x1EAF,
  25828. abrevecyrillic: 0x04D1,
  25829. abrevedotbelow: 0x1EB7,
  25830. abrevegrave: 0x1EB1,
  25831. abrevehookabove: 0x1EB3,
  25832. abrevetilde: 0x1EB5,
  25833. acaron: 0x01CE,
  25834. acircle: 0x24D0,
  25835. acircumflex: 0x00E2,
  25836. acircumflexacute: 0x1EA5,
  25837. acircumflexdotbelow: 0x1EAD,
  25838. acircumflexgrave: 0x1EA7,
  25839. acircumflexhookabove: 0x1EA9,
  25840. acircumflextilde: 0x1EAB,
  25841. acute: 0x00B4,
  25842. acutebelowcmb: 0x0317,
  25843. acutecmb: 0x0301,
  25844. acutecomb: 0x0301,
  25845. acutedeva: 0x0954,
  25846. acutelowmod: 0x02CF,
  25847. acutetonecmb: 0x0341,
  25848. acyrillic: 0x0430,
  25849. adblgrave: 0x0201,
  25850. addakgurmukhi: 0x0A71,
  25851. adeva: 0x0905,
  25852. adieresis: 0x00E4,
  25853. adieresiscyrillic: 0x04D3,
  25854. adieresismacron: 0x01DF,
  25855. adotbelow: 0x1EA1,
  25856. adotmacron: 0x01E1,
  25857. ae: 0x00E6,
  25858. aeacute: 0x01FD,
  25859. aekorean: 0x3150,
  25860. aemacron: 0x01E3,
  25861. afii00208: 0x2015,
  25862. afii08941: 0x20A4,
  25863. afii10017: 0x0410,
  25864. afii10018: 0x0411,
  25865. afii10019: 0x0412,
  25866. afii10020: 0x0413,
  25867. afii10021: 0x0414,
  25868. afii10022: 0x0415,
  25869. afii10023: 0x0401,
  25870. afii10024: 0x0416,
  25871. afii10025: 0x0417,
  25872. afii10026: 0x0418,
  25873. afii10027: 0x0419,
  25874. afii10028: 0x041A,
  25875. afii10029: 0x041B,
  25876. afii10030: 0x041C,
  25877. afii10031: 0x041D,
  25878. afii10032: 0x041E,
  25879. afii10033: 0x041F,
  25880. afii10034: 0x0420,
  25881. afii10035: 0x0421,
  25882. afii10036: 0x0422,
  25883. afii10037: 0x0423,
  25884. afii10038: 0x0424,
  25885. afii10039: 0x0425,
  25886. afii10040: 0x0426,
  25887. afii10041: 0x0427,
  25888. afii10042: 0x0428,
  25889. afii10043: 0x0429,
  25890. afii10044: 0x042A,
  25891. afii10045: 0x042B,
  25892. afii10046: 0x042C,
  25893. afii10047: 0x042D,
  25894. afii10048: 0x042E,
  25895. afii10049: 0x042F,
  25896. afii10050: 0x0490,
  25897. afii10051: 0x0402,
  25898. afii10052: 0x0403,
  25899. afii10053: 0x0404,
  25900. afii10054: 0x0405,
  25901. afii10055: 0x0406,
  25902. afii10056: 0x0407,
  25903. afii10057: 0x0408,
  25904. afii10058: 0x0409,
  25905. afii10059: 0x040A,
  25906. afii10060: 0x040B,
  25907. afii10061: 0x040C,
  25908. afii10062: 0x040E,
  25909. afii10063: 0xF6C4,
  25910. afii10064: 0xF6C5,
  25911. afii10065: 0x0430,
  25912. afii10066: 0x0431,
  25913. afii10067: 0x0432,
  25914. afii10068: 0x0433,
  25915. afii10069: 0x0434,
  25916. afii10070: 0x0435,
  25917. afii10071: 0x0451,
  25918. afii10072: 0x0436,
  25919. afii10073: 0x0437,
  25920. afii10074: 0x0438,
  25921. afii10075: 0x0439,
  25922. afii10076: 0x043A,
  25923. afii10077: 0x043B,
  25924. afii10078: 0x043C,
  25925. afii10079: 0x043D,
  25926. afii10080: 0x043E,
  25927. afii10081: 0x043F,
  25928. afii10082: 0x0440,
  25929. afii10083: 0x0441,
  25930. afii10084: 0x0442,
  25931. afii10085: 0x0443,
  25932. afii10086: 0x0444,
  25933. afii10087: 0x0445,
  25934. afii10088: 0x0446,
  25935. afii10089: 0x0447,
  25936. afii10090: 0x0448,
  25937. afii10091: 0x0449,
  25938. afii10092: 0x044A,
  25939. afii10093: 0x044B,
  25940. afii10094: 0x044C,
  25941. afii10095: 0x044D,
  25942. afii10096: 0x044E,
  25943. afii10097: 0x044F,
  25944. afii10098: 0x0491,
  25945. afii10099: 0x0452,
  25946. afii10100: 0x0453,
  25947. afii10101: 0x0454,
  25948. afii10102: 0x0455,
  25949. afii10103: 0x0456,
  25950. afii10104: 0x0457,
  25951. afii10105: 0x0458,
  25952. afii10106: 0x0459,
  25953. afii10107: 0x045A,
  25954. afii10108: 0x045B,
  25955. afii10109: 0x045C,
  25956. afii10110: 0x045E,
  25957. afii10145: 0x040F,
  25958. afii10146: 0x0462,
  25959. afii10147: 0x0472,
  25960. afii10148: 0x0474,
  25961. afii10192: 0xF6C6,
  25962. afii10193: 0x045F,
  25963. afii10194: 0x0463,
  25964. afii10195: 0x0473,
  25965. afii10196: 0x0475,
  25966. afii10831: 0xF6C7,
  25967. afii10832: 0xF6C8,
  25968. afii10846: 0x04D9,
  25969. afii299: 0x200E,
  25970. afii300: 0x200F,
  25971. afii301: 0x200D,
  25972. afii57381: 0x066A,
  25973. afii57388: 0x060C,
  25974. afii57392: 0x0660,
  25975. afii57393: 0x0661,
  25976. afii57394: 0x0662,
  25977. afii57395: 0x0663,
  25978. afii57396: 0x0664,
  25979. afii57397: 0x0665,
  25980. afii57398: 0x0666,
  25981. afii57399: 0x0667,
  25982. afii57400: 0x0668,
  25983. afii57401: 0x0669,
  25984. afii57403: 0x061B,
  25985. afii57407: 0x061F,
  25986. afii57409: 0x0621,
  25987. afii57410: 0x0622,
  25988. afii57411: 0x0623,
  25989. afii57412: 0x0624,
  25990. afii57413: 0x0625,
  25991. afii57414: 0x0626,
  25992. afii57415: 0x0627,
  25993. afii57416: 0x0628,
  25994. afii57417: 0x0629,
  25995. afii57418: 0x062A,
  25996. afii57419: 0x062B,
  25997. afii57420: 0x062C,
  25998. afii57421: 0x062D,
  25999. afii57422: 0x062E,
  26000. afii57423: 0x062F,
  26001. afii57424: 0x0630,
  26002. afii57425: 0x0631,
  26003. afii57426: 0x0632,
  26004. afii57427: 0x0633,
  26005. afii57428: 0x0634,
  26006. afii57429: 0x0635,
  26007. afii57430: 0x0636,
  26008. afii57431: 0x0637,
  26009. afii57432: 0x0638,
  26010. afii57433: 0x0639,
  26011. afii57434: 0x063A,
  26012. afii57440: 0x0640,
  26013. afii57441: 0x0641,
  26014. afii57442: 0x0642,
  26015. afii57443: 0x0643,
  26016. afii57444: 0x0644,
  26017. afii57445: 0x0645,
  26018. afii57446: 0x0646,
  26019. afii57448: 0x0648,
  26020. afii57449: 0x0649,
  26021. afii57450: 0x064A,
  26022. afii57451: 0x064B,
  26023. afii57452: 0x064C,
  26024. afii57453: 0x064D,
  26025. afii57454: 0x064E,
  26026. afii57455: 0x064F,
  26027. afii57456: 0x0650,
  26028. afii57457: 0x0651,
  26029. afii57458: 0x0652,
  26030. afii57470: 0x0647,
  26031. afii57505: 0x06A4,
  26032. afii57506: 0x067E,
  26033. afii57507: 0x0686,
  26034. afii57508: 0x0698,
  26035. afii57509: 0x06AF,
  26036. afii57511: 0x0679,
  26037. afii57512: 0x0688,
  26038. afii57513: 0x0691,
  26039. afii57514: 0x06BA,
  26040. afii57519: 0x06D2,
  26041. afii57534: 0x06D5,
  26042. afii57636: 0x20AA,
  26043. afii57645: 0x05BE,
  26044. afii57658: 0x05C3,
  26045. afii57664: 0x05D0,
  26046. afii57665: 0x05D1,
  26047. afii57666: 0x05D2,
  26048. afii57667: 0x05D3,
  26049. afii57668: 0x05D4,
  26050. afii57669: 0x05D5,
  26051. afii57670: 0x05D6,
  26052. afii57671: 0x05D7,
  26053. afii57672: 0x05D8,
  26054. afii57673: 0x05D9,
  26055. afii57674: 0x05DA,
  26056. afii57675: 0x05DB,
  26057. afii57676: 0x05DC,
  26058. afii57677: 0x05DD,
  26059. afii57678: 0x05DE,
  26060. afii57679: 0x05DF,
  26061. afii57680: 0x05E0,
  26062. afii57681: 0x05E1,
  26063. afii57682: 0x05E2,
  26064. afii57683: 0x05E3,
  26065. afii57684: 0x05E4,
  26066. afii57685: 0x05E5,
  26067. afii57686: 0x05E6,
  26068. afii57687: 0x05E7,
  26069. afii57688: 0x05E8,
  26070. afii57689: 0x05E9,
  26071. afii57690: 0x05EA,
  26072. afii57694: 0xFB2A,
  26073. afii57695: 0xFB2B,
  26074. afii57700: 0xFB4B,
  26075. afii57705: 0xFB1F,
  26076. afii57716: 0x05F0,
  26077. afii57717: 0x05F1,
  26078. afii57718: 0x05F2,
  26079. afii57723: 0xFB35,
  26080. afii57793: 0x05B4,
  26081. afii57794: 0x05B5,
  26082. afii57795: 0x05B6,
  26083. afii57796: 0x05BB,
  26084. afii57797: 0x05B8,
  26085. afii57798: 0x05B7,
  26086. afii57799: 0x05B0,
  26087. afii57800: 0x05B2,
  26088. afii57801: 0x05B1,
  26089. afii57802: 0x05B3,
  26090. afii57803: 0x05C2,
  26091. afii57804: 0x05C1,
  26092. afii57806: 0x05B9,
  26093. afii57807: 0x05BC,
  26094. afii57839: 0x05BD,
  26095. afii57841: 0x05BF,
  26096. afii57842: 0x05C0,
  26097. afii57929: 0x02BC,
  26098. afii61248: 0x2105,
  26099. afii61289: 0x2113,
  26100. afii61352: 0x2116,
  26101. afii61573: 0x202C,
  26102. afii61574: 0x202D,
  26103. afii61575: 0x202E,
  26104. afii61664: 0x200C,
  26105. afii63167: 0x066D,
  26106. afii64937: 0x02BD,
  26107. agrave: 0x00E0,
  26108. agujarati: 0x0A85,
  26109. agurmukhi: 0x0A05,
  26110. ahiragana: 0x3042,
  26111. ahookabove: 0x1EA3,
  26112. aibengali: 0x0990,
  26113. aibopomofo: 0x311E,
  26114. aideva: 0x0910,
  26115. aiecyrillic: 0x04D5,
  26116. aigujarati: 0x0A90,
  26117. aigurmukhi: 0x0A10,
  26118. aimatragurmukhi: 0x0A48,
  26119. ainarabic: 0x0639,
  26120. ainfinalarabic: 0xFECA,
  26121. aininitialarabic: 0xFECB,
  26122. ainmedialarabic: 0xFECC,
  26123. ainvertedbreve: 0x0203,
  26124. aivowelsignbengali: 0x09C8,
  26125. aivowelsigndeva: 0x0948,
  26126. aivowelsigngujarati: 0x0AC8,
  26127. akatakana: 0x30A2,
  26128. akatakanahalfwidth: 0xFF71,
  26129. akorean: 0x314F,
  26130. alef: 0x05D0,
  26131. alefarabic: 0x0627,
  26132. alefdageshhebrew: 0xFB30,
  26133. aleffinalarabic: 0xFE8E,
  26134. alefhamzaabovearabic: 0x0623,
  26135. alefhamzaabovefinalarabic: 0xFE84,
  26136. alefhamzabelowarabic: 0x0625,
  26137. alefhamzabelowfinalarabic: 0xFE88,
  26138. alefhebrew: 0x05D0,
  26139. aleflamedhebrew: 0xFB4F,
  26140. alefmaddaabovearabic: 0x0622,
  26141. alefmaddaabovefinalarabic: 0xFE82,
  26142. alefmaksuraarabic: 0x0649,
  26143. alefmaksurafinalarabic: 0xFEF0,
  26144. alefmaksurainitialarabic: 0xFEF3,
  26145. alefmaksuramedialarabic: 0xFEF4,
  26146. alefpatahhebrew: 0xFB2E,
  26147. alefqamatshebrew: 0xFB2F,
  26148. aleph: 0x2135,
  26149. allequal: 0x224C,
  26150. alpha: 0x03B1,
  26151. alphatonos: 0x03AC,
  26152. amacron: 0x0101,
  26153. amonospace: 0xFF41,
  26154. ampersand: 0x0026,
  26155. ampersandmonospace: 0xFF06,
  26156. ampersandsmall: 0xF726,
  26157. amsquare: 0x33C2,
  26158. anbopomofo: 0x3122,
  26159. angbopomofo: 0x3124,
  26160. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  26161. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  26162. angkhankhuthai: 0x0E5A,
  26163. angle: 0x2220,
  26164. anglebracketleft: 0x3008,
  26165. anglebracketleftvertical: 0xFE3F,
  26166. anglebracketright: 0x3009,
  26167. anglebracketrightvertical: 0xFE40,
  26168. angleleft: 0x2329,
  26169. angleright: 0x232A,
  26170. angstrom: 0x212B,
  26171. anoteleia: 0x0387,
  26172. anudattadeva: 0x0952,
  26173. anusvarabengali: 0x0982,
  26174. anusvaradeva: 0x0902,
  26175. anusvaragujarati: 0x0A82,
  26176. aogonek: 0x0105,
  26177. apaatosquare: 0x3300,
  26178. aparen: 0x249C,
  26179. apostrophearmenian: 0x055A,
  26180. apostrophemod: 0x02BC,
  26181. apple: 0xF8FF,
  26182. approaches: 0x2250,
  26183. approxequal: 0x2248,
  26184. approxequalorimage: 0x2252,
  26185. approximatelyequal: 0x2245,
  26186. araeaekorean: 0x318E,
  26187. araeakorean: 0x318D,
  26188. arc: 0x2312,
  26189. arighthalfring: 0x1E9A,
  26190. aring: 0x00E5,
  26191. aringacute: 0x01FB,
  26192. aringbelow: 0x1E01,
  26193. arrowboth: 0x2194,
  26194. arrowdashdown: 0x21E3,
  26195. arrowdashleft: 0x21E0,
  26196. arrowdashright: 0x21E2,
  26197. arrowdashup: 0x21E1,
  26198. arrowdblboth: 0x21D4,
  26199. arrowdbldown: 0x21D3,
  26200. arrowdblleft: 0x21D0,
  26201. arrowdblright: 0x21D2,
  26202. arrowdblup: 0x21D1,
  26203. arrowdown: 0x2193,
  26204. arrowdownleft: 0x2199,
  26205. arrowdownright: 0x2198,
  26206. arrowdownwhite: 0x21E9,
  26207. arrowheaddownmod: 0x02C5,
  26208. arrowheadleftmod: 0x02C2,
  26209. arrowheadrightmod: 0x02C3,
  26210. arrowheadupmod: 0x02C4,
  26211. arrowhorizex: 0xF8E7,
  26212. arrowleft: 0x2190,
  26213. arrowleftdbl: 0x21D0,
  26214. arrowleftdblstroke: 0x21CD,
  26215. arrowleftoverright: 0x21C6,
  26216. arrowleftwhite: 0x21E6,
  26217. arrowright: 0x2192,
  26218. arrowrightdblstroke: 0x21CF,
  26219. arrowrightheavy: 0x279E,
  26220. arrowrightoverleft: 0x21C4,
  26221. arrowrightwhite: 0x21E8,
  26222. arrowtableft: 0x21E4,
  26223. arrowtabright: 0x21E5,
  26224. arrowup: 0x2191,
  26225. arrowupdn: 0x2195,
  26226. arrowupdnbse: 0x21A8,
  26227. arrowupdownbase: 0x21A8,
  26228. arrowupleft: 0x2196,
  26229. arrowupleftofdown: 0x21C5,
  26230. arrowupright: 0x2197,
  26231. arrowupwhite: 0x21E7,
  26232. arrowvertex: 0xF8E6,
  26233. asciicircum: 0x005E,
  26234. asciicircummonospace: 0xFF3E,
  26235. asciitilde: 0x007E,
  26236. asciitildemonospace: 0xFF5E,
  26237. ascript: 0x0251,
  26238. ascriptturned: 0x0252,
  26239. asmallhiragana: 0x3041,
  26240. asmallkatakana: 0x30A1,
  26241. asmallkatakanahalfwidth: 0xFF67,
  26242. asterisk: 0x002A,
  26243. asteriskaltonearabic: 0x066D,
  26244. asteriskarabic: 0x066D,
  26245. asteriskmath: 0x2217,
  26246. asteriskmonospace: 0xFF0A,
  26247. asterisksmall: 0xFE61,
  26248. asterism: 0x2042,
  26249. asuperior: 0xF6E9,
  26250. asymptoticallyequal: 0x2243,
  26251. at: 0x0040,
  26252. atilde: 0x00E3,
  26253. atmonospace: 0xFF20,
  26254. atsmall: 0xFE6B,
  26255. aturned: 0x0250,
  26256. aubengali: 0x0994,
  26257. aubopomofo: 0x3120,
  26258. audeva: 0x0914,
  26259. augujarati: 0x0A94,
  26260. augurmukhi: 0x0A14,
  26261. aulengthmarkbengali: 0x09D7,
  26262. aumatragurmukhi: 0x0A4C,
  26263. auvowelsignbengali: 0x09CC,
  26264. auvowelsigndeva: 0x094C,
  26265. auvowelsigngujarati: 0x0ACC,
  26266. avagrahadeva: 0x093D,
  26267. aybarmenian: 0x0561,
  26268. ayin: 0x05E2,
  26269. ayinaltonehebrew: 0xFB20,
  26270. ayinhebrew: 0x05E2,
  26271. b: 0x0062,
  26272. babengali: 0x09AC,
  26273. backslash: 0x005C,
  26274. backslashmonospace: 0xFF3C,
  26275. badeva: 0x092C,
  26276. bagujarati: 0x0AAC,
  26277. bagurmukhi: 0x0A2C,
  26278. bahiragana: 0x3070,
  26279. bahtthai: 0x0E3F,
  26280. bakatakana: 0x30D0,
  26281. bar: 0x007C,
  26282. barmonospace: 0xFF5C,
  26283. bbopomofo: 0x3105,
  26284. bcircle: 0x24D1,
  26285. bdotaccent: 0x1E03,
  26286. bdotbelow: 0x1E05,
  26287. beamedsixteenthnotes: 0x266C,
  26288. because: 0x2235,
  26289. becyrillic: 0x0431,
  26290. beharabic: 0x0628,
  26291. behfinalarabic: 0xFE90,
  26292. behinitialarabic: 0xFE91,
  26293. behiragana: 0x3079,
  26294. behmedialarabic: 0xFE92,
  26295. behmeeminitialarabic: 0xFC9F,
  26296. behmeemisolatedarabic: 0xFC08,
  26297. behnoonfinalarabic: 0xFC6D,
  26298. bekatakana: 0x30D9,
  26299. benarmenian: 0x0562,
  26300. bet: 0x05D1,
  26301. beta: 0x03B2,
  26302. betasymbolgreek: 0x03D0,
  26303. betdagesh: 0xFB31,
  26304. betdageshhebrew: 0xFB31,
  26305. bethebrew: 0x05D1,
  26306. betrafehebrew: 0xFB4C,
  26307. bhabengali: 0x09AD,
  26308. bhadeva: 0x092D,
  26309. bhagujarati: 0x0AAD,
  26310. bhagurmukhi: 0x0A2D,
  26311. bhook: 0x0253,
  26312. bihiragana: 0x3073,
  26313. bikatakana: 0x30D3,
  26314. bilabialclick: 0x0298,
  26315. bindigurmukhi: 0x0A02,
  26316. birusquare: 0x3331,
  26317. blackcircle: 0x25CF,
  26318. blackdiamond: 0x25C6,
  26319. blackdownpointingtriangle: 0x25BC,
  26320. blackleftpointingpointer: 0x25C4,
  26321. blackleftpointingtriangle: 0x25C0,
  26322. blacklenticularbracketleft: 0x3010,
  26323. blacklenticularbracketleftvertical: 0xFE3B,
  26324. blacklenticularbracketright: 0x3011,
  26325. blacklenticularbracketrightvertical: 0xFE3C,
  26326. blacklowerlefttriangle: 0x25E3,
  26327. blacklowerrighttriangle: 0x25E2,
  26328. blackrectangle: 0x25AC,
  26329. blackrightpointingpointer: 0x25BA,
  26330. blackrightpointingtriangle: 0x25B6,
  26331. blacksmallsquare: 0x25AA,
  26332. blacksmilingface: 0x263B,
  26333. blacksquare: 0x25A0,
  26334. blackstar: 0x2605,
  26335. blackupperlefttriangle: 0x25E4,
  26336. blackupperrighttriangle: 0x25E5,
  26337. blackuppointingsmalltriangle: 0x25B4,
  26338. blackuppointingtriangle: 0x25B2,
  26339. blank: 0x2423,
  26340. blinebelow: 0x1E07,
  26341. block: 0x2588,
  26342. bmonospace: 0xFF42,
  26343. bobaimaithai: 0x0E1A,
  26344. bohiragana: 0x307C,
  26345. bokatakana: 0x30DC,
  26346. bparen: 0x249D,
  26347. bqsquare: 0x33C3,
  26348. braceex: 0xF8F4,
  26349. braceleft: 0x007B,
  26350. braceleftbt: 0xF8F3,
  26351. braceleftmid: 0xF8F2,
  26352. braceleftmonospace: 0xFF5B,
  26353. braceleftsmall: 0xFE5B,
  26354. bracelefttp: 0xF8F1,
  26355. braceleftvertical: 0xFE37,
  26356. braceright: 0x007D,
  26357. bracerightbt: 0xF8FE,
  26358. bracerightmid: 0xF8FD,
  26359. bracerightmonospace: 0xFF5D,
  26360. bracerightsmall: 0xFE5C,
  26361. bracerighttp: 0xF8FC,
  26362. bracerightvertical: 0xFE38,
  26363. bracketleft: 0x005B,
  26364. bracketleftbt: 0xF8F0,
  26365. bracketleftex: 0xF8EF,
  26366. bracketleftmonospace: 0xFF3B,
  26367. bracketlefttp: 0xF8EE,
  26368. bracketright: 0x005D,
  26369. bracketrightbt: 0xF8FB,
  26370. bracketrightex: 0xF8FA,
  26371. bracketrightmonospace: 0xFF3D,
  26372. bracketrighttp: 0xF8F9,
  26373. breve: 0x02D8,
  26374. brevebelowcmb: 0x032E,
  26375. brevecmb: 0x0306,
  26376. breveinvertedbelowcmb: 0x032F,
  26377. breveinvertedcmb: 0x0311,
  26378. breveinverteddoublecmb: 0x0361,
  26379. bridgebelowcmb: 0x032A,
  26380. bridgeinvertedbelowcmb: 0x033A,
  26381. brokenbar: 0x00A6,
  26382. bstroke: 0x0180,
  26383. bsuperior: 0xF6EA,
  26384. btopbar: 0x0183,
  26385. buhiragana: 0x3076,
  26386. bukatakana: 0x30D6,
  26387. bullet: 0x2022,
  26388. bulletinverse: 0x25D8,
  26389. bulletoperator: 0x2219,
  26390. bullseye: 0x25CE,
  26391. c: 0x0063,
  26392. caarmenian: 0x056E,
  26393. cabengali: 0x099A,
  26394. cacute: 0x0107,
  26395. cadeva: 0x091A,
  26396. cagujarati: 0x0A9A,
  26397. cagurmukhi: 0x0A1A,
  26398. calsquare: 0x3388,
  26399. candrabindubengali: 0x0981,
  26400. candrabinducmb: 0x0310,
  26401. candrabindudeva: 0x0901,
  26402. candrabindugujarati: 0x0A81,
  26403. capslock: 0x21EA,
  26404. careof: 0x2105,
  26405. caron: 0x02C7,
  26406. caronbelowcmb: 0x032C,
  26407. caroncmb: 0x030C,
  26408. carriagereturn: 0x21B5,
  26409. cbopomofo: 0x3118,
  26410. ccaron: 0x010D,
  26411. ccedilla: 0x00E7,
  26412. ccedillaacute: 0x1E09,
  26413. ccircle: 0x24D2,
  26414. ccircumflex: 0x0109,
  26415. ccurl: 0x0255,
  26416. cdot: 0x010B,
  26417. cdotaccent: 0x010B,
  26418. cdsquare: 0x33C5,
  26419. cedilla: 0x00B8,
  26420. cedillacmb: 0x0327,
  26421. cent: 0x00A2,
  26422. centigrade: 0x2103,
  26423. centinferior: 0xF6DF,
  26424. centmonospace: 0xFFE0,
  26425. centoldstyle: 0xF7A2,
  26426. centsuperior: 0xF6E0,
  26427. chaarmenian: 0x0579,
  26428. chabengali: 0x099B,
  26429. chadeva: 0x091B,
  26430. chagujarati: 0x0A9B,
  26431. chagurmukhi: 0x0A1B,
  26432. chbopomofo: 0x3114,
  26433. cheabkhasiancyrillic: 0x04BD,
  26434. checkmark: 0x2713,
  26435. checyrillic: 0x0447,
  26436. chedescenderabkhasiancyrillic: 0x04BF,
  26437. chedescendercyrillic: 0x04B7,
  26438. chedieresiscyrillic: 0x04F5,
  26439. cheharmenian: 0x0573,
  26440. chekhakassiancyrillic: 0x04CC,
  26441. cheverticalstrokecyrillic: 0x04B9,
  26442. chi: 0x03C7,
  26443. chieuchacirclekorean: 0x3277,
  26444. chieuchaparenkorean: 0x3217,
  26445. chieuchcirclekorean: 0x3269,
  26446. chieuchkorean: 0x314A,
  26447. chieuchparenkorean: 0x3209,
  26448. chochangthai: 0x0E0A,
  26449. chochanthai: 0x0E08,
  26450. chochingthai: 0x0E09,
  26451. chochoethai: 0x0E0C,
  26452. chook: 0x0188,
  26453. cieucacirclekorean: 0x3276,
  26454. cieucaparenkorean: 0x3216,
  26455. cieuccirclekorean: 0x3268,
  26456. cieuckorean: 0x3148,
  26457. cieucparenkorean: 0x3208,
  26458. cieucuparenkorean: 0x321C,
  26459. circle: 0x25CB,
  26460. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  26461. circlemultiply: 0x2297,
  26462. circleot: 0x2299,
  26463. circleplus: 0x2295,
  26464. circlepostalmark: 0x3036,
  26465. circlewithlefthalfblack: 0x25D0,
  26466. circlewithrighthalfblack: 0x25D1,
  26467. circumflex: 0x02C6,
  26468. circumflexbelowcmb: 0x032D,
  26469. circumflexcmb: 0x0302,
  26470. clear: 0x2327,
  26471. clickalveolar: 0x01C2,
  26472. clickdental: 0x01C0,
  26473. clicklateral: 0x01C1,
  26474. clickretroflex: 0x01C3,
  26475. club: 0x2663,
  26476. clubsuitblack: 0x2663,
  26477. clubsuitwhite: 0x2667,
  26478. cmcubedsquare: 0x33A4,
  26479. cmonospace: 0xFF43,
  26480. cmsquaredsquare: 0x33A0,
  26481. coarmenian: 0x0581,
  26482. colon: 0x003A,
  26483. colonmonetary: 0x20A1,
  26484. colonmonospace: 0xFF1A,
  26485. colonsign: 0x20A1,
  26486. colonsmall: 0xFE55,
  26487. colontriangularhalfmod: 0x02D1,
  26488. colontriangularmod: 0x02D0,
  26489. comma: 0x002C,
  26490. commaabovecmb: 0x0313,
  26491. commaaboverightcmb: 0x0315,
  26492. commaaccent: 0xF6C3,
  26493. commaarabic: 0x060C,
  26494. commaarmenian: 0x055D,
  26495. commainferior: 0xF6E1,
  26496. commamonospace: 0xFF0C,
  26497. commareversedabovecmb: 0x0314,
  26498. commareversedmod: 0x02BD,
  26499. commasmall: 0xFE50,
  26500. commasuperior: 0xF6E2,
  26501. commaturnedabovecmb: 0x0312,
  26502. commaturnedmod: 0x02BB,
  26503. compass: 0x263C,
  26504. congruent: 0x2245,
  26505. contourintegral: 0x222E,
  26506. control: 0x2303,
  26507. controlACK: 0x0006,
  26508. controlBEL: 0x0007,
  26509. controlBS: 0x0008,
  26510. controlCAN: 0x0018,
  26511. controlCR: 0x000D,
  26512. controlDC1: 0x0011,
  26513. controlDC2: 0x0012,
  26514. controlDC3: 0x0013,
  26515. controlDC4: 0x0014,
  26516. controlDEL: 0x007F,
  26517. controlDLE: 0x0010,
  26518. controlEM: 0x0019,
  26519. controlENQ: 0x0005,
  26520. controlEOT: 0x0004,
  26521. controlESC: 0x001B,
  26522. controlETB: 0x0017,
  26523. controlETX: 0x0003,
  26524. controlFF: 0x000C,
  26525. controlFS: 0x001C,
  26526. controlGS: 0x001D,
  26527. controlHT: 0x0009,
  26528. controlLF: 0x000A,
  26529. controlNAK: 0x0015,
  26530. controlRS: 0x001E,
  26531. controlSI: 0x000F,
  26532. controlSO: 0x000E,
  26533. controlSOT: 0x0002,
  26534. controlSTX: 0x0001,
  26535. controlSUB: 0x001A,
  26536. controlSYN: 0x0016,
  26537. controlUS: 0x001F,
  26538. controlVT: 0x000B,
  26539. copyright: 0x00A9,
  26540. copyrightsans: 0xF8E9,
  26541. copyrightserif: 0xF6D9,
  26542. cornerbracketleft: 0x300C,
  26543. cornerbracketlefthalfwidth: 0xFF62,
  26544. cornerbracketleftvertical: 0xFE41,
  26545. cornerbracketright: 0x300D,
  26546. cornerbracketrighthalfwidth: 0xFF63,
  26547. cornerbracketrightvertical: 0xFE42,
  26548. corporationsquare: 0x337F,
  26549. cosquare: 0x33C7,
  26550. coverkgsquare: 0x33C6,
  26551. cparen: 0x249E,
  26552. cruzeiro: 0x20A2,
  26553. cstretched: 0x0297,
  26554. curlyand: 0x22CF,
  26555. curlyor: 0x22CE,
  26556. currency: 0x00A4,
  26557. cyrBreve: 0xF6D1,
  26558. cyrFlex: 0xF6D2,
  26559. cyrbreve: 0xF6D4,
  26560. cyrflex: 0xF6D5,
  26561. d: 0x0064,
  26562. daarmenian: 0x0564,
  26563. dabengali: 0x09A6,
  26564. dadarabic: 0x0636,
  26565. dadeva: 0x0926,
  26566. dadfinalarabic: 0xFEBE,
  26567. dadinitialarabic: 0xFEBF,
  26568. dadmedialarabic: 0xFEC0,
  26569. dagesh: 0x05BC,
  26570. dageshhebrew: 0x05BC,
  26571. dagger: 0x2020,
  26572. daggerdbl: 0x2021,
  26573. dagujarati: 0x0AA6,
  26574. dagurmukhi: 0x0A26,
  26575. dahiragana: 0x3060,
  26576. dakatakana: 0x30C0,
  26577. dalarabic: 0x062F,
  26578. dalet: 0x05D3,
  26579. daletdagesh: 0xFB33,
  26580. daletdageshhebrew: 0xFB33,
  26581. dalethebrew: 0x05D3,
  26582. dalfinalarabic: 0xFEAA,
  26583. dammaarabic: 0x064F,
  26584. dammalowarabic: 0x064F,
  26585. dammatanaltonearabic: 0x064C,
  26586. dammatanarabic: 0x064C,
  26587. danda: 0x0964,
  26588. dargahebrew: 0x05A7,
  26589. dargalefthebrew: 0x05A7,
  26590. dasiapneumatacyrilliccmb: 0x0485,
  26591. dblGrave: 0xF6D3,
  26592. dblanglebracketleft: 0x300A,
  26593. dblanglebracketleftvertical: 0xFE3D,
  26594. dblanglebracketright: 0x300B,
  26595. dblanglebracketrightvertical: 0xFE3E,
  26596. dblarchinvertedbelowcmb: 0x032B,
  26597. dblarrowleft: 0x21D4,
  26598. dblarrowright: 0x21D2,
  26599. dbldanda: 0x0965,
  26600. dblgrave: 0xF6D6,
  26601. dblgravecmb: 0x030F,
  26602. dblintegral: 0x222C,
  26603. dbllowline: 0x2017,
  26604. dbllowlinecmb: 0x0333,
  26605. dbloverlinecmb: 0x033F,
  26606. dblprimemod: 0x02BA,
  26607. dblverticalbar: 0x2016,
  26608. dblverticallineabovecmb: 0x030E,
  26609. dbopomofo: 0x3109,
  26610. dbsquare: 0x33C8,
  26611. dcaron: 0x010F,
  26612. dcedilla: 0x1E11,
  26613. dcircle: 0x24D3,
  26614. dcircumflexbelow: 0x1E13,
  26615. dcroat: 0x0111,
  26616. ddabengali: 0x09A1,
  26617. ddadeva: 0x0921,
  26618. ddagujarati: 0x0AA1,
  26619. ddagurmukhi: 0x0A21,
  26620. ddalarabic: 0x0688,
  26621. ddalfinalarabic: 0xFB89,
  26622. dddhadeva: 0x095C,
  26623. ddhabengali: 0x09A2,
  26624. ddhadeva: 0x0922,
  26625. ddhagujarati: 0x0AA2,
  26626. ddhagurmukhi: 0x0A22,
  26627. ddotaccent: 0x1E0B,
  26628. ddotbelow: 0x1E0D,
  26629. decimalseparatorarabic: 0x066B,
  26630. decimalseparatorpersian: 0x066B,
  26631. decyrillic: 0x0434,
  26632. degree: 0x00B0,
  26633. dehihebrew: 0x05AD,
  26634. dehiragana: 0x3067,
  26635. deicoptic: 0x03EF,
  26636. dekatakana: 0x30C7,
  26637. deleteleft: 0x232B,
  26638. deleteright: 0x2326,
  26639. delta: 0x03B4,
  26640. deltaturned: 0x018D,
  26641. denominatorminusonenumeratorbengali: 0x09F8,
  26642. dezh: 0x02A4,
  26643. dhabengali: 0x09A7,
  26644. dhadeva: 0x0927,
  26645. dhagujarati: 0x0AA7,
  26646. dhagurmukhi: 0x0A27,
  26647. dhook: 0x0257,
  26648. dialytikatonos: 0x0385,
  26649. dialytikatonoscmb: 0x0344,
  26650. diamond: 0x2666,
  26651. diamondsuitwhite: 0x2662,
  26652. dieresis: 0x00A8,
  26653. dieresisacute: 0xF6D7,
  26654. dieresisbelowcmb: 0x0324,
  26655. dieresiscmb: 0x0308,
  26656. dieresisgrave: 0xF6D8,
  26657. dieresistonos: 0x0385,
  26658. dihiragana: 0x3062,
  26659. dikatakana: 0x30C2,
  26660. dittomark: 0x3003,
  26661. divide: 0x00F7,
  26662. divides: 0x2223,
  26663. divisionslash: 0x2215,
  26664. djecyrillic: 0x0452,
  26665. dkshade: 0x2593,
  26666. dlinebelow: 0x1E0F,
  26667. dlsquare: 0x3397,
  26668. dmacron: 0x0111,
  26669. dmonospace: 0xFF44,
  26670. dnblock: 0x2584,
  26671. dochadathai: 0x0E0E,
  26672. dodekthai: 0x0E14,
  26673. dohiragana: 0x3069,
  26674. dokatakana: 0x30C9,
  26675. dollar: 0x0024,
  26676. dollarinferior: 0xF6E3,
  26677. dollarmonospace: 0xFF04,
  26678. dollaroldstyle: 0xF724,
  26679. dollarsmall: 0xFE69,
  26680. dollarsuperior: 0xF6E4,
  26681. dong: 0x20AB,
  26682. dorusquare: 0x3326,
  26683. dotaccent: 0x02D9,
  26684. dotaccentcmb: 0x0307,
  26685. dotbelowcmb: 0x0323,
  26686. dotbelowcomb: 0x0323,
  26687. dotkatakana: 0x30FB,
  26688. dotlessi: 0x0131,
  26689. dotlessj: 0xF6BE,
  26690. dotlessjstrokehook: 0x0284,
  26691. dotmath: 0x22C5,
  26692. dottedcircle: 0x25CC,
  26693. doubleyodpatah: 0xFB1F,
  26694. doubleyodpatahhebrew: 0xFB1F,
  26695. downtackbelowcmb: 0x031E,
  26696. downtackmod: 0x02D5,
  26697. dparen: 0x249F,
  26698. dsuperior: 0xF6EB,
  26699. dtail: 0x0256,
  26700. dtopbar: 0x018C,
  26701. duhiragana: 0x3065,
  26702. dukatakana: 0x30C5,
  26703. dz: 0x01F3,
  26704. dzaltone: 0x02A3,
  26705. dzcaron: 0x01C6,
  26706. dzcurl: 0x02A5,
  26707. dzeabkhasiancyrillic: 0x04E1,
  26708. dzecyrillic: 0x0455,
  26709. dzhecyrillic: 0x045F,
  26710. e: 0x0065,
  26711. eacute: 0x00E9,
  26712. earth: 0x2641,
  26713. ebengali: 0x098F,
  26714. ebopomofo: 0x311C,
  26715. ebreve: 0x0115,
  26716. ecandradeva: 0x090D,
  26717. ecandragujarati: 0x0A8D,
  26718. ecandravowelsigndeva: 0x0945,
  26719. ecandravowelsigngujarati: 0x0AC5,
  26720. ecaron: 0x011B,
  26721. ecedillabreve: 0x1E1D,
  26722. echarmenian: 0x0565,
  26723. echyiwnarmenian: 0x0587,
  26724. ecircle: 0x24D4,
  26725. ecircumflex: 0x00EA,
  26726. ecircumflexacute: 0x1EBF,
  26727. ecircumflexbelow: 0x1E19,
  26728. ecircumflexdotbelow: 0x1EC7,
  26729. ecircumflexgrave: 0x1EC1,
  26730. ecircumflexhookabove: 0x1EC3,
  26731. ecircumflextilde: 0x1EC5,
  26732. ecyrillic: 0x0454,
  26733. edblgrave: 0x0205,
  26734. edeva: 0x090F,
  26735. edieresis: 0x00EB,
  26736. edot: 0x0117,
  26737. edotaccent: 0x0117,
  26738. edotbelow: 0x1EB9,
  26739. eegurmukhi: 0x0A0F,
  26740. eematragurmukhi: 0x0A47,
  26741. efcyrillic: 0x0444,
  26742. egrave: 0x00E8,
  26743. egujarati: 0x0A8F,
  26744. eharmenian: 0x0567,
  26745. ehbopomofo: 0x311D,
  26746. ehiragana: 0x3048,
  26747. ehookabove: 0x1EBB,
  26748. eibopomofo: 0x311F,
  26749. eight: 0x0038,
  26750. eightarabic: 0x0668,
  26751. eightbengali: 0x09EE,
  26752. eightcircle: 0x2467,
  26753. eightcircleinversesansserif: 0x2791,
  26754. eightdeva: 0x096E,
  26755. eighteencircle: 0x2471,
  26756. eighteenparen: 0x2485,
  26757. eighteenperiod: 0x2499,
  26758. eightgujarati: 0x0AEE,
  26759. eightgurmukhi: 0x0A6E,
  26760. eighthackarabic: 0x0668,
  26761. eighthangzhou: 0x3028,
  26762. eighthnotebeamed: 0x266B,
  26763. eightideographicparen: 0x3227,
  26764. eightinferior: 0x2088,
  26765. eightmonospace: 0xFF18,
  26766. eightoldstyle: 0xF738,
  26767. eightparen: 0x247B,
  26768. eightperiod: 0x248F,
  26769. eightpersian: 0x06F8,
  26770. eightroman: 0x2177,
  26771. eightsuperior: 0x2078,
  26772. eightthai: 0x0E58,
  26773. einvertedbreve: 0x0207,
  26774. eiotifiedcyrillic: 0x0465,
  26775. ekatakana: 0x30A8,
  26776. ekatakanahalfwidth: 0xFF74,
  26777. ekonkargurmukhi: 0x0A74,
  26778. ekorean: 0x3154,
  26779. elcyrillic: 0x043B,
  26780. element: 0x2208,
  26781. elevencircle: 0x246A,
  26782. elevenparen: 0x247E,
  26783. elevenperiod: 0x2492,
  26784. elevenroman: 0x217A,
  26785. ellipsis: 0x2026,
  26786. ellipsisvertical: 0x22EE,
  26787. emacron: 0x0113,
  26788. emacronacute: 0x1E17,
  26789. emacrongrave: 0x1E15,
  26790. emcyrillic: 0x043C,
  26791. emdash: 0x2014,
  26792. emdashvertical: 0xFE31,
  26793. emonospace: 0xFF45,
  26794. emphasismarkarmenian: 0x055B,
  26795. emptyset: 0x2205,
  26796. enbopomofo: 0x3123,
  26797. encyrillic: 0x043D,
  26798. endash: 0x2013,
  26799. endashvertical: 0xFE32,
  26800. endescendercyrillic: 0x04A3,
  26801. eng: 0x014B,
  26802. engbopomofo: 0x3125,
  26803. enghecyrillic: 0x04A5,
  26804. enhookcyrillic: 0x04C8,
  26805. enspace: 0x2002,
  26806. eogonek: 0x0119,
  26807. eokorean: 0x3153,
  26808. eopen: 0x025B,
  26809. eopenclosed: 0x029A,
  26810. eopenreversed: 0x025C,
  26811. eopenreversedclosed: 0x025E,
  26812. eopenreversedhook: 0x025D,
  26813. eparen: 0x24A0,
  26814. epsilon: 0x03B5,
  26815. epsilontonos: 0x03AD,
  26816. equal: 0x003D,
  26817. equalmonospace: 0xFF1D,
  26818. equalsmall: 0xFE66,
  26819. equalsuperior: 0x207C,
  26820. equivalence: 0x2261,
  26821. erbopomofo: 0x3126,
  26822. ercyrillic: 0x0440,
  26823. ereversed: 0x0258,
  26824. ereversedcyrillic: 0x044D,
  26825. escyrillic: 0x0441,
  26826. esdescendercyrillic: 0x04AB,
  26827. esh: 0x0283,
  26828. eshcurl: 0x0286,
  26829. eshortdeva: 0x090E,
  26830. eshortvowelsigndeva: 0x0946,
  26831. eshreversedloop: 0x01AA,
  26832. eshsquatreversed: 0x0285,
  26833. esmallhiragana: 0x3047,
  26834. esmallkatakana: 0x30A7,
  26835. esmallkatakanahalfwidth: 0xFF6A,
  26836. estimated: 0x212E,
  26837. esuperior: 0xF6EC,
  26838. eta: 0x03B7,
  26839. etarmenian: 0x0568,
  26840. etatonos: 0x03AE,
  26841. eth: 0x00F0,
  26842. etilde: 0x1EBD,
  26843. etildebelow: 0x1E1B,
  26844. etnahtafoukhhebrew: 0x0591,
  26845. etnahtafoukhlefthebrew: 0x0591,
  26846. etnahtahebrew: 0x0591,
  26847. etnahtalefthebrew: 0x0591,
  26848. eturned: 0x01DD,
  26849. eukorean: 0x3161,
  26850. euro: 0x20AC,
  26851. evowelsignbengali: 0x09C7,
  26852. evowelsigndeva: 0x0947,
  26853. evowelsigngujarati: 0x0AC7,
  26854. exclam: 0x0021,
  26855. exclamarmenian: 0x055C,
  26856. exclamdbl: 0x203C,
  26857. exclamdown: 0x00A1,
  26858. exclamdownsmall: 0xF7A1,
  26859. exclammonospace: 0xFF01,
  26860. exclamsmall: 0xF721,
  26861. existential: 0x2203,
  26862. ezh: 0x0292,
  26863. ezhcaron: 0x01EF,
  26864. ezhcurl: 0x0293,
  26865. ezhreversed: 0x01B9,
  26866. ezhtail: 0x01BA,
  26867. f: 0x0066,
  26868. fadeva: 0x095E,
  26869. fagurmukhi: 0x0A5E,
  26870. fahrenheit: 0x2109,
  26871. fathaarabic: 0x064E,
  26872. fathalowarabic: 0x064E,
  26873. fathatanarabic: 0x064B,
  26874. fbopomofo: 0x3108,
  26875. fcircle: 0x24D5,
  26876. fdotaccent: 0x1E1F,
  26877. feharabic: 0x0641,
  26878. feharmenian: 0x0586,
  26879. fehfinalarabic: 0xFED2,
  26880. fehinitialarabic: 0xFED3,
  26881. fehmedialarabic: 0xFED4,
  26882. feicoptic: 0x03E5,
  26883. female: 0x2640,
  26884. ff: 0xFB00,
  26885. ffi: 0xFB03,
  26886. ffl: 0xFB04,
  26887. fi: 0xFB01,
  26888. fifteencircle: 0x246E,
  26889. fifteenparen: 0x2482,
  26890. fifteenperiod: 0x2496,
  26891. figuredash: 0x2012,
  26892. filledbox: 0x25A0,
  26893. filledrect: 0x25AC,
  26894. finalkaf: 0x05DA,
  26895. finalkafdagesh: 0xFB3A,
  26896. finalkafdageshhebrew: 0xFB3A,
  26897. finalkafhebrew: 0x05DA,
  26898. finalmem: 0x05DD,
  26899. finalmemhebrew: 0x05DD,
  26900. finalnun: 0x05DF,
  26901. finalnunhebrew: 0x05DF,
  26902. finalpe: 0x05E3,
  26903. finalpehebrew: 0x05E3,
  26904. finaltsadi: 0x05E5,
  26905. finaltsadihebrew: 0x05E5,
  26906. firsttonechinese: 0x02C9,
  26907. fisheye: 0x25C9,
  26908. fitacyrillic: 0x0473,
  26909. five: 0x0035,
  26910. fivearabic: 0x0665,
  26911. fivebengali: 0x09EB,
  26912. fivecircle: 0x2464,
  26913. fivecircleinversesansserif: 0x278E,
  26914. fivedeva: 0x096B,
  26915. fiveeighths: 0x215D,
  26916. fivegujarati: 0x0AEB,
  26917. fivegurmukhi: 0x0A6B,
  26918. fivehackarabic: 0x0665,
  26919. fivehangzhou: 0x3025,
  26920. fiveideographicparen: 0x3224,
  26921. fiveinferior: 0x2085,
  26922. fivemonospace: 0xFF15,
  26923. fiveoldstyle: 0xF735,
  26924. fiveparen: 0x2478,
  26925. fiveperiod: 0x248C,
  26926. fivepersian: 0x06F5,
  26927. fiveroman: 0x2174,
  26928. fivesuperior: 0x2075,
  26929. fivethai: 0x0E55,
  26930. fl: 0xFB02,
  26931. florin: 0x0192,
  26932. fmonospace: 0xFF46,
  26933. fmsquare: 0x3399,
  26934. fofanthai: 0x0E1F,
  26935. fofathai: 0x0E1D,
  26936. fongmanthai: 0x0E4F,
  26937. forall: 0x2200,
  26938. four: 0x0034,
  26939. fourarabic: 0x0664,
  26940. fourbengali: 0x09EA,
  26941. fourcircle: 0x2463,
  26942. fourcircleinversesansserif: 0x278D,
  26943. fourdeva: 0x096A,
  26944. fourgujarati: 0x0AEA,
  26945. fourgurmukhi: 0x0A6A,
  26946. fourhackarabic: 0x0664,
  26947. fourhangzhou: 0x3024,
  26948. fourideographicparen: 0x3223,
  26949. fourinferior: 0x2084,
  26950. fourmonospace: 0xFF14,
  26951. fournumeratorbengali: 0x09F7,
  26952. fouroldstyle: 0xF734,
  26953. fourparen: 0x2477,
  26954. fourperiod: 0x248B,
  26955. fourpersian: 0x06F4,
  26956. fourroman: 0x2173,
  26957. foursuperior: 0x2074,
  26958. fourteencircle: 0x246D,
  26959. fourteenparen: 0x2481,
  26960. fourteenperiod: 0x2495,
  26961. fourthai: 0x0E54,
  26962. fourthtonechinese: 0x02CB,
  26963. fparen: 0x24A1,
  26964. fraction: 0x2044,
  26965. franc: 0x20A3,
  26966. g: 0x0067,
  26967. gabengali: 0x0997,
  26968. gacute: 0x01F5,
  26969. gadeva: 0x0917,
  26970. gafarabic: 0x06AF,
  26971. gaffinalarabic: 0xFB93,
  26972. gafinitialarabic: 0xFB94,
  26973. gafmedialarabic: 0xFB95,
  26974. gagujarati: 0x0A97,
  26975. gagurmukhi: 0x0A17,
  26976. gahiragana: 0x304C,
  26977. gakatakana: 0x30AC,
  26978. gamma: 0x03B3,
  26979. gammalatinsmall: 0x0263,
  26980. gammasuperior: 0x02E0,
  26981. gangiacoptic: 0x03EB,
  26982. gbopomofo: 0x310D,
  26983. gbreve: 0x011F,
  26984. gcaron: 0x01E7,
  26985. gcedilla: 0x0123,
  26986. gcircle: 0x24D6,
  26987. gcircumflex: 0x011D,
  26988. gcommaaccent: 0x0123,
  26989. gdot: 0x0121,
  26990. gdotaccent: 0x0121,
  26991. gecyrillic: 0x0433,
  26992. gehiragana: 0x3052,
  26993. gekatakana: 0x30B2,
  26994. geometricallyequal: 0x2251,
  26995. gereshaccenthebrew: 0x059C,
  26996. gereshhebrew: 0x05F3,
  26997. gereshmuqdamhebrew: 0x059D,
  26998. germandbls: 0x00DF,
  26999. gershayimaccenthebrew: 0x059E,
  27000. gershayimhebrew: 0x05F4,
  27001. getamark: 0x3013,
  27002. ghabengali: 0x0998,
  27003. ghadarmenian: 0x0572,
  27004. ghadeva: 0x0918,
  27005. ghagujarati: 0x0A98,
  27006. ghagurmukhi: 0x0A18,
  27007. ghainarabic: 0x063A,
  27008. ghainfinalarabic: 0xFECE,
  27009. ghaininitialarabic: 0xFECF,
  27010. ghainmedialarabic: 0xFED0,
  27011. ghemiddlehookcyrillic: 0x0495,
  27012. ghestrokecyrillic: 0x0493,
  27013. gheupturncyrillic: 0x0491,
  27014. ghhadeva: 0x095A,
  27015. ghhagurmukhi: 0x0A5A,
  27016. ghook: 0x0260,
  27017. ghzsquare: 0x3393,
  27018. gihiragana: 0x304E,
  27019. gikatakana: 0x30AE,
  27020. gimarmenian: 0x0563,
  27021. gimel: 0x05D2,
  27022. gimeldagesh: 0xFB32,
  27023. gimeldageshhebrew: 0xFB32,
  27024. gimelhebrew: 0x05D2,
  27025. gjecyrillic: 0x0453,
  27026. glottalinvertedstroke: 0x01BE,
  27027. glottalstop: 0x0294,
  27028. glottalstopinverted: 0x0296,
  27029. glottalstopmod: 0x02C0,
  27030. glottalstopreversed: 0x0295,
  27031. glottalstopreversedmod: 0x02C1,
  27032. glottalstopreversedsuperior: 0x02E4,
  27033. glottalstopstroke: 0x02A1,
  27034. glottalstopstrokereversed: 0x02A2,
  27035. gmacron: 0x1E21,
  27036. gmonospace: 0xFF47,
  27037. gohiragana: 0x3054,
  27038. gokatakana: 0x30B4,
  27039. gparen: 0x24A2,
  27040. gpasquare: 0x33AC,
  27041. gradient: 0x2207,
  27042. grave: 0x0060,
  27043. gravebelowcmb: 0x0316,
  27044. gravecmb: 0x0300,
  27045. gravecomb: 0x0300,
  27046. gravedeva: 0x0953,
  27047. gravelowmod: 0x02CE,
  27048. gravemonospace: 0xFF40,
  27049. gravetonecmb: 0x0340,
  27050. greater: 0x003E,
  27051. greaterequal: 0x2265,
  27052. greaterequalorless: 0x22DB,
  27053. greatermonospace: 0xFF1E,
  27054. greaterorequivalent: 0x2273,
  27055. greaterorless: 0x2277,
  27056. greateroverequal: 0x2267,
  27057. greatersmall: 0xFE65,
  27058. gscript: 0x0261,
  27059. gstroke: 0x01E5,
  27060. guhiragana: 0x3050,
  27061. guillemotleft: 0x00AB,
  27062. guillemotright: 0x00BB,
  27063. guilsinglleft: 0x2039,
  27064. guilsinglright: 0x203A,
  27065. gukatakana: 0x30B0,
  27066. guramusquare: 0x3318,
  27067. gysquare: 0x33C9,
  27068. h: 0x0068,
  27069. haabkhasiancyrillic: 0x04A9,
  27070. haaltonearabic: 0x06C1,
  27071. habengali: 0x09B9,
  27072. hadescendercyrillic: 0x04B3,
  27073. hadeva: 0x0939,
  27074. hagujarati: 0x0AB9,
  27075. hagurmukhi: 0x0A39,
  27076. haharabic: 0x062D,
  27077. hahfinalarabic: 0xFEA2,
  27078. hahinitialarabic: 0xFEA3,
  27079. hahiragana: 0x306F,
  27080. hahmedialarabic: 0xFEA4,
  27081. haitusquare: 0x332A,
  27082. hakatakana: 0x30CF,
  27083. hakatakanahalfwidth: 0xFF8A,
  27084. halantgurmukhi: 0x0A4D,
  27085. hamzaarabic: 0x0621,
  27086. hamzalowarabic: 0x0621,
  27087. hangulfiller: 0x3164,
  27088. hardsigncyrillic: 0x044A,
  27089. harpoonleftbarbup: 0x21BC,
  27090. harpoonrightbarbup: 0x21C0,
  27091. hasquare: 0x33CA,
  27092. hatafpatah: 0x05B2,
  27093. hatafpatah16: 0x05B2,
  27094. hatafpatah23: 0x05B2,
  27095. hatafpatah2f: 0x05B2,
  27096. hatafpatahhebrew: 0x05B2,
  27097. hatafpatahnarrowhebrew: 0x05B2,
  27098. hatafpatahquarterhebrew: 0x05B2,
  27099. hatafpatahwidehebrew: 0x05B2,
  27100. hatafqamats: 0x05B3,
  27101. hatafqamats1b: 0x05B3,
  27102. hatafqamats28: 0x05B3,
  27103. hatafqamats34: 0x05B3,
  27104. hatafqamatshebrew: 0x05B3,
  27105. hatafqamatsnarrowhebrew: 0x05B3,
  27106. hatafqamatsquarterhebrew: 0x05B3,
  27107. hatafqamatswidehebrew: 0x05B3,
  27108. hatafsegol: 0x05B1,
  27109. hatafsegol17: 0x05B1,
  27110. hatafsegol24: 0x05B1,
  27111. hatafsegol30: 0x05B1,
  27112. hatafsegolhebrew: 0x05B1,
  27113. hatafsegolnarrowhebrew: 0x05B1,
  27114. hatafsegolquarterhebrew: 0x05B1,
  27115. hatafsegolwidehebrew: 0x05B1,
  27116. hbar: 0x0127,
  27117. hbopomofo: 0x310F,
  27118. hbrevebelow: 0x1E2B,
  27119. hcedilla: 0x1E29,
  27120. hcircle: 0x24D7,
  27121. hcircumflex: 0x0125,
  27122. hdieresis: 0x1E27,
  27123. hdotaccent: 0x1E23,
  27124. hdotbelow: 0x1E25,
  27125. he: 0x05D4,
  27126. heart: 0x2665,
  27127. heartsuitblack: 0x2665,
  27128. heartsuitwhite: 0x2661,
  27129. hedagesh: 0xFB34,
  27130. hedageshhebrew: 0xFB34,
  27131. hehaltonearabic: 0x06C1,
  27132. heharabic: 0x0647,
  27133. hehebrew: 0x05D4,
  27134. hehfinalaltonearabic: 0xFBA7,
  27135. hehfinalalttwoarabic: 0xFEEA,
  27136. hehfinalarabic: 0xFEEA,
  27137. hehhamzaabovefinalarabic: 0xFBA5,
  27138. hehhamzaaboveisolatedarabic: 0xFBA4,
  27139. hehinitialaltonearabic: 0xFBA8,
  27140. hehinitialarabic: 0xFEEB,
  27141. hehiragana: 0x3078,
  27142. hehmedialaltonearabic: 0xFBA9,
  27143. hehmedialarabic: 0xFEEC,
  27144. heiseierasquare: 0x337B,
  27145. hekatakana: 0x30D8,
  27146. hekatakanahalfwidth: 0xFF8D,
  27147. hekutaarusquare: 0x3336,
  27148. henghook: 0x0267,
  27149. herutusquare: 0x3339,
  27150. het: 0x05D7,
  27151. hethebrew: 0x05D7,
  27152. hhook: 0x0266,
  27153. hhooksuperior: 0x02B1,
  27154. hieuhacirclekorean: 0x327B,
  27155. hieuhaparenkorean: 0x321B,
  27156. hieuhcirclekorean: 0x326D,
  27157. hieuhkorean: 0x314E,
  27158. hieuhparenkorean: 0x320D,
  27159. hihiragana: 0x3072,
  27160. hikatakana: 0x30D2,
  27161. hikatakanahalfwidth: 0xFF8B,
  27162. hiriq: 0x05B4,
  27163. hiriq14: 0x05B4,
  27164. hiriq21: 0x05B4,
  27165. hiriq2d: 0x05B4,
  27166. hiriqhebrew: 0x05B4,
  27167. hiriqnarrowhebrew: 0x05B4,
  27168. hiriqquarterhebrew: 0x05B4,
  27169. hiriqwidehebrew: 0x05B4,
  27170. hlinebelow: 0x1E96,
  27171. hmonospace: 0xFF48,
  27172. hoarmenian: 0x0570,
  27173. hohipthai: 0x0E2B,
  27174. hohiragana: 0x307B,
  27175. hokatakana: 0x30DB,
  27176. hokatakanahalfwidth: 0xFF8E,
  27177. holam: 0x05B9,
  27178. holam19: 0x05B9,
  27179. holam26: 0x05B9,
  27180. holam32: 0x05B9,
  27181. holamhebrew: 0x05B9,
  27182. holamnarrowhebrew: 0x05B9,
  27183. holamquarterhebrew: 0x05B9,
  27184. holamwidehebrew: 0x05B9,
  27185. honokhukthai: 0x0E2E,
  27186. hookabovecomb: 0x0309,
  27187. hookcmb: 0x0309,
  27188. hookpalatalizedbelowcmb: 0x0321,
  27189. hookretroflexbelowcmb: 0x0322,
  27190. hoonsquare: 0x3342,
  27191. horicoptic: 0x03E9,
  27192. horizontalbar: 0x2015,
  27193. horncmb: 0x031B,
  27194. hotsprings: 0x2668,
  27195. house: 0x2302,
  27196. hparen: 0x24A3,
  27197. hsuperior: 0x02B0,
  27198. hturned: 0x0265,
  27199. huhiragana: 0x3075,
  27200. huiitosquare: 0x3333,
  27201. hukatakana: 0x30D5,
  27202. hukatakanahalfwidth: 0xFF8C,
  27203. hungarumlaut: 0x02DD,
  27204. hungarumlautcmb: 0x030B,
  27205. hv: 0x0195,
  27206. hyphen: 0x002D,
  27207. hypheninferior: 0xF6E5,
  27208. hyphenmonospace: 0xFF0D,
  27209. hyphensmall: 0xFE63,
  27210. hyphensuperior: 0xF6E6,
  27211. hyphentwo: 0x2010,
  27212. i: 0x0069,
  27213. iacute: 0x00ED,
  27214. iacyrillic: 0x044F,
  27215. ibengali: 0x0987,
  27216. ibopomofo: 0x3127,
  27217. ibreve: 0x012D,
  27218. icaron: 0x01D0,
  27219. icircle: 0x24D8,
  27220. icircumflex: 0x00EE,
  27221. icyrillic: 0x0456,
  27222. idblgrave: 0x0209,
  27223. ideographearthcircle: 0x328F,
  27224. ideographfirecircle: 0x328B,
  27225. ideographicallianceparen: 0x323F,
  27226. ideographiccallparen: 0x323A,
  27227. ideographiccentrecircle: 0x32A5,
  27228. ideographicclose: 0x3006,
  27229. ideographiccomma: 0x3001,
  27230. ideographiccommaleft: 0xFF64,
  27231. ideographiccongratulationparen: 0x3237,
  27232. ideographiccorrectcircle: 0x32A3,
  27233. ideographicearthparen: 0x322F,
  27234. ideographicenterpriseparen: 0x323D,
  27235. ideographicexcellentcircle: 0x329D,
  27236. ideographicfestivalparen: 0x3240,
  27237. ideographicfinancialcircle: 0x3296,
  27238. ideographicfinancialparen: 0x3236,
  27239. ideographicfireparen: 0x322B,
  27240. ideographichaveparen: 0x3232,
  27241. ideographichighcircle: 0x32A4,
  27242. ideographiciterationmark: 0x3005,
  27243. ideographiclaborcircle: 0x3298,
  27244. ideographiclaborparen: 0x3238,
  27245. ideographicleftcircle: 0x32A7,
  27246. ideographiclowcircle: 0x32A6,
  27247. ideographicmedicinecircle: 0x32A9,
  27248. ideographicmetalparen: 0x322E,
  27249. ideographicmoonparen: 0x322A,
  27250. ideographicnameparen: 0x3234,
  27251. ideographicperiod: 0x3002,
  27252. ideographicprintcircle: 0x329E,
  27253. ideographicreachparen: 0x3243,
  27254. ideographicrepresentparen: 0x3239,
  27255. ideographicresourceparen: 0x323E,
  27256. ideographicrightcircle: 0x32A8,
  27257. ideographicsecretcircle: 0x3299,
  27258. ideographicselfparen: 0x3242,
  27259. ideographicsocietyparen: 0x3233,
  27260. ideographicspace: 0x3000,
  27261. ideographicspecialparen: 0x3235,
  27262. ideographicstockparen: 0x3231,
  27263. ideographicstudyparen: 0x323B,
  27264. ideographicsunparen: 0x3230,
  27265. ideographicsuperviseparen: 0x323C,
  27266. ideographicwaterparen: 0x322C,
  27267. ideographicwoodparen: 0x322D,
  27268. ideographiczero: 0x3007,
  27269. ideographmetalcircle: 0x328E,
  27270. ideographmooncircle: 0x328A,
  27271. ideographnamecircle: 0x3294,
  27272. ideographsuncircle: 0x3290,
  27273. ideographwatercircle: 0x328C,
  27274. ideographwoodcircle: 0x328D,
  27275. ideva: 0x0907,
  27276. idieresis: 0x00EF,
  27277. idieresisacute: 0x1E2F,
  27278. idieresiscyrillic: 0x04E5,
  27279. idotbelow: 0x1ECB,
  27280. iebrevecyrillic: 0x04D7,
  27281. iecyrillic: 0x0435,
  27282. ieungacirclekorean: 0x3275,
  27283. ieungaparenkorean: 0x3215,
  27284. ieungcirclekorean: 0x3267,
  27285. ieungkorean: 0x3147,
  27286. ieungparenkorean: 0x3207,
  27287. igrave: 0x00EC,
  27288. igujarati: 0x0A87,
  27289. igurmukhi: 0x0A07,
  27290. ihiragana: 0x3044,
  27291. ihookabove: 0x1EC9,
  27292. iibengali: 0x0988,
  27293. iicyrillic: 0x0438,
  27294. iideva: 0x0908,
  27295. iigujarati: 0x0A88,
  27296. iigurmukhi: 0x0A08,
  27297. iimatragurmukhi: 0x0A40,
  27298. iinvertedbreve: 0x020B,
  27299. iishortcyrillic: 0x0439,
  27300. iivowelsignbengali: 0x09C0,
  27301. iivowelsigndeva: 0x0940,
  27302. iivowelsigngujarati: 0x0AC0,
  27303. ij: 0x0133,
  27304. ikatakana: 0x30A4,
  27305. ikatakanahalfwidth: 0xFF72,
  27306. ikorean: 0x3163,
  27307. ilde: 0x02DC,
  27308. iluyhebrew: 0x05AC,
  27309. imacron: 0x012B,
  27310. imacroncyrillic: 0x04E3,
  27311. imageorapproximatelyequal: 0x2253,
  27312. imatragurmukhi: 0x0A3F,
  27313. imonospace: 0xFF49,
  27314. increment: 0x2206,
  27315. infinity: 0x221E,
  27316. iniarmenian: 0x056B,
  27317. integral: 0x222B,
  27318. integralbottom: 0x2321,
  27319. integralbt: 0x2321,
  27320. integralex: 0xF8F5,
  27321. integraltop: 0x2320,
  27322. integraltp: 0x2320,
  27323. intersection: 0x2229,
  27324. intisquare: 0x3305,
  27325. invbullet: 0x25D8,
  27326. invcircle: 0x25D9,
  27327. invsmileface: 0x263B,
  27328. iocyrillic: 0x0451,
  27329. iogonek: 0x012F,
  27330. iota: 0x03B9,
  27331. iotadieresis: 0x03CA,
  27332. iotadieresistonos: 0x0390,
  27333. iotalatin: 0x0269,
  27334. iotatonos: 0x03AF,
  27335. iparen: 0x24A4,
  27336. irigurmukhi: 0x0A72,
  27337. ismallhiragana: 0x3043,
  27338. ismallkatakana: 0x30A3,
  27339. ismallkatakanahalfwidth: 0xFF68,
  27340. issharbengali: 0x09FA,
  27341. istroke: 0x0268,
  27342. isuperior: 0xF6ED,
  27343. iterationhiragana: 0x309D,
  27344. iterationkatakana: 0x30FD,
  27345. itilde: 0x0129,
  27346. itildebelow: 0x1E2D,
  27347. iubopomofo: 0x3129,
  27348. iucyrillic: 0x044E,
  27349. ivowelsignbengali: 0x09BF,
  27350. ivowelsigndeva: 0x093F,
  27351. ivowelsigngujarati: 0x0ABF,
  27352. izhitsacyrillic: 0x0475,
  27353. izhitsadblgravecyrillic: 0x0477,
  27354. j: 0x006A,
  27355. jaarmenian: 0x0571,
  27356. jabengali: 0x099C,
  27357. jadeva: 0x091C,
  27358. jagujarati: 0x0A9C,
  27359. jagurmukhi: 0x0A1C,
  27360. jbopomofo: 0x3110,
  27361. jcaron: 0x01F0,
  27362. jcircle: 0x24D9,
  27363. jcircumflex: 0x0135,
  27364. jcrossedtail: 0x029D,
  27365. jdotlessstroke: 0x025F,
  27366. jecyrillic: 0x0458,
  27367. jeemarabic: 0x062C,
  27368. jeemfinalarabic: 0xFE9E,
  27369. jeeminitialarabic: 0xFE9F,
  27370. jeemmedialarabic: 0xFEA0,
  27371. jeharabic: 0x0698,
  27372. jehfinalarabic: 0xFB8B,
  27373. jhabengali: 0x099D,
  27374. jhadeva: 0x091D,
  27375. jhagujarati: 0x0A9D,
  27376. jhagurmukhi: 0x0A1D,
  27377. jheharmenian: 0x057B,
  27378. jis: 0x3004,
  27379. jmonospace: 0xFF4A,
  27380. jparen: 0x24A5,
  27381. jsuperior: 0x02B2,
  27382. k: 0x006B,
  27383. kabashkircyrillic: 0x04A1,
  27384. kabengali: 0x0995,
  27385. kacute: 0x1E31,
  27386. kacyrillic: 0x043A,
  27387. kadescendercyrillic: 0x049B,
  27388. kadeva: 0x0915,
  27389. kaf: 0x05DB,
  27390. kafarabic: 0x0643,
  27391. kafdagesh: 0xFB3B,
  27392. kafdageshhebrew: 0xFB3B,
  27393. kaffinalarabic: 0xFEDA,
  27394. kafhebrew: 0x05DB,
  27395. kafinitialarabic: 0xFEDB,
  27396. kafmedialarabic: 0xFEDC,
  27397. kafrafehebrew: 0xFB4D,
  27398. kagujarati: 0x0A95,
  27399. kagurmukhi: 0x0A15,
  27400. kahiragana: 0x304B,
  27401. kahookcyrillic: 0x04C4,
  27402. kakatakana: 0x30AB,
  27403. kakatakanahalfwidth: 0xFF76,
  27404. kappa: 0x03BA,
  27405. kappasymbolgreek: 0x03F0,
  27406. kapyeounmieumkorean: 0x3171,
  27407. kapyeounphieuphkorean: 0x3184,
  27408. kapyeounpieupkorean: 0x3178,
  27409. kapyeounssangpieupkorean: 0x3179,
  27410. karoriisquare: 0x330D,
  27411. kashidaautoarabic: 0x0640,
  27412. kashidaautonosidebearingarabic: 0x0640,
  27413. kasmallkatakana: 0x30F5,
  27414. kasquare: 0x3384,
  27415. kasraarabic: 0x0650,
  27416. kasratanarabic: 0x064D,
  27417. kastrokecyrillic: 0x049F,
  27418. katahiraprolongmarkhalfwidth: 0xFF70,
  27419. kaverticalstrokecyrillic: 0x049D,
  27420. kbopomofo: 0x310E,
  27421. kcalsquare: 0x3389,
  27422. kcaron: 0x01E9,
  27423. kcedilla: 0x0137,
  27424. kcircle: 0x24DA,
  27425. kcommaaccent: 0x0137,
  27426. kdotbelow: 0x1E33,
  27427. keharmenian: 0x0584,
  27428. kehiragana: 0x3051,
  27429. kekatakana: 0x30B1,
  27430. kekatakanahalfwidth: 0xFF79,
  27431. kenarmenian: 0x056F,
  27432. kesmallkatakana: 0x30F6,
  27433. kgreenlandic: 0x0138,
  27434. khabengali: 0x0996,
  27435. khacyrillic: 0x0445,
  27436. khadeva: 0x0916,
  27437. khagujarati: 0x0A96,
  27438. khagurmukhi: 0x0A16,
  27439. khaharabic: 0x062E,
  27440. khahfinalarabic: 0xFEA6,
  27441. khahinitialarabic: 0xFEA7,
  27442. khahmedialarabic: 0xFEA8,
  27443. kheicoptic: 0x03E7,
  27444. khhadeva: 0x0959,
  27445. khhagurmukhi: 0x0A59,
  27446. khieukhacirclekorean: 0x3278,
  27447. khieukhaparenkorean: 0x3218,
  27448. khieukhcirclekorean: 0x326A,
  27449. khieukhkorean: 0x314B,
  27450. khieukhparenkorean: 0x320A,
  27451. khokhaithai: 0x0E02,
  27452. khokhonthai: 0x0E05,
  27453. khokhuatthai: 0x0E03,
  27454. khokhwaithai: 0x0E04,
  27455. khomutthai: 0x0E5B,
  27456. khook: 0x0199,
  27457. khorakhangthai: 0x0E06,
  27458. khzsquare: 0x3391,
  27459. kihiragana: 0x304D,
  27460. kikatakana: 0x30AD,
  27461. kikatakanahalfwidth: 0xFF77,
  27462. kiroguramusquare: 0x3315,
  27463. kiromeetorusquare: 0x3316,
  27464. kirosquare: 0x3314,
  27465. kiyeokacirclekorean: 0x326E,
  27466. kiyeokaparenkorean: 0x320E,
  27467. kiyeokcirclekorean: 0x3260,
  27468. kiyeokkorean: 0x3131,
  27469. kiyeokparenkorean: 0x3200,
  27470. kiyeoksioskorean: 0x3133,
  27471. kjecyrillic: 0x045C,
  27472. klinebelow: 0x1E35,
  27473. klsquare: 0x3398,
  27474. kmcubedsquare: 0x33A6,
  27475. kmonospace: 0xFF4B,
  27476. kmsquaredsquare: 0x33A2,
  27477. kohiragana: 0x3053,
  27478. kohmsquare: 0x33C0,
  27479. kokaithai: 0x0E01,
  27480. kokatakana: 0x30B3,
  27481. kokatakanahalfwidth: 0xFF7A,
  27482. kooposquare: 0x331E,
  27483. koppacyrillic: 0x0481,
  27484. koreanstandardsymbol: 0x327F,
  27485. koroniscmb: 0x0343,
  27486. kparen: 0x24A6,
  27487. kpasquare: 0x33AA,
  27488. ksicyrillic: 0x046F,
  27489. ktsquare: 0x33CF,
  27490. kturned: 0x029E,
  27491. kuhiragana: 0x304F,
  27492. kukatakana: 0x30AF,
  27493. kukatakanahalfwidth: 0xFF78,
  27494. kvsquare: 0x33B8,
  27495. kwsquare: 0x33BE,
  27496. l: 0x006C,
  27497. labengali: 0x09B2,
  27498. lacute: 0x013A,
  27499. ladeva: 0x0932,
  27500. lagujarati: 0x0AB2,
  27501. lagurmukhi: 0x0A32,
  27502. lakkhangyaothai: 0x0E45,
  27503. lamaleffinalarabic: 0xFEFC,
  27504. lamalefhamzaabovefinalarabic: 0xFEF8,
  27505. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  27506. lamalefhamzabelowfinalarabic: 0xFEFA,
  27507. lamalefhamzabelowisolatedarabic: 0xFEF9,
  27508. lamalefisolatedarabic: 0xFEFB,
  27509. lamalefmaddaabovefinalarabic: 0xFEF6,
  27510. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  27511. lamarabic: 0x0644,
  27512. lambda: 0x03BB,
  27513. lambdastroke: 0x019B,
  27514. lamed: 0x05DC,
  27515. lameddagesh: 0xFB3C,
  27516. lameddageshhebrew: 0xFB3C,
  27517. lamedhebrew: 0x05DC,
  27518. lamfinalarabic: 0xFEDE,
  27519. lamhahinitialarabic: 0xFCCA,
  27520. laminitialarabic: 0xFEDF,
  27521. lamjeeminitialarabic: 0xFCC9,
  27522. lamkhahinitialarabic: 0xFCCB,
  27523. lamlamhehisolatedarabic: 0xFDF2,
  27524. lammedialarabic: 0xFEE0,
  27525. lammeemhahinitialarabic: 0xFD88,
  27526. lammeeminitialarabic: 0xFCCC,
  27527. largecircle: 0x25EF,
  27528. lbar: 0x019A,
  27529. lbelt: 0x026C,
  27530. lbopomofo: 0x310C,
  27531. lcaron: 0x013E,
  27532. lcedilla: 0x013C,
  27533. lcircle: 0x24DB,
  27534. lcircumflexbelow: 0x1E3D,
  27535. lcommaaccent: 0x013C,
  27536. ldot: 0x0140,
  27537. ldotaccent: 0x0140,
  27538. ldotbelow: 0x1E37,
  27539. ldotbelowmacron: 0x1E39,
  27540. leftangleabovecmb: 0x031A,
  27541. lefttackbelowcmb: 0x0318,
  27542. less: 0x003C,
  27543. lessequal: 0x2264,
  27544. lessequalorgreater: 0x22DA,
  27545. lessmonospace: 0xFF1C,
  27546. lessorequivalent: 0x2272,
  27547. lessorgreater: 0x2276,
  27548. lessoverequal: 0x2266,
  27549. lesssmall: 0xFE64,
  27550. lezh: 0x026E,
  27551. lfblock: 0x258C,
  27552. lhookretroflex: 0x026D,
  27553. lira: 0x20A4,
  27554. liwnarmenian: 0x056C,
  27555. lj: 0x01C9,
  27556. ljecyrillic: 0x0459,
  27557. ll: 0xF6C0,
  27558. lladeva: 0x0933,
  27559. llagujarati: 0x0AB3,
  27560. llinebelow: 0x1E3B,
  27561. llladeva: 0x0934,
  27562. llvocalicbengali: 0x09E1,
  27563. llvocalicdeva: 0x0961,
  27564. llvocalicvowelsignbengali: 0x09E3,
  27565. llvocalicvowelsigndeva: 0x0963,
  27566. lmiddletilde: 0x026B,
  27567. lmonospace: 0xFF4C,
  27568. lmsquare: 0x33D0,
  27569. lochulathai: 0x0E2C,
  27570. logicaland: 0x2227,
  27571. logicalnot: 0x00AC,
  27572. logicalnotreversed: 0x2310,
  27573. logicalor: 0x2228,
  27574. lolingthai: 0x0E25,
  27575. longs: 0x017F,
  27576. lowlinecenterline: 0xFE4E,
  27577. lowlinecmb: 0x0332,
  27578. lowlinedashed: 0xFE4D,
  27579. lozenge: 0x25CA,
  27580. lparen: 0x24A7,
  27581. lslash: 0x0142,
  27582. lsquare: 0x2113,
  27583. lsuperior: 0xF6EE,
  27584. ltshade: 0x2591,
  27585. luthai: 0x0E26,
  27586. lvocalicbengali: 0x098C,
  27587. lvocalicdeva: 0x090C,
  27588. lvocalicvowelsignbengali: 0x09E2,
  27589. lvocalicvowelsigndeva: 0x0962,
  27590. lxsquare: 0x33D3,
  27591. m: 0x006D,
  27592. mabengali: 0x09AE,
  27593. macron: 0x00AF,
  27594. macronbelowcmb: 0x0331,
  27595. macroncmb: 0x0304,
  27596. macronlowmod: 0x02CD,
  27597. macronmonospace: 0xFFE3,
  27598. macute: 0x1E3F,
  27599. madeva: 0x092E,
  27600. magujarati: 0x0AAE,
  27601. magurmukhi: 0x0A2E,
  27602. mahapakhhebrew: 0x05A4,
  27603. mahapakhlefthebrew: 0x05A4,
  27604. mahiragana: 0x307E,
  27605. maichattawalowleftthai: 0xF895,
  27606. maichattawalowrightthai: 0xF894,
  27607. maichattawathai: 0x0E4B,
  27608. maichattawaupperleftthai: 0xF893,
  27609. maieklowleftthai: 0xF88C,
  27610. maieklowrightthai: 0xF88B,
  27611. maiekthai: 0x0E48,
  27612. maiekupperleftthai: 0xF88A,
  27613. maihanakatleftthai: 0xF884,
  27614. maihanakatthai: 0x0E31,
  27615. maitaikhuleftthai: 0xF889,
  27616. maitaikhuthai: 0x0E47,
  27617. maitholowleftthai: 0xF88F,
  27618. maitholowrightthai: 0xF88E,
  27619. maithothai: 0x0E49,
  27620. maithoupperleftthai: 0xF88D,
  27621. maitrilowleftthai: 0xF892,
  27622. maitrilowrightthai: 0xF891,
  27623. maitrithai: 0x0E4A,
  27624. maitriupperleftthai: 0xF890,
  27625. maiyamokthai: 0x0E46,
  27626. makatakana: 0x30DE,
  27627. makatakanahalfwidth: 0xFF8F,
  27628. male: 0x2642,
  27629. mansyonsquare: 0x3347,
  27630. maqafhebrew: 0x05BE,
  27631. mars: 0x2642,
  27632. masoracirclehebrew: 0x05AF,
  27633. masquare: 0x3383,
  27634. mbopomofo: 0x3107,
  27635. mbsquare: 0x33D4,
  27636. mcircle: 0x24DC,
  27637. mcubedsquare: 0x33A5,
  27638. mdotaccent: 0x1E41,
  27639. mdotbelow: 0x1E43,
  27640. meemarabic: 0x0645,
  27641. meemfinalarabic: 0xFEE2,
  27642. meeminitialarabic: 0xFEE3,
  27643. meemmedialarabic: 0xFEE4,
  27644. meemmeeminitialarabic: 0xFCD1,
  27645. meemmeemisolatedarabic: 0xFC48,
  27646. meetorusquare: 0x334D,
  27647. mehiragana: 0x3081,
  27648. meizierasquare: 0x337E,
  27649. mekatakana: 0x30E1,
  27650. mekatakanahalfwidth: 0xFF92,
  27651. mem: 0x05DE,
  27652. memdagesh: 0xFB3E,
  27653. memdageshhebrew: 0xFB3E,
  27654. memhebrew: 0x05DE,
  27655. menarmenian: 0x0574,
  27656. merkhahebrew: 0x05A5,
  27657. merkhakefulahebrew: 0x05A6,
  27658. merkhakefulalefthebrew: 0x05A6,
  27659. merkhalefthebrew: 0x05A5,
  27660. mhook: 0x0271,
  27661. mhzsquare: 0x3392,
  27662. middledotkatakanahalfwidth: 0xFF65,
  27663. middot: 0x00B7,
  27664. mieumacirclekorean: 0x3272,
  27665. mieumaparenkorean: 0x3212,
  27666. mieumcirclekorean: 0x3264,
  27667. mieumkorean: 0x3141,
  27668. mieumpansioskorean: 0x3170,
  27669. mieumparenkorean: 0x3204,
  27670. mieumpieupkorean: 0x316E,
  27671. mieumsioskorean: 0x316F,
  27672. mihiragana: 0x307F,
  27673. mikatakana: 0x30DF,
  27674. mikatakanahalfwidth: 0xFF90,
  27675. minus: 0x2212,
  27676. minusbelowcmb: 0x0320,
  27677. minuscircle: 0x2296,
  27678. minusmod: 0x02D7,
  27679. minusplus: 0x2213,
  27680. minute: 0x2032,
  27681. miribaarusquare: 0x334A,
  27682. mirisquare: 0x3349,
  27683. mlonglegturned: 0x0270,
  27684. mlsquare: 0x3396,
  27685. mmcubedsquare: 0x33A3,
  27686. mmonospace: 0xFF4D,
  27687. mmsquaredsquare: 0x339F,
  27688. mohiragana: 0x3082,
  27689. mohmsquare: 0x33C1,
  27690. mokatakana: 0x30E2,
  27691. mokatakanahalfwidth: 0xFF93,
  27692. molsquare: 0x33D6,
  27693. momathai: 0x0E21,
  27694. moverssquare: 0x33A7,
  27695. moverssquaredsquare: 0x33A8,
  27696. mparen: 0x24A8,
  27697. mpasquare: 0x33AB,
  27698. mssquare: 0x33B3,
  27699. msuperior: 0xF6EF,
  27700. mturned: 0x026F,
  27701. mu: 0x00B5,
  27702. mu1: 0x00B5,
  27703. muasquare: 0x3382,
  27704. muchgreater: 0x226B,
  27705. muchless: 0x226A,
  27706. mufsquare: 0x338C,
  27707. mugreek: 0x03BC,
  27708. mugsquare: 0x338D,
  27709. muhiragana: 0x3080,
  27710. mukatakana: 0x30E0,
  27711. mukatakanahalfwidth: 0xFF91,
  27712. mulsquare: 0x3395,
  27713. multiply: 0x00D7,
  27714. mumsquare: 0x339B,
  27715. munahhebrew: 0x05A3,
  27716. munahlefthebrew: 0x05A3,
  27717. musicalnote: 0x266A,
  27718. musicalnotedbl: 0x266B,
  27719. musicflatsign: 0x266D,
  27720. musicsharpsign: 0x266F,
  27721. mussquare: 0x33B2,
  27722. muvsquare: 0x33B6,
  27723. muwsquare: 0x33BC,
  27724. mvmegasquare: 0x33B9,
  27725. mvsquare: 0x33B7,
  27726. mwmegasquare: 0x33BF,
  27727. mwsquare: 0x33BD,
  27728. n: 0x006E,
  27729. nabengali: 0x09A8,
  27730. nabla: 0x2207,
  27731. nacute: 0x0144,
  27732. nadeva: 0x0928,
  27733. nagujarati: 0x0AA8,
  27734. nagurmukhi: 0x0A28,
  27735. nahiragana: 0x306A,
  27736. nakatakana: 0x30CA,
  27737. nakatakanahalfwidth: 0xFF85,
  27738. napostrophe: 0x0149,
  27739. nasquare: 0x3381,
  27740. nbopomofo: 0x310B,
  27741. nbspace: 0x00A0,
  27742. ncaron: 0x0148,
  27743. ncedilla: 0x0146,
  27744. ncircle: 0x24DD,
  27745. ncircumflexbelow: 0x1E4B,
  27746. ncommaaccent: 0x0146,
  27747. ndotaccent: 0x1E45,
  27748. ndotbelow: 0x1E47,
  27749. nehiragana: 0x306D,
  27750. nekatakana: 0x30CD,
  27751. nekatakanahalfwidth: 0xFF88,
  27752. newsheqelsign: 0x20AA,
  27753. nfsquare: 0x338B,
  27754. ngabengali: 0x0999,
  27755. ngadeva: 0x0919,
  27756. ngagujarati: 0x0A99,
  27757. ngagurmukhi: 0x0A19,
  27758. ngonguthai: 0x0E07,
  27759. nhiragana: 0x3093,
  27760. nhookleft: 0x0272,
  27761. nhookretroflex: 0x0273,
  27762. nieunacirclekorean: 0x326F,
  27763. nieunaparenkorean: 0x320F,
  27764. nieuncieuckorean: 0x3135,
  27765. nieuncirclekorean: 0x3261,
  27766. nieunhieuhkorean: 0x3136,
  27767. nieunkorean: 0x3134,
  27768. nieunpansioskorean: 0x3168,
  27769. nieunparenkorean: 0x3201,
  27770. nieunsioskorean: 0x3167,
  27771. nieuntikeutkorean: 0x3166,
  27772. nihiragana: 0x306B,
  27773. nikatakana: 0x30CB,
  27774. nikatakanahalfwidth: 0xFF86,
  27775. nikhahitleftthai: 0xF899,
  27776. nikhahitthai: 0x0E4D,
  27777. nine: 0x0039,
  27778. ninearabic: 0x0669,
  27779. ninebengali: 0x09EF,
  27780. ninecircle: 0x2468,
  27781. ninecircleinversesansserif: 0x2792,
  27782. ninedeva: 0x096F,
  27783. ninegujarati: 0x0AEF,
  27784. ninegurmukhi: 0x0A6F,
  27785. ninehackarabic: 0x0669,
  27786. ninehangzhou: 0x3029,
  27787. nineideographicparen: 0x3228,
  27788. nineinferior: 0x2089,
  27789. ninemonospace: 0xFF19,
  27790. nineoldstyle: 0xF739,
  27791. nineparen: 0x247C,
  27792. nineperiod: 0x2490,
  27793. ninepersian: 0x06F9,
  27794. nineroman: 0x2178,
  27795. ninesuperior: 0x2079,
  27796. nineteencircle: 0x2472,
  27797. nineteenparen: 0x2486,
  27798. nineteenperiod: 0x249A,
  27799. ninethai: 0x0E59,
  27800. nj: 0x01CC,
  27801. njecyrillic: 0x045A,
  27802. nkatakana: 0x30F3,
  27803. nkatakanahalfwidth: 0xFF9D,
  27804. nlegrightlong: 0x019E,
  27805. nlinebelow: 0x1E49,
  27806. nmonospace: 0xFF4E,
  27807. nmsquare: 0x339A,
  27808. nnabengali: 0x09A3,
  27809. nnadeva: 0x0923,
  27810. nnagujarati: 0x0AA3,
  27811. nnagurmukhi: 0x0A23,
  27812. nnnadeva: 0x0929,
  27813. nohiragana: 0x306E,
  27814. nokatakana: 0x30CE,
  27815. nokatakanahalfwidth: 0xFF89,
  27816. nonbreakingspace: 0x00A0,
  27817. nonenthai: 0x0E13,
  27818. nonuthai: 0x0E19,
  27819. noonarabic: 0x0646,
  27820. noonfinalarabic: 0xFEE6,
  27821. noonghunnaarabic: 0x06BA,
  27822. noonghunnafinalarabic: 0xFB9F,
  27823. nooninitialarabic: 0xFEE7,
  27824. noonjeeminitialarabic: 0xFCD2,
  27825. noonjeemisolatedarabic: 0xFC4B,
  27826. noonmedialarabic: 0xFEE8,
  27827. noonmeeminitialarabic: 0xFCD5,
  27828. noonmeemisolatedarabic: 0xFC4E,
  27829. noonnoonfinalarabic: 0xFC8D,
  27830. notcontains: 0x220C,
  27831. notelement: 0x2209,
  27832. notelementof: 0x2209,
  27833. notequal: 0x2260,
  27834. notgreater: 0x226F,
  27835. notgreaternorequal: 0x2271,
  27836. notgreaternorless: 0x2279,
  27837. notidentical: 0x2262,
  27838. notless: 0x226E,
  27839. notlessnorequal: 0x2270,
  27840. notparallel: 0x2226,
  27841. notprecedes: 0x2280,
  27842. notsubset: 0x2284,
  27843. notsucceeds: 0x2281,
  27844. notsuperset: 0x2285,
  27845. nowarmenian: 0x0576,
  27846. nparen: 0x24A9,
  27847. nssquare: 0x33B1,
  27848. nsuperior: 0x207F,
  27849. ntilde: 0x00F1,
  27850. nu: 0x03BD,
  27851. nuhiragana: 0x306C,
  27852. nukatakana: 0x30CC,
  27853. nukatakanahalfwidth: 0xFF87,
  27854. nuktabengali: 0x09BC,
  27855. nuktadeva: 0x093C,
  27856. nuktagujarati: 0x0ABC,
  27857. nuktagurmukhi: 0x0A3C,
  27858. numbersign: 0x0023,
  27859. numbersignmonospace: 0xFF03,
  27860. numbersignsmall: 0xFE5F,
  27861. numeralsigngreek: 0x0374,
  27862. numeralsignlowergreek: 0x0375,
  27863. numero: 0x2116,
  27864. nun: 0x05E0,
  27865. nundagesh: 0xFB40,
  27866. nundageshhebrew: 0xFB40,
  27867. nunhebrew: 0x05E0,
  27868. nvsquare: 0x33B5,
  27869. nwsquare: 0x33BB,
  27870. nyabengali: 0x099E,
  27871. nyadeva: 0x091E,
  27872. nyagujarati: 0x0A9E,
  27873. nyagurmukhi: 0x0A1E,
  27874. o: 0x006F,
  27875. oacute: 0x00F3,
  27876. oangthai: 0x0E2D,
  27877. obarred: 0x0275,
  27878. obarredcyrillic: 0x04E9,
  27879. obarreddieresiscyrillic: 0x04EB,
  27880. obengali: 0x0993,
  27881. obopomofo: 0x311B,
  27882. obreve: 0x014F,
  27883. ocandradeva: 0x0911,
  27884. ocandragujarati: 0x0A91,
  27885. ocandravowelsigndeva: 0x0949,
  27886. ocandravowelsigngujarati: 0x0AC9,
  27887. ocaron: 0x01D2,
  27888. ocircle: 0x24DE,
  27889. ocircumflex: 0x00F4,
  27890. ocircumflexacute: 0x1ED1,
  27891. ocircumflexdotbelow: 0x1ED9,
  27892. ocircumflexgrave: 0x1ED3,
  27893. ocircumflexhookabove: 0x1ED5,
  27894. ocircumflextilde: 0x1ED7,
  27895. ocyrillic: 0x043E,
  27896. odblacute: 0x0151,
  27897. odblgrave: 0x020D,
  27898. odeva: 0x0913,
  27899. odieresis: 0x00F6,
  27900. odieresiscyrillic: 0x04E7,
  27901. odotbelow: 0x1ECD,
  27902. oe: 0x0153,
  27903. oekorean: 0x315A,
  27904. ogonek: 0x02DB,
  27905. ogonekcmb: 0x0328,
  27906. ograve: 0x00F2,
  27907. ogujarati: 0x0A93,
  27908. oharmenian: 0x0585,
  27909. ohiragana: 0x304A,
  27910. ohookabove: 0x1ECF,
  27911. ohorn: 0x01A1,
  27912. ohornacute: 0x1EDB,
  27913. ohorndotbelow: 0x1EE3,
  27914. ohorngrave: 0x1EDD,
  27915. ohornhookabove: 0x1EDF,
  27916. ohorntilde: 0x1EE1,
  27917. ohungarumlaut: 0x0151,
  27918. oi: 0x01A3,
  27919. oinvertedbreve: 0x020F,
  27920. okatakana: 0x30AA,
  27921. okatakanahalfwidth: 0xFF75,
  27922. okorean: 0x3157,
  27923. olehebrew: 0x05AB,
  27924. omacron: 0x014D,
  27925. omacronacute: 0x1E53,
  27926. omacrongrave: 0x1E51,
  27927. omdeva: 0x0950,
  27928. omega: 0x03C9,
  27929. omega1: 0x03D6,
  27930. omegacyrillic: 0x0461,
  27931. omegalatinclosed: 0x0277,
  27932. omegaroundcyrillic: 0x047B,
  27933. omegatitlocyrillic: 0x047D,
  27934. omegatonos: 0x03CE,
  27935. omgujarati: 0x0AD0,
  27936. omicron: 0x03BF,
  27937. omicrontonos: 0x03CC,
  27938. omonospace: 0xFF4F,
  27939. one: 0x0031,
  27940. onearabic: 0x0661,
  27941. onebengali: 0x09E7,
  27942. onecircle: 0x2460,
  27943. onecircleinversesansserif: 0x278A,
  27944. onedeva: 0x0967,
  27945. onedotenleader: 0x2024,
  27946. oneeighth: 0x215B,
  27947. onefitted: 0xF6DC,
  27948. onegujarati: 0x0AE7,
  27949. onegurmukhi: 0x0A67,
  27950. onehackarabic: 0x0661,
  27951. onehalf: 0x00BD,
  27952. onehangzhou: 0x3021,
  27953. oneideographicparen: 0x3220,
  27954. oneinferior: 0x2081,
  27955. onemonospace: 0xFF11,
  27956. onenumeratorbengali: 0x09F4,
  27957. oneoldstyle: 0xF731,
  27958. oneparen: 0x2474,
  27959. oneperiod: 0x2488,
  27960. onepersian: 0x06F1,
  27961. onequarter: 0x00BC,
  27962. oneroman: 0x2170,
  27963. onesuperior: 0x00B9,
  27964. onethai: 0x0E51,
  27965. onethird: 0x2153,
  27966. oogonek: 0x01EB,
  27967. oogonekmacron: 0x01ED,
  27968. oogurmukhi: 0x0A13,
  27969. oomatragurmukhi: 0x0A4B,
  27970. oopen: 0x0254,
  27971. oparen: 0x24AA,
  27972. openbullet: 0x25E6,
  27973. option: 0x2325,
  27974. ordfeminine: 0x00AA,
  27975. ordmasculine: 0x00BA,
  27976. orthogonal: 0x221F,
  27977. oshortdeva: 0x0912,
  27978. oshortvowelsigndeva: 0x094A,
  27979. oslash: 0x00F8,
  27980. oslashacute: 0x01FF,
  27981. osmallhiragana: 0x3049,
  27982. osmallkatakana: 0x30A9,
  27983. osmallkatakanahalfwidth: 0xFF6B,
  27984. ostrokeacute: 0x01FF,
  27985. osuperior: 0xF6F0,
  27986. otcyrillic: 0x047F,
  27987. otilde: 0x00F5,
  27988. otildeacute: 0x1E4D,
  27989. otildedieresis: 0x1E4F,
  27990. oubopomofo: 0x3121,
  27991. overline: 0x203E,
  27992. overlinecenterline: 0xFE4A,
  27993. overlinecmb: 0x0305,
  27994. overlinedashed: 0xFE49,
  27995. overlinedblwavy: 0xFE4C,
  27996. overlinewavy: 0xFE4B,
  27997. overscore: 0x00AF,
  27998. ovowelsignbengali: 0x09CB,
  27999. ovowelsigndeva: 0x094B,
  28000. ovowelsigngujarati: 0x0ACB,
  28001. p: 0x0070,
  28002. paampssquare: 0x3380,
  28003. paasentosquare: 0x332B,
  28004. pabengali: 0x09AA,
  28005. pacute: 0x1E55,
  28006. padeva: 0x092A,
  28007. pagedown: 0x21DF,
  28008. pageup: 0x21DE,
  28009. pagujarati: 0x0AAA,
  28010. pagurmukhi: 0x0A2A,
  28011. pahiragana: 0x3071,
  28012. paiyannoithai: 0x0E2F,
  28013. pakatakana: 0x30D1,
  28014. palatalizationcyrilliccmb: 0x0484,
  28015. palochkacyrillic: 0x04C0,
  28016. pansioskorean: 0x317F,
  28017. paragraph: 0x00B6,
  28018. parallel: 0x2225,
  28019. parenleft: 0x0028,
  28020. parenleftaltonearabic: 0xFD3E,
  28021. parenleftbt: 0xF8ED,
  28022. parenleftex: 0xF8EC,
  28023. parenleftinferior: 0x208D,
  28024. parenleftmonospace: 0xFF08,
  28025. parenleftsmall: 0xFE59,
  28026. parenleftsuperior: 0x207D,
  28027. parenlefttp: 0xF8EB,
  28028. parenleftvertical: 0xFE35,
  28029. parenright: 0x0029,
  28030. parenrightaltonearabic: 0xFD3F,
  28031. parenrightbt: 0xF8F8,
  28032. parenrightex: 0xF8F7,
  28033. parenrightinferior: 0x208E,
  28034. parenrightmonospace: 0xFF09,
  28035. parenrightsmall: 0xFE5A,
  28036. parenrightsuperior: 0x207E,
  28037. parenrighttp: 0xF8F6,
  28038. parenrightvertical: 0xFE36,
  28039. partialdiff: 0x2202,
  28040. paseqhebrew: 0x05C0,
  28041. pashtahebrew: 0x0599,
  28042. pasquare: 0x33A9,
  28043. patah: 0x05B7,
  28044. patah11: 0x05B7,
  28045. patah1d: 0x05B7,
  28046. patah2a: 0x05B7,
  28047. patahhebrew: 0x05B7,
  28048. patahnarrowhebrew: 0x05B7,
  28049. patahquarterhebrew: 0x05B7,
  28050. patahwidehebrew: 0x05B7,
  28051. pazerhebrew: 0x05A1,
  28052. pbopomofo: 0x3106,
  28053. pcircle: 0x24DF,
  28054. pdotaccent: 0x1E57,
  28055. pe: 0x05E4,
  28056. pecyrillic: 0x043F,
  28057. pedagesh: 0xFB44,
  28058. pedageshhebrew: 0xFB44,
  28059. peezisquare: 0x333B,
  28060. pefinaldageshhebrew: 0xFB43,
  28061. peharabic: 0x067E,
  28062. peharmenian: 0x057A,
  28063. pehebrew: 0x05E4,
  28064. pehfinalarabic: 0xFB57,
  28065. pehinitialarabic: 0xFB58,
  28066. pehiragana: 0x307A,
  28067. pehmedialarabic: 0xFB59,
  28068. pekatakana: 0x30DA,
  28069. pemiddlehookcyrillic: 0x04A7,
  28070. perafehebrew: 0xFB4E,
  28071. percent: 0x0025,
  28072. percentarabic: 0x066A,
  28073. percentmonospace: 0xFF05,
  28074. percentsmall: 0xFE6A,
  28075. period: 0x002E,
  28076. periodarmenian: 0x0589,
  28077. periodcentered: 0x00B7,
  28078. periodhalfwidth: 0xFF61,
  28079. periodinferior: 0xF6E7,
  28080. periodmonospace: 0xFF0E,
  28081. periodsmall: 0xFE52,
  28082. periodsuperior: 0xF6E8,
  28083. perispomenigreekcmb: 0x0342,
  28084. perpendicular: 0x22A5,
  28085. perthousand: 0x2030,
  28086. peseta: 0x20A7,
  28087. pfsquare: 0x338A,
  28088. phabengali: 0x09AB,
  28089. phadeva: 0x092B,
  28090. phagujarati: 0x0AAB,
  28091. phagurmukhi: 0x0A2B,
  28092. phi: 0x03C6,
  28093. phi1: 0x03D5,
  28094. phieuphacirclekorean: 0x327A,
  28095. phieuphaparenkorean: 0x321A,
  28096. phieuphcirclekorean: 0x326C,
  28097. phieuphkorean: 0x314D,
  28098. phieuphparenkorean: 0x320C,
  28099. philatin: 0x0278,
  28100. phinthuthai: 0x0E3A,
  28101. phisymbolgreek: 0x03D5,
  28102. phook: 0x01A5,
  28103. phophanthai: 0x0E1E,
  28104. phophungthai: 0x0E1C,
  28105. phosamphaothai: 0x0E20,
  28106. pi: 0x03C0,
  28107. pieupacirclekorean: 0x3273,
  28108. pieupaparenkorean: 0x3213,
  28109. pieupcieuckorean: 0x3176,
  28110. pieupcirclekorean: 0x3265,
  28111. pieupkiyeokkorean: 0x3172,
  28112. pieupkorean: 0x3142,
  28113. pieupparenkorean: 0x3205,
  28114. pieupsioskiyeokkorean: 0x3174,
  28115. pieupsioskorean: 0x3144,
  28116. pieupsiostikeutkorean: 0x3175,
  28117. pieupthieuthkorean: 0x3177,
  28118. pieuptikeutkorean: 0x3173,
  28119. pihiragana: 0x3074,
  28120. pikatakana: 0x30D4,
  28121. pisymbolgreek: 0x03D6,
  28122. piwrarmenian: 0x0583,
  28123. plus: 0x002B,
  28124. plusbelowcmb: 0x031F,
  28125. pluscircle: 0x2295,
  28126. plusminus: 0x00B1,
  28127. plusmod: 0x02D6,
  28128. plusmonospace: 0xFF0B,
  28129. plussmall: 0xFE62,
  28130. plussuperior: 0x207A,
  28131. pmonospace: 0xFF50,
  28132. pmsquare: 0x33D8,
  28133. pohiragana: 0x307D,
  28134. pointingindexdownwhite: 0x261F,
  28135. pointingindexleftwhite: 0x261C,
  28136. pointingindexrightwhite: 0x261E,
  28137. pointingindexupwhite: 0x261D,
  28138. pokatakana: 0x30DD,
  28139. poplathai: 0x0E1B,
  28140. postalmark: 0x3012,
  28141. postalmarkface: 0x3020,
  28142. pparen: 0x24AB,
  28143. precedes: 0x227A,
  28144. prescription: 0x211E,
  28145. primemod: 0x02B9,
  28146. primereversed: 0x2035,
  28147. product: 0x220F,
  28148. projective: 0x2305,
  28149. prolongedkana: 0x30FC,
  28150. propellor: 0x2318,
  28151. propersubset: 0x2282,
  28152. propersuperset: 0x2283,
  28153. proportion: 0x2237,
  28154. proportional: 0x221D,
  28155. psi: 0x03C8,
  28156. psicyrillic: 0x0471,
  28157. psilipneumatacyrilliccmb: 0x0486,
  28158. pssquare: 0x33B0,
  28159. puhiragana: 0x3077,
  28160. pukatakana: 0x30D7,
  28161. pvsquare: 0x33B4,
  28162. pwsquare: 0x33BA,
  28163. q: 0x0071,
  28164. qadeva: 0x0958,
  28165. qadmahebrew: 0x05A8,
  28166. qafarabic: 0x0642,
  28167. qaffinalarabic: 0xFED6,
  28168. qafinitialarabic: 0xFED7,
  28169. qafmedialarabic: 0xFED8,
  28170. qamats: 0x05B8,
  28171. qamats10: 0x05B8,
  28172. qamats1a: 0x05B8,
  28173. qamats1c: 0x05B8,
  28174. qamats27: 0x05B8,
  28175. qamats29: 0x05B8,
  28176. qamats33: 0x05B8,
  28177. qamatsde: 0x05B8,
  28178. qamatshebrew: 0x05B8,
  28179. qamatsnarrowhebrew: 0x05B8,
  28180. qamatsqatanhebrew: 0x05B8,
  28181. qamatsqatannarrowhebrew: 0x05B8,
  28182. qamatsqatanquarterhebrew: 0x05B8,
  28183. qamatsqatanwidehebrew: 0x05B8,
  28184. qamatsquarterhebrew: 0x05B8,
  28185. qamatswidehebrew: 0x05B8,
  28186. qarneyparahebrew: 0x059F,
  28187. qbopomofo: 0x3111,
  28188. qcircle: 0x24E0,
  28189. qhook: 0x02A0,
  28190. qmonospace: 0xFF51,
  28191. qof: 0x05E7,
  28192. qofdagesh: 0xFB47,
  28193. qofdageshhebrew: 0xFB47,
  28194. qofhebrew: 0x05E7,
  28195. qparen: 0x24AC,
  28196. quarternote: 0x2669,
  28197. qubuts: 0x05BB,
  28198. qubuts18: 0x05BB,
  28199. qubuts25: 0x05BB,
  28200. qubuts31: 0x05BB,
  28201. qubutshebrew: 0x05BB,
  28202. qubutsnarrowhebrew: 0x05BB,
  28203. qubutsquarterhebrew: 0x05BB,
  28204. qubutswidehebrew: 0x05BB,
  28205. question: 0x003F,
  28206. questionarabic: 0x061F,
  28207. questionarmenian: 0x055E,
  28208. questiondown: 0x00BF,
  28209. questiondownsmall: 0xF7BF,
  28210. questiongreek: 0x037E,
  28211. questionmonospace: 0xFF1F,
  28212. questionsmall: 0xF73F,
  28213. quotedbl: 0x0022,
  28214. quotedblbase: 0x201E,
  28215. quotedblleft: 0x201C,
  28216. quotedblmonospace: 0xFF02,
  28217. quotedblprime: 0x301E,
  28218. quotedblprimereversed: 0x301D,
  28219. quotedblright: 0x201D,
  28220. quoteleft: 0x2018,
  28221. quoteleftreversed: 0x201B,
  28222. quotereversed: 0x201B,
  28223. quoteright: 0x2019,
  28224. quoterightn: 0x0149,
  28225. quotesinglbase: 0x201A,
  28226. quotesingle: 0x0027,
  28227. quotesinglemonospace: 0xFF07,
  28228. r: 0x0072,
  28229. raarmenian: 0x057C,
  28230. rabengali: 0x09B0,
  28231. racute: 0x0155,
  28232. radeva: 0x0930,
  28233. radical: 0x221A,
  28234. radicalex: 0xF8E5,
  28235. radoverssquare: 0x33AE,
  28236. radoverssquaredsquare: 0x33AF,
  28237. radsquare: 0x33AD,
  28238. rafe: 0x05BF,
  28239. rafehebrew: 0x05BF,
  28240. ragujarati: 0x0AB0,
  28241. ragurmukhi: 0x0A30,
  28242. rahiragana: 0x3089,
  28243. rakatakana: 0x30E9,
  28244. rakatakanahalfwidth: 0xFF97,
  28245. ralowerdiagonalbengali: 0x09F1,
  28246. ramiddlediagonalbengali: 0x09F0,
  28247. ramshorn: 0x0264,
  28248. ratio: 0x2236,
  28249. rbopomofo: 0x3116,
  28250. rcaron: 0x0159,
  28251. rcedilla: 0x0157,
  28252. rcircle: 0x24E1,
  28253. rcommaaccent: 0x0157,
  28254. rdblgrave: 0x0211,
  28255. rdotaccent: 0x1E59,
  28256. rdotbelow: 0x1E5B,
  28257. rdotbelowmacron: 0x1E5D,
  28258. referencemark: 0x203B,
  28259. reflexsubset: 0x2286,
  28260. reflexsuperset: 0x2287,
  28261. registered: 0x00AE,
  28262. registersans: 0xF8E8,
  28263. registerserif: 0xF6DA,
  28264. reharabic: 0x0631,
  28265. reharmenian: 0x0580,
  28266. rehfinalarabic: 0xFEAE,
  28267. rehiragana: 0x308C,
  28268. rekatakana: 0x30EC,
  28269. rekatakanahalfwidth: 0xFF9A,
  28270. resh: 0x05E8,
  28271. reshdageshhebrew: 0xFB48,
  28272. reshhebrew: 0x05E8,
  28273. reversedtilde: 0x223D,
  28274. reviahebrew: 0x0597,
  28275. reviamugrashhebrew: 0x0597,
  28276. revlogicalnot: 0x2310,
  28277. rfishhook: 0x027E,
  28278. rfishhookreversed: 0x027F,
  28279. rhabengali: 0x09DD,
  28280. rhadeva: 0x095D,
  28281. rho: 0x03C1,
  28282. rhook: 0x027D,
  28283. rhookturned: 0x027B,
  28284. rhookturnedsuperior: 0x02B5,
  28285. rhosymbolgreek: 0x03F1,
  28286. rhotichookmod: 0x02DE,
  28287. rieulacirclekorean: 0x3271,
  28288. rieulaparenkorean: 0x3211,
  28289. rieulcirclekorean: 0x3263,
  28290. rieulhieuhkorean: 0x3140,
  28291. rieulkiyeokkorean: 0x313A,
  28292. rieulkiyeoksioskorean: 0x3169,
  28293. rieulkorean: 0x3139,
  28294. rieulmieumkorean: 0x313B,
  28295. rieulpansioskorean: 0x316C,
  28296. rieulparenkorean: 0x3203,
  28297. rieulphieuphkorean: 0x313F,
  28298. rieulpieupkorean: 0x313C,
  28299. rieulpieupsioskorean: 0x316B,
  28300. rieulsioskorean: 0x313D,
  28301. rieulthieuthkorean: 0x313E,
  28302. rieultikeutkorean: 0x316A,
  28303. rieulyeorinhieuhkorean: 0x316D,
  28304. rightangle: 0x221F,
  28305. righttackbelowcmb: 0x0319,
  28306. righttriangle: 0x22BF,
  28307. rihiragana: 0x308A,
  28308. rikatakana: 0x30EA,
  28309. rikatakanahalfwidth: 0xFF98,
  28310. ring: 0x02DA,
  28311. ringbelowcmb: 0x0325,
  28312. ringcmb: 0x030A,
  28313. ringhalfleft: 0x02BF,
  28314. ringhalfleftarmenian: 0x0559,
  28315. ringhalfleftbelowcmb: 0x031C,
  28316. ringhalfleftcentered: 0x02D3,
  28317. ringhalfright: 0x02BE,
  28318. ringhalfrightbelowcmb: 0x0339,
  28319. ringhalfrightcentered: 0x02D2,
  28320. rinvertedbreve: 0x0213,
  28321. rittorusquare: 0x3351,
  28322. rlinebelow: 0x1E5F,
  28323. rlongleg: 0x027C,
  28324. rlonglegturned: 0x027A,
  28325. rmonospace: 0xFF52,
  28326. rohiragana: 0x308D,
  28327. rokatakana: 0x30ED,
  28328. rokatakanahalfwidth: 0xFF9B,
  28329. roruathai: 0x0E23,
  28330. rparen: 0x24AD,
  28331. rrabengali: 0x09DC,
  28332. rradeva: 0x0931,
  28333. rragurmukhi: 0x0A5C,
  28334. rreharabic: 0x0691,
  28335. rrehfinalarabic: 0xFB8D,
  28336. rrvocalicbengali: 0x09E0,
  28337. rrvocalicdeva: 0x0960,
  28338. rrvocalicgujarati: 0x0AE0,
  28339. rrvocalicvowelsignbengali: 0x09C4,
  28340. rrvocalicvowelsigndeva: 0x0944,
  28341. rrvocalicvowelsigngujarati: 0x0AC4,
  28342. rsuperior: 0xF6F1,
  28343. rtblock: 0x2590,
  28344. rturned: 0x0279,
  28345. rturnedsuperior: 0x02B4,
  28346. ruhiragana: 0x308B,
  28347. rukatakana: 0x30EB,
  28348. rukatakanahalfwidth: 0xFF99,
  28349. rupeemarkbengali: 0x09F2,
  28350. rupeesignbengali: 0x09F3,
  28351. rupiah: 0xF6DD,
  28352. ruthai: 0x0E24,
  28353. rvocalicbengali: 0x098B,
  28354. rvocalicdeva: 0x090B,
  28355. rvocalicgujarati: 0x0A8B,
  28356. rvocalicvowelsignbengali: 0x09C3,
  28357. rvocalicvowelsigndeva: 0x0943,
  28358. rvocalicvowelsigngujarati: 0x0AC3,
  28359. s: 0x0073,
  28360. sabengali: 0x09B8,
  28361. sacute: 0x015B,
  28362. sacutedotaccent: 0x1E65,
  28363. sadarabic: 0x0635,
  28364. sadeva: 0x0938,
  28365. sadfinalarabic: 0xFEBA,
  28366. sadinitialarabic: 0xFEBB,
  28367. sadmedialarabic: 0xFEBC,
  28368. sagujarati: 0x0AB8,
  28369. sagurmukhi: 0x0A38,
  28370. sahiragana: 0x3055,
  28371. sakatakana: 0x30B5,
  28372. sakatakanahalfwidth: 0xFF7B,
  28373. sallallahoualayhewasallamarabic: 0xFDFA,
  28374. samekh: 0x05E1,
  28375. samekhdagesh: 0xFB41,
  28376. samekhdageshhebrew: 0xFB41,
  28377. samekhhebrew: 0x05E1,
  28378. saraaathai: 0x0E32,
  28379. saraaethai: 0x0E41,
  28380. saraaimaimalaithai: 0x0E44,
  28381. saraaimaimuanthai: 0x0E43,
  28382. saraamthai: 0x0E33,
  28383. saraathai: 0x0E30,
  28384. saraethai: 0x0E40,
  28385. saraiileftthai: 0xF886,
  28386. saraiithai: 0x0E35,
  28387. saraileftthai: 0xF885,
  28388. saraithai: 0x0E34,
  28389. saraothai: 0x0E42,
  28390. saraueeleftthai: 0xF888,
  28391. saraueethai: 0x0E37,
  28392. saraueleftthai: 0xF887,
  28393. sarauethai: 0x0E36,
  28394. sarauthai: 0x0E38,
  28395. sarauuthai: 0x0E39,
  28396. sbopomofo: 0x3119,
  28397. scaron: 0x0161,
  28398. scarondotaccent: 0x1E67,
  28399. scedilla: 0x015F,
  28400. schwa: 0x0259,
  28401. schwacyrillic: 0x04D9,
  28402. schwadieresiscyrillic: 0x04DB,
  28403. schwahook: 0x025A,
  28404. scircle: 0x24E2,
  28405. scircumflex: 0x015D,
  28406. scommaaccent: 0x0219,
  28407. sdotaccent: 0x1E61,
  28408. sdotbelow: 0x1E63,
  28409. sdotbelowdotaccent: 0x1E69,
  28410. seagullbelowcmb: 0x033C,
  28411. second: 0x2033,
  28412. secondtonechinese: 0x02CA,
  28413. section: 0x00A7,
  28414. seenarabic: 0x0633,
  28415. seenfinalarabic: 0xFEB2,
  28416. seeninitialarabic: 0xFEB3,
  28417. seenmedialarabic: 0xFEB4,
  28418. segol: 0x05B6,
  28419. segol13: 0x05B6,
  28420. segol1f: 0x05B6,
  28421. segol2c: 0x05B6,
  28422. segolhebrew: 0x05B6,
  28423. segolnarrowhebrew: 0x05B6,
  28424. segolquarterhebrew: 0x05B6,
  28425. segoltahebrew: 0x0592,
  28426. segolwidehebrew: 0x05B6,
  28427. seharmenian: 0x057D,
  28428. sehiragana: 0x305B,
  28429. sekatakana: 0x30BB,
  28430. sekatakanahalfwidth: 0xFF7E,
  28431. semicolon: 0x003B,
  28432. semicolonarabic: 0x061B,
  28433. semicolonmonospace: 0xFF1B,
  28434. semicolonsmall: 0xFE54,
  28435. semivoicedmarkkana: 0x309C,
  28436. semivoicedmarkkanahalfwidth: 0xFF9F,
  28437. sentisquare: 0x3322,
  28438. sentosquare: 0x3323,
  28439. seven: 0x0037,
  28440. sevenarabic: 0x0667,
  28441. sevenbengali: 0x09ED,
  28442. sevencircle: 0x2466,
  28443. sevencircleinversesansserif: 0x2790,
  28444. sevendeva: 0x096D,
  28445. seveneighths: 0x215E,
  28446. sevengujarati: 0x0AED,
  28447. sevengurmukhi: 0x0A6D,
  28448. sevenhackarabic: 0x0667,
  28449. sevenhangzhou: 0x3027,
  28450. sevenideographicparen: 0x3226,
  28451. seveninferior: 0x2087,
  28452. sevenmonospace: 0xFF17,
  28453. sevenoldstyle: 0xF737,
  28454. sevenparen: 0x247A,
  28455. sevenperiod: 0x248E,
  28456. sevenpersian: 0x06F7,
  28457. sevenroman: 0x2176,
  28458. sevensuperior: 0x2077,
  28459. seventeencircle: 0x2470,
  28460. seventeenparen: 0x2484,
  28461. seventeenperiod: 0x2498,
  28462. seventhai: 0x0E57,
  28463. sfthyphen: 0x00AD,
  28464. shaarmenian: 0x0577,
  28465. shabengali: 0x09B6,
  28466. shacyrillic: 0x0448,
  28467. shaddaarabic: 0x0651,
  28468. shaddadammaarabic: 0xFC61,
  28469. shaddadammatanarabic: 0xFC5E,
  28470. shaddafathaarabic: 0xFC60,
  28471. shaddakasraarabic: 0xFC62,
  28472. shaddakasratanarabic: 0xFC5F,
  28473. shade: 0x2592,
  28474. shadedark: 0x2593,
  28475. shadelight: 0x2591,
  28476. shademedium: 0x2592,
  28477. shadeva: 0x0936,
  28478. shagujarati: 0x0AB6,
  28479. shagurmukhi: 0x0A36,
  28480. shalshelethebrew: 0x0593,
  28481. shbopomofo: 0x3115,
  28482. shchacyrillic: 0x0449,
  28483. sheenarabic: 0x0634,
  28484. sheenfinalarabic: 0xFEB6,
  28485. sheeninitialarabic: 0xFEB7,
  28486. sheenmedialarabic: 0xFEB8,
  28487. sheicoptic: 0x03E3,
  28488. sheqel: 0x20AA,
  28489. sheqelhebrew: 0x20AA,
  28490. sheva: 0x05B0,
  28491. sheva115: 0x05B0,
  28492. sheva15: 0x05B0,
  28493. sheva22: 0x05B0,
  28494. sheva2e: 0x05B0,
  28495. shevahebrew: 0x05B0,
  28496. shevanarrowhebrew: 0x05B0,
  28497. shevaquarterhebrew: 0x05B0,
  28498. shevawidehebrew: 0x05B0,
  28499. shhacyrillic: 0x04BB,
  28500. shimacoptic: 0x03ED,
  28501. shin: 0x05E9,
  28502. shindagesh: 0xFB49,
  28503. shindageshhebrew: 0xFB49,
  28504. shindageshshindot: 0xFB2C,
  28505. shindageshshindothebrew: 0xFB2C,
  28506. shindageshsindot: 0xFB2D,
  28507. shindageshsindothebrew: 0xFB2D,
  28508. shindothebrew: 0x05C1,
  28509. shinhebrew: 0x05E9,
  28510. shinshindot: 0xFB2A,
  28511. shinshindothebrew: 0xFB2A,
  28512. shinsindot: 0xFB2B,
  28513. shinsindothebrew: 0xFB2B,
  28514. shook: 0x0282,
  28515. sigma: 0x03C3,
  28516. sigma1: 0x03C2,
  28517. sigmafinal: 0x03C2,
  28518. sigmalunatesymbolgreek: 0x03F2,
  28519. sihiragana: 0x3057,
  28520. sikatakana: 0x30B7,
  28521. sikatakanahalfwidth: 0xFF7C,
  28522. siluqhebrew: 0x05BD,
  28523. siluqlefthebrew: 0x05BD,
  28524. similar: 0x223C,
  28525. sindothebrew: 0x05C2,
  28526. siosacirclekorean: 0x3274,
  28527. siosaparenkorean: 0x3214,
  28528. sioscieuckorean: 0x317E,
  28529. sioscirclekorean: 0x3266,
  28530. sioskiyeokkorean: 0x317A,
  28531. sioskorean: 0x3145,
  28532. siosnieunkorean: 0x317B,
  28533. siosparenkorean: 0x3206,
  28534. siospieupkorean: 0x317D,
  28535. siostikeutkorean: 0x317C,
  28536. six: 0x0036,
  28537. sixarabic: 0x0666,
  28538. sixbengali: 0x09EC,
  28539. sixcircle: 0x2465,
  28540. sixcircleinversesansserif: 0x278F,
  28541. sixdeva: 0x096C,
  28542. sixgujarati: 0x0AEC,
  28543. sixgurmukhi: 0x0A6C,
  28544. sixhackarabic: 0x0666,
  28545. sixhangzhou: 0x3026,
  28546. sixideographicparen: 0x3225,
  28547. sixinferior: 0x2086,
  28548. sixmonospace: 0xFF16,
  28549. sixoldstyle: 0xF736,
  28550. sixparen: 0x2479,
  28551. sixperiod: 0x248D,
  28552. sixpersian: 0x06F6,
  28553. sixroman: 0x2175,
  28554. sixsuperior: 0x2076,
  28555. sixteencircle: 0x246F,
  28556. sixteencurrencydenominatorbengali: 0x09F9,
  28557. sixteenparen: 0x2483,
  28558. sixteenperiod: 0x2497,
  28559. sixthai: 0x0E56,
  28560. slash: 0x002F,
  28561. slashmonospace: 0xFF0F,
  28562. slong: 0x017F,
  28563. slongdotaccent: 0x1E9B,
  28564. smileface: 0x263A,
  28565. smonospace: 0xFF53,
  28566. sofpasuqhebrew: 0x05C3,
  28567. softhyphen: 0x00AD,
  28568. softsigncyrillic: 0x044C,
  28569. sohiragana: 0x305D,
  28570. sokatakana: 0x30BD,
  28571. sokatakanahalfwidth: 0xFF7F,
  28572. soliduslongoverlaycmb: 0x0338,
  28573. solidusshortoverlaycmb: 0x0337,
  28574. sorusithai: 0x0E29,
  28575. sosalathai: 0x0E28,
  28576. sosothai: 0x0E0B,
  28577. sosuathai: 0x0E2A,
  28578. space: 0x0020,
  28579. spacehackarabic: 0x0020,
  28580. spade: 0x2660,
  28581. spadesuitblack: 0x2660,
  28582. spadesuitwhite: 0x2664,
  28583. sparen: 0x24AE,
  28584. squarebelowcmb: 0x033B,
  28585. squarecc: 0x33C4,
  28586. squarecm: 0x339D,
  28587. squarediagonalcrosshatchfill: 0x25A9,
  28588. squarehorizontalfill: 0x25A4,
  28589. squarekg: 0x338F,
  28590. squarekm: 0x339E,
  28591. squarekmcapital: 0x33CE,
  28592. squareln: 0x33D1,
  28593. squarelog: 0x33D2,
  28594. squaremg: 0x338E,
  28595. squaremil: 0x33D5,
  28596. squaremm: 0x339C,
  28597. squaremsquared: 0x33A1,
  28598. squareorthogonalcrosshatchfill: 0x25A6,
  28599. squareupperlefttolowerrightfill: 0x25A7,
  28600. squareupperrighttolowerleftfill: 0x25A8,
  28601. squareverticalfill: 0x25A5,
  28602. squarewhitewithsmallblack: 0x25A3,
  28603. srsquare: 0x33DB,
  28604. ssabengali: 0x09B7,
  28605. ssadeva: 0x0937,
  28606. ssagujarati: 0x0AB7,
  28607. ssangcieuckorean: 0x3149,
  28608. ssanghieuhkorean: 0x3185,
  28609. ssangieungkorean: 0x3180,
  28610. ssangkiyeokkorean: 0x3132,
  28611. ssangnieunkorean: 0x3165,
  28612. ssangpieupkorean: 0x3143,
  28613. ssangsioskorean: 0x3146,
  28614. ssangtikeutkorean: 0x3138,
  28615. ssuperior: 0xF6F2,
  28616. sterling: 0x00A3,
  28617. sterlingmonospace: 0xFFE1,
  28618. strokelongoverlaycmb: 0x0336,
  28619. strokeshortoverlaycmb: 0x0335,
  28620. subset: 0x2282,
  28621. subsetnotequal: 0x228A,
  28622. subsetorequal: 0x2286,
  28623. succeeds: 0x227B,
  28624. suchthat: 0x220B,
  28625. suhiragana: 0x3059,
  28626. sukatakana: 0x30B9,
  28627. sukatakanahalfwidth: 0xFF7D,
  28628. sukunarabic: 0x0652,
  28629. summation: 0x2211,
  28630. sun: 0x263C,
  28631. superset: 0x2283,
  28632. supersetnotequal: 0x228B,
  28633. supersetorequal: 0x2287,
  28634. svsquare: 0x33DC,
  28635. syouwaerasquare: 0x337C,
  28636. t: 0x0074,
  28637. tabengali: 0x09A4,
  28638. tackdown: 0x22A4,
  28639. tackleft: 0x22A3,
  28640. tadeva: 0x0924,
  28641. tagujarati: 0x0AA4,
  28642. tagurmukhi: 0x0A24,
  28643. taharabic: 0x0637,
  28644. tahfinalarabic: 0xFEC2,
  28645. tahinitialarabic: 0xFEC3,
  28646. tahiragana: 0x305F,
  28647. tahmedialarabic: 0xFEC4,
  28648. taisyouerasquare: 0x337D,
  28649. takatakana: 0x30BF,
  28650. takatakanahalfwidth: 0xFF80,
  28651. tatweelarabic: 0x0640,
  28652. tau: 0x03C4,
  28653. tav: 0x05EA,
  28654. tavdages: 0xFB4A,
  28655. tavdagesh: 0xFB4A,
  28656. tavdageshhebrew: 0xFB4A,
  28657. tavhebrew: 0x05EA,
  28658. tbar: 0x0167,
  28659. tbopomofo: 0x310A,
  28660. tcaron: 0x0165,
  28661. tccurl: 0x02A8,
  28662. tcedilla: 0x0163,
  28663. tcheharabic: 0x0686,
  28664. tchehfinalarabic: 0xFB7B,
  28665. tchehinitialarabic: 0xFB7C,
  28666. tchehmedialarabic: 0xFB7D,
  28667. tcircle: 0x24E3,
  28668. tcircumflexbelow: 0x1E71,
  28669. tcommaaccent: 0x0163,
  28670. tdieresis: 0x1E97,
  28671. tdotaccent: 0x1E6B,
  28672. tdotbelow: 0x1E6D,
  28673. tecyrillic: 0x0442,
  28674. tedescendercyrillic: 0x04AD,
  28675. teharabic: 0x062A,
  28676. tehfinalarabic: 0xFE96,
  28677. tehhahinitialarabic: 0xFCA2,
  28678. tehhahisolatedarabic: 0xFC0C,
  28679. tehinitialarabic: 0xFE97,
  28680. tehiragana: 0x3066,
  28681. tehjeeminitialarabic: 0xFCA1,
  28682. tehjeemisolatedarabic: 0xFC0B,
  28683. tehmarbutaarabic: 0x0629,
  28684. tehmarbutafinalarabic: 0xFE94,
  28685. tehmedialarabic: 0xFE98,
  28686. tehmeeminitialarabic: 0xFCA4,
  28687. tehmeemisolatedarabic: 0xFC0E,
  28688. tehnoonfinalarabic: 0xFC73,
  28689. tekatakana: 0x30C6,
  28690. tekatakanahalfwidth: 0xFF83,
  28691. telephone: 0x2121,
  28692. telephoneblack: 0x260E,
  28693. telishagedolahebrew: 0x05A0,
  28694. telishaqetanahebrew: 0x05A9,
  28695. tencircle: 0x2469,
  28696. tenideographicparen: 0x3229,
  28697. tenparen: 0x247D,
  28698. tenperiod: 0x2491,
  28699. tenroman: 0x2179,
  28700. tesh: 0x02A7,
  28701. tet: 0x05D8,
  28702. tetdagesh: 0xFB38,
  28703. tetdageshhebrew: 0xFB38,
  28704. tethebrew: 0x05D8,
  28705. tetsecyrillic: 0x04B5,
  28706. tevirhebrew: 0x059B,
  28707. tevirlefthebrew: 0x059B,
  28708. thabengali: 0x09A5,
  28709. thadeva: 0x0925,
  28710. thagujarati: 0x0AA5,
  28711. thagurmukhi: 0x0A25,
  28712. thalarabic: 0x0630,
  28713. thalfinalarabic: 0xFEAC,
  28714. thanthakhatlowleftthai: 0xF898,
  28715. thanthakhatlowrightthai: 0xF897,
  28716. thanthakhatthai: 0x0E4C,
  28717. thanthakhatupperleftthai: 0xF896,
  28718. theharabic: 0x062B,
  28719. thehfinalarabic: 0xFE9A,
  28720. thehinitialarabic: 0xFE9B,
  28721. thehmedialarabic: 0xFE9C,
  28722. thereexists: 0x2203,
  28723. therefore: 0x2234,
  28724. theta: 0x03B8,
  28725. theta1: 0x03D1,
  28726. thetasymbolgreek: 0x03D1,
  28727. thieuthacirclekorean: 0x3279,
  28728. thieuthaparenkorean: 0x3219,
  28729. thieuthcirclekorean: 0x326B,
  28730. thieuthkorean: 0x314C,
  28731. thieuthparenkorean: 0x320B,
  28732. thirteencircle: 0x246C,
  28733. thirteenparen: 0x2480,
  28734. thirteenperiod: 0x2494,
  28735. thonangmonthothai: 0x0E11,
  28736. thook: 0x01AD,
  28737. thophuthaothai: 0x0E12,
  28738. thorn: 0x00FE,
  28739. thothahanthai: 0x0E17,
  28740. thothanthai: 0x0E10,
  28741. thothongthai: 0x0E18,
  28742. thothungthai: 0x0E16,
  28743. thousandcyrillic: 0x0482,
  28744. thousandsseparatorarabic: 0x066C,
  28745. thousandsseparatorpersian: 0x066C,
  28746. three: 0x0033,
  28747. threearabic: 0x0663,
  28748. threebengali: 0x09E9,
  28749. threecircle: 0x2462,
  28750. threecircleinversesansserif: 0x278C,
  28751. threedeva: 0x0969,
  28752. threeeighths: 0x215C,
  28753. threegujarati: 0x0AE9,
  28754. threegurmukhi: 0x0A69,
  28755. threehackarabic: 0x0663,
  28756. threehangzhou: 0x3023,
  28757. threeideographicparen: 0x3222,
  28758. threeinferior: 0x2083,
  28759. threemonospace: 0xFF13,
  28760. threenumeratorbengali: 0x09F6,
  28761. threeoldstyle: 0xF733,
  28762. threeparen: 0x2476,
  28763. threeperiod: 0x248A,
  28764. threepersian: 0x06F3,
  28765. threequarters: 0x00BE,
  28766. threequartersemdash: 0xF6DE,
  28767. threeroman: 0x2172,
  28768. threesuperior: 0x00B3,
  28769. threethai: 0x0E53,
  28770. thzsquare: 0x3394,
  28771. tihiragana: 0x3061,
  28772. tikatakana: 0x30C1,
  28773. tikatakanahalfwidth: 0xFF81,
  28774. tikeutacirclekorean: 0x3270,
  28775. tikeutaparenkorean: 0x3210,
  28776. tikeutcirclekorean: 0x3262,
  28777. tikeutkorean: 0x3137,
  28778. tikeutparenkorean: 0x3202,
  28779. tilde: 0x02DC,
  28780. tildebelowcmb: 0x0330,
  28781. tildecmb: 0x0303,
  28782. tildecomb: 0x0303,
  28783. tildedoublecmb: 0x0360,
  28784. tildeoperator: 0x223C,
  28785. tildeoverlaycmb: 0x0334,
  28786. tildeverticalcmb: 0x033E,
  28787. timescircle: 0x2297,
  28788. tipehahebrew: 0x0596,
  28789. tipehalefthebrew: 0x0596,
  28790. tippigurmukhi: 0x0A70,
  28791. titlocyrilliccmb: 0x0483,
  28792. tiwnarmenian: 0x057F,
  28793. tlinebelow: 0x1E6F,
  28794. tmonospace: 0xFF54,
  28795. toarmenian: 0x0569,
  28796. tohiragana: 0x3068,
  28797. tokatakana: 0x30C8,
  28798. tokatakanahalfwidth: 0xFF84,
  28799. tonebarextrahighmod: 0x02E5,
  28800. tonebarextralowmod: 0x02E9,
  28801. tonebarhighmod: 0x02E6,
  28802. tonebarlowmod: 0x02E8,
  28803. tonebarmidmod: 0x02E7,
  28804. tonefive: 0x01BD,
  28805. tonesix: 0x0185,
  28806. tonetwo: 0x01A8,
  28807. tonos: 0x0384,
  28808. tonsquare: 0x3327,
  28809. topatakthai: 0x0E0F,
  28810. tortoiseshellbracketleft: 0x3014,
  28811. tortoiseshellbracketleftsmall: 0xFE5D,
  28812. tortoiseshellbracketleftvertical: 0xFE39,
  28813. tortoiseshellbracketright: 0x3015,
  28814. tortoiseshellbracketrightsmall: 0xFE5E,
  28815. tortoiseshellbracketrightvertical: 0xFE3A,
  28816. totaothai: 0x0E15,
  28817. tpalatalhook: 0x01AB,
  28818. tparen: 0x24AF,
  28819. trademark: 0x2122,
  28820. trademarksans: 0xF8EA,
  28821. trademarkserif: 0xF6DB,
  28822. tretroflexhook: 0x0288,
  28823. triagdn: 0x25BC,
  28824. triaglf: 0x25C4,
  28825. triagrt: 0x25BA,
  28826. triagup: 0x25B2,
  28827. ts: 0x02A6,
  28828. tsadi: 0x05E6,
  28829. tsadidagesh: 0xFB46,
  28830. tsadidageshhebrew: 0xFB46,
  28831. tsadihebrew: 0x05E6,
  28832. tsecyrillic: 0x0446,
  28833. tsere: 0x05B5,
  28834. tsere12: 0x05B5,
  28835. tsere1e: 0x05B5,
  28836. tsere2b: 0x05B5,
  28837. tserehebrew: 0x05B5,
  28838. tserenarrowhebrew: 0x05B5,
  28839. tserequarterhebrew: 0x05B5,
  28840. tserewidehebrew: 0x05B5,
  28841. tshecyrillic: 0x045B,
  28842. tsuperior: 0xF6F3,
  28843. ttabengali: 0x099F,
  28844. ttadeva: 0x091F,
  28845. ttagujarati: 0x0A9F,
  28846. ttagurmukhi: 0x0A1F,
  28847. tteharabic: 0x0679,
  28848. ttehfinalarabic: 0xFB67,
  28849. ttehinitialarabic: 0xFB68,
  28850. ttehmedialarabic: 0xFB69,
  28851. tthabengali: 0x09A0,
  28852. tthadeva: 0x0920,
  28853. tthagujarati: 0x0AA0,
  28854. tthagurmukhi: 0x0A20,
  28855. tturned: 0x0287,
  28856. tuhiragana: 0x3064,
  28857. tukatakana: 0x30C4,
  28858. tukatakanahalfwidth: 0xFF82,
  28859. tusmallhiragana: 0x3063,
  28860. tusmallkatakana: 0x30C3,
  28861. tusmallkatakanahalfwidth: 0xFF6F,
  28862. twelvecircle: 0x246B,
  28863. twelveparen: 0x247F,
  28864. twelveperiod: 0x2493,
  28865. twelveroman: 0x217B,
  28866. twentycircle: 0x2473,
  28867. twentyhangzhou: 0x5344,
  28868. twentyparen: 0x2487,
  28869. twentyperiod: 0x249B,
  28870. two: 0x0032,
  28871. twoarabic: 0x0662,
  28872. twobengali: 0x09E8,
  28873. twocircle: 0x2461,
  28874. twocircleinversesansserif: 0x278B,
  28875. twodeva: 0x0968,
  28876. twodotenleader: 0x2025,
  28877. twodotleader: 0x2025,
  28878. twodotleadervertical: 0xFE30,
  28879. twogujarati: 0x0AE8,
  28880. twogurmukhi: 0x0A68,
  28881. twohackarabic: 0x0662,
  28882. twohangzhou: 0x3022,
  28883. twoideographicparen: 0x3221,
  28884. twoinferior: 0x2082,
  28885. twomonospace: 0xFF12,
  28886. twonumeratorbengali: 0x09F5,
  28887. twooldstyle: 0xF732,
  28888. twoparen: 0x2475,
  28889. twoperiod: 0x2489,
  28890. twopersian: 0x06F2,
  28891. tworoman: 0x2171,
  28892. twostroke: 0x01BB,
  28893. twosuperior: 0x00B2,
  28894. twothai: 0x0E52,
  28895. twothirds: 0x2154,
  28896. u: 0x0075,
  28897. uacute: 0x00FA,
  28898. ubar: 0x0289,
  28899. ubengali: 0x0989,
  28900. ubopomofo: 0x3128,
  28901. ubreve: 0x016D,
  28902. ucaron: 0x01D4,
  28903. ucircle: 0x24E4,
  28904. ucircumflex: 0x00FB,
  28905. ucircumflexbelow: 0x1E77,
  28906. ucyrillic: 0x0443,
  28907. udattadeva: 0x0951,
  28908. udblacute: 0x0171,
  28909. udblgrave: 0x0215,
  28910. udeva: 0x0909,
  28911. udieresis: 0x00FC,
  28912. udieresisacute: 0x01D8,
  28913. udieresisbelow: 0x1E73,
  28914. udieresiscaron: 0x01DA,
  28915. udieresiscyrillic: 0x04F1,
  28916. udieresisgrave: 0x01DC,
  28917. udieresismacron: 0x01D6,
  28918. udotbelow: 0x1EE5,
  28919. ugrave: 0x00F9,
  28920. ugujarati: 0x0A89,
  28921. ugurmukhi: 0x0A09,
  28922. uhiragana: 0x3046,
  28923. uhookabove: 0x1EE7,
  28924. uhorn: 0x01B0,
  28925. uhornacute: 0x1EE9,
  28926. uhorndotbelow: 0x1EF1,
  28927. uhorngrave: 0x1EEB,
  28928. uhornhookabove: 0x1EED,
  28929. uhorntilde: 0x1EEF,
  28930. uhungarumlaut: 0x0171,
  28931. uhungarumlautcyrillic: 0x04F3,
  28932. uinvertedbreve: 0x0217,
  28933. ukatakana: 0x30A6,
  28934. ukatakanahalfwidth: 0xFF73,
  28935. ukcyrillic: 0x0479,
  28936. ukorean: 0x315C,
  28937. umacron: 0x016B,
  28938. umacroncyrillic: 0x04EF,
  28939. umacrondieresis: 0x1E7B,
  28940. umatragurmukhi: 0x0A41,
  28941. umonospace: 0xFF55,
  28942. underscore: 0x005F,
  28943. underscoredbl: 0x2017,
  28944. underscoremonospace: 0xFF3F,
  28945. underscorevertical: 0xFE33,
  28946. underscorewavy: 0xFE4F,
  28947. union: 0x222A,
  28948. universal: 0x2200,
  28949. uogonek: 0x0173,
  28950. uparen: 0x24B0,
  28951. upblock: 0x2580,
  28952. upperdothebrew: 0x05C4,
  28953. upsilon: 0x03C5,
  28954. upsilondieresis: 0x03CB,
  28955. upsilondieresistonos: 0x03B0,
  28956. upsilonlatin: 0x028A,
  28957. upsilontonos: 0x03CD,
  28958. uptackbelowcmb: 0x031D,
  28959. uptackmod: 0x02D4,
  28960. uragurmukhi: 0x0A73,
  28961. uring: 0x016F,
  28962. ushortcyrillic: 0x045E,
  28963. usmallhiragana: 0x3045,
  28964. usmallkatakana: 0x30A5,
  28965. usmallkatakanahalfwidth: 0xFF69,
  28966. ustraightcyrillic: 0x04AF,
  28967. ustraightstrokecyrillic: 0x04B1,
  28968. utilde: 0x0169,
  28969. utildeacute: 0x1E79,
  28970. utildebelow: 0x1E75,
  28971. uubengali: 0x098A,
  28972. uudeva: 0x090A,
  28973. uugujarati: 0x0A8A,
  28974. uugurmukhi: 0x0A0A,
  28975. uumatragurmukhi: 0x0A42,
  28976. uuvowelsignbengali: 0x09C2,
  28977. uuvowelsigndeva: 0x0942,
  28978. uuvowelsigngujarati: 0x0AC2,
  28979. uvowelsignbengali: 0x09C1,
  28980. uvowelsigndeva: 0x0941,
  28981. uvowelsigngujarati: 0x0AC1,
  28982. v: 0x0076,
  28983. vadeva: 0x0935,
  28984. vagujarati: 0x0AB5,
  28985. vagurmukhi: 0x0A35,
  28986. vakatakana: 0x30F7,
  28987. vav: 0x05D5,
  28988. vavdagesh: 0xFB35,
  28989. vavdagesh65: 0xFB35,
  28990. vavdageshhebrew: 0xFB35,
  28991. vavhebrew: 0x05D5,
  28992. vavholam: 0xFB4B,
  28993. vavholamhebrew: 0xFB4B,
  28994. vavvavhebrew: 0x05F0,
  28995. vavyodhebrew: 0x05F1,
  28996. vcircle: 0x24E5,
  28997. vdotbelow: 0x1E7F,
  28998. vecyrillic: 0x0432,
  28999. veharabic: 0x06A4,
  29000. vehfinalarabic: 0xFB6B,
  29001. vehinitialarabic: 0xFB6C,
  29002. vehmedialarabic: 0xFB6D,
  29003. vekatakana: 0x30F9,
  29004. venus: 0x2640,
  29005. verticalbar: 0x007C,
  29006. verticallineabovecmb: 0x030D,
  29007. verticallinebelowcmb: 0x0329,
  29008. verticallinelowmod: 0x02CC,
  29009. verticallinemod: 0x02C8,
  29010. vewarmenian: 0x057E,
  29011. vhook: 0x028B,
  29012. vikatakana: 0x30F8,
  29013. viramabengali: 0x09CD,
  29014. viramadeva: 0x094D,
  29015. viramagujarati: 0x0ACD,
  29016. visargabengali: 0x0983,
  29017. visargadeva: 0x0903,
  29018. visargagujarati: 0x0A83,
  29019. vmonospace: 0xFF56,
  29020. voarmenian: 0x0578,
  29021. voicediterationhiragana: 0x309E,
  29022. voicediterationkatakana: 0x30FE,
  29023. voicedmarkkana: 0x309B,
  29024. voicedmarkkanahalfwidth: 0xFF9E,
  29025. vokatakana: 0x30FA,
  29026. vparen: 0x24B1,
  29027. vtilde: 0x1E7D,
  29028. vturned: 0x028C,
  29029. vuhiragana: 0x3094,
  29030. vukatakana: 0x30F4,
  29031. w: 0x0077,
  29032. wacute: 0x1E83,
  29033. waekorean: 0x3159,
  29034. wahiragana: 0x308F,
  29035. wakatakana: 0x30EF,
  29036. wakatakanahalfwidth: 0xFF9C,
  29037. wakorean: 0x3158,
  29038. wasmallhiragana: 0x308E,
  29039. wasmallkatakana: 0x30EE,
  29040. wattosquare: 0x3357,
  29041. wavedash: 0x301C,
  29042. wavyunderscorevertical: 0xFE34,
  29043. wawarabic: 0x0648,
  29044. wawfinalarabic: 0xFEEE,
  29045. wawhamzaabovearabic: 0x0624,
  29046. wawhamzaabovefinalarabic: 0xFE86,
  29047. wbsquare: 0x33DD,
  29048. wcircle: 0x24E6,
  29049. wcircumflex: 0x0175,
  29050. wdieresis: 0x1E85,
  29051. wdotaccent: 0x1E87,
  29052. wdotbelow: 0x1E89,
  29053. wehiragana: 0x3091,
  29054. weierstrass: 0x2118,
  29055. wekatakana: 0x30F1,
  29056. wekorean: 0x315E,
  29057. weokorean: 0x315D,
  29058. wgrave: 0x1E81,
  29059. whitebullet: 0x25E6,
  29060. whitecircle: 0x25CB,
  29061. whitecircleinverse: 0x25D9,
  29062. whitecornerbracketleft: 0x300E,
  29063. whitecornerbracketleftvertical: 0xFE43,
  29064. whitecornerbracketright: 0x300F,
  29065. whitecornerbracketrightvertical: 0xFE44,
  29066. whitediamond: 0x25C7,
  29067. whitediamondcontainingblacksmalldiamond: 0x25C8,
  29068. whitedownpointingsmalltriangle: 0x25BF,
  29069. whitedownpointingtriangle: 0x25BD,
  29070. whiteleftpointingsmalltriangle: 0x25C3,
  29071. whiteleftpointingtriangle: 0x25C1,
  29072. whitelenticularbracketleft: 0x3016,
  29073. whitelenticularbracketright: 0x3017,
  29074. whiterightpointingsmalltriangle: 0x25B9,
  29075. whiterightpointingtriangle: 0x25B7,
  29076. whitesmallsquare: 0x25AB,
  29077. whitesmilingface: 0x263A,
  29078. whitesquare: 0x25A1,
  29079. whitestar: 0x2606,
  29080. whitetelephone: 0x260F,
  29081. whitetortoiseshellbracketleft: 0x3018,
  29082. whitetortoiseshellbracketright: 0x3019,
  29083. whiteuppointingsmalltriangle: 0x25B5,
  29084. whiteuppointingtriangle: 0x25B3,
  29085. wihiragana: 0x3090,
  29086. wikatakana: 0x30F0,
  29087. wikorean: 0x315F,
  29088. wmonospace: 0xFF57,
  29089. wohiragana: 0x3092,
  29090. wokatakana: 0x30F2,
  29091. wokatakanahalfwidth: 0xFF66,
  29092. won: 0x20A9,
  29093. wonmonospace: 0xFFE6,
  29094. wowaenthai: 0x0E27,
  29095. wparen: 0x24B2,
  29096. wring: 0x1E98,
  29097. wsuperior: 0x02B7,
  29098. wturned: 0x028D,
  29099. wynn: 0x01BF,
  29100. x: 0x0078,
  29101. xabovecmb: 0x033D,
  29102. xbopomofo: 0x3112,
  29103. xcircle: 0x24E7,
  29104. xdieresis: 0x1E8D,
  29105. xdotaccent: 0x1E8B,
  29106. xeharmenian: 0x056D,
  29107. xi: 0x03BE,
  29108. xmonospace: 0xFF58,
  29109. xparen: 0x24B3,
  29110. xsuperior: 0x02E3,
  29111. y: 0x0079,
  29112. yaadosquare: 0x334E,
  29113. yabengali: 0x09AF,
  29114. yacute: 0x00FD,
  29115. yadeva: 0x092F,
  29116. yaekorean: 0x3152,
  29117. yagujarati: 0x0AAF,
  29118. yagurmukhi: 0x0A2F,
  29119. yahiragana: 0x3084,
  29120. yakatakana: 0x30E4,
  29121. yakatakanahalfwidth: 0xFF94,
  29122. yakorean: 0x3151,
  29123. yamakkanthai: 0x0E4E,
  29124. yasmallhiragana: 0x3083,
  29125. yasmallkatakana: 0x30E3,
  29126. yasmallkatakanahalfwidth: 0xFF6C,
  29127. yatcyrillic: 0x0463,
  29128. ycircle: 0x24E8,
  29129. ycircumflex: 0x0177,
  29130. ydieresis: 0x00FF,
  29131. ydotaccent: 0x1E8F,
  29132. ydotbelow: 0x1EF5,
  29133. yeharabic: 0x064A,
  29134. yehbarreearabic: 0x06D2,
  29135. yehbarreefinalarabic: 0xFBAF,
  29136. yehfinalarabic: 0xFEF2,
  29137. yehhamzaabovearabic: 0x0626,
  29138. yehhamzaabovefinalarabic: 0xFE8A,
  29139. yehhamzaaboveinitialarabic: 0xFE8B,
  29140. yehhamzaabovemedialarabic: 0xFE8C,
  29141. yehinitialarabic: 0xFEF3,
  29142. yehmedialarabic: 0xFEF4,
  29143. yehmeeminitialarabic: 0xFCDD,
  29144. yehmeemisolatedarabic: 0xFC58,
  29145. yehnoonfinalarabic: 0xFC94,
  29146. yehthreedotsbelowarabic: 0x06D1,
  29147. yekorean: 0x3156,
  29148. yen: 0x00A5,
  29149. yenmonospace: 0xFFE5,
  29150. yeokorean: 0x3155,
  29151. yeorinhieuhkorean: 0x3186,
  29152. yerahbenyomohebrew: 0x05AA,
  29153. yerahbenyomolefthebrew: 0x05AA,
  29154. yericyrillic: 0x044B,
  29155. yerudieresiscyrillic: 0x04F9,
  29156. yesieungkorean: 0x3181,
  29157. yesieungpansioskorean: 0x3183,
  29158. yesieungsioskorean: 0x3182,
  29159. yetivhebrew: 0x059A,
  29160. ygrave: 0x1EF3,
  29161. yhook: 0x01B4,
  29162. yhookabove: 0x1EF7,
  29163. yiarmenian: 0x0575,
  29164. yicyrillic: 0x0457,
  29165. yikorean: 0x3162,
  29166. yinyang: 0x262F,
  29167. yiwnarmenian: 0x0582,
  29168. ymonospace: 0xFF59,
  29169. yod: 0x05D9,
  29170. yoddagesh: 0xFB39,
  29171. yoddageshhebrew: 0xFB39,
  29172. yodhebrew: 0x05D9,
  29173. yodyodhebrew: 0x05F2,
  29174. yodyodpatahhebrew: 0xFB1F,
  29175. yohiragana: 0x3088,
  29176. yoikorean: 0x3189,
  29177. yokatakana: 0x30E8,
  29178. yokatakanahalfwidth: 0xFF96,
  29179. yokorean: 0x315B,
  29180. yosmallhiragana: 0x3087,
  29181. yosmallkatakana: 0x30E7,
  29182. yosmallkatakanahalfwidth: 0xFF6E,
  29183. yotgreek: 0x03F3,
  29184. yoyaekorean: 0x3188,
  29185. yoyakorean: 0x3187,
  29186. yoyakthai: 0x0E22,
  29187. yoyingthai: 0x0E0D,
  29188. yparen: 0x24B4,
  29189. ypogegrammeni: 0x037A,
  29190. ypogegrammenigreekcmb: 0x0345,
  29191. yr: 0x01A6,
  29192. yring: 0x1E99,
  29193. ysuperior: 0x02B8,
  29194. ytilde: 0x1EF9,
  29195. yturned: 0x028E,
  29196. yuhiragana: 0x3086,
  29197. yuikorean: 0x318C,
  29198. yukatakana: 0x30E6,
  29199. yukatakanahalfwidth: 0xFF95,
  29200. yukorean: 0x3160,
  29201. yusbigcyrillic: 0x046B,
  29202. yusbigiotifiedcyrillic: 0x046D,
  29203. yuslittlecyrillic: 0x0467,
  29204. yuslittleiotifiedcyrillic: 0x0469,
  29205. yusmallhiragana: 0x3085,
  29206. yusmallkatakana: 0x30E5,
  29207. yusmallkatakanahalfwidth: 0xFF6D,
  29208. yuyekorean: 0x318B,
  29209. yuyeokorean: 0x318A,
  29210. yyabengali: 0x09DF,
  29211. yyadeva: 0x095F,
  29212. z: 0x007A,
  29213. zaarmenian: 0x0566,
  29214. zacute: 0x017A,
  29215. zadeva: 0x095B,
  29216. zagurmukhi: 0x0A5B,
  29217. zaharabic: 0x0638,
  29218. zahfinalarabic: 0xFEC6,
  29219. zahinitialarabic: 0xFEC7,
  29220. zahiragana: 0x3056,
  29221. zahmedialarabic: 0xFEC8,
  29222. zainarabic: 0x0632,
  29223. zainfinalarabic: 0xFEB0,
  29224. zakatakana: 0x30B6,
  29225. zaqefgadolhebrew: 0x0595,
  29226. zaqefqatanhebrew: 0x0594,
  29227. zarqahebrew: 0x0598,
  29228. zayin: 0x05D6,
  29229. zayindagesh: 0xFB36,
  29230. zayindageshhebrew: 0xFB36,
  29231. zayinhebrew: 0x05D6,
  29232. zbopomofo: 0x3117,
  29233. zcaron: 0x017E,
  29234. zcircle: 0x24E9,
  29235. zcircumflex: 0x1E91,
  29236. zcurl: 0x0291,
  29237. zdot: 0x017C,
  29238. zdotaccent: 0x017C,
  29239. zdotbelow: 0x1E93,
  29240. zecyrillic: 0x0437,
  29241. zedescendercyrillic: 0x0499,
  29242. zedieresiscyrillic: 0x04DF,
  29243. zehiragana: 0x305C,
  29244. zekatakana: 0x30BC,
  29245. zero: 0x0030,
  29246. zeroarabic: 0x0660,
  29247. zerobengali: 0x09E6,
  29248. zerodeva: 0x0966,
  29249. zerogujarati: 0x0AE6,
  29250. zerogurmukhi: 0x0A66,
  29251. zerohackarabic: 0x0660,
  29252. zeroinferior: 0x2080,
  29253. zeromonospace: 0xFF10,
  29254. zerooldstyle: 0xF730,
  29255. zeropersian: 0x06F0,
  29256. zerosuperior: 0x2070,
  29257. zerothai: 0x0E50,
  29258. zerowidthjoiner: 0xFEFF,
  29259. zerowidthnonjoiner: 0x200C,
  29260. zerowidthspace: 0x200B,
  29261. zeta: 0x03B6,
  29262. zhbopomofo: 0x3113,
  29263. zhearmenian: 0x056A,
  29264. zhebrevecyrillic: 0x04C2,
  29265. zhecyrillic: 0x0436,
  29266. zhedescendercyrillic: 0x0497,
  29267. zhedieresiscyrillic: 0x04DD,
  29268. zihiragana: 0x3058,
  29269. zikatakana: 0x30B8,
  29270. zinorhebrew: 0x05AE,
  29271. zlinebelow: 0x1E95,
  29272. zmonospace: 0xFF5A,
  29273. zohiragana: 0x305E,
  29274. zokatakana: 0x30BE,
  29275. zparen: 0x24B5,
  29276. zretroflexhook: 0x0290,
  29277. zstroke: 0x01B6,
  29278. zuhiragana: 0x305A,
  29279. zukatakana: 0x30BA,
  29280. '.notdef': 0x0000
  29281. };
  29282. var PDFImage = (function PDFImageClosure() {
  29283. /**
  29284. * Decode the image in the main thread if it supported. Resovles the promise
  29285. * when the image data is ready.
  29286. */
  29287. function handleImageData(handler, xref, res, image) {
  29288. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  29289. // For natively supported jpegs send them to the main thread for decoding.
  29290. var dict = image.dict;
  29291. var colorSpace = dict.get('ColorSpace', 'CS');
  29292. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  29293. var numComps = colorSpace.numComps;
  29294. var decodePromise = handler.sendWithPromise('JpegDecode',
  29295. [image.getIR(), numComps]);
  29296. return decodePromise.then(function (message) {
  29297. var data = message.data;
  29298. return new Stream(data, 0, data.length, image.dict);
  29299. });
  29300. } else {
  29301. return Promise.resolve(image);
  29302. }
  29303. }
  29304. /**
  29305. * Decode and clamp a value. The formula is different from the spec because we
  29306. * don't decode to float range [0,1], we decode it in the [0,max] range.
  29307. */
  29308. function decodeAndClamp(value, addend, coefficient, max) {
  29309. value = addend + value * coefficient;
  29310. // Clamp the value to the range
  29311. return (value < 0 ? 0 : (value > max ? max : value));
  29312. }
  29313. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  29314. this.image = image;
  29315. var dict = image.dict;
  29316. if (dict.has('Filter')) {
  29317. var filter = dict.get('Filter').name;
  29318. if (filter === 'JPXDecode') {
  29319. var jpxImage = new JpxImage();
  29320. jpxImage.parseImageProperties(image.stream);
  29321. image.stream.reset();
  29322. image.bitsPerComponent = jpxImage.bitsPerComponent;
  29323. image.numComps = jpxImage.componentsCount;
  29324. } else if (filter === 'JBIG2Decode') {
  29325. image.bitsPerComponent = 1;
  29326. image.numComps = 1;
  29327. }
  29328. }
  29329. // TODO cache rendered images?
  29330. this.width = dict.get('Width', 'W');
  29331. this.height = dict.get('Height', 'H');
  29332. if (this.width < 1 || this.height < 1) {
  29333. error('Invalid image width: ' + this.width + ' or height: ' +
  29334. this.height);
  29335. }
  29336. this.interpolate = dict.get('Interpolate', 'I') || false;
  29337. this.imageMask = dict.get('ImageMask', 'IM') || false;
  29338. this.matte = dict.get('Matte') || false;
  29339. var bitsPerComponent = image.bitsPerComponent;
  29340. if (!bitsPerComponent) {
  29341. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  29342. if (!bitsPerComponent) {
  29343. if (this.imageMask) {
  29344. bitsPerComponent = 1;
  29345. } else {
  29346. error('Bits per component missing in image: ' + this.imageMask);
  29347. }
  29348. }
  29349. }
  29350. this.bpc = bitsPerComponent;
  29351. if (!this.imageMask) {
  29352. var colorSpace = dict.get('ColorSpace', 'CS');
  29353. if (!colorSpace) {
  29354. info('JPX images (which do not require color spaces)');
  29355. switch (image.numComps) {
  29356. case 1:
  29357. colorSpace = Name.get('DeviceGray');
  29358. break;
  29359. case 3:
  29360. colorSpace = Name.get('DeviceRGB');
  29361. break;
  29362. case 4:
  29363. colorSpace = Name.get('DeviceCMYK');
  29364. break;
  29365. default:
  29366. error('JPX images with ' + this.numComps +
  29367. ' color components not supported.');
  29368. }
  29369. }
  29370. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  29371. this.numComps = this.colorSpace.numComps;
  29372. }
  29373. this.decode = dict.get('Decode', 'D');
  29374. this.needsDecode = false;
  29375. if (this.decode &&
  29376. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  29377. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  29378. this.needsDecode = true;
  29379. // Do some preprocessing to avoid more math.
  29380. var max = (1 << bitsPerComponent) - 1;
  29381. this.decodeCoefficients = [];
  29382. this.decodeAddends = [];
  29383. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  29384. var dmin = this.decode[i];
  29385. var dmax = this.decode[i + 1];
  29386. this.decodeCoefficients[j] = dmax - dmin;
  29387. this.decodeAddends[j] = max * dmin;
  29388. }
  29389. }
  29390. if (smask) {
  29391. this.smask = new PDFImage(xref, res, smask, false);
  29392. } else if (mask) {
  29393. if (isStream(mask)) {
  29394. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  29395. } else {
  29396. // Color key mask (just an array).
  29397. this.mask = mask;
  29398. }
  29399. }
  29400. }
  29401. /**
  29402. * Handles processing of image data and returns the Promise that is resolved
  29403. * with a PDFImage when the image is ready to be used.
  29404. */
  29405. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  29406. res, image, inline) {
  29407. var imagePromise = handleImageData(handler, xref, res, image);
  29408. var smaskPromise;
  29409. var maskPromise;
  29410. var smask = image.dict.get('SMask');
  29411. var mask = image.dict.get('Mask');
  29412. if (smask) {
  29413. smaskPromise = handleImageData(handler, xref, res, smask);
  29414. maskPromise = Promise.resolve(null);
  29415. } else {
  29416. smaskPromise = Promise.resolve(null);
  29417. if (mask) {
  29418. if (isStream(mask)) {
  29419. maskPromise = handleImageData(handler, xref, res, mask);
  29420. } else if (isArray(mask)) {
  29421. maskPromise = Promise.resolve(mask);
  29422. } else {
  29423. warn('Unsupported mask format.');
  29424. maskPromise = Promise.resolve(null);
  29425. }
  29426. } else {
  29427. maskPromise = Promise.resolve(null);
  29428. }
  29429. }
  29430. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  29431. function(results) {
  29432. var imageData = results[0];
  29433. var smaskData = results[1];
  29434. var maskData = results[2];
  29435. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  29436. });
  29437. };
  29438. /**
  29439. * Resize an image using the nearest neighbor algorithm. Currently only
  29440. * supports one and three component images.
  29441. * @param {TypedArray} pixels The original image with one component.
  29442. * @param {Number} bpc Number of bits per component.
  29443. * @param {Number} components Number of color components, 1 or 3 is supported.
  29444. * @param {Number} w1 Original width.
  29445. * @param {Number} h1 Original height.
  29446. * @param {Number} w2 New width.
  29447. * @param {Number} h2 New height.
  29448. * @param {TypedArray} dest (Optional) The destination buffer.
  29449. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  29450. * @return {TypedArray} Resized image data.
  29451. */
  29452. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  29453. w1, h1, w2, h2, dest, alpha01) {
  29454. if (components !== 1 && components !== 3) {
  29455. error('Unsupported component count for resizing.');
  29456. }
  29457. var length = w2 * h2 * components;
  29458. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  29459. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  29460. var xRatio = w1 / w2;
  29461. var yRatio = h1 / h2;
  29462. var i, j, py, newIndex = 0, oldIndex;
  29463. var xScaled = new Uint16Array(w2);
  29464. var w1Scanline = w1 * components;
  29465. if (alpha01 !== 1) {
  29466. alpha01 = 0;
  29467. }
  29468. for (j = 0; j < w2; j++) {
  29469. xScaled[j] = Math.floor(j * xRatio) * components;
  29470. }
  29471. if (components === 1) {
  29472. for (i = 0; i < h2; i++) {
  29473. py = Math.floor(i * yRatio) * w1Scanline;
  29474. for (j = 0; j < w2; j++) {
  29475. oldIndex = py + xScaled[j];
  29476. temp[newIndex++] = pixels[oldIndex];
  29477. }
  29478. }
  29479. } else if (components === 3) {
  29480. for (i = 0; i < h2; i++) {
  29481. py = Math.floor(i * yRatio) * w1Scanline;
  29482. for (j = 0; j < w2; j++) {
  29483. oldIndex = py + xScaled[j];
  29484. temp[newIndex++] = pixels[oldIndex++];
  29485. temp[newIndex++] = pixels[oldIndex++];
  29486. temp[newIndex++] = pixels[oldIndex++];
  29487. newIndex += alpha01;
  29488. }
  29489. }
  29490. }
  29491. return temp;
  29492. };
  29493. PDFImage.createMask =
  29494. function PDFImage_createMask(imgArray, width, height,
  29495. imageIsFromDecodeStream, inverseDecode) {
  29496. // |imgArray| might not contain full data for every pixel of the mask, so
  29497. // we need to distinguish between |computedLength| and |actualLength|.
  29498. // In particular, if inverseDecode is true, then the array we return must
  29499. // have a length of |computedLength|.
  29500. var computedLength = ((width + 7) >> 3) * height;
  29501. var actualLength = imgArray.byteLength;
  29502. var haveFullData = computedLength === actualLength;
  29503. var data, i;
  29504. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  29505. // imgArray came from a DecodeStream and its data is in an appropriate
  29506. // form, so we can just transfer it.
  29507. data = imgArray;
  29508. } else if (!inverseDecode) {
  29509. data = new Uint8Array(actualLength);
  29510. data.set(imgArray);
  29511. } else {
  29512. data = new Uint8Array(computedLength);
  29513. data.set(imgArray);
  29514. for (i = actualLength; i < computedLength; i++) {
  29515. data[i] = 0xff;
  29516. }
  29517. }
  29518. // If necessary, invert the original mask data (but not any extra we might
  29519. // have added above). It's safe to modify the array -- whether it's the
  29520. // original or a copy, we're about to transfer it anyway, so nothing else
  29521. // in this thread can be relying on its contents.
  29522. if (inverseDecode) {
  29523. for (i = 0; i < actualLength; i++) {
  29524. data[i] = ~data[i];
  29525. }
  29526. }
  29527. return {data: data, width: width, height: height};
  29528. };
  29529. PDFImage.prototype = {
  29530. get drawWidth() {
  29531. return Math.max(this.width,
  29532. this.smask && this.smask.width || 0,
  29533. this.mask && this.mask.width || 0);
  29534. },
  29535. get drawHeight() {
  29536. return Math.max(this.height,
  29537. this.smask && this.smask.height || 0,
  29538. this.mask && this.mask.height || 0);
  29539. },
  29540. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  29541. var bpc = this.bpc;
  29542. var numComps = this.numComps;
  29543. var decodeAddends = this.decodeAddends;
  29544. var decodeCoefficients = this.decodeCoefficients;
  29545. var max = (1 << bpc) - 1;
  29546. var i, ii;
  29547. if (bpc === 1) {
  29548. // If the buffer needed decode that means it just needs to be inverted.
  29549. for (i = 0, ii = buffer.length; i < ii; i++) {
  29550. buffer[i] = +!(buffer[i]);
  29551. }
  29552. return;
  29553. }
  29554. var index = 0;
  29555. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  29556. for (var j = 0; j < numComps; j++) {
  29557. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  29558. decodeCoefficients[j], max);
  29559. index++;
  29560. }
  29561. }
  29562. },
  29563. getComponents: function PDFImage_getComponents(buffer) {
  29564. var bpc = this.bpc;
  29565. // This image doesn't require any extra work.
  29566. if (bpc === 8) {
  29567. return buffer;
  29568. }
  29569. var width = this.width;
  29570. var height = this.height;
  29571. var numComps = this.numComps;
  29572. var length = width * height * numComps;
  29573. var bufferPos = 0;
  29574. var output = (bpc <= 8 ? new Uint8Array(length) :
  29575. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  29576. var rowComps = width * numComps;
  29577. var max = (1 << bpc) - 1;
  29578. var i = 0, ii, buf;
  29579. if (bpc === 1) {
  29580. // Optimization for reading 1 bpc images.
  29581. var mask, loop1End, loop2End;
  29582. for (var j = 0; j < height; j++) {
  29583. loop1End = i + (rowComps & ~7);
  29584. loop2End = i + rowComps;
  29585. // unroll loop for all full bytes
  29586. while (i < loop1End) {
  29587. buf = buffer[bufferPos++];
  29588. output[i] = (buf >> 7) & 1;
  29589. output[i + 1] = (buf >> 6) & 1;
  29590. output[i + 2] = (buf >> 5) & 1;
  29591. output[i + 3] = (buf >> 4) & 1;
  29592. output[i + 4] = (buf >> 3) & 1;
  29593. output[i + 5] = (buf >> 2) & 1;
  29594. output[i + 6] = (buf >> 1) & 1;
  29595. output[i + 7] = buf & 1;
  29596. i += 8;
  29597. }
  29598. // handle remaing bits
  29599. if (i < loop2End) {
  29600. buf = buffer[bufferPos++];
  29601. mask = 128;
  29602. while (i < loop2End) {
  29603. output[i++] = +!!(buf & mask);
  29604. mask >>= 1;
  29605. }
  29606. }
  29607. }
  29608. } else {
  29609. // The general case that handles all other bpc values.
  29610. var bits = 0;
  29611. buf = 0;
  29612. for (i = 0, ii = length; i < ii; ++i) {
  29613. if (i % rowComps === 0) {
  29614. buf = 0;
  29615. bits = 0;
  29616. }
  29617. while (bits < bpc) {
  29618. buf = (buf << 8) | buffer[bufferPos++];
  29619. bits += 8;
  29620. }
  29621. var remainingBits = bits - bpc;
  29622. var value = buf >> remainingBits;
  29623. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  29624. buf = buf & ((1 << remainingBits) - 1);
  29625. bits = remainingBits;
  29626. }
  29627. }
  29628. return output;
  29629. },
  29630. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  29631. actualHeight, image) {
  29632. var smask = this.smask;
  29633. var mask = this.mask;
  29634. var alphaBuf, sw, sh, i, ii, j;
  29635. if (smask) {
  29636. sw = smask.width;
  29637. sh = smask.height;
  29638. alphaBuf = new Uint8Array(sw * sh);
  29639. smask.fillGrayBuffer(alphaBuf);
  29640. if (sw !== width || sh !== height) {
  29641. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  29642. height);
  29643. }
  29644. } else if (mask) {
  29645. if (mask instanceof PDFImage) {
  29646. sw = mask.width;
  29647. sh = mask.height;
  29648. alphaBuf = new Uint8Array(sw * sh);
  29649. mask.numComps = 1;
  29650. mask.fillGrayBuffer(alphaBuf);
  29651. // Need to invert values in rgbaBuf
  29652. for (i = 0, ii = sw * sh; i < ii; ++i) {
  29653. alphaBuf[i] = 255 - alphaBuf[i];
  29654. }
  29655. if (sw !== width || sh !== height) {
  29656. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  29657. height);
  29658. }
  29659. } else if (isArray(mask)) {
  29660. // Color key mask: if any of the compontents are outside the range
  29661. // then they should be painted.
  29662. alphaBuf = new Uint8Array(width * height);
  29663. var numComps = this.numComps;
  29664. for (i = 0, ii = width * height; i < ii; ++i) {
  29665. var opacity = 0;
  29666. var imageOffset = i * numComps;
  29667. for (j = 0; j < numComps; ++j) {
  29668. var color = image[imageOffset + j];
  29669. var maskOffset = j * 2;
  29670. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  29671. opacity = 255;
  29672. break;
  29673. }
  29674. }
  29675. alphaBuf[i] = opacity;
  29676. }
  29677. } else {
  29678. error('Unknown mask format.');
  29679. }
  29680. }
  29681. if (alphaBuf) {
  29682. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  29683. rgbaBuf[j] = alphaBuf[i];
  29684. }
  29685. } else {
  29686. // No mask.
  29687. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  29688. rgbaBuf[j] = 255;
  29689. }
  29690. }
  29691. },
  29692. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  29693. var matte = this.smask && this.smask.matte;
  29694. if (!matte) {
  29695. return;
  29696. }
  29697. var matteRgb = this.colorSpace.getRgb(matte, 0);
  29698. var matteR = matteRgb[0];
  29699. var matteG = matteRgb[1];
  29700. var matteB = matteRgb[2];
  29701. var length = width * height * 4;
  29702. var r, g, b;
  29703. for (var i = 0; i < length; i += 4) {
  29704. var alpha = buffer[i + 3];
  29705. if (alpha === 0) {
  29706. // according formula we have to get Infinity in all components
  29707. // making it white (typical paper color) should be okay
  29708. buffer[i] = 255;
  29709. buffer[i + 1] = 255;
  29710. buffer[i + 2] = 255;
  29711. continue;
  29712. }
  29713. var k = 255 / alpha;
  29714. r = (buffer[i] - matteR) * k + matteR;
  29715. g = (buffer[i + 1] - matteG) * k + matteG;
  29716. b = (buffer[i + 2] - matteB) * k + matteB;
  29717. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  29718. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  29719. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  29720. }
  29721. },
  29722. createImageData: function PDFImage_createImageData(forceRGBA) {
  29723. var drawWidth = this.drawWidth;
  29724. var drawHeight = this.drawHeight;
  29725. var imgData = { // other fields are filled in below
  29726. width: drawWidth,
  29727. height: drawHeight
  29728. };
  29729. var numComps = this.numComps;
  29730. var originalWidth = this.width;
  29731. var originalHeight = this.height;
  29732. var bpc = this.bpc;
  29733. // Rows start at byte boundary.
  29734. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  29735. var imgArray;
  29736. if (!forceRGBA) {
  29737. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  29738. // without any complications, we pass a same-sized copy to the main
  29739. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  29740. // of memory for many scanned documents. It's also much faster.
  29741. //
  29742. // Similarly, if it is a 24-bit-per pixel RGB image without any
  29743. // complications, we avoid expanding by 1.333x to RGBA form.
  29744. var kind;
  29745. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  29746. kind = ImageKind.GRAYSCALE_1BPP;
  29747. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
  29748. kind = ImageKind.RGB_24BPP;
  29749. }
  29750. if (kind && !this.smask && !this.mask && !this.needsDecode &&
  29751. drawWidth === originalWidth && drawHeight === originalHeight) {
  29752. imgData.kind = kind;
  29753. imgArray = this.getImageBytes(originalHeight * rowBytes);
  29754. // If imgArray came from a DecodeStream, we're safe to transfer it
  29755. // (and thus neuter it) because it will constitute the entire
  29756. // DecodeStream's data. But if it came from a Stream, we need to
  29757. // copy it because it'll only be a portion of the Stream's data, and
  29758. // the rest will be read later on.
  29759. if (this.image instanceof DecodeStream) {
  29760. imgData.data = imgArray;
  29761. } else {
  29762. var newArray = new Uint8Array(imgArray.length);
  29763. newArray.set(imgArray);
  29764. imgData.data = newArray;
  29765. }
  29766. return imgData;
  29767. }
  29768. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  29769. imgData.kind = ImageKind.RGB_24BPP;
  29770. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  29771. drawWidth, drawHeight, true);
  29772. return imgData;
  29773. }
  29774. }
  29775. imgArray = this.getImageBytes(originalHeight * rowBytes);
  29776. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  29777. var actualHeight = 0 | (imgArray.length / rowBytes *
  29778. drawHeight / originalHeight);
  29779. var comps = this.getComponents(imgArray);
  29780. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  29781. // more compact RGB_24BPP form if allowable.
  29782. var alpha01, maybeUndoPreblend;
  29783. if (!forceRGBA && !this.smask && !this.mask) {
  29784. imgData.kind = ImageKind.RGB_24BPP;
  29785. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  29786. alpha01 = 0;
  29787. maybeUndoPreblend = false;
  29788. } else {
  29789. imgData.kind = ImageKind.RGBA_32BPP;
  29790. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  29791. alpha01 = 1;
  29792. maybeUndoPreblend = true;
  29793. // Color key masking (opacity) must be performed before decoding.
  29794. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  29795. comps);
  29796. }
  29797. if (this.needsDecode) {
  29798. this.decodeBuffer(comps);
  29799. }
  29800. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  29801. drawWidth, drawHeight, actualHeight, bpc, comps,
  29802. alpha01);
  29803. if (maybeUndoPreblend) {
  29804. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  29805. }
  29806. return imgData;
  29807. },
  29808. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  29809. var numComps = this.numComps;
  29810. if (numComps !== 1) {
  29811. error('Reading gray scale from a color image: ' + numComps);
  29812. }
  29813. var width = this.width;
  29814. var height = this.height;
  29815. var bpc = this.bpc;
  29816. // rows start at byte boundary
  29817. var rowBytes = (width * numComps * bpc + 7) >> 3;
  29818. var imgArray = this.getImageBytes(height * rowBytes);
  29819. var comps = this.getComponents(imgArray);
  29820. var i, length;
  29821. if (bpc === 1) {
  29822. // inline decoding (= inversion) for 1 bpc images
  29823. length = width * height;
  29824. if (this.needsDecode) {
  29825. // invert and scale to {0, 255}
  29826. for (i = 0; i < length; ++i) {
  29827. buffer[i] = (comps[i] - 1) & 255;
  29828. }
  29829. } else {
  29830. // scale to {0, 255}
  29831. for (i = 0; i < length; ++i) {
  29832. buffer[i] = (-comps[i]) & 255;
  29833. }
  29834. }
  29835. return;
  29836. }
  29837. if (this.needsDecode) {
  29838. this.decodeBuffer(comps);
  29839. }
  29840. length = width * height;
  29841. // we aren't using a colorspace so we need to scale the value
  29842. var scale = 255 / ((1 << bpc) - 1);
  29843. for (i = 0; i < length; ++i) {
  29844. buffer[i] = (scale * comps[i]) | 0;
  29845. }
  29846. },
  29847. getImageBytes: function PDFImage_getImageBytes(length,
  29848. drawWidth, drawHeight,
  29849. forceRGB) {
  29850. this.image.reset();
  29851. this.image.drawWidth = drawWidth || this.width;
  29852. this.image.drawHeight = drawHeight || this.height;
  29853. this.image.forceRGB = !!forceRGB;
  29854. return this.image.getBytes(length);
  29855. }
  29856. };
  29857. return PDFImage;
  29858. })();
  29859. // The Metrics object contains glyph widths (in glyph space units).
  29860. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  29861. // space unit corresponds to 1/1000th of text space unit.
  29862. var Metrics = {
  29863. 'Courier': 600,
  29864. 'Courier-Bold': 600,
  29865. 'Courier-BoldOblique': 600,
  29866. 'Courier-Oblique': 600,
  29867. 'Helvetica' : {
  29868. 'space': 278,
  29869. 'exclam': 278,
  29870. 'quotedbl': 355,
  29871. 'numbersign': 556,
  29872. 'dollar': 556,
  29873. 'percent': 889,
  29874. 'ampersand': 667,
  29875. 'quoteright': 222,
  29876. 'parenleft': 333,
  29877. 'parenright': 333,
  29878. 'asterisk': 389,
  29879. 'plus': 584,
  29880. 'comma': 278,
  29881. 'hyphen': 333,
  29882. 'period': 278,
  29883. 'slash': 278,
  29884. 'zero': 556,
  29885. 'one': 556,
  29886. 'two': 556,
  29887. 'three': 556,
  29888. 'four': 556,
  29889. 'five': 556,
  29890. 'six': 556,
  29891. 'seven': 556,
  29892. 'eight': 556,
  29893. 'nine': 556,
  29894. 'colon': 278,
  29895. 'semicolon': 278,
  29896. 'less': 584,
  29897. 'equal': 584,
  29898. 'greater': 584,
  29899. 'question': 556,
  29900. 'at': 1015,
  29901. 'A': 667,
  29902. 'B': 667,
  29903. 'C': 722,
  29904. 'D': 722,
  29905. 'E': 667,
  29906. 'F': 611,
  29907. 'G': 778,
  29908. 'H': 722,
  29909. 'I': 278,
  29910. 'J': 500,
  29911. 'K': 667,
  29912. 'L': 556,
  29913. 'M': 833,
  29914. 'N': 722,
  29915. 'O': 778,
  29916. 'P': 667,
  29917. 'Q': 778,
  29918. 'R': 722,
  29919. 'S': 667,
  29920. 'T': 611,
  29921. 'U': 722,
  29922. 'V': 667,
  29923. 'W': 944,
  29924. 'X': 667,
  29925. 'Y': 667,
  29926. 'Z': 611,
  29927. 'bracketleft': 278,
  29928. 'backslash': 278,
  29929. 'bracketright': 278,
  29930. 'asciicircum': 469,
  29931. 'underscore': 556,
  29932. 'quoteleft': 222,
  29933. 'a': 556,
  29934. 'b': 556,
  29935. 'c': 500,
  29936. 'd': 556,
  29937. 'e': 556,
  29938. 'f': 278,
  29939. 'g': 556,
  29940. 'h': 556,
  29941. 'i': 222,
  29942. 'j': 222,
  29943. 'k': 500,
  29944. 'l': 222,
  29945. 'm': 833,
  29946. 'n': 556,
  29947. 'o': 556,
  29948. 'p': 556,
  29949. 'q': 556,
  29950. 'r': 333,
  29951. 's': 500,
  29952. 't': 278,
  29953. 'u': 556,
  29954. 'v': 500,
  29955. 'w': 722,
  29956. 'x': 500,
  29957. 'y': 500,
  29958. 'z': 500,
  29959. 'braceleft': 334,
  29960. 'bar': 260,
  29961. 'braceright': 334,
  29962. 'asciitilde': 584,
  29963. 'exclamdown': 333,
  29964. 'cent': 556,
  29965. 'sterling': 556,
  29966. 'fraction': 167,
  29967. 'yen': 556,
  29968. 'florin': 556,
  29969. 'section': 556,
  29970. 'currency': 556,
  29971. 'quotesingle': 191,
  29972. 'quotedblleft': 333,
  29973. 'guillemotleft': 556,
  29974. 'guilsinglleft': 333,
  29975. 'guilsinglright': 333,
  29976. 'fi': 500,
  29977. 'fl': 500,
  29978. 'endash': 556,
  29979. 'dagger': 556,
  29980. 'daggerdbl': 556,
  29981. 'periodcentered': 278,
  29982. 'paragraph': 537,
  29983. 'bullet': 350,
  29984. 'quotesinglbase': 222,
  29985. 'quotedblbase': 333,
  29986. 'quotedblright': 333,
  29987. 'guillemotright': 556,
  29988. 'ellipsis': 1000,
  29989. 'perthousand': 1000,
  29990. 'questiondown': 611,
  29991. 'grave': 333,
  29992. 'acute': 333,
  29993. 'circumflex': 333,
  29994. 'tilde': 333,
  29995. 'macron': 333,
  29996. 'breve': 333,
  29997. 'dotaccent': 333,
  29998. 'dieresis': 333,
  29999. 'ring': 333,
  30000. 'cedilla': 333,
  30001. 'hungarumlaut': 333,
  30002. 'ogonek': 333,
  30003. 'caron': 333,
  30004. 'emdash': 1000,
  30005. 'AE': 1000,
  30006. 'ordfeminine': 370,
  30007. 'Lslash': 556,
  30008. 'Oslash': 778,
  30009. 'OE': 1000,
  30010. 'ordmasculine': 365,
  30011. 'ae': 889,
  30012. 'dotlessi': 278,
  30013. 'lslash': 222,
  30014. 'oslash': 611,
  30015. 'oe': 944,
  30016. 'germandbls': 611,
  30017. 'Idieresis': 278,
  30018. 'eacute': 556,
  30019. 'abreve': 556,
  30020. 'uhungarumlaut': 556,
  30021. 'ecaron': 556,
  30022. 'Ydieresis': 667,
  30023. 'divide': 584,
  30024. 'Yacute': 667,
  30025. 'Acircumflex': 667,
  30026. 'aacute': 556,
  30027. 'Ucircumflex': 722,
  30028. 'yacute': 500,
  30029. 'scommaaccent': 500,
  30030. 'ecircumflex': 556,
  30031. 'Uring': 722,
  30032. 'Udieresis': 722,
  30033. 'aogonek': 556,
  30034. 'Uacute': 722,
  30035. 'uogonek': 556,
  30036. 'Edieresis': 667,
  30037. 'Dcroat': 722,
  30038. 'commaaccent': 250,
  30039. 'copyright': 737,
  30040. 'Emacron': 667,
  30041. 'ccaron': 500,
  30042. 'aring': 556,
  30043. 'Ncommaaccent': 722,
  30044. 'lacute': 222,
  30045. 'agrave': 556,
  30046. 'Tcommaaccent': 611,
  30047. 'Cacute': 722,
  30048. 'atilde': 556,
  30049. 'Edotaccent': 667,
  30050. 'scaron': 500,
  30051. 'scedilla': 500,
  30052. 'iacute': 278,
  30053. 'lozenge': 471,
  30054. 'Rcaron': 722,
  30055. 'Gcommaaccent': 778,
  30056. 'ucircumflex': 556,
  30057. 'acircumflex': 556,
  30058. 'Amacron': 667,
  30059. 'rcaron': 333,
  30060. 'ccedilla': 500,
  30061. 'Zdotaccent': 611,
  30062. 'Thorn': 667,
  30063. 'Omacron': 778,
  30064. 'Racute': 722,
  30065. 'Sacute': 667,
  30066. 'dcaron': 643,
  30067. 'Umacron': 722,
  30068. 'uring': 556,
  30069. 'threesuperior': 333,
  30070. 'Ograve': 778,
  30071. 'Agrave': 667,
  30072. 'Abreve': 667,
  30073. 'multiply': 584,
  30074. 'uacute': 556,
  30075. 'Tcaron': 611,
  30076. 'partialdiff': 476,
  30077. 'ydieresis': 500,
  30078. 'Nacute': 722,
  30079. 'icircumflex': 278,
  30080. 'Ecircumflex': 667,
  30081. 'adieresis': 556,
  30082. 'edieresis': 556,
  30083. 'cacute': 500,
  30084. 'nacute': 556,
  30085. 'umacron': 556,
  30086. 'Ncaron': 722,
  30087. 'Iacute': 278,
  30088. 'plusminus': 584,
  30089. 'brokenbar': 260,
  30090. 'registered': 737,
  30091. 'Gbreve': 778,
  30092. 'Idotaccent': 278,
  30093. 'summation': 600,
  30094. 'Egrave': 667,
  30095. 'racute': 333,
  30096. 'omacron': 556,
  30097. 'Zacute': 611,
  30098. 'Zcaron': 611,
  30099. 'greaterequal': 549,
  30100. 'Eth': 722,
  30101. 'Ccedilla': 722,
  30102. 'lcommaaccent': 222,
  30103. 'tcaron': 317,
  30104. 'eogonek': 556,
  30105. 'Uogonek': 722,
  30106. 'Aacute': 667,
  30107. 'Adieresis': 667,
  30108. 'egrave': 556,
  30109. 'zacute': 500,
  30110. 'iogonek': 222,
  30111. 'Oacute': 778,
  30112. 'oacute': 556,
  30113. 'amacron': 556,
  30114. 'sacute': 500,
  30115. 'idieresis': 278,
  30116. 'Ocircumflex': 778,
  30117. 'Ugrave': 722,
  30118. 'Delta': 612,
  30119. 'thorn': 556,
  30120. 'twosuperior': 333,
  30121. 'Odieresis': 778,
  30122. 'mu': 556,
  30123. 'igrave': 278,
  30124. 'ohungarumlaut': 556,
  30125. 'Eogonek': 667,
  30126. 'dcroat': 556,
  30127. 'threequarters': 834,
  30128. 'Scedilla': 667,
  30129. 'lcaron': 299,
  30130. 'Kcommaaccent': 667,
  30131. 'Lacute': 556,
  30132. 'trademark': 1000,
  30133. 'edotaccent': 556,
  30134. 'Igrave': 278,
  30135. 'Imacron': 278,
  30136. 'Lcaron': 556,
  30137. 'onehalf': 834,
  30138. 'lessequal': 549,
  30139. 'ocircumflex': 556,
  30140. 'ntilde': 556,
  30141. 'Uhungarumlaut': 722,
  30142. 'Eacute': 667,
  30143. 'emacron': 556,
  30144. 'gbreve': 556,
  30145. 'onequarter': 834,
  30146. 'Scaron': 667,
  30147. 'Scommaaccent': 667,
  30148. 'Ohungarumlaut': 778,
  30149. 'degree': 400,
  30150. 'ograve': 556,
  30151. 'Ccaron': 722,
  30152. 'ugrave': 556,
  30153. 'radical': 453,
  30154. 'Dcaron': 722,
  30155. 'rcommaaccent': 333,
  30156. 'Ntilde': 722,
  30157. 'otilde': 556,
  30158. 'Rcommaaccent': 722,
  30159. 'Lcommaaccent': 556,
  30160. 'Atilde': 667,
  30161. 'Aogonek': 667,
  30162. 'Aring': 667,
  30163. 'Otilde': 778,
  30164. 'zdotaccent': 500,
  30165. 'Ecaron': 667,
  30166. 'Iogonek': 278,
  30167. 'kcommaaccent': 500,
  30168. 'minus': 584,
  30169. 'Icircumflex': 278,
  30170. 'ncaron': 556,
  30171. 'tcommaaccent': 278,
  30172. 'logicalnot': 584,
  30173. 'odieresis': 556,
  30174. 'udieresis': 556,
  30175. 'notequal': 549,
  30176. 'gcommaaccent': 556,
  30177. 'eth': 556,
  30178. 'zcaron': 500,
  30179. 'ncommaaccent': 556,
  30180. 'onesuperior': 333,
  30181. 'imacron': 278,
  30182. 'Euro': 556
  30183. },
  30184. 'Helvetica-Bold': {
  30185. 'space': 278,
  30186. 'exclam': 333,
  30187. 'quotedbl': 474,
  30188. 'numbersign': 556,
  30189. 'dollar': 556,
  30190. 'percent': 889,
  30191. 'ampersand': 722,
  30192. 'quoteright': 278,
  30193. 'parenleft': 333,
  30194. 'parenright': 333,
  30195. 'asterisk': 389,
  30196. 'plus': 584,
  30197. 'comma': 278,
  30198. 'hyphen': 333,
  30199. 'period': 278,
  30200. 'slash': 278,
  30201. 'zero': 556,
  30202. 'one': 556,
  30203. 'two': 556,
  30204. 'three': 556,
  30205. 'four': 556,
  30206. 'five': 556,
  30207. 'six': 556,
  30208. 'seven': 556,
  30209. 'eight': 556,
  30210. 'nine': 556,
  30211. 'colon': 333,
  30212. 'semicolon': 333,
  30213. 'less': 584,
  30214. 'equal': 584,
  30215. 'greater': 584,
  30216. 'question': 611,
  30217. 'at': 975,
  30218. 'A': 722,
  30219. 'B': 722,
  30220. 'C': 722,
  30221. 'D': 722,
  30222. 'E': 667,
  30223. 'F': 611,
  30224. 'G': 778,
  30225. 'H': 722,
  30226. 'I': 278,
  30227. 'J': 556,
  30228. 'K': 722,
  30229. 'L': 611,
  30230. 'M': 833,
  30231. 'N': 722,
  30232. 'O': 778,
  30233. 'P': 667,
  30234. 'Q': 778,
  30235. 'R': 722,
  30236. 'S': 667,
  30237. 'T': 611,
  30238. 'U': 722,
  30239. 'V': 667,
  30240. 'W': 944,
  30241. 'X': 667,
  30242. 'Y': 667,
  30243. 'Z': 611,
  30244. 'bracketleft': 333,
  30245. 'backslash': 278,
  30246. 'bracketright': 333,
  30247. 'asciicircum': 584,
  30248. 'underscore': 556,
  30249. 'quoteleft': 278,
  30250. 'a': 556,
  30251. 'b': 611,
  30252. 'c': 556,
  30253. 'd': 611,
  30254. 'e': 556,
  30255. 'f': 333,
  30256. 'g': 611,
  30257. 'h': 611,
  30258. 'i': 278,
  30259. 'j': 278,
  30260. 'k': 556,
  30261. 'l': 278,
  30262. 'm': 889,
  30263. 'n': 611,
  30264. 'o': 611,
  30265. 'p': 611,
  30266. 'q': 611,
  30267. 'r': 389,
  30268. 's': 556,
  30269. 't': 333,
  30270. 'u': 611,
  30271. 'v': 556,
  30272. 'w': 778,
  30273. 'x': 556,
  30274. 'y': 556,
  30275. 'z': 500,
  30276. 'braceleft': 389,
  30277. 'bar': 280,
  30278. 'braceright': 389,
  30279. 'asciitilde': 584,
  30280. 'exclamdown': 333,
  30281. 'cent': 556,
  30282. 'sterling': 556,
  30283. 'fraction': 167,
  30284. 'yen': 556,
  30285. 'florin': 556,
  30286. 'section': 556,
  30287. 'currency': 556,
  30288. 'quotesingle': 238,
  30289. 'quotedblleft': 500,
  30290. 'guillemotleft': 556,
  30291. 'guilsinglleft': 333,
  30292. 'guilsinglright': 333,
  30293. 'fi': 611,
  30294. 'fl': 611,
  30295. 'endash': 556,
  30296. 'dagger': 556,
  30297. 'daggerdbl': 556,
  30298. 'periodcentered': 278,
  30299. 'paragraph': 556,
  30300. 'bullet': 350,
  30301. 'quotesinglbase': 278,
  30302. 'quotedblbase': 500,
  30303. 'quotedblright': 500,
  30304. 'guillemotright': 556,
  30305. 'ellipsis': 1000,
  30306. 'perthousand': 1000,
  30307. 'questiondown': 611,
  30308. 'grave': 333,
  30309. 'acute': 333,
  30310. 'circumflex': 333,
  30311. 'tilde': 333,
  30312. 'macron': 333,
  30313. 'breve': 333,
  30314. 'dotaccent': 333,
  30315. 'dieresis': 333,
  30316. 'ring': 333,
  30317. 'cedilla': 333,
  30318. 'hungarumlaut': 333,
  30319. 'ogonek': 333,
  30320. 'caron': 333,
  30321. 'emdash': 1000,
  30322. 'AE': 1000,
  30323. 'ordfeminine': 370,
  30324. 'Lslash': 611,
  30325. 'Oslash': 778,
  30326. 'OE': 1000,
  30327. 'ordmasculine': 365,
  30328. 'ae': 889,
  30329. 'dotlessi': 278,
  30330. 'lslash': 278,
  30331. 'oslash': 611,
  30332. 'oe': 944,
  30333. 'germandbls': 611,
  30334. 'Idieresis': 278,
  30335. 'eacute': 556,
  30336. 'abreve': 556,
  30337. 'uhungarumlaut': 611,
  30338. 'ecaron': 556,
  30339. 'Ydieresis': 667,
  30340. 'divide': 584,
  30341. 'Yacute': 667,
  30342. 'Acircumflex': 722,
  30343. 'aacute': 556,
  30344. 'Ucircumflex': 722,
  30345. 'yacute': 556,
  30346. 'scommaaccent': 556,
  30347. 'ecircumflex': 556,
  30348. 'Uring': 722,
  30349. 'Udieresis': 722,
  30350. 'aogonek': 556,
  30351. 'Uacute': 722,
  30352. 'uogonek': 611,
  30353. 'Edieresis': 667,
  30354. 'Dcroat': 722,
  30355. 'commaaccent': 250,
  30356. 'copyright': 737,
  30357. 'Emacron': 667,
  30358. 'ccaron': 556,
  30359. 'aring': 556,
  30360. 'Ncommaaccent': 722,
  30361. 'lacute': 278,
  30362. 'agrave': 556,
  30363. 'Tcommaaccent': 611,
  30364. 'Cacute': 722,
  30365. 'atilde': 556,
  30366. 'Edotaccent': 667,
  30367. 'scaron': 556,
  30368. 'scedilla': 556,
  30369. 'iacute': 278,
  30370. 'lozenge': 494,
  30371. 'Rcaron': 722,
  30372. 'Gcommaaccent': 778,
  30373. 'ucircumflex': 611,
  30374. 'acircumflex': 556,
  30375. 'Amacron': 722,
  30376. 'rcaron': 389,
  30377. 'ccedilla': 556,
  30378. 'Zdotaccent': 611,
  30379. 'Thorn': 667,
  30380. 'Omacron': 778,
  30381. 'Racute': 722,
  30382. 'Sacute': 667,
  30383. 'dcaron': 743,
  30384. 'Umacron': 722,
  30385. 'uring': 611,
  30386. 'threesuperior': 333,
  30387. 'Ograve': 778,
  30388. 'Agrave': 722,
  30389. 'Abreve': 722,
  30390. 'multiply': 584,
  30391. 'uacute': 611,
  30392. 'Tcaron': 611,
  30393. 'partialdiff': 494,
  30394. 'ydieresis': 556,
  30395. 'Nacute': 722,
  30396. 'icircumflex': 278,
  30397. 'Ecircumflex': 667,
  30398. 'adieresis': 556,
  30399. 'edieresis': 556,
  30400. 'cacute': 556,
  30401. 'nacute': 611,
  30402. 'umacron': 611,
  30403. 'Ncaron': 722,
  30404. 'Iacute': 278,
  30405. 'plusminus': 584,
  30406. 'brokenbar': 280,
  30407. 'registered': 737,
  30408. 'Gbreve': 778,
  30409. 'Idotaccent': 278,
  30410. 'summation': 600,
  30411. 'Egrave': 667,
  30412. 'racute': 389,
  30413. 'omacron': 611,
  30414. 'Zacute': 611,
  30415. 'Zcaron': 611,
  30416. 'greaterequal': 549,
  30417. 'Eth': 722,
  30418. 'Ccedilla': 722,
  30419. 'lcommaaccent': 278,
  30420. 'tcaron': 389,
  30421. 'eogonek': 556,
  30422. 'Uogonek': 722,
  30423. 'Aacute': 722,
  30424. 'Adieresis': 722,
  30425. 'egrave': 556,
  30426. 'zacute': 500,
  30427. 'iogonek': 278,
  30428. 'Oacute': 778,
  30429. 'oacute': 611,
  30430. 'amacron': 556,
  30431. 'sacute': 556,
  30432. 'idieresis': 278,
  30433. 'Ocircumflex': 778,
  30434. 'Ugrave': 722,
  30435. 'Delta': 612,
  30436. 'thorn': 611,
  30437. 'twosuperior': 333,
  30438. 'Odieresis': 778,
  30439. 'mu': 611,
  30440. 'igrave': 278,
  30441. 'ohungarumlaut': 611,
  30442. 'Eogonek': 667,
  30443. 'dcroat': 611,
  30444. 'threequarters': 834,
  30445. 'Scedilla': 667,
  30446. 'lcaron': 400,
  30447. 'Kcommaaccent': 722,
  30448. 'Lacute': 611,
  30449. 'trademark': 1000,
  30450. 'edotaccent': 556,
  30451. 'Igrave': 278,
  30452. 'Imacron': 278,
  30453. 'Lcaron': 611,
  30454. 'onehalf': 834,
  30455. 'lessequal': 549,
  30456. 'ocircumflex': 611,
  30457. 'ntilde': 611,
  30458. 'Uhungarumlaut': 722,
  30459. 'Eacute': 667,
  30460. 'emacron': 556,
  30461. 'gbreve': 611,
  30462. 'onequarter': 834,
  30463. 'Scaron': 667,
  30464. 'Scommaaccent': 667,
  30465. 'Ohungarumlaut': 778,
  30466. 'degree': 400,
  30467. 'ograve': 611,
  30468. 'Ccaron': 722,
  30469. 'ugrave': 611,
  30470. 'radical': 549,
  30471. 'Dcaron': 722,
  30472. 'rcommaaccent': 389,
  30473. 'Ntilde': 722,
  30474. 'otilde': 611,
  30475. 'Rcommaaccent': 722,
  30476. 'Lcommaaccent': 611,
  30477. 'Atilde': 722,
  30478. 'Aogonek': 722,
  30479. 'Aring': 722,
  30480. 'Otilde': 778,
  30481. 'zdotaccent': 500,
  30482. 'Ecaron': 667,
  30483. 'Iogonek': 278,
  30484. 'kcommaaccent': 556,
  30485. 'minus': 584,
  30486. 'Icircumflex': 278,
  30487. 'ncaron': 611,
  30488. 'tcommaaccent': 333,
  30489. 'logicalnot': 584,
  30490. 'odieresis': 611,
  30491. 'udieresis': 611,
  30492. 'notequal': 549,
  30493. 'gcommaaccent': 611,
  30494. 'eth': 611,
  30495. 'zcaron': 500,
  30496. 'ncommaaccent': 611,
  30497. 'onesuperior': 333,
  30498. 'imacron': 278,
  30499. 'Euro': 556
  30500. },
  30501. 'Helvetica-BoldOblique': {
  30502. 'space': 278,
  30503. 'exclam': 333,
  30504. 'quotedbl': 474,
  30505. 'numbersign': 556,
  30506. 'dollar': 556,
  30507. 'percent': 889,
  30508. 'ampersand': 722,
  30509. 'quoteright': 278,
  30510. 'parenleft': 333,
  30511. 'parenright': 333,
  30512. 'asterisk': 389,
  30513. 'plus': 584,
  30514. 'comma': 278,
  30515. 'hyphen': 333,
  30516. 'period': 278,
  30517. 'slash': 278,
  30518. 'zero': 556,
  30519. 'one': 556,
  30520. 'two': 556,
  30521. 'three': 556,
  30522. 'four': 556,
  30523. 'five': 556,
  30524. 'six': 556,
  30525. 'seven': 556,
  30526. 'eight': 556,
  30527. 'nine': 556,
  30528. 'colon': 333,
  30529. 'semicolon': 333,
  30530. 'less': 584,
  30531. 'equal': 584,
  30532. 'greater': 584,
  30533. 'question': 611,
  30534. 'at': 975,
  30535. 'A': 722,
  30536. 'B': 722,
  30537. 'C': 722,
  30538. 'D': 722,
  30539. 'E': 667,
  30540. 'F': 611,
  30541. 'G': 778,
  30542. 'H': 722,
  30543. 'I': 278,
  30544. 'J': 556,
  30545. 'K': 722,
  30546. 'L': 611,
  30547. 'M': 833,
  30548. 'N': 722,
  30549. 'O': 778,
  30550. 'P': 667,
  30551. 'Q': 778,
  30552. 'R': 722,
  30553. 'S': 667,
  30554. 'T': 611,
  30555. 'U': 722,
  30556. 'V': 667,
  30557. 'W': 944,
  30558. 'X': 667,
  30559. 'Y': 667,
  30560. 'Z': 611,
  30561. 'bracketleft': 333,
  30562. 'backslash': 278,
  30563. 'bracketright': 333,
  30564. 'asciicircum': 584,
  30565. 'underscore': 556,
  30566. 'quoteleft': 278,
  30567. 'a': 556,
  30568. 'b': 611,
  30569. 'c': 556,
  30570. 'd': 611,
  30571. 'e': 556,
  30572. 'f': 333,
  30573. 'g': 611,
  30574. 'h': 611,
  30575. 'i': 278,
  30576. 'j': 278,
  30577. 'k': 556,
  30578. 'l': 278,
  30579. 'm': 889,
  30580. 'n': 611,
  30581. 'o': 611,
  30582. 'p': 611,
  30583. 'q': 611,
  30584. 'r': 389,
  30585. 's': 556,
  30586. 't': 333,
  30587. 'u': 611,
  30588. 'v': 556,
  30589. 'w': 778,
  30590. 'x': 556,
  30591. 'y': 556,
  30592. 'z': 500,
  30593. 'braceleft': 389,
  30594. 'bar': 280,
  30595. 'braceright': 389,
  30596. 'asciitilde': 584,
  30597. 'exclamdown': 333,
  30598. 'cent': 556,
  30599. 'sterling': 556,
  30600. 'fraction': 167,
  30601. 'yen': 556,
  30602. 'florin': 556,
  30603. 'section': 556,
  30604. 'currency': 556,
  30605. 'quotesingle': 238,
  30606. 'quotedblleft': 500,
  30607. 'guillemotleft': 556,
  30608. 'guilsinglleft': 333,
  30609. 'guilsinglright': 333,
  30610. 'fi': 611,
  30611. 'fl': 611,
  30612. 'endash': 556,
  30613. 'dagger': 556,
  30614. 'daggerdbl': 556,
  30615. 'periodcentered': 278,
  30616. 'paragraph': 556,
  30617. 'bullet': 350,
  30618. 'quotesinglbase': 278,
  30619. 'quotedblbase': 500,
  30620. 'quotedblright': 500,
  30621. 'guillemotright': 556,
  30622. 'ellipsis': 1000,
  30623. 'perthousand': 1000,
  30624. 'questiondown': 611,
  30625. 'grave': 333,
  30626. 'acute': 333,
  30627. 'circumflex': 333,
  30628. 'tilde': 333,
  30629. 'macron': 333,
  30630. 'breve': 333,
  30631. 'dotaccent': 333,
  30632. 'dieresis': 333,
  30633. 'ring': 333,
  30634. 'cedilla': 333,
  30635. 'hungarumlaut': 333,
  30636. 'ogonek': 333,
  30637. 'caron': 333,
  30638. 'emdash': 1000,
  30639. 'AE': 1000,
  30640. 'ordfeminine': 370,
  30641. 'Lslash': 611,
  30642. 'Oslash': 778,
  30643. 'OE': 1000,
  30644. 'ordmasculine': 365,
  30645. 'ae': 889,
  30646. 'dotlessi': 278,
  30647. 'lslash': 278,
  30648. 'oslash': 611,
  30649. 'oe': 944,
  30650. 'germandbls': 611,
  30651. 'Idieresis': 278,
  30652. 'eacute': 556,
  30653. 'abreve': 556,
  30654. 'uhungarumlaut': 611,
  30655. 'ecaron': 556,
  30656. 'Ydieresis': 667,
  30657. 'divide': 584,
  30658. 'Yacute': 667,
  30659. 'Acircumflex': 722,
  30660. 'aacute': 556,
  30661. 'Ucircumflex': 722,
  30662. 'yacute': 556,
  30663. 'scommaaccent': 556,
  30664. 'ecircumflex': 556,
  30665. 'Uring': 722,
  30666. 'Udieresis': 722,
  30667. 'aogonek': 556,
  30668. 'Uacute': 722,
  30669. 'uogonek': 611,
  30670. 'Edieresis': 667,
  30671. 'Dcroat': 722,
  30672. 'commaaccent': 250,
  30673. 'copyright': 737,
  30674. 'Emacron': 667,
  30675. 'ccaron': 556,
  30676. 'aring': 556,
  30677. 'Ncommaaccent': 722,
  30678. 'lacute': 278,
  30679. 'agrave': 556,
  30680. 'Tcommaaccent': 611,
  30681. 'Cacute': 722,
  30682. 'atilde': 556,
  30683. 'Edotaccent': 667,
  30684. 'scaron': 556,
  30685. 'scedilla': 556,
  30686. 'iacute': 278,
  30687. 'lozenge': 494,
  30688. 'Rcaron': 722,
  30689. 'Gcommaaccent': 778,
  30690. 'ucircumflex': 611,
  30691. 'acircumflex': 556,
  30692. 'Amacron': 722,
  30693. 'rcaron': 389,
  30694. 'ccedilla': 556,
  30695. 'Zdotaccent': 611,
  30696. 'Thorn': 667,
  30697. 'Omacron': 778,
  30698. 'Racute': 722,
  30699. 'Sacute': 667,
  30700. 'dcaron': 743,
  30701. 'Umacron': 722,
  30702. 'uring': 611,
  30703. 'threesuperior': 333,
  30704. 'Ograve': 778,
  30705. 'Agrave': 722,
  30706. 'Abreve': 722,
  30707. 'multiply': 584,
  30708. 'uacute': 611,
  30709. 'Tcaron': 611,
  30710. 'partialdiff': 494,
  30711. 'ydieresis': 556,
  30712. 'Nacute': 722,
  30713. 'icircumflex': 278,
  30714. 'Ecircumflex': 667,
  30715. 'adieresis': 556,
  30716. 'edieresis': 556,
  30717. 'cacute': 556,
  30718. 'nacute': 611,
  30719. 'umacron': 611,
  30720. 'Ncaron': 722,
  30721. 'Iacute': 278,
  30722. 'plusminus': 584,
  30723. 'brokenbar': 280,
  30724. 'registered': 737,
  30725. 'Gbreve': 778,
  30726. 'Idotaccent': 278,
  30727. 'summation': 600,
  30728. 'Egrave': 667,
  30729. 'racute': 389,
  30730. 'omacron': 611,
  30731. 'Zacute': 611,
  30732. 'Zcaron': 611,
  30733. 'greaterequal': 549,
  30734. 'Eth': 722,
  30735. 'Ccedilla': 722,
  30736. 'lcommaaccent': 278,
  30737. 'tcaron': 389,
  30738. 'eogonek': 556,
  30739. 'Uogonek': 722,
  30740. 'Aacute': 722,
  30741. 'Adieresis': 722,
  30742. 'egrave': 556,
  30743. 'zacute': 500,
  30744. 'iogonek': 278,
  30745. 'Oacute': 778,
  30746. 'oacute': 611,
  30747. 'amacron': 556,
  30748. 'sacute': 556,
  30749. 'idieresis': 278,
  30750. 'Ocircumflex': 778,
  30751. 'Ugrave': 722,
  30752. 'Delta': 612,
  30753. 'thorn': 611,
  30754. 'twosuperior': 333,
  30755. 'Odieresis': 778,
  30756. 'mu': 611,
  30757. 'igrave': 278,
  30758. 'ohungarumlaut': 611,
  30759. 'Eogonek': 667,
  30760. 'dcroat': 611,
  30761. 'threequarters': 834,
  30762. 'Scedilla': 667,
  30763. 'lcaron': 400,
  30764. 'Kcommaaccent': 722,
  30765. 'Lacute': 611,
  30766. 'trademark': 1000,
  30767. 'edotaccent': 556,
  30768. 'Igrave': 278,
  30769. 'Imacron': 278,
  30770. 'Lcaron': 611,
  30771. 'onehalf': 834,
  30772. 'lessequal': 549,
  30773. 'ocircumflex': 611,
  30774. 'ntilde': 611,
  30775. 'Uhungarumlaut': 722,
  30776. 'Eacute': 667,
  30777. 'emacron': 556,
  30778. 'gbreve': 611,
  30779. 'onequarter': 834,
  30780. 'Scaron': 667,
  30781. 'Scommaaccent': 667,
  30782. 'Ohungarumlaut': 778,
  30783. 'degree': 400,
  30784. 'ograve': 611,
  30785. 'Ccaron': 722,
  30786. 'ugrave': 611,
  30787. 'radical': 549,
  30788. 'Dcaron': 722,
  30789. 'rcommaaccent': 389,
  30790. 'Ntilde': 722,
  30791. 'otilde': 611,
  30792. 'Rcommaaccent': 722,
  30793. 'Lcommaaccent': 611,
  30794. 'Atilde': 722,
  30795. 'Aogonek': 722,
  30796. 'Aring': 722,
  30797. 'Otilde': 778,
  30798. 'zdotaccent': 500,
  30799. 'Ecaron': 667,
  30800. 'Iogonek': 278,
  30801. 'kcommaaccent': 556,
  30802. 'minus': 584,
  30803. 'Icircumflex': 278,
  30804. 'ncaron': 611,
  30805. 'tcommaaccent': 333,
  30806. 'logicalnot': 584,
  30807. 'odieresis': 611,
  30808. 'udieresis': 611,
  30809. 'notequal': 549,
  30810. 'gcommaaccent': 611,
  30811. 'eth': 611,
  30812. 'zcaron': 500,
  30813. 'ncommaaccent': 611,
  30814. 'onesuperior': 333,
  30815. 'imacron': 278,
  30816. 'Euro': 556
  30817. },
  30818. 'Helvetica-Oblique' : {
  30819. 'space': 278,
  30820. 'exclam': 278,
  30821. 'quotedbl': 355,
  30822. 'numbersign': 556,
  30823. 'dollar': 556,
  30824. 'percent': 889,
  30825. 'ampersand': 667,
  30826. 'quoteright': 222,
  30827. 'parenleft': 333,
  30828. 'parenright': 333,
  30829. 'asterisk': 389,
  30830. 'plus': 584,
  30831. 'comma': 278,
  30832. 'hyphen': 333,
  30833. 'period': 278,
  30834. 'slash': 278,
  30835. 'zero': 556,
  30836. 'one': 556,
  30837. 'two': 556,
  30838. 'three': 556,
  30839. 'four': 556,
  30840. 'five': 556,
  30841. 'six': 556,
  30842. 'seven': 556,
  30843. 'eight': 556,
  30844. 'nine': 556,
  30845. 'colon': 278,
  30846. 'semicolon': 278,
  30847. 'less': 584,
  30848. 'equal': 584,
  30849. 'greater': 584,
  30850. 'question': 556,
  30851. 'at': 1015,
  30852. 'A': 667,
  30853. 'B': 667,
  30854. 'C': 722,
  30855. 'D': 722,
  30856. 'E': 667,
  30857. 'F': 611,
  30858. 'G': 778,
  30859. 'H': 722,
  30860. 'I': 278,
  30861. 'J': 500,
  30862. 'K': 667,
  30863. 'L': 556,
  30864. 'M': 833,
  30865. 'N': 722,
  30866. 'O': 778,
  30867. 'P': 667,
  30868. 'Q': 778,
  30869. 'R': 722,
  30870. 'S': 667,
  30871. 'T': 611,
  30872. 'U': 722,
  30873. 'V': 667,
  30874. 'W': 944,
  30875. 'X': 667,
  30876. 'Y': 667,
  30877. 'Z': 611,
  30878. 'bracketleft': 278,
  30879. 'backslash': 278,
  30880. 'bracketright': 278,
  30881. 'asciicircum': 469,
  30882. 'underscore': 556,
  30883. 'quoteleft': 222,
  30884. 'a': 556,
  30885. 'b': 556,
  30886. 'c': 500,
  30887. 'd': 556,
  30888. 'e': 556,
  30889. 'f': 278,
  30890. 'g': 556,
  30891. 'h': 556,
  30892. 'i': 222,
  30893. 'j': 222,
  30894. 'k': 500,
  30895. 'l': 222,
  30896. 'm': 833,
  30897. 'n': 556,
  30898. 'o': 556,
  30899. 'p': 556,
  30900. 'q': 556,
  30901. 'r': 333,
  30902. 's': 500,
  30903. 't': 278,
  30904. 'u': 556,
  30905. 'v': 500,
  30906. 'w': 722,
  30907. 'x': 500,
  30908. 'y': 500,
  30909. 'z': 500,
  30910. 'braceleft': 334,
  30911. 'bar': 260,
  30912. 'braceright': 334,
  30913. 'asciitilde': 584,
  30914. 'exclamdown': 333,
  30915. 'cent': 556,
  30916. 'sterling': 556,
  30917. 'fraction': 167,
  30918. 'yen': 556,
  30919. 'florin': 556,
  30920. 'section': 556,
  30921. 'currency': 556,
  30922. 'quotesingle': 191,
  30923. 'quotedblleft': 333,
  30924. 'guillemotleft': 556,
  30925. 'guilsinglleft': 333,
  30926. 'guilsinglright': 333,
  30927. 'fi': 500,
  30928. 'fl': 500,
  30929. 'endash': 556,
  30930. 'dagger': 556,
  30931. 'daggerdbl': 556,
  30932. 'periodcentered': 278,
  30933. 'paragraph': 537,
  30934. 'bullet': 350,
  30935. 'quotesinglbase': 222,
  30936. 'quotedblbase': 333,
  30937. 'quotedblright': 333,
  30938. 'guillemotright': 556,
  30939. 'ellipsis': 1000,
  30940. 'perthousand': 1000,
  30941. 'questiondown': 611,
  30942. 'grave': 333,
  30943. 'acute': 333,
  30944. 'circumflex': 333,
  30945. 'tilde': 333,
  30946. 'macron': 333,
  30947. 'breve': 333,
  30948. 'dotaccent': 333,
  30949. 'dieresis': 333,
  30950. 'ring': 333,
  30951. 'cedilla': 333,
  30952. 'hungarumlaut': 333,
  30953. 'ogonek': 333,
  30954. 'caron': 333,
  30955. 'emdash': 1000,
  30956. 'AE': 1000,
  30957. 'ordfeminine': 370,
  30958. 'Lslash': 556,
  30959. 'Oslash': 778,
  30960. 'OE': 1000,
  30961. 'ordmasculine': 365,
  30962. 'ae': 889,
  30963. 'dotlessi': 278,
  30964. 'lslash': 222,
  30965. 'oslash': 611,
  30966. 'oe': 944,
  30967. 'germandbls': 611,
  30968. 'Idieresis': 278,
  30969. 'eacute': 556,
  30970. 'abreve': 556,
  30971. 'uhungarumlaut': 556,
  30972. 'ecaron': 556,
  30973. 'Ydieresis': 667,
  30974. 'divide': 584,
  30975. 'Yacute': 667,
  30976. 'Acircumflex': 667,
  30977. 'aacute': 556,
  30978. 'Ucircumflex': 722,
  30979. 'yacute': 500,
  30980. 'scommaaccent': 500,
  30981. 'ecircumflex': 556,
  30982. 'Uring': 722,
  30983. 'Udieresis': 722,
  30984. 'aogonek': 556,
  30985. 'Uacute': 722,
  30986. 'uogonek': 556,
  30987. 'Edieresis': 667,
  30988. 'Dcroat': 722,
  30989. 'commaaccent': 250,
  30990. 'copyright': 737,
  30991. 'Emacron': 667,
  30992. 'ccaron': 500,
  30993. 'aring': 556,
  30994. 'Ncommaaccent': 722,
  30995. 'lacute': 222,
  30996. 'agrave': 556,
  30997. 'Tcommaaccent': 611,
  30998. 'Cacute': 722,
  30999. 'atilde': 556,
  31000. 'Edotaccent': 667,
  31001. 'scaron': 500,
  31002. 'scedilla': 500,
  31003. 'iacute': 278,
  31004. 'lozenge': 471,
  31005. 'Rcaron': 722,
  31006. 'Gcommaaccent': 778,
  31007. 'ucircumflex': 556,
  31008. 'acircumflex': 556,
  31009. 'Amacron': 667,
  31010. 'rcaron': 333,
  31011. 'ccedilla': 500,
  31012. 'Zdotaccent': 611,
  31013. 'Thorn': 667,
  31014. 'Omacron': 778,
  31015. 'Racute': 722,
  31016. 'Sacute': 667,
  31017. 'dcaron': 643,
  31018. 'Umacron': 722,
  31019. 'uring': 556,
  31020. 'threesuperior': 333,
  31021. 'Ograve': 778,
  31022. 'Agrave': 667,
  31023. 'Abreve': 667,
  31024. 'multiply': 584,
  31025. 'uacute': 556,
  31026. 'Tcaron': 611,
  31027. 'partialdiff': 476,
  31028. 'ydieresis': 500,
  31029. 'Nacute': 722,
  31030. 'icircumflex': 278,
  31031. 'Ecircumflex': 667,
  31032. 'adieresis': 556,
  31033. 'edieresis': 556,
  31034. 'cacute': 500,
  31035. 'nacute': 556,
  31036. 'umacron': 556,
  31037. 'Ncaron': 722,
  31038. 'Iacute': 278,
  31039. 'plusminus': 584,
  31040. 'brokenbar': 260,
  31041. 'registered': 737,
  31042. 'Gbreve': 778,
  31043. 'Idotaccent': 278,
  31044. 'summation': 600,
  31045. 'Egrave': 667,
  31046. 'racute': 333,
  31047. 'omacron': 556,
  31048. 'Zacute': 611,
  31049. 'Zcaron': 611,
  31050. 'greaterequal': 549,
  31051. 'Eth': 722,
  31052. 'Ccedilla': 722,
  31053. 'lcommaaccent': 222,
  31054. 'tcaron': 317,
  31055. 'eogonek': 556,
  31056. 'Uogonek': 722,
  31057. 'Aacute': 667,
  31058. 'Adieresis': 667,
  31059. 'egrave': 556,
  31060. 'zacute': 500,
  31061. 'iogonek': 222,
  31062. 'Oacute': 778,
  31063. 'oacute': 556,
  31064. 'amacron': 556,
  31065. 'sacute': 500,
  31066. 'idieresis': 278,
  31067. 'Ocircumflex': 778,
  31068. 'Ugrave': 722,
  31069. 'Delta': 612,
  31070. 'thorn': 556,
  31071. 'twosuperior': 333,
  31072. 'Odieresis': 778,
  31073. 'mu': 556,
  31074. 'igrave': 278,
  31075. 'ohungarumlaut': 556,
  31076. 'Eogonek': 667,
  31077. 'dcroat': 556,
  31078. 'threequarters': 834,
  31079. 'Scedilla': 667,
  31080. 'lcaron': 299,
  31081. 'Kcommaaccent': 667,
  31082. 'Lacute': 556,
  31083. 'trademark': 1000,
  31084. 'edotaccent': 556,
  31085. 'Igrave': 278,
  31086. 'Imacron': 278,
  31087. 'Lcaron': 556,
  31088. 'onehalf': 834,
  31089. 'lessequal': 549,
  31090. 'ocircumflex': 556,
  31091. 'ntilde': 556,
  31092. 'Uhungarumlaut': 722,
  31093. 'Eacute': 667,
  31094. 'emacron': 556,
  31095. 'gbreve': 556,
  31096. 'onequarter': 834,
  31097. 'Scaron': 667,
  31098. 'Scommaaccent': 667,
  31099. 'Ohungarumlaut': 778,
  31100. 'degree': 400,
  31101. 'ograve': 556,
  31102. 'Ccaron': 722,
  31103. 'ugrave': 556,
  31104. 'radical': 453,
  31105. 'Dcaron': 722,
  31106. 'rcommaaccent': 333,
  31107. 'Ntilde': 722,
  31108. 'otilde': 556,
  31109. 'Rcommaaccent': 722,
  31110. 'Lcommaaccent': 556,
  31111. 'Atilde': 667,
  31112. 'Aogonek': 667,
  31113. 'Aring': 667,
  31114. 'Otilde': 778,
  31115. 'zdotaccent': 500,
  31116. 'Ecaron': 667,
  31117. 'Iogonek': 278,
  31118. 'kcommaaccent': 500,
  31119. 'minus': 584,
  31120. 'Icircumflex': 278,
  31121. 'ncaron': 556,
  31122. 'tcommaaccent': 278,
  31123. 'logicalnot': 584,
  31124. 'odieresis': 556,
  31125. 'udieresis': 556,
  31126. 'notequal': 549,
  31127. 'gcommaaccent': 556,
  31128. 'eth': 556,
  31129. 'zcaron': 500,
  31130. 'ncommaaccent': 556,
  31131. 'onesuperior': 333,
  31132. 'imacron': 278,
  31133. 'Euro': 556
  31134. },
  31135. 'Symbol': {
  31136. 'space': 250,
  31137. 'exclam': 333,
  31138. 'universal': 713,
  31139. 'numbersign': 500,
  31140. 'existential': 549,
  31141. 'percent': 833,
  31142. 'ampersand': 778,
  31143. 'suchthat': 439,
  31144. 'parenleft': 333,
  31145. 'parenright': 333,
  31146. 'asteriskmath': 500,
  31147. 'plus': 549,
  31148. 'comma': 250,
  31149. 'minus': 549,
  31150. 'period': 250,
  31151. 'slash': 278,
  31152. 'zero': 500,
  31153. 'one': 500,
  31154. 'two': 500,
  31155. 'three': 500,
  31156. 'four': 500,
  31157. 'five': 500,
  31158. 'six': 500,
  31159. 'seven': 500,
  31160. 'eight': 500,
  31161. 'nine': 500,
  31162. 'colon': 278,
  31163. 'semicolon': 278,
  31164. 'less': 549,
  31165. 'equal': 549,
  31166. 'greater': 549,
  31167. 'question': 444,
  31168. 'congruent': 549,
  31169. 'Alpha': 722,
  31170. 'Beta': 667,
  31171. 'Chi': 722,
  31172. 'Delta': 612,
  31173. 'Epsilon': 611,
  31174. 'Phi': 763,
  31175. 'Gamma': 603,
  31176. 'Eta': 722,
  31177. 'Iota': 333,
  31178. 'theta1': 631,
  31179. 'Kappa': 722,
  31180. 'Lambda': 686,
  31181. 'Mu': 889,
  31182. 'Nu': 722,
  31183. 'Omicron': 722,
  31184. 'Pi': 768,
  31185. 'Theta': 741,
  31186. 'Rho': 556,
  31187. 'Sigma': 592,
  31188. 'Tau': 611,
  31189. 'Upsilon': 690,
  31190. 'sigma1': 439,
  31191. 'Omega': 768,
  31192. 'Xi': 645,
  31193. 'Psi': 795,
  31194. 'Zeta': 611,
  31195. 'bracketleft': 333,
  31196. 'therefore': 863,
  31197. 'bracketright': 333,
  31198. 'perpendicular': 658,
  31199. 'underscore': 500,
  31200. 'radicalex': 500,
  31201. 'alpha': 631,
  31202. 'beta': 549,
  31203. 'chi': 549,
  31204. 'delta': 494,
  31205. 'epsilon': 439,
  31206. 'phi': 521,
  31207. 'gamma': 411,
  31208. 'eta': 603,
  31209. 'iota': 329,
  31210. 'phi1': 603,
  31211. 'kappa': 549,
  31212. 'lambda': 549,
  31213. 'mu': 576,
  31214. 'nu': 521,
  31215. 'omicron': 549,
  31216. 'pi': 549,
  31217. 'theta': 521,
  31218. 'rho': 549,
  31219. 'sigma': 603,
  31220. 'tau': 439,
  31221. 'upsilon': 576,
  31222. 'omega1': 713,
  31223. 'omega': 686,
  31224. 'xi': 493,
  31225. 'psi': 686,
  31226. 'zeta': 494,
  31227. 'braceleft': 480,
  31228. 'bar': 200,
  31229. 'braceright': 480,
  31230. 'similar': 549,
  31231. 'Euro': 750,
  31232. 'Upsilon1': 620,
  31233. 'minute': 247,
  31234. 'lessequal': 549,
  31235. 'fraction': 167,
  31236. 'infinity': 713,
  31237. 'florin': 500,
  31238. 'club': 753,
  31239. 'diamond': 753,
  31240. 'heart': 753,
  31241. 'spade': 753,
  31242. 'arrowboth': 1042,
  31243. 'arrowleft': 987,
  31244. 'arrowup': 603,
  31245. 'arrowright': 987,
  31246. 'arrowdown': 603,
  31247. 'degree': 400,
  31248. 'plusminus': 549,
  31249. 'second': 411,
  31250. 'greaterequal': 549,
  31251. 'multiply': 549,
  31252. 'proportional': 713,
  31253. 'partialdiff': 494,
  31254. 'bullet': 460,
  31255. 'divide': 549,
  31256. 'notequal': 549,
  31257. 'equivalence': 549,
  31258. 'approxequal': 549,
  31259. 'ellipsis': 1000,
  31260. 'arrowvertex': 603,
  31261. 'arrowhorizex': 1000,
  31262. 'carriagereturn': 658,
  31263. 'aleph': 823,
  31264. 'Ifraktur': 686,
  31265. 'Rfraktur': 795,
  31266. 'weierstrass': 987,
  31267. 'circlemultiply': 768,
  31268. 'circleplus': 768,
  31269. 'emptyset': 823,
  31270. 'intersection': 768,
  31271. 'union': 768,
  31272. 'propersuperset': 713,
  31273. 'reflexsuperset': 713,
  31274. 'notsubset': 713,
  31275. 'propersubset': 713,
  31276. 'reflexsubset': 713,
  31277. 'element': 713,
  31278. 'notelement': 713,
  31279. 'angle': 768,
  31280. 'gradient': 713,
  31281. 'registerserif': 790,
  31282. 'copyrightserif': 790,
  31283. 'trademarkserif': 890,
  31284. 'product': 823,
  31285. 'radical': 549,
  31286. 'dotmath': 250,
  31287. 'logicalnot': 713,
  31288. 'logicaland': 603,
  31289. 'logicalor': 603,
  31290. 'arrowdblboth': 1042,
  31291. 'arrowdblleft': 987,
  31292. 'arrowdblup': 603,
  31293. 'arrowdblright': 987,
  31294. 'arrowdbldown': 603,
  31295. 'lozenge': 494,
  31296. 'angleleft': 329,
  31297. 'registersans': 790,
  31298. 'copyrightsans': 790,
  31299. 'trademarksans': 786,
  31300. 'summation': 713,
  31301. 'parenlefttp': 384,
  31302. 'parenleftex': 384,
  31303. 'parenleftbt': 384,
  31304. 'bracketlefttp': 384,
  31305. 'bracketleftex': 384,
  31306. 'bracketleftbt': 384,
  31307. 'bracelefttp': 494,
  31308. 'braceleftmid': 494,
  31309. 'braceleftbt': 494,
  31310. 'braceex': 494,
  31311. 'angleright': 329,
  31312. 'integral': 274,
  31313. 'integraltp': 686,
  31314. 'integralex': 686,
  31315. 'integralbt': 686,
  31316. 'parenrighttp': 384,
  31317. 'parenrightex': 384,
  31318. 'parenrightbt': 384,
  31319. 'bracketrighttp': 384,
  31320. 'bracketrightex': 384,
  31321. 'bracketrightbt': 384,
  31322. 'bracerighttp': 494,
  31323. 'bracerightmid': 494,
  31324. 'bracerightbt': 494,
  31325. 'apple': 790
  31326. },
  31327. 'Times-Roman': {
  31328. 'space': 250,
  31329. 'exclam': 333,
  31330. 'quotedbl': 408,
  31331. 'numbersign': 500,
  31332. 'dollar': 500,
  31333. 'percent': 833,
  31334. 'ampersand': 778,
  31335. 'quoteright': 333,
  31336. 'parenleft': 333,
  31337. 'parenright': 333,
  31338. 'asterisk': 500,
  31339. 'plus': 564,
  31340. 'comma': 250,
  31341. 'hyphen': 333,
  31342. 'period': 250,
  31343. 'slash': 278,
  31344. 'zero': 500,
  31345. 'one': 500,
  31346. 'two': 500,
  31347. 'three': 500,
  31348. 'four': 500,
  31349. 'five': 500,
  31350. 'six': 500,
  31351. 'seven': 500,
  31352. 'eight': 500,
  31353. 'nine': 500,
  31354. 'colon': 278,
  31355. 'semicolon': 278,
  31356. 'less': 564,
  31357. 'equal': 564,
  31358. 'greater': 564,
  31359. 'question': 444,
  31360. 'at': 921,
  31361. 'A': 722,
  31362. 'B': 667,
  31363. 'C': 667,
  31364. 'D': 722,
  31365. 'E': 611,
  31366. 'F': 556,
  31367. 'G': 722,
  31368. 'H': 722,
  31369. 'I': 333,
  31370. 'J': 389,
  31371. 'K': 722,
  31372. 'L': 611,
  31373. 'M': 889,
  31374. 'N': 722,
  31375. 'O': 722,
  31376. 'P': 556,
  31377. 'Q': 722,
  31378. 'R': 667,
  31379. 'S': 556,
  31380. 'T': 611,
  31381. 'U': 722,
  31382. 'V': 722,
  31383. 'W': 944,
  31384. 'X': 722,
  31385. 'Y': 722,
  31386. 'Z': 611,
  31387. 'bracketleft': 333,
  31388. 'backslash': 278,
  31389. 'bracketright': 333,
  31390. 'asciicircum': 469,
  31391. 'underscore': 500,
  31392. 'quoteleft': 333,
  31393. 'a': 444,
  31394. 'b': 500,
  31395. 'c': 444,
  31396. 'd': 500,
  31397. 'e': 444,
  31398. 'f': 333,
  31399. 'g': 500,
  31400. 'h': 500,
  31401. 'i': 278,
  31402. 'j': 278,
  31403. 'k': 500,
  31404. 'l': 278,
  31405. 'm': 778,
  31406. 'n': 500,
  31407. 'o': 500,
  31408. 'p': 500,
  31409. 'q': 500,
  31410. 'r': 333,
  31411. 's': 389,
  31412. 't': 278,
  31413. 'u': 500,
  31414. 'v': 500,
  31415. 'w': 722,
  31416. 'x': 500,
  31417. 'y': 500,
  31418. 'z': 444,
  31419. 'braceleft': 480,
  31420. 'bar': 200,
  31421. 'braceright': 480,
  31422. 'asciitilde': 541,
  31423. 'exclamdown': 333,
  31424. 'cent': 500,
  31425. 'sterling': 500,
  31426. 'fraction': 167,
  31427. 'yen': 500,
  31428. 'florin': 500,
  31429. 'section': 500,
  31430. 'currency': 500,
  31431. 'quotesingle': 180,
  31432. 'quotedblleft': 444,
  31433. 'guillemotleft': 500,
  31434. 'guilsinglleft': 333,
  31435. 'guilsinglright': 333,
  31436. 'fi': 556,
  31437. 'fl': 556,
  31438. 'endash': 500,
  31439. 'dagger': 500,
  31440. 'daggerdbl': 500,
  31441. 'periodcentered': 250,
  31442. 'paragraph': 453,
  31443. 'bullet': 350,
  31444. 'quotesinglbase': 333,
  31445. 'quotedblbase': 444,
  31446. 'quotedblright': 444,
  31447. 'guillemotright': 500,
  31448. 'ellipsis': 1000,
  31449. 'perthousand': 1000,
  31450. 'questiondown': 444,
  31451. 'grave': 333,
  31452. 'acute': 333,
  31453. 'circumflex': 333,
  31454. 'tilde': 333,
  31455. 'macron': 333,
  31456. 'breve': 333,
  31457. 'dotaccent': 333,
  31458. 'dieresis': 333,
  31459. 'ring': 333,
  31460. 'cedilla': 333,
  31461. 'hungarumlaut': 333,
  31462. 'ogonek': 333,
  31463. 'caron': 333,
  31464. 'emdash': 1000,
  31465. 'AE': 889,
  31466. 'ordfeminine': 276,
  31467. 'Lslash': 611,
  31468. 'Oslash': 722,
  31469. 'OE': 889,
  31470. 'ordmasculine': 310,
  31471. 'ae': 667,
  31472. 'dotlessi': 278,
  31473. 'lslash': 278,
  31474. 'oslash': 500,
  31475. 'oe': 722,
  31476. 'germandbls': 500,
  31477. 'Idieresis': 333,
  31478. 'eacute': 444,
  31479. 'abreve': 444,
  31480. 'uhungarumlaut': 500,
  31481. 'ecaron': 444,
  31482. 'Ydieresis': 722,
  31483. 'divide': 564,
  31484. 'Yacute': 722,
  31485. 'Acircumflex': 722,
  31486. 'aacute': 444,
  31487. 'Ucircumflex': 722,
  31488. 'yacute': 500,
  31489. 'scommaaccent': 389,
  31490. 'ecircumflex': 444,
  31491. 'Uring': 722,
  31492. 'Udieresis': 722,
  31493. 'aogonek': 444,
  31494. 'Uacute': 722,
  31495. 'uogonek': 500,
  31496. 'Edieresis': 611,
  31497. 'Dcroat': 722,
  31498. 'commaaccent': 250,
  31499. 'copyright': 760,
  31500. 'Emacron': 611,
  31501. 'ccaron': 444,
  31502. 'aring': 444,
  31503. 'Ncommaaccent': 722,
  31504. 'lacute': 278,
  31505. 'agrave': 444,
  31506. 'Tcommaaccent': 611,
  31507. 'Cacute': 667,
  31508. 'atilde': 444,
  31509. 'Edotaccent': 611,
  31510. 'scaron': 389,
  31511. 'scedilla': 389,
  31512. 'iacute': 278,
  31513. 'lozenge': 471,
  31514. 'Rcaron': 667,
  31515. 'Gcommaaccent': 722,
  31516. 'ucircumflex': 500,
  31517. 'acircumflex': 444,
  31518. 'Amacron': 722,
  31519. 'rcaron': 333,
  31520. 'ccedilla': 444,
  31521. 'Zdotaccent': 611,
  31522. 'Thorn': 556,
  31523. 'Omacron': 722,
  31524. 'Racute': 667,
  31525. 'Sacute': 556,
  31526. 'dcaron': 588,
  31527. 'Umacron': 722,
  31528. 'uring': 500,
  31529. 'threesuperior': 300,
  31530. 'Ograve': 722,
  31531. 'Agrave': 722,
  31532. 'Abreve': 722,
  31533. 'multiply': 564,
  31534. 'uacute': 500,
  31535. 'Tcaron': 611,
  31536. 'partialdiff': 476,
  31537. 'ydieresis': 500,
  31538. 'Nacute': 722,
  31539. 'icircumflex': 278,
  31540. 'Ecircumflex': 611,
  31541. 'adieresis': 444,
  31542. 'edieresis': 444,
  31543. 'cacute': 444,
  31544. 'nacute': 500,
  31545. 'umacron': 500,
  31546. 'Ncaron': 722,
  31547. 'Iacute': 333,
  31548. 'plusminus': 564,
  31549. 'brokenbar': 200,
  31550. 'registered': 760,
  31551. 'Gbreve': 722,
  31552. 'Idotaccent': 333,
  31553. 'summation': 600,
  31554. 'Egrave': 611,
  31555. 'racute': 333,
  31556. 'omacron': 500,
  31557. 'Zacute': 611,
  31558. 'Zcaron': 611,
  31559. 'greaterequal': 549,
  31560. 'Eth': 722,
  31561. 'Ccedilla': 667,
  31562. 'lcommaaccent': 278,
  31563. 'tcaron': 326,
  31564. 'eogonek': 444,
  31565. 'Uogonek': 722,
  31566. 'Aacute': 722,
  31567. 'Adieresis': 722,
  31568. 'egrave': 444,
  31569. 'zacute': 444,
  31570. 'iogonek': 278,
  31571. 'Oacute': 722,
  31572. 'oacute': 500,
  31573. 'amacron': 444,
  31574. 'sacute': 389,
  31575. 'idieresis': 278,
  31576. 'Ocircumflex': 722,
  31577. 'Ugrave': 722,
  31578. 'Delta': 612,
  31579. 'thorn': 500,
  31580. 'twosuperior': 300,
  31581. 'Odieresis': 722,
  31582. 'mu': 500,
  31583. 'igrave': 278,
  31584. 'ohungarumlaut': 500,
  31585. 'Eogonek': 611,
  31586. 'dcroat': 500,
  31587. 'threequarters': 750,
  31588. 'Scedilla': 556,
  31589. 'lcaron': 344,
  31590. 'Kcommaaccent': 722,
  31591. 'Lacute': 611,
  31592. 'trademark': 980,
  31593. 'edotaccent': 444,
  31594. 'Igrave': 333,
  31595. 'Imacron': 333,
  31596. 'Lcaron': 611,
  31597. 'onehalf': 750,
  31598. 'lessequal': 549,
  31599. 'ocircumflex': 500,
  31600. 'ntilde': 500,
  31601. 'Uhungarumlaut': 722,
  31602. 'Eacute': 611,
  31603. 'emacron': 444,
  31604. 'gbreve': 500,
  31605. 'onequarter': 750,
  31606. 'Scaron': 556,
  31607. 'Scommaaccent': 556,
  31608. 'Ohungarumlaut': 722,
  31609. 'degree': 400,
  31610. 'ograve': 500,
  31611. 'Ccaron': 667,
  31612. 'ugrave': 500,
  31613. 'radical': 453,
  31614. 'Dcaron': 722,
  31615. 'rcommaaccent': 333,
  31616. 'Ntilde': 722,
  31617. 'otilde': 500,
  31618. 'Rcommaaccent': 667,
  31619. 'Lcommaaccent': 611,
  31620. 'Atilde': 722,
  31621. 'Aogonek': 722,
  31622. 'Aring': 722,
  31623. 'Otilde': 722,
  31624. 'zdotaccent': 444,
  31625. 'Ecaron': 611,
  31626. 'Iogonek': 333,
  31627. 'kcommaaccent': 500,
  31628. 'minus': 564,
  31629. 'Icircumflex': 333,
  31630. 'ncaron': 500,
  31631. 'tcommaaccent': 278,
  31632. 'logicalnot': 564,
  31633. 'odieresis': 500,
  31634. 'udieresis': 500,
  31635. 'notequal': 549,
  31636. 'gcommaaccent': 500,
  31637. 'eth': 500,
  31638. 'zcaron': 444,
  31639. 'ncommaaccent': 500,
  31640. 'onesuperior': 300,
  31641. 'imacron': 278,
  31642. 'Euro': 500
  31643. },
  31644. 'Times-Bold': {
  31645. 'space': 250,
  31646. 'exclam': 333,
  31647. 'quotedbl': 555,
  31648. 'numbersign': 500,
  31649. 'dollar': 500,
  31650. 'percent': 1000,
  31651. 'ampersand': 833,
  31652. 'quoteright': 333,
  31653. 'parenleft': 333,
  31654. 'parenright': 333,
  31655. 'asterisk': 500,
  31656. 'plus': 570,
  31657. 'comma': 250,
  31658. 'hyphen': 333,
  31659. 'period': 250,
  31660. 'slash': 278,
  31661. 'zero': 500,
  31662. 'one': 500,
  31663. 'two': 500,
  31664. 'three': 500,
  31665. 'four': 500,
  31666. 'five': 500,
  31667. 'six': 500,
  31668. 'seven': 500,
  31669. 'eight': 500,
  31670. 'nine': 500,
  31671. 'colon': 333,
  31672. 'semicolon': 333,
  31673. 'less': 570,
  31674. 'equal': 570,
  31675. 'greater': 570,
  31676. 'question': 500,
  31677. 'at': 930,
  31678. 'A': 722,
  31679. 'B': 667,
  31680. 'C': 722,
  31681. 'D': 722,
  31682. 'E': 667,
  31683. 'F': 611,
  31684. 'G': 778,
  31685. 'H': 778,
  31686. 'I': 389,
  31687. 'J': 500,
  31688. 'K': 778,
  31689. 'L': 667,
  31690. 'M': 944,
  31691. 'N': 722,
  31692. 'O': 778,
  31693. 'P': 611,
  31694. 'Q': 778,
  31695. 'R': 722,
  31696. 'S': 556,
  31697. 'T': 667,
  31698. 'U': 722,
  31699. 'V': 722,
  31700. 'W': 1000,
  31701. 'X': 722,
  31702. 'Y': 722,
  31703. 'Z': 667,
  31704. 'bracketleft': 333,
  31705. 'backslash': 278,
  31706. 'bracketright': 333,
  31707. 'asciicircum': 581,
  31708. 'underscore': 500,
  31709. 'quoteleft': 333,
  31710. 'a': 500,
  31711. 'b': 556,
  31712. 'c': 444,
  31713. 'd': 556,
  31714. 'e': 444,
  31715. 'f': 333,
  31716. 'g': 500,
  31717. 'h': 556,
  31718. 'i': 278,
  31719. 'j': 333,
  31720. 'k': 556,
  31721. 'l': 278,
  31722. 'm': 833,
  31723. 'n': 556,
  31724. 'o': 500,
  31725. 'p': 556,
  31726. 'q': 556,
  31727. 'r': 444,
  31728. 's': 389,
  31729. 't': 333,
  31730. 'u': 556,
  31731. 'v': 500,
  31732. 'w': 722,
  31733. 'x': 500,
  31734. 'y': 500,
  31735. 'z': 444,
  31736. 'braceleft': 394,
  31737. 'bar': 220,
  31738. 'braceright': 394,
  31739. 'asciitilde': 520,
  31740. 'exclamdown': 333,
  31741. 'cent': 500,
  31742. 'sterling': 500,
  31743. 'fraction': 167,
  31744. 'yen': 500,
  31745. 'florin': 500,
  31746. 'section': 500,
  31747. 'currency': 500,
  31748. 'quotesingle': 278,
  31749. 'quotedblleft': 500,
  31750. 'guillemotleft': 500,
  31751. 'guilsinglleft': 333,
  31752. 'guilsinglright': 333,
  31753. 'fi': 556,
  31754. 'fl': 556,
  31755. 'endash': 500,
  31756. 'dagger': 500,
  31757. 'daggerdbl': 500,
  31758. 'periodcentered': 250,
  31759. 'paragraph': 540,
  31760. 'bullet': 350,
  31761. 'quotesinglbase': 333,
  31762. 'quotedblbase': 500,
  31763. 'quotedblright': 500,
  31764. 'guillemotright': 500,
  31765. 'ellipsis': 1000,
  31766. 'perthousand': 1000,
  31767. 'questiondown': 500,
  31768. 'grave': 333,
  31769. 'acute': 333,
  31770. 'circumflex': 333,
  31771. 'tilde': 333,
  31772. 'macron': 333,
  31773. 'breve': 333,
  31774. 'dotaccent': 333,
  31775. 'dieresis': 333,
  31776. 'ring': 333,
  31777. 'cedilla': 333,
  31778. 'hungarumlaut': 333,
  31779. 'ogonek': 333,
  31780. 'caron': 333,
  31781. 'emdash': 1000,
  31782. 'AE': 1000,
  31783. 'ordfeminine': 300,
  31784. 'Lslash': 667,
  31785. 'Oslash': 778,
  31786. 'OE': 1000,
  31787. 'ordmasculine': 330,
  31788. 'ae': 722,
  31789. 'dotlessi': 278,
  31790. 'lslash': 278,
  31791. 'oslash': 500,
  31792. 'oe': 722,
  31793. 'germandbls': 556,
  31794. 'Idieresis': 389,
  31795. 'eacute': 444,
  31796. 'abreve': 500,
  31797. 'uhungarumlaut': 556,
  31798. 'ecaron': 444,
  31799. 'Ydieresis': 722,
  31800. 'divide': 570,
  31801. 'Yacute': 722,
  31802. 'Acircumflex': 722,
  31803. 'aacute': 500,
  31804. 'Ucircumflex': 722,
  31805. 'yacute': 500,
  31806. 'scommaaccent': 389,
  31807. 'ecircumflex': 444,
  31808. 'Uring': 722,
  31809. 'Udieresis': 722,
  31810. 'aogonek': 500,
  31811. 'Uacute': 722,
  31812. 'uogonek': 556,
  31813. 'Edieresis': 667,
  31814. 'Dcroat': 722,
  31815. 'commaaccent': 250,
  31816. 'copyright': 747,
  31817. 'Emacron': 667,
  31818. 'ccaron': 444,
  31819. 'aring': 500,
  31820. 'Ncommaaccent': 722,
  31821. 'lacute': 278,
  31822. 'agrave': 500,
  31823. 'Tcommaaccent': 667,
  31824. 'Cacute': 722,
  31825. 'atilde': 500,
  31826. 'Edotaccent': 667,
  31827. 'scaron': 389,
  31828. 'scedilla': 389,
  31829. 'iacute': 278,
  31830. 'lozenge': 494,
  31831. 'Rcaron': 722,
  31832. 'Gcommaaccent': 778,
  31833. 'ucircumflex': 556,
  31834. 'acircumflex': 500,
  31835. 'Amacron': 722,
  31836. 'rcaron': 444,
  31837. 'ccedilla': 444,
  31838. 'Zdotaccent': 667,
  31839. 'Thorn': 611,
  31840. 'Omacron': 778,
  31841. 'Racute': 722,
  31842. 'Sacute': 556,
  31843. 'dcaron': 672,
  31844. 'Umacron': 722,
  31845. 'uring': 556,
  31846. 'threesuperior': 300,
  31847. 'Ograve': 778,
  31848. 'Agrave': 722,
  31849. 'Abreve': 722,
  31850. 'multiply': 570,
  31851. 'uacute': 556,
  31852. 'Tcaron': 667,
  31853. 'partialdiff': 494,
  31854. 'ydieresis': 500,
  31855. 'Nacute': 722,
  31856. 'icircumflex': 278,
  31857. 'Ecircumflex': 667,
  31858. 'adieresis': 500,
  31859. 'edieresis': 444,
  31860. 'cacute': 444,
  31861. 'nacute': 556,
  31862. 'umacron': 556,
  31863. 'Ncaron': 722,
  31864. 'Iacute': 389,
  31865. 'plusminus': 570,
  31866. 'brokenbar': 220,
  31867. 'registered': 747,
  31868. 'Gbreve': 778,
  31869. 'Idotaccent': 389,
  31870. 'summation': 600,
  31871. 'Egrave': 667,
  31872. 'racute': 444,
  31873. 'omacron': 500,
  31874. 'Zacute': 667,
  31875. 'Zcaron': 667,
  31876. 'greaterequal': 549,
  31877. 'Eth': 722,
  31878. 'Ccedilla': 722,
  31879. 'lcommaaccent': 278,
  31880. 'tcaron': 416,
  31881. 'eogonek': 444,
  31882. 'Uogonek': 722,
  31883. 'Aacute': 722,
  31884. 'Adieresis': 722,
  31885. 'egrave': 444,
  31886. 'zacute': 444,
  31887. 'iogonek': 278,
  31888. 'Oacute': 778,
  31889. 'oacute': 500,
  31890. 'amacron': 500,
  31891. 'sacute': 389,
  31892. 'idieresis': 278,
  31893. 'Ocircumflex': 778,
  31894. 'Ugrave': 722,
  31895. 'Delta': 612,
  31896. 'thorn': 556,
  31897. 'twosuperior': 300,
  31898. 'Odieresis': 778,
  31899. 'mu': 556,
  31900. 'igrave': 278,
  31901. 'ohungarumlaut': 500,
  31902. 'Eogonek': 667,
  31903. 'dcroat': 556,
  31904. 'threequarters': 750,
  31905. 'Scedilla': 556,
  31906. 'lcaron': 394,
  31907. 'Kcommaaccent': 778,
  31908. 'Lacute': 667,
  31909. 'trademark': 1000,
  31910. 'edotaccent': 444,
  31911. 'Igrave': 389,
  31912. 'Imacron': 389,
  31913. 'Lcaron': 667,
  31914. 'onehalf': 750,
  31915. 'lessequal': 549,
  31916. 'ocircumflex': 500,
  31917. 'ntilde': 556,
  31918. 'Uhungarumlaut': 722,
  31919. 'Eacute': 667,
  31920. 'emacron': 444,
  31921. 'gbreve': 500,
  31922. 'onequarter': 750,
  31923. 'Scaron': 556,
  31924. 'Scommaaccent': 556,
  31925. 'Ohungarumlaut': 778,
  31926. 'degree': 400,
  31927. 'ograve': 500,
  31928. 'Ccaron': 722,
  31929. 'ugrave': 556,
  31930. 'radical': 549,
  31931. 'Dcaron': 722,
  31932. 'rcommaaccent': 444,
  31933. 'Ntilde': 722,
  31934. 'otilde': 500,
  31935. 'Rcommaaccent': 722,
  31936. 'Lcommaaccent': 667,
  31937. 'Atilde': 722,
  31938. 'Aogonek': 722,
  31939. 'Aring': 722,
  31940. 'Otilde': 778,
  31941. 'zdotaccent': 444,
  31942. 'Ecaron': 667,
  31943. 'Iogonek': 389,
  31944. 'kcommaaccent': 556,
  31945. 'minus': 570,
  31946. 'Icircumflex': 389,
  31947. 'ncaron': 556,
  31948. 'tcommaaccent': 333,
  31949. 'logicalnot': 570,
  31950. 'odieresis': 500,
  31951. 'udieresis': 556,
  31952. 'notequal': 549,
  31953. 'gcommaaccent': 500,
  31954. 'eth': 500,
  31955. 'zcaron': 444,
  31956. 'ncommaaccent': 556,
  31957. 'onesuperior': 300,
  31958. 'imacron': 278,
  31959. 'Euro': 500
  31960. },
  31961. 'Times-BoldItalic': {
  31962. 'space': 250,
  31963. 'exclam': 389,
  31964. 'quotedbl': 555,
  31965. 'numbersign': 500,
  31966. 'dollar': 500,
  31967. 'percent': 833,
  31968. 'ampersand': 778,
  31969. 'quoteright': 333,
  31970. 'parenleft': 333,
  31971. 'parenright': 333,
  31972. 'asterisk': 500,
  31973. 'plus': 570,
  31974. 'comma': 250,
  31975. 'hyphen': 333,
  31976. 'period': 250,
  31977. 'slash': 278,
  31978. 'zero': 500,
  31979. 'one': 500,
  31980. 'two': 500,
  31981. 'three': 500,
  31982. 'four': 500,
  31983. 'five': 500,
  31984. 'six': 500,
  31985. 'seven': 500,
  31986. 'eight': 500,
  31987. 'nine': 500,
  31988. 'colon': 333,
  31989. 'semicolon': 333,
  31990. 'less': 570,
  31991. 'equal': 570,
  31992. 'greater': 570,
  31993. 'question': 500,
  31994. 'at': 832,
  31995. 'A': 667,
  31996. 'B': 667,
  31997. 'C': 667,
  31998. 'D': 722,
  31999. 'E': 667,
  32000. 'F': 667,
  32001. 'G': 722,
  32002. 'H': 778,
  32003. 'I': 389,
  32004. 'J': 500,
  32005. 'K': 667,
  32006. 'L': 611,
  32007. 'M': 889,
  32008. 'N': 722,
  32009. 'O': 722,
  32010. 'P': 611,
  32011. 'Q': 722,
  32012. 'R': 667,
  32013. 'S': 556,
  32014. 'T': 611,
  32015. 'U': 722,
  32016. 'V': 667,
  32017. 'W': 889,
  32018. 'X': 667,
  32019. 'Y': 611,
  32020. 'Z': 611,
  32021. 'bracketleft': 333,
  32022. 'backslash': 278,
  32023. 'bracketright': 333,
  32024. 'asciicircum': 570,
  32025. 'underscore': 500,
  32026. 'quoteleft': 333,
  32027. 'a': 500,
  32028. 'b': 500,
  32029. 'c': 444,
  32030. 'd': 500,
  32031. 'e': 444,
  32032. 'f': 333,
  32033. 'g': 500,
  32034. 'h': 556,
  32035. 'i': 278,
  32036. 'j': 278,
  32037. 'k': 500,
  32038. 'l': 278,
  32039. 'm': 778,
  32040. 'n': 556,
  32041. 'o': 500,
  32042. 'p': 500,
  32043. 'q': 500,
  32044. 'r': 389,
  32045. 's': 389,
  32046. 't': 278,
  32047. 'u': 556,
  32048. 'v': 444,
  32049. 'w': 667,
  32050. 'x': 500,
  32051. 'y': 444,
  32052. 'z': 389,
  32053. 'braceleft': 348,
  32054. 'bar': 220,
  32055. 'braceright': 348,
  32056. 'asciitilde': 570,
  32057. 'exclamdown': 389,
  32058. 'cent': 500,
  32059. 'sterling': 500,
  32060. 'fraction': 167,
  32061. 'yen': 500,
  32062. 'florin': 500,
  32063. 'section': 500,
  32064. 'currency': 500,
  32065. 'quotesingle': 278,
  32066. 'quotedblleft': 500,
  32067. 'guillemotleft': 500,
  32068. 'guilsinglleft': 333,
  32069. 'guilsinglright': 333,
  32070. 'fi': 556,
  32071. 'fl': 556,
  32072. 'endash': 500,
  32073. 'dagger': 500,
  32074. 'daggerdbl': 500,
  32075. 'periodcentered': 250,
  32076. 'paragraph': 500,
  32077. 'bullet': 350,
  32078. 'quotesinglbase': 333,
  32079. 'quotedblbase': 500,
  32080. 'quotedblright': 500,
  32081. 'guillemotright': 500,
  32082. 'ellipsis': 1000,
  32083. 'perthousand': 1000,
  32084. 'questiondown': 500,
  32085. 'grave': 333,
  32086. 'acute': 333,
  32087. 'circumflex': 333,
  32088. 'tilde': 333,
  32089. 'macron': 333,
  32090. 'breve': 333,
  32091. 'dotaccent': 333,
  32092. 'dieresis': 333,
  32093. 'ring': 333,
  32094. 'cedilla': 333,
  32095. 'hungarumlaut': 333,
  32096. 'ogonek': 333,
  32097. 'caron': 333,
  32098. 'emdash': 1000,
  32099. 'AE': 944,
  32100. 'ordfeminine': 266,
  32101. 'Lslash': 611,
  32102. 'Oslash': 722,
  32103. 'OE': 944,
  32104. 'ordmasculine': 300,
  32105. 'ae': 722,
  32106. 'dotlessi': 278,
  32107. 'lslash': 278,
  32108. 'oslash': 500,
  32109. 'oe': 722,
  32110. 'germandbls': 500,
  32111. 'Idieresis': 389,
  32112. 'eacute': 444,
  32113. 'abreve': 500,
  32114. 'uhungarumlaut': 556,
  32115. 'ecaron': 444,
  32116. 'Ydieresis': 611,
  32117. 'divide': 570,
  32118. 'Yacute': 611,
  32119. 'Acircumflex': 667,
  32120. 'aacute': 500,
  32121. 'Ucircumflex': 722,
  32122. 'yacute': 444,
  32123. 'scommaaccent': 389,
  32124. 'ecircumflex': 444,
  32125. 'Uring': 722,
  32126. 'Udieresis': 722,
  32127. 'aogonek': 500,
  32128. 'Uacute': 722,
  32129. 'uogonek': 556,
  32130. 'Edieresis': 667,
  32131. 'Dcroat': 722,
  32132. 'commaaccent': 250,
  32133. 'copyright': 747,
  32134. 'Emacron': 667,
  32135. 'ccaron': 444,
  32136. 'aring': 500,
  32137. 'Ncommaaccent': 722,
  32138. 'lacute': 278,
  32139. 'agrave': 500,
  32140. 'Tcommaaccent': 611,
  32141. 'Cacute': 667,
  32142. 'atilde': 500,
  32143. 'Edotaccent': 667,
  32144. 'scaron': 389,
  32145. 'scedilla': 389,
  32146. 'iacute': 278,
  32147. 'lozenge': 494,
  32148. 'Rcaron': 667,
  32149. 'Gcommaaccent': 722,
  32150. 'ucircumflex': 556,
  32151. 'acircumflex': 500,
  32152. 'Amacron': 667,
  32153. 'rcaron': 389,
  32154. 'ccedilla': 444,
  32155. 'Zdotaccent': 611,
  32156. 'Thorn': 611,
  32157. 'Omacron': 722,
  32158. 'Racute': 667,
  32159. 'Sacute': 556,
  32160. 'dcaron': 608,
  32161. 'Umacron': 722,
  32162. 'uring': 556,
  32163. 'threesuperior': 300,
  32164. 'Ograve': 722,
  32165. 'Agrave': 667,
  32166. 'Abreve': 667,
  32167. 'multiply': 570,
  32168. 'uacute': 556,
  32169. 'Tcaron': 611,
  32170. 'partialdiff': 494,
  32171. 'ydieresis': 444,
  32172. 'Nacute': 722,
  32173. 'icircumflex': 278,
  32174. 'Ecircumflex': 667,
  32175. 'adieresis': 500,
  32176. 'edieresis': 444,
  32177. 'cacute': 444,
  32178. 'nacute': 556,
  32179. 'umacron': 556,
  32180. 'Ncaron': 722,
  32181. 'Iacute': 389,
  32182. 'plusminus': 570,
  32183. 'brokenbar': 220,
  32184. 'registered': 747,
  32185. 'Gbreve': 722,
  32186. 'Idotaccent': 389,
  32187. 'summation': 600,
  32188. 'Egrave': 667,
  32189. 'racute': 389,
  32190. 'omacron': 500,
  32191. 'Zacute': 611,
  32192. 'Zcaron': 611,
  32193. 'greaterequal': 549,
  32194. 'Eth': 722,
  32195. 'Ccedilla': 667,
  32196. 'lcommaaccent': 278,
  32197. 'tcaron': 366,
  32198. 'eogonek': 444,
  32199. 'Uogonek': 722,
  32200. 'Aacute': 667,
  32201. 'Adieresis': 667,
  32202. 'egrave': 444,
  32203. 'zacute': 389,
  32204. 'iogonek': 278,
  32205. 'Oacute': 722,
  32206. 'oacute': 500,
  32207. 'amacron': 500,
  32208. 'sacute': 389,
  32209. 'idieresis': 278,
  32210. 'Ocircumflex': 722,
  32211. 'Ugrave': 722,
  32212. 'Delta': 612,
  32213. 'thorn': 500,
  32214. 'twosuperior': 300,
  32215. 'Odieresis': 722,
  32216. 'mu': 576,
  32217. 'igrave': 278,
  32218. 'ohungarumlaut': 500,
  32219. 'Eogonek': 667,
  32220. 'dcroat': 500,
  32221. 'threequarters': 750,
  32222. 'Scedilla': 556,
  32223. 'lcaron': 382,
  32224. 'Kcommaaccent': 667,
  32225. 'Lacute': 611,
  32226. 'trademark': 1000,
  32227. 'edotaccent': 444,
  32228. 'Igrave': 389,
  32229. 'Imacron': 389,
  32230. 'Lcaron': 611,
  32231. 'onehalf': 750,
  32232. 'lessequal': 549,
  32233. 'ocircumflex': 500,
  32234. 'ntilde': 556,
  32235. 'Uhungarumlaut': 722,
  32236. 'Eacute': 667,
  32237. 'emacron': 444,
  32238. 'gbreve': 500,
  32239. 'onequarter': 750,
  32240. 'Scaron': 556,
  32241. 'Scommaaccent': 556,
  32242. 'Ohungarumlaut': 722,
  32243. 'degree': 400,
  32244. 'ograve': 500,
  32245. 'Ccaron': 667,
  32246. 'ugrave': 556,
  32247. 'radical': 549,
  32248. 'Dcaron': 722,
  32249. 'rcommaaccent': 389,
  32250. 'Ntilde': 722,
  32251. 'otilde': 500,
  32252. 'Rcommaaccent': 667,
  32253. 'Lcommaaccent': 611,
  32254. 'Atilde': 667,
  32255. 'Aogonek': 667,
  32256. 'Aring': 667,
  32257. 'Otilde': 722,
  32258. 'zdotaccent': 389,
  32259. 'Ecaron': 667,
  32260. 'Iogonek': 389,
  32261. 'kcommaaccent': 500,
  32262. 'minus': 606,
  32263. 'Icircumflex': 389,
  32264. 'ncaron': 556,
  32265. 'tcommaaccent': 278,
  32266. 'logicalnot': 606,
  32267. 'odieresis': 500,
  32268. 'udieresis': 556,
  32269. 'notequal': 549,
  32270. 'gcommaaccent': 500,
  32271. 'eth': 500,
  32272. 'zcaron': 389,
  32273. 'ncommaaccent': 556,
  32274. 'onesuperior': 300,
  32275. 'imacron': 278,
  32276. 'Euro': 500
  32277. },
  32278. 'Times-Italic': {
  32279. 'space': 250,
  32280. 'exclam': 333,
  32281. 'quotedbl': 420,
  32282. 'numbersign': 500,
  32283. 'dollar': 500,
  32284. 'percent': 833,
  32285. 'ampersand': 778,
  32286. 'quoteright': 333,
  32287. 'parenleft': 333,
  32288. 'parenright': 333,
  32289. 'asterisk': 500,
  32290. 'plus': 675,
  32291. 'comma': 250,
  32292. 'hyphen': 333,
  32293. 'period': 250,
  32294. 'slash': 278,
  32295. 'zero': 500,
  32296. 'one': 500,
  32297. 'two': 500,
  32298. 'three': 500,
  32299. 'four': 500,
  32300. 'five': 500,
  32301. 'six': 500,
  32302. 'seven': 500,
  32303. 'eight': 500,
  32304. 'nine': 500,
  32305. 'colon': 333,
  32306. 'semicolon': 333,
  32307. 'less': 675,
  32308. 'equal': 675,
  32309. 'greater': 675,
  32310. 'question': 500,
  32311. 'at': 920,
  32312. 'A': 611,
  32313. 'B': 611,
  32314. 'C': 667,
  32315. 'D': 722,
  32316. 'E': 611,
  32317. 'F': 611,
  32318. 'G': 722,
  32319. 'H': 722,
  32320. 'I': 333,
  32321. 'J': 444,
  32322. 'K': 667,
  32323. 'L': 556,
  32324. 'M': 833,
  32325. 'N': 667,
  32326. 'O': 722,
  32327. 'P': 611,
  32328. 'Q': 722,
  32329. 'R': 611,
  32330. 'S': 500,
  32331. 'T': 556,
  32332. 'U': 722,
  32333. 'V': 611,
  32334. 'W': 833,
  32335. 'X': 611,
  32336. 'Y': 556,
  32337. 'Z': 556,
  32338. 'bracketleft': 389,
  32339. 'backslash': 278,
  32340. 'bracketright': 389,
  32341. 'asciicircum': 422,
  32342. 'underscore': 500,
  32343. 'quoteleft': 333,
  32344. 'a': 500,
  32345. 'b': 500,
  32346. 'c': 444,
  32347. 'd': 500,
  32348. 'e': 444,
  32349. 'f': 278,
  32350. 'g': 500,
  32351. 'h': 500,
  32352. 'i': 278,
  32353. 'j': 278,
  32354. 'k': 444,
  32355. 'l': 278,
  32356. 'm': 722,
  32357. 'n': 500,
  32358. 'o': 500,
  32359. 'p': 500,
  32360. 'q': 500,
  32361. 'r': 389,
  32362. 's': 389,
  32363. 't': 278,
  32364. 'u': 500,
  32365. 'v': 444,
  32366. 'w': 667,
  32367. 'x': 444,
  32368. 'y': 444,
  32369. 'z': 389,
  32370. 'braceleft': 400,
  32371. 'bar': 275,
  32372. 'braceright': 400,
  32373. 'asciitilde': 541,
  32374. 'exclamdown': 389,
  32375. 'cent': 500,
  32376. 'sterling': 500,
  32377. 'fraction': 167,
  32378. 'yen': 500,
  32379. 'florin': 500,
  32380. 'section': 500,
  32381. 'currency': 500,
  32382. 'quotesingle': 214,
  32383. 'quotedblleft': 556,
  32384. 'guillemotleft': 500,
  32385. 'guilsinglleft': 333,
  32386. 'guilsinglright': 333,
  32387. 'fi': 500,
  32388. 'fl': 500,
  32389. 'endash': 500,
  32390. 'dagger': 500,
  32391. 'daggerdbl': 500,
  32392. 'periodcentered': 250,
  32393. 'paragraph': 523,
  32394. 'bullet': 350,
  32395. 'quotesinglbase': 333,
  32396. 'quotedblbase': 556,
  32397. 'quotedblright': 556,
  32398. 'guillemotright': 500,
  32399. 'ellipsis': 889,
  32400. 'perthousand': 1000,
  32401. 'questiondown': 500,
  32402. 'grave': 333,
  32403. 'acute': 333,
  32404. 'circumflex': 333,
  32405. 'tilde': 333,
  32406. 'macron': 333,
  32407. 'breve': 333,
  32408. 'dotaccent': 333,
  32409. 'dieresis': 333,
  32410. 'ring': 333,
  32411. 'cedilla': 333,
  32412. 'hungarumlaut': 333,
  32413. 'ogonek': 333,
  32414. 'caron': 333,
  32415. 'emdash': 889,
  32416. 'AE': 889,
  32417. 'ordfeminine': 276,
  32418. 'Lslash': 556,
  32419. 'Oslash': 722,
  32420. 'OE': 944,
  32421. 'ordmasculine': 310,
  32422. 'ae': 667,
  32423. 'dotlessi': 278,
  32424. 'lslash': 278,
  32425. 'oslash': 500,
  32426. 'oe': 667,
  32427. 'germandbls': 500,
  32428. 'Idieresis': 333,
  32429. 'eacute': 444,
  32430. 'abreve': 500,
  32431. 'uhungarumlaut': 500,
  32432. 'ecaron': 444,
  32433. 'Ydieresis': 556,
  32434. 'divide': 675,
  32435. 'Yacute': 556,
  32436. 'Acircumflex': 611,
  32437. 'aacute': 500,
  32438. 'Ucircumflex': 722,
  32439. 'yacute': 444,
  32440. 'scommaaccent': 389,
  32441. 'ecircumflex': 444,
  32442. 'Uring': 722,
  32443. 'Udieresis': 722,
  32444. 'aogonek': 500,
  32445. 'Uacute': 722,
  32446. 'uogonek': 500,
  32447. 'Edieresis': 611,
  32448. 'Dcroat': 722,
  32449. 'commaaccent': 250,
  32450. 'copyright': 760,
  32451. 'Emacron': 611,
  32452. 'ccaron': 444,
  32453. 'aring': 500,
  32454. 'Ncommaaccent': 667,
  32455. 'lacute': 278,
  32456. 'agrave': 500,
  32457. 'Tcommaaccent': 556,
  32458. 'Cacute': 667,
  32459. 'atilde': 500,
  32460. 'Edotaccent': 611,
  32461. 'scaron': 389,
  32462. 'scedilla': 389,
  32463. 'iacute': 278,
  32464. 'lozenge': 471,
  32465. 'Rcaron': 611,
  32466. 'Gcommaaccent': 722,
  32467. 'ucircumflex': 500,
  32468. 'acircumflex': 500,
  32469. 'Amacron': 611,
  32470. 'rcaron': 389,
  32471. 'ccedilla': 444,
  32472. 'Zdotaccent': 556,
  32473. 'Thorn': 611,
  32474. 'Omacron': 722,
  32475. 'Racute': 611,
  32476. 'Sacute': 500,
  32477. 'dcaron': 544,
  32478. 'Umacron': 722,
  32479. 'uring': 500,
  32480. 'threesuperior': 300,
  32481. 'Ograve': 722,
  32482. 'Agrave': 611,
  32483. 'Abreve': 611,
  32484. 'multiply': 675,
  32485. 'uacute': 500,
  32486. 'Tcaron': 556,
  32487. 'partialdiff': 476,
  32488. 'ydieresis': 444,
  32489. 'Nacute': 667,
  32490. 'icircumflex': 278,
  32491. 'Ecircumflex': 611,
  32492. 'adieresis': 500,
  32493. 'edieresis': 444,
  32494. 'cacute': 444,
  32495. 'nacute': 500,
  32496. 'umacron': 500,
  32497. 'Ncaron': 667,
  32498. 'Iacute': 333,
  32499. 'plusminus': 675,
  32500. 'brokenbar': 275,
  32501. 'registered': 760,
  32502. 'Gbreve': 722,
  32503. 'Idotaccent': 333,
  32504. 'summation': 600,
  32505. 'Egrave': 611,
  32506. 'racute': 389,
  32507. 'omacron': 500,
  32508. 'Zacute': 556,
  32509. 'Zcaron': 556,
  32510. 'greaterequal': 549,
  32511. 'Eth': 722,
  32512. 'Ccedilla': 667,
  32513. 'lcommaaccent': 278,
  32514. 'tcaron': 300,
  32515. 'eogonek': 444,
  32516. 'Uogonek': 722,
  32517. 'Aacute': 611,
  32518. 'Adieresis': 611,
  32519. 'egrave': 444,
  32520. 'zacute': 389,
  32521. 'iogonek': 278,
  32522. 'Oacute': 722,
  32523. 'oacute': 500,
  32524. 'amacron': 500,
  32525. 'sacute': 389,
  32526. 'idieresis': 278,
  32527. 'Ocircumflex': 722,
  32528. 'Ugrave': 722,
  32529. 'Delta': 612,
  32530. 'thorn': 500,
  32531. 'twosuperior': 300,
  32532. 'Odieresis': 722,
  32533. 'mu': 500,
  32534. 'igrave': 278,
  32535. 'ohungarumlaut': 500,
  32536. 'Eogonek': 611,
  32537. 'dcroat': 500,
  32538. 'threequarters': 750,
  32539. 'Scedilla': 500,
  32540. 'lcaron': 300,
  32541. 'Kcommaaccent': 667,
  32542. 'Lacute': 556,
  32543. 'trademark': 980,
  32544. 'edotaccent': 444,
  32545. 'Igrave': 333,
  32546. 'Imacron': 333,
  32547. 'Lcaron': 611,
  32548. 'onehalf': 750,
  32549. 'lessequal': 549,
  32550. 'ocircumflex': 500,
  32551. 'ntilde': 500,
  32552. 'Uhungarumlaut': 722,
  32553. 'Eacute': 611,
  32554. 'emacron': 444,
  32555. 'gbreve': 500,
  32556. 'onequarter': 750,
  32557. 'Scaron': 500,
  32558. 'Scommaaccent': 500,
  32559. 'Ohungarumlaut': 722,
  32560. 'degree': 400,
  32561. 'ograve': 500,
  32562. 'Ccaron': 667,
  32563. 'ugrave': 500,
  32564. 'radical': 453,
  32565. 'Dcaron': 722,
  32566. 'rcommaaccent': 389,
  32567. 'Ntilde': 667,
  32568. 'otilde': 500,
  32569. 'Rcommaaccent': 611,
  32570. 'Lcommaaccent': 556,
  32571. 'Atilde': 611,
  32572. 'Aogonek': 611,
  32573. 'Aring': 611,
  32574. 'Otilde': 722,
  32575. 'zdotaccent': 389,
  32576. 'Ecaron': 611,
  32577. 'Iogonek': 333,
  32578. 'kcommaaccent': 444,
  32579. 'minus': 675,
  32580. 'Icircumflex': 333,
  32581. 'ncaron': 500,
  32582. 'tcommaaccent': 278,
  32583. 'logicalnot': 675,
  32584. 'odieresis': 500,
  32585. 'udieresis': 500,
  32586. 'notequal': 549,
  32587. 'gcommaaccent': 500,
  32588. 'eth': 500,
  32589. 'zcaron': 389,
  32590. 'ncommaaccent': 500,
  32591. 'onesuperior': 300,
  32592. 'imacron': 278,
  32593. 'Euro': 500
  32594. },
  32595. 'ZapfDingbats': {
  32596. 'space': 278,
  32597. 'a1': 974,
  32598. 'a2': 961,
  32599. 'a202': 974,
  32600. 'a3': 980,
  32601. 'a4': 719,
  32602. 'a5': 789,
  32603. 'a119': 790,
  32604. 'a118': 791,
  32605. 'a117': 690,
  32606. 'a11': 960,
  32607. 'a12': 939,
  32608. 'a13': 549,
  32609. 'a14': 855,
  32610. 'a15': 911,
  32611. 'a16': 933,
  32612. 'a105': 911,
  32613. 'a17': 945,
  32614. 'a18': 974,
  32615. 'a19': 755,
  32616. 'a20': 846,
  32617. 'a21': 762,
  32618. 'a22': 761,
  32619. 'a23': 571,
  32620. 'a24': 677,
  32621. 'a25': 763,
  32622. 'a26': 760,
  32623. 'a27': 759,
  32624. 'a28': 754,
  32625. 'a6': 494,
  32626. 'a7': 552,
  32627. 'a8': 537,
  32628. 'a9': 577,
  32629. 'a10': 692,
  32630. 'a29': 786,
  32631. 'a30': 788,
  32632. 'a31': 788,
  32633. 'a32': 790,
  32634. 'a33': 793,
  32635. 'a34': 794,
  32636. 'a35': 816,
  32637. 'a36': 823,
  32638. 'a37': 789,
  32639. 'a38': 841,
  32640. 'a39': 823,
  32641. 'a40': 833,
  32642. 'a41': 816,
  32643. 'a42': 831,
  32644. 'a43': 923,
  32645. 'a44': 744,
  32646. 'a45': 723,
  32647. 'a46': 749,
  32648. 'a47': 790,
  32649. 'a48': 792,
  32650. 'a49': 695,
  32651. 'a50': 776,
  32652. 'a51': 768,
  32653. 'a52': 792,
  32654. 'a53': 759,
  32655. 'a54': 707,
  32656. 'a55': 708,
  32657. 'a56': 682,
  32658. 'a57': 701,
  32659. 'a58': 826,
  32660. 'a59': 815,
  32661. 'a60': 789,
  32662. 'a61': 789,
  32663. 'a62': 707,
  32664. 'a63': 687,
  32665. 'a64': 696,
  32666. 'a65': 689,
  32667. 'a66': 786,
  32668. 'a67': 787,
  32669. 'a68': 713,
  32670. 'a69': 791,
  32671. 'a70': 785,
  32672. 'a71': 791,
  32673. 'a72': 873,
  32674. 'a73': 761,
  32675. 'a74': 762,
  32676. 'a203': 762,
  32677. 'a75': 759,
  32678. 'a204': 759,
  32679. 'a76': 892,
  32680. 'a77': 892,
  32681. 'a78': 788,
  32682. 'a79': 784,
  32683. 'a81': 438,
  32684. 'a82': 138,
  32685. 'a83': 277,
  32686. 'a84': 415,
  32687. 'a97': 392,
  32688. 'a98': 392,
  32689. 'a99': 668,
  32690. 'a100': 668,
  32691. 'a89': 390,
  32692. 'a90': 390,
  32693. 'a93': 317,
  32694. 'a94': 317,
  32695. 'a91': 276,
  32696. 'a92': 276,
  32697. 'a205': 509,
  32698. 'a85': 509,
  32699. 'a206': 410,
  32700. 'a86': 410,
  32701. 'a87': 234,
  32702. 'a88': 234,
  32703. 'a95': 334,
  32704. 'a96': 334,
  32705. 'a101': 732,
  32706. 'a102': 544,
  32707. 'a103': 544,
  32708. 'a104': 910,
  32709. 'a106': 667,
  32710. 'a107': 760,
  32711. 'a108': 760,
  32712. 'a112': 776,
  32713. 'a111': 595,
  32714. 'a110': 694,
  32715. 'a109': 626,
  32716. 'a120': 788,
  32717. 'a121': 788,
  32718. 'a122': 788,
  32719. 'a123': 788,
  32720. 'a124': 788,
  32721. 'a125': 788,
  32722. 'a126': 788,
  32723. 'a127': 788,
  32724. 'a128': 788,
  32725. 'a129': 788,
  32726. 'a130': 788,
  32727. 'a131': 788,
  32728. 'a132': 788,
  32729. 'a133': 788,
  32730. 'a134': 788,
  32731. 'a135': 788,
  32732. 'a136': 788,
  32733. 'a137': 788,
  32734. 'a138': 788,
  32735. 'a139': 788,
  32736. 'a140': 788,
  32737. 'a141': 788,
  32738. 'a142': 788,
  32739. 'a143': 788,
  32740. 'a144': 788,
  32741. 'a145': 788,
  32742. 'a146': 788,
  32743. 'a147': 788,
  32744. 'a148': 788,
  32745. 'a149': 788,
  32746. 'a150': 788,
  32747. 'a151': 788,
  32748. 'a152': 788,
  32749. 'a153': 788,
  32750. 'a154': 788,
  32751. 'a155': 788,
  32752. 'a156': 788,
  32753. 'a157': 788,
  32754. 'a158': 788,
  32755. 'a159': 788,
  32756. 'a160': 894,
  32757. 'a161': 838,
  32758. 'a163': 1016,
  32759. 'a164': 458,
  32760. 'a196': 748,
  32761. 'a165': 924,
  32762. 'a192': 748,
  32763. 'a166': 918,
  32764. 'a167': 927,
  32765. 'a168': 928,
  32766. 'a169': 928,
  32767. 'a170': 834,
  32768. 'a171': 873,
  32769. 'a172': 828,
  32770. 'a173': 924,
  32771. 'a162': 924,
  32772. 'a174': 917,
  32773. 'a175': 930,
  32774. 'a176': 931,
  32775. 'a177': 463,
  32776. 'a178': 883,
  32777. 'a179': 836,
  32778. 'a193': 836,
  32779. 'a180': 867,
  32780. 'a199': 867,
  32781. 'a181': 696,
  32782. 'a200': 696,
  32783. 'a182': 874,
  32784. 'a201': 874,
  32785. 'a183': 760,
  32786. 'a184': 946,
  32787. 'a197': 771,
  32788. 'a185': 865,
  32789. 'a194': 771,
  32790. 'a198': 888,
  32791. 'a186': 967,
  32792. 'a195': 888,
  32793. 'a187': 831,
  32794. 'a188': 873,
  32795. 'a189': 927,
  32796. 'a190': 970,
  32797. 'a191': 918
  32798. }
  32799. };
  32800. var EOF = {};
  32801. function isEOF(v) {
  32802. return (v === EOF);
  32803. }
  32804. var Parser = (function ParserClosure() {
  32805. function Parser(lexer, allowStreams, xref) {
  32806. this.lexer = lexer;
  32807. this.allowStreams = allowStreams;
  32808. this.xref = xref;
  32809. this.imageCache = {
  32810. length: 0,
  32811. adler32: 0,
  32812. stream: null
  32813. };
  32814. this.refill();
  32815. }
  32816. Parser.prototype = {
  32817. refill: function Parser_refill() {
  32818. this.buf1 = this.lexer.getObj();
  32819. this.buf2 = this.lexer.getObj();
  32820. },
  32821. shift: function Parser_shift() {
  32822. if (isCmd(this.buf2, 'ID')) {
  32823. this.buf1 = this.buf2;
  32824. this.buf2 = null;
  32825. } else {
  32826. this.buf1 = this.buf2;
  32827. this.buf2 = this.lexer.getObj();
  32828. }
  32829. },
  32830. getObj: function Parser_getObj(cipherTransform) {
  32831. var buf1 = this.buf1;
  32832. this.shift();
  32833. if (buf1 instanceof Cmd) {
  32834. switch (buf1.cmd) {
  32835. case 'BI': // inline image
  32836. return this.makeInlineImage(cipherTransform);
  32837. case '[': // array
  32838. var array = [];
  32839. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  32840. array.push(this.getObj(cipherTransform));
  32841. }
  32842. if (isEOF(this.buf1)) {
  32843. error('End of file inside array');
  32844. }
  32845. this.shift();
  32846. return array;
  32847. case '<<': // dictionary or stream
  32848. var dict = new Dict(this.xref);
  32849. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  32850. if (!isName(this.buf1)) {
  32851. info('Malformed dictionary: key must be a name object');
  32852. this.shift();
  32853. continue;
  32854. }
  32855. var key = this.buf1.name;
  32856. this.shift();
  32857. if (isEOF(this.buf1)) {
  32858. break;
  32859. }
  32860. dict.set(key, this.getObj(cipherTransform));
  32861. }
  32862. if (isEOF(this.buf1)) {
  32863. error('End of file inside dictionary');
  32864. }
  32865. // Stream objects are not allowed inside content streams or
  32866. // object streams.
  32867. if (isCmd(this.buf2, 'stream')) {
  32868. return (this.allowStreams ?
  32869. this.makeStream(dict, cipherTransform) : dict);
  32870. }
  32871. this.shift();
  32872. return dict;
  32873. default: // simple object
  32874. return buf1;
  32875. }
  32876. }
  32877. if (isInt(buf1)) { // indirect reference or integer
  32878. var num = buf1;
  32879. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  32880. var ref = new Ref(num, this.buf1);
  32881. this.shift();
  32882. this.shift();
  32883. return ref;
  32884. }
  32885. return num;
  32886. }
  32887. if (isString(buf1)) { // string
  32888. var str = buf1;
  32889. if (cipherTransform) {
  32890. str = cipherTransform.decryptString(str);
  32891. }
  32892. return str;
  32893. }
  32894. // simple object
  32895. return buf1;
  32896. },
  32897. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  32898. var lexer = this.lexer;
  32899. var stream = lexer.stream;
  32900. // parse dictionary
  32901. var dict = new Dict(null);
  32902. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  32903. if (!isName(this.buf1)) {
  32904. error('Dictionary key must be a name object');
  32905. }
  32906. var key = this.buf1.name;
  32907. this.shift();
  32908. if (isEOF(this.buf1)) {
  32909. break;
  32910. }
  32911. dict.set(key, this.getObj(cipherTransform));
  32912. }
  32913. // parse image stream
  32914. var startPos = stream.pos;
  32915. // searching for the /EI\s/
  32916. var state = 0, ch, i, ii;
  32917. var E = 0x45, I = 0x49, SPACE = 0x20, NL = 0xA, CR = 0xD;
  32918. while ((ch = stream.getByte()) !== -1) {
  32919. if (state === 0) {
  32920. state = (ch === E) ? 1 : 0;
  32921. } else if (state === 1) {
  32922. state = (ch === I) ? 2 : 0;
  32923. } else {
  32924. assert(state === 2);
  32925. if (ch === SPACE || ch === NL || ch === CR) {
  32926. // Let's check the next five bytes are ASCII... just be sure.
  32927. var n = 5;
  32928. var followingBytes = stream.peekBytes(n);
  32929. for (i = 0; i < n; i++) {
  32930. ch = followingBytes[i];
  32931. if (ch !== NL && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  32932. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  32933. // it's binary stuff. Resetting the state.
  32934. state = 0;
  32935. break;
  32936. }
  32937. }
  32938. if (state === 2) {
  32939. break; // finished!
  32940. }
  32941. } else {
  32942. state = 0;
  32943. }
  32944. }
  32945. }
  32946. var length = (stream.pos - 4) - startPos;
  32947. var imageStream = stream.makeSubStream(startPos, length, dict);
  32948. // trying to cache repeat images, first we are trying to "warm up" caching
  32949. // using length, then comparing adler32
  32950. var MAX_LENGTH_TO_CACHE = 1000;
  32951. var cacheImage = false, adler32;
  32952. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  32953. var imageBytes = imageStream.getBytes();
  32954. imageStream.reset();
  32955. var a = 1;
  32956. var b = 0;
  32957. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  32958. a = (a + (imageBytes[i] & 0xff)) % 65521;
  32959. b = (b + a) % 65521;
  32960. }
  32961. adler32 = (b << 16) | a;
  32962. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  32963. this.buf2 = Cmd.get('EI');
  32964. this.shift();
  32965. this.imageCache.stream.reset();
  32966. return this.imageCache.stream;
  32967. }
  32968. cacheImage = true;
  32969. }
  32970. if (!cacheImage && !this.imageCache.stream) {
  32971. this.imageCache.length = length;
  32972. this.imageCache.stream = null;
  32973. }
  32974. if (cipherTransform) {
  32975. imageStream = cipherTransform.createStream(imageStream, length);
  32976. }
  32977. imageStream = this.filter(imageStream, dict, length);
  32978. imageStream.dict = dict;
  32979. if (cacheImage) {
  32980. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  32981. this.imageCache.adler32 = adler32;
  32982. this.imageCache.stream = imageStream;
  32983. }
  32984. this.buf2 = Cmd.get('EI');
  32985. this.shift();
  32986. return imageStream;
  32987. },
  32988. fetchIfRef: function Parser_fetchIfRef(obj) {
  32989. // not relying on the xref.fetchIfRef -- xref might not be set
  32990. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  32991. },
  32992. makeStream: function Parser_makeStream(dict, cipherTransform) {
  32993. var lexer = this.lexer;
  32994. var stream = lexer.stream;
  32995. // get stream start position
  32996. lexer.skipToNextLine();
  32997. var pos = stream.pos - 1;
  32998. // get length
  32999. var length = this.fetchIfRef(dict.get('Length'));
  33000. if (!isInt(length)) {
  33001. info('Bad ' + length + ' attribute in stream');
  33002. length = 0;
  33003. }
  33004. // skip over the stream data
  33005. stream.pos = pos + length;
  33006. lexer.nextChar();
  33007. this.shift(); // '>>'
  33008. this.shift(); // 'stream'
  33009. if (!isCmd(this.buf1, 'endstream')) {
  33010. // bad stream length, scanning for endstream
  33011. stream.pos = pos;
  33012. var SCAN_BLOCK_SIZE = 2048;
  33013. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  33014. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  33015. 0x61, 0x6D];
  33016. var skipped = 0, found = false, i, j;
  33017. while (stream.pos < stream.end) {
  33018. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  33019. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  33020. if (scanLength <= 0) {
  33021. break;
  33022. }
  33023. found = false;
  33024. for (i = 0, j = 0; i < scanLength; i++) {
  33025. var b = scanBytes[i];
  33026. if (b !== ENDSTREAM_SIGNATURE[j]) {
  33027. i -= j;
  33028. j = 0;
  33029. } else {
  33030. j++;
  33031. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  33032. i++;
  33033. found = true;
  33034. break;
  33035. }
  33036. }
  33037. }
  33038. if (found) {
  33039. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  33040. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  33041. break;
  33042. }
  33043. skipped += scanLength;
  33044. stream.pos += scanLength;
  33045. }
  33046. if (!found) {
  33047. error('Missing endstream');
  33048. }
  33049. length = skipped;
  33050. lexer.nextChar();
  33051. this.shift();
  33052. this.shift();
  33053. }
  33054. this.shift(); // 'endstream'
  33055. stream = stream.makeSubStream(pos, length, dict);
  33056. if (cipherTransform) {
  33057. stream = cipherTransform.createStream(stream, length);
  33058. }
  33059. stream = this.filter(stream, dict, length);
  33060. stream.dict = dict;
  33061. return stream;
  33062. },
  33063. filter: function Parser_filter(stream, dict, length) {
  33064. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  33065. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  33066. if (isName(filter)) {
  33067. return this.makeFilter(stream, filter.name, length, params);
  33068. }
  33069. var maybeLength = length;
  33070. if (isArray(filter)) {
  33071. var filterArray = filter;
  33072. var paramsArray = params;
  33073. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  33074. filter = filterArray[i];
  33075. if (!isName(filter)) {
  33076. error('Bad filter name: ' + filter);
  33077. }
  33078. params = null;
  33079. if (isArray(paramsArray) && (i in paramsArray)) {
  33080. params = paramsArray[i];
  33081. }
  33082. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  33083. // after the first stream the length variable is invalid
  33084. maybeLength = null;
  33085. }
  33086. }
  33087. return stream;
  33088. },
  33089. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  33090. if (stream.dict.get('Length') === 0) {
  33091. return new NullStream(stream);
  33092. }
  33093. try {
  33094. var xrefStreamStats = this.xref.stats.streamTypes;
  33095. if (name === 'FlateDecode' || name === 'Fl') {
  33096. xrefStreamStats[StreamType.FLATE] = true;
  33097. if (params) {
  33098. return new PredictorStream(new FlateStream(stream, maybeLength),
  33099. maybeLength, params);
  33100. }
  33101. return new FlateStream(stream, maybeLength);
  33102. }
  33103. if (name === 'LZWDecode' || name === 'LZW') {
  33104. xrefStreamStats[StreamType.LZW] = true;
  33105. var earlyChange = 1;
  33106. if (params) {
  33107. if (params.has('EarlyChange')) {
  33108. earlyChange = params.get('EarlyChange');
  33109. }
  33110. return new PredictorStream(
  33111. new LZWStream(stream, maybeLength, earlyChange),
  33112. maybeLength, params);
  33113. }
  33114. return new LZWStream(stream, maybeLength, earlyChange);
  33115. }
  33116. if (name === 'DCTDecode' || name === 'DCT') {
  33117. xrefStreamStats[StreamType.DCT] = true;
  33118. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  33119. }
  33120. if (name === 'JPXDecode' || name === 'JPX') {
  33121. xrefStreamStats[StreamType.JPX] = true;
  33122. return new JpxStream(stream, maybeLength, stream.dict);
  33123. }
  33124. if (name === 'ASCII85Decode' || name === 'A85') {
  33125. xrefStreamStats[StreamType.A85] = true;
  33126. return new Ascii85Stream(stream, maybeLength);
  33127. }
  33128. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  33129. xrefStreamStats[StreamType.AHX] = true;
  33130. return new AsciiHexStream(stream, maybeLength);
  33131. }
  33132. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  33133. xrefStreamStats[StreamType.CCF] = true;
  33134. return new CCITTFaxStream(stream, maybeLength, params);
  33135. }
  33136. if (name === 'RunLengthDecode' || name === 'RL') {
  33137. xrefStreamStats[StreamType.RL] = true;
  33138. return new RunLengthStream(stream, maybeLength);
  33139. }
  33140. if (name === 'JBIG2Decode') {
  33141. xrefStreamStats[StreamType.JBIG] = true;
  33142. return new Jbig2Stream(stream, maybeLength, stream.dict);
  33143. }
  33144. warn('filter "' + name + '" not supported yet');
  33145. return stream;
  33146. } catch (ex) {
  33147. if (ex instanceof MissingDataException) {
  33148. throw ex;
  33149. }
  33150. warn('Invalid stream: \"' + ex + '\"');
  33151. return new NullStream(stream);
  33152. }
  33153. }
  33154. };
  33155. return Parser;
  33156. })();
  33157. var Lexer = (function LexerClosure() {
  33158. function Lexer(stream, knownCommands) {
  33159. this.stream = stream;
  33160. this.nextChar();
  33161. // While lexing, we build up many strings one char at a time. Using += for
  33162. // this can result in lots of garbage strings. It's better to build an
  33163. // array of single-char strings and then join() them together at the end.
  33164. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  33165. // purpose uses less memory than using a new array for each string.
  33166. this.strBuf = [];
  33167. // The PDFs might have "glued" commands with other commands, operands or
  33168. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  33169. // commands and their prefixes. The prefixes are built the following way:
  33170. // if there a command that is a prefix of the other valid command or
  33171. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  33172. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  33173. // other commands or literals as a prefix. The knowCommands is optional.
  33174. this.knownCommands = knownCommands;
  33175. }
  33176. Lexer.isSpace = function Lexer_isSpace(ch) {
  33177. // Space is one of the following characters: SPACE, TAB, CR or LF.
  33178. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  33179. };
  33180. // A '1' in this array means the character is white space. A '1' or
  33181. // '2' means the character ends a name or command.
  33182. var specialChars = [
  33183. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  33184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  33185. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  33186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  33187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  33188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  33189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  33190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  33191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  33192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  33193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  33194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  33195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  33196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  33197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  33198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  33199. ];
  33200. function toHexDigit(ch) {
  33201. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  33202. return ch & 0x0F;
  33203. }
  33204. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  33205. // 'A'-'F', 'a'-'f'
  33206. return (ch & 0x0F) + 9;
  33207. }
  33208. return -1;
  33209. }
  33210. Lexer.prototype = {
  33211. nextChar: function Lexer_nextChar() {
  33212. return (this.currentChar = this.stream.getByte());
  33213. },
  33214. peekChar: function Lexer_peekChar() {
  33215. return this.stream.peekBytes(1)[0];
  33216. },
  33217. getNumber: function Lexer_getNumber() {
  33218. var ch = this.currentChar;
  33219. var eNotation = false;
  33220. var divideBy = 0; // different from 0 if it's a floating point value
  33221. var sign = 1;
  33222. if (ch === 0x2D) { // '-'
  33223. sign = -1;
  33224. ch = this.nextChar();
  33225. } else if (ch === 0x2B) { // '+'
  33226. ch = this.nextChar();
  33227. }
  33228. if (ch === 0x2E) { // '.'
  33229. divideBy = 10;
  33230. ch = this.nextChar();
  33231. }
  33232. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  33233. error('Invalid number: ' + String.fromCharCode(ch));
  33234. return 0;
  33235. }
  33236. var baseValue = ch - 0x30; // '0'
  33237. var powerValue = 0;
  33238. var powerValueSign = 1;
  33239. while ((ch = this.nextChar()) >= 0) {
  33240. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  33241. var currentDigit = ch - 0x30; // '0'
  33242. if (eNotation) { // We are after an 'e' or 'E'
  33243. powerValue = powerValue * 10 + currentDigit;
  33244. } else {
  33245. if (divideBy !== 0) { // We are after a point
  33246. divideBy *= 10;
  33247. }
  33248. baseValue = baseValue * 10 + currentDigit;
  33249. }
  33250. } else if (ch === 0x2E) { // '.'
  33251. if (divideBy === 0) {
  33252. divideBy = 1;
  33253. } else {
  33254. // A number can have only one '.'
  33255. break;
  33256. }
  33257. } else if (ch === 0x2D) { // '-'
  33258. // ignore minus signs in the middle of numbers to match
  33259. // Adobe's behavior
  33260. warn('Badly formated number');
  33261. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  33262. // 'E' can be either a scientific notation or the beginning of a new
  33263. // operator
  33264. ch = this.peekChar();
  33265. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  33266. powerValueSign = (ch === 0x2D) ? -1 : 1;
  33267. this.nextChar(); // Consume the sign character
  33268. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  33269. // The 'E' must be the beginning of a new operator
  33270. break;
  33271. }
  33272. eNotation = true;
  33273. } else {
  33274. // the last character doesn't belong to us
  33275. break;
  33276. }
  33277. }
  33278. if (divideBy !== 0) {
  33279. baseValue /= divideBy;
  33280. }
  33281. if (eNotation) {
  33282. baseValue *= Math.pow(10, powerValueSign * powerValue);
  33283. }
  33284. return sign * baseValue;
  33285. },
  33286. getString: function Lexer_getString() {
  33287. var numParen = 1;
  33288. var done = false;
  33289. var strBuf = this.strBuf;
  33290. strBuf.length = 0;
  33291. var ch = this.nextChar();
  33292. while (true) {
  33293. var charBuffered = false;
  33294. switch (ch | 0) {
  33295. case -1:
  33296. warn('Unterminated string');
  33297. done = true;
  33298. break;
  33299. case 0x28: // '('
  33300. ++numParen;
  33301. strBuf.push('(');
  33302. break;
  33303. case 0x29: // ')'
  33304. if (--numParen === 0) {
  33305. this.nextChar(); // consume strings ')'
  33306. done = true;
  33307. } else {
  33308. strBuf.push(')');
  33309. }
  33310. break;
  33311. case 0x5C: // '\\'
  33312. ch = this.nextChar();
  33313. switch (ch) {
  33314. case -1:
  33315. warn('Unterminated string');
  33316. done = true;
  33317. break;
  33318. case 0x6E: // 'n'
  33319. strBuf.push('\n');
  33320. break;
  33321. case 0x72: // 'r'
  33322. strBuf.push('\r');
  33323. break;
  33324. case 0x74: // 't'
  33325. strBuf.push('\t');
  33326. break;
  33327. case 0x62: // 'b'
  33328. strBuf.push('\b');
  33329. break;
  33330. case 0x66: // 'f'
  33331. strBuf.push('\f');
  33332. break;
  33333. case 0x5C: // '\'
  33334. case 0x28: // '('
  33335. case 0x29: // ')'
  33336. strBuf.push(String.fromCharCode(ch));
  33337. break;
  33338. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  33339. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  33340. var x = ch & 0x0F;
  33341. ch = this.nextChar();
  33342. charBuffered = true;
  33343. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  33344. x = (x << 3) + (ch & 0x0F);
  33345. ch = this.nextChar();
  33346. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  33347. charBuffered = false;
  33348. x = (x << 3) + (ch & 0x0F);
  33349. }
  33350. }
  33351. strBuf.push(String.fromCharCode(x));
  33352. break;
  33353. case 0x0D: // CR
  33354. if (this.peekChar() === 0x0A) { // LF
  33355. this.nextChar();
  33356. }
  33357. break;
  33358. case 0x0A: // LF
  33359. break;
  33360. default:
  33361. strBuf.push(String.fromCharCode(ch));
  33362. break;
  33363. }
  33364. break;
  33365. default:
  33366. strBuf.push(String.fromCharCode(ch));
  33367. break;
  33368. }
  33369. if (done) {
  33370. break;
  33371. }
  33372. if (!charBuffered) {
  33373. ch = this.nextChar();
  33374. }
  33375. }
  33376. return strBuf.join('');
  33377. },
  33378. getName: function Lexer_getName() {
  33379. var ch;
  33380. var strBuf = this.strBuf;
  33381. strBuf.length = 0;
  33382. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  33383. if (ch === 0x23) { // '#'
  33384. ch = this.nextChar();
  33385. var x = toHexDigit(ch);
  33386. if (x !== -1) {
  33387. var x2 = toHexDigit(this.nextChar());
  33388. if (x2 === -1) {
  33389. error('Illegal digit in hex char in name: ' + x2);
  33390. }
  33391. strBuf.push(String.fromCharCode((x << 4) | x2));
  33392. } else {
  33393. strBuf.push('#', String.fromCharCode(ch));
  33394. }
  33395. } else {
  33396. strBuf.push(String.fromCharCode(ch));
  33397. }
  33398. }
  33399. if (strBuf.length > 128) {
  33400. error('Warning: name token is longer than allowed by the spec: ' +
  33401. strBuf.length);
  33402. }
  33403. return Name.get(strBuf.join(''));
  33404. },
  33405. getHexString: function Lexer_getHexString() {
  33406. var strBuf = this.strBuf;
  33407. strBuf.length = 0;
  33408. var ch = this.currentChar;
  33409. var isFirstHex = true;
  33410. var firstDigit;
  33411. var secondDigit;
  33412. while (true) {
  33413. if (ch < 0) {
  33414. warn('Unterminated hex string');
  33415. break;
  33416. } else if (ch === 0x3E) { // '>'
  33417. this.nextChar();
  33418. break;
  33419. } else if (specialChars[ch] === 1) {
  33420. ch = this.nextChar();
  33421. continue;
  33422. } else {
  33423. if (isFirstHex) {
  33424. firstDigit = toHexDigit(ch);
  33425. if (firstDigit === -1) {
  33426. warn('Ignoring invalid character "' + ch + '" in hex string');
  33427. ch = this.nextChar();
  33428. continue;
  33429. }
  33430. } else {
  33431. secondDigit = toHexDigit(ch);
  33432. if (secondDigit === -1) {
  33433. warn('Ignoring invalid character "' + ch + '" in hex string');
  33434. ch = this.nextChar();
  33435. continue;
  33436. }
  33437. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  33438. }
  33439. isFirstHex = !isFirstHex;
  33440. ch = this.nextChar();
  33441. }
  33442. }
  33443. return strBuf.join('');
  33444. },
  33445. getObj: function Lexer_getObj() {
  33446. // skip whitespace and comments
  33447. var comment = false;
  33448. var ch = this.currentChar;
  33449. while (true) {
  33450. if (ch < 0) {
  33451. return EOF;
  33452. }
  33453. if (comment) {
  33454. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  33455. comment = false;
  33456. }
  33457. } else if (ch === 0x25) { // '%'
  33458. comment = true;
  33459. } else if (specialChars[ch] !== 1) {
  33460. break;
  33461. }
  33462. ch = this.nextChar();
  33463. }
  33464. // start reading token
  33465. switch (ch | 0) {
  33466. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  33467. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  33468. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  33469. return this.getNumber();
  33470. case 0x28: // '('
  33471. return this.getString();
  33472. case 0x2F: // '/'
  33473. return this.getName();
  33474. // array punctuation
  33475. case 0x5B: // '['
  33476. this.nextChar();
  33477. return Cmd.get('[');
  33478. case 0x5D: // ']'
  33479. this.nextChar();
  33480. return Cmd.get(']');
  33481. // hex string or dict punctuation
  33482. case 0x3C: // '<'
  33483. ch = this.nextChar();
  33484. if (ch === 0x3C) {
  33485. // dict punctuation
  33486. this.nextChar();
  33487. return Cmd.get('<<');
  33488. }
  33489. return this.getHexString();
  33490. // dict punctuation
  33491. case 0x3E: // '>'
  33492. ch = this.nextChar();
  33493. if (ch === 0x3E) {
  33494. this.nextChar();
  33495. return Cmd.get('>>');
  33496. }
  33497. return Cmd.get('>');
  33498. case 0x7B: // '{'
  33499. this.nextChar();
  33500. return Cmd.get('{');
  33501. case 0x7D: // '}'
  33502. this.nextChar();
  33503. return Cmd.get('}');
  33504. case 0x29: // ')'
  33505. error('Illegal character: ' + ch);
  33506. break;
  33507. }
  33508. // command
  33509. var str = String.fromCharCode(ch);
  33510. var knownCommands = this.knownCommands;
  33511. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  33512. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  33513. // stop if known command is found and next character does not make
  33514. // the str a command
  33515. var possibleCommand = str + String.fromCharCode(ch);
  33516. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  33517. break;
  33518. }
  33519. if (str.length === 128) {
  33520. error('Command token too long: ' + str.length);
  33521. }
  33522. str = possibleCommand;
  33523. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  33524. }
  33525. if (str === 'true') {
  33526. return true;
  33527. }
  33528. if (str === 'false') {
  33529. return false;
  33530. }
  33531. if (str === 'null') {
  33532. return null;
  33533. }
  33534. return Cmd.get(str);
  33535. },
  33536. skipToNextLine: function Lexer_skipToNextLine() {
  33537. var ch = this.currentChar;
  33538. while (ch >= 0) {
  33539. if (ch === 0x0D) { // CR
  33540. ch = this.nextChar();
  33541. if (ch === 0x0A) { // LF
  33542. this.nextChar();
  33543. }
  33544. break;
  33545. } else if (ch === 0x0A) { // LF
  33546. this.nextChar();
  33547. break;
  33548. }
  33549. ch = this.nextChar();
  33550. }
  33551. }
  33552. };
  33553. return Lexer;
  33554. })();
  33555. var Linearization = {
  33556. create: function LinearizationCreate(stream) {
  33557. function getInt(name, allowZeroValue) {
  33558. var obj = linDict.get(name);
  33559. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  33560. return obj;
  33561. }
  33562. throw new Error('The "' + name + '" parameter in the linearization ' +
  33563. 'dictionary is invalid.');
  33564. }
  33565. function getHints() {
  33566. var hints = linDict.get('H'), hintsLength, item;
  33567. if (isArray(hints) &&
  33568. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  33569. for (var index = 0; index < hintsLength; index++) {
  33570. if (!(isInt(item = hints[index]) && item > 0)) {
  33571. throw new Error('Hint (' + index +
  33572. ') in the linearization dictionary is invalid.');
  33573. }
  33574. }
  33575. return hints;
  33576. }
  33577. throw new Error('Hint array in the linearization dictionary is invalid.');
  33578. }
  33579. var parser = new Parser(new Lexer(stream), false, null);
  33580. var obj1 = parser.getObj();
  33581. var obj2 = parser.getObj();
  33582. var obj3 = parser.getObj();
  33583. var linDict = parser.getObj();
  33584. var obj, length;
  33585. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  33586. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  33587. return null; // No valid linearization dictionary found.
  33588. } else if ((length = getInt('L')) !== stream.length) {
  33589. throw new Error('The "L" parameter in the linearization dictionary ' +
  33590. 'does not equal the stream length.');
  33591. }
  33592. return {
  33593. length: length,
  33594. hints: getHints(),
  33595. objectNumberFirst: getInt('O'),
  33596. endFirst: getInt('E'),
  33597. numPages: getInt('N'),
  33598. mainXRefEntriesOffset: getInt('T'),
  33599. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  33600. };
  33601. }
  33602. };
  33603. var PostScriptParser = (function PostScriptParserClosure() {
  33604. function PostScriptParser(lexer) {
  33605. this.lexer = lexer;
  33606. this.operators = [];
  33607. this.token = null;
  33608. this.prev = null;
  33609. }
  33610. PostScriptParser.prototype = {
  33611. nextToken: function PostScriptParser_nextToken() {
  33612. this.prev = this.token;
  33613. this.token = this.lexer.getToken();
  33614. },
  33615. accept: function PostScriptParser_accept(type) {
  33616. if (this.token.type === type) {
  33617. this.nextToken();
  33618. return true;
  33619. }
  33620. return false;
  33621. },
  33622. expect: function PostScriptParser_expect(type) {
  33623. if (this.accept(type)) {
  33624. return true;
  33625. }
  33626. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  33627. type + '.');
  33628. },
  33629. parse: function PostScriptParser_parse() {
  33630. this.nextToken();
  33631. this.expect(PostScriptTokenTypes.LBRACE);
  33632. this.parseBlock();
  33633. this.expect(PostScriptTokenTypes.RBRACE);
  33634. return this.operators;
  33635. },
  33636. parseBlock: function PostScriptParser_parseBlock() {
  33637. while (true) {
  33638. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  33639. this.operators.push(this.prev.value);
  33640. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  33641. this.operators.push(this.prev.value);
  33642. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33643. this.parseCondition();
  33644. } else {
  33645. return;
  33646. }
  33647. }
  33648. },
  33649. parseCondition: function PostScriptParser_parseCondition() {
  33650. // Add two place holders that will be updated later
  33651. var conditionLocation = this.operators.length;
  33652. this.operators.push(null, null);
  33653. this.parseBlock();
  33654. this.expect(PostScriptTokenTypes.RBRACE);
  33655. if (this.accept(PostScriptTokenTypes.IF)) {
  33656. // The true block is right after the 'if' so it just falls through on
  33657. // true else it jumps and skips the true block.
  33658. this.operators[conditionLocation] = this.operators.length;
  33659. this.operators[conditionLocation + 1] = 'jz';
  33660. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  33661. var jumpLocation = this.operators.length;
  33662. this.operators.push(null, null);
  33663. var endOfTrue = this.operators.length;
  33664. this.parseBlock();
  33665. this.expect(PostScriptTokenTypes.RBRACE);
  33666. this.expect(PostScriptTokenTypes.IFELSE);
  33667. // The jump is added at the end of the true block to skip the false
  33668. // block.
  33669. this.operators[jumpLocation] = this.operators.length;
  33670. this.operators[jumpLocation + 1] = 'j';
  33671. this.operators[conditionLocation] = endOfTrue;
  33672. this.operators[conditionLocation + 1] = 'jz';
  33673. } else {
  33674. error('PS Function: error parsing conditional.');
  33675. }
  33676. }
  33677. };
  33678. return PostScriptParser;
  33679. })();
  33680. var PostScriptTokenTypes = {
  33681. LBRACE: 0,
  33682. RBRACE: 1,
  33683. NUMBER: 2,
  33684. OPERATOR: 3,
  33685. IF: 4,
  33686. IFELSE: 5
  33687. };
  33688. var PostScriptToken = (function PostScriptTokenClosure() {
  33689. function PostScriptToken(type, value) {
  33690. this.type = type;
  33691. this.value = value;
  33692. }
  33693. var opCache = {};
  33694. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  33695. var opValue = opCache[op];
  33696. if (opValue) {
  33697. return opValue;
  33698. }
  33699. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  33700. };
  33701. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  33702. '{');
  33703. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  33704. '}');
  33705. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  33706. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  33707. 'IFELSE');
  33708. return PostScriptToken;
  33709. })();
  33710. var PostScriptLexer = (function PostScriptLexerClosure() {
  33711. function PostScriptLexer(stream) {
  33712. this.stream = stream;
  33713. this.nextChar();
  33714. this.strBuf = [];
  33715. }
  33716. PostScriptLexer.prototype = {
  33717. nextChar: function PostScriptLexer_nextChar() {
  33718. return (this.currentChar = this.stream.getByte());
  33719. },
  33720. getToken: function PostScriptLexer_getToken() {
  33721. var comment = false;
  33722. var ch = this.currentChar;
  33723. // skip comments
  33724. while (true) {
  33725. if (ch < 0) {
  33726. return EOF;
  33727. }
  33728. if (comment) {
  33729. if (ch === 0x0A || ch === 0x0D) {
  33730. comment = false;
  33731. }
  33732. } else if (ch === 0x25) { // '%'
  33733. comment = true;
  33734. } else if (!Lexer.isSpace(ch)) {
  33735. break;
  33736. }
  33737. ch = this.nextChar();
  33738. }
  33739. switch (ch | 0) {
  33740. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  33741. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  33742. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  33743. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  33744. this.getNumber());
  33745. case 0x7B: // '{'
  33746. this.nextChar();
  33747. return PostScriptToken.LBRACE;
  33748. case 0x7D: // '}'
  33749. this.nextChar();
  33750. return PostScriptToken.RBRACE;
  33751. }
  33752. // operator
  33753. var strBuf = this.strBuf;
  33754. strBuf.length = 0;
  33755. strBuf[0] = String.fromCharCode(ch);
  33756. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  33757. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  33758. strBuf.push(String.fromCharCode(ch));
  33759. }
  33760. var str = strBuf.join('');
  33761. switch (str.toLowerCase()) {
  33762. case 'if':
  33763. return PostScriptToken.IF;
  33764. case 'ifelse':
  33765. return PostScriptToken.IFELSE;
  33766. default:
  33767. return PostScriptToken.getOperator(str);
  33768. }
  33769. },
  33770. getNumber: function PostScriptLexer_getNumber() {
  33771. var ch = this.currentChar;
  33772. var strBuf = this.strBuf;
  33773. strBuf.length = 0;
  33774. strBuf[0] = String.fromCharCode(ch);
  33775. while ((ch = this.nextChar()) >= 0) {
  33776. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  33777. ch === 0x2D || ch === 0x2E) { // '-', '.'
  33778. strBuf.push(String.fromCharCode(ch));
  33779. } else {
  33780. break;
  33781. }
  33782. }
  33783. var value = parseFloat(strBuf.join(''));
  33784. if (isNaN(value)) {
  33785. error('Invalid floating point number: ' + value);
  33786. }
  33787. return value;
  33788. }
  33789. };
  33790. return PostScriptLexer;
  33791. })();
  33792. var Stream = (function StreamClosure() {
  33793. function Stream(arrayBuffer, start, length, dict) {
  33794. this.bytes = (arrayBuffer instanceof Uint8Array ?
  33795. arrayBuffer : new Uint8Array(arrayBuffer));
  33796. this.start = start || 0;
  33797. this.pos = this.start;
  33798. this.end = (start + length) || this.bytes.length;
  33799. this.dict = dict;
  33800. }
  33801. // required methods for a stream. if a particular stream does not
  33802. // implement these, an error should be thrown
  33803. Stream.prototype = {
  33804. get length() {
  33805. return this.end - this.start;
  33806. },
  33807. get isEmpty() {
  33808. return this.length === 0;
  33809. },
  33810. getByte: function Stream_getByte() {
  33811. if (this.pos >= this.end) {
  33812. return -1;
  33813. }
  33814. return this.bytes[this.pos++];
  33815. },
  33816. getUint16: function Stream_getUint16() {
  33817. var b0 = this.getByte();
  33818. var b1 = this.getByte();
  33819. return (b0 << 8) + b1;
  33820. },
  33821. getInt32: function Stream_getInt32() {
  33822. var b0 = this.getByte();
  33823. var b1 = this.getByte();
  33824. var b2 = this.getByte();
  33825. var b3 = this.getByte();
  33826. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  33827. },
  33828. // returns subarray of original buffer
  33829. // should only be read
  33830. getBytes: function Stream_getBytes(length) {
  33831. var bytes = this.bytes;
  33832. var pos = this.pos;
  33833. var strEnd = this.end;
  33834. if (!length) {
  33835. return bytes.subarray(pos, strEnd);
  33836. }
  33837. var end = pos + length;
  33838. if (end > strEnd) {
  33839. end = strEnd;
  33840. }
  33841. this.pos = end;
  33842. return bytes.subarray(pos, end);
  33843. },
  33844. peekBytes: function Stream_peekBytes(length) {
  33845. var bytes = this.getBytes(length);
  33846. this.pos -= bytes.length;
  33847. return bytes;
  33848. },
  33849. skip: function Stream_skip(n) {
  33850. if (!n) {
  33851. n = 1;
  33852. }
  33853. this.pos += n;
  33854. },
  33855. reset: function Stream_reset() {
  33856. this.pos = this.start;
  33857. },
  33858. moveStart: function Stream_moveStart() {
  33859. this.start = this.pos;
  33860. },
  33861. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  33862. return new Stream(this.bytes.buffer, start, length, dict);
  33863. },
  33864. isStream: true
  33865. };
  33866. return Stream;
  33867. })();
  33868. var StringStream = (function StringStreamClosure() {
  33869. function StringStream(str) {
  33870. var length = str.length;
  33871. var bytes = new Uint8Array(length);
  33872. for (var n = 0; n < length; ++n) {
  33873. bytes[n] = str.charCodeAt(n);
  33874. }
  33875. Stream.call(this, bytes);
  33876. }
  33877. StringStream.prototype = Stream.prototype;
  33878. return StringStream;
  33879. })();
  33880. // super class for the decoding streams
  33881. var DecodeStream = (function DecodeStreamClosure() {
  33882. // Lots of DecodeStreams are created whose buffers are never used. For these
  33883. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  33884. // having special cases that would be required if we used |null| for an empty
  33885. // buffer.
  33886. var emptyBuffer = new Uint8Array(0);
  33887. function DecodeStream(maybeMinBufferLength) {
  33888. this.pos = 0;
  33889. this.bufferLength = 0;
  33890. this.eof = false;
  33891. this.buffer = emptyBuffer;
  33892. this.minBufferLength = 512;
  33893. if (maybeMinBufferLength) {
  33894. // Compute the first power of two that is as big as maybeMinBufferLength.
  33895. while (this.minBufferLength < maybeMinBufferLength) {
  33896. this.minBufferLength *= 2;
  33897. }
  33898. }
  33899. }
  33900. DecodeStream.prototype = {
  33901. get isEmpty() {
  33902. while (!this.eof && this.bufferLength === 0) {
  33903. this.readBlock();
  33904. }
  33905. return this.bufferLength === 0;
  33906. },
  33907. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  33908. var buffer = this.buffer;
  33909. if (requested <= buffer.byteLength) {
  33910. return buffer;
  33911. }
  33912. var size = this.minBufferLength;
  33913. while (size < requested) {
  33914. size *= 2;
  33915. }
  33916. var buffer2 = new Uint8Array(size);
  33917. buffer2.set(buffer);
  33918. return (this.buffer = buffer2);
  33919. },
  33920. getByte: function DecodeStream_getByte() {
  33921. var pos = this.pos;
  33922. while (this.bufferLength <= pos) {
  33923. if (this.eof) {
  33924. return -1;
  33925. }
  33926. this.readBlock();
  33927. }
  33928. return this.buffer[this.pos++];
  33929. },
  33930. getUint16: function DecodeStream_getUint16() {
  33931. var b0 = this.getByte();
  33932. var b1 = this.getByte();
  33933. return (b0 << 8) + b1;
  33934. },
  33935. getInt32: function DecodeStream_getInt32() {
  33936. var b0 = this.getByte();
  33937. var b1 = this.getByte();
  33938. var b2 = this.getByte();
  33939. var b3 = this.getByte();
  33940. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  33941. },
  33942. getBytes: function DecodeStream_getBytes(length) {
  33943. var end, pos = this.pos;
  33944. if (length) {
  33945. this.ensureBuffer(pos + length);
  33946. end = pos + length;
  33947. while (!this.eof && this.bufferLength < end) {
  33948. this.readBlock();
  33949. }
  33950. var bufEnd = this.bufferLength;
  33951. if (end > bufEnd) {
  33952. end = bufEnd;
  33953. }
  33954. } else {
  33955. while (!this.eof) {
  33956. this.readBlock();
  33957. }
  33958. end = this.bufferLength;
  33959. }
  33960. this.pos = end;
  33961. return this.buffer.subarray(pos, end);
  33962. },
  33963. peekBytes: function DecodeStream_peekBytes(length) {
  33964. var bytes = this.getBytes(length);
  33965. this.pos -= bytes.length;
  33966. return bytes;
  33967. },
  33968. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  33969. var end = start + length;
  33970. while (this.bufferLength <= end && !this.eof) {
  33971. this.readBlock();
  33972. }
  33973. return new Stream(this.buffer, start, length, dict);
  33974. },
  33975. skip: function DecodeStream_skip(n) {
  33976. if (!n) {
  33977. n = 1;
  33978. }
  33979. this.pos += n;
  33980. },
  33981. reset: function DecodeStream_reset() {
  33982. this.pos = 0;
  33983. },
  33984. getBaseStreams: function DecodeStream_getBaseStreams() {
  33985. if (this.str && this.str.getBaseStreams) {
  33986. return this.str.getBaseStreams();
  33987. }
  33988. return [];
  33989. }
  33990. };
  33991. return DecodeStream;
  33992. })();
  33993. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  33994. function StreamsSequenceStream(streams) {
  33995. this.streams = streams;
  33996. DecodeStream.call(this, /* maybeLength = */ null);
  33997. }
  33998. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  33999. StreamsSequenceStream.prototype.readBlock =
  34000. function streamSequenceStreamReadBlock() {
  34001. var streams = this.streams;
  34002. if (streams.length === 0) {
  34003. this.eof = true;
  34004. return;
  34005. }
  34006. var stream = streams.shift();
  34007. var chunk = stream.getBytes();
  34008. var bufferLength = this.bufferLength;
  34009. var newLength = bufferLength + chunk.length;
  34010. var buffer = this.ensureBuffer(newLength);
  34011. buffer.set(chunk, bufferLength);
  34012. this.bufferLength = newLength;
  34013. };
  34014. StreamsSequenceStream.prototype.getBaseStreams =
  34015. function StreamsSequenceStream_getBaseStreams() {
  34016. var baseStreams = [];
  34017. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  34018. var stream = this.streams[i];
  34019. if (stream.getBaseStreams) {
  34020. Util.appendToArray(baseStreams, stream.getBaseStreams());
  34021. }
  34022. }
  34023. return baseStreams;
  34024. };
  34025. return StreamsSequenceStream;
  34026. })();
  34027. var FlateStream = (function FlateStreamClosure() {
  34028. var codeLenCodeMap = new Uint32Array([
  34029. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  34030. ]);
  34031. var lengthDecode = new Uint32Array([
  34032. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  34033. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  34034. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  34035. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  34036. ]);
  34037. var distDecode = new Uint32Array([
  34038. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  34039. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  34040. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  34041. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  34042. ]);
  34043. var fixedLitCodeTab = [new Uint32Array([
  34044. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  34045. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  34046. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  34047. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  34048. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  34049. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  34050. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  34051. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  34052. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  34053. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  34054. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  34055. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  34056. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  34057. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  34058. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  34059. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  34060. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  34061. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  34062. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  34063. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  34064. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  34065. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  34066. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  34067. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  34068. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  34069. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  34070. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  34071. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  34072. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  34073. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  34074. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  34075. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  34076. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  34077. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  34078. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  34079. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  34080. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  34081. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  34082. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  34083. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  34084. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  34085. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  34086. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  34087. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  34088. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  34089. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  34090. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  34091. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  34092. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  34093. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  34094. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  34095. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  34096. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  34097. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  34098. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  34099. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  34100. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  34101. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  34102. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  34103. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  34104. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  34105. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  34106. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  34107. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  34108. ]), 9];
  34109. var fixedDistCodeTab = [new Uint32Array([
  34110. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  34111. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  34112. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  34113. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  34114. ]), 5];
  34115. function FlateStream(str, maybeLength) {
  34116. this.str = str;
  34117. this.dict = str.dict;
  34118. var cmf = str.getByte();
  34119. var flg = str.getByte();
  34120. if (cmf === -1 || flg === -1) {
  34121. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  34122. }
  34123. if ((cmf & 0x0f) !== 0x08) {
  34124. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  34125. }
  34126. if ((((cmf << 8) + flg) % 31) !== 0) {
  34127. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  34128. }
  34129. if (flg & 0x20) {
  34130. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  34131. }
  34132. this.codeSize = 0;
  34133. this.codeBuf = 0;
  34134. DecodeStream.call(this, maybeLength);
  34135. }
  34136. FlateStream.prototype = Object.create(DecodeStream.prototype);
  34137. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  34138. var str = this.str;
  34139. var codeSize = this.codeSize;
  34140. var codeBuf = this.codeBuf;
  34141. var b;
  34142. while (codeSize < bits) {
  34143. if ((b = str.getByte()) === -1) {
  34144. error('Bad encoding in flate stream');
  34145. }
  34146. codeBuf |= b << codeSize;
  34147. codeSize += 8;
  34148. }
  34149. b = codeBuf & ((1 << bits) - 1);
  34150. this.codeBuf = codeBuf >> bits;
  34151. this.codeSize = codeSize -= bits;
  34152. return b;
  34153. };
  34154. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  34155. var str = this.str;
  34156. var codes = table[0];
  34157. var maxLen = table[1];
  34158. var codeSize = this.codeSize;
  34159. var codeBuf = this.codeBuf;
  34160. var b;
  34161. while (codeSize < maxLen) {
  34162. if ((b = str.getByte()) === -1) {
  34163. // premature end of stream. code might however still be valid.
  34164. // codeSize < codeLen check below guards against incomplete codeVal.
  34165. break;
  34166. }
  34167. codeBuf |= (b << codeSize);
  34168. codeSize += 8;
  34169. }
  34170. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  34171. var codeLen = code >> 16;
  34172. var codeVal = code & 0xffff;
  34173. if (codeLen < 1 || codeSize < codeLen) {
  34174. error('Bad encoding in flate stream');
  34175. }
  34176. this.codeBuf = (codeBuf >> codeLen);
  34177. this.codeSize = (codeSize - codeLen);
  34178. return codeVal;
  34179. };
  34180. FlateStream.prototype.generateHuffmanTable =
  34181. function flateStreamGenerateHuffmanTable(lengths) {
  34182. var n = lengths.length;
  34183. // find max code length
  34184. var maxLen = 0;
  34185. var i;
  34186. for (i = 0; i < n; ++i) {
  34187. if (lengths[i] > maxLen) {
  34188. maxLen = lengths[i];
  34189. }
  34190. }
  34191. // build the table
  34192. var size = 1 << maxLen;
  34193. var codes = new Uint32Array(size);
  34194. for (var len = 1, code = 0, skip = 2;
  34195. len <= maxLen;
  34196. ++len, code <<= 1, skip <<= 1) {
  34197. for (var val = 0; val < n; ++val) {
  34198. if (lengths[val] === len) {
  34199. // bit-reverse the code
  34200. var code2 = 0;
  34201. var t = code;
  34202. for (i = 0; i < len; ++i) {
  34203. code2 = (code2 << 1) | (t & 1);
  34204. t >>= 1;
  34205. }
  34206. // fill the table entries
  34207. for (i = code2; i < size; i += skip) {
  34208. codes[i] = (len << 16) | val;
  34209. }
  34210. ++code;
  34211. }
  34212. }
  34213. }
  34214. return [codes, maxLen];
  34215. };
  34216. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  34217. var buffer, len;
  34218. var str = this.str;
  34219. // read block header
  34220. var hdr = this.getBits(3);
  34221. if (hdr & 1) {
  34222. this.eof = true;
  34223. }
  34224. hdr >>= 1;
  34225. if (hdr === 0) { // uncompressed block
  34226. var b;
  34227. if ((b = str.getByte()) === -1) {
  34228. error('Bad block header in flate stream');
  34229. }
  34230. var blockLen = b;
  34231. if ((b = str.getByte()) === -1) {
  34232. error('Bad block header in flate stream');
  34233. }
  34234. blockLen |= (b << 8);
  34235. if ((b = str.getByte()) === -1) {
  34236. error('Bad block header in flate stream');
  34237. }
  34238. var check = b;
  34239. if ((b = str.getByte()) === -1) {
  34240. error('Bad block header in flate stream');
  34241. }
  34242. check |= (b << 8);
  34243. if (check !== (~blockLen & 0xffff) &&
  34244. (blockLen !== 0 || check !== 0)) {
  34245. // Ignoring error for bad "empty" block (see issue 1277)
  34246. error('Bad uncompressed block length in flate stream');
  34247. }
  34248. this.codeBuf = 0;
  34249. this.codeSize = 0;
  34250. var bufferLength = this.bufferLength;
  34251. buffer = this.ensureBuffer(bufferLength + blockLen);
  34252. var end = bufferLength + blockLen;
  34253. this.bufferLength = end;
  34254. if (blockLen === 0) {
  34255. if (str.peekBytes(1).length === 0) {
  34256. this.eof = true;
  34257. }
  34258. } else {
  34259. for (var n = bufferLength; n < end; ++n) {
  34260. if ((b = str.getByte()) === -1) {
  34261. this.eof = true;
  34262. break;
  34263. }
  34264. buffer[n] = b;
  34265. }
  34266. }
  34267. return;
  34268. }
  34269. var litCodeTable;
  34270. var distCodeTable;
  34271. if (hdr === 1) { // compressed block, fixed codes
  34272. litCodeTable = fixedLitCodeTab;
  34273. distCodeTable = fixedDistCodeTab;
  34274. } else if (hdr === 2) { // compressed block, dynamic codes
  34275. var numLitCodes = this.getBits(5) + 257;
  34276. var numDistCodes = this.getBits(5) + 1;
  34277. var numCodeLenCodes = this.getBits(4) + 4;
  34278. // build the code lengths code table
  34279. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  34280. var i;
  34281. for (i = 0; i < numCodeLenCodes; ++i) {
  34282. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  34283. }
  34284. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  34285. // build the literal and distance code tables
  34286. len = 0;
  34287. i = 0;
  34288. var codes = numLitCodes + numDistCodes;
  34289. var codeLengths = new Uint8Array(codes);
  34290. var bitsLength, bitsOffset, what;
  34291. while (i < codes) {
  34292. var code = this.getCode(codeLenCodeTab);
  34293. if (code === 16) {
  34294. bitsLength = 2; bitsOffset = 3; what = len;
  34295. } else if (code === 17) {
  34296. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  34297. } else if (code === 18) {
  34298. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  34299. } else {
  34300. codeLengths[i++] = len = code;
  34301. continue;
  34302. }
  34303. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  34304. while (repeatLength-- > 0) {
  34305. codeLengths[i++] = what;
  34306. }
  34307. }
  34308. litCodeTable =
  34309. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  34310. distCodeTable =
  34311. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  34312. } else {
  34313. error('Unknown block type in flate stream');
  34314. }
  34315. buffer = this.buffer;
  34316. var limit = buffer ? buffer.length : 0;
  34317. var pos = this.bufferLength;
  34318. while (true) {
  34319. var code1 = this.getCode(litCodeTable);
  34320. if (code1 < 256) {
  34321. if (pos + 1 >= limit) {
  34322. buffer = this.ensureBuffer(pos + 1);
  34323. limit = buffer.length;
  34324. }
  34325. buffer[pos++] = code1;
  34326. continue;
  34327. }
  34328. if (code1 === 256) {
  34329. this.bufferLength = pos;
  34330. return;
  34331. }
  34332. code1 -= 257;
  34333. code1 = lengthDecode[code1];
  34334. var code2 = code1 >> 16;
  34335. if (code2 > 0) {
  34336. code2 = this.getBits(code2);
  34337. }
  34338. len = (code1 & 0xffff) + code2;
  34339. code1 = this.getCode(distCodeTable);
  34340. code1 = distDecode[code1];
  34341. code2 = code1 >> 16;
  34342. if (code2 > 0) {
  34343. code2 = this.getBits(code2);
  34344. }
  34345. var dist = (code1 & 0xffff) + code2;
  34346. if (pos + len >= limit) {
  34347. buffer = this.ensureBuffer(pos + len);
  34348. limit = buffer.length;
  34349. }
  34350. for (var k = 0; k < len; ++k, ++pos) {
  34351. buffer[pos] = buffer[pos - dist];
  34352. }
  34353. }
  34354. };
  34355. return FlateStream;
  34356. })();
  34357. var PredictorStream = (function PredictorStreamClosure() {
  34358. function PredictorStream(str, maybeLength, params) {
  34359. var predictor = this.predictor = params.get('Predictor') || 1;
  34360. if (predictor <= 1) {
  34361. return str; // no prediction
  34362. }
  34363. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  34364. error('Unsupported predictor: ' + predictor);
  34365. }
  34366. if (predictor === 2) {
  34367. this.readBlock = this.readBlockTiff;
  34368. } else {
  34369. this.readBlock = this.readBlockPng;
  34370. }
  34371. this.str = str;
  34372. this.dict = str.dict;
  34373. var colors = this.colors = params.get('Colors') || 1;
  34374. var bits = this.bits = params.get('BitsPerComponent') || 8;
  34375. var columns = this.columns = params.get('Columns') || 1;
  34376. this.pixBytes = (colors * bits + 7) >> 3;
  34377. this.rowBytes = (columns * colors * bits + 7) >> 3;
  34378. DecodeStream.call(this, maybeLength);
  34379. return this;
  34380. }
  34381. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  34382. PredictorStream.prototype.readBlockTiff =
  34383. function predictorStreamReadBlockTiff() {
  34384. var rowBytes = this.rowBytes;
  34385. var bufferLength = this.bufferLength;
  34386. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  34387. var bits = this.bits;
  34388. var colors = this.colors;
  34389. var rawBytes = this.str.getBytes(rowBytes);
  34390. this.eof = !rawBytes.length;
  34391. if (this.eof) {
  34392. return;
  34393. }
  34394. var inbuf = 0, outbuf = 0;
  34395. var inbits = 0, outbits = 0;
  34396. var pos = bufferLength;
  34397. var i;
  34398. if (bits === 1) {
  34399. for (i = 0; i < rowBytes; ++i) {
  34400. var c = rawBytes[i];
  34401. inbuf = (inbuf << 8) | c;
  34402. // bitwise addition is exclusive or
  34403. // first shift inbuf and then add
  34404. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  34405. // truncate inbuf (assumes colors < 16)
  34406. inbuf &= 0xFFFF;
  34407. }
  34408. } else if (bits === 8) {
  34409. for (i = 0; i < colors; ++i) {
  34410. buffer[pos++] = rawBytes[i];
  34411. }
  34412. for (; i < rowBytes; ++i) {
  34413. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  34414. pos++;
  34415. }
  34416. } else {
  34417. var compArray = new Uint8Array(colors + 1);
  34418. var bitMask = (1 << bits) - 1;
  34419. var j = 0, k = bufferLength;
  34420. var columns = this.columns;
  34421. for (i = 0; i < columns; ++i) {
  34422. for (var kk = 0; kk < colors; ++kk) {
  34423. if (inbits < bits) {
  34424. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  34425. inbits += 8;
  34426. }
  34427. compArray[kk] = (compArray[kk] +
  34428. (inbuf >> (inbits - bits))) & bitMask;
  34429. inbits -= bits;
  34430. outbuf = (outbuf << bits) | compArray[kk];
  34431. outbits += bits;
  34432. if (outbits >= 8) {
  34433. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  34434. outbits -= 8;
  34435. }
  34436. }
  34437. }
  34438. if (outbits > 0) {
  34439. buffer[k++] = (outbuf << (8 - outbits)) +
  34440. (inbuf & ((1 << (8 - outbits)) - 1));
  34441. }
  34442. }
  34443. this.bufferLength += rowBytes;
  34444. };
  34445. PredictorStream.prototype.readBlockPng =
  34446. function predictorStreamReadBlockPng() {
  34447. var rowBytes = this.rowBytes;
  34448. var pixBytes = this.pixBytes;
  34449. var predictor = this.str.getByte();
  34450. var rawBytes = this.str.getBytes(rowBytes);
  34451. this.eof = !rawBytes.length;
  34452. if (this.eof) {
  34453. return;
  34454. }
  34455. var bufferLength = this.bufferLength;
  34456. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  34457. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  34458. if (prevRow.length === 0) {
  34459. prevRow = new Uint8Array(rowBytes);
  34460. }
  34461. var i, j = bufferLength, up, c;
  34462. switch (predictor) {
  34463. case 0:
  34464. for (i = 0; i < rowBytes; ++i) {
  34465. buffer[j++] = rawBytes[i];
  34466. }
  34467. break;
  34468. case 1:
  34469. for (i = 0; i < pixBytes; ++i) {
  34470. buffer[j++] = rawBytes[i];
  34471. }
  34472. for (; i < rowBytes; ++i) {
  34473. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  34474. j++;
  34475. }
  34476. break;
  34477. case 2:
  34478. for (i = 0; i < rowBytes; ++i) {
  34479. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  34480. }
  34481. break;
  34482. case 3:
  34483. for (i = 0; i < pixBytes; ++i) {
  34484. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  34485. }
  34486. for (; i < rowBytes; ++i) {
  34487. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  34488. rawBytes[i]) & 0xFF;
  34489. j++;
  34490. }
  34491. break;
  34492. case 4:
  34493. // we need to save the up left pixels values. the simplest way
  34494. // is to create a new buffer
  34495. for (i = 0; i < pixBytes; ++i) {
  34496. up = prevRow[i];
  34497. c = rawBytes[i];
  34498. buffer[j++] = up + c;
  34499. }
  34500. for (; i < rowBytes; ++i) {
  34501. up = prevRow[i];
  34502. var upLeft = prevRow[i - pixBytes];
  34503. var left = buffer[j - pixBytes];
  34504. var p = left + up - upLeft;
  34505. var pa = p - left;
  34506. if (pa < 0) {
  34507. pa = -pa;
  34508. }
  34509. var pb = p - up;
  34510. if (pb < 0) {
  34511. pb = -pb;
  34512. }
  34513. var pc = p - upLeft;
  34514. if (pc < 0) {
  34515. pc = -pc;
  34516. }
  34517. c = rawBytes[i];
  34518. if (pa <= pb && pa <= pc) {
  34519. buffer[j++] = left + c;
  34520. } else if (pb <= pc) {
  34521. buffer[j++] = up + c;
  34522. } else {
  34523. buffer[j++] = upLeft + c;
  34524. }
  34525. }
  34526. break;
  34527. default:
  34528. error('Unsupported predictor: ' + predictor);
  34529. }
  34530. this.bufferLength += rowBytes;
  34531. };
  34532. return PredictorStream;
  34533. })();
  34534. /**
  34535. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  34536. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  34537. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  34538. * a library to decode these images and the stream behaves like all the other
  34539. * DecodeStreams.
  34540. */
  34541. var JpegStream = (function JpegStreamClosure() {
  34542. function JpegStream(stream, maybeLength, dict, xref) {
  34543. // TODO: per poppler, some images may have 'junk' before that
  34544. // need to be removed
  34545. this.stream = stream;
  34546. this.maybeLength = maybeLength;
  34547. this.dict = dict;
  34548. DecodeStream.call(this, maybeLength);
  34549. }
  34550. JpegStream.prototype = Object.create(DecodeStream.prototype);
  34551. Object.defineProperty(JpegStream.prototype, 'bytes', {
  34552. get: function JpegStream_bytes() {
  34553. // If this.maybeLength is null, we'll get the entire stream.
  34554. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  34555. },
  34556. configurable: true
  34557. });
  34558. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  34559. if (this.bufferLength) {
  34560. return;
  34561. }
  34562. try {
  34563. var jpegImage = new JpegImage();
  34564. // checking if values needs to be transformed before conversion
  34565. if (this.dict && isArray(this.dict.get('Decode'))) {
  34566. var decodeArr = this.dict.get('Decode');
  34567. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  34568. var decodeArrLength = decodeArr.length;
  34569. var transform = new Int32Array(decodeArrLength);
  34570. var transformNeeded = false;
  34571. var maxValue = (1 << bitsPerComponent) - 1;
  34572. for (var i = 0; i < decodeArrLength; i += 2) {
  34573. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  34574. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  34575. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  34576. transformNeeded = true;
  34577. }
  34578. }
  34579. if (transformNeeded) {
  34580. jpegImage.decodeTransform = transform;
  34581. }
  34582. }
  34583. jpegImage.parse(this.bytes);
  34584. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  34585. this.forceRGB);
  34586. this.buffer = data;
  34587. this.bufferLength = data.length;
  34588. this.eof = true;
  34589. } catch (e) {
  34590. error('JPEG error: ' + e);
  34591. }
  34592. };
  34593. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  34594. this.ensureBuffer();
  34595. return this.buffer;
  34596. };
  34597. JpegStream.prototype.getIR = function JpegStream_getIR() {
  34598. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  34599. };
  34600. /**
  34601. * Checks if the image can be decoded and displayed by the browser without any
  34602. * further processing such as color space conversions.
  34603. */
  34604. JpegStream.prototype.isNativelySupported =
  34605. function JpegStream_isNativelySupported(xref, res) {
  34606. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  34607. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  34608. };
  34609. /**
  34610. * Checks if the image can be decoded by the browser.
  34611. */
  34612. JpegStream.prototype.isNativelyDecodable =
  34613. function JpegStream_isNativelyDecodable(xref, res) {
  34614. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  34615. var numComps = cs.numComps;
  34616. return numComps === 1 || numComps === 3;
  34617. };
  34618. return JpegStream;
  34619. })();
  34620. /**
  34621. * For JPEG 2000's we use a library to decode these images and
  34622. * the stream behaves like all the other DecodeStreams.
  34623. */
  34624. var JpxStream = (function JpxStreamClosure() {
  34625. function JpxStream(stream, maybeLength, dict) {
  34626. this.stream = stream;
  34627. this.maybeLength = maybeLength;
  34628. this.dict = dict;
  34629. DecodeStream.call(this, maybeLength);
  34630. }
  34631. JpxStream.prototype = Object.create(DecodeStream.prototype);
  34632. Object.defineProperty(JpxStream.prototype, 'bytes', {
  34633. get: function JpxStream_bytes() {
  34634. // If this.maybeLength is null, we'll get the entire stream.
  34635. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  34636. },
  34637. configurable: true
  34638. });
  34639. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  34640. if (this.bufferLength) {
  34641. return;
  34642. }
  34643. var jpxImage = new JpxImage();
  34644. jpxImage.parse(this.bytes);
  34645. var width = jpxImage.width;
  34646. var height = jpxImage.height;
  34647. var componentsCount = jpxImage.componentsCount;
  34648. var tileCount = jpxImage.tiles.length;
  34649. if (tileCount === 1) {
  34650. this.buffer = jpxImage.tiles[0].items;
  34651. } else {
  34652. var data = new Uint8Array(width * height * componentsCount);
  34653. for (var k = 0; k < tileCount; k++) {
  34654. var tileComponents = jpxImage.tiles[k];
  34655. var tileWidth = tileComponents.width;
  34656. var tileHeight = tileComponents.height;
  34657. var tileLeft = tileComponents.left;
  34658. var tileTop = tileComponents.top;
  34659. var src = tileComponents.items;
  34660. var srcPosition = 0;
  34661. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  34662. var imgRowSize = width * componentsCount;
  34663. var tileRowSize = tileWidth * componentsCount;
  34664. for (var j = 0; j < tileHeight; j++) {
  34665. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  34666. data.set(rowBytes, dataPosition);
  34667. srcPosition += tileRowSize;
  34668. dataPosition += imgRowSize;
  34669. }
  34670. }
  34671. this.buffer = data;
  34672. }
  34673. this.bufferLength = this.buffer.length;
  34674. this.eof = true;
  34675. };
  34676. return JpxStream;
  34677. })();
  34678. /**
  34679. * For JBIG2's we use a library to decode these images and
  34680. * the stream behaves like all the other DecodeStreams.
  34681. */
  34682. var Jbig2Stream = (function Jbig2StreamClosure() {
  34683. function Jbig2Stream(stream, maybeLength, dict) {
  34684. this.stream = stream;
  34685. this.maybeLength = maybeLength;
  34686. this.dict = dict;
  34687. DecodeStream.call(this, maybeLength);
  34688. }
  34689. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  34690. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  34691. get: function Jbig2Stream_bytes() {
  34692. // If this.maybeLength is null, we'll get the entire stream.
  34693. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  34694. },
  34695. configurable: true
  34696. });
  34697. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  34698. if (this.bufferLength) {
  34699. return;
  34700. }
  34701. var jbig2Image = new Jbig2Image();
  34702. var chunks = [], decodeParams = this.dict.get('DecodeParms');
  34703. // According to the PDF specification, DecodeParms can be either
  34704. // a dictionary, or an array whose elements are dictionaries.
  34705. if (isArray(decodeParams)) {
  34706. if (decodeParams.length > 1) {
  34707. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  34708. 'not supported.');
  34709. }
  34710. decodeParams = decodeParams[0];
  34711. }
  34712. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  34713. var globalsStream = decodeParams.get('JBIG2Globals');
  34714. var globals = globalsStream.getBytes();
  34715. chunks.push({data: globals, start: 0, end: globals.length});
  34716. }
  34717. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  34718. var data = jbig2Image.parseChunks(chunks);
  34719. var dataLength = data.length;
  34720. // JBIG2 had black as 1 and white as 0, inverting the colors
  34721. for (var i = 0; i < dataLength; i++) {
  34722. data[i] ^= 0xFF;
  34723. }
  34724. this.buffer = data;
  34725. this.bufferLength = dataLength;
  34726. this.eof = true;
  34727. };
  34728. return Jbig2Stream;
  34729. })();
  34730. var DecryptStream = (function DecryptStreamClosure() {
  34731. function DecryptStream(str, maybeLength, decrypt) {
  34732. this.str = str;
  34733. this.dict = str.dict;
  34734. this.decrypt = decrypt;
  34735. this.nextChunk = null;
  34736. this.initialized = false;
  34737. DecodeStream.call(this, maybeLength);
  34738. }
  34739. var chunkSize = 512;
  34740. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  34741. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  34742. var chunk;
  34743. if (this.initialized) {
  34744. chunk = this.nextChunk;
  34745. } else {
  34746. chunk = this.str.getBytes(chunkSize);
  34747. this.initialized = true;
  34748. }
  34749. if (!chunk || chunk.length === 0) {
  34750. this.eof = true;
  34751. return;
  34752. }
  34753. this.nextChunk = this.str.getBytes(chunkSize);
  34754. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  34755. var decrypt = this.decrypt;
  34756. chunk = decrypt(chunk, !hasMoreData);
  34757. var bufferLength = this.bufferLength;
  34758. var i, n = chunk.length;
  34759. var buffer = this.ensureBuffer(bufferLength + n);
  34760. for (i = 0; i < n; i++) {
  34761. buffer[bufferLength++] = chunk[i];
  34762. }
  34763. this.bufferLength = bufferLength;
  34764. };
  34765. return DecryptStream;
  34766. })();
  34767. var Ascii85Stream = (function Ascii85StreamClosure() {
  34768. function Ascii85Stream(str, maybeLength) {
  34769. this.str = str;
  34770. this.dict = str.dict;
  34771. this.input = new Uint8Array(5);
  34772. // Most streams increase in size when decoded, but Ascii85 streams
  34773. // typically shrink by ~20%.
  34774. if (maybeLength) {
  34775. maybeLength = 0.8 * maybeLength;
  34776. }
  34777. DecodeStream.call(this, maybeLength);
  34778. }
  34779. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  34780. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  34781. var TILDA_CHAR = 0x7E; // '~'
  34782. var Z_LOWER_CHAR = 0x7A; // 'z'
  34783. var EOF = -1;
  34784. var str = this.str;
  34785. var c = str.getByte();
  34786. while (Lexer.isSpace(c)) {
  34787. c = str.getByte();
  34788. }
  34789. if (c === EOF || c === TILDA_CHAR) {
  34790. this.eof = true;
  34791. return;
  34792. }
  34793. var bufferLength = this.bufferLength, buffer;
  34794. var i;
  34795. // special code for z
  34796. if (c === Z_LOWER_CHAR) {
  34797. buffer = this.ensureBuffer(bufferLength + 4);
  34798. for (i = 0; i < 4; ++i) {
  34799. buffer[bufferLength + i] = 0;
  34800. }
  34801. this.bufferLength += 4;
  34802. } else {
  34803. var input = this.input;
  34804. input[0] = c;
  34805. for (i = 1; i < 5; ++i) {
  34806. c = str.getByte();
  34807. while (Lexer.isSpace(c)) {
  34808. c = str.getByte();
  34809. }
  34810. input[i] = c;
  34811. if (c === EOF || c === TILDA_CHAR) {
  34812. break;
  34813. }
  34814. }
  34815. buffer = this.ensureBuffer(bufferLength + i - 1);
  34816. this.bufferLength += i - 1;
  34817. // partial ending;
  34818. if (i < 5) {
  34819. for (; i < 5; ++i) {
  34820. input[i] = 0x21 + 84;
  34821. }
  34822. this.eof = true;
  34823. }
  34824. var t = 0;
  34825. for (i = 0; i < 5; ++i) {
  34826. t = t * 85 + (input[i] - 0x21);
  34827. }
  34828. for (i = 3; i >= 0; --i) {
  34829. buffer[bufferLength + i] = t & 0xFF;
  34830. t >>= 8;
  34831. }
  34832. }
  34833. };
  34834. return Ascii85Stream;
  34835. })();
  34836. var AsciiHexStream = (function AsciiHexStreamClosure() {
  34837. function AsciiHexStream(str, maybeLength) {
  34838. this.str = str;
  34839. this.dict = str.dict;
  34840. this.firstDigit = -1;
  34841. // Most streams increase in size when decoded, but AsciiHex streams shrink
  34842. // by 50%.
  34843. if (maybeLength) {
  34844. maybeLength = 0.5 * maybeLength;
  34845. }
  34846. DecodeStream.call(this, maybeLength);
  34847. }
  34848. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  34849. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  34850. var UPSTREAM_BLOCK_SIZE = 8000;
  34851. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  34852. if (!bytes.length) {
  34853. this.eof = true;
  34854. return;
  34855. }
  34856. var maxDecodeLength = (bytes.length + 1) >> 1;
  34857. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  34858. var bufferLength = this.bufferLength;
  34859. var firstDigit = this.firstDigit;
  34860. for (var i = 0, ii = bytes.length; i < ii; i++) {
  34861. var ch = bytes[i], digit;
  34862. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34863. digit = ch & 0x0F;
  34864. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34865. // 'A'-'Z', 'a'-'z'
  34866. digit = (ch & 0x0F) + 9;
  34867. } else if (ch === 0x3E) { // '>'
  34868. this.eof = true;
  34869. break;
  34870. } else { // probably whitespace
  34871. continue; // ignoring
  34872. }
  34873. if (firstDigit < 0) {
  34874. firstDigit = digit;
  34875. } else {
  34876. buffer[bufferLength++] = (firstDigit << 4) | digit;
  34877. firstDigit = -1;
  34878. }
  34879. }
  34880. if (firstDigit >= 0 && this.eof) {
  34881. // incomplete byte
  34882. buffer[bufferLength++] = (firstDigit << 4);
  34883. firstDigit = -1;
  34884. }
  34885. this.firstDigit = firstDigit;
  34886. this.bufferLength = bufferLength;
  34887. };
  34888. return AsciiHexStream;
  34889. })();
  34890. var RunLengthStream = (function RunLengthStreamClosure() {
  34891. function RunLengthStream(str, maybeLength) {
  34892. this.str = str;
  34893. this.dict = str.dict;
  34894. DecodeStream.call(this, maybeLength);
  34895. }
  34896. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  34897. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  34898. // The repeatHeader has following format. The first byte defines type of run
  34899. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  34900. // (in addition to the second byte from the header), n = 129 through 255 -
  34901. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  34902. var repeatHeader = this.str.getBytes(2);
  34903. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  34904. this.eof = true;
  34905. return;
  34906. }
  34907. var buffer;
  34908. var bufferLength = this.bufferLength;
  34909. var n = repeatHeader[0];
  34910. if (n < 128) {
  34911. // copy n bytes
  34912. buffer = this.ensureBuffer(bufferLength + n + 1);
  34913. buffer[bufferLength++] = repeatHeader[1];
  34914. if (n > 0) {
  34915. var source = this.str.getBytes(n);
  34916. buffer.set(source, bufferLength);
  34917. bufferLength += n;
  34918. }
  34919. } else {
  34920. n = 257 - n;
  34921. var b = repeatHeader[1];
  34922. buffer = this.ensureBuffer(bufferLength + n + 1);
  34923. for (var i = 0; i < n; i++) {
  34924. buffer[bufferLength++] = b;
  34925. }
  34926. }
  34927. this.bufferLength = bufferLength;
  34928. };
  34929. return RunLengthStream;
  34930. })();
  34931. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  34932. var ccittEOL = -2;
  34933. var twoDimPass = 0;
  34934. var twoDimHoriz = 1;
  34935. var twoDimVert0 = 2;
  34936. var twoDimVertR1 = 3;
  34937. var twoDimVertL1 = 4;
  34938. var twoDimVertR2 = 5;
  34939. var twoDimVertL2 = 6;
  34940. var twoDimVertR3 = 7;
  34941. var twoDimVertL3 = 8;
  34942. var twoDimTable = [
  34943. [-1, -1], [-1, -1], // 000000x
  34944. [7, twoDimVertL3], // 0000010
  34945. [7, twoDimVertR3], // 0000011
  34946. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  34947. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  34948. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  34949. [4, twoDimPass], [4, twoDimPass],
  34950. [4, twoDimPass], [4, twoDimPass],
  34951. [4, twoDimPass], [4, twoDimPass],
  34952. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  34953. [3, twoDimHoriz], [3, twoDimHoriz],
  34954. [3, twoDimHoriz], [3, twoDimHoriz],
  34955. [3, twoDimHoriz], [3, twoDimHoriz],
  34956. [3, twoDimHoriz], [3, twoDimHoriz],
  34957. [3, twoDimHoriz], [3, twoDimHoriz],
  34958. [3, twoDimHoriz], [3, twoDimHoriz],
  34959. [3, twoDimHoriz], [3, twoDimHoriz],
  34960. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  34961. [3, twoDimVertL1], [3, twoDimVertL1],
  34962. [3, twoDimVertL1], [3, twoDimVertL1],
  34963. [3, twoDimVertL1], [3, twoDimVertL1],
  34964. [3, twoDimVertL1], [3, twoDimVertL1],
  34965. [3, twoDimVertL1], [3, twoDimVertL1],
  34966. [3, twoDimVertL1], [3, twoDimVertL1],
  34967. [3, twoDimVertL1], [3, twoDimVertL1],
  34968. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  34969. [3, twoDimVertR1], [3, twoDimVertR1],
  34970. [3, twoDimVertR1], [3, twoDimVertR1],
  34971. [3, twoDimVertR1], [3, twoDimVertR1],
  34972. [3, twoDimVertR1], [3, twoDimVertR1],
  34973. [3, twoDimVertR1], [3, twoDimVertR1],
  34974. [3, twoDimVertR1], [3, twoDimVertR1],
  34975. [3, twoDimVertR1], [3, twoDimVertR1],
  34976. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  34977. [1, twoDimVert0], [1, twoDimVert0],
  34978. [1, twoDimVert0], [1, twoDimVert0],
  34979. [1, twoDimVert0], [1, twoDimVert0],
  34980. [1, twoDimVert0], [1, twoDimVert0],
  34981. [1, twoDimVert0], [1, twoDimVert0],
  34982. [1, twoDimVert0], [1, twoDimVert0],
  34983. [1, twoDimVert0], [1, twoDimVert0],
  34984. [1, twoDimVert0], [1, twoDimVert0],
  34985. [1, twoDimVert0], [1, twoDimVert0],
  34986. [1, twoDimVert0], [1, twoDimVert0],
  34987. [1, twoDimVert0], [1, twoDimVert0],
  34988. [1, twoDimVert0], [1, twoDimVert0],
  34989. [1, twoDimVert0], [1, twoDimVert0],
  34990. [1, twoDimVert0], [1, twoDimVert0],
  34991. [1, twoDimVert0], [1, twoDimVert0],
  34992. [1, twoDimVert0], [1, twoDimVert0],
  34993. [1, twoDimVert0], [1, twoDimVert0],
  34994. [1, twoDimVert0], [1, twoDimVert0],
  34995. [1, twoDimVert0], [1, twoDimVert0],
  34996. [1, twoDimVert0], [1, twoDimVert0],
  34997. [1, twoDimVert0], [1, twoDimVert0],
  34998. [1, twoDimVert0], [1, twoDimVert0],
  34999. [1, twoDimVert0], [1, twoDimVert0],
  35000. [1, twoDimVert0], [1, twoDimVert0],
  35001. [1, twoDimVert0], [1, twoDimVert0],
  35002. [1, twoDimVert0], [1, twoDimVert0],
  35003. [1, twoDimVert0], [1, twoDimVert0],
  35004. [1, twoDimVert0], [1, twoDimVert0],
  35005. [1, twoDimVert0], [1, twoDimVert0],
  35006. [1, twoDimVert0], [1, twoDimVert0],
  35007. [1, twoDimVert0], [1, twoDimVert0]
  35008. ];
  35009. var whiteTable1 = [
  35010. [-1, -1], // 00000
  35011. [12, ccittEOL], // 00001
  35012. [-1, -1], [-1, -1], // 0001x
  35013. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  35014. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  35015. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  35016. [11, 1792], [11, 1792], // 1000x
  35017. [12, 1984], // 10010
  35018. [12, 2048], // 10011
  35019. [12, 2112], // 10100
  35020. [12, 2176], // 10101
  35021. [12, 2240], // 10110
  35022. [12, 2304], // 10111
  35023. [11, 1856], [11, 1856], // 1100x
  35024. [11, 1920], [11, 1920], // 1101x
  35025. [12, 2368], // 11100
  35026. [12, 2432], // 11101
  35027. [12, 2496], // 11110
  35028. [12, 2560] // 11111
  35029. ];
  35030. var whiteTable2 = [
  35031. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  35032. [8, 29], [8, 29], // 00000010x
  35033. [8, 30], [8, 30], // 00000011x
  35034. [8, 45], [8, 45], // 00000100x
  35035. [8, 46], [8, 46], // 00000101x
  35036. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  35037. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  35038. [8, 47], [8, 47], // 00001010x
  35039. [8, 48], [8, 48], // 00001011x
  35040. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  35041. [6, 13], [6, 13], [6, 13], [6, 13],
  35042. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  35043. [8, 33], [8, 33], // 00010010x
  35044. [8, 34], [8, 34], // 00010011x
  35045. [8, 35], [8, 35], // 00010100x
  35046. [8, 36], [8, 36], // 00010101x
  35047. [8, 37], [8, 37], // 00010110x
  35048. [8, 38], [8, 38], // 00010111x
  35049. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  35050. [8, 31], [8, 31], // 00011010x
  35051. [8, 32], [8, 32], // 00011011x
  35052. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  35053. [6, 1], [6, 1], [6, 1], [6, 1],
  35054. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  35055. [6, 12], [6, 12], [6, 12], [6, 12],
  35056. [8, 53], [8, 53], // 00100100x
  35057. [8, 54], [8, 54], // 00100101x
  35058. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  35059. [8, 39], [8, 39], // 00101000x
  35060. [8, 40], [8, 40], // 00101001x
  35061. [8, 41], [8, 41], // 00101010x
  35062. [8, 42], [8, 42], // 00101011x
  35063. [8, 43], [8, 43], // 00101100x
  35064. [8, 44], [8, 44], // 00101101x
  35065. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  35066. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  35067. [8, 61], [8, 61], // 00110010x
  35068. [8, 62], [8, 62], // 00110011x
  35069. [8, 63], [8, 63], // 00110100x
  35070. [8, 0], [8, 0], // 00110101x
  35071. [8, 320], [8, 320], // 00110110x
  35072. [8, 384], [8, 384], // 00110111x
  35073. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  35074. [5, 10], [5, 10], [5, 10], [5, 10],
  35075. [5, 10], [5, 10], [5, 10], [5, 10],
  35076. [5, 10], [5, 10], [5, 10], [5, 10],
  35077. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  35078. [5, 11], [5, 11], [5, 11], [5, 11],
  35079. [5, 11], [5, 11], [5, 11], [5, 11],
  35080. [5, 11], [5, 11], [5, 11], [5, 11],
  35081. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  35082. [8, 59], [8, 59], // 01001010x
  35083. [8, 60], [8, 60], // 01001011x
  35084. [9, 1472], // 010011000
  35085. [9, 1536], // 010011001
  35086. [9, 1600], // 010011010
  35087. [9, 1728], // 010011011
  35088. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  35089. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  35090. [8, 49], [8, 49], // 01010010x
  35091. [8, 50], [8, 50], // 01010011x
  35092. [8, 51], [8, 51], // 01010100x
  35093. [8, 52], [8, 52], // 01010101x
  35094. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  35095. [8, 55], [8, 55], // 01011000x
  35096. [8, 56], [8, 56], // 01011001x
  35097. [8, 57], [8, 57], // 01011010x
  35098. [8, 58], [8, 58], // 01011011x
  35099. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  35100. [6, 192], [6, 192], [6, 192], [6, 192],
  35101. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  35102. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  35103. [8, 448], [8, 448], // 01100100x
  35104. [8, 512], [8, 512], // 01100101x
  35105. [9, 704], // 011001100
  35106. [9, 768], // 011001101
  35107. [8, 640], [8, 640], // 01100111x
  35108. [8, 576], [8, 576], // 01101000x
  35109. [9, 832], // 011010010
  35110. [9, 896], // 011010011
  35111. [9, 960], // 011010100
  35112. [9, 1024], // 011010101
  35113. [9, 1088], // 011010110
  35114. [9, 1152], // 011010111
  35115. [9, 1216], // 011011000
  35116. [9, 1280], // 011011001
  35117. [9, 1344], // 011011010
  35118. [9, 1408], // 011011011
  35119. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  35120. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  35121. [4, 2], [4, 2], [4, 2], [4, 2],
  35122. [4, 2], [4, 2], [4, 2], [4, 2],
  35123. [4, 2], [4, 2], [4, 2], [4, 2],
  35124. [4, 2], [4, 2], [4, 2], [4, 2],
  35125. [4, 2], [4, 2], [4, 2], [4, 2],
  35126. [4, 2], [4, 2], [4, 2], [4, 2],
  35127. [4, 2], [4, 2], [4, 2], [4, 2],
  35128. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  35129. [4, 3], [4, 3], [4, 3], [4, 3],
  35130. [4, 3], [4, 3], [4, 3], [4, 3],
  35131. [4, 3], [4, 3], [4, 3], [4, 3],
  35132. [4, 3], [4, 3], [4, 3], [4, 3],
  35133. [4, 3], [4, 3], [4, 3], [4, 3],
  35134. [4, 3], [4, 3], [4, 3], [4, 3],
  35135. [4, 3], [4, 3], [4, 3], [4, 3],
  35136. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  35137. [5, 128], [5, 128], [5, 128], [5, 128],
  35138. [5, 128], [5, 128], [5, 128], [5, 128],
  35139. [5, 128], [5, 128], [5, 128], [5, 128],
  35140. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  35141. [5, 8], [5, 8], [5, 8], [5, 8],
  35142. [5, 8], [5, 8], [5, 8], [5, 8],
  35143. [5, 8], [5, 8], [5, 8], [5, 8],
  35144. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  35145. [5, 9], [5, 9], [5, 9], [5, 9],
  35146. [5, 9], [5, 9], [5, 9], [5, 9],
  35147. [5, 9], [5, 9], [5, 9], [5, 9],
  35148. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  35149. [6, 16], [6, 16], [6, 16], [6, 16],
  35150. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  35151. [6, 17], [6, 17], [6, 17], [6, 17],
  35152. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  35153. [4, 4], [4, 4], [4, 4], [4, 4],
  35154. [4, 4], [4, 4], [4, 4], [4, 4],
  35155. [4, 4], [4, 4], [4, 4], [4, 4],
  35156. [4, 4], [4, 4], [4, 4], [4, 4],
  35157. [4, 4], [4, 4], [4, 4], [4, 4],
  35158. [4, 4], [4, 4], [4, 4], [4, 4],
  35159. [4, 4], [4, 4], [4, 4], [4, 4],
  35160. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  35161. [4, 5], [4, 5], [4, 5], [4, 5],
  35162. [4, 5], [4, 5], [4, 5], [4, 5],
  35163. [4, 5], [4, 5], [4, 5], [4, 5],
  35164. [4, 5], [4, 5], [4, 5], [4, 5],
  35165. [4, 5], [4, 5], [4, 5], [4, 5],
  35166. [4, 5], [4, 5], [4, 5], [4, 5],
  35167. [4, 5], [4, 5], [4, 5], [4, 5],
  35168. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  35169. [6, 14], [6, 14], [6, 14], [6, 14],
  35170. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  35171. [6, 15], [6, 15], [6, 15], [6, 15],
  35172. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  35173. [5, 64], [5, 64], [5, 64], [5, 64],
  35174. [5, 64], [5, 64], [5, 64], [5, 64],
  35175. [5, 64], [5, 64], [5, 64], [5, 64],
  35176. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  35177. [4, 6], [4, 6], [4, 6], [4, 6],
  35178. [4, 6], [4, 6], [4, 6], [4, 6],
  35179. [4, 6], [4, 6], [4, 6], [4, 6],
  35180. [4, 6], [4, 6], [4, 6], [4, 6],
  35181. [4, 6], [4, 6], [4, 6], [4, 6],
  35182. [4, 6], [4, 6], [4, 6], [4, 6],
  35183. [4, 6], [4, 6], [4, 6], [4, 6],
  35184. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  35185. [4, 7], [4, 7], [4, 7], [4, 7],
  35186. [4, 7], [4, 7], [4, 7], [4, 7],
  35187. [4, 7], [4, 7], [4, 7], [4, 7],
  35188. [4, 7], [4, 7], [4, 7], [4, 7],
  35189. [4, 7], [4, 7], [4, 7], [4, 7],
  35190. [4, 7], [4, 7], [4, 7], [4, 7],
  35191. [4, 7], [4, 7], [4, 7], [4, 7]
  35192. ];
  35193. var blackTable1 = [
  35194. [-1, -1], [-1, -1], // 000000000000x
  35195. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  35196. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  35197. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  35198. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  35199. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  35200. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  35201. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  35202. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  35203. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  35204. [12, 1984], [12, 1984], // 000000010010x
  35205. [12, 2048], [12, 2048], // 000000010011x
  35206. [12, 2112], [12, 2112], // 000000010100x
  35207. [12, 2176], [12, 2176], // 000000010101x
  35208. [12, 2240], [12, 2240], // 000000010110x
  35209. [12, 2304], [12, 2304], // 000000010111x
  35210. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  35211. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  35212. [12, 2368], [12, 2368], // 000000011100x
  35213. [12, 2432], [12, 2432], // 000000011101x
  35214. [12, 2496], [12, 2496], // 000000011110x
  35215. [12, 2560], [12, 2560], // 000000011111x
  35216. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  35217. [10, 18], [10, 18], [10, 18], [10, 18],
  35218. [12, 52], [12, 52], // 000000100100x
  35219. [13, 640], // 0000001001010
  35220. [13, 704], // 0000001001011
  35221. [13, 768], // 0000001001100
  35222. [13, 832], // 0000001001101
  35223. [12, 55], [12, 55], // 000000100111x
  35224. [12, 56], [12, 56], // 000000101000x
  35225. [13, 1280], // 0000001010010
  35226. [13, 1344], // 0000001010011
  35227. [13, 1408], // 0000001010100
  35228. [13, 1472], // 0000001010101
  35229. [12, 59], [12, 59], // 000000101011x
  35230. [12, 60], [12, 60], // 000000101100x
  35231. [13, 1536], // 0000001011010
  35232. [13, 1600], // 0000001011011
  35233. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  35234. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  35235. [13, 1664], // 0000001100100
  35236. [13, 1728], // 0000001100101
  35237. [12, 320], [12, 320], // 000000110011x
  35238. [12, 384], [12, 384], // 000000110100x
  35239. [12, 448], [12, 448], // 000000110101x
  35240. [13, 512], // 0000001101100
  35241. [13, 576], // 0000001101101
  35242. [12, 53], [12, 53], // 000000110111x
  35243. [12, 54], [12, 54], // 000000111000x
  35244. [13, 896], // 0000001110010
  35245. [13, 960], // 0000001110011
  35246. [13, 1024], // 0000001110100
  35247. [13, 1088], // 0000001110101
  35248. [13, 1152], // 0000001110110
  35249. [13, 1216], // 0000001110111
  35250. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  35251. [10, 64], [10, 64], [10, 64], [10, 64]
  35252. ];
  35253. var blackTable2 = [
  35254. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  35255. [8, 13], [8, 13], [8, 13], [8, 13],
  35256. [8, 13], [8, 13], [8, 13], [8, 13],
  35257. [8, 13], [8, 13], [8, 13], [8, 13],
  35258. [11, 23], [11, 23], // 00000101000x
  35259. [12, 50], // 000001010010
  35260. [12, 51], // 000001010011
  35261. [12, 44], // 000001010100
  35262. [12, 45], // 000001010101
  35263. [12, 46], // 000001010110
  35264. [12, 47], // 000001010111
  35265. [12, 57], // 000001011000
  35266. [12, 58], // 000001011001
  35267. [12, 61], // 000001011010
  35268. [12, 256], // 000001011011
  35269. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  35270. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  35271. [12, 48], // 000001100100
  35272. [12, 49], // 000001100101
  35273. [12, 62], // 000001100110
  35274. [12, 63], // 000001100111
  35275. [12, 30], // 000001101000
  35276. [12, 31], // 000001101001
  35277. [12, 32], // 000001101010
  35278. [12, 33], // 000001101011
  35279. [12, 40], // 000001101100
  35280. [12, 41], // 000001101101
  35281. [11, 22], [11, 22], // 00000110111x
  35282. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  35283. [8, 14], [8, 14], [8, 14], [8, 14],
  35284. [8, 14], [8, 14], [8, 14], [8, 14],
  35285. [8, 14], [8, 14], [8, 14], [8, 14],
  35286. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  35287. [7, 10], [7, 10], [7, 10], [7, 10],
  35288. [7, 10], [7, 10], [7, 10], [7, 10],
  35289. [7, 10], [7, 10], [7, 10], [7, 10],
  35290. [7, 10], [7, 10], [7, 10], [7, 10],
  35291. [7, 10], [7, 10], [7, 10], [7, 10],
  35292. [7, 10], [7, 10], [7, 10], [7, 10],
  35293. [7, 10], [7, 10], [7, 10], [7, 10],
  35294. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  35295. [7, 11], [7, 11], [7, 11], [7, 11],
  35296. [7, 11], [7, 11], [7, 11], [7, 11],
  35297. [7, 11], [7, 11], [7, 11], [7, 11],
  35298. [7, 11], [7, 11], [7, 11], [7, 11],
  35299. [7, 11], [7, 11], [7, 11], [7, 11],
  35300. [7, 11], [7, 11], [7, 11], [7, 11],
  35301. [7, 11], [7, 11], [7, 11], [7, 11],
  35302. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  35303. [9, 15], [9, 15], [9, 15], [9, 15],
  35304. [12, 128], // 000011001000
  35305. [12, 192], // 000011001001
  35306. [12, 26], // 000011001010
  35307. [12, 27], // 000011001011
  35308. [12, 28], // 000011001100
  35309. [12, 29], // 000011001101
  35310. [11, 19], [11, 19], // 00001100111x
  35311. [11, 20], [11, 20], // 00001101000x
  35312. [12, 34], // 000011010010
  35313. [12, 35], // 000011010011
  35314. [12, 36], // 000011010100
  35315. [12, 37], // 000011010101
  35316. [12, 38], // 000011010110
  35317. [12, 39], // 000011010111
  35318. [11, 21], [11, 21], // 00001101100x
  35319. [12, 42], // 000011011010
  35320. [12, 43], // 000011011011
  35321. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  35322. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  35323. [7, 12], [7, 12], [7, 12], [7, 12],
  35324. [7, 12], [7, 12], [7, 12], [7, 12],
  35325. [7, 12], [7, 12], [7, 12], [7, 12],
  35326. [7, 12], [7, 12], [7, 12], [7, 12],
  35327. [7, 12], [7, 12], [7, 12], [7, 12],
  35328. [7, 12], [7, 12], [7, 12], [7, 12],
  35329. [7, 12], [7, 12], [7, 12], [7, 12]
  35330. ];
  35331. var blackTable3 = [
  35332. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  35333. [6, 9], // 000100
  35334. [6, 8], // 000101
  35335. [5, 7], [5, 7], // 00011x
  35336. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  35337. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  35338. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  35339. [3, 1], [3, 1], [3, 1], [3, 1],
  35340. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  35341. [3, 4], [3, 4], [3, 4], [3, 4],
  35342. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  35343. [2, 3], [2, 3], [2, 3], [2, 3],
  35344. [2, 3], [2, 3], [2, 3], [2, 3],
  35345. [2, 3], [2, 3], [2, 3], [2, 3],
  35346. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  35347. [2, 2], [2, 2], [2, 2], [2, 2],
  35348. [2, 2], [2, 2], [2, 2], [2, 2],
  35349. [2, 2], [2, 2], [2, 2], [2, 2]
  35350. ];
  35351. function CCITTFaxStream(str, maybeLength, params) {
  35352. this.str = str;
  35353. this.dict = str.dict;
  35354. params = params || Dict.empty;
  35355. this.encoding = params.get('K') || 0;
  35356. this.eoline = params.get('EndOfLine') || false;
  35357. this.byteAlign = params.get('EncodedByteAlign') || false;
  35358. this.columns = params.get('Columns') || 1728;
  35359. this.rows = params.get('Rows') || 0;
  35360. var eoblock = params.get('EndOfBlock');
  35361. if (eoblock === null || eoblock === undefined) {
  35362. eoblock = true;
  35363. }
  35364. this.eoblock = eoblock;
  35365. this.black = params.get('BlackIs1') || false;
  35366. this.codingLine = new Uint32Array(this.columns + 1);
  35367. this.refLine = new Uint32Array(this.columns + 2);
  35368. this.codingLine[0] = this.columns;
  35369. this.codingPos = 0;
  35370. this.row = 0;
  35371. this.nextLine2D = this.encoding < 0;
  35372. this.inputBits = 0;
  35373. this.inputBuf = 0;
  35374. this.outputBits = 0;
  35375. var code1;
  35376. while ((code1 = this.lookBits(12)) === 0) {
  35377. this.eatBits(1);
  35378. }
  35379. if (code1 === 1) {
  35380. this.eatBits(12);
  35381. }
  35382. if (this.encoding > 0) {
  35383. this.nextLine2D = !this.lookBits(1);
  35384. this.eatBits(1);
  35385. }
  35386. DecodeStream.call(this, maybeLength);
  35387. }
  35388. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  35389. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  35390. while (!this.eof) {
  35391. var c = this.lookChar();
  35392. this.ensureBuffer(this.bufferLength + 1);
  35393. this.buffer[this.bufferLength++] = c;
  35394. }
  35395. };
  35396. CCITTFaxStream.prototype.addPixels =
  35397. function ccittFaxStreamAddPixels(a1, blackPixels) {
  35398. var codingLine = this.codingLine;
  35399. var codingPos = this.codingPos;
  35400. if (a1 > codingLine[codingPos]) {
  35401. if (a1 > this.columns) {
  35402. info('row is wrong length');
  35403. this.err = true;
  35404. a1 = this.columns;
  35405. }
  35406. if ((codingPos & 1) ^ blackPixels) {
  35407. ++codingPos;
  35408. }
  35409. codingLine[codingPos] = a1;
  35410. }
  35411. this.codingPos = codingPos;
  35412. };
  35413. CCITTFaxStream.prototype.addPixelsNeg =
  35414. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  35415. var codingLine = this.codingLine;
  35416. var codingPos = this.codingPos;
  35417. if (a1 > codingLine[codingPos]) {
  35418. if (a1 > this.columns) {
  35419. info('row is wrong length');
  35420. this.err = true;
  35421. a1 = this.columns;
  35422. }
  35423. if ((codingPos & 1) ^ blackPixels) {
  35424. ++codingPos;
  35425. }
  35426. codingLine[codingPos] = a1;
  35427. } else if (a1 < codingLine[codingPos]) {
  35428. if (a1 < 0) {
  35429. info('invalid code');
  35430. this.err = true;
  35431. a1 = 0;
  35432. }
  35433. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  35434. --codingPos;
  35435. }
  35436. codingLine[codingPos] = a1;
  35437. }
  35438. this.codingPos = codingPos;
  35439. };
  35440. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  35441. var refLine = this.refLine;
  35442. var codingLine = this.codingLine;
  35443. var columns = this.columns;
  35444. var refPos, blackPixels, bits, i;
  35445. if (this.outputBits === 0) {
  35446. if (this.eof) {
  35447. return null;
  35448. }
  35449. this.err = false;
  35450. var code1, code2, code3;
  35451. if (this.nextLine2D) {
  35452. for (i = 0; codingLine[i] < columns; ++i) {
  35453. refLine[i] = codingLine[i];
  35454. }
  35455. refLine[i++] = columns;
  35456. refLine[i] = columns;
  35457. codingLine[0] = 0;
  35458. this.codingPos = 0;
  35459. refPos = 0;
  35460. blackPixels = 0;
  35461. while (codingLine[this.codingPos] < columns) {
  35462. code1 = this.getTwoDimCode();
  35463. switch (code1) {
  35464. case twoDimPass:
  35465. this.addPixels(refLine[refPos + 1], blackPixels);
  35466. if (refLine[refPos + 1] < columns) {
  35467. refPos += 2;
  35468. }
  35469. break;
  35470. case twoDimHoriz:
  35471. code1 = code2 = 0;
  35472. if (blackPixels) {
  35473. do {
  35474. code1 += (code3 = this.getBlackCode());
  35475. } while (code3 >= 64);
  35476. do {
  35477. code2 += (code3 = this.getWhiteCode());
  35478. } while (code3 >= 64);
  35479. } else {
  35480. do {
  35481. code1 += (code3 = this.getWhiteCode());
  35482. } while (code3 >= 64);
  35483. do {
  35484. code2 += (code3 = this.getBlackCode());
  35485. } while (code3 >= 64);
  35486. }
  35487. this.addPixels(codingLine[this.codingPos] +
  35488. code1, blackPixels);
  35489. if (codingLine[this.codingPos] < columns) {
  35490. this.addPixels(codingLine[this.codingPos] + code2,
  35491. blackPixels ^ 1);
  35492. }
  35493. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35494. refLine[refPos] < columns) {
  35495. refPos += 2;
  35496. }
  35497. break;
  35498. case twoDimVertR3:
  35499. this.addPixels(refLine[refPos] + 3, blackPixels);
  35500. blackPixels ^= 1;
  35501. if (codingLine[this.codingPos] < columns) {
  35502. ++refPos;
  35503. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35504. refLine[refPos] < columns) {
  35505. refPos += 2;
  35506. }
  35507. }
  35508. break;
  35509. case twoDimVertR2:
  35510. this.addPixels(refLine[refPos] + 2, blackPixels);
  35511. blackPixels ^= 1;
  35512. if (codingLine[this.codingPos] < columns) {
  35513. ++refPos;
  35514. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35515. refLine[refPos] < columns) {
  35516. refPos += 2;
  35517. }
  35518. }
  35519. break;
  35520. case twoDimVertR1:
  35521. this.addPixels(refLine[refPos] + 1, blackPixels);
  35522. blackPixels ^= 1;
  35523. if (codingLine[this.codingPos] < columns) {
  35524. ++refPos;
  35525. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35526. refLine[refPos] < columns) {
  35527. refPos += 2;
  35528. }
  35529. }
  35530. break;
  35531. case twoDimVert0:
  35532. this.addPixels(refLine[refPos], blackPixels);
  35533. blackPixels ^= 1;
  35534. if (codingLine[this.codingPos] < columns) {
  35535. ++refPos;
  35536. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35537. refLine[refPos] < columns) {
  35538. refPos += 2;
  35539. }
  35540. }
  35541. break;
  35542. case twoDimVertL3:
  35543. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  35544. blackPixels ^= 1;
  35545. if (codingLine[this.codingPos] < columns) {
  35546. if (refPos > 0) {
  35547. --refPos;
  35548. } else {
  35549. ++refPos;
  35550. }
  35551. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35552. refLine[refPos] < columns) {
  35553. refPos += 2;
  35554. }
  35555. }
  35556. break;
  35557. case twoDimVertL2:
  35558. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  35559. blackPixels ^= 1;
  35560. if (codingLine[this.codingPos] < columns) {
  35561. if (refPos > 0) {
  35562. --refPos;
  35563. } else {
  35564. ++refPos;
  35565. }
  35566. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35567. refLine[refPos] < columns) {
  35568. refPos += 2;
  35569. }
  35570. }
  35571. break;
  35572. case twoDimVertL1:
  35573. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  35574. blackPixels ^= 1;
  35575. if (codingLine[this.codingPos] < columns) {
  35576. if (refPos > 0) {
  35577. --refPos;
  35578. } else {
  35579. ++refPos;
  35580. }
  35581. while (refLine[refPos] <= codingLine[this.codingPos] &&
  35582. refLine[refPos] < columns) {
  35583. refPos += 2;
  35584. }
  35585. }
  35586. break;
  35587. case EOF:
  35588. this.addPixels(columns, 0);
  35589. this.eof = true;
  35590. break;
  35591. default:
  35592. info('bad 2d code');
  35593. this.addPixels(columns, 0);
  35594. this.err = true;
  35595. }
  35596. }
  35597. } else {
  35598. codingLine[0] = 0;
  35599. this.codingPos = 0;
  35600. blackPixels = 0;
  35601. while (codingLine[this.codingPos] < columns) {
  35602. code1 = 0;
  35603. if (blackPixels) {
  35604. do {
  35605. code1 += (code3 = this.getBlackCode());
  35606. } while (code3 >= 64);
  35607. } else {
  35608. do {
  35609. code1 += (code3 = this.getWhiteCode());
  35610. } while (code3 >= 64);
  35611. }
  35612. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  35613. blackPixels ^= 1;
  35614. }
  35615. }
  35616. var gotEOL = false;
  35617. if (!this.eoblock && this.row === this.rows - 1) {
  35618. this.eof = true;
  35619. } else if (this.eoline || !this.byteAlign) {
  35620. code1 = this.lookBits(12);
  35621. if (this.eoline) {
  35622. while (code1 !== EOF && code1 !== 1) {
  35623. this.eatBits(1);
  35624. code1 = this.lookBits(12);
  35625. }
  35626. } else {
  35627. while (code1 === 0) {
  35628. this.eatBits(1);
  35629. code1 = this.lookBits(12);
  35630. }
  35631. }
  35632. if (code1 === 1) {
  35633. this.eatBits(12);
  35634. gotEOL = true;
  35635. } else if (code1 === EOF) {
  35636. this.eof = true;
  35637. }
  35638. }
  35639. if (this.byteAlign && !gotEOL) {
  35640. this.inputBits &= ~7;
  35641. }
  35642. if (!this.eof && this.encoding > 0) {
  35643. this.nextLine2D = !this.lookBits(1);
  35644. this.eatBits(1);
  35645. }
  35646. if (this.eoblock && gotEOL && this.byteAlign) {
  35647. code1 = this.lookBits(12);
  35648. if (code1 === 1) {
  35649. this.eatBits(12);
  35650. if (this.encoding > 0) {
  35651. this.lookBits(1);
  35652. this.eatBits(1);
  35653. }
  35654. if (this.encoding >= 0) {
  35655. for (i = 0; i < 4; ++i) {
  35656. code1 = this.lookBits(12);
  35657. if (code1 !== 1) {
  35658. info('bad rtc code: ' + code1);
  35659. }
  35660. this.eatBits(12);
  35661. if (this.encoding > 0) {
  35662. this.lookBits(1);
  35663. this.eatBits(1);
  35664. }
  35665. }
  35666. }
  35667. this.eof = true;
  35668. }
  35669. } else if (this.err && this.eoline) {
  35670. while (true) {
  35671. code1 = this.lookBits(13);
  35672. if (code1 === EOF) {
  35673. this.eof = true;
  35674. return null;
  35675. }
  35676. if ((code1 >> 1) === 1) {
  35677. break;
  35678. }
  35679. this.eatBits(1);
  35680. }
  35681. this.eatBits(12);
  35682. if (this.encoding > 0) {
  35683. this.eatBits(1);
  35684. this.nextLine2D = !(code1 & 1);
  35685. }
  35686. }
  35687. if (codingLine[0] > 0) {
  35688. this.outputBits = codingLine[this.codingPos = 0];
  35689. } else {
  35690. this.outputBits = codingLine[this.codingPos = 1];
  35691. }
  35692. this.row++;
  35693. }
  35694. var c;
  35695. if (this.outputBits >= 8) {
  35696. c = (this.codingPos & 1) ? 0 : 0xFF;
  35697. this.outputBits -= 8;
  35698. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  35699. this.codingPos++;
  35700. this.outputBits = (codingLine[this.codingPos] -
  35701. codingLine[this.codingPos - 1]);
  35702. }
  35703. } else {
  35704. bits = 8;
  35705. c = 0;
  35706. do {
  35707. if (this.outputBits > bits) {
  35708. c <<= bits;
  35709. if (!(this.codingPos & 1)) {
  35710. c |= 0xFF >> (8 - bits);
  35711. }
  35712. this.outputBits -= bits;
  35713. bits = 0;
  35714. } else {
  35715. c <<= this.outputBits;
  35716. if (!(this.codingPos & 1)) {
  35717. c |= 0xFF >> (8 - this.outputBits);
  35718. }
  35719. bits -= this.outputBits;
  35720. this.outputBits = 0;
  35721. if (codingLine[this.codingPos] < columns) {
  35722. this.codingPos++;
  35723. this.outputBits = (codingLine[this.codingPos] -
  35724. codingLine[this.codingPos - 1]);
  35725. } else if (bits > 0) {
  35726. c <<= bits;
  35727. bits = 0;
  35728. }
  35729. }
  35730. } while (bits);
  35731. }
  35732. if (this.black) {
  35733. c ^= 0xFF;
  35734. }
  35735. return c;
  35736. };
  35737. // This functions returns the code found from the table.
  35738. // The start and end parameters set the boundaries for searching the table.
  35739. // The limit parameter is optional. Function returns an array with three
  35740. // values. The first array element indicates whether a valid code is being
  35741. // returned. The second array element is the actual code. The third array
  35742. // element indicates whether EOF was reached.
  35743. CCITTFaxStream.prototype.findTableCode =
  35744. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  35745. var limitValue = limit || 0;
  35746. for (var i = start; i <= end; ++i) {
  35747. var code = this.lookBits(i);
  35748. if (code === EOF) {
  35749. return [true, 1, false];
  35750. }
  35751. if (i < end) {
  35752. code <<= end - i;
  35753. }
  35754. if (!limitValue || code >= limitValue) {
  35755. var p = table[code - limitValue];
  35756. if (p[0] === i) {
  35757. this.eatBits(i);
  35758. return [true, p[1], true];
  35759. }
  35760. }
  35761. }
  35762. return [false, 0, false];
  35763. };
  35764. CCITTFaxStream.prototype.getTwoDimCode =
  35765. function ccittFaxStreamGetTwoDimCode() {
  35766. var code = 0;
  35767. var p;
  35768. if (this.eoblock) {
  35769. code = this.lookBits(7);
  35770. p = twoDimTable[code];
  35771. if (p && p[0] > 0) {
  35772. this.eatBits(p[0]);
  35773. return p[1];
  35774. }
  35775. } else {
  35776. var result = this.findTableCode(1, 7, twoDimTable);
  35777. if (result[0] && result[2]) {
  35778. return result[1];
  35779. }
  35780. }
  35781. info('Bad two dim code');
  35782. return EOF;
  35783. };
  35784. CCITTFaxStream.prototype.getWhiteCode =
  35785. function ccittFaxStreamGetWhiteCode() {
  35786. var code = 0;
  35787. var p;
  35788. if (this.eoblock) {
  35789. code = this.lookBits(12);
  35790. if (code === EOF) {
  35791. return 1;
  35792. }
  35793. if ((code >> 5) === 0) {
  35794. p = whiteTable1[code];
  35795. } else {
  35796. p = whiteTable2[code >> 3];
  35797. }
  35798. if (p[0] > 0) {
  35799. this.eatBits(p[0]);
  35800. return p[1];
  35801. }
  35802. } else {
  35803. var result = this.findTableCode(1, 9, whiteTable2);
  35804. if (result[0]) {
  35805. return result[1];
  35806. }
  35807. result = this.findTableCode(11, 12, whiteTable1);
  35808. if (result[0]) {
  35809. return result[1];
  35810. }
  35811. }
  35812. info('bad white code');
  35813. this.eatBits(1);
  35814. return 1;
  35815. };
  35816. CCITTFaxStream.prototype.getBlackCode =
  35817. function ccittFaxStreamGetBlackCode() {
  35818. var code, p;
  35819. if (this.eoblock) {
  35820. code = this.lookBits(13);
  35821. if (code === EOF) {
  35822. return 1;
  35823. }
  35824. if ((code >> 7) === 0) {
  35825. p = blackTable1[code];
  35826. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  35827. p = blackTable2[(code >> 1) - 64];
  35828. } else {
  35829. p = blackTable3[code >> 7];
  35830. }
  35831. if (p[0] > 0) {
  35832. this.eatBits(p[0]);
  35833. return p[1];
  35834. }
  35835. } else {
  35836. var result = this.findTableCode(2, 6, blackTable3);
  35837. if (result[0]) {
  35838. return result[1];
  35839. }
  35840. result = this.findTableCode(7, 12, blackTable2, 64);
  35841. if (result[0]) {
  35842. return result[1];
  35843. }
  35844. result = this.findTableCode(10, 13, blackTable1);
  35845. if (result[0]) {
  35846. return result[1];
  35847. }
  35848. }
  35849. info('bad black code');
  35850. this.eatBits(1);
  35851. return 1;
  35852. };
  35853. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  35854. var c;
  35855. while (this.inputBits < n) {
  35856. if ((c = this.str.getByte()) === -1) {
  35857. if (this.inputBits === 0) {
  35858. return EOF;
  35859. }
  35860. return ((this.inputBuf << (n - this.inputBits)) &
  35861. (0xFFFF >> (16 - n)));
  35862. }
  35863. this.inputBuf = (this.inputBuf << 8) + c;
  35864. this.inputBits += 8;
  35865. }
  35866. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  35867. };
  35868. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  35869. if ((this.inputBits -= n) < 0) {
  35870. this.inputBits = 0;
  35871. }
  35872. };
  35873. return CCITTFaxStream;
  35874. })();
  35875. var LZWStream = (function LZWStreamClosure() {
  35876. function LZWStream(str, maybeLength, earlyChange) {
  35877. this.str = str;
  35878. this.dict = str.dict;
  35879. this.cachedData = 0;
  35880. this.bitsCached = 0;
  35881. var maxLzwDictionarySize = 4096;
  35882. var lzwState = {
  35883. earlyChange: earlyChange,
  35884. codeLength: 9,
  35885. nextCode: 258,
  35886. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  35887. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  35888. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  35889. currentSequence: new Uint8Array(maxLzwDictionarySize),
  35890. currentSequenceLength: 0
  35891. };
  35892. for (var i = 0; i < 256; ++i) {
  35893. lzwState.dictionaryValues[i] = i;
  35894. lzwState.dictionaryLengths[i] = 1;
  35895. }
  35896. this.lzwState = lzwState;
  35897. DecodeStream.call(this, maybeLength);
  35898. }
  35899. LZWStream.prototype = Object.create(DecodeStream.prototype);
  35900. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  35901. var bitsCached = this.bitsCached;
  35902. var cachedData = this.cachedData;
  35903. while (bitsCached < n) {
  35904. var c = this.str.getByte();
  35905. if (c === -1) {
  35906. this.eof = true;
  35907. return null;
  35908. }
  35909. cachedData = (cachedData << 8) | c;
  35910. bitsCached += 8;
  35911. }
  35912. this.bitsCached = (bitsCached -= n);
  35913. this.cachedData = cachedData;
  35914. this.lastCode = null;
  35915. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  35916. };
  35917. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  35918. var blockSize = 512;
  35919. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  35920. var i, j, q;
  35921. var lzwState = this.lzwState;
  35922. if (!lzwState) {
  35923. return; // eof was found
  35924. }
  35925. var earlyChange = lzwState.earlyChange;
  35926. var nextCode = lzwState.nextCode;
  35927. var dictionaryValues = lzwState.dictionaryValues;
  35928. var dictionaryLengths = lzwState.dictionaryLengths;
  35929. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  35930. var codeLength = lzwState.codeLength;
  35931. var prevCode = lzwState.prevCode;
  35932. var currentSequence = lzwState.currentSequence;
  35933. var currentSequenceLength = lzwState.currentSequenceLength;
  35934. var decodedLength = 0;
  35935. var currentBufferLength = this.bufferLength;
  35936. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  35937. for (i = 0; i < blockSize; i++) {
  35938. var code = this.readBits(codeLength);
  35939. var hasPrev = currentSequenceLength > 0;
  35940. if (code < 256) {
  35941. currentSequence[0] = code;
  35942. currentSequenceLength = 1;
  35943. } else if (code >= 258) {
  35944. if (code < nextCode) {
  35945. currentSequenceLength = dictionaryLengths[code];
  35946. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  35947. currentSequence[j] = dictionaryValues[q];
  35948. q = dictionaryPrevCodes[q];
  35949. }
  35950. } else {
  35951. currentSequence[currentSequenceLength++] = currentSequence[0];
  35952. }
  35953. } else if (code === 256) {
  35954. codeLength = 9;
  35955. nextCode = 258;
  35956. currentSequenceLength = 0;
  35957. continue;
  35958. } else {
  35959. this.eof = true;
  35960. delete this.lzwState;
  35961. break;
  35962. }
  35963. if (hasPrev) {
  35964. dictionaryPrevCodes[nextCode] = prevCode;
  35965. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  35966. dictionaryValues[nextCode] = currentSequence[0];
  35967. nextCode++;
  35968. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  35969. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  35970. 0.6931471805599453 + 1, 12) | 0;
  35971. }
  35972. prevCode = code;
  35973. decodedLength += currentSequenceLength;
  35974. if (estimatedDecodedSize < decodedLength) {
  35975. do {
  35976. estimatedDecodedSize += decodedSizeDelta;
  35977. } while (estimatedDecodedSize < decodedLength);
  35978. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  35979. }
  35980. for (j = 0; j < currentSequenceLength; j++) {
  35981. buffer[currentBufferLength++] = currentSequence[j];
  35982. }
  35983. }
  35984. lzwState.nextCode = nextCode;
  35985. lzwState.codeLength = codeLength;
  35986. lzwState.prevCode = prevCode;
  35987. lzwState.currentSequenceLength = currentSequenceLength;
  35988. this.bufferLength = currentBufferLength;
  35989. };
  35990. return LZWStream;
  35991. })();
  35992. var NullStream = (function NullStreamClosure() {
  35993. function NullStream() {
  35994. Stream.call(this, new Uint8Array(0));
  35995. }
  35996. NullStream.prototype = Stream.prototype;
  35997. return NullStream;
  35998. })();
  35999. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  36000. setup: function wphSetup(handler) {
  36001. var pdfManager;
  36002. function loadDocument(recoveryMode) {
  36003. var loadDocumentCapability = createPromiseCapability();
  36004. var parseSuccess = function parseSuccess() {
  36005. var numPagesPromise = pdfManager.ensureDoc('numPages');
  36006. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  36007. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  36008. Promise.all([numPagesPromise, fingerprintPromise,
  36009. encryptedPromise]).then(function onDocReady(results) {
  36010. var doc = {
  36011. numPages: results[0],
  36012. fingerprint: results[1],
  36013. encrypted: !!results[2],
  36014. };
  36015. loadDocumentCapability.resolve(doc);
  36016. },
  36017. parseFailure);
  36018. };
  36019. var parseFailure = function parseFailure(e) {
  36020. loadDocumentCapability.reject(e);
  36021. };
  36022. pdfManager.ensureDoc('checkHeader', []).then(function() {
  36023. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  36024. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  36025. parseSuccess, parseFailure);
  36026. }, parseFailure);
  36027. }, parseFailure);
  36028. return loadDocumentCapability.promise;
  36029. }
  36030. function getPdfManager(data) {
  36031. var pdfManagerCapability = createPromiseCapability();
  36032. var source = data.source;
  36033. var disableRange = data.disableRange;
  36034. if (source.data) {
  36035. try {
  36036. pdfManager = new LocalPdfManager(source.data, source.password);
  36037. pdfManagerCapability.resolve();
  36038. } catch (ex) {
  36039. pdfManagerCapability.reject(ex);
  36040. }
  36041. return pdfManagerCapability.promise;
  36042. } else if (source.chunkedViewerLoading) {
  36043. try {
  36044. pdfManager = new NetworkPdfManager(source, handler);
  36045. pdfManagerCapability.resolve();
  36046. } catch (ex) {
  36047. pdfManagerCapability.reject(ex);
  36048. }
  36049. return pdfManagerCapability.promise;
  36050. }
  36051. var networkManager = new NetworkManager(source.url, {
  36052. httpHeaders: source.httpHeaders,
  36053. withCredentials: source.withCredentials
  36054. });
  36055. var fullRequestXhrId = networkManager.requestFull({
  36056. onHeadersReceived: function onHeadersReceived() {
  36057. if (disableRange) {
  36058. return;
  36059. }
  36060. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  36061. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  36062. return;
  36063. }
  36064. var contentEncoding =
  36065. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  36066. if (contentEncoding !== 'identity') {
  36067. return;
  36068. }
  36069. var length = fullRequestXhr.getResponseHeader('Content-Length');
  36070. length = parseInt(length, 10);
  36071. if (!isInt(length)) {
  36072. return;
  36073. }
  36074. source.length = length;
  36075. if (length <= 2 * RANGE_CHUNK_SIZE) {
  36076. // The file size is smaller than the size of two chunks, so it does
  36077. // not make any sense to abort the request and retry with a range
  36078. // request.
  36079. return;
  36080. }
  36081. // NOTE: by cancelling the full request, and then issuing range
  36082. // requests, there will be an issue for sites where you can only
  36083. // request the pdf once. However, if this is the case, then the
  36084. // server should not be returning that it can support range requests.
  36085. networkManager.abortRequest(fullRequestXhrId);
  36086. try {
  36087. pdfManager = new NetworkPdfManager(source, handler);
  36088. pdfManagerCapability.resolve(pdfManager);
  36089. } catch (ex) {
  36090. pdfManagerCapability.reject(ex);
  36091. }
  36092. },
  36093. onDone: function onDone(args) {
  36094. // the data is array, instantiating directly from it
  36095. try {
  36096. pdfManager = new LocalPdfManager(args.chunk, source.password);
  36097. pdfManagerCapability.resolve();
  36098. } catch (ex) {
  36099. pdfManagerCapability.reject(ex);
  36100. }
  36101. },
  36102. onError: function onError(status) {
  36103. if (status === 404) {
  36104. var exception = new MissingPDFException('Missing PDF "' +
  36105. source.url + '".');
  36106. handler.send('MissingPDF', { exception: exception });
  36107. } else {
  36108. handler.send('DocError', 'Unexpected server response (' +
  36109. status + ') while retrieving PDF "' +
  36110. source.url + '".');
  36111. }
  36112. },
  36113. onProgress: function onProgress(evt) {
  36114. handler.send('DocProgress', {
  36115. loaded: evt.loaded,
  36116. total: evt.lengthComputable ? evt.total : source.length
  36117. });
  36118. }
  36119. });
  36120. return pdfManagerCapability.promise;
  36121. }
  36122. handler.on('test', function wphSetupTest(data) {
  36123. // check if Uint8Array can be sent to worker
  36124. if (!(data instanceof Uint8Array)) {
  36125. handler.send('test', false);
  36126. return;
  36127. }
  36128. // making sure postMessage transfers are working
  36129. var supportTransfers = data[0] === 255;
  36130. handler.postMessageTransfers = supportTransfers;
  36131. // check if the response property is supported by xhr
  36132. var xhr = new XMLHttpRequest();
  36133. var responseExists = 'response' in xhr;
  36134. // check if the property is actually implemented
  36135. try {
  36136. var dummy = xhr.responseType;
  36137. } catch (e) {
  36138. responseExists = false;
  36139. }
  36140. if (!responseExists) {
  36141. handler.send('test', false);
  36142. return;
  36143. }
  36144. handler.send('test', {
  36145. supportTypedArray: true,
  36146. supportTransfers: supportTransfers
  36147. });
  36148. });
  36149. handler.on('GetDocRequest', function wphSetupDoc(data) {
  36150. var onSuccess = function(doc) {
  36151. handler.send('GetDoc', { pdfInfo: doc });
  36152. };
  36153. var onFailure = function(e) {
  36154. if (e instanceof PasswordException) {
  36155. if (e.code === PasswordResponses.NEED_PASSWORD) {
  36156. handler.send('NeedPassword', {
  36157. exception: e
  36158. });
  36159. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  36160. handler.send('IncorrectPassword', {
  36161. exception: e
  36162. });
  36163. }
  36164. } else if (e instanceof InvalidPDFException) {
  36165. handler.send('InvalidPDF', {
  36166. exception: e
  36167. });
  36168. } else if (e instanceof MissingPDFException) {
  36169. handler.send('MissingPDF', {
  36170. exception: e
  36171. });
  36172. } else {
  36173. handler.send('UnknownError', {
  36174. exception: new UnknownErrorException(e.message, e.toString())
  36175. });
  36176. }
  36177. };
  36178. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  36179. -1 : data.maxImageSize;
  36180. PDFJS.disableFontFace = data.disableFontFace;
  36181. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  36182. PDFJS.verbosity = data.verbosity;
  36183. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  36184. null : data.cMapUrl;
  36185. PDFJS.cMapPacked = data.cMapPacked === true;
  36186. getPdfManager(data).then(function () {
  36187. pdfManager.onLoadedStream().then(function(stream) {
  36188. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  36189. });
  36190. }).then(function pdfManagerReady() {
  36191. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  36192. // Try again with recoveryMode == true
  36193. if (!(ex instanceof XRefParseException)) {
  36194. if (ex instanceof PasswordException) {
  36195. // after password exception prepare to receive a new password
  36196. // to repeat loading
  36197. pdfManager.passwordChanged().then(pdfManagerReady);
  36198. }
  36199. onFailure(ex);
  36200. return;
  36201. }
  36202. pdfManager.requestLoadedStream();
  36203. pdfManager.onLoadedStream().then(function() {
  36204. loadDocument(true).then(onSuccess, onFailure);
  36205. });
  36206. }, onFailure);
  36207. }, onFailure);
  36208. });
  36209. handler.on('GetPage', function wphSetupGetPage(data) {
  36210. return pdfManager.getPage(data.pageIndex).then(function(page) {
  36211. var rotatePromise = pdfManager.ensure(page, 'rotate');
  36212. var refPromise = pdfManager.ensure(page, 'ref');
  36213. var viewPromise = pdfManager.ensure(page, 'view');
  36214. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  36215. function(results) {
  36216. return {
  36217. rotate: results[0],
  36218. ref: results[1],
  36219. view: results[2]
  36220. };
  36221. });
  36222. });
  36223. });
  36224. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  36225. var ref = new Ref(data.ref.num, data.ref.gen);
  36226. var catalog = pdfManager.pdfDocument.catalog;
  36227. return catalog.getPageIndex(ref);
  36228. });
  36229. handler.on('GetDestinations',
  36230. function wphSetupGetDestinations(data) {
  36231. return pdfManager.ensureCatalog('destinations');
  36232. }
  36233. );
  36234. handler.on('GetAttachments',
  36235. function wphSetupGetAttachments(data) {
  36236. return pdfManager.ensureCatalog('attachments');
  36237. }
  36238. );
  36239. handler.on('GetJavaScript',
  36240. function wphSetupGetJavaScript(data) {
  36241. return pdfManager.ensureCatalog('javaScript');
  36242. }
  36243. );
  36244. handler.on('GetOutline',
  36245. function wphSetupGetOutline(data) {
  36246. return pdfManager.ensureCatalog('documentOutline');
  36247. }
  36248. );
  36249. handler.on('GetMetadata',
  36250. function wphSetupGetMetadata(data) {
  36251. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  36252. pdfManager.ensureCatalog('metadata')]);
  36253. }
  36254. );
  36255. handler.on('GetData', function wphSetupGetData(data) {
  36256. pdfManager.requestLoadedStream();
  36257. return pdfManager.onLoadedStream().then(function(stream) {
  36258. return stream.bytes;
  36259. });
  36260. });
  36261. handler.on('GetStats',
  36262. function wphSetupGetStats(data) {
  36263. return pdfManager.pdfDocument.xref.stats;
  36264. }
  36265. );
  36266. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  36267. pdfManager.updatePassword(data);
  36268. });
  36269. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  36270. return pdfManager.getPage(data.pageIndex).then(function(page) {
  36271. return pdfManager.ensure(page, 'getAnnotationsData', []);
  36272. });
  36273. });
  36274. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  36275. pdfManager.getPage(data.pageIndex).then(function(page) {
  36276. var pageNum = data.pageIndex + 1;
  36277. var start = Date.now();
  36278. // Pre compile the pdf page and fetch the fonts/images.
  36279. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  36280. info('page=' + pageNum + ' - getOperatorList: time=' +
  36281. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  36282. }, function(e) {
  36283. var minimumStackMessage =
  36284. 'worker.js: while trying to getPage() and getOperatorList()';
  36285. var wrappedException;
  36286. // Turn the error into an obj that can be serialized
  36287. if (typeof e === 'string') {
  36288. wrappedException = {
  36289. message: e,
  36290. stack: minimumStackMessage
  36291. };
  36292. } else if (typeof e === 'object') {
  36293. wrappedException = {
  36294. message: e.message || e.toString(),
  36295. stack: e.stack || minimumStackMessage
  36296. };
  36297. } else {
  36298. wrappedException = {
  36299. message: 'Unknown exception type: ' + (typeof e),
  36300. stack: minimumStackMessage
  36301. };
  36302. }
  36303. handler.send('PageError', {
  36304. pageNum: pageNum,
  36305. error: wrappedException,
  36306. intent: data.intent
  36307. });
  36308. });
  36309. });
  36310. }, this);
  36311. handler.on('GetTextContent', function wphExtractText(data) {
  36312. return pdfManager.getPage(data.pageIndex).then(function(page) {
  36313. var pageNum = data.pageIndex + 1;
  36314. var start = Date.now();
  36315. return page.extractTextContent().then(function(textContent) {
  36316. info('text indexing: page=' + pageNum + ' - time=' +
  36317. (Date.now() - start) + 'ms');
  36318. return textContent;
  36319. });
  36320. });
  36321. });
  36322. handler.on('Cleanup', function wphCleanup(data) {
  36323. return pdfManager.cleanup();
  36324. });
  36325. handler.on('Terminate', function wphTerminate(data) {
  36326. pdfManager.terminate();
  36327. });
  36328. }
  36329. };
  36330. var consoleTimer = {};
  36331. var workerConsole = {
  36332. log: function log() {
  36333. var args = Array.prototype.slice.call(arguments);
  36334. globalScope.postMessage({
  36335. action: 'console_log',
  36336. data: args
  36337. });
  36338. },
  36339. error: function error() {
  36340. var args = Array.prototype.slice.call(arguments);
  36341. globalScope.postMessage({
  36342. action: 'console_error',
  36343. data: args
  36344. });
  36345. throw 'pdf.js execution error';
  36346. },
  36347. time: function time(name) {
  36348. consoleTimer[name] = Date.now();
  36349. },
  36350. timeEnd: function timeEnd(name) {
  36351. var time = consoleTimer[name];
  36352. if (!time) {
  36353. error('Unknown timer name ' + name);
  36354. }
  36355. this.log('Timer:', name, Date.now() - time);
  36356. }
  36357. };
  36358. // Worker thread?
  36359. if (typeof window === 'undefined') {
  36360. if (!('console' in globalScope)) {
  36361. globalScope.console = workerConsole;
  36362. }
  36363. // Listen for unsupported features so we can pass them on to the main thread.
  36364. PDFJS.UnsupportedManager.listen(function (msg) {
  36365. globalScope.postMessage({
  36366. action: '_unsupported_feature',
  36367. data: msg
  36368. });
  36369. });
  36370. var handler = new MessageHandler('worker_processor', this);
  36371. WorkerMessageHandler.setup(handler);
  36372. }
  36373. /* This class implements the QM Coder decoding as defined in
  36374. * JPEG 2000 Part I Final Committee Draft Version 1.0
  36375. * Annex C.3 Arithmetic decoding procedure
  36376. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  36377. *
  36378. * The arithmetic decoder is used in conjunction with context models to decode
  36379. * JPEG2000 and JBIG2 streams.
  36380. */
  36381. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  36382. // Table C-2
  36383. var QeTable = [
  36384. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  36385. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  36386. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  36387. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  36388. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  36389. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  36390. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  36391. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  36392. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  36393. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  36394. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  36395. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  36396. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  36397. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  36398. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  36399. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  36400. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  36401. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  36402. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  36403. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  36404. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  36405. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  36406. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  36407. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  36408. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  36409. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  36410. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  36411. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  36412. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  36413. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  36414. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  36415. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  36416. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  36417. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  36418. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  36419. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  36420. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  36421. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  36422. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  36423. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  36424. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  36425. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  36426. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  36427. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  36428. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  36429. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  36430. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  36431. ];
  36432. // C.3.5 Initialisation of the decoder (INITDEC)
  36433. function ArithmeticDecoder(data, start, end) {
  36434. this.data = data;
  36435. this.bp = start;
  36436. this.dataEnd = end;
  36437. this.chigh = data[start];
  36438. this.clow = 0;
  36439. this.byteIn();
  36440. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  36441. this.clow = (this.clow << 7) & 0xFFFF;
  36442. this.ct -= 7;
  36443. this.a = 0x8000;
  36444. }
  36445. ArithmeticDecoder.prototype = {
  36446. // C.3.4 Compressed data input (BYTEIN)
  36447. byteIn: function ArithmeticDecoder_byteIn() {
  36448. var data = this.data;
  36449. var bp = this.bp;
  36450. if (data[bp] === 0xFF) {
  36451. var b1 = data[bp + 1];
  36452. if (b1 > 0x8F) {
  36453. this.clow += 0xFF00;
  36454. this.ct = 8;
  36455. } else {
  36456. bp++;
  36457. this.clow += (data[bp] << 9);
  36458. this.ct = 7;
  36459. this.bp = bp;
  36460. }
  36461. } else {
  36462. bp++;
  36463. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  36464. this.ct = 8;
  36465. this.bp = bp;
  36466. }
  36467. if (this.clow > 0xFFFF) {
  36468. this.chigh += (this.clow >> 16);
  36469. this.clow &= 0xFFFF;
  36470. }
  36471. },
  36472. // C.3.2 Decoding a decision (DECODE)
  36473. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  36474. // contexts are packed into 1 byte:
  36475. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  36476. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  36477. var qeTableIcx = QeTable[cx_index];
  36478. var qeIcx = qeTableIcx.qe;
  36479. var d;
  36480. var a = this.a - qeIcx;
  36481. if (this.chigh < qeIcx) {
  36482. // exchangeLps
  36483. if (a < qeIcx) {
  36484. a = qeIcx;
  36485. d = cx_mps;
  36486. cx_index = qeTableIcx.nmps;
  36487. } else {
  36488. a = qeIcx;
  36489. d = 1 ^ cx_mps;
  36490. if (qeTableIcx.switchFlag === 1) {
  36491. cx_mps = d;
  36492. }
  36493. cx_index = qeTableIcx.nlps;
  36494. }
  36495. } else {
  36496. this.chigh -= qeIcx;
  36497. if ((a & 0x8000) !== 0) {
  36498. this.a = a;
  36499. return cx_mps;
  36500. }
  36501. // exchangeMps
  36502. if (a < qeIcx) {
  36503. d = 1 ^ cx_mps;
  36504. if (qeTableIcx.switchFlag === 1) {
  36505. cx_mps = d;
  36506. }
  36507. cx_index = qeTableIcx.nlps;
  36508. } else {
  36509. d = cx_mps;
  36510. cx_index = qeTableIcx.nmps;
  36511. }
  36512. }
  36513. // C.3.3 renormD;
  36514. do {
  36515. if (this.ct === 0) {
  36516. this.byteIn();
  36517. }
  36518. a <<= 1;
  36519. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  36520. this.clow = (this.clow << 1) & 0xFFFF;
  36521. this.ct--;
  36522. } while ((a & 0x8000) === 0);
  36523. this.a = a;
  36524. contexts[pos] = cx_index << 1 | cx_mps;
  36525. return d;
  36526. }
  36527. };
  36528. return ArithmeticDecoder;
  36529. })();
  36530. var JpegImage = (function jpegImage() {
  36531. var dctZigZag = new Uint8Array([
  36532. 0,
  36533. 1, 8,
  36534. 16, 9, 2,
  36535. 3, 10, 17, 24,
  36536. 32, 25, 18, 11, 4,
  36537. 5, 12, 19, 26, 33, 40,
  36538. 48, 41, 34, 27, 20, 13, 6,
  36539. 7, 14, 21, 28, 35, 42, 49, 56,
  36540. 57, 50, 43, 36, 29, 22, 15,
  36541. 23, 30, 37, 44, 51, 58,
  36542. 59, 52, 45, 38, 31,
  36543. 39, 46, 53, 60,
  36544. 61, 54, 47,
  36545. 55, 62,
  36546. 63
  36547. ]);
  36548. var dctCos1 = 4017; // cos(pi/16)
  36549. var dctSin1 = 799; // sin(pi/16)
  36550. var dctCos3 = 3406; // cos(3*pi/16)
  36551. var dctSin3 = 2276; // sin(3*pi/16)
  36552. var dctCos6 = 1567; // cos(6*pi/16)
  36553. var dctSin6 = 3784; // sin(6*pi/16)
  36554. var dctSqrt2 = 5793; // sqrt(2)
  36555. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  36556. function constructor() {
  36557. }
  36558. function buildHuffmanTable(codeLengths, values) {
  36559. var k = 0, code = [], i, j, length = 16;
  36560. while (length > 0 && !codeLengths[length - 1]) {
  36561. length--;
  36562. }
  36563. code.push({children: [], index: 0});
  36564. var p = code[0], q;
  36565. for (i = 0; i < length; i++) {
  36566. for (j = 0; j < codeLengths[i]; j++) {
  36567. p = code.pop();
  36568. p.children[p.index] = values[k];
  36569. while (p.index > 0) {
  36570. p = code.pop();
  36571. }
  36572. p.index++;
  36573. code.push(p);
  36574. while (code.length <= i) {
  36575. code.push(q = {children: [], index: 0});
  36576. p.children[p.index] = q.children;
  36577. p = q;
  36578. }
  36579. k++;
  36580. }
  36581. if (i + 1 < length) {
  36582. // p here points to last code
  36583. code.push(q = {children: [], index: 0});
  36584. p.children[p.index] = q.children;
  36585. p = q;
  36586. }
  36587. }
  36588. return code[0].children;
  36589. }
  36590. function getBlockBufferOffset(component, row, col) {
  36591. return 64 * ((component.blocksPerLine + 1) * row + col);
  36592. }
  36593. function decodeScan(data, offset, frame, components, resetInterval,
  36594. spectralStart, spectralEnd, successivePrev, successive) {
  36595. var precision = frame.precision;
  36596. var samplesPerLine = frame.samplesPerLine;
  36597. var scanLines = frame.scanLines;
  36598. var mcusPerLine = frame.mcusPerLine;
  36599. var progressive = frame.progressive;
  36600. var maxH = frame.maxH, maxV = frame.maxV;
  36601. var startOffset = offset, bitsData = 0, bitsCount = 0;
  36602. function readBit() {
  36603. if (bitsCount > 0) {
  36604. bitsCount--;
  36605. return (bitsData >> bitsCount) & 1;
  36606. }
  36607. bitsData = data[offset++];
  36608. if (bitsData === 0xFF) {
  36609. var nextByte = data[offset++];
  36610. if (nextByte) {
  36611. throw 'unexpected marker: ' +
  36612. ((bitsData << 8) | nextByte).toString(16);
  36613. }
  36614. // unstuff 0
  36615. }
  36616. bitsCount = 7;
  36617. return bitsData >>> 7;
  36618. }
  36619. function decodeHuffman(tree) {
  36620. var node = tree;
  36621. var bit;
  36622. while ((bit = readBit()) !== null) {
  36623. node = node[bit];
  36624. if (typeof node === 'number') {
  36625. return node;
  36626. }
  36627. if (typeof node !== 'object') {
  36628. throw 'invalid huffman sequence';
  36629. }
  36630. }
  36631. return null;
  36632. }
  36633. function receive(length) {
  36634. var n = 0;
  36635. while (length > 0) {
  36636. var bit = readBit();
  36637. if (bit === null) {
  36638. return;
  36639. }
  36640. n = (n << 1) | bit;
  36641. length--;
  36642. }
  36643. return n;
  36644. }
  36645. function receiveAndExtend(length) {
  36646. if (length === 1) {
  36647. return readBit() === 1 ? 1 : -1;
  36648. }
  36649. var n = receive(length);
  36650. if (n >= 1 << (length - 1)) {
  36651. return n;
  36652. }
  36653. return n + (-1 << length) + 1;
  36654. }
  36655. function decodeBaseline(component, offset) {
  36656. var t = decodeHuffman(component.huffmanTableDC);
  36657. var diff = t === 0 ? 0 : receiveAndExtend(t);
  36658. component.blockData[offset] = (component.pred += diff);
  36659. var k = 1;
  36660. while (k < 64) {
  36661. var rs = decodeHuffman(component.huffmanTableAC);
  36662. var s = rs & 15, r = rs >> 4;
  36663. if (s === 0) {
  36664. if (r < 15) {
  36665. break;
  36666. }
  36667. k += 16;
  36668. continue;
  36669. }
  36670. k += r;
  36671. var z = dctZigZag[k];
  36672. component.blockData[offset + z] = receiveAndExtend(s);
  36673. k++;
  36674. }
  36675. }
  36676. function decodeDCFirst(component, offset) {
  36677. var t = decodeHuffman(component.huffmanTableDC);
  36678. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  36679. component.blockData[offset] = (component.pred += diff);
  36680. }
  36681. function decodeDCSuccessive(component, offset) {
  36682. component.blockData[offset] |= readBit() << successive;
  36683. }
  36684. var eobrun = 0;
  36685. function decodeACFirst(component, offset) {
  36686. if (eobrun > 0) {
  36687. eobrun--;
  36688. return;
  36689. }
  36690. var k = spectralStart, e = spectralEnd;
  36691. while (k <= e) {
  36692. var rs = decodeHuffman(component.huffmanTableAC);
  36693. var s = rs & 15, r = rs >> 4;
  36694. if (s === 0) {
  36695. if (r < 15) {
  36696. eobrun = receive(r) + (1 << r) - 1;
  36697. break;
  36698. }
  36699. k += 16;
  36700. continue;
  36701. }
  36702. k += r;
  36703. var z = dctZigZag[k];
  36704. component.blockData[offset + z] =
  36705. receiveAndExtend(s) * (1 << successive);
  36706. k++;
  36707. }
  36708. }
  36709. var successiveACState = 0, successiveACNextValue;
  36710. function decodeACSuccessive(component, offset) {
  36711. var k = spectralStart;
  36712. var e = spectralEnd;
  36713. var r = 0;
  36714. var s;
  36715. var rs;
  36716. while (k <= e) {
  36717. var z = dctZigZag[k];
  36718. switch (successiveACState) {
  36719. case 0: // initial state
  36720. rs = decodeHuffman(component.huffmanTableAC);
  36721. s = rs & 15;
  36722. r = rs >> 4;
  36723. if (s === 0) {
  36724. if (r < 15) {
  36725. eobrun = receive(r) + (1 << r);
  36726. successiveACState = 4;
  36727. } else {
  36728. r = 16;
  36729. successiveACState = 1;
  36730. }
  36731. } else {
  36732. if (s !== 1) {
  36733. throw 'invalid ACn encoding';
  36734. }
  36735. successiveACNextValue = receiveAndExtend(s);
  36736. successiveACState = r ? 2 : 3;
  36737. }
  36738. continue;
  36739. case 1: // skipping r zero items
  36740. case 2:
  36741. if (component.blockData[offset + z]) {
  36742. component.blockData[offset + z] += (readBit() << successive);
  36743. } else {
  36744. r--;
  36745. if (r === 0) {
  36746. successiveACState = successiveACState === 2 ? 3 : 0;
  36747. }
  36748. }
  36749. break;
  36750. case 3: // set value for a zero item
  36751. if (component.blockData[offset + z]) {
  36752. component.blockData[offset + z] += (readBit() << successive);
  36753. } else {
  36754. component.blockData[offset + z] =
  36755. successiveACNextValue << successive;
  36756. successiveACState = 0;
  36757. }
  36758. break;
  36759. case 4: // eob
  36760. if (component.blockData[offset + z]) {
  36761. component.blockData[offset + z] += (readBit() << successive);
  36762. }
  36763. break;
  36764. }
  36765. k++;
  36766. }
  36767. if (successiveACState === 4) {
  36768. eobrun--;
  36769. if (eobrun === 0) {
  36770. successiveACState = 0;
  36771. }
  36772. }
  36773. }
  36774. function decodeMcu(component, decode, mcu, row, col) {
  36775. var mcuRow = (mcu / mcusPerLine) | 0;
  36776. var mcuCol = mcu % mcusPerLine;
  36777. var blockRow = mcuRow * component.v + row;
  36778. var blockCol = mcuCol * component.h + col;
  36779. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  36780. decode(component, offset);
  36781. }
  36782. function decodeBlock(component, decode, mcu) {
  36783. var blockRow = (mcu / component.blocksPerLine) | 0;
  36784. var blockCol = mcu % component.blocksPerLine;
  36785. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  36786. decode(component, offset);
  36787. }
  36788. var componentsLength = components.length;
  36789. var component, i, j, k, n;
  36790. var decodeFn;
  36791. if (progressive) {
  36792. if (spectralStart === 0) {
  36793. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  36794. } else {
  36795. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  36796. }
  36797. } else {
  36798. decodeFn = decodeBaseline;
  36799. }
  36800. var mcu = 0, marker;
  36801. var mcuExpected;
  36802. if (componentsLength === 1) {
  36803. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  36804. } else {
  36805. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  36806. }
  36807. if (!resetInterval) {
  36808. resetInterval = mcuExpected;
  36809. }
  36810. var h, v;
  36811. while (mcu < mcuExpected) {
  36812. // reset interval stuff
  36813. for (i = 0; i < componentsLength; i++) {
  36814. components[i].pred = 0;
  36815. }
  36816. eobrun = 0;
  36817. if (componentsLength === 1) {
  36818. component = components[0];
  36819. for (n = 0; n < resetInterval; n++) {
  36820. decodeBlock(component, decodeFn, mcu);
  36821. mcu++;
  36822. }
  36823. } else {
  36824. for (n = 0; n < resetInterval; n++) {
  36825. for (i = 0; i < componentsLength; i++) {
  36826. component = components[i];
  36827. h = component.h;
  36828. v = component.v;
  36829. for (j = 0; j < v; j++) {
  36830. for (k = 0; k < h; k++) {
  36831. decodeMcu(component, decodeFn, mcu, j, k);
  36832. }
  36833. }
  36834. }
  36835. mcu++;
  36836. }
  36837. }
  36838. // find marker
  36839. bitsCount = 0;
  36840. marker = (data[offset] << 8) | data[offset + 1];
  36841. if (marker <= 0xFF00) {
  36842. throw 'marker was not found';
  36843. }
  36844. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  36845. offset += 2;
  36846. } else {
  36847. break;
  36848. }
  36849. }
  36850. return offset - startOffset;
  36851. }
  36852. // A port of poppler's IDCT method which in turn is taken from:
  36853. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  36854. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  36855. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  36856. // 988-991.
  36857. function quantizeAndInverse(component, blockBufferOffset, p) {
  36858. var qt = component.quantizationTable, blockData = component.blockData;
  36859. var v0, v1, v2, v3, v4, v5, v6, v7;
  36860. var p0, p1, p2, p3, p4, p5, p6, p7;
  36861. var t;
  36862. // inverse DCT on rows
  36863. for (var row = 0; row < 64; row += 8) {
  36864. // gather block data
  36865. p0 = blockData[blockBufferOffset + row];
  36866. p1 = blockData[blockBufferOffset + row + 1];
  36867. p2 = blockData[blockBufferOffset + row + 2];
  36868. p3 = blockData[blockBufferOffset + row + 3];
  36869. p4 = blockData[blockBufferOffset + row + 4];
  36870. p5 = blockData[blockBufferOffset + row + 5];
  36871. p6 = blockData[blockBufferOffset + row + 6];
  36872. p7 = blockData[blockBufferOffset + row + 7];
  36873. // dequant p0
  36874. p0 *= qt[row];
  36875. // check for all-zero AC coefficients
  36876. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  36877. t = (dctSqrt2 * p0 + 512) >> 10;
  36878. p[row] = t;
  36879. p[row + 1] = t;
  36880. p[row + 2] = t;
  36881. p[row + 3] = t;
  36882. p[row + 4] = t;
  36883. p[row + 5] = t;
  36884. p[row + 6] = t;
  36885. p[row + 7] = t;
  36886. continue;
  36887. }
  36888. // dequant p1 ... p7
  36889. p1 *= qt[row + 1];
  36890. p2 *= qt[row + 2];
  36891. p3 *= qt[row + 3];
  36892. p4 *= qt[row + 4];
  36893. p5 *= qt[row + 5];
  36894. p6 *= qt[row + 6];
  36895. p7 *= qt[row + 7];
  36896. // stage 4
  36897. v0 = (dctSqrt2 * p0 + 128) >> 8;
  36898. v1 = (dctSqrt2 * p4 + 128) >> 8;
  36899. v2 = p2;
  36900. v3 = p6;
  36901. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  36902. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  36903. v5 = p3 << 4;
  36904. v6 = p5 << 4;
  36905. // stage 3
  36906. v0 = (v0 + v1 + 1) >> 1;
  36907. v1 = v0 - v1;
  36908. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  36909. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  36910. v3 = t;
  36911. v4 = (v4 + v6 + 1) >> 1;
  36912. v6 = v4 - v6;
  36913. v7 = (v7 + v5 + 1) >> 1;
  36914. v5 = v7 - v5;
  36915. // stage 2
  36916. v0 = (v0 + v3 + 1) >> 1;
  36917. v3 = v0 - v3;
  36918. v1 = (v1 + v2 + 1) >> 1;
  36919. v2 = v1 - v2;
  36920. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  36921. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  36922. v7 = t;
  36923. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  36924. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  36925. v6 = t;
  36926. // stage 1
  36927. p[row] = v0 + v7;
  36928. p[row + 7] = v0 - v7;
  36929. p[row + 1] = v1 + v6;
  36930. p[row + 6] = v1 - v6;
  36931. p[row + 2] = v2 + v5;
  36932. p[row + 5] = v2 - v5;
  36933. p[row + 3] = v3 + v4;
  36934. p[row + 4] = v3 - v4;
  36935. }
  36936. // inverse DCT on columns
  36937. for (var col = 0; col < 8; ++col) {
  36938. p0 = p[col];
  36939. p1 = p[col + 8];
  36940. p2 = p[col + 16];
  36941. p3 = p[col + 24];
  36942. p4 = p[col + 32];
  36943. p5 = p[col + 40];
  36944. p6 = p[col + 48];
  36945. p7 = p[col + 56];
  36946. // check for all-zero AC coefficients
  36947. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  36948. t = (dctSqrt2 * p0 + 8192) >> 14;
  36949. // convert to 8 bit
  36950. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  36951. blockData[blockBufferOffset + col] = t;
  36952. blockData[blockBufferOffset + col + 8] = t;
  36953. blockData[blockBufferOffset + col + 16] = t;
  36954. blockData[blockBufferOffset + col + 24] = t;
  36955. blockData[blockBufferOffset + col + 32] = t;
  36956. blockData[blockBufferOffset + col + 40] = t;
  36957. blockData[blockBufferOffset + col + 48] = t;
  36958. blockData[blockBufferOffset + col + 56] = t;
  36959. continue;
  36960. }
  36961. // stage 4
  36962. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  36963. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  36964. v2 = p2;
  36965. v3 = p6;
  36966. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  36967. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  36968. v5 = p3;
  36969. v6 = p5;
  36970. // stage 3
  36971. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  36972. // converting to UInt8 range later.
  36973. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  36974. v1 = v0 - v1;
  36975. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  36976. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  36977. v3 = t;
  36978. v4 = (v4 + v6 + 1) >> 1;
  36979. v6 = v4 - v6;
  36980. v7 = (v7 + v5 + 1) >> 1;
  36981. v5 = v7 - v5;
  36982. // stage 2
  36983. v0 = (v0 + v3 + 1) >> 1;
  36984. v3 = v0 - v3;
  36985. v1 = (v1 + v2 + 1) >> 1;
  36986. v2 = v1 - v2;
  36987. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  36988. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  36989. v7 = t;
  36990. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  36991. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  36992. v6 = t;
  36993. // stage 1
  36994. p0 = v0 + v7;
  36995. p7 = v0 - v7;
  36996. p1 = v1 + v6;
  36997. p6 = v1 - v6;
  36998. p2 = v2 + v5;
  36999. p5 = v2 - v5;
  37000. p3 = v3 + v4;
  37001. p4 = v3 - v4;
  37002. // convert to 8-bit integers
  37003. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  37004. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  37005. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  37006. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  37007. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  37008. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  37009. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  37010. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  37011. // store block data
  37012. blockData[blockBufferOffset + col] = p0;
  37013. blockData[blockBufferOffset + col + 8] = p1;
  37014. blockData[blockBufferOffset + col + 16] = p2;
  37015. blockData[blockBufferOffset + col + 24] = p3;
  37016. blockData[blockBufferOffset + col + 32] = p4;
  37017. blockData[blockBufferOffset + col + 40] = p5;
  37018. blockData[blockBufferOffset + col + 48] = p6;
  37019. blockData[blockBufferOffset + col + 56] = p7;
  37020. }
  37021. }
  37022. function buildComponentData(frame, component) {
  37023. var blocksPerLine = component.blocksPerLine;
  37024. var blocksPerColumn = component.blocksPerColumn;
  37025. var computationBuffer = new Int16Array(64);
  37026. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  37027. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  37028. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  37029. quantizeAndInverse(component, offset, computationBuffer);
  37030. }
  37031. }
  37032. return component.blockData;
  37033. }
  37034. function clamp0to255(a) {
  37035. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  37036. }
  37037. constructor.prototype = {
  37038. parse: function parse(data) {
  37039. function readUint16() {
  37040. var value = (data[offset] << 8) | data[offset + 1];
  37041. offset += 2;
  37042. return value;
  37043. }
  37044. function readDataBlock() {
  37045. var length = readUint16();
  37046. var array = data.subarray(offset, offset + length - 2);
  37047. offset += array.length;
  37048. return array;
  37049. }
  37050. function prepareComponents(frame) {
  37051. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  37052. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  37053. for (var i = 0; i < frame.components.length; i++) {
  37054. component = frame.components[i];
  37055. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  37056. component.h / frame.maxH);
  37057. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  37058. component.v / frame.maxV);
  37059. var blocksPerLineForMcu = mcusPerLine * component.h;
  37060. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  37061. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  37062. (blocksPerLineForMcu + 1);
  37063. component.blockData = new Int16Array(blocksBufferSize);
  37064. component.blocksPerLine = blocksPerLine;
  37065. component.blocksPerColumn = blocksPerColumn;
  37066. }
  37067. frame.mcusPerLine = mcusPerLine;
  37068. frame.mcusPerColumn = mcusPerColumn;
  37069. }
  37070. var offset = 0, length = data.length;
  37071. var jfif = null;
  37072. var adobe = null;
  37073. var pixels = null;
  37074. var frame, resetInterval;
  37075. var quantizationTables = [];
  37076. var huffmanTablesAC = [], huffmanTablesDC = [];
  37077. var fileMarker = readUint16();
  37078. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  37079. throw 'SOI not found';
  37080. }
  37081. fileMarker = readUint16();
  37082. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  37083. var i, j, l;
  37084. switch(fileMarker) {
  37085. case 0xFFE0: // APP0 (Application Specific)
  37086. case 0xFFE1: // APP1
  37087. case 0xFFE2: // APP2
  37088. case 0xFFE3: // APP3
  37089. case 0xFFE4: // APP4
  37090. case 0xFFE5: // APP5
  37091. case 0xFFE6: // APP6
  37092. case 0xFFE7: // APP7
  37093. case 0xFFE8: // APP8
  37094. case 0xFFE9: // APP9
  37095. case 0xFFEA: // APP10
  37096. case 0xFFEB: // APP11
  37097. case 0xFFEC: // APP12
  37098. case 0xFFED: // APP13
  37099. case 0xFFEE: // APP14
  37100. case 0xFFEF: // APP15
  37101. case 0xFFFE: // COM (Comment)
  37102. var appData = readDataBlock();
  37103. if (fileMarker === 0xFFE0) {
  37104. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  37105. appData[2] === 0x49 && appData[3] === 0x46 &&
  37106. appData[4] === 0) { // 'JFIF\x00'
  37107. jfif = {
  37108. version: { major: appData[5], minor: appData[6] },
  37109. densityUnits: appData[7],
  37110. xDensity: (appData[8] << 8) | appData[9],
  37111. yDensity: (appData[10] << 8) | appData[11],
  37112. thumbWidth: appData[12],
  37113. thumbHeight: appData[13],
  37114. thumbData: appData.subarray(14, 14 +
  37115. 3 * appData[12] * appData[13])
  37116. };
  37117. }
  37118. }
  37119. // TODO APP1 - Exif
  37120. if (fileMarker === 0xFFEE) {
  37121. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  37122. appData[2] === 0x6F && appData[3] === 0x62 &&
  37123. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  37124. adobe = {
  37125. version: appData[6],
  37126. flags0: (appData[7] << 8) | appData[8],
  37127. flags1: (appData[9] << 8) | appData[10],
  37128. transformCode: appData[11]
  37129. };
  37130. }
  37131. }
  37132. break;
  37133. case 0xFFDB: // DQT (Define Quantization Tables)
  37134. var quantizationTablesLength = readUint16();
  37135. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  37136. var z;
  37137. while (offset < quantizationTablesEnd) {
  37138. var quantizationTableSpec = data[offset++];
  37139. var tableData = new Uint16Array(64);
  37140. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  37141. for (j = 0; j < 64; j++) {
  37142. z = dctZigZag[j];
  37143. tableData[z] = data[offset++];
  37144. }
  37145. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  37146. for (j = 0; j < 64; j++) {
  37147. z = dctZigZag[j];
  37148. tableData[z] = readUint16();
  37149. }
  37150. } else {
  37151. throw 'DQT: invalid table spec';
  37152. }
  37153. quantizationTables[quantizationTableSpec & 15] = tableData;
  37154. }
  37155. break;
  37156. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  37157. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  37158. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  37159. if (frame) {
  37160. throw 'Only single frame JPEGs supported';
  37161. }
  37162. readUint16(); // skip data length
  37163. frame = {};
  37164. frame.extended = (fileMarker === 0xFFC1);
  37165. frame.progressive = (fileMarker === 0xFFC2);
  37166. frame.precision = data[offset++];
  37167. frame.scanLines = readUint16();
  37168. frame.samplesPerLine = readUint16();
  37169. frame.components = [];
  37170. frame.componentIds = {};
  37171. var componentsCount = data[offset++], componentId;
  37172. var maxH = 0, maxV = 0;
  37173. for (i = 0; i < componentsCount; i++) {
  37174. componentId = data[offset];
  37175. var h = data[offset + 1] >> 4;
  37176. var v = data[offset + 1] & 15;
  37177. if (maxH < h) {
  37178. maxH = h;
  37179. }
  37180. if (maxV < v) {
  37181. maxV = v;
  37182. }
  37183. var qId = data[offset + 2];
  37184. l = frame.components.push({
  37185. h: h,
  37186. v: v,
  37187. quantizationTable: quantizationTables[qId]
  37188. });
  37189. frame.componentIds[componentId] = l - 1;
  37190. offset += 3;
  37191. }
  37192. frame.maxH = maxH;
  37193. frame.maxV = maxV;
  37194. prepareComponents(frame);
  37195. break;
  37196. case 0xFFC4: // DHT (Define Huffman Tables)
  37197. var huffmanLength = readUint16();
  37198. for (i = 2; i < huffmanLength;) {
  37199. var huffmanTableSpec = data[offset++];
  37200. var codeLengths = new Uint8Array(16);
  37201. var codeLengthSum = 0;
  37202. for (j = 0; j < 16; j++, offset++) {
  37203. codeLengthSum += (codeLengths[j] = data[offset]);
  37204. }
  37205. var huffmanValues = new Uint8Array(codeLengthSum);
  37206. for (j = 0; j < codeLengthSum; j++, offset++) {
  37207. huffmanValues[j] = data[offset];
  37208. }
  37209. i += 17 + codeLengthSum;
  37210. ((huffmanTableSpec >> 4) === 0 ?
  37211. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  37212. buildHuffmanTable(codeLengths, huffmanValues);
  37213. }
  37214. break;
  37215. case 0xFFDD: // DRI (Define Restart Interval)
  37216. readUint16(); // skip data length
  37217. resetInterval = readUint16();
  37218. break;
  37219. case 0xFFDA: // SOS (Start of Scan)
  37220. var scanLength = readUint16();
  37221. var selectorsCount = data[offset++];
  37222. var components = [], component;
  37223. for (i = 0; i < selectorsCount; i++) {
  37224. var componentIndex = frame.componentIds[data[offset++]];
  37225. component = frame.components[componentIndex];
  37226. var tableSpec = data[offset++];
  37227. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  37228. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  37229. components.push(component);
  37230. }
  37231. var spectralStart = data[offset++];
  37232. var spectralEnd = data[offset++];
  37233. var successiveApproximation = data[offset++];
  37234. var processed = decodeScan(data, offset,
  37235. frame, components, resetInterval,
  37236. spectralStart, spectralEnd,
  37237. successiveApproximation >> 4, successiveApproximation & 15);
  37238. offset += processed;
  37239. break;
  37240. default:
  37241. if (data[offset - 3] === 0xFF &&
  37242. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  37243. // could be incorrect encoding -- last 0xFF byte of the previous
  37244. // block was eaten by the encoder
  37245. offset -= 3;
  37246. break;
  37247. }
  37248. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  37249. }
  37250. fileMarker = readUint16();
  37251. }
  37252. this.width = frame.samplesPerLine;
  37253. this.height = frame.scanLines;
  37254. this.jfif = jfif;
  37255. this.adobe = adobe;
  37256. this.components = [];
  37257. for (i = 0; i < frame.components.length; i++) {
  37258. component = frame.components[i];
  37259. this.components.push({
  37260. output: buildComponentData(frame, component),
  37261. scaleX: component.h / frame.maxH,
  37262. scaleY: component.v / frame.maxV,
  37263. blocksPerLine: component.blocksPerLine,
  37264. blocksPerColumn: component.blocksPerColumn
  37265. });
  37266. }
  37267. this.numComponents = this.components.length;
  37268. },
  37269. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  37270. var scaleX = this.width / width, scaleY = this.height / height;
  37271. var component, componentScaleX, componentScaleY, blocksPerScanline;
  37272. var x, y, i, j, k;
  37273. var index;
  37274. var offset = 0;
  37275. var output;
  37276. var numComponents = this.components.length;
  37277. var dataLength = width * height * numComponents;
  37278. var data = new Uint8Array(dataLength);
  37279. var xScaleBlockOffset = new Uint32Array(width);
  37280. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  37281. for (i = 0; i < numComponents; i++) {
  37282. component = this.components[i];
  37283. componentScaleX = component.scaleX * scaleX;
  37284. componentScaleY = component.scaleY * scaleY;
  37285. offset = i;
  37286. output = component.output;
  37287. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  37288. // precalculate the xScaleBlockOffset
  37289. for (x = 0; x < width; x++) {
  37290. j = 0 | (x * componentScaleX);
  37291. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  37292. }
  37293. // linearize the blocks of the component
  37294. for (y = 0; y < height; y++) {
  37295. j = 0 | (y * componentScaleY);
  37296. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  37297. for (x = 0; x < width; x++) {
  37298. data[offset] = output[index + xScaleBlockOffset[x]];
  37299. offset += numComponents;
  37300. }
  37301. }
  37302. }
  37303. // decodeTransform will contains pairs of multiplier (-256..256) and
  37304. // additive
  37305. var transform = this.decodeTransform;
  37306. if (transform) {
  37307. for (i = 0; i < dataLength;) {
  37308. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  37309. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  37310. }
  37311. }
  37312. }
  37313. return data;
  37314. },
  37315. _isColorConversionNeeded: function isColorConversionNeeded() {
  37316. if (this.adobe && this.adobe.transformCode) {
  37317. // The adobe transform marker overrides any previous setting
  37318. return true;
  37319. } else if (this.numComponents === 3) {
  37320. return true;
  37321. } else {
  37322. return false;
  37323. }
  37324. },
  37325. _convertYccToRgb: function convertYccToRgb(data) {
  37326. var Y, Cb, Cr;
  37327. for (var i = 0, length = data.length; i < length; i += 3) {
  37328. Y = data[i ];
  37329. Cb = data[i + 1];
  37330. Cr = data[i + 2];
  37331. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  37332. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  37333. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  37334. }
  37335. return data;
  37336. },
  37337. _convertYcckToRgb: function convertYcckToRgb(data) {
  37338. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  37339. var offset = 0;
  37340. for (var i = 0, length = data.length; i < length; i += 4) {
  37341. Y = data[i];
  37342. Cb = data[i + 1];
  37343. Cr = data[i + 2];
  37344. k = data[i + 3];
  37345. CbCb = Cb * Cb;
  37346. CbCr = Cb * Cr;
  37347. CbY = Cb * Y;
  37348. Cbk = Cb * k;
  37349. CrCr = Cr * Cr;
  37350. Crk = Cr * k;
  37351. CrY = Cr * Y;
  37352. YY = Y * Y;
  37353. Yk = Y * k;
  37354. kk = k * k;
  37355. var r = - 122.67195406894 -
  37356. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  37357. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  37358. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  37359. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  37360. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  37361. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  37362. 0.000336197177618394 * kk + 0.484791561490776 * k;
  37363. var g = 107.268039397724 +
  37364. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  37365. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  37366. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  37367. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  37368. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  37369. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  37370. 0.000318913117588328 * kk - 0.213742400323665 * k;
  37371. var b = - 20.810012546947 -
  37372. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  37373. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  37374. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  37375. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  37376. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  37377. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  37378. 0.000343531996510555 * kk + 0.24165260232407 * k;
  37379. data[offset++] = clamp0to255(r);
  37380. data[offset++] = clamp0to255(g);
  37381. data[offset++] = clamp0to255(b);
  37382. }
  37383. return data;
  37384. },
  37385. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  37386. var Y, Cb, Cr;
  37387. for (var i = 0, length = data.length; i < length; i += 4) {
  37388. Y = data[i];
  37389. Cb = data[i + 1];
  37390. Cr = data[i + 2];
  37391. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  37392. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  37393. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  37394. // K in data[i + 3] is unchanged
  37395. }
  37396. return data;
  37397. },
  37398. _convertCmykToRgb: function convertCmykToRgb(data) {
  37399. var c, m, y, k;
  37400. var offset = 0;
  37401. var min = -255 * 255 * 255;
  37402. var scale = 1 / 255 / 255;
  37403. for (var i = 0, length = data.length; i < length; i += 4) {
  37404. c = data[i];
  37405. m = data[i + 1];
  37406. y = data[i + 2];
  37407. k = data[i + 3];
  37408. var r =
  37409. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  37410. 18.82290502165302 * y + 212.25662451639585 * k -
  37411. 72734.4411664936) +
  37412. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  37413. 17.873870861415444 * k - 1401.7366389350734) +
  37414. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  37415. 4465.541406466231) -
  37416. k * (21.86122147463605 * k + 48317.86113160301);
  37417. var g =
  37418. c * (8.841041422036149 * c + 60.118027045597366 * m +
  37419. 6.871425592049007 * y + 31.159100130055922 * k -
  37420. 20220.756542821975) +
  37421. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  37422. 131.35250912493976 * k - 48691.05921601825) +
  37423. y * (4.444339102852739 * y + 9.8632861493405 * k -
  37424. 6341.191035517494) -
  37425. k * (20.737325471181034 * k + 47890.15695978492);
  37426. var b =
  37427. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  37428. 30.89978309703729 * y - 0.23883238689178934 * k -
  37429. 3616.812083916688) +
  37430. m * (10.49593273432072 * m + 63.02378494754052 * y +
  37431. 50.606957656360734 * k - 28620.90484698408) +
  37432. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  37433. 49363.43385999684) -
  37434. k * (22.33816807309886 * k + 45932.16563550634);
  37435. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  37436. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  37437. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  37438. }
  37439. return data;
  37440. },
  37441. getData: function getData(width, height, forceRGBoutput) {
  37442. if (this.numComponents > 4) {
  37443. throw 'Unsupported color mode';
  37444. }
  37445. // type of data: Uint8Array(width * height * numComponents)
  37446. var data = this._getLinearizedBlockData(width, height);
  37447. if (this.numComponents === 3) {
  37448. return this._convertYccToRgb(data);
  37449. } else if (this.numComponents === 4) {
  37450. if (this._isColorConversionNeeded()) {
  37451. if (forceRGBoutput) {
  37452. return this._convertYcckToRgb(data);
  37453. } else {
  37454. return this._convertYcckToCmyk(data);
  37455. }
  37456. } else if (forceRGBoutput) {
  37457. return this._convertCmykToRgb(data);
  37458. }
  37459. }
  37460. return data;
  37461. }
  37462. };
  37463. return constructor;
  37464. })();
  37465. var JpxImage = (function JpxImageClosure() {
  37466. // Table E.1
  37467. var SubbandsGainLog2 = {
  37468. 'LL': 0,
  37469. 'LH': 1,
  37470. 'HL': 1,
  37471. 'HH': 2
  37472. };
  37473. function JpxImage() {
  37474. this.failOnCorruptedImage = false;
  37475. }
  37476. JpxImage.prototype = {
  37477. parse: function JpxImage_parse(data) {
  37478. var head = readUint16(data, 0);
  37479. // No box header, immediate start of codestream (SOC)
  37480. if (head === 0xFF4F) {
  37481. this.parseCodestream(data, 0, data.length);
  37482. return;
  37483. }
  37484. var position = 0, length = data.length;
  37485. while (position < length) {
  37486. var headerSize = 8;
  37487. var lbox = readUint32(data, position);
  37488. var tbox = readUint32(data, position + 4);
  37489. position += headerSize;
  37490. if (lbox === 1) {
  37491. // XLBox: read UInt64 according to spec.
  37492. // JavaScript's int precision of 53 bit should be sufficient here.
  37493. lbox = readUint32(data, position) * 4294967296 +
  37494. readUint32(data, position + 4);
  37495. position += 8;
  37496. headerSize += 8;
  37497. }
  37498. if (lbox === 0) {
  37499. lbox = length - position + headerSize;
  37500. }
  37501. if (lbox < headerSize) {
  37502. throw new Error('JPX Error: Invalid box field size');
  37503. }
  37504. var dataLength = lbox - headerSize;
  37505. var jumpDataLength = true;
  37506. switch (tbox) {
  37507. case 0x6A501A1A: // 'jP\032\032'
  37508. // TODO
  37509. break;
  37510. case 0x6A703268: // 'jp2h'
  37511. jumpDataLength = false; // parsing child boxes
  37512. break;
  37513. case 0x636F6C72: // 'colr'
  37514. // TODO
  37515. break;
  37516. case 0x6A703263: // 'jp2c'
  37517. this.parseCodestream(data, position, position + dataLength);
  37518. break;
  37519. }
  37520. if (jumpDataLength) {
  37521. position += dataLength;
  37522. }
  37523. }
  37524. },
  37525. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  37526. var newByte = stream.getByte();
  37527. while (newByte >= 0) {
  37528. var oldByte = newByte;
  37529. newByte = stream.getByte();
  37530. var code = (oldByte << 8) | newByte;
  37531. // Image and tile size (SIZ)
  37532. if (code === 0xFF51) {
  37533. stream.skip(4);
  37534. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  37535. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  37536. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  37537. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  37538. stream.skip(16);
  37539. var Csiz = stream.getUint16(); // Byte 36
  37540. this.width = Xsiz - XOsiz;
  37541. this.height = Ysiz - YOsiz;
  37542. this.componentsCount = Csiz;
  37543. // Results are always returned as Uint8Arrays
  37544. this.bitsPerComponent = 8;
  37545. return;
  37546. }
  37547. }
  37548. throw new Error('JPX Error: No size marker found in JPX stream');
  37549. },
  37550. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  37551. var context = {};
  37552. try {
  37553. var doNotRecover = false;
  37554. var position = start;
  37555. while (position + 1 < end) {
  37556. var code = readUint16(data, position);
  37557. position += 2;
  37558. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  37559. switch (code) {
  37560. case 0xFF4F: // Start of codestream (SOC)
  37561. context.mainHeader = true;
  37562. break;
  37563. case 0xFFD9: // End of codestream (EOC)
  37564. break;
  37565. case 0xFF51: // Image and tile size (SIZ)
  37566. length = readUint16(data, position);
  37567. var siz = {};
  37568. siz.Xsiz = readUint32(data, position + 4);
  37569. siz.Ysiz = readUint32(data, position + 8);
  37570. siz.XOsiz = readUint32(data, position + 12);
  37571. siz.YOsiz = readUint32(data, position + 16);
  37572. siz.XTsiz = readUint32(data, position + 20);
  37573. siz.YTsiz = readUint32(data, position + 24);
  37574. siz.XTOsiz = readUint32(data, position + 28);
  37575. siz.YTOsiz = readUint32(data, position + 32);
  37576. var componentsCount = readUint16(data, position + 36);
  37577. siz.Csiz = componentsCount;
  37578. var components = [];
  37579. j = position + 38;
  37580. for (var i = 0; i < componentsCount; i++) {
  37581. var component = {
  37582. precision: (data[j] & 0x7F) + 1,
  37583. isSigned: !!(data[j] & 0x80),
  37584. XRsiz: data[j + 1],
  37585. YRsiz: data[j + 1]
  37586. };
  37587. calculateComponentDimensions(component, siz);
  37588. components.push(component);
  37589. }
  37590. context.SIZ = siz;
  37591. context.components = components;
  37592. calculateTileGrids(context, components);
  37593. context.QCC = [];
  37594. context.COC = [];
  37595. break;
  37596. case 0xFF55: // Tile-part lengths, main header (TLM)
  37597. var Ltlm = readUint16(data, position); // Marker segment length
  37598. // Skip tile length markers
  37599. position += Ltlm;
  37600. break;
  37601. case 0xFF5C: // Quantization default (QCD)
  37602. length = readUint16(data, position);
  37603. var qcd = {};
  37604. j = position + 2;
  37605. sqcd = data[j++];
  37606. switch (sqcd & 0x1F) {
  37607. case 0:
  37608. spqcdSize = 8;
  37609. scalarExpounded = true;
  37610. break;
  37611. case 1:
  37612. spqcdSize = 16;
  37613. scalarExpounded = false;
  37614. break;
  37615. case 2:
  37616. spqcdSize = 16;
  37617. scalarExpounded = true;
  37618. break;
  37619. default:
  37620. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  37621. }
  37622. qcd.noQuantization = (spqcdSize === 8);
  37623. qcd.scalarExpounded = scalarExpounded;
  37624. qcd.guardBits = sqcd >> 5;
  37625. spqcds = [];
  37626. while (j < length + position) {
  37627. var spqcd = {};
  37628. if (spqcdSize === 8) {
  37629. spqcd.epsilon = data[j++] >> 3;
  37630. spqcd.mu = 0;
  37631. } else {
  37632. spqcd.epsilon = data[j] >> 3;
  37633. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  37634. j += 2;
  37635. }
  37636. spqcds.push(spqcd);
  37637. }
  37638. qcd.SPqcds = spqcds;
  37639. if (context.mainHeader) {
  37640. context.QCD = qcd;
  37641. } else {
  37642. context.currentTile.QCD = qcd;
  37643. context.currentTile.QCC = [];
  37644. }
  37645. break;
  37646. case 0xFF5D: // Quantization component (QCC)
  37647. length = readUint16(data, position);
  37648. var qcc = {};
  37649. j = position + 2;
  37650. var cqcc;
  37651. if (context.SIZ.Csiz < 257) {
  37652. cqcc = data[j++];
  37653. } else {
  37654. cqcc = readUint16(data, j);
  37655. j += 2;
  37656. }
  37657. sqcd = data[j++];
  37658. switch (sqcd & 0x1F) {
  37659. case 0:
  37660. spqcdSize = 8;
  37661. scalarExpounded = true;
  37662. break;
  37663. case 1:
  37664. spqcdSize = 16;
  37665. scalarExpounded = false;
  37666. break;
  37667. case 2:
  37668. spqcdSize = 16;
  37669. scalarExpounded = true;
  37670. break;
  37671. default:
  37672. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  37673. }
  37674. qcc.noQuantization = (spqcdSize === 8);
  37675. qcc.scalarExpounded = scalarExpounded;
  37676. qcc.guardBits = sqcd >> 5;
  37677. spqcds = [];
  37678. while (j < (length + position)) {
  37679. spqcd = {};
  37680. if (spqcdSize === 8) {
  37681. spqcd.epsilon = data[j++] >> 3;
  37682. spqcd.mu = 0;
  37683. } else {
  37684. spqcd.epsilon = data[j] >> 3;
  37685. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  37686. j += 2;
  37687. }
  37688. spqcds.push(spqcd);
  37689. }
  37690. qcc.SPqcds = spqcds;
  37691. if (context.mainHeader) {
  37692. context.QCC[cqcc] = qcc;
  37693. } else {
  37694. context.currentTile.QCC[cqcc] = qcc;
  37695. }
  37696. break;
  37697. case 0xFF52: // Coding style default (COD)
  37698. length = readUint16(data, position);
  37699. var cod = {};
  37700. j = position + 2;
  37701. var scod = data[j++];
  37702. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  37703. cod.sopMarkerUsed = !!(scod & 2);
  37704. cod.ephMarkerUsed = !!(scod & 4);
  37705. cod.progressionOrder = data[j++];
  37706. cod.layersCount = readUint16(data, j);
  37707. j += 2;
  37708. cod.multipleComponentTransform = data[j++];
  37709. cod.decompositionLevelsCount = data[j++];
  37710. cod.xcb = (data[j++] & 0xF) + 2;
  37711. cod.ycb = (data[j++] & 0xF) + 2;
  37712. var blockStyle = data[j++];
  37713. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  37714. cod.resetContextProbabilities = !!(blockStyle & 2);
  37715. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  37716. cod.verticalyStripe = !!(blockStyle & 8);
  37717. cod.predictableTermination = !!(blockStyle & 16);
  37718. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  37719. cod.reversibleTransformation = data[j++];
  37720. if (cod.entropyCoderWithCustomPrecincts) {
  37721. var precinctsSizes = [];
  37722. while (j < length + position) {
  37723. var precinctsSize = data[j++];
  37724. precinctsSizes.push({
  37725. PPx: precinctsSize & 0xF,
  37726. PPy: precinctsSize >> 4
  37727. });
  37728. }
  37729. cod.precinctsSizes = precinctsSizes;
  37730. }
  37731. var unsupported = [];
  37732. if (cod.sopMarkerUsed) {
  37733. unsupported.push('sopMarkerUsed');
  37734. }
  37735. if (cod.ephMarkerUsed) {
  37736. unsupported.push('ephMarkerUsed');
  37737. }
  37738. if (cod.selectiveArithmeticCodingBypass) {
  37739. unsupported.push('selectiveArithmeticCodingBypass');
  37740. }
  37741. if (cod.resetContextProbabilities) {
  37742. unsupported.push('resetContextProbabilities');
  37743. }
  37744. if (cod.terminationOnEachCodingPass) {
  37745. unsupported.push('terminationOnEachCodingPass');
  37746. }
  37747. if (cod.verticalyStripe) {
  37748. unsupported.push('verticalyStripe');
  37749. }
  37750. if (cod.predictableTermination) {
  37751. unsupported.push('predictableTermination');
  37752. }
  37753. if (unsupported.length > 0) {
  37754. doNotRecover = true;
  37755. throw new Error('JPX Error: Unsupported COD options (' +
  37756. unsupported.join(', ') + ')');
  37757. }
  37758. if (context.mainHeader) {
  37759. context.COD = cod;
  37760. } else {
  37761. context.currentTile.COD = cod;
  37762. context.currentTile.COC = [];
  37763. }
  37764. break;
  37765. case 0xFF90: // Start of tile-part (SOT)
  37766. length = readUint16(data, position);
  37767. tile = {};
  37768. tile.index = readUint16(data, position + 2);
  37769. tile.length = readUint32(data, position + 4);
  37770. tile.dataEnd = tile.length + position - 2;
  37771. tile.partIndex = data[position + 8];
  37772. tile.partsCount = data[position + 9];
  37773. context.mainHeader = false;
  37774. if (tile.partIndex === 0) {
  37775. // reset component specific settings
  37776. tile.COD = context.COD;
  37777. tile.COC = context.COC.slice(0); // clone of the global COC
  37778. tile.QCD = context.QCD;
  37779. tile.QCC = context.QCC.slice(0); // clone of the global COC
  37780. }
  37781. context.currentTile = tile;
  37782. break;
  37783. case 0xFF93: // Start of data (SOD)
  37784. tile = context.currentTile;
  37785. if (tile.partIndex === 0) {
  37786. initializeTile(context, tile.index);
  37787. buildPackets(context);
  37788. }
  37789. // moving to the end of the data
  37790. length = tile.dataEnd - position;
  37791. parseTilePackets(context, data, position, length);
  37792. break;
  37793. case 0xFF64: // Comment (COM)
  37794. length = readUint16(data, position);
  37795. // skipping content
  37796. break;
  37797. case 0xFF53: // Coding style component (COC)
  37798. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  37799. 'not implemented');
  37800. default:
  37801. throw new Error('JPX Error: Unknown codestream code: ' +
  37802. code.toString(16));
  37803. }
  37804. position += length;
  37805. }
  37806. } catch (e) {
  37807. if (doNotRecover || this.failOnCorruptedImage) {
  37808. throw e;
  37809. } else {
  37810. warn('Trying to recover from ' + e.message);
  37811. }
  37812. }
  37813. this.tiles = transformComponents(context);
  37814. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  37815. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  37816. this.componentsCount = context.SIZ.Csiz;
  37817. }
  37818. };
  37819. function calculateComponentDimensions(component, siz) {
  37820. // Section B.2 Component mapping
  37821. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  37822. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  37823. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  37824. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  37825. component.width = component.x1 - component.x0;
  37826. component.height = component.y1 - component.y0;
  37827. }
  37828. function calculateTileGrids(context, components) {
  37829. var siz = context.SIZ;
  37830. // Section B.3 Division into tile and tile-components
  37831. var tile, tiles = [];
  37832. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  37833. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  37834. for (var q = 0; q < numYtiles; q++) {
  37835. for (var p = 0; p < numXtiles; p++) {
  37836. tile = {};
  37837. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  37838. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  37839. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  37840. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  37841. tile.width = tile.tx1 - tile.tx0;
  37842. tile.height = tile.ty1 - tile.ty0;
  37843. tile.components = [];
  37844. tiles.push(tile);
  37845. }
  37846. }
  37847. context.tiles = tiles;
  37848. var componentsCount = siz.Csiz;
  37849. for (var i = 0, ii = componentsCount; i < ii; i++) {
  37850. var component = components[i];
  37851. for (var j = 0, jj = tiles.length; j < jj; j++) {
  37852. var tileComponent = {};
  37853. tile = tiles[j];
  37854. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  37855. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  37856. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  37857. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  37858. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  37859. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  37860. tile.components[i] = tileComponent;
  37861. }
  37862. }
  37863. }
  37864. function getBlocksDimensions(context, component, r) {
  37865. var codOrCoc = component.codingStyleParameters;
  37866. var result = {};
  37867. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  37868. result.PPx = 15;
  37869. result.PPy = 15;
  37870. } else {
  37871. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  37872. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  37873. }
  37874. // calculate codeblock size as described in section B.7
  37875. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  37876. Math.min(codOrCoc.xcb, result.PPx));
  37877. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  37878. Math.min(codOrCoc.ycb, result.PPy));
  37879. return result;
  37880. }
  37881. function buildPrecincts(context, resolution, dimensions) {
  37882. // Section B.6 Division resolution to precincts
  37883. var precinctWidth = 1 << dimensions.PPx;
  37884. var precinctHeight = 1 << dimensions.PPy;
  37885. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  37886. Math.ceil(resolution.trx1 / precinctWidth) -
  37887. Math.floor(resolution.trx0 / precinctWidth) : 0);
  37888. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  37889. Math.ceil(resolution.try1 / precinctHeight) -
  37890. Math.floor(resolution.try0 / precinctHeight) : 0);
  37891. var numprecincts = numprecinctswide * numprecinctshigh;
  37892. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  37893. precinctWidth;
  37894. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  37895. precinctHeight;
  37896. resolution.precinctParameters = {
  37897. precinctXOffset: precinctXOffset,
  37898. precinctYOffset: precinctYOffset,
  37899. precinctWidth: precinctWidth,
  37900. precinctHeight: precinctHeight,
  37901. numprecinctswide: numprecinctswide,
  37902. numprecinctshigh: numprecinctshigh,
  37903. numprecincts: numprecincts
  37904. };
  37905. }
  37906. function buildCodeblocks(context, subband, dimensions) {
  37907. // Section B.7 Division sub-band into code-blocks
  37908. var xcb_ = dimensions.xcb_;
  37909. var ycb_ = dimensions.ycb_;
  37910. var codeblockWidth = 1 << xcb_;
  37911. var codeblockHeight = 1 << ycb_;
  37912. var cbx0 = subband.tbx0 >> xcb_;
  37913. var cby0 = subband.tby0 >> ycb_;
  37914. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  37915. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  37916. var precinctParameters = subband.resolution.precinctParameters;
  37917. var codeblocks = [];
  37918. var precincts = [];
  37919. var i, j, codeblock, precinctNumber;
  37920. for (j = cby0; j < cby1; j++) {
  37921. for (i = cbx0; i < cbx1; i++) {
  37922. codeblock = {
  37923. cbx: i,
  37924. cby: j,
  37925. tbx0: codeblockWidth * i,
  37926. tby0: codeblockHeight * j,
  37927. tbx1: codeblockWidth * (i + 1),
  37928. tby1: codeblockHeight * (j + 1)
  37929. };
  37930. // calculate precinct number
  37931. var pi = Math.floor((codeblock.tbx0 -
  37932. precinctParameters.precinctXOffset) /
  37933. precinctParameters.precinctWidth);
  37934. var pj = Math.floor((codeblock.tby0 -
  37935. precinctParameters.precinctYOffset) /
  37936. precinctParameters.precinctHeight);
  37937. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  37938. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  37939. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  37940. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  37941. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  37942. codeblock.precinctNumber = precinctNumber;
  37943. codeblock.subbandType = subband.type;
  37944. codeblock.Lblock = 3;
  37945. codeblocks.push(codeblock);
  37946. // building precinct for the sub-band
  37947. var precinct = precincts[precinctNumber];
  37948. if (precinct !== undefined) {
  37949. if (i < precinct.cbxMin) {
  37950. precinct.cbxMin = i;
  37951. } else if (i > precinct.cbxMax) {
  37952. precinct.cbxMax = i;
  37953. }
  37954. if (j < precinct.cbyMin) {
  37955. precinct.cbxMin = j;
  37956. } else if (j > precinct.cbyMax) {
  37957. precinct.cbyMax = j;
  37958. }
  37959. } else {
  37960. precincts[precinctNumber] = precinct = {
  37961. cbxMin: i,
  37962. cbyMin: j,
  37963. cbxMax: i,
  37964. cbyMax: j
  37965. };
  37966. }
  37967. codeblock.precinct = precinct;
  37968. }
  37969. }
  37970. subband.codeblockParameters = {
  37971. codeblockWidth: xcb_,
  37972. codeblockHeight: ycb_,
  37973. numcodeblockwide: cbx1 - cbx0 + 1,
  37974. numcodeblockhigh: cby1 - cby1 + 1
  37975. };
  37976. subband.codeblocks = codeblocks;
  37977. subband.precincts = precincts;
  37978. }
  37979. function createPacket(resolution, precinctNumber, layerNumber) {
  37980. var precinctCodeblocks = [];
  37981. // Section B.10.8 Order of info in packet
  37982. var subbands = resolution.subbands;
  37983. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  37984. for (var i = 0, ii = subbands.length; i < ii; i++) {
  37985. var subband = subbands[i];
  37986. var codeblocks = subband.codeblocks;
  37987. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  37988. var codeblock = codeblocks[j];
  37989. if (codeblock.precinctNumber !== precinctNumber) {
  37990. continue;
  37991. }
  37992. precinctCodeblocks.push(codeblock);
  37993. }
  37994. }
  37995. return {
  37996. layerNumber: layerNumber,
  37997. codeblocks: precinctCodeblocks
  37998. };
  37999. }
  38000. function LayerResolutionComponentPositionIterator(context) {
  38001. var siz = context.SIZ;
  38002. var tileIndex = context.currentTile.index;
  38003. var tile = context.tiles[tileIndex];
  38004. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  38005. var componentsCount = siz.Csiz;
  38006. var maxDecompositionLevelsCount = 0;
  38007. for (var q = 0; q < componentsCount; q++) {
  38008. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  38009. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  38010. }
  38011. var l = 0, r = 0, i = 0, k = 0;
  38012. this.nextPacket = function JpxImage_nextPacket() {
  38013. // Section B.12.1.1 Layer-resolution-component-position
  38014. for (; l < layersCount; l++) {
  38015. for (; r <= maxDecompositionLevelsCount; r++) {
  38016. for (; i < componentsCount; i++) {
  38017. var component = tile.components[i];
  38018. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  38019. continue;
  38020. }
  38021. var resolution = component.resolutions[r];
  38022. var numprecincts = resolution.precinctParameters.numprecincts;
  38023. for (; k < numprecincts;) {
  38024. var packet = createPacket(resolution, k, l);
  38025. k++;
  38026. return packet;
  38027. }
  38028. k = 0;
  38029. }
  38030. i = 0;
  38031. }
  38032. r = 0;
  38033. }
  38034. throw new Error('JPX Error: Out of packets');
  38035. };
  38036. }
  38037. function ResolutionLayerComponentPositionIterator(context) {
  38038. var siz = context.SIZ;
  38039. var tileIndex = context.currentTile.index;
  38040. var tile = context.tiles[tileIndex];
  38041. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  38042. var componentsCount = siz.Csiz;
  38043. var maxDecompositionLevelsCount = 0;
  38044. for (var q = 0; q < componentsCount; q++) {
  38045. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  38046. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  38047. }
  38048. var r = 0, l = 0, i = 0, k = 0;
  38049. this.nextPacket = function JpxImage_nextPacket() {
  38050. // Section B.12.1.2 Resolution-layer-component-position
  38051. for (; r <= maxDecompositionLevelsCount; r++) {
  38052. for (; l < layersCount; l++) {
  38053. for (; i < componentsCount; i++) {
  38054. var component = tile.components[i];
  38055. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  38056. continue;
  38057. }
  38058. var resolution = component.resolutions[r];
  38059. var numprecincts = resolution.precinctParameters.numprecincts;
  38060. for (; k < numprecincts;) {
  38061. var packet = createPacket(resolution, k, l);
  38062. k++;
  38063. return packet;
  38064. }
  38065. k = 0;
  38066. }
  38067. i = 0;
  38068. }
  38069. l = 0;
  38070. }
  38071. throw new Error('JPX Error: Out of packets');
  38072. };
  38073. }
  38074. function buildPackets(context) {
  38075. var siz = context.SIZ;
  38076. var tileIndex = context.currentTile.index;
  38077. var tile = context.tiles[tileIndex];
  38078. var componentsCount = siz.Csiz;
  38079. // Creating resolutions and sub-bands for each component
  38080. for (var c = 0; c < componentsCount; c++) {
  38081. var component = tile.components[c];
  38082. var decompositionLevelsCount =
  38083. component.codingStyleParameters.decompositionLevelsCount;
  38084. // Section B.5 Resolution levels and sub-bands
  38085. var resolutions = [];
  38086. var subbands = [];
  38087. for (var r = 0; r <= decompositionLevelsCount; r++) {
  38088. var blocksDimensions = getBlocksDimensions(context, component, r);
  38089. var resolution = {};
  38090. var scale = 1 << (decompositionLevelsCount - r);
  38091. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  38092. resolution.try0 = Math.ceil(component.tcy0 / scale);
  38093. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  38094. resolution.try1 = Math.ceil(component.tcy1 / scale);
  38095. buildPrecincts(context, resolution, blocksDimensions);
  38096. resolutions.push(resolution);
  38097. var subband;
  38098. if (r === 0) {
  38099. // one sub-band (LL) with last decomposition
  38100. subband = {};
  38101. subband.type = 'LL';
  38102. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  38103. subband.tby0 = Math.ceil(component.tcy0 / scale);
  38104. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  38105. subband.tby1 = Math.ceil(component.tcy1 / scale);
  38106. subband.resolution = resolution;
  38107. buildCodeblocks(context, subband, blocksDimensions);
  38108. subbands.push(subband);
  38109. resolution.subbands = [subband];
  38110. } else {
  38111. var bscale = 1 << (decompositionLevelsCount - r + 1);
  38112. var resolutionSubbands = [];
  38113. // three sub-bands (HL, LH and HH) with rest of decompositions
  38114. subband = {};
  38115. subband.type = 'HL';
  38116. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  38117. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  38118. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  38119. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  38120. subband.resolution = resolution;
  38121. buildCodeblocks(context, subband, blocksDimensions);
  38122. subbands.push(subband);
  38123. resolutionSubbands.push(subband);
  38124. subband = {};
  38125. subband.type = 'LH';
  38126. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  38127. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  38128. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  38129. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  38130. subband.resolution = resolution;
  38131. buildCodeblocks(context, subband, blocksDimensions);
  38132. subbands.push(subband);
  38133. resolutionSubbands.push(subband);
  38134. subband = {};
  38135. subband.type = 'HH';
  38136. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  38137. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  38138. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  38139. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  38140. subband.resolution = resolution;
  38141. buildCodeblocks(context, subband, blocksDimensions);
  38142. subbands.push(subband);
  38143. resolutionSubbands.push(subband);
  38144. resolution.subbands = resolutionSubbands;
  38145. }
  38146. }
  38147. component.resolutions = resolutions;
  38148. component.subbands = subbands;
  38149. }
  38150. // Generate the packets sequence
  38151. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  38152. switch (progressionOrder) {
  38153. case 0:
  38154. tile.packetsIterator =
  38155. new LayerResolutionComponentPositionIterator(context);
  38156. break;
  38157. case 1:
  38158. tile.packetsIterator =
  38159. new ResolutionLayerComponentPositionIterator(context);
  38160. break;
  38161. default:
  38162. throw new Error('JPX Error: Unsupported progression order ' +
  38163. progressionOrder);
  38164. }
  38165. }
  38166. function parseTilePackets(context, data, offset, dataLength) {
  38167. var position = 0;
  38168. var buffer, bufferSize = 0, skipNextBit = false;
  38169. function readBits(count) {
  38170. while (bufferSize < count) {
  38171. var b = data[offset + position];
  38172. position++;
  38173. if (skipNextBit) {
  38174. buffer = (buffer << 7) | b;
  38175. bufferSize += 7;
  38176. skipNextBit = false;
  38177. } else {
  38178. buffer = (buffer << 8) | b;
  38179. bufferSize += 8;
  38180. }
  38181. if (b === 0xFF) {
  38182. skipNextBit = true;
  38183. }
  38184. }
  38185. bufferSize -= count;
  38186. return (buffer >>> bufferSize) & ((1 << count) - 1);
  38187. }
  38188. function alignToByte() {
  38189. bufferSize = 0;
  38190. if (skipNextBit) {
  38191. position++;
  38192. skipNextBit = false;
  38193. }
  38194. }
  38195. function readCodingpasses() {
  38196. if (readBits(1) === 0) {
  38197. return 1;
  38198. }
  38199. if (readBits(1) === 0) {
  38200. return 2;
  38201. }
  38202. var value = readBits(2);
  38203. if (value < 3) {
  38204. return value + 3;
  38205. }
  38206. value = readBits(5);
  38207. if (value < 31) {
  38208. return value + 6;
  38209. }
  38210. value = readBits(7);
  38211. return value + 37;
  38212. }
  38213. var tileIndex = context.currentTile.index;
  38214. var tile = context.tiles[tileIndex];
  38215. var packetsIterator = tile.packetsIterator;
  38216. while (position < dataLength) {
  38217. var packet = packetsIterator.nextPacket();
  38218. if (!readBits(1)) {
  38219. alignToByte();
  38220. continue;
  38221. }
  38222. var layerNumber = packet.layerNumber;
  38223. var queue = [], codeblock;
  38224. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  38225. codeblock = packet.codeblocks[i];
  38226. var precinct = codeblock.precinct;
  38227. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  38228. var codeblockRow = codeblock.cby - precinct.cbyMin;
  38229. var codeblockIncluded = false;
  38230. var firstTimeInclusion = false;
  38231. var valueReady;
  38232. if ('included' in codeblock) {
  38233. codeblockIncluded = !!readBits(1);
  38234. } else {
  38235. // reading inclusion tree
  38236. precinct = codeblock.precinct;
  38237. var inclusionTree, zeroBitPlanesTree;
  38238. if ('inclusionTree' in precinct) {
  38239. inclusionTree = precinct.inclusionTree;
  38240. } else {
  38241. // building inclusion and zero bit-planes trees
  38242. var width = precinct.cbxMax - precinct.cbxMin + 1;
  38243. var height = precinct.cbyMax - precinct.cbyMin + 1;
  38244. inclusionTree = new InclusionTree(width, height, layerNumber);
  38245. zeroBitPlanesTree = new TagTree(width, height);
  38246. precinct.inclusionTree = inclusionTree;
  38247. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  38248. }
  38249. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  38250. while (true) {
  38251. if (readBits(1)) {
  38252. valueReady = !inclusionTree.nextLevel();
  38253. if (valueReady) {
  38254. codeblock.included = true;
  38255. codeblockIncluded = firstTimeInclusion = true;
  38256. break;
  38257. }
  38258. } else {
  38259. inclusionTree.incrementValue(layerNumber);
  38260. break;
  38261. }
  38262. }
  38263. }
  38264. }
  38265. if (!codeblockIncluded) {
  38266. continue;
  38267. }
  38268. if (firstTimeInclusion) {
  38269. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  38270. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  38271. while (true) {
  38272. if (readBits(1)) {
  38273. valueReady = !zeroBitPlanesTree.nextLevel();
  38274. if (valueReady) {
  38275. break;
  38276. }
  38277. } else {
  38278. zeroBitPlanesTree.incrementValue();
  38279. }
  38280. }
  38281. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  38282. }
  38283. var codingpasses = readCodingpasses();
  38284. while (readBits(1)) {
  38285. codeblock.Lblock++;
  38286. }
  38287. var codingpassesLog2 = log2(codingpasses);
  38288. // rounding down log2
  38289. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  38290. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  38291. var codedDataLength = readBits(bits);
  38292. queue.push({
  38293. codeblock: codeblock,
  38294. codingpasses: codingpasses,
  38295. dataLength: codedDataLength
  38296. });
  38297. }
  38298. alignToByte();
  38299. while (queue.length > 0) {
  38300. var packetItem = queue.shift();
  38301. codeblock = packetItem.codeblock;
  38302. if (!('data' in codeblock)) {
  38303. codeblock.data = [];
  38304. }
  38305. codeblock.data.push({
  38306. data: data,
  38307. start: offset + position,
  38308. end: offset + position + packetItem.dataLength,
  38309. codingpasses: packetItem.codingpasses
  38310. });
  38311. position += packetItem.dataLength;
  38312. }
  38313. }
  38314. return position;
  38315. }
  38316. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  38317. delta, mb, reversible, segmentationSymbolUsed) {
  38318. var x0 = subband.tbx0;
  38319. var y0 = subband.tby0;
  38320. var width = subband.tbx1 - subband.tbx0;
  38321. var codeblocks = subband.codeblocks;
  38322. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  38323. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  38324. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  38325. var codeblock = codeblocks[i];
  38326. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  38327. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  38328. if (blockWidth === 0 || blockHeight === 0) {
  38329. continue;
  38330. }
  38331. if (!('data' in codeblock)) {
  38332. continue;
  38333. }
  38334. var bitModel, currentCodingpassType;
  38335. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  38336. codeblock.zeroBitPlanes, mb);
  38337. currentCodingpassType = 2; // first bit plane starts from cleanup
  38338. // collect data
  38339. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  38340. var j, jj, dataItem;
  38341. for (j = 0, jj = data.length; j < jj; j++) {
  38342. dataItem = data[j];
  38343. totalLength += dataItem.end - dataItem.start;
  38344. codingpasses += dataItem.codingpasses;
  38345. }
  38346. var encodedData = new Uint8Array(totalLength);
  38347. var position = 0;
  38348. for (j = 0, jj = data.length; j < jj; j++) {
  38349. dataItem = data[j];
  38350. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  38351. encodedData.set(chunk, position);
  38352. position += chunk.length;
  38353. }
  38354. // decoding the item
  38355. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  38356. bitModel.setDecoder(decoder);
  38357. for (j = 0; j < codingpasses; j++) {
  38358. switch (currentCodingpassType) {
  38359. case 0:
  38360. bitModel.runSignificancePropogationPass();
  38361. break;
  38362. case 1:
  38363. bitModel.runMagnitudeRefinementPass();
  38364. break;
  38365. case 2:
  38366. bitModel.runCleanupPass();
  38367. if (segmentationSymbolUsed) {
  38368. bitModel.checkSegmentationSymbol();
  38369. }
  38370. break;
  38371. }
  38372. currentCodingpassType = (currentCodingpassType + 1) % 3;
  38373. }
  38374. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  38375. var sign = bitModel.coefficentsSign;
  38376. var magnitude = bitModel.coefficentsMagnitude;
  38377. var bitsDecoded = bitModel.bitsDecoded;
  38378. var magnitudeCorrection = reversible ? 0 : 0.5;
  38379. var k, n, nb;
  38380. position = 0;
  38381. // Do the interleaving of Section F.3.3 here, so we do not need
  38382. // to copy later. LL level is not interleaved, just copied.
  38383. var interleave = (subband.type !== 'LL');
  38384. for (j = 0; j < blockHeight; j++) {
  38385. var row = (offset / width) | 0; // row in the non-interleaved subband
  38386. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  38387. for (k = 0; k < blockWidth; k++) {
  38388. n = magnitude[position];
  38389. if (n !== 0) {
  38390. n = (n + magnitudeCorrection) * delta;
  38391. if (sign[position] !== 0) {
  38392. n = -n;
  38393. }
  38394. nb = bitsDecoded[position];
  38395. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  38396. if (reversible && (nb >= mb)) {
  38397. coefficients[pos] = n;
  38398. } else {
  38399. coefficients[pos] = n * (1 << (mb - nb));
  38400. }
  38401. }
  38402. offset++;
  38403. position++;
  38404. }
  38405. offset += width - blockWidth;
  38406. }
  38407. }
  38408. }
  38409. function transformTile(context, tile, c) {
  38410. var component = tile.components[c];
  38411. var codingStyleParameters = component.codingStyleParameters;
  38412. var quantizationParameters = component.quantizationParameters;
  38413. var decompositionLevelsCount =
  38414. codingStyleParameters.decompositionLevelsCount;
  38415. var spqcds = quantizationParameters.SPqcds;
  38416. var scalarExpounded = quantizationParameters.scalarExpounded;
  38417. var guardBits = quantizationParameters.guardBits;
  38418. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  38419. var precision = context.components[c].precision;
  38420. var reversible = codingStyleParameters.reversibleTransformation;
  38421. var transform = (reversible ? new ReversibleTransform() :
  38422. new IrreversibleTransform());
  38423. var subbandCoefficients = [];
  38424. var b = 0;
  38425. for (var i = 0; i <= decompositionLevelsCount; i++) {
  38426. var resolution = component.resolutions[i];
  38427. var width = resolution.trx1 - resolution.trx0;
  38428. var height = resolution.try1 - resolution.try0;
  38429. // Allocate space for the whole sublevel.
  38430. var coefficients = new Float32Array(width * height);
  38431. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  38432. var mu, epsilon;
  38433. if (!scalarExpounded) {
  38434. // formula E-5
  38435. mu = spqcds[0].mu;
  38436. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  38437. } else {
  38438. mu = spqcds[b].mu;
  38439. epsilon = spqcds[b].epsilon;
  38440. b++;
  38441. }
  38442. var subband = resolution.subbands[j];
  38443. var gainLog2 = SubbandsGainLog2[subband.type];
  38444. // calulate quantization coefficient (Section E.1.1.1)
  38445. var delta = (reversible ? 1 :
  38446. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  38447. var mb = (guardBits + epsilon - 1);
  38448. // In the first resolution level, copyCoefficients will fill the
  38449. // whole array with coefficients. In the succeding passes,
  38450. // copyCoefficients will consecutively fill in the values that belong
  38451. // to the interleaved positions of the HL, LH, and HH coefficients.
  38452. // The LL coefficients will then be interleaved in Transform.iterate().
  38453. copyCoefficients(coefficients, width, height, subband, delta, mb,
  38454. reversible, segmentationSymbolUsed);
  38455. }
  38456. subbandCoefficients.push({
  38457. width: width,
  38458. height: height,
  38459. items: coefficients
  38460. });
  38461. }
  38462. var result = transform.calculate(subbandCoefficients,
  38463. component.tcx0, component.tcy0);
  38464. return {
  38465. left: component.tcx0,
  38466. top: component.tcy0,
  38467. width: result.width,
  38468. height: result.height,
  38469. items: result.items
  38470. };
  38471. }
  38472. function transformComponents(context) {
  38473. var siz = context.SIZ;
  38474. var components = context.components;
  38475. var componentsCount = siz.Csiz;
  38476. var resultImages = [];
  38477. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  38478. var tile = context.tiles[i];
  38479. var transformedTiles = [];
  38480. var c;
  38481. for (c = 0; c < componentsCount; c++) {
  38482. transformedTiles[c] = transformTile(context, tile, c);
  38483. }
  38484. var tile0 = transformedTiles[0];
  38485. var out = new Uint8Array(tile0.items.length * componentsCount);
  38486. var result = {
  38487. left: tile0.left,
  38488. top: tile0.top,
  38489. width: tile0.width,
  38490. height: tile0.height,
  38491. items: out
  38492. };
  38493. // Section G.2.2 Inverse multi component transform
  38494. var shift, offset, max, min, maxK;
  38495. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  38496. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  38497. var fourComponents = componentsCount === 4;
  38498. var y0items = transformedTiles[0].items;
  38499. var y1items = transformedTiles[1].items;
  38500. var y2items = transformedTiles[2].items;
  38501. var y3items = fourComponents ? transformedTiles[3].items : null;
  38502. // HACK: The multiple component transform formulas below assume that
  38503. // all components have the same precision. With this in mind, we
  38504. // compute shift and offset only once.
  38505. shift = components[0].precision - 8;
  38506. offset = (128 << shift) + 0.5;
  38507. max = 255 * (1 << shift);
  38508. maxK = max * 0.5;
  38509. min = -maxK;
  38510. var component0 = tile.components[0];
  38511. var alpha01 = componentsCount - 3;
  38512. jj = y0items.length;
  38513. if (!component0.codingStyleParameters.reversibleTransformation) {
  38514. // inverse irreversible multiple component transform
  38515. for (j = 0; j < jj; j++, pos += alpha01) {
  38516. y0 = y0items[j] + offset;
  38517. y1 = y1items[j];
  38518. y2 = y2items[j];
  38519. r = y0 + 1.402 * y2;
  38520. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  38521. b = y0 + 1.772 * y1;
  38522. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  38523. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  38524. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  38525. }
  38526. } else {
  38527. // inverse reversible multiple component transform
  38528. for (j = 0; j < jj; j++, pos += alpha01) {
  38529. y0 = y0items[j] + offset;
  38530. y1 = y1items[j];
  38531. y2 = y2items[j];
  38532. g = y0 - ((y2 + y1) >> 2);
  38533. r = g + y2;
  38534. b = g + y1;
  38535. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  38536. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  38537. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  38538. }
  38539. }
  38540. if (fourComponents) {
  38541. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  38542. k = y3items[j];
  38543. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  38544. }
  38545. }
  38546. } else { // no multi-component transform
  38547. for (c = 0; c < componentsCount; c++) {
  38548. var items = transformedTiles[c].items;
  38549. shift = components[c].precision - 8;
  38550. offset = (128 << shift) + 0.5;
  38551. max = (127.5 * (1 << shift));
  38552. min = -max;
  38553. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  38554. val = items[j];
  38555. out[pos] = val <= min ? 0 :
  38556. val >= max ? 255 : (val + offset) >> shift;
  38557. pos += componentsCount;
  38558. }
  38559. }
  38560. }
  38561. resultImages.push(result);
  38562. }
  38563. return resultImages;
  38564. }
  38565. function initializeTile(context, tileIndex) {
  38566. var siz = context.SIZ;
  38567. var componentsCount = siz.Csiz;
  38568. var tile = context.tiles[tileIndex];
  38569. for (var c = 0; c < componentsCount; c++) {
  38570. var component = tile.components[c];
  38571. var qcdOrQcc = (c in context.currentTile.QCC ?
  38572. context.currentTile.QCC[c] : context.currentTile.QCD);
  38573. component.quantizationParameters = qcdOrQcc;
  38574. var codOrCoc = (c in context.currentTile.COC ?
  38575. context.currentTile.COC[c] : context.currentTile.COD);
  38576. component.codingStyleParameters = codOrCoc;
  38577. }
  38578. tile.codingStyleDefaultParameters = context.currentTile.COD;
  38579. }
  38580. // Section B.10.2 Tag trees
  38581. var TagTree = (function TagTreeClosure() {
  38582. function TagTree(width, height) {
  38583. var levelsLength = log2(Math.max(width, height)) + 1;
  38584. this.levels = [];
  38585. for (var i = 0; i < levelsLength; i++) {
  38586. var level = {
  38587. width: width,
  38588. height: height,
  38589. items: []
  38590. };
  38591. this.levels.push(level);
  38592. width = Math.ceil(width / 2);
  38593. height = Math.ceil(height / 2);
  38594. }
  38595. }
  38596. TagTree.prototype = {
  38597. reset: function TagTree_reset(i, j) {
  38598. var currentLevel = 0, value = 0, level;
  38599. while (currentLevel < this.levels.length) {
  38600. level = this.levels[currentLevel];
  38601. var index = i + j * level.width;
  38602. if (index in level.items) {
  38603. value = level.items[index];
  38604. break;
  38605. }
  38606. level.index = index;
  38607. i >>= 1;
  38608. j >>= 1;
  38609. currentLevel++;
  38610. }
  38611. currentLevel--;
  38612. level = this.levels[currentLevel];
  38613. level.items[level.index] = value;
  38614. this.currentLevel = currentLevel;
  38615. delete this.value;
  38616. },
  38617. incrementValue: function TagTree_incrementValue() {
  38618. var level = this.levels[this.currentLevel];
  38619. level.items[level.index]++;
  38620. },
  38621. nextLevel: function TagTree_nextLevel() {
  38622. var currentLevel = this.currentLevel;
  38623. var level = this.levels[currentLevel];
  38624. var value = level.items[level.index];
  38625. currentLevel--;
  38626. if (currentLevel < 0) {
  38627. this.value = value;
  38628. return false;
  38629. }
  38630. this.currentLevel = currentLevel;
  38631. level = this.levels[currentLevel];
  38632. level.items[level.index] = value;
  38633. return true;
  38634. }
  38635. };
  38636. return TagTree;
  38637. })();
  38638. var InclusionTree = (function InclusionTreeClosure() {
  38639. function InclusionTree(width, height, defaultValue) {
  38640. var levelsLength = log2(Math.max(width, height)) + 1;
  38641. this.levels = [];
  38642. for (var i = 0; i < levelsLength; i++) {
  38643. var items = new Uint8Array(width * height);
  38644. for (var j = 0, jj = items.length; j < jj; j++) {
  38645. items[j] = defaultValue;
  38646. }
  38647. var level = {
  38648. width: width,
  38649. height: height,
  38650. items: items
  38651. };
  38652. this.levels.push(level);
  38653. width = Math.ceil(width / 2);
  38654. height = Math.ceil(height / 2);
  38655. }
  38656. }
  38657. InclusionTree.prototype = {
  38658. reset: function InclusionTree_reset(i, j, stopValue) {
  38659. var currentLevel = 0;
  38660. while (currentLevel < this.levels.length) {
  38661. var level = this.levels[currentLevel];
  38662. var index = i + j * level.width;
  38663. level.index = index;
  38664. var value = level.items[index];
  38665. if (value === 0xFF) {
  38666. break;
  38667. }
  38668. if (value > stopValue) {
  38669. this.currentLevel = currentLevel;
  38670. // already know about this one, propagating the value to top levels
  38671. this.propagateValues();
  38672. return false;
  38673. }
  38674. i >>= 1;
  38675. j >>= 1;
  38676. currentLevel++;
  38677. }
  38678. this.currentLevel = currentLevel - 1;
  38679. return true;
  38680. },
  38681. incrementValue: function InclusionTree_incrementValue(stopValue) {
  38682. var level = this.levels[this.currentLevel];
  38683. level.items[level.index] = stopValue + 1;
  38684. this.propagateValues();
  38685. },
  38686. propagateValues: function InclusionTree_propagateValues() {
  38687. var levelIndex = this.currentLevel;
  38688. var level = this.levels[levelIndex];
  38689. var currentValue = level.items[level.index];
  38690. while (--levelIndex >= 0) {
  38691. level = this.levels[levelIndex];
  38692. level.items[level.index] = currentValue;
  38693. }
  38694. },
  38695. nextLevel: function InclusionTree_nextLevel() {
  38696. var currentLevel = this.currentLevel;
  38697. var level = this.levels[currentLevel];
  38698. var value = level.items[level.index];
  38699. level.items[level.index] = 0xFF;
  38700. currentLevel--;
  38701. if (currentLevel < 0) {
  38702. return false;
  38703. }
  38704. this.currentLevel = currentLevel;
  38705. level = this.levels[currentLevel];
  38706. level.items[level.index] = value;
  38707. return true;
  38708. }
  38709. };
  38710. return InclusionTree;
  38711. })();
  38712. // Section D. Coefficient bit modeling
  38713. var BitModel = (function BitModelClosure() {
  38714. var UNIFORM_CONTEXT = 17;
  38715. var RUNLENGTH_CONTEXT = 18;
  38716. // Table D-1
  38717. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  38718. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  38719. var LLAndLHContextsLabel = new Uint8Array([
  38720. 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,
  38721. 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,
  38722. 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
  38723. ]);
  38724. var HLContextLabel = new Uint8Array([
  38725. 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,
  38726. 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,
  38727. 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
  38728. ]);
  38729. var HHContextLabel = new Uint8Array([
  38730. 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,
  38731. 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,
  38732. 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
  38733. ]);
  38734. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  38735. this.width = width;
  38736. this.height = height;
  38737. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  38738. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  38739. var coefficientCount = width * height;
  38740. // coefficients outside the encoding region treated as insignificant
  38741. // add border state cells for significanceState
  38742. this.neighborsSignificance = new Uint8Array(coefficientCount);
  38743. this.coefficentsSign = new Uint8Array(coefficientCount);
  38744. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  38745. mb > 6 ? new Uint16Array(coefficientCount) :
  38746. new Uint8Array(coefficientCount);
  38747. this.processingFlags = new Uint8Array(coefficientCount);
  38748. var bitsDecoded = new Uint8Array(coefficientCount);
  38749. if (zeroBitPlanes !== 0) {
  38750. for (var i = 0; i < coefficientCount; i++) {
  38751. bitsDecoded[i] = zeroBitPlanes;
  38752. }
  38753. }
  38754. this.bitsDecoded = bitsDecoded;
  38755. this.reset();
  38756. }
  38757. BitModel.prototype = {
  38758. setDecoder: function BitModel_setDecoder(decoder) {
  38759. this.decoder = decoder;
  38760. },
  38761. reset: function BitModel_reset() {
  38762. // We have 17 contexts that are accessed via context labels,
  38763. // plus the uniform and runlength context.
  38764. this.contexts = new Int8Array(19);
  38765. // Contexts are packed into 1 byte:
  38766. // highest 7 bits carry the index, lowest bit carries mps
  38767. this.contexts[0] = (4 << 1) | 0;
  38768. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  38769. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  38770. },
  38771. setNeighborsSignificance:
  38772. function BitModel_setNeighborsSignificance(row, column, index) {
  38773. var neighborsSignificance = this.neighborsSignificance;
  38774. var width = this.width, height = this.height;
  38775. var left = (column > 0);
  38776. var right = (column + 1 < width);
  38777. var i;
  38778. if (row > 0) {
  38779. i = index - width;
  38780. if (left) {
  38781. neighborsSignificance[i - 1] += 0x10;
  38782. }
  38783. if (right) {
  38784. neighborsSignificance[i + 1] += 0x10;
  38785. }
  38786. neighborsSignificance[i] += 0x04;
  38787. }
  38788. if (row + 1 < height) {
  38789. i = index + width;
  38790. if (left) {
  38791. neighborsSignificance[i - 1] += 0x10;
  38792. }
  38793. if (right) {
  38794. neighborsSignificance[i + 1] += 0x10;
  38795. }
  38796. neighborsSignificance[i] += 0x04;
  38797. }
  38798. if (left) {
  38799. neighborsSignificance[index - 1] += 0x01;
  38800. }
  38801. if (right) {
  38802. neighborsSignificance[index + 1] += 0x01;
  38803. }
  38804. neighborsSignificance[index] |= 0x80;
  38805. },
  38806. runSignificancePropogationPass:
  38807. function BitModel_runSignificancePropogationPass() {
  38808. var decoder = this.decoder;
  38809. var width = this.width, height = this.height;
  38810. var coefficentsMagnitude = this.coefficentsMagnitude;
  38811. var coefficentsSign = this.coefficentsSign;
  38812. var neighborsSignificance = this.neighborsSignificance;
  38813. var processingFlags = this.processingFlags;
  38814. var contexts = this.contexts;
  38815. var labels = this.contextLabelTable;
  38816. var bitsDecoded = this.bitsDecoded;
  38817. var processedInverseMask = ~1;
  38818. var processedMask = 1;
  38819. var firstMagnitudeBitMask = 2;
  38820. for (var i0 = 0; i0 < height; i0 += 4) {
  38821. for (var j = 0; j < width; j++) {
  38822. var index = i0 * width + j;
  38823. for (var i1 = 0; i1 < 4; i1++, index += width) {
  38824. var i = i0 + i1;
  38825. if (i >= height) {
  38826. break;
  38827. }
  38828. // clear processed flag first
  38829. processingFlags[index] &= processedInverseMask;
  38830. if (coefficentsMagnitude[index] ||
  38831. !neighborsSignificance[index]) {
  38832. continue;
  38833. }
  38834. var contextLabel = labels[neighborsSignificance[index]];
  38835. var decision = decoder.readBit(contexts, contextLabel);
  38836. if (decision) {
  38837. var sign = this.decodeSignBit(i, j, index);
  38838. coefficentsSign[index] = sign;
  38839. coefficentsMagnitude[index] = 1;
  38840. this.setNeighborsSignificance(i, j, index);
  38841. processingFlags[index] |= firstMagnitudeBitMask;
  38842. }
  38843. bitsDecoded[index]++;
  38844. processingFlags[index] |= processedMask;
  38845. }
  38846. }
  38847. }
  38848. },
  38849. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  38850. var width = this.width, height = this.height;
  38851. var coefficentsMagnitude = this.coefficentsMagnitude;
  38852. var coefficentsSign = this.coefficentsSign;
  38853. var contribution, sign0, sign1, significance1;
  38854. var contextLabel, decoded;
  38855. // calculate horizontal contribution
  38856. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  38857. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  38858. sign1 = coefficentsSign[index + 1];
  38859. if (significance1) {
  38860. sign0 = coefficentsSign[index - 1];
  38861. contribution = 1 - sign1 - sign0;
  38862. } else {
  38863. contribution = 1 - sign1 - sign1;
  38864. }
  38865. } else if (significance1) {
  38866. sign0 = coefficentsSign[index - 1];
  38867. contribution = 1 - sign0 - sign0;
  38868. } else {
  38869. contribution = 0;
  38870. }
  38871. var horizontalContribution = 3 * contribution;
  38872. // calculate vertical contribution and combine with the horizontal
  38873. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  38874. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  38875. sign1 = coefficentsSign[index + width];
  38876. if (significance1) {
  38877. sign0 = coefficentsSign[index - width];
  38878. contribution = 1 - sign1 - sign0 + horizontalContribution;
  38879. } else {
  38880. contribution = 1 - sign1 - sign1 + horizontalContribution;
  38881. }
  38882. } else if (significance1) {
  38883. sign0 = coefficentsSign[index - width];
  38884. contribution = 1 - sign0 - sign0 + horizontalContribution;
  38885. } else {
  38886. contribution = horizontalContribution;
  38887. }
  38888. if (contribution >= 0) {
  38889. contextLabel = 9 + contribution;
  38890. decoded = this.decoder.readBit(this.contexts, contextLabel);
  38891. } else {
  38892. contextLabel = 9 - contribution;
  38893. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  38894. }
  38895. return decoded;
  38896. },
  38897. runMagnitudeRefinementPass:
  38898. function BitModel_runMagnitudeRefinementPass() {
  38899. var decoder = this.decoder;
  38900. var width = this.width, height = this.height;
  38901. var coefficentsMagnitude = this.coefficentsMagnitude;
  38902. var neighborsSignificance = this.neighborsSignificance;
  38903. var contexts = this.contexts;
  38904. var bitsDecoded = this.bitsDecoded;
  38905. var processingFlags = this.processingFlags;
  38906. var processedMask = 1;
  38907. var firstMagnitudeBitMask = 2;
  38908. var length = width * height;
  38909. var width4 = width * 4;
  38910. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  38911. indexNext = Math.min(length, index0 + width4);
  38912. for (var j = 0; j < width; j++) {
  38913. for (var index = index0 + j; index < indexNext; index += width) {
  38914. // significant but not those that have just become
  38915. if (!coefficentsMagnitude[index] ||
  38916. (processingFlags[index] & processedMask) !== 0) {
  38917. continue;
  38918. }
  38919. var contextLabel = 16;
  38920. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  38921. processingFlags[index] ^= firstMagnitudeBitMask;
  38922. // first refinement
  38923. var significance = neighborsSignificance[index] & 127;
  38924. contextLabel = significance === 0 ? 15 : 14;
  38925. }
  38926. var bit = decoder.readBit(contexts, contextLabel);
  38927. coefficentsMagnitude[index] =
  38928. (coefficentsMagnitude[index] << 1) | bit;
  38929. bitsDecoded[index]++;
  38930. processingFlags[index] |= processedMask;
  38931. }
  38932. }
  38933. }
  38934. },
  38935. runCleanupPass: function BitModel_runCleanupPass() {
  38936. var decoder = this.decoder;
  38937. var width = this.width, height = this.height;
  38938. var neighborsSignificance = this.neighborsSignificance;
  38939. var coefficentsMagnitude = this.coefficentsMagnitude;
  38940. var coefficentsSign = this.coefficentsSign;
  38941. var contexts = this.contexts;
  38942. var labels = this.contextLabelTable;
  38943. var bitsDecoded = this.bitsDecoded;
  38944. var processingFlags = this.processingFlags;
  38945. var processedMask = 1;
  38946. var firstMagnitudeBitMask = 2;
  38947. var oneRowDown = width;
  38948. var twoRowsDown = width * 2;
  38949. var threeRowsDown = width * 3;
  38950. var iNext;
  38951. for (var i0 = 0; i0 < height; i0 = iNext) {
  38952. iNext = Math.min(i0 + 4, height);
  38953. var indexBase = i0 * width;
  38954. var checkAllEmpty = i0 + 3 < height;
  38955. for (var j = 0; j < width; j++) {
  38956. var index0 = indexBase + j;
  38957. // using the property: labels[neighborsSignificance[index]] === 0
  38958. // when neighborsSignificance[index] === 0
  38959. var allEmpty = (checkAllEmpty &&
  38960. processingFlags[index0] === 0 &&
  38961. processingFlags[index0 + oneRowDown] === 0 &&
  38962. processingFlags[index0 + twoRowsDown] === 0 &&
  38963. processingFlags[index0 + threeRowsDown] === 0 &&
  38964. neighborsSignificance[index0] === 0 &&
  38965. neighborsSignificance[index0 + oneRowDown] === 0 &&
  38966. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  38967. neighborsSignificance[index0 + threeRowsDown] === 0);
  38968. var i1 = 0, index = index0;
  38969. var i = i0, sign;
  38970. if (allEmpty) {
  38971. var hasSignificantCoefficent =
  38972. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  38973. if (!hasSignificantCoefficent) {
  38974. bitsDecoded[index0]++;
  38975. bitsDecoded[index0 + oneRowDown]++;
  38976. bitsDecoded[index0 + twoRowsDown]++;
  38977. bitsDecoded[index0 + threeRowsDown]++;
  38978. continue; // next column
  38979. }
  38980. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  38981. decoder.readBit(contexts, UNIFORM_CONTEXT);
  38982. if (i1 !== 0) {
  38983. i = i0 + i1;
  38984. index += i1 * width;
  38985. }
  38986. sign = this.decodeSignBit(i, j, index);
  38987. coefficentsSign[index] = sign;
  38988. coefficentsMagnitude[index] = 1;
  38989. this.setNeighborsSignificance(i, j, index);
  38990. processingFlags[index] |= firstMagnitudeBitMask;
  38991. index = index0;
  38992. for (var i2 = i0; i2 <= i; i2++, index += width) {
  38993. bitsDecoded[index]++;
  38994. }
  38995. i1++;
  38996. }
  38997. for (i = i0 + i1; i < iNext; i++, index += width) {
  38998. if (coefficentsMagnitude[index] ||
  38999. (processingFlags[index] & processedMask) !== 0) {
  39000. continue;
  39001. }
  39002. var contextLabel = labels[neighborsSignificance[index]];
  39003. var decision = decoder.readBit(contexts, contextLabel);
  39004. if (decision === 1) {
  39005. sign = this.decodeSignBit(i, j, index);
  39006. coefficentsSign[index] = sign;
  39007. coefficentsMagnitude[index] = 1;
  39008. this.setNeighborsSignificance(i, j, index);
  39009. processingFlags[index] |= firstMagnitudeBitMask;
  39010. }
  39011. bitsDecoded[index]++;
  39012. }
  39013. }
  39014. }
  39015. },
  39016. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  39017. var decoder = this.decoder;
  39018. var contexts = this.contexts;
  39019. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  39020. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  39021. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  39022. decoder.readBit(contexts, UNIFORM_CONTEXT);
  39023. if (symbol !== 0xA) {
  39024. throw new Error('JPX Error: Invalid segmentation symbol');
  39025. }
  39026. }
  39027. };
  39028. return BitModel;
  39029. })();
  39030. // Section F, Discrete wavelet transformation
  39031. var Transform = (function TransformClosure() {
  39032. function Transform() {}
  39033. Transform.prototype.calculate =
  39034. function transformCalculate(subbands, u0, v0) {
  39035. var ll = subbands[0];
  39036. for (var i = 1, ii = subbands.length; i < ii; i++) {
  39037. ll = this.iterate(ll, subbands[i], u0, v0);
  39038. }
  39039. return ll;
  39040. };
  39041. Transform.prototype.extend = function extend(buffer, offset, size) {
  39042. // Section F.3.7 extending... using max extension of 4
  39043. var i1 = offset - 1, j1 = offset + 1;
  39044. var i2 = offset + size - 2, j2 = offset + size;
  39045. buffer[i1--] = buffer[j1++];
  39046. buffer[j2++] = buffer[i2--];
  39047. buffer[i1--] = buffer[j1++];
  39048. buffer[j2++] = buffer[i2--];
  39049. buffer[i1--] = buffer[j1++];
  39050. buffer[j2++] = buffer[i2--];
  39051. buffer[i1] = buffer[j1];
  39052. buffer[j2] = buffer[i2];
  39053. };
  39054. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  39055. u0, v0) {
  39056. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  39057. var width = hl_lh_hh.width;
  39058. var height = hl_lh_hh.height;
  39059. var items = hl_lh_hh.items;
  39060. var i, j, k, l, u, v;
  39061. // Interleave LL according to Section F.3.3
  39062. for (k = 0, i = 0; i < llHeight; i++) {
  39063. l = i * 2 * width;
  39064. for (j = 0; j < llWidth; j++, k++, l += 2) {
  39065. items[l] = llItems[k];
  39066. }
  39067. }
  39068. // The LL band is not needed anymore.
  39069. llItems = ll.items = null;
  39070. var bufferPadding = 4;
  39071. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  39072. // Section F.3.4 HOR_SR
  39073. if (width === 1) {
  39074. // if width = 1, when u0 even keep items as is, when odd divide by 2
  39075. if ((u0 & 1) !== 0) {
  39076. for (v = 0, k = 0; v < height; v++, k += width) {
  39077. items[k] *= 0.5;
  39078. }
  39079. }
  39080. } else {
  39081. for (v = 0, k = 0; v < height; v++, k += width) {
  39082. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  39083. this.extend(rowBuffer, bufferPadding, width);
  39084. this.filter(rowBuffer, bufferPadding, width);
  39085. items.set(
  39086. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  39087. k);
  39088. }
  39089. }
  39090. // Accesses to the items array can take long, because it may not fit into
  39091. // CPU cache and has to be fetched from main memory. Since subsequent
  39092. // accesses to the items array are not local when reading columns, we
  39093. // have a cache miss every time. To reduce cache misses, get up to
  39094. // 'numBuffers' items at a time and store them into the individual
  39095. // buffers. The colBuffers should be small enough to fit into CPU cache.
  39096. var numBuffers = 16;
  39097. var colBuffers = [];
  39098. for (i = 0; i < numBuffers; i++) {
  39099. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  39100. }
  39101. var b, currentBuffer = 0;
  39102. ll = bufferPadding + height;
  39103. // Section F.3.5 VER_SR
  39104. if (height === 1) {
  39105. // if height = 1, when v0 even keep items as is, when odd divide by 2
  39106. if ((v0 & 1) !== 0) {
  39107. for (u = 0; u < width; u++) {
  39108. items[u] *= 0.5;
  39109. }
  39110. }
  39111. } else {
  39112. for (u = 0; u < width; u++) {
  39113. // if we ran out of buffers, copy several image columns at once
  39114. if (currentBuffer === 0) {
  39115. numBuffers = Math.min(width - u, numBuffers);
  39116. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  39117. for (b = 0; b < numBuffers; b++) {
  39118. colBuffers[b][l] = items[k + b];
  39119. }
  39120. }
  39121. currentBuffer = numBuffers;
  39122. }
  39123. currentBuffer--;
  39124. var buffer = colBuffers[currentBuffer];
  39125. this.extend(buffer, bufferPadding, height);
  39126. this.filter(buffer, bufferPadding, height);
  39127. // If this is last buffer in this group of buffers, flush all buffers.
  39128. if (currentBuffer === 0) {
  39129. k = u - numBuffers + 1;
  39130. for (l = bufferPadding; l < ll; k += width, l++) {
  39131. for (b = 0; b < numBuffers; b++) {
  39132. items[k + b] = colBuffers[b][l];
  39133. }
  39134. }
  39135. }
  39136. }
  39137. }
  39138. return {
  39139. width: width,
  39140. height: height,
  39141. items: items
  39142. };
  39143. };
  39144. return Transform;
  39145. })();
  39146. // Section 3.8.2 Irreversible 9-7 filter
  39147. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  39148. function IrreversibleTransform() {
  39149. Transform.call(this);
  39150. }
  39151. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  39152. IrreversibleTransform.prototype.filter =
  39153. function irreversibleTransformFilter(x, offset, length) {
  39154. var len = length >> 1;
  39155. offset = offset | 0;
  39156. var j, n, current, next;
  39157. var alpha = -1.586134342059924;
  39158. var beta = -0.052980118572961;
  39159. var gamma = 0.882911075530934;
  39160. var delta = 0.443506852043971;
  39161. var K = 1.230174104914001;
  39162. var K_ = 1 / K;
  39163. // step 1 is combined with step 3
  39164. // step 2
  39165. j = offset - 3;
  39166. for (n = len + 4; n--; j += 2) {
  39167. x[j] *= K_;
  39168. }
  39169. // step 1 & 3
  39170. j = offset - 2;
  39171. current = delta * x[j -1];
  39172. for (n = len + 3; n--; j += 2) {
  39173. next = delta * x[j + 1];
  39174. x[j] = K * x[j] - current - next;
  39175. if (n--) {
  39176. j += 2;
  39177. current = delta * x[j + 1];
  39178. x[j] = K * x[j] - current - next;
  39179. } else {
  39180. break;
  39181. }
  39182. }
  39183. // step 4
  39184. j = offset - 1;
  39185. current = gamma * x[j - 1];
  39186. for (n = len + 2; n--; j += 2) {
  39187. next = gamma * x[j + 1];
  39188. x[j] -= current + next;
  39189. if (n--) {
  39190. j += 2;
  39191. current = gamma * x[j + 1];
  39192. x[j] -= current + next;
  39193. } else {
  39194. break;
  39195. }
  39196. }
  39197. // step 5
  39198. j = offset;
  39199. current = beta * x[j - 1];
  39200. for (n = len + 1; n--; j += 2) {
  39201. next = beta * x[j + 1];
  39202. x[j] -= current + next;
  39203. if (n--) {
  39204. j += 2;
  39205. current = beta * x[j + 1];
  39206. x[j] -= current + next;
  39207. } else {
  39208. break;
  39209. }
  39210. }
  39211. // step 6
  39212. if (len !== 0) {
  39213. j = offset + 1;
  39214. current = alpha * x[j - 1];
  39215. for (n = len; n--; j += 2) {
  39216. next = alpha * x[j + 1];
  39217. x[j] -= current + next;
  39218. if (n--) {
  39219. j += 2;
  39220. current = alpha * x[j + 1];
  39221. x[j] -= current + next;
  39222. } else {
  39223. break;
  39224. }
  39225. }
  39226. }
  39227. };
  39228. return IrreversibleTransform;
  39229. })();
  39230. // Section 3.8.1 Reversible 5-3 filter
  39231. var ReversibleTransform = (function ReversibleTransformClosure() {
  39232. function ReversibleTransform() {
  39233. Transform.call(this);
  39234. }
  39235. ReversibleTransform.prototype = Object.create(Transform.prototype);
  39236. ReversibleTransform.prototype.filter =
  39237. function reversibleTransformFilter(x, offset, length) {
  39238. var len = length >> 1;
  39239. offset = offset | 0;
  39240. var j, n;
  39241. for (j = offset, n = len + 1; n--; j += 2) {
  39242. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  39243. }
  39244. for (j = offset + 1, n = len; n--; j += 2) {
  39245. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  39246. }
  39247. };
  39248. return ReversibleTransform;
  39249. })();
  39250. return JpxImage;
  39251. })();
  39252. var Jbig2Image = (function Jbig2ImageClosure() {
  39253. // Utility data structures
  39254. function ContextCache() {}
  39255. ContextCache.prototype = {
  39256. getContexts: function(id) {
  39257. if (id in this) {
  39258. return this[id];
  39259. }
  39260. return (this[id] = new Int8Array(1 << 16));
  39261. }
  39262. };
  39263. function DecodingContext(data, start, end) {
  39264. this.data = data;
  39265. this.start = start;
  39266. this.end = end;
  39267. }
  39268. DecodingContext.prototype = {
  39269. get decoder() {
  39270. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  39271. return shadow(this, 'decoder', decoder);
  39272. },
  39273. get contextCache() {
  39274. var cache = new ContextCache();
  39275. return shadow(this, 'contextCache', cache);
  39276. }
  39277. };
  39278. // Annex A. Arithmetic Integer Decoding Procedure
  39279. // A.2 Procedure for decoding values
  39280. function decodeInteger(contextCache, procedure, decoder) {
  39281. var contexts = contextCache.getContexts(procedure);
  39282. var prev = 1;
  39283. function readBits(length) {
  39284. var v = 0;
  39285. for (var i = 0; i < length; i++) {
  39286. var bit = decoder.readBit(contexts, prev);
  39287. prev = (prev < 256 ? (prev << 1) | bit :
  39288. (((prev << 1) | bit) & 511) | 256);
  39289. v = (v << 1) | bit;
  39290. }
  39291. return v >>> 0;
  39292. }
  39293. var sign = readBits(1);
  39294. var value = readBits(1) ?
  39295. (readBits(1) ?
  39296. (readBits(1) ?
  39297. (readBits(1) ?
  39298. (readBits(1) ?
  39299. (readBits(32) + 4436) :
  39300. readBits(12) + 340) :
  39301. readBits(8) + 84) :
  39302. readBits(6) + 20) :
  39303. readBits(4) + 4) :
  39304. readBits(2);
  39305. return (sign === 0 ? value : (value > 0 ? -value : null));
  39306. }
  39307. // A.3 The IAID decoding procedure
  39308. function decodeIAID(contextCache, decoder, codeLength) {
  39309. var contexts = contextCache.getContexts('IAID');
  39310. var prev = 1;
  39311. for (var i = 0; i < codeLength; i++) {
  39312. var bit = decoder.readBit(contexts, prev);
  39313. prev = (prev << 1) | bit;
  39314. }
  39315. if (codeLength < 31) {
  39316. return prev & ((1 << codeLength) - 1);
  39317. }
  39318. return prev & 0x7FFFFFFF;
  39319. }
  39320. // 7.3 Segment types
  39321. var SegmentTypes = [
  39322. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  39323. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  39324. null, null, null, null, null, 'patternDictionary', null, null, null,
  39325. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  39326. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  39327. null, null, null, null, null, 'IntermediateGenericRegion', null,
  39328. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  39329. 'IntermediateGenericRefinementRegion', null,
  39330. 'ImmediateGenericRefinementRegion',
  39331. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  39332. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  39333. 'Tables', null, null, null, null, null, null, null, null,
  39334. 'Extension'
  39335. ];
  39336. var CodingTemplates = [
  39337. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  39338. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  39339. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  39340. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  39341. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  39342. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  39343. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  39344. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  39345. {x: -1, y: 0}],
  39346. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  39347. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  39348. ];
  39349. var RefinementTemplates = [
  39350. {
  39351. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  39352. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  39353. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  39354. },
  39355. {
  39356. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  39357. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  39358. {x: 0, y: 1}, {x: 1, y: 1}]
  39359. }
  39360. ];
  39361. // See 6.2.5.7 Decoding the bitmap.
  39362. var ReusedContexts = [
  39363. 0x9B25, // 10011 0110010 0101
  39364. 0x0795, // 0011 110010 101
  39365. 0x00E5, // 001 11001 01
  39366. 0x0195 // 011001 0101
  39367. ];
  39368. var RefinementReusedContexts = [
  39369. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  39370. 0x0008 // '0000' + '001000'
  39371. ];
  39372. function decodeBitmapTemplate0(width, height, decodingContext) {
  39373. var decoder = decodingContext.decoder;
  39374. var contexts = decodingContext.contextCache.getContexts('GB');
  39375. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  39376. // ...ooooo....
  39377. // ..ooooooo... Context template for current pixel (X)
  39378. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  39379. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  39380. for (i = 0; i < height; i++) {
  39381. row = bitmap[i] = new Uint8Array(width);
  39382. row1 = (i < 1) ? row : bitmap[i - 1];
  39383. row2 = (i < 2) ? row : bitmap[i - 2];
  39384. // At the beginning of each row:
  39385. // Fill contextLabel with pixels that are above/right of (X)
  39386. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  39387. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  39388. (row1[3] << 4);
  39389. for (j = 0; j < width; j++) {
  39390. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  39391. // At each pixel: Clear contextLabel pixels that are shifted
  39392. // out of the context, then add new ones.
  39393. // If j + n is out of range at the right image border, then
  39394. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  39395. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  39396. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  39397. }
  39398. }
  39399. return bitmap;
  39400. }
  39401. // 6.2 Generic Region Decoding Procedure
  39402. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  39403. decodingContext) {
  39404. if (mmr) {
  39405. error('JBIG2 error: MMR encoding is not supported');
  39406. }
  39407. // Use optimized version for the most common case
  39408. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  39409. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  39410. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  39411. return decodeBitmapTemplate0(width, height, decodingContext);
  39412. }
  39413. var useskip = !!skip;
  39414. var template = CodingTemplates[templateIndex].concat(at);
  39415. // Sorting is non-standard, and it is not required. But sorting increases
  39416. // the number of template bits that can be reused from the previous
  39417. // contextLabel in the main loop.
  39418. template.sort(function (a, b) {
  39419. return (a.y - b.y) || (a.x - b.x);
  39420. });
  39421. var templateLength = template.length;
  39422. var templateX = new Int8Array(templateLength);
  39423. var templateY = new Int8Array(templateLength);
  39424. var changingTemplateEntries = [];
  39425. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  39426. var c, k;
  39427. for (k = 0; k < templateLength; k++) {
  39428. templateX[k] = template[k].x;
  39429. templateY[k] = template[k].y;
  39430. minX = Math.min(minX, template[k].x);
  39431. maxX = Math.max(maxX, template[k].x);
  39432. minY = Math.min(minY, template[k].y);
  39433. // Check if the template pixel appears in two consecutive context labels,
  39434. // so it can be reused. Otherwise, we add it to the list of changing
  39435. // template entries.
  39436. if (k < templateLength - 1 &&
  39437. template[k].y === template[k + 1].y &&
  39438. template[k].x === template[k + 1].x - 1) {
  39439. reuseMask |= 1 << (templateLength - 1 - k);
  39440. } else {
  39441. changingTemplateEntries.push(k);
  39442. }
  39443. }
  39444. var changingEntriesLength = changingTemplateEntries.length;
  39445. var changingTemplateX = new Int8Array(changingEntriesLength);
  39446. var changingTemplateY = new Int8Array(changingEntriesLength);
  39447. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  39448. for (c = 0; c < changingEntriesLength; c++) {
  39449. k = changingTemplateEntries[c];
  39450. changingTemplateX[c] = template[k].x;
  39451. changingTemplateY[c] = template[k].y;
  39452. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  39453. }
  39454. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  39455. var sbb_left = -minX;
  39456. var sbb_top = -minY;
  39457. var sbb_right = width - maxX;
  39458. var pseudoPixelContext = ReusedContexts[templateIndex];
  39459. var row = new Uint8Array(width);
  39460. var bitmap = [];
  39461. var decoder = decodingContext.decoder;
  39462. var contexts = decodingContext.contextCache.getContexts('GB');
  39463. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  39464. for (var i = 0; i < height; i++) {
  39465. if (prediction) {
  39466. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  39467. ltp ^= sltp;
  39468. if (ltp) {
  39469. bitmap.push(row); // duplicate previous row
  39470. continue;
  39471. }
  39472. }
  39473. row = new Uint8Array(row);
  39474. bitmap.push(row);
  39475. for (j = 0; j < width; j++) {
  39476. if (useskip && skip[i][j]) {
  39477. row[j] = 0;
  39478. continue;
  39479. }
  39480. // Are we in the middle of a scanline, so we can reuse contextLabel
  39481. // bits?
  39482. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  39483. // If yes, we can just shift the bits that are reusable and only
  39484. // fetch the remaining ones.
  39485. contextLabel = (contextLabel << 1) & reuseMask;
  39486. for (k = 0; k < changingEntriesLength; k++) {
  39487. i0 = i + changingTemplateY[k];
  39488. j0 = j + changingTemplateX[k];
  39489. bit = bitmap[i0][j0];
  39490. if (bit) {
  39491. bit = changingTemplateBit[k];
  39492. contextLabel |= bit;
  39493. }
  39494. }
  39495. } else {
  39496. // compute the contextLabel from scratch
  39497. contextLabel = 0;
  39498. shift = templateLength - 1;
  39499. for (k = 0; k < templateLength; k++, shift--) {
  39500. j0 = j + templateX[k];
  39501. if (j0 >= 0 && j0 < width) {
  39502. i0 = i + templateY[k];
  39503. if (i0 >= 0) {
  39504. bit = bitmap[i0][j0];
  39505. if (bit) {
  39506. contextLabel |= bit << shift;
  39507. }
  39508. }
  39509. }
  39510. }
  39511. }
  39512. var pixel = decoder.readBit(contexts, contextLabel);
  39513. row[j] = pixel;
  39514. }
  39515. }
  39516. return bitmap;
  39517. }
  39518. // 6.3.2 Generic Refinement Region Decoding Procedure
  39519. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  39520. offsetX, offsetY, prediction, at,
  39521. decodingContext) {
  39522. var codingTemplate = RefinementTemplates[templateIndex].coding;
  39523. if (templateIndex === 0) {
  39524. codingTemplate = codingTemplate.concat([at[0]]);
  39525. }
  39526. var codingTemplateLength = codingTemplate.length;
  39527. var codingTemplateX = new Int32Array(codingTemplateLength);
  39528. var codingTemplateY = new Int32Array(codingTemplateLength);
  39529. var k;
  39530. for (k = 0; k < codingTemplateLength; k++) {
  39531. codingTemplateX[k] = codingTemplate[k].x;
  39532. codingTemplateY[k] = codingTemplate[k].y;
  39533. }
  39534. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  39535. if (templateIndex === 0) {
  39536. referenceTemplate = referenceTemplate.concat([at[1]]);
  39537. }
  39538. var referenceTemplateLength = referenceTemplate.length;
  39539. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  39540. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  39541. for (k = 0; k < referenceTemplateLength; k++) {
  39542. referenceTemplateX[k] = referenceTemplate[k].x;
  39543. referenceTemplateY[k] = referenceTemplate[k].y;
  39544. }
  39545. var referenceWidth = referenceBitmap[0].length;
  39546. var referenceHeight = referenceBitmap.length;
  39547. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  39548. var bitmap = [];
  39549. var decoder = decodingContext.decoder;
  39550. var contexts = decodingContext.contextCache.getContexts('GR');
  39551. var ltp = 0;
  39552. for (var i = 0; i < height; i++) {
  39553. if (prediction) {
  39554. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  39555. ltp ^= sltp;
  39556. if (ltp) {
  39557. error('JBIG2 error: prediction is not supported');
  39558. }
  39559. }
  39560. var row = new Uint8Array(width);
  39561. bitmap.push(row);
  39562. for (var j = 0; j < width; j++) {
  39563. var i0, j0;
  39564. var contextLabel = 0;
  39565. for (k = 0; k < codingTemplateLength; k++) {
  39566. i0 = i + codingTemplateY[k];
  39567. j0 = j + codingTemplateX[k];
  39568. if (i0 < 0 || j0 < 0 || j0 >= width) {
  39569. contextLabel <<= 1; // out of bound pixel
  39570. } else {
  39571. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  39572. }
  39573. }
  39574. for (k = 0; k < referenceTemplateLength; k++) {
  39575. i0 = i + referenceTemplateY[k] + offsetY;
  39576. j0 = j + referenceTemplateX[k] + offsetX;
  39577. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  39578. j0 >= referenceWidth) {
  39579. contextLabel <<= 1; // out of bound pixel
  39580. } else {
  39581. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  39582. }
  39583. }
  39584. var pixel = decoder.readBit(contexts, contextLabel);
  39585. row[j] = pixel;
  39586. }
  39587. }
  39588. return bitmap;
  39589. }
  39590. // 6.5.5 Decoding the symbol dictionary
  39591. function decodeSymbolDictionary(huffman, refinement, symbols,
  39592. numberOfNewSymbols, numberOfExportedSymbols,
  39593. huffmanTables, templateIndex, at,
  39594. refinementTemplateIndex, refinementAt,
  39595. decodingContext) {
  39596. if (huffman) {
  39597. error('JBIG2 error: huffman is not supported');
  39598. }
  39599. var newSymbols = [];
  39600. var currentHeight = 0;
  39601. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  39602. var decoder = decodingContext.decoder;
  39603. var contextCache = decodingContext.contextCache;
  39604. while (newSymbols.length < numberOfNewSymbols) {
  39605. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  39606. currentHeight += deltaHeight;
  39607. var currentWidth = 0;
  39608. var totalWidth = 0;
  39609. while (true) {
  39610. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  39611. if (deltaWidth === null) {
  39612. break; // OOB
  39613. }
  39614. currentWidth += deltaWidth;
  39615. totalWidth += currentWidth;
  39616. var bitmap;
  39617. if (refinement) {
  39618. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  39619. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  39620. if (numberOfInstances > 1) {
  39621. bitmap = decodeTextRegion(huffman, refinement,
  39622. currentWidth, currentHeight, 0,
  39623. numberOfInstances, 1, //strip size
  39624. symbols.concat(newSymbols),
  39625. symbolCodeLength,
  39626. 0, //transposed
  39627. 0, //ds offset
  39628. 1, //top left 7.4.3.1.1
  39629. 0, //OR operator
  39630. huffmanTables,
  39631. refinementTemplateIndex, refinementAt,
  39632. decodingContext);
  39633. } else {
  39634. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  39635. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  39636. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  39637. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  39638. newSymbols[symbolId - symbols.length]);
  39639. bitmap = decodeRefinement(currentWidth, currentHeight,
  39640. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  39641. decodingContext);
  39642. }
  39643. } else {
  39644. // 6.5.8.1 Direct-coded symbol bitmap
  39645. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  39646. templateIndex, false, null, at, decodingContext);
  39647. }
  39648. newSymbols.push(bitmap);
  39649. }
  39650. }
  39651. // 6.5.10 Exported symbols
  39652. var exportedSymbols = [];
  39653. var flags = [], currentFlag = false;
  39654. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  39655. while (flags.length < totalSymbolsLength) {
  39656. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  39657. while (runLength--) {
  39658. flags.push(currentFlag);
  39659. }
  39660. currentFlag = !currentFlag;
  39661. }
  39662. for (var i = 0, ii = symbols.length; i < ii; i++) {
  39663. if (flags[i]) {
  39664. exportedSymbols.push(symbols[i]);
  39665. }
  39666. }
  39667. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  39668. if (flags[i]) {
  39669. exportedSymbols.push(newSymbols[j]);
  39670. }
  39671. }
  39672. return exportedSymbols;
  39673. }
  39674. function decodeTextRegion(huffman, refinement, width, height,
  39675. defaultPixelValue, numberOfSymbolInstances,
  39676. stripSize, inputSymbols, symbolCodeLength,
  39677. transposed, dsOffset, referenceCorner,
  39678. combinationOperator, huffmanTables,
  39679. refinementTemplateIndex, refinementAt,
  39680. decodingContext) {
  39681. if (huffman) {
  39682. error('JBIG2 error: huffman is not supported');
  39683. }
  39684. // Prepare bitmap
  39685. var bitmap = [];
  39686. var i, row;
  39687. for (i = 0; i < height; i++) {
  39688. row = new Uint8Array(width);
  39689. if (defaultPixelValue) {
  39690. for (var j = 0; j < width; j++) {
  39691. row[j] = defaultPixelValue;
  39692. }
  39693. }
  39694. bitmap.push(row);
  39695. }
  39696. var decoder = decodingContext.decoder;
  39697. var contextCache = decodingContext.contextCache;
  39698. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  39699. var firstS = 0;
  39700. i = 0;
  39701. while (i < numberOfSymbolInstances) {
  39702. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  39703. stripT += deltaT;
  39704. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  39705. firstS += deltaFirstS;
  39706. var currentS = firstS;
  39707. do {
  39708. var currentT = (stripSize === 1 ? 0 :
  39709. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  39710. var t = stripSize * stripT + currentT;
  39711. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  39712. var applyRefinement = (refinement &&
  39713. decodeInteger(contextCache, 'IARI', decoder));
  39714. var symbolBitmap = inputSymbols[symbolId];
  39715. var symbolWidth = symbolBitmap[0].length;
  39716. var symbolHeight = symbolBitmap.length;
  39717. if (applyRefinement) {
  39718. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  39719. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  39720. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  39721. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  39722. symbolWidth += rdw;
  39723. symbolHeight += rdh;
  39724. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  39725. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  39726. (rdh >> 1) + rdy, false, refinementAt,
  39727. decodingContext);
  39728. }
  39729. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  39730. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  39731. var s2, t2, symbolRow;
  39732. if (transposed) {
  39733. // Place Symbol Bitmap from T1,S1
  39734. for (s2 = 0; s2 < symbolHeight; s2++) {
  39735. row = bitmap[offsetS + s2];
  39736. if (!row) {
  39737. continue;
  39738. }
  39739. symbolRow = symbolBitmap[s2];
  39740. // To ignore Parts of Symbol bitmap which goes
  39741. // outside bitmap region
  39742. var maxWidth = Math.min(width - offsetT, symbolWidth);
  39743. switch (combinationOperator) {
  39744. case 0: // OR
  39745. for (t2 = 0; t2 < maxWidth; t2++) {
  39746. row[offsetT + t2] |= symbolRow[t2];
  39747. }
  39748. break;
  39749. case 2: // XOR
  39750. for (t2 = 0; t2 < maxWidth; t2++) {
  39751. row[offsetT + t2] ^= symbolRow[t2];
  39752. }
  39753. break;
  39754. default:
  39755. error('JBIG2 error: operator ' + combinationOperator +
  39756. ' is not supported');
  39757. }
  39758. }
  39759. currentS += symbolHeight - 1;
  39760. } else {
  39761. for (t2 = 0; t2 < symbolHeight; t2++) {
  39762. row = bitmap[offsetT + t2];
  39763. if (!row) {
  39764. continue;
  39765. }
  39766. symbolRow = symbolBitmap[t2];
  39767. switch (combinationOperator) {
  39768. case 0: // OR
  39769. for (s2 = 0; s2 < symbolWidth; s2++) {
  39770. row[offsetS + s2] |= symbolRow[s2];
  39771. }
  39772. break;
  39773. case 2: // XOR
  39774. for (s2 = 0; s2 < symbolWidth; s2++) {
  39775. row[offsetS + s2] ^= symbolRow[s2];
  39776. }
  39777. break;
  39778. default:
  39779. error('JBIG2 error: operator ' + combinationOperator +
  39780. ' is not supported');
  39781. }
  39782. }
  39783. currentS += symbolWidth - 1;
  39784. }
  39785. i++;
  39786. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  39787. if (deltaS === null) {
  39788. break; // OOB
  39789. }
  39790. currentS += deltaS + dsOffset;
  39791. } while (true);
  39792. }
  39793. return bitmap;
  39794. }
  39795. function readSegmentHeader(data, start) {
  39796. var segmentHeader = {};
  39797. segmentHeader.number = readUint32(data, start);
  39798. var flags = data[start + 4];
  39799. var segmentType = flags & 0x3F;
  39800. if (!SegmentTypes[segmentType]) {
  39801. error('JBIG2 error: invalid segment type: ' + segmentType);
  39802. }
  39803. segmentHeader.type = segmentType;
  39804. segmentHeader.typeName = SegmentTypes[segmentType];
  39805. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  39806. var pageAssociationFieldSize = !!(flags & 0x40);
  39807. var referredFlags = data[start + 5];
  39808. var referredToCount = (referredFlags >> 5) & 7;
  39809. var retainBits = [referredFlags & 31];
  39810. var position = start + 6;
  39811. if (referredFlags === 7) {
  39812. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  39813. position += 3;
  39814. var bytes = (referredToCount + 7) >> 3;
  39815. retainBits[0] = data[position++];
  39816. while (--bytes > 0) {
  39817. retainBits.push(data[position++]);
  39818. }
  39819. } else if (referredFlags === 5 || referredFlags === 6) {
  39820. error('JBIG2 error: invalid referred-to flags');
  39821. }
  39822. segmentHeader.retainBits = retainBits;
  39823. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  39824. (segmentHeader.number <= 65536 ? 2 : 4));
  39825. var referredTo = [];
  39826. var i, ii;
  39827. for (i = 0; i < referredToCount; i++) {
  39828. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  39829. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  39830. readUint32(data, position)));
  39831. referredTo.push(number);
  39832. position += referredToSegmentNumberSize;
  39833. }
  39834. segmentHeader.referredTo = referredTo;
  39835. if (!pageAssociationFieldSize) {
  39836. segmentHeader.pageAssociation = data[position++];
  39837. } else {
  39838. segmentHeader.pageAssociation = readUint32(data, position);
  39839. position += 4;
  39840. }
  39841. segmentHeader.length = readUint32(data, position);
  39842. position += 4;
  39843. if (segmentHeader.length === 0xFFFFFFFF) {
  39844. // 7.2.7 Segment data length, unknown segment length
  39845. if (segmentType === 38) { // ImmediateGenericRegion
  39846. var genericRegionInfo = readRegionSegmentInformation(data, position);
  39847. var genericRegionSegmentFlags = data[position +
  39848. RegionSegmentInformationFieldLength];
  39849. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  39850. // searching for the segment end
  39851. var searchPatternLength = 6;
  39852. var searchPattern = new Uint8Array(searchPatternLength);
  39853. if (!genericRegionMmr) {
  39854. searchPattern[0] = 0xFF;
  39855. searchPattern[1] = 0xAC;
  39856. }
  39857. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  39858. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  39859. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  39860. searchPattern[5] = genericRegionInfo.height & 0xFF;
  39861. for (i = position, ii = data.length; i < ii; i++) {
  39862. var j = 0;
  39863. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  39864. j++;
  39865. }
  39866. if (j === searchPatternLength) {
  39867. segmentHeader.length = i + searchPatternLength;
  39868. break;
  39869. }
  39870. }
  39871. if (segmentHeader.length === 0xFFFFFFFF) {
  39872. error('JBIG2 error: segment end was not found');
  39873. }
  39874. } else {
  39875. error('JBIG2 error: invalid unknown segment length');
  39876. }
  39877. }
  39878. segmentHeader.headerEnd = position;
  39879. return segmentHeader;
  39880. }
  39881. function readSegments(header, data, start, end) {
  39882. var segments = [];
  39883. var position = start;
  39884. while (position < end) {
  39885. var segmentHeader = readSegmentHeader(data, position);
  39886. position = segmentHeader.headerEnd;
  39887. var segment = {
  39888. header: segmentHeader,
  39889. data: data
  39890. };
  39891. if (!header.randomAccess) {
  39892. segment.start = position;
  39893. position += segmentHeader.length;
  39894. segment.end = position;
  39895. }
  39896. segments.push(segment);
  39897. if (segmentHeader.type === 51) {
  39898. break; // end of file is found
  39899. }
  39900. }
  39901. if (header.randomAccess) {
  39902. for (var i = 0, ii = segments.length; i < ii; i++) {
  39903. segments[i].start = position;
  39904. position += segments[i].header.length;
  39905. segments[i].end = position;
  39906. }
  39907. }
  39908. return segments;
  39909. }
  39910. // 7.4.1 Region segment information field
  39911. function readRegionSegmentInformation(data, start) {
  39912. return {
  39913. width: readUint32(data, start),
  39914. height: readUint32(data, start + 4),
  39915. x: readUint32(data, start + 8),
  39916. y: readUint32(data, start + 12),
  39917. combinationOperator: data[start + 16] & 7
  39918. };
  39919. }
  39920. var RegionSegmentInformationFieldLength = 17;
  39921. function processSegment(segment, visitor) {
  39922. var header = segment.header;
  39923. var data = segment.data, position = segment.start, end = segment.end;
  39924. var args, at, i, atLength;
  39925. switch (header.type) {
  39926. case 0: // SymbolDictionary
  39927. // 7.4.2 Symbol dictionary segment syntax
  39928. var dictionary = {};
  39929. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  39930. dictionary.huffman = !!(dictionaryFlags & 1);
  39931. dictionary.refinement = !!(dictionaryFlags & 2);
  39932. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  39933. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  39934. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  39935. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  39936. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  39937. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  39938. dictionary.template = (dictionaryFlags >> 10) & 3;
  39939. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  39940. position += 2;
  39941. if (!dictionary.huffman) {
  39942. atLength = dictionary.template === 0 ? 4 : 1;
  39943. at = [];
  39944. for (i = 0; i < atLength; i++) {
  39945. at.push({
  39946. x: readInt8(data, position),
  39947. y: readInt8(data, position + 1)
  39948. });
  39949. position += 2;
  39950. }
  39951. dictionary.at = at;
  39952. }
  39953. if (dictionary.refinement && !dictionary.refinementTemplate) {
  39954. at = [];
  39955. for (i = 0; i < 2; i++) {
  39956. at.push({
  39957. x: readInt8(data, position),
  39958. y: readInt8(data, position + 1)
  39959. });
  39960. position += 2;
  39961. }
  39962. dictionary.refinementAt = at;
  39963. }
  39964. dictionary.numberOfExportedSymbols = readUint32(data, position);
  39965. position += 4;
  39966. dictionary.numberOfNewSymbols = readUint32(data, position);
  39967. position += 4;
  39968. args = [dictionary, header.number, header.referredTo,
  39969. data, position, end];
  39970. break;
  39971. case 6: // ImmediateTextRegion
  39972. case 7: // ImmediateLosslessTextRegion
  39973. var textRegion = {};
  39974. textRegion.info = readRegionSegmentInformation(data, position);
  39975. position += RegionSegmentInformationFieldLength;
  39976. var textRegionSegmentFlags = readUint16(data, position);
  39977. position += 2;
  39978. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  39979. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  39980. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  39981. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  39982. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  39983. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  39984. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  39985. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  39986. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  39987. if (textRegion.huffman) {
  39988. var textRegionHuffmanFlags = readUint16(data, position);
  39989. position += 2;
  39990. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  39991. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  39992. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  39993. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  39994. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  39995. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  39996. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  39997. textRegion.huffmanRefinementSizeSelector =
  39998. !!(textRegionHuffmanFlags & 14);
  39999. }
  40000. if (textRegion.refinement && !textRegion.refinementTemplate) {
  40001. at = [];
  40002. for (i = 0; i < 2; i++) {
  40003. at.push({
  40004. x: readInt8(data, position),
  40005. y: readInt8(data, position + 1)
  40006. });
  40007. position += 2;
  40008. }
  40009. textRegion.refinementAt = at;
  40010. }
  40011. textRegion.numberOfSymbolInstances = readUint32(data, position);
  40012. position += 4;
  40013. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  40014. if (textRegion.huffman) {
  40015. error('JBIG2 error: huffman is not supported');
  40016. }
  40017. args = [textRegion, header.referredTo, data, position, end];
  40018. break;
  40019. case 38: // ImmediateGenericRegion
  40020. case 39: // ImmediateLosslessGenericRegion
  40021. var genericRegion = {};
  40022. genericRegion.info = readRegionSegmentInformation(data, position);
  40023. position += RegionSegmentInformationFieldLength;
  40024. var genericRegionSegmentFlags = data[position++];
  40025. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  40026. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  40027. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  40028. if (!genericRegion.mmr) {
  40029. atLength = genericRegion.template === 0 ? 4 : 1;
  40030. at = [];
  40031. for (i = 0; i < atLength; i++) {
  40032. at.push({
  40033. x: readInt8(data, position),
  40034. y: readInt8(data, position + 1)
  40035. });
  40036. position += 2;
  40037. }
  40038. genericRegion.at = at;
  40039. }
  40040. args = [genericRegion, data, position, end];
  40041. break;
  40042. case 48: // PageInformation
  40043. var pageInfo = {
  40044. width: readUint32(data, position),
  40045. height: readUint32(data, position + 4),
  40046. resolutionX: readUint32(data, position + 8),
  40047. resolutionY: readUint32(data, position + 12)
  40048. };
  40049. if (pageInfo.height === 0xFFFFFFFF) {
  40050. delete pageInfo.height;
  40051. }
  40052. var pageSegmentFlags = data[position + 16];
  40053. var pageStripingInformatiom = readUint16(data, position + 17);
  40054. pageInfo.lossless = !!(pageSegmentFlags & 1);
  40055. pageInfo.refinement = !!(pageSegmentFlags & 2);
  40056. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  40057. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  40058. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  40059. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  40060. args = [pageInfo];
  40061. break;
  40062. case 49: // EndOfPage
  40063. break;
  40064. case 50: // EndOfStripe
  40065. break;
  40066. case 51: // EndOfFile
  40067. break;
  40068. case 62: // 7.4.15 defines 2 extension types which
  40069. // are comments and can be ignored.
  40070. break;
  40071. default:
  40072. error('JBIG2 error: segment type ' + header.typeName + '(' +
  40073. header.type + ') is not implemented');
  40074. }
  40075. var callbackName = 'on' + header.typeName;
  40076. if (callbackName in visitor) {
  40077. visitor[callbackName].apply(visitor, args);
  40078. }
  40079. }
  40080. function processSegments(segments, visitor) {
  40081. for (var i = 0, ii = segments.length; i < ii; i++) {
  40082. processSegment(segments[i], visitor);
  40083. }
  40084. }
  40085. function parseJbig2(data, start, end) {
  40086. var position = start;
  40087. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  40088. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  40089. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  40090. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  40091. error('JBIG2 error: invalid header');
  40092. }
  40093. var header = {};
  40094. position += 8;
  40095. var flags = data[position++];
  40096. header.randomAccess = !(flags & 1);
  40097. if (!(flags & 2)) {
  40098. header.numberOfPages = readUint32(data, position);
  40099. position += 4;
  40100. }
  40101. var segments = readSegments(header, data, position, end);
  40102. error('Not implemented');
  40103. // processSegments(segments, new SimpleSegmentVisitor());
  40104. }
  40105. function parseJbig2Chunks(chunks) {
  40106. var visitor = new SimpleSegmentVisitor();
  40107. for (var i = 0, ii = chunks.length; i < ii; i++) {
  40108. var chunk = chunks[i];
  40109. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  40110. processSegments(segments, visitor);
  40111. }
  40112. return visitor.buffer;
  40113. }
  40114. function SimpleSegmentVisitor() {}
  40115. SimpleSegmentVisitor.prototype = {
  40116. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  40117. this.currentPageInfo = info;
  40118. var rowSize = (info.width + 7) >> 3;
  40119. var buffer = new Uint8Array(rowSize * info.height);
  40120. // The contents of ArrayBuffers are initialized to 0.
  40121. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  40122. if (info.defaultPixelValue) {
  40123. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40124. buffer[i] = 0xFF;
  40125. }
  40126. }
  40127. this.buffer = buffer;
  40128. },
  40129. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  40130. var pageInfo = this.currentPageInfo;
  40131. var width = regionInfo.width, height = regionInfo.height;
  40132. var rowSize = (pageInfo.width + 7) >> 3;
  40133. var combinationOperator = pageInfo.combinationOperatorOverride ?
  40134. regionInfo.combinationOperator : pageInfo.combinationOperator;
  40135. var buffer = this.buffer;
  40136. var mask0 = 128 >> (regionInfo.x & 7);
  40137. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  40138. var i, j, mask, offset;
  40139. switch (combinationOperator) {
  40140. case 0: // OR
  40141. for (i = 0; i < height; i++) {
  40142. mask = mask0;
  40143. offset = offset0;
  40144. for (j = 0; j < width; j++) {
  40145. if (bitmap[i][j]) {
  40146. buffer[offset] |= mask;
  40147. }
  40148. mask >>= 1;
  40149. if (!mask) {
  40150. mask = 128;
  40151. offset++;
  40152. }
  40153. }
  40154. offset0 += rowSize;
  40155. }
  40156. break;
  40157. case 2: // XOR
  40158. for (i = 0; i < height; i++) {
  40159. mask = mask0;
  40160. offset = offset0;
  40161. for (j = 0; j < width; j++) {
  40162. if (bitmap[i][j]) {
  40163. buffer[offset] ^= mask;
  40164. }
  40165. mask >>= 1;
  40166. if (!mask) {
  40167. mask = 128;
  40168. offset++;
  40169. }
  40170. }
  40171. offset0 += rowSize;
  40172. }
  40173. break;
  40174. default:
  40175. error('JBIG2 error: operator ' + combinationOperator +
  40176. ' is not supported');
  40177. }
  40178. },
  40179. onImmediateGenericRegion:
  40180. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  40181. start, end) {
  40182. var regionInfo = region.info;
  40183. var decodingContext = new DecodingContext(data, start, end);
  40184. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  40185. region.template, region.prediction, null,
  40186. region.at, decodingContext);
  40187. this.drawBitmap(regionInfo, bitmap);
  40188. },
  40189. onImmediateLosslessGenericRegion:
  40190. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  40191. this.onImmediateGenericRegion.apply(this, arguments);
  40192. },
  40193. onSymbolDictionary:
  40194. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  40195. currentSegment,
  40196. referredSegments,
  40197. data, start, end) {
  40198. var huffmanTables;
  40199. if (dictionary.huffman) {
  40200. error('JBIG2 error: huffman is not supported');
  40201. }
  40202. // Combines exported symbols from all referred segments
  40203. var symbols = this.symbols;
  40204. if (!symbols) {
  40205. this.symbols = symbols = {};
  40206. }
  40207. var inputSymbols = [];
  40208. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  40209. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  40210. }
  40211. var decodingContext = new DecodingContext(data, start, end);
  40212. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  40213. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  40214. dictionary.numberOfExportedSymbols, huffmanTables,
  40215. dictionary.template, dictionary.at,
  40216. dictionary.refinementTemplate, dictionary.refinementAt,
  40217. decodingContext);
  40218. },
  40219. onImmediateTextRegion:
  40220. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  40221. referredSegments,
  40222. data, start, end) {
  40223. var regionInfo = region.info;
  40224. var huffmanTables;
  40225. // Combines exported symbols from all referred segments
  40226. var symbols = this.symbols;
  40227. var inputSymbols = [];
  40228. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  40229. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  40230. }
  40231. var symbolCodeLength = log2(inputSymbols.length);
  40232. var decodingContext = new DecodingContext(data, start, end);
  40233. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  40234. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  40235. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  40236. symbolCodeLength, region.transposed, region.dsOffset,
  40237. region.referenceCorner, region.combinationOperator, huffmanTables,
  40238. region.refinementTemplate, region.refinementAt, decodingContext);
  40239. this.drawBitmap(regionInfo, bitmap);
  40240. },
  40241. onImmediateLosslessTextRegion:
  40242. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  40243. this.onImmediateTextRegion.apply(this, arguments);
  40244. }
  40245. };
  40246. function Jbig2Image() {}
  40247. Jbig2Image.prototype = {
  40248. parseChunks: function Jbig2Image_parseChunks(chunks) {
  40249. return parseJbig2Chunks(chunks);
  40250. }
  40251. };
  40252. return Jbig2Image;
  40253. })();
  40254. var bidi = PDFJS.bidi = (function bidiClosure() {
  40255. // Character types for symbols from 0000 to 00FF.
  40256. var baseTypes = [
  40257. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  40258. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  40259. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  40260. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  40261. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  40262. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  40263. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  40264. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  40265. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  40266. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  40267. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  40268. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  40269. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  40270. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  40271. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  40272. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  40273. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  40274. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  40275. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  40276. ];
  40277. // Character types for symbols from 0600 to 06FF
  40278. var arabicTypes = [
  40279. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40280. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  40281. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40282. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40283. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40284. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40285. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  40286. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  40287. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  40288. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  40289. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40290. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40291. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40292. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40293. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40294. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40295. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40296. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40297. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  40298. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  40299. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  40300. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  40301. ];
  40302. function isOdd(i) {
  40303. return (i & 1) !== 0;
  40304. }
  40305. function isEven(i) {
  40306. return (i & 1) === 0;
  40307. }
  40308. function findUnequal(arr, start, value) {
  40309. for (var j = start, jj = arr.length; j < jj; ++j) {
  40310. if (arr[j] !== value) {
  40311. return j;
  40312. }
  40313. }
  40314. return j;
  40315. }
  40316. function setValues(arr, start, end, value) {
  40317. for (var j = start; j < end; ++j) {
  40318. arr[j] = value;
  40319. }
  40320. }
  40321. function reverseValues(arr, start, end) {
  40322. for (var i = start, j = end - 1; i < j; ++i, --j) {
  40323. var temp = arr[i];
  40324. arr[i] = arr[j];
  40325. arr[j] = temp;
  40326. }
  40327. }
  40328. function createBidiText(str, isLTR, vertical) {
  40329. return {
  40330. str: str,
  40331. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  40332. };
  40333. }
  40334. // These are used in bidi(), which is called frequently. We re-use them on
  40335. // each call to avoid unnecessary allocations.
  40336. var chars = [];
  40337. var types = [];
  40338. function bidi(str, startLevel, vertical) {
  40339. var isLTR = true;
  40340. var strLength = str.length;
  40341. if (strLength === 0 || vertical) {
  40342. return createBidiText(str, isLTR, vertical);
  40343. }
  40344. // Get types and fill arrays
  40345. chars.length = strLength;
  40346. types.length = strLength;
  40347. var numBidi = 0;
  40348. var i, ii;
  40349. for (i = 0; i < strLength; ++i) {
  40350. chars[i] = str.charAt(i);
  40351. var charCode = str.charCodeAt(i);
  40352. var charType = 'L';
  40353. if (charCode <= 0x00ff) {
  40354. charType = baseTypes[charCode];
  40355. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  40356. charType = 'R';
  40357. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  40358. charType = arabicTypes[charCode & 0xff];
  40359. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  40360. charType = 'AL';
  40361. }
  40362. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  40363. numBidi++;
  40364. }
  40365. types[i] = charType;
  40366. }
  40367. // Detect the bidi method
  40368. // - If there are no rtl characters then no bidi needed
  40369. // - If less than 30% chars are rtl then string is primarily ltr
  40370. // - If more than 30% chars are rtl then string is primarily rtl
  40371. if (numBidi === 0) {
  40372. isLTR = true;
  40373. return createBidiText(str, isLTR);
  40374. }
  40375. if (startLevel === -1) {
  40376. if ((strLength / numBidi) < 0.3) {
  40377. isLTR = true;
  40378. startLevel = 0;
  40379. } else {
  40380. isLTR = false;
  40381. startLevel = 1;
  40382. }
  40383. }
  40384. var levels = [];
  40385. for (i = 0; i < strLength; ++i) {
  40386. levels[i] = startLevel;
  40387. }
  40388. /*
  40389. X1-X10: skip most of this, since we are NOT doing the embeddings.
  40390. */
  40391. var e = (isOdd(startLevel) ? 'R' : 'L');
  40392. var sor = e;
  40393. var eor = sor;
  40394. /*
  40395. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  40396. type of the NSM to the type of the previous character. If the NSM is at the
  40397. start of the level run, it will get the type of sor.
  40398. */
  40399. var lastType = sor;
  40400. for (i = 0; i < strLength; ++i) {
  40401. if (types[i] === 'NSM') {
  40402. types[i] = lastType;
  40403. } else {
  40404. lastType = types[i];
  40405. }
  40406. }
  40407. /*
  40408. W2. Search backwards from each instance of a European number until the
  40409. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  40410. the type of the European number to Arabic number.
  40411. */
  40412. lastType = sor;
  40413. var t;
  40414. for (i = 0; i < strLength; ++i) {
  40415. t = types[i];
  40416. if (t === 'EN') {
  40417. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  40418. } else if (t === 'R' || t === 'L' || t === 'AL') {
  40419. lastType = t;
  40420. }
  40421. }
  40422. /*
  40423. W3. Change all ALs to R.
  40424. */
  40425. for (i = 0; i < strLength; ++i) {
  40426. t = types[i];
  40427. if (t === 'AL') {
  40428. types[i] = 'R';
  40429. }
  40430. }
  40431. /*
  40432. W4. A single European separator between two European numbers changes to a
  40433. European number. A single common separator between two numbers of the same
  40434. type changes to that type:
  40435. */
  40436. for (i = 1; i < strLength - 1; ++i) {
  40437. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  40438. types[i] = 'EN';
  40439. }
  40440. if (types[i] === 'CS' &&
  40441. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  40442. types[i + 1] === types[i - 1]) {
  40443. types[i] = types[i - 1];
  40444. }
  40445. }
  40446. /*
  40447. W5. A sequence of European terminators adjacent to European numbers changes
  40448. to all European numbers:
  40449. */
  40450. for (i = 0; i < strLength; ++i) {
  40451. if (types[i] === 'EN') {
  40452. // do before
  40453. var j;
  40454. for (j = i - 1; j >= 0; --j) {
  40455. if (types[j] !== 'ET') {
  40456. break;
  40457. }
  40458. types[j] = 'EN';
  40459. }
  40460. // do after
  40461. for (j = i + 1; j < strLength; --j) {
  40462. if (types[j] !== 'ET') {
  40463. break;
  40464. }
  40465. types[j] = 'EN';
  40466. }
  40467. }
  40468. }
  40469. /*
  40470. W6. Otherwise, separators and terminators change to Other Neutral:
  40471. */
  40472. for (i = 0; i < strLength; ++i) {
  40473. t = types[i];
  40474. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  40475. types[i] = 'ON';
  40476. }
  40477. }
  40478. /*
  40479. W7. Search backwards from each instance of a European number until the
  40480. first strong type (R, L, or sor) is found. If an L is found, then change
  40481. the type of the European number to L.
  40482. */
  40483. lastType = sor;
  40484. for (i = 0; i < strLength; ++i) {
  40485. t = types[i];
  40486. if (t === 'EN') {
  40487. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  40488. } else if (t === 'R' || t === 'L') {
  40489. lastType = t;
  40490. }
  40491. }
  40492. /*
  40493. N1. A sequence of neutrals takes the direction of the surrounding strong
  40494. text if the text on both sides has the same direction. European and Arabic
  40495. numbers are treated as though they were R. Start-of-level-run (sor) and
  40496. end-of-level-run (eor) are used at level run boundaries.
  40497. */
  40498. for (i = 0; i < strLength; ++i) {
  40499. if (types[i] === 'ON') {
  40500. var end = findUnequal(types, i + 1, 'ON');
  40501. var before = sor;
  40502. if (i > 0) {
  40503. before = types[i - 1];
  40504. }
  40505. var after = eor;
  40506. if (end + 1 < strLength) {
  40507. after = types[end + 1];
  40508. }
  40509. if (before !== 'L') {
  40510. before = 'R';
  40511. }
  40512. if (after !== 'L') {
  40513. after = 'R';
  40514. }
  40515. if (before === after) {
  40516. setValues(types, i, end, before);
  40517. }
  40518. i = end - 1; // reset to end (-1 so next iteration is ok)
  40519. }
  40520. }
  40521. /*
  40522. N2. Any remaining neutrals take the embedding direction.
  40523. */
  40524. for (i = 0; i < strLength; ++i) {
  40525. if (types[i] === 'ON') {
  40526. types[i] = e;
  40527. }
  40528. }
  40529. /*
  40530. I1. For all characters with an even (left-to-right) embedding direction,
  40531. those of type R go up one level and those of type AN or EN go up two
  40532. levels.
  40533. I2. For all characters with an odd (right-to-left) embedding direction,
  40534. those of type L, EN or AN go up one level.
  40535. */
  40536. for (i = 0; i < strLength; ++i) {
  40537. t = types[i];
  40538. if (isEven(levels[i])) {
  40539. if (t === 'R') {
  40540. levels[i] += 1;
  40541. } else if (t === 'AN' || t === 'EN') {
  40542. levels[i] += 2;
  40543. }
  40544. } else { // isOdd
  40545. if (t === 'L' || t === 'AN' || t === 'EN') {
  40546. levels[i] += 1;
  40547. }
  40548. }
  40549. }
  40550. /*
  40551. L1. On each line, reset the embedding level of the following characters to
  40552. the paragraph embedding level:
  40553. segment separators,
  40554. paragraph separators,
  40555. any sequence of whitespace characters preceding a segment separator or
  40556. paragraph separator, and any sequence of white space characters at the end
  40557. of the line.
  40558. */
  40559. // don't bother as text is only single line
  40560. /*
  40561. L2. From the highest level found in the text to the lowest odd level on
  40562. each line, reverse any contiguous sequence of characters that are at that
  40563. level or higher.
  40564. */
  40565. // find highest level & lowest odd level
  40566. var highestLevel = -1;
  40567. var lowestOddLevel = 99;
  40568. var level;
  40569. for (i = 0, ii = levels.length; i < ii; ++i) {
  40570. level = levels[i];
  40571. if (highestLevel < level) {
  40572. highestLevel = level;
  40573. }
  40574. if (lowestOddLevel > level && isOdd(level)) {
  40575. lowestOddLevel = level;
  40576. }
  40577. }
  40578. // now reverse between those limits
  40579. for (level = highestLevel; level >= lowestOddLevel; --level) {
  40580. // find segments to reverse
  40581. var start = -1;
  40582. for (i = 0, ii = levels.length; i < ii; ++i) {
  40583. if (levels[i] < level) {
  40584. if (start >= 0) {
  40585. reverseValues(chars, start, i);
  40586. start = -1;
  40587. }
  40588. } else if (start < 0) {
  40589. start = i;
  40590. }
  40591. }
  40592. if (start >= 0) {
  40593. reverseValues(chars, start, levels.length);
  40594. }
  40595. }
  40596. /*
  40597. L3. Combining marks applied to a right-to-left base character will at this
  40598. point precede their base character. If the rendering engine expects them to
  40599. follow the base characters in the final display process, then the ordering
  40600. of the marks and the base character must be reversed.
  40601. */
  40602. // don't bother for now
  40603. /*
  40604. L4. A character that possesses the mirrored property as specified by
  40605. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  40606. directionality of that character is R.
  40607. */
  40608. // don't mirror as characters are already mirrored in the pdf
  40609. // Finally, return string
  40610. var result = '';
  40611. for (i = 0, ii = chars.length; i < ii; ++i) {
  40612. var ch = chars[i];
  40613. if (ch !== '<' && ch !== '>') {
  40614. result += ch;
  40615. }
  40616. }
  40617. return createBidiText(result, isLTR);
  40618. }
  40619. return bidi;
  40620. })();
  40621. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  40622. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  40623. /* Copyright 2014 Opera Software ASA
  40624. *
  40625. * Licensed under the Apache License, Version 2.0 (the "License");
  40626. * you may not use this file except in compliance with the License.
  40627. * You may obtain a copy of the License at
  40628. *
  40629. * http://www.apache.org/licenses/LICENSE-2.0
  40630. *
  40631. * Unless required by applicable law or agreed to in writing, software
  40632. * distributed under the License is distributed on an "AS IS" BASIS,
  40633. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  40634. * See the License for the specific language governing permissions and
  40635. * limitations under the License.
  40636. *
  40637. *
  40638. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  40639. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  40640. */
  40641. /* globals Uint32ArrayView */
  40642. 'use strict';
  40643. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  40644. // Workaround for missing math precison in JS.
  40645. var MASK_HIGH = 0xffff0000;
  40646. var MASK_LOW = 0xffff;
  40647. function MurmurHash3_64 (seed) {
  40648. var SEED = 0xc3d2e1f0;
  40649. this.h1 = seed ? seed & 0xffffffff : SEED;
  40650. this.h2 = seed ? seed & 0xffffffff : SEED;
  40651. }
  40652. var alwaysUseUint32ArrayView = false;
  40653. // old webkits have issues with non-aligned arrays
  40654. try {
  40655. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  40656. } catch (e) {
  40657. alwaysUseUint32ArrayView = true;
  40658. }
  40659. MurmurHash3_64.prototype = {
  40660. update: function MurmurHash3_64_update(input) {
  40661. var useUint32ArrayView = alwaysUseUint32ArrayView;
  40662. var i;
  40663. if (typeof input === 'string') {
  40664. var data = new Uint8Array(input.length * 2);
  40665. var length = 0;
  40666. for (i = 0; i < input.length; i++) {
  40667. var code = input.charCodeAt(i);
  40668. if (code <= 0xff) {
  40669. data[length++] = code;
  40670. }
  40671. else {
  40672. data[length++] = code >>> 8;
  40673. data[length++] = code & 0xff;
  40674. }
  40675. }
  40676. } else if (input instanceof Uint8Array) {
  40677. data = input;
  40678. length = data.length;
  40679. } else if (typeof input === 'object' && ('length' in input)) {
  40680. // processing regular arrays as well, e.g. for IE9
  40681. data = input;
  40682. length = data.length;
  40683. useUint32ArrayView = true;
  40684. } else {
  40685. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  40686. 'Input must be a string or array.');
  40687. }
  40688. var blockCounts = length >> 2;
  40689. var tailLength = length - blockCounts * 4;
  40690. // we don't care about endianness here
  40691. var dataUint32 = useUint32ArrayView ?
  40692. new Uint32ArrayView(data, blockCounts) :
  40693. new Uint32Array(data.buffer, 0, blockCounts);
  40694. var k1 = 0;
  40695. var k2 = 0;
  40696. var h1 = this.h1;
  40697. var h2 = this.h2;
  40698. var C1 = 0xcc9e2d51;
  40699. var C2 = 0x1b873593;
  40700. var C1_LOW = C1 & MASK_LOW;
  40701. var C2_LOW = C2 & MASK_LOW;
  40702. for (i = 0; i < blockCounts; i++) {
  40703. if (i & 1) {
  40704. k1 = dataUint32[i];
  40705. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  40706. k1 = k1 << 15 | k1 >>> 17;
  40707. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  40708. h1 ^= k1;
  40709. h1 = h1 << 13 | h1 >>> 19;
  40710. h1 = h1 * 5 + 0xe6546b64;
  40711. } else {
  40712. k2 = dataUint32[i];
  40713. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  40714. k2 = k2 << 15 | k2 >>> 17;
  40715. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  40716. h2 ^= k2;
  40717. h2 = h2 << 13 | h2 >>> 19;
  40718. h2 = h2 * 5 + 0xe6546b64;
  40719. }
  40720. }
  40721. k1 = 0;
  40722. switch (tailLength) {
  40723. case 3:
  40724. k1 ^= data[blockCounts * 4 + 2] << 16;
  40725. /* falls through */
  40726. case 2:
  40727. k1 ^= data[blockCounts * 4 + 1] << 8;
  40728. /* falls through */
  40729. case 1:
  40730. k1 ^= data[blockCounts * 4];
  40731. /* falls through */
  40732. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  40733. k1 = k1 << 15 | k1 >>> 17;
  40734. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  40735. if (blockCounts & 1) {
  40736. h1 ^= k1;
  40737. } else {
  40738. h2 ^= k1;
  40739. }
  40740. }
  40741. this.h1 = h1;
  40742. this.h2 = h2;
  40743. return this;
  40744. },
  40745. hexdigest: function MurmurHash3_64_hexdigest () {
  40746. var h1 = this.h1;
  40747. var h2 = this.h2;
  40748. h1 ^= h2 >>> 1;
  40749. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  40750. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  40751. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  40752. h1 ^= h2 >>> 1;
  40753. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  40754. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  40755. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  40756. h1 ^= h2 >>> 1;
  40757. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  40758. var hex = (arr[i] >>> 0).toString(16);
  40759. while (hex.length < 8) {
  40760. hex = '0' + hex;
  40761. }
  40762. str += hex;
  40763. }
  40764. return str;
  40765. }
  40766. };
  40767. return MurmurHash3_64;
  40768. })();
  40769. }).call((typeof window === 'undefined') ? this : window);
  40770. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  40771. // workerSrc is not set -- using last script url to define default location
  40772. PDFJS.workerSrc = (function () {
  40773. 'use strict';
  40774. var scriptTagContainer = document.body ||
  40775. document.getElementsByTagName('head')[0];
  40776. var pdfjsSrc = scriptTagContainer.lastChild.src;
  40777. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  40778. })();
  40779. }