pdf.combined.js 1.4 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.1.105';
  24. PDFJS.build = '6f3024f';
  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 (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  223. console.log('Error: ' + msg);
  224. console.log(backtrace());
  225. }
  226. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  227. throw new Error(msg);
  228. }
  229. function backtrace() {
  230. try {
  231. throw new Error();
  232. } catch (e) {
  233. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  234. }
  235. }
  236. function assert(cond, msg) {
  237. if (!cond) {
  238. error(msg);
  239. }
  240. }
  241. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  242. unknown: 'unknown',
  243. forms: 'forms',
  244. javaScript: 'javaScript',
  245. smask: 'smask',
  246. shadingPattern: 'shadingPattern',
  247. font: 'font'
  248. };
  249. var UnsupportedManager = PDFJS.UnsupportedManager =
  250. (function UnsupportedManagerClosure() {
  251. var listeners = [];
  252. return {
  253. listen: function (cb) {
  254. listeners.push(cb);
  255. },
  256. notify: function (featureId) {
  257. warn('Unsupported feature "' + featureId + '"');
  258. for (var i = 0, ii = listeners.length; i < ii; i++) {
  259. listeners[i](featureId);
  260. }
  261. }
  262. };
  263. })();
  264. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  265. // absolute URL, it will be returned as is.
  266. function combineUrl(baseUrl, url) {
  267. if (!url) {
  268. return baseUrl;
  269. }
  270. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  271. return url;
  272. }
  273. var i;
  274. if (url.charAt(0) === '/') {
  275. // absolute path
  276. i = baseUrl.indexOf('://');
  277. if (url.charAt(1) === '/') {
  278. ++i;
  279. } else {
  280. i = baseUrl.indexOf('/', i + 3);
  281. }
  282. return baseUrl.substring(0, i) + url;
  283. } else {
  284. // relative path
  285. var pathLength = baseUrl.length;
  286. i = baseUrl.lastIndexOf('#');
  287. pathLength = i >= 0 ? i : pathLength;
  288. i = baseUrl.lastIndexOf('?', pathLength);
  289. pathLength = i >= 0 ? i : pathLength;
  290. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  291. return baseUrl.substring(0, prefixLength + 1) + url;
  292. }
  293. }
  294. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  295. function isValidUrl(url, allowRelative) {
  296. if (!url) {
  297. return false;
  298. }
  299. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  300. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  301. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  302. if (!protocol) {
  303. return allowRelative;
  304. }
  305. protocol = protocol[0].toLowerCase();
  306. switch (protocol) {
  307. case 'http':
  308. case 'https':
  309. case 'ftp':
  310. case 'mailto':
  311. case 'tel':
  312. return true;
  313. default:
  314. return false;
  315. }
  316. }
  317. PDFJS.isValidUrl = isValidUrl;
  318. function shadow(obj, prop, value) {
  319. Object.defineProperty(obj, prop, { value: value,
  320. enumerable: true,
  321. configurable: true,
  322. writable: false });
  323. return value;
  324. }
  325. PDFJS.shadow = shadow;
  326. var PasswordResponses = PDFJS.PasswordResponses = {
  327. NEED_PASSWORD: 1,
  328. INCORRECT_PASSWORD: 2
  329. };
  330. var PasswordException = (function PasswordExceptionClosure() {
  331. function PasswordException(msg, code) {
  332. this.name = 'PasswordException';
  333. this.message = msg;
  334. this.code = code;
  335. }
  336. PasswordException.prototype = new Error();
  337. PasswordException.constructor = PasswordException;
  338. return PasswordException;
  339. })();
  340. PDFJS.PasswordException = PasswordException;
  341. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  342. function UnknownErrorException(msg, details) {
  343. this.name = 'UnknownErrorException';
  344. this.message = msg;
  345. this.details = details;
  346. }
  347. UnknownErrorException.prototype = new Error();
  348. UnknownErrorException.constructor = UnknownErrorException;
  349. return UnknownErrorException;
  350. })();
  351. PDFJS.UnknownErrorException = UnknownErrorException;
  352. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  353. function InvalidPDFException(msg) {
  354. this.name = 'InvalidPDFException';
  355. this.message = msg;
  356. }
  357. InvalidPDFException.prototype = new Error();
  358. InvalidPDFException.constructor = InvalidPDFException;
  359. return InvalidPDFException;
  360. })();
  361. PDFJS.InvalidPDFException = InvalidPDFException;
  362. var MissingPDFException = (function MissingPDFExceptionClosure() {
  363. function MissingPDFException(msg) {
  364. this.name = 'MissingPDFException';
  365. this.message = msg;
  366. }
  367. MissingPDFException.prototype = new Error();
  368. MissingPDFException.constructor = MissingPDFException;
  369. return MissingPDFException;
  370. })();
  371. PDFJS.MissingPDFException = MissingPDFException;
  372. var UnexpectedResponseException =
  373. (function UnexpectedResponseExceptionClosure() {
  374. function UnexpectedResponseException(msg, status) {
  375. this.name = 'UnexpectedResponseException';
  376. this.message = msg;
  377. this.status = status;
  378. }
  379. UnexpectedResponseException.prototype = new Error();
  380. UnexpectedResponseException.constructor = UnexpectedResponseException;
  381. return UnexpectedResponseException;
  382. })();
  383. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  384. var NotImplementedException = (function NotImplementedExceptionClosure() {
  385. function NotImplementedException(msg) {
  386. this.message = msg;
  387. }
  388. NotImplementedException.prototype = new Error();
  389. NotImplementedException.prototype.name = 'NotImplementedException';
  390. NotImplementedException.constructor = NotImplementedException;
  391. return NotImplementedException;
  392. })();
  393. var MissingDataException = (function MissingDataExceptionClosure() {
  394. function MissingDataException(begin, end) {
  395. this.begin = begin;
  396. this.end = end;
  397. this.message = 'Missing data [' + begin + ', ' + end + ')';
  398. }
  399. MissingDataException.prototype = new Error();
  400. MissingDataException.prototype.name = 'MissingDataException';
  401. MissingDataException.constructor = MissingDataException;
  402. return MissingDataException;
  403. })();
  404. var XRefParseException = (function XRefParseExceptionClosure() {
  405. function XRefParseException(msg) {
  406. this.message = msg;
  407. }
  408. XRefParseException.prototype = new Error();
  409. XRefParseException.prototype.name = 'XRefParseException';
  410. XRefParseException.constructor = XRefParseException;
  411. return XRefParseException;
  412. })();
  413. function bytesToString(bytes) {
  414. assert(bytes !== null && typeof bytes === 'object' &&
  415. bytes.length !== undefined, 'Invalid argument for bytesToString');
  416. var length = bytes.length;
  417. var MAX_ARGUMENT_COUNT = 8192;
  418. if (length < MAX_ARGUMENT_COUNT) {
  419. return String.fromCharCode.apply(null, bytes);
  420. }
  421. var strBuf = [];
  422. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  423. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  424. var chunk = bytes.subarray(i, chunkEnd);
  425. strBuf.push(String.fromCharCode.apply(null, chunk));
  426. }
  427. return strBuf.join('');
  428. }
  429. function stringToBytes(str) {
  430. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  431. var length = str.length;
  432. var bytes = new Uint8Array(length);
  433. for (var i = 0; i < length; ++i) {
  434. bytes[i] = str.charCodeAt(i) & 0xFF;
  435. }
  436. return bytes;
  437. }
  438. function string32(value) {
  439. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  440. (value >> 8) & 0xff, value & 0xff);
  441. }
  442. function log2(x) {
  443. var n = 1, i = 0;
  444. while (x > n) {
  445. n <<= 1;
  446. i++;
  447. }
  448. return i;
  449. }
  450. function readInt8(data, start) {
  451. return (data[start] << 24) >> 24;
  452. }
  453. function readUint16(data, offset) {
  454. return (data[offset] << 8) | data[offset + 1];
  455. }
  456. function readUint32(data, offset) {
  457. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  458. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  459. }
  460. // Lazy test the endianness of the platform
  461. // NOTE: This will be 'true' for simulated TypedArrays
  462. function isLittleEndian() {
  463. var buffer8 = new Uint8Array(2);
  464. buffer8[0] = 1;
  465. var buffer16 = new Uint16Array(buffer8.buffer);
  466. return (buffer16[0] === 1);
  467. }
  468. Object.defineProperty(PDFJS, 'isLittleEndian', {
  469. configurable: true,
  470. get: function PDFJS_isLittleEndian() {
  471. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  472. }
  473. });
  474. // Lazy test if the userAgant support CanvasTypedArrays
  475. function hasCanvasTypedArrays() {
  476. var canvas = document.createElement('canvas');
  477. canvas.width = canvas.height = 1;
  478. var ctx = canvas.getContext('2d');
  479. var imageData = ctx.createImageData(1, 1);
  480. return (typeof imageData.data.buffer !== 'undefined');
  481. }
  482. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  483. configurable: true,
  484. get: function PDFJS_hasCanvasTypedArrays() {
  485. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  486. }
  487. });
  488. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  489. function Uint32ArrayView(buffer, length) {
  490. this.buffer = buffer;
  491. this.byteLength = buffer.length;
  492. this.length = length === undefined ? (this.byteLength >> 2) : length;
  493. ensureUint32ArrayViewProps(this.length);
  494. }
  495. Uint32ArrayView.prototype = Object.create(null);
  496. var uint32ArrayViewSetters = 0;
  497. function createUint32ArrayProp(index) {
  498. return {
  499. get: function () {
  500. var buffer = this.buffer, offset = index << 2;
  501. return (buffer[offset] | (buffer[offset + 1] << 8) |
  502. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  503. },
  504. set: function (value) {
  505. var buffer = this.buffer, offset = index << 2;
  506. buffer[offset] = value & 255;
  507. buffer[offset + 1] = (value >> 8) & 255;
  508. buffer[offset + 2] = (value >> 16) & 255;
  509. buffer[offset + 3] = (value >>> 24) & 255;
  510. }
  511. };
  512. }
  513. function ensureUint32ArrayViewProps(length) {
  514. while (uint32ArrayViewSetters < length) {
  515. Object.defineProperty(Uint32ArrayView.prototype,
  516. uint32ArrayViewSetters,
  517. createUint32ArrayProp(uint32ArrayViewSetters));
  518. uint32ArrayViewSetters++;
  519. }
  520. }
  521. return Uint32ArrayView;
  522. })();
  523. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  524. var Util = PDFJS.Util = (function UtilClosure() {
  525. function Util() {}
  526. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  527. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  528. // creating many intermediate strings.
  529. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  530. rgbBuf[1] = r;
  531. rgbBuf[3] = g;
  532. rgbBuf[5] = b;
  533. return rgbBuf.join('');
  534. };
  535. // Concatenates two transformation matrices together and returns the result.
  536. Util.transform = function Util_transform(m1, m2) {
  537. return [
  538. m1[0] * m2[0] + m1[2] * m2[1],
  539. m1[1] * m2[0] + m1[3] * m2[1],
  540. m1[0] * m2[2] + m1[2] * m2[3],
  541. m1[1] * m2[2] + m1[3] * m2[3],
  542. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  543. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  544. ];
  545. };
  546. // For 2d affine transforms
  547. Util.applyTransform = function Util_applyTransform(p, m) {
  548. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  549. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  550. return [xt, yt];
  551. };
  552. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  553. var d = m[0] * m[3] - m[1] * m[2];
  554. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  555. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  556. return [xt, yt];
  557. };
  558. // Applies the transform to the rectangle and finds the minimum axially
  559. // aligned bounding box.
  560. Util.getAxialAlignedBoundingBox =
  561. function Util_getAxialAlignedBoundingBox(r, m) {
  562. var p1 = Util.applyTransform(r, m);
  563. var p2 = Util.applyTransform(r.slice(2, 4), m);
  564. var p3 = Util.applyTransform([r[0], r[3]], m);
  565. var p4 = Util.applyTransform([r[2], r[1]], m);
  566. return [
  567. Math.min(p1[0], p2[0], p3[0], p4[0]),
  568. Math.min(p1[1], p2[1], p3[1], p4[1]),
  569. Math.max(p1[0], p2[0], p3[0], p4[0]),
  570. Math.max(p1[1], p2[1], p3[1], p4[1])
  571. ];
  572. };
  573. Util.inverseTransform = function Util_inverseTransform(m) {
  574. var d = m[0] * m[3] - m[1] * m[2];
  575. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  576. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  577. };
  578. // Apply a generic 3d matrix M on a 3-vector v:
  579. // | a b c | | X |
  580. // | d e f | x | Y |
  581. // | g h i | | Z |
  582. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  583. // with v as [X,Y,Z]
  584. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  585. return [
  586. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  587. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  588. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  589. ];
  590. };
  591. // This calculation uses Singular Value Decomposition.
  592. // The SVD can be represented with formula A = USV. We are interested in the
  593. // matrix S here because it represents the scale values.
  594. Util.singularValueDecompose2dScale =
  595. function Util_singularValueDecompose2dScale(m) {
  596. var transpose = [m[0], m[2], m[1], m[3]];
  597. // Multiply matrix m with its transpose.
  598. var a = m[0] * transpose[0] + m[1] * transpose[2];
  599. var b = m[0] * transpose[1] + m[1] * transpose[3];
  600. var c = m[2] * transpose[0] + m[3] * transpose[2];
  601. var d = m[2] * transpose[1] + m[3] * transpose[3];
  602. // Solve the second degree polynomial to get roots.
  603. var first = (a + d) / 2;
  604. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  605. var sx = first + second || 1;
  606. var sy = first - second || 1;
  607. // Scale values are the square roots of the eigenvalues.
  608. return [Math.sqrt(sx), Math.sqrt(sy)];
  609. };
  610. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  611. // For coordinate systems whose origin lies in the bottom-left, this
  612. // means normalization to (BL,TR) ordering. For systems with origin in the
  613. // top-left, this means (TL,BR) ordering.
  614. Util.normalizeRect = function Util_normalizeRect(rect) {
  615. var r = rect.slice(0); // clone rect
  616. if (rect[0] > rect[2]) {
  617. r[0] = rect[2];
  618. r[2] = rect[0];
  619. }
  620. if (rect[1] > rect[3]) {
  621. r[1] = rect[3];
  622. r[3] = rect[1];
  623. }
  624. return r;
  625. };
  626. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  627. // intersection of rect1 and rect2. If no intersection, returns 'false'
  628. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  629. Util.intersect = function Util_intersect(rect1, rect2) {
  630. function compare(a, b) {
  631. return a - b;
  632. }
  633. // Order points along the axes
  634. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  635. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  636. result = [];
  637. rect1 = Util.normalizeRect(rect1);
  638. rect2 = Util.normalizeRect(rect2);
  639. // X: first and second points belong to different rectangles?
  640. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  641. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  642. // Intersection must be between second and third points
  643. result[0] = orderedX[1];
  644. result[2] = orderedX[2];
  645. } else {
  646. return false;
  647. }
  648. // Y: first and second points belong to different rectangles?
  649. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  650. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  651. // Intersection must be between second and third points
  652. result[1] = orderedY[1];
  653. result[3] = orderedY[2];
  654. } else {
  655. return false;
  656. }
  657. return result;
  658. };
  659. Util.sign = function Util_sign(num) {
  660. return num < 0 ? -1 : 1;
  661. };
  662. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  663. Array.prototype.push.apply(arr1, arr2);
  664. };
  665. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  666. Array.prototype.unshift.apply(arr1, arr2);
  667. };
  668. Util.extendObj = function extendObj(obj1, obj2) {
  669. for (var key in obj2) {
  670. obj1[key] = obj2[key];
  671. }
  672. };
  673. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  674. name) {
  675. while (dict && !dict.has(name)) {
  676. dict = dict.get('Parent');
  677. }
  678. if (!dict) {
  679. return null;
  680. }
  681. return dict.get(name);
  682. };
  683. Util.inherit = function Util_inherit(sub, base, prototype) {
  684. sub.prototype = Object.create(base.prototype);
  685. sub.prototype.constructor = sub;
  686. for (var prop in prototype) {
  687. sub.prototype[prop] = prototype[prop];
  688. }
  689. };
  690. Util.loadScript = function Util_loadScript(src, callback) {
  691. var script = document.createElement('script');
  692. var loaded = false;
  693. script.setAttribute('src', src);
  694. if (callback) {
  695. script.onload = function() {
  696. if (!loaded) {
  697. callback();
  698. }
  699. loaded = true;
  700. };
  701. }
  702. document.getElementsByTagName('head')[0].appendChild(script);
  703. };
  704. return Util;
  705. })();
  706. /**
  707. * PDF page viewport created based on scale, rotation and offset.
  708. * @class
  709. * @alias PDFJS.PageViewport
  710. */
  711. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  712. /**
  713. * @constructor
  714. * @private
  715. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  716. * @param scale {number} scale of the viewport.
  717. * @param rotation {number} rotations of the viewport in degrees.
  718. * @param offsetX {number} offset X
  719. * @param offsetY {number} offset Y
  720. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  721. */
  722. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  723. this.viewBox = viewBox;
  724. this.scale = scale;
  725. this.rotation = rotation;
  726. this.offsetX = offsetX;
  727. this.offsetY = offsetY;
  728. // creating transform to convert pdf coordinate system to the normal
  729. // canvas like coordinates taking in account scale and rotation
  730. var centerX = (viewBox[2] + viewBox[0]) / 2;
  731. var centerY = (viewBox[3] + viewBox[1]) / 2;
  732. var rotateA, rotateB, rotateC, rotateD;
  733. rotation = rotation % 360;
  734. rotation = rotation < 0 ? rotation + 360 : rotation;
  735. switch (rotation) {
  736. case 180:
  737. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  738. break;
  739. case 90:
  740. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  741. break;
  742. case 270:
  743. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  744. break;
  745. //case 0:
  746. default:
  747. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  748. break;
  749. }
  750. if (dontFlip) {
  751. rotateC = -rotateC; rotateD = -rotateD;
  752. }
  753. var offsetCanvasX, offsetCanvasY;
  754. var width, height;
  755. if (rotateA === 0) {
  756. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  757. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  758. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  759. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  760. } else {
  761. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  762. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  763. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  764. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  765. }
  766. // creating transform for the following operations:
  767. // translate(-centerX, -centerY), rotate and flip vertically,
  768. // scale, and translate(offsetCanvasX, offsetCanvasY)
  769. this.transform = [
  770. rotateA * scale,
  771. rotateB * scale,
  772. rotateC * scale,
  773. rotateD * scale,
  774. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  775. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  776. ];
  777. this.width = width;
  778. this.height = height;
  779. this.fontScale = scale;
  780. }
  781. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  782. /**
  783. * Clones viewport with additional properties.
  784. * @param args {Object} (optional) If specified, may contain the 'scale' or
  785. * 'rotation' properties to override the corresponding properties in
  786. * the cloned viewport.
  787. * @returns {PDFJS.PageViewport} Cloned viewport.
  788. */
  789. clone: function PageViewPort_clone(args) {
  790. args = args || {};
  791. var scale = 'scale' in args ? args.scale : this.scale;
  792. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  793. return new PageViewport(this.viewBox.slice(), scale, rotation,
  794. this.offsetX, this.offsetY, args.dontFlip);
  795. },
  796. /**
  797. * Converts PDF point to the viewport coordinates. For examples, useful for
  798. * converting PDF location into canvas pixel coordinates.
  799. * @param x {number} X coordinate.
  800. * @param y {number} Y coordinate.
  801. * @returns {Object} Object that contains 'x' and 'y' properties of the
  802. * point in the viewport coordinate space.
  803. * @see {@link convertToPdfPoint}
  804. * @see {@link convertToViewportRectangle}
  805. */
  806. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  807. return Util.applyTransform([x, y], this.transform);
  808. },
  809. /**
  810. * Converts PDF rectangle to the viewport coordinates.
  811. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  812. * @returns {Array} Contains corresponding coordinates of the rectangle
  813. * in the viewport coordinate space.
  814. * @see {@link convertToViewportPoint}
  815. */
  816. convertToViewportRectangle:
  817. function PageViewport_convertToViewportRectangle(rect) {
  818. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  819. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  820. return [tl[0], tl[1], br[0], br[1]];
  821. },
  822. /**
  823. * Converts viewport coordinates to the PDF location. For examples, useful
  824. * for converting canvas pixel location into PDF one.
  825. * @param x {number} X coordinate.
  826. * @param y {number} Y coordinate.
  827. * @returns {Object} Object that contains 'x' and 'y' properties of the
  828. * point in the PDF coordinate space.
  829. * @see {@link convertToViewportPoint}
  830. */
  831. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  832. return Util.applyInverseTransform([x, y], this.transform);
  833. }
  834. };
  835. return PageViewport;
  836. })();
  837. var PDFStringTranslateTable = [
  838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  839. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  840. 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,
  841. 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,
  842. 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,
  843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  844. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  845. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  846. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  847. ];
  848. function stringToPDFString(str) {
  849. var i, n = str.length, strBuf = [];
  850. if (str[0] === '\xFE' && str[1] === '\xFF') {
  851. // UTF16BE BOM
  852. for (i = 2; i < n; i += 2) {
  853. strBuf.push(String.fromCharCode(
  854. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  855. }
  856. } else {
  857. for (i = 0; i < n; ++i) {
  858. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  859. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  860. }
  861. }
  862. return strBuf.join('');
  863. }
  864. function stringToUTF8String(str) {
  865. return decodeURIComponent(escape(str));
  866. }
  867. function isEmptyObj(obj) {
  868. for (var key in obj) {
  869. return false;
  870. }
  871. return true;
  872. }
  873. function isBool(v) {
  874. return typeof v === 'boolean';
  875. }
  876. function isInt(v) {
  877. return typeof v === 'number' && ((v | 0) === v);
  878. }
  879. function isNum(v) {
  880. return typeof v === 'number';
  881. }
  882. function isString(v) {
  883. return typeof v === 'string';
  884. }
  885. function isName(v) {
  886. return v instanceof Name;
  887. }
  888. function isCmd(v, cmd) {
  889. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  890. }
  891. function isDict(v, type) {
  892. if (!(v instanceof Dict)) {
  893. return false;
  894. }
  895. if (!type) {
  896. return true;
  897. }
  898. var dictType = v.get('Type');
  899. return isName(dictType) && dictType.name === type;
  900. }
  901. function isArray(v) {
  902. return v instanceof Array;
  903. }
  904. function isStream(v) {
  905. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  906. }
  907. function isArrayBuffer(v) {
  908. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  909. }
  910. function isRef(v) {
  911. return v instanceof Ref;
  912. }
  913. /**
  914. * Promise Capability object.
  915. *
  916. * @typedef {Object} PromiseCapability
  917. * @property {Promise} promise - A promise object.
  918. * @property {function} resolve - Fullfills the promise.
  919. * @property {function} reject - Rejects the promise.
  920. */
  921. /**
  922. * Creates a promise capability object.
  923. * @alias PDFJS.createPromiseCapability
  924. *
  925. * @return {PromiseCapability} A capability object contains:
  926. * - a Promise, resolve and reject methods.
  927. */
  928. function createPromiseCapability() {
  929. var capability = {};
  930. capability.promise = new Promise(function (resolve, reject) {
  931. capability.resolve = resolve;
  932. capability.reject = reject;
  933. });
  934. return capability;
  935. }
  936. PDFJS.createPromiseCapability = createPromiseCapability;
  937. /**
  938. * Polyfill for Promises:
  939. * The following promise implementation tries to generally implement the
  940. * Promise/A+ spec. Some notable differences from other promise libaries are:
  941. * - There currently isn't a seperate deferred and promise object.
  942. * - Unhandled rejections eventually show an error if they aren't handled.
  943. *
  944. * Based off of the work in:
  945. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  946. */
  947. (function PromiseClosure() {
  948. if (globalScope.Promise) {
  949. // Promises existing in the DOM/Worker, checking presence of all/resolve
  950. if (typeof globalScope.Promise.all !== 'function') {
  951. globalScope.Promise.all = function (iterable) {
  952. var count = 0, results = [], resolve, reject;
  953. var promise = new globalScope.Promise(function (resolve_, reject_) {
  954. resolve = resolve_;
  955. reject = reject_;
  956. });
  957. iterable.forEach(function (p, i) {
  958. count++;
  959. p.then(function (result) {
  960. results[i] = result;
  961. count--;
  962. if (count === 0) {
  963. resolve(results);
  964. }
  965. }, reject);
  966. });
  967. if (count === 0) {
  968. resolve(results);
  969. }
  970. return promise;
  971. };
  972. }
  973. if (typeof globalScope.Promise.resolve !== 'function') {
  974. globalScope.Promise.resolve = function (value) {
  975. return new globalScope.Promise(function (resolve) { resolve(value); });
  976. };
  977. }
  978. if (typeof globalScope.Promise.reject !== 'function') {
  979. globalScope.Promise.reject = function (reason) {
  980. return new globalScope.Promise(function (resolve, reject) {
  981. reject(reason);
  982. });
  983. };
  984. }
  985. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  986. globalScope.Promise.prototype.catch = function (onReject) {
  987. return globalScope.Promise.prototype.then(undefined, onReject);
  988. };
  989. }
  990. return;
  991. }
  992. var STATUS_PENDING = 0;
  993. var STATUS_RESOLVED = 1;
  994. var STATUS_REJECTED = 2;
  995. // In an attempt to avoid silent exceptions, unhandled rejections are
  996. // tracked and if they aren't handled in a certain amount of time an
  997. // error is logged.
  998. var REJECTION_TIMEOUT = 500;
  999. var HandlerManager = {
  1000. handlers: [],
  1001. running: false,
  1002. unhandledRejections: [],
  1003. pendingRejectionCheck: false,
  1004. scheduleHandlers: function scheduleHandlers(promise) {
  1005. if (promise._status === STATUS_PENDING) {
  1006. return;
  1007. }
  1008. this.handlers = this.handlers.concat(promise._handlers);
  1009. promise._handlers = [];
  1010. if (this.running) {
  1011. return;
  1012. }
  1013. this.running = true;
  1014. setTimeout(this.runHandlers.bind(this), 0);
  1015. },
  1016. runHandlers: function runHandlers() {
  1017. var RUN_TIMEOUT = 1; // ms
  1018. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1019. while (this.handlers.length > 0) {
  1020. var handler = this.handlers.shift();
  1021. var nextStatus = handler.thisPromise._status;
  1022. var nextValue = handler.thisPromise._value;
  1023. try {
  1024. if (nextStatus === STATUS_RESOLVED) {
  1025. if (typeof handler.onResolve === 'function') {
  1026. nextValue = handler.onResolve(nextValue);
  1027. }
  1028. } else if (typeof handler.onReject === 'function') {
  1029. nextValue = handler.onReject(nextValue);
  1030. nextStatus = STATUS_RESOLVED;
  1031. if (handler.thisPromise._unhandledRejection) {
  1032. this.removeUnhandeledRejection(handler.thisPromise);
  1033. }
  1034. }
  1035. } catch (ex) {
  1036. nextStatus = STATUS_REJECTED;
  1037. nextValue = ex;
  1038. }
  1039. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1040. if (Date.now() >= timeoutAt) {
  1041. break;
  1042. }
  1043. }
  1044. if (this.handlers.length > 0) {
  1045. setTimeout(this.runHandlers.bind(this), 0);
  1046. return;
  1047. }
  1048. this.running = false;
  1049. },
  1050. addUnhandledRejection: function addUnhandledRejection(promise) {
  1051. this.unhandledRejections.push({
  1052. promise: promise,
  1053. time: Date.now()
  1054. });
  1055. this.scheduleRejectionCheck();
  1056. },
  1057. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1058. promise._unhandledRejection = false;
  1059. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1060. if (this.unhandledRejections[i].promise === promise) {
  1061. this.unhandledRejections.splice(i);
  1062. i--;
  1063. }
  1064. }
  1065. },
  1066. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1067. if (this.pendingRejectionCheck) {
  1068. return;
  1069. }
  1070. this.pendingRejectionCheck = true;
  1071. setTimeout(function rejectionCheck() {
  1072. this.pendingRejectionCheck = false;
  1073. var now = Date.now();
  1074. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1075. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1076. var unhandled = this.unhandledRejections[i].promise._value;
  1077. var msg = 'Unhandled rejection: ' + unhandled;
  1078. if (unhandled.stack) {
  1079. msg += '\n' + unhandled.stack;
  1080. }
  1081. warn(msg);
  1082. this.unhandledRejections.splice(i);
  1083. i--;
  1084. }
  1085. }
  1086. if (this.unhandledRejections.length) {
  1087. this.scheduleRejectionCheck();
  1088. }
  1089. }.bind(this), REJECTION_TIMEOUT);
  1090. }
  1091. };
  1092. function Promise(resolver) {
  1093. this._status = STATUS_PENDING;
  1094. this._handlers = [];
  1095. try {
  1096. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1097. } catch (e) {
  1098. this._reject(e);
  1099. }
  1100. }
  1101. /**
  1102. * Builds a promise that is resolved when all the passed in promises are
  1103. * resolved.
  1104. * @param {array} array of data and/or promises to wait for.
  1105. * @return {Promise} New dependant promise.
  1106. */
  1107. Promise.all = function Promise_all(promises) {
  1108. var resolveAll, rejectAll;
  1109. var deferred = new Promise(function (resolve, reject) {
  1110. resolveAll = resolve;
  1111. rejectAll = reject;
  1112. });
  1113. var unresolved = promises.length;
  1114. var results = [];
  1115. if (unresolved === 0) {
  1116. resolveAll(results);
  1117. return deferred;
  1118. }
  1119. function reject(reason) {
  1120. if (deferred._status === STATUS_REJECTED) {
  1121. return;
  1122. }
  1123. results = [];
  1124. rejectAll(reason);
  1125. }
  1126. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1127. var promise = promises[i];
  1128. var resolve = (function(i) {
  1129. return function(value) {
  1130. if (deferred._status === STATUS_REJECTED) {
  1131. return;
  1132. }
  1133. results[i] = value;
  1134. unresolved--;
  1135. if (unresolved === 0) {
  1136. resolveAll(results);
  1137. }
  1138. };
  1139. })(i);
  1140. if (Promise.isPromise(promise)) {
  1141. promise.then(resolve, reject);
  1142. } else {
  1143. resolve(promise);
  1144. }
  1145. }
  1146. return deferred;
  1147. };
  1148. /**
  1149. * Checks if the value is likely a promise (has a 'then' function).
  1150. * @return {boolean} true if value is thenable
  1151. */
  1152. Promise.isPromise = function Promise_isPromise(value) {
  1153. return value && typeof value.then === 'function';
  1154. };
  1155. /**
  1156. * Creates resolved promise
  1157. * @param value resolve value
  1158. * @returns {Promise}
  1159. */
  1160. Promise.resolve = function Promise_resolve(value) {
  1161. return new Promise(function (resolve) { resolve(value); });
  1162. };
  1163. /**
  1164. * Creates rejected promise
  1165. * @param reason rejection value
  1166. * @returns {Promise}
  1167. */
  1168. Promise.reject = function Promise_reject(reason) {
  1169. return new Promise(function (resolve, reject) { reject(reason); });
  1170. };
  1171. Promise.prototype = {
  1172. _status: null,
  1173. _value: null,
  1174. _handlers: null,
  1175. _unhandledRejection: null,
  1176. _updateStatus: function Promise__updateStatus(status, value) {
  1177. if (this._status === STATUS_RESOLVED ||
  1178. this._status === STATUS_REJECTED) {
  1179. return;
  1180. }
  1181. if (status === STATUS_RESOLVED &&
  1182. Promise.isPromise(value)) {
  1183. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1184. this._updateStatus.bind(this, STATUS_REJECTED));
  1185. return;
  1186. }
  1187. this._status = status;
  1188. this._value = value;
  1189. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1190. this._unhandledRejection = true;
  1191. HandlerManager.addUnhandledRejection(this);
  1192. }
  1193. HandlerManager.scheduleHandlers(this);
  1194. },
  1195. _resolve: function Promise_resolve(value) {
  1196. this._updateStatus(STATUS_RESOLVED, value);
  1197. },
  1198. _reject: function Promise_reject(reason) {
  1199. this._updateStatus(STATUS_REJECTED, reason);
  1200. },
  1201. then: function Promise_then(onResolve, onReject) {
  1202. var nextPromise = new Promise(function (resolve, reject) {
  1203. this.resolve = resolve;
  1204. this.reject = reject;
  1205. });
  1206. this._handlers.push({
  1207. thisPromise: this,
  1208. onResolve: onResolve,
  1209. onReject: onReject,
  1210. nextPromise: nextPromise
  1211. });
  1212. HandlerManager.scheduleHandlers(this);
  1213. return nextPromise;
  1214. },
  1215. catch: function Promise_catch(onReject) {
  1216. return this.then(undefined, onReject);
  1217. }
  1218. };
  1219. globalScope.Promise = Promise;
  1220. })();
  1221. var StatTimer = (function StatTimerClosure() {
  1222. function rpad(str, pad, length) {
  1223. while (str.length < length) {
  1224. str += pad;
  1225. }
  1226. return str;
  1227. }
  1228. function StatTimer() {
  1229. this.started = {};
  1230. this.times = [];
  1231. this.enabled = true;
  1232. }
  1233. StatTimer.prototype = {
  1234. time: function StatTimer_time(name) {
  1235. if (!this.enabled) {
  1236. return;
  1237. }
  1238. if (name in this.started) {
  1239. warn('Timer is already running for ' + name);
  1240. }
  1241. this.started[name] = Date.now();
  1242. },
  1243. timeEnd: function StatTimer_timeEnd(name) {
  1244. if (!this.enabled) {
  1245. return;
  1246. }
  1247. if (!(name in this.started)) {
  1248. warn('Timer has not been started for ' + name);
  1249. }
  1250. this.times.push({
  1251. 'name': name,
  1252. 'start': this.started[name],
  1253. 'end': Date.now()
  1254. });
  1255. // Remove timer from started so it can be called again.
  1256. delete this.started[name];
  1257. },
  1258. toString: function StatTimer_toString() {
  1259. var i, ii;
  1260. var times = this.times;
  1261. var out = '';
  1262. // Find the longest name for padding purposes.
  1263. var longest = 0;
  1264. for (i = 0, ii = times.length; i < ii; ++i) {
  1265. var name = times[i]['name'];
  1266. if (name.length > longest) {
  1267. longest = name.length;
  1268. }
  1269. }
  1270. for (i = 0, ii = times.length; i < ii; ++i) {
  1271. var span = times[i];
  1272. var duration = span.end - span.start;
  1273. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1274. }
  1275. return out;
  1276. }
  1277. };
  1278. return StatTimer;
  1279. })();
  1280. PDFJS.createBlob = function createBlob(data, contentType) {
  1281. if (typeof Blob !== 'undefined') {
  1282. return new Blob([data], { type: contentType });
  1283. }
  1284. // Blob builder is deprecated in FF14 and removed in FF18.
  1285. var bb = new MozBlobBuilder();
  1286. bb.append(data);
  1287. return bb.getBlob(contentType);
  1288. };
  1289. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1290. // Blob/createObjectURL is not available, falling back to data schema.
  1291. var digits =
  1292. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1293. return function createObjectURL(data, contentType) {
  1294. if (!PDFJS.disableCreateObjectURL &&
  1295. typeof URL !== 'undefined' && URL.createObjectURL) {
  1296. var blob = PDFJS.createBlob(data, contentType);
  1297. return URL.createObjectURL(blob);
  1298. }
  1299. var buffer = 'data:' + contentType + ';base64,';
  1300. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1301. var b1 = data[i] & 0xFF;
  1302. var b2 = data[i + 1] & 0xFF;
  1303. var b3 = data[i + 2] & 0xFF;
  1304. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1305. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1306. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1307. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1308. }
  1309. return buffer;
  1310. };
  1311. })();
  1312. function MessageHandler(name, comObj) {
  1313. this.name = name;
  1314. this.comObj = comObj;
  1315. this.callbackIndex = 1;
  1316. this.postMessageTransfers = true;
  1317. var callbacksCapabilities = this.callbacksCapabilities = {};
  1318. var ah = this.actionHandler = {};
  1319. ah['console_log'] = [function ahConsoleLog(data) {
  1320. console.log.apply(console, data);
  1321. }];
  1322. ah['console_error'] = [function ahConsoleError(data) {
  1323. console.error.apply(console, data);
  1324. }];
  1325. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1326. UnsupportedManager.notify(data);
  1327. }];
  1328. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1329. var data = event.data;
  1330. if (data.isReply) {
  1331. var callbackId = data.callbackId;
  1332. if (data.callbackId in callbacksCapabilities) {
  1333. var callback = callbacksCapabilities[callbackId];
  1334. delete callbacksCapabilities[callbackId];
  1335. if ('error' in data) {
  1336. callback.reject(data.error);
  1337. } else {
  1338. callback.resolve(data.data);
  1339. }
  1340. } else {
  1341. error('Cannot resolve callback ' + callbackId);
  1342. }
  1343. } else if (data.action in ah) {
  1344. var action = ah[data.action];
  1345. if (data.callbackId) {
  1346. Promise.resolve().then(function () {
  1347. return action[0].call(action[1], data.data);
  1348. }).then(function (result) {
  1349. comObj.postMessage({
  1350. isReply: true,
  1351. callbackId: data.callbackId,
  1352. data: result
  1353. });
  1354. }, function (reason) {
  1355. comObj.postMessage({
  1356. isReply: true,
  1357. callbackId: data.callbackId,
  1358. error: reason
  1359. });
  1360. });
  1361. } else {
  1362. action[0].call(action[1], data.data);
  1363. }
  1364. } else {
  1365. error('Unknown action from worker: ' + data.action);
  1366. }
  1367. };
  1368. }
  1369. MessageHandler.prototype = {
  1370. on: function messageHandlerOn(actionName, handler, scope) {
  1371. var ah = this.actionHandler;
  1372. if (ah[actionName]) {
  1373. error('There is already an actionName called "' + actionName + '"');
  1374. }
  1375. ah[actionName] = [handler, scope];
  1376. },
  1377. /**
  1378. * Sends a message to the comObj to invoke the action with the supplied data.
  1379. * @param {String} actionName Action to call.
  1380. * @param {JSON} data JSON data to send.
  1381. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1382. */
  1383. send: function messageHandlerSend(actionName, data, transfers) {
  1384. var message = {
  1385. action: actionName,
  1386. data: data
  1387. };
  1388. this.postMessage(message, transfers);
  1389. },
  1390. /**
  1391. * Sends a message to the comObj to invoke the action with the supplied data.
  1392. * Expects that other side will callback with the response.
  1393. * @param {String} actionName Action to call.
  1394. * @param {JSON} data JSON data to send.
  1395. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1396. * @returns {Promise} Promise to be resolved with response data.
  1397. */
  1398. sendWithPromise:
  1399. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1400. var callbackId = this.callbackIndex++;
  1401. var message = {
  1402. action: actionName,
  1403. data: data,
  1404. callbackId: callbackId
  1405. };
  1406. var capability = createPromiseCapability();
  1407. this.callbacksCapabilities[callbackId] = capability;
  1408. try {
  1409. this.postMessage(message, transfers);
  1410. } catch (e) {
  1411. capability.reject(e);
  1412. }
  1413. return capability.promise;
  1414. },
  1415. /**
  1416. * Sends raw message to the comObj.
  1417. * @private
  1418. * @param message {Object} Raw message.
  1419. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1420. */
  1421. postMessage: function (message, transfers) {
  1422. if (transfers && this.postMessageTransfers) {
  1423. this.comObj.postMessage(message, transfers);
  1424. } else {
  1425. this.comObj.postMessage(message);
  1426. }
  1427. }
  1428. };
  1429. function loadJpegStream(id, imageUrl, objs) {
  1430. var img = new Image();
  1431. img.onload = (function loadJpegStream_onloadClosure() {
  1432. objs.resolve(id, img);
  1433. });
  1434. img.onerror = (function loadJpegStream_onerrorClosure() {
  1435. objs.resolve(id, null);
  1436. warn('Error during JPEG image loading');
  1437. });
  1438. img.src = imageUrl;
  1439. }
  1440. /**
  1441. * The maximum allowed image size in total pixels e.g. width * height. Images
  1442. * above this value will not be drawn. Use -1 for no limit.
  1443. * @var {number}
  1444. */
  1445. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1446. -1 : PDFJS.maxImageSize);
  1447. /**
  1448. * The url of where the predefined Adobe CMaps are located. Include trailing
  1449. * slash.
  1450. * @var {string}
  1451. */
  1452. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1453. /**
  1454. * Specifies if CMaps are binary packed.
  1455. * @var {boolean}
  1456. */
  1457. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1458. /**
  1459. * By default fonts are converted to OpenType fonts and loaded via font face
  1460. * rules. If disabled, the font will be rendered using a built in font renderer
  1461. * that constructs the glyphs with primitive path commands.
  1462. * @var {boolean}
  1463. */
  1464. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1465. false : PDFJS.disableFontFace);
  1466. /**
  1467. * Path for image resources, mainly for annotation icons. Include trailing
  1468. * slash.
  1469. * @var {string}
  1470. */
  1471. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1472. '' : PDFJS.imageResourcesPath);
  1473. /**
  1474. * Disable the web worker and run all code on the main thread. This will happen
  1475. * automatically if the browser doesn't support workers or sending typed arrays
  1476. * to workers.
  1477. * @var {boolean}
  1478. */
  1479. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1480. false : PDFJS.disableWorker);
  1481. /**
  1482. * Path and filename of the worker file. Required when the worker is enabled in
  1483. * development mode. If unspecified in the production build, the worker will be
  1484. * loaded based on the location of the pdf.js file.
  1485. * @var {string}
  1486. */
  1487. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1488. /**
  1489. * Disable range request loading of PDF files. When enabled and if the server
  1490. * supports partial content requests then the PDF will be fetched in chunks.
  1491. * Enabled (false) by default.
  1492. * @var {boolean}
  1493. */
  1494. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1495. false : PDFJS.disableRange);
  1496. /**
  1497. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1498. * in chunks. This default behavior can be disabled.
  1499. * @var {boolean}
  1500. */
  1501. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1502. false : PDFJS.disableStream);
  1503. /**
  1504. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1505. * will automatically keep fetching more data even if it isn't needed to display
  1506. * the current page. This default behavior can be disabled.
  1507. *
  1508. * NOTE: It is also necessary to disable streaming, see above,
  1509. * in order for disabling of pre-fetching to work correctly.
  1510. * @var {boolean}
  1511. */
  1512. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1513. false : PDFJS.disableAutoFetch);
  1514. /**
  1515. * Enables special hooks for debugging PDF.js.
  1516. * @var {boolean}
  1517. */
  1518. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1519. /**
  1520. * Enables transfer usage in postMessage for ArrayBuffers.
  1521. * @var {boolean}
  1522. */
  1523. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1524. true : PDFJS.postMessageTransfers);
  1525. /**
  1526. * Disables URL.createObjectURL usage.
  1527. * @var {boolean}
  1528. */
  1529. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1530. false : PDFJS.disableCreateObjectURL);
  1531. /**
  1532. * Disables WebGL usage.
  1533. * @var {boolean}
  1534. */
  1535. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1536. true : PDFJS.disableWebGL);
  1537. /**
  1538. * Disables fullscreen support, and by extension Presentation Mode,
  1539. * in browsers which support the fullscreen API.
  1540. * @var {boolean}
  1541. */
  1542. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  1543. false : PDFJS.disableFullscreen);
  1544. /**
  1545. * Enables CSS only zooming.
  1546. * @var {boolean}
  1547. */
  1548. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1549. false : PDFJS.useOnlyCssZoom);
  1550. /**
  1551. * Controls the logging level.
  1552. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1553. * - errors
  1554. * - warnings [default]
  1555. * - infos
  1556. * @var {number}
  1557. */
  1558. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1559. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1560. /**
  1561. * The maximum supported canvas size in total pixels e.g. width * height.
  1562. * The default value is 4096 * 4096. Use -1 for no limit.
  1563. * @var {number}
  1564. */
  1565. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1566. 16777216 : PDFJS.maxCanvasPixels);
  1567. /**
  1568. * Opens external links in a new window if enabled. The default behavior opens
  1569. * external links in the PDF.js window.
  1570. * @var {boolean}
  1571. */
  1572. PDFJS.openExternalLinksInNewWindow = (
  1573. PDFJS.openExternalLinksInNewWindow === undefined ?
  1574. false : PDFJS.openExternalLinksInNewWindow);
  1575. /**
  1576. * Document initialization / loading parameters object.
  1577. *
  1578. * @typedef {Object} DocumentInitParameters
  1579. * @property {string} url - The URL of the PDF.
  1580. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1581. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1582. * use atob() to convert it to a binary string first.
  1583. * @property {Object} httpHeaders - Basic authentication headers.
  1584. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1585. * Access-Control requests should be made using credentials such as cookies
  1586. * or authorization headers. The default is false.
  1587. * @property {string} password - For decrypting password-protected PDFs.
  1588. * @property {TypedArray} initialData - A typed array with the first portion or
  1589. * all of the pdf data. Used by the extension since some data is already
  1590. * loaded before the switch to range requests.
  1591. * @property {number} length - The PDF file length. It's used for progress
  1592. * reports and range requests operations.
  1593. * @property {PDFDataRangeTransport} range
  1594. */
  1595. /**
  1596. * @typedef {Object} PDFDocumentStats
  1597. * @property {Array} streamTypes - Used stream types in the document (an item
  1598. * is set to true if specific stream ID was used in the document).
  1599. * @property {Array} fontTypes - Used font type in the document (an item is set
  1600. * to true if specific font ID was used in the document).
  1601. */
  1602. /**
  1603. * This is the main entry point for loading a PDF and interacting with it.
  1604. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1605. * is used, which means it must follow the same origin rules that any XHR does
  1606. * e.g. No cross domain requests without CORS.
  1607. *
  1608. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1609. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1610. * already populated with data or parameter object.
  1611. *
  1612. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1613. * if you want to manually serve range requests for data in the PDF.
  1614. *
  1615. * @param {function} passwordCallback (deprecated) It is used to request a
  1616. * password if wrong or no password was provided. The callback receives two
  1617. * parameters: function that needs to be called with new password and reason
  1618. * (see {PasswordResponses}).
  1619. *
  1620. * @param {function} progressCallback (deprecated) It is used to be able to
  1621. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1622. * a loading bar). The callback receives an {Object} with the properties:
  1623. * {number} loaded and {number} total.
  1624. *
  1625. * @return {PDFDocumentLoadingTask}
  1626. */
  1627. PDFJS.getDocument = function getDocument(src,
  1628. pdfDataRangeTransport,
  1629. passwordCallback,
  1630. progressCallback) {
  1631. var task = new PDFDocumentLoadingTask();
  1632. // Support of the obsolete arguments (for compatibility with API v1.0)
  1633. if (pdfDataRangeTransport) {
  1634. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1635. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1636. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1637. pdfDataRangeTransport.length = src.length;
  1638. pdfDataRangeTransport.initialData = src.initialData;
  1639. }
  1640. src = Object.create(src);
  1641. src.range = pdfDataRangeTransport;
  1642. }
  1643. task.onPassword = passwordCallback || null;
  1644. task.onProgress = progressCallback || null;
  1645. var workerInitializedCapability, transport;
  1646. var source;
  1647. if (typeof src === 'string') {
  1648. source = { url: src };
  1649. } else if (isArrayBuffer(src)) {
  1650. source = { data: src };
  1651. } else if (src instanceof PDFDataRangeTransport) {
  1652. source = { range: src };
  1653. } else {
  1654. if (typeof src !== 'object') {
  1655. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1656. 'string or a parameter object');
  1657. }
  1658. if (!src.url && !src.data && !src.range) {
  1659. error('Invalid parameter object: need either .data, .range or .url');
  1660. }
  1661. source = src;
  1662. }
  1663. var params = {};
  1664. for (var key in source) {
  1665. if (key === 'url' && typeof window !== 'undefined') {
  1666. // The full path is required in the 'url' field.
  1667. params[key] = combineUrl(window.location.href, source[key]);
  1668. continue;
  1669. } else if (key === 'range') {
  1670. continue;
  1671. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1672. // Converting string or array-like data to Uint8Array.
  1673. var pdfBytes = source[key];
  1674. if (typeof pdfBytes === 'string') {
  1675. params[key] = stringToBytes(pdfBytes);
  1676. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1677. !isNaN(pdfBytes.length)) {
  1678. params[key] = new Uint8Array(pdfBytes);
  1679. } else {
  1680. error('Invalid PDF binary data: either typed array, string or ' +
  1681. 'array-like object is expected in the data property.');
  1682. }
  1683. continue;
  1684. }
  1685. params[key] = source[key];
  1686. }
  1687. workerInitializedCapability = createPromiseCapability();
  1688. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1689. workerInitializedCapability.promise.then(function transportInitialized() {
  1690. transport.fetchDocument(task, params);
  1691. });
  1692. return task;
  1693. };
  1694. /**
  1695. * PDF document loading operation.
  1696. * @class
  1697. */
  1698. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1699. /** @constructs PDFDocumentLoadingTask */
  1700. function PDFDocumentLoadingTask() {
  1701. this._capability = createPromiseCapability();
  1702. /**
  1703. * Callback to request a password if wrong or no password was provided.
  1704. * The callback receives two parameters: function that needs to be called
  1705. * with new password and reason (see {PasswordResponses}).
  1706. */
  1707. this.onPassword = null;
  1708. /**
  1709. * Callback to be able to monitor the loading progress of the PDF file
  1710. * (necessary to implement e.g. a loading bar). The callback receives
  1711. * an {Object} with the properties: {number} loaded and {number} total.
  1712. */
  1713. this.onProgress = null;
  1714. }
  1715. PDFDocumentLoadingTask.prototype =
  1716. /** @lends PDFDocumentLoadingTask.prototype */ {
  1717. /**
  1718. * @return {Promise}
  1719. */
  1720. get promise() {
  1721. return this._capability.promise;
  1722. },
  1723. // TODO add cancel or abort method
  1724. /**
  1725. * Registers callbacks to indicate the document loading completion.
  1726. *
  1727. * @param {function} onFulfilled The callback for the loading completion.
  1728. * @param {function} onRejected The callback for the loading failure.
  1729. * @return {Promise} A promise that is resolved after the onFulfilled or
  1730. * onRejected callback.
  1731. */
  1732. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1733. return this.promise.then.apply(this.promise, arguments);
  1734. }
  1735. };
  1736. return PDFDocumentLoadingTask;
  1737. })();
  1738. /**
  1739. * Abstract class to support range requests file loading.
  1740. * @class
  1741. */
  1742. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1743. /**
  1744. * @constructs PDFDataRangeTransport
  1745. * @param {number} length
  1746. * @param {Uint8Array} initialData
  1747. */
  1748. function PDFDataRangeTransport(length, initialData) {
  1749. this.length = length;
  1750. this.initialData = initialData;
  1751. this._rangeListeners = [];
  1752. this._progressListeners = [];
  1753. this._progressiveReadListeners = [];
  1754. this._readyCapability = createPromiseCapability();
  1755. }
  1756. PDFDataRangeTransport.prototype =
  1757. /** @lends PDFDataRangeTransport.prototype */ {
  1758. addRangeListener:
  1759. function PDFDataRangeTransport_addRangeListener(listener) {
  1760. this._rangeListeners.push(listener);
  1761. },
  1762. addProgressListener:
  1763. function PDFDataRangeTransport_addProgressListener(listener) {
  1764. this._progressListeners.push(listener);
  1765. },
  1766. addProgressiveReadListener:
  1767. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1768. this._progressiveReadListeners.push(listener);
  1769. },
  1770. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1771. var listeners = this._rangeListeners;
  1772. for (var i = 0, n = listeners.length; i < n; ++i) {
  1773. listeners[i](begin, chunk);
  1774. }
  1775. },
  1776. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1777. this._readyCapability.promise.then(function () {
  1778. var listeners = this._progressListeners;
  1779. for (var i = 0, n = listeners.length; i < n; ++i) {
  1780. listeners[i](loaded);
  1781. }
  1782. }.bind(this));
  1783. },
  1784. onDataProgressiveRead:
  1785. function PDFDataRangeTransport_onDataProgress(chunk) {
  1786. this._readyCapability.promise.then(function () {
  1787. var listeners = this._progressiveReadListeners;
  1788. for (var i = 0, n = listeners.length; i < n; ++i) {
  1789. listeners[i](chunk);
  1790. }
  1791. }.bind(this));
  1792. },
  1793. transportReady: function PDFDataRangeTransport_transportReady() {
  1794. this._readyCapability.resolve();
  1795. },
  1796. requestDataRange:
  1797. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1798. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1799. }
  1800. };
  1801. return PDFDataRangeTransport;
  1802. })();
  1803. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1804. /**
  1805. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1806. * properties that can be read synchronously.
  1807. * @class
  1808. */
  1809. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1810. function PDFDocumentProxy(pdfInfo, transport) {
  1811. this.pdfInfo = pdfInfo;
  1812. this.transport = transport;
  1813. }
  1814. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1815. /**
  1816. * @return {number} Total number of pages the PDF contains.
  1817. */
  1818. get numPages() {
  1819. return this.pdfInfo.numPages;
  1820. },
  1821. /**
  1822. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1823. * unique.
  1824. */
  1825. get fingerprint() {
  1826. return this.pdfInfo.fingerprint;
  1827. },
  1828. /**
  1829. * @param {number} pageNumber The page number to get. The first page is 1.
  1830. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1831. * object.
  1832. */
  1833. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1834. return this.transport.getPage(pageNumber);
  1835. },
  1836. /**
  1837. * @param {{num: number, gen: number}} ref The page reference. Must have
  1838. * the 'num' and 'gen' properties.
  1839. * @return {Promise} A promise that is resolved with the page index that is
  1840. * associated with the reference.
  1841. */
  1842. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1843. return this.transport.getPageIndex(ref);
  1844. },
  1845. /**
  1846. * @return {Promise} A promise that is resolved with a lookup table for
  1847. * mapping named destinations to reference numbers.
  1848. *
  1849. * This can be slow for large documents: use getDestination instead
  1850. */
  1851. getDestinations: function PDFDocumentProxy_getDestinations() {
  1852. return this.transport.getDestinations();
  1853. },
  1854. /**
  1855. * @param {string} id The named destination to get.
  1856. * @return {Promise} A promise that is resolved with all information
  1857. * of the given named destination.
  1858. */
  1859. getDestination: function PDFDocumentProxy_getDestination(id) {
  1860. return this.transport.getDestination(id);
  1861. },
  1862. /**
  1863. * @return {Promise} A promise that is resolved with a lookup table for
  1864. * mapping named attachments to their content.
  1865. */
  1866. getAttachments: function PDFDocumentProxy_getAttachments() {
  1867. return this.transport.getAttachments();
  1868. },
  1869. /**
  1870. * @return {Promise} A promise that is resolved with an array of all the
  1871. * JavaScript strings in the name tree.
  1872. */
  1873. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1874. return this.transport.getJavaScript();
  1875. },
  1876. /**
  1877. * @return {Promise} A promise that is resolved with an {Array} that is a
  1878. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1879. * [
  1880. * {
  1881. * title: string,
  1882. * bold: boolean,
  1883. * italic: boolean,
  1884. * color: rgb array,
  1885. * dest: dest obj,
  1886. * items: array of more items like this
  1887. * },
  1888. * ...
  1889. * ].
  1890. */
  1891. getOutline: function PDFDocumentProxy_getOutline() {
  1892. return this.transport.getOutline();
  1893. },
  1894. /**
  1895. * @return {Promise} A promise that is resolved with an {Object} that has
  1896. * info and metadata properties. Info is an {Object} filled with anything
  1897. * available in the information dictionary and similarly metadata is a
  1898. * {Metadata} object with information from the metadata section of the PDF.
  1899. */
  1900. getMetadata: function PDFDocumentProxy_getMetadata() {
  1901. return this.transport.getMetadata();
  1902. },
  1903. /**
  1904. * @return {Promise} A promise that is resolved with a TypedArray that has
  1905. * the raw data from the PDF.
  1906. */
  1907. getData: function PDFDocumentProxy_getData() {
  1908. return this.transport.getData();
  1909. },
  1910. /**
  1911. * @return {Promise} A promise that is resolved when the document's data
  1912. * is loaded. It is resolved with an {Object} that contains the length
  1913. * property that indicates size of the PDF data in bytes.
  1914. */
  1915. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1916. return this.transport.downloadInfoCapability.promise;
  1917. },
  1918. /**
  1919. * @return {Promise} A promise this is resolved with current stats about
  1920. * document structures (see {@link PDFDocumentStats}).
  1921. */
  1922. getStats: function PDFDocumentProxy_getStats() {
  1923. return this.transport.getStats();
  1924. },
  1925. /**
  1926. * Cleans up resources allocated by the document, e.g. created @font-face.
  1927. */
  1928. cleanup: function PDFDocumentProxy_cleanup() {
  1929. this.transport.startCleanup();
  1930. },
  1931. /**
  1932. * Destroys current document instance and terminates worker.
  1933. */
  1934. destroy: function PDFDocumentProxy_destroy() {
  1935. this.transport.destroy();
  1936. }
  1937. };
  1938. return PDFDocumentProxy;
  1939. })();
  1940. /**
  1941. * Page text content.
  1942. *
  1943. * @typedef {Object} TextContent
  1944. * @property {array} items - array of {@link TextItem}
  1945. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1946. * name.
  1947. */
  1948. /**
  1949. * Page text content part.
  1950. *
  1951. * @typedef {Object} TextItem
  1952. * @property {string} str - text content.
  1953. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1954. * @property {array} transform - transformation matrix.
  1955. * @property {number} width - width in device space.
  1956. * @property {number} height - height in device space.
  1957. * @property {string} fontName - font name used by pdf.js for converted font.
  1958. */
  1959. /**
  1960. * Text style.
  1961. *
  1962. * @typedef {Object} TextStyle
  1963. * @property {number} ascent - font ascent.
  1964. * @property {number} descent - font descent.
  1965. * @property {boolean} vertical - text is in vertical mode.
  1966. * @property {string} fontFamily - possible font family
  1967. */
  1968. /**
  1969. * Page render parameters.
  1970. *
  1971. * @typedef {Object} RenderParameters
  1972. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1973. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1974. * calling of PDFPage.getViewport method.
  1975. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1976. * (default value is 'display').
  1977. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1978. * endLayout and appendImage functions.
  1979. * @property {function} continueCallback - (deprecated) A function that will be
  1980. * called each time the rendering is paused. To continue
  1981. * rendering call the function that is the first argument
  1982. * to the callback.
  1983. */
  1984. /**
  1985. * PDF page operator list.
  1986. *
  1987. * @typedef {Object} PDFOperatorList
  1988. * @property {Array} fnArray - Array containing the operator functions.
  1989. * @property {Array} argsArray - Array containing the arguments of the
  1990. * functions.
  1991. */
  1992. /**
  1993. * Proxy to a PDFPage in the worker thread.
  1994. * @class
  1995. */
  1996. var PDFPageProxy = (function PDFPageProxyClosure() {
  1997. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1998. this.pageIndex = pageIndex;
  1999. this.pageInfo = pageInfo;
  2000. this.transport = transport;
  2001. this.stats = new StatTimer();
  2002. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  2003. this.commonObjs = transport.commonObjs;
  2004. this.objs = new PDFObjects();
  2005. this.cleanupAfterRender = false;
  2006. this.pendingDestroy = false;
  2007. this.intentStates = {};
  2008. }
  2009. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2010. /**
  2011. * @return {number} Page number of the page. First page is 1.
  2012. */
  2013. get pageNumber() {
  2014. return this.pageIndex + 1;
  2015. },
  2016. /**
  2017. * @return {number} The number of degrees the page is rotated clockwise.
  2018. */
  2019. get rotate() {
  2020. return this.pageInfo.rotate;
  2021. },
  2022. /**
  2023. * @return {Object} The reference that points to this page. It has 'num' and
  2024. * 'gen' properties.
  2025. */
  2026. get ref() {
  2027. return this.pageInfo.ref;
  2028. },
  2029. /**
  2030. * @return {Array} An array of the visible portion of the PDF page in the
  2031. * user space units - [x1, y1, x2, y2].
  2032. */
  2033. get view() {
  2034. return this.pageInfo.view;
  2035. },
  2036. /**
  2037. * @param {number} scale The desired scale of the viewport.
  2038. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2039. * defaults to the page rotation.
  2040. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2041. * along with transforms required for rendering.
  2042. */
  2043. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2044. if (arguments.length < 2) {
  2045. rotate = this.rotate;
  2046. }
  2047. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2048. },
  2049. /**
  2050. * @return {Promise} A promise that is resolved with an {Array} of the
  2051. * annotation objects.
  2052. */
  2053. getAnnotations: function PDFPageProxy_getAnnotations() {
  2054. if (this.annotationsPromise) {
  2055. return this.annotationsPromise;
  2056. }
  2057. var promise = this.transport.getAnnotations(this.pageIndex);
  2058. this.annotationsPromise = promise;
  2059. return promise;
  2060. },
  2061. /**
  2062. * Begins the process of rendering a page to the desired context.
  2063. * @param {RenderParameters} params Page render parameters.
  2064. * @return {RenderTask} An object that contains the promise, which
  2065. * is resolved when the page finishes rendering.
  2066. */
  2067. render: function PDFPageProxy_render(params) {
  2068. var stats = this.stats;
  2069. stats.time('Overall');
  2070. // If there was a pending destroy cancel it so no cleanup happens during
  2071. // this call to render.
  2072. this.pendingDestroy = false;
  2073. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2074. if (!this.intentStates[renderingIntent]) {
  2075. this.intentStates[renderingIntent] = {};
  2076. }
  2077. var intentState = this.intentStates[renderingIntent];
  2078. // If there's no displayReadyCapability yet, then the operatorList
  2079. // was never requested before. Make the request and create the promise.
  2080. if (!intentState.displayReadyCapability) {
  2081. intentState.receivingOperatorList = true;
  2082. intentState.displayReadyCapability = createPromiseCapability();
  2083. intentState.operatorList = {
  2084. fnArray: [],
  2085. argsArray: [],
  2086. lastChunk: false
  2087. };
  2088. this.stats.time('Page Request');
  2089. this.transport.messageHandler.send('RenderPageRequest', {
  2090. pageIndex: this.pageNumber - 1,
  2091. intent: renderingIntent
  2092. });
  2093. }
  2094. var internalRenderTask = new InternalRenderTask(complete, params,
  2095. this.objs,
  2096. this.commonObjs,
  2097. intentState.operatorList,
  2098. this.pageNumber);
  2099. if (!intentState.renderTasks) {
  2100. intentState.renderTasks = [];
  2101. }
  2102. intentState.renderTasks.push(internalRenderTask);
  2103. var renderTask = internalRenderTask.task;
  2104. // Obsolete parameter support
  2105. if (params.continueCallback) {
  2106. renderTask.onContinue = params.continueCallback;
  2107. }
  2108. var self = this;
  2109. intentState.displayReadyCapability.promise.then(
  2110. function pageDisplayReadyPromise(transparency) {
  2111. if (self.pendingDestroy) {
  2112. complete();
  2113. return;
  2114. }
  2115. stats.time('Rendering');
  2116. internalRenderTask.initalizeGraphics(transparency);
  2117. internalRenderTask.operatorListChanged();
  2118. },
  2119. function pageDisplayReadPromiseError(reason) {
  2120. complete(reason);
  2121. }
  2122. );
  2123. function complete(error) {
  2124. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2125. if (i >= 0) {
  2126. intentState.renderTasks.splice(i, 1);
  2127. }
  2128. if (self.cleanupAfterRender) {
  2129. self.pendingDestroy = true;
  2130. }
  2131. self._tryDestroy();
  2132. if (error) {
  2133. internalRenderTask.capability.reject(error);
  2134. } else {
  2135. internalRenderTask.capability.resolve();
  2136. }
  2137. stats.timeEnd('Rendering');
  2138. stats.timeEnd('Overall');
  2139. }
  2140. return renderTask;
  2141. },
  2142. /**
  2143. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2144. * object that represents page's operator list.
  2145. */
  2146. getOperatorList: function PDFPageProxy_getOperatorList() {
  2147. function operatorListChanged() {
  2148. if (intentState.operatorList.lastChunk) {
  2149. intentState.opListReadCapability.resolve(intentState.operatorList);
  2150. }
  2151. }
  2152. var renderingIntent = 'oplist';
  2153. if (!this.intentStates[renderingIntent]) {
  2154. this.intentStates[renderingIntent] = {};
  2155. }
  2156. var intentState = this.intentStates[renderingIntent];
  2157. if (!intentState.opListReadCapability) {
  2158. var opListTask = {};
  2159. opListTask.operatorListChanged = operatorListChanged;
  2160. intentState.receivingOperatorList = true;
  2161. intentState.opListReadCapability = createPromiseCapability();
  2162. intentState.renderTasks = [];
  2163. intentState.renderTasks.push(opListTask);
  2164. intentState.operatorList = {
  2165. fnArray: [],
  2166. argsArray: [],
  2167. lastChunk: false
  2168. };
  2169. this.transport.messageHandler.send('RenderPageRequest', {
  2170. pageIndex: this.pageIndex,
  2171. intent: renderingIntent
  2172. });
  2173. }
  2174. return intentState.opListReadCapability.promise;
  2175. },
  2176. /**
  2177. * @return {Promise} That is resolved a {@link TextContent}
  2178. * object that represent the page text content.
  2179. */
  2180. getTextContent: function PDFPageProxy_getTextContent() {
  2181. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2182. pageIndex: this.pageNumber - 1
  2183. });
  2184. },
  2185. /**
  2186. * Destroys resources allocated by the page.
  2187. */
  2188. destroy: function PDFPageProxy_destroy() {
  2189. this.pendingDestroy = true;
  2190. this._tryDestroy();
  2191. },
  2192. /**
  2193. * For internal use only. Attempts to clean up if rendering is in a state
  2194. * where that's possible.
  2195. * @ignore
  2196. */
  2197. _tryDestroy: function PDFPageProxy__destroy() {
  2198. if (!this.pendingDestroy ||
  2199. Object.keys(this.intentStates).some(function(intent) {
  2200. var intentState = this.intentStates[intent];
  2201. return (intentState.renderTasks.length !== 0 ||
  2202. intentState.receivingOperatorList);
  2203. }, this)) {
  2204. return;
  2205. }
  2206. Object.keys(this.intentStates).forEach(function(intent) {
  2207. delete this.intentStates[intent];
  2208. }, this);
  2209. this.objs.clear();
  2210. this.annotationsPromise = null;
  2211. this.pendingDestroy = false;
  2212. },
  2213. /**
  2214. * For internal use only.
  2215. * @ignore
  2216. */
  2217. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2218. intent) {
  2219. var intentState = this.intentStates[intent];
  2220. // TODO Refactor RenderPageRequest to separate rendering
  2221. // and operator list logic
  2222. if (intentState.displayReadyCapability) {
  2223. intentState.displayReadyCapability.resolve(transparency);
  2224. }
  2225. },
  2226. /**
  2227. * For internal use only.
  2228. * @ignore
  2229. */
  2230. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2231. intent) {
  2232. var intentState = this.intentStates[intent];
  2233. var i, ii;
  2234. // Add the new chunk to the current operator list.
  2235. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2236. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2237. intentState.operatorList.argsArray.push(
  2238. operatorListChunk.argsArray[i]);
  2239. }
  2240. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2241. // Notify all the rendering tasks there are more operators to be consumed.
  2242. for (i = 0; i < intentState.renderTasks.length; i++) {
  2243. intentState.renderTasks[i].operatorListChanged();
  2244. }
  2245. if (operatorListChunk.lastChunk) {
  2246. intentState.receivingOperatorList = false;
  2247. this._tryDestroy();
  2248. }
  2249. }
  2250. };
  2251. return PDFPageProxy;
  2252. })();
  2253. /**
  2254. * For internal use only.
  2255. * @ignore
  2256. */
  2257. var WorkerTransport = (function WorkerTransportClosure() {
  2258. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2259. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2260. this.workerInitializedCapability = workerInitializedCapability;
  2261. this.commonObjs = new PDFObjects();
  2262. this.loadingTask = null;
  2263. this.pageCache = [];
  2264. this.pagePromises = [];
  2265. this.downloadInfoCapability = createPromiseCapability();
  2266. // If worker support isn't disabled explicit and the browser has worker
  2267. // support, create a new web worker and test if it/the browser fullfills
  2268. // all requirements to run parts of pdf.js in a web worker.
  2269. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2270. // as it arrives on the worker. Chrome added this with version 15.
  2271. // Either workers are disabled, not supported or have thrown an exception.
  2272. // Thus, we fallback to a faked worker.
  2273. this.setupFakeWorker();
  2274. }
  2275. WorkerTransport.prototype = {
  2276. destroy: function WorkerTransport_destroy() {
  2277. this.pageCache = [];
  2278. this.pagePromises = [];
  2279. var self = this;
  2280. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2281. FontLoader.clear();
  2282. if (self.worker) {
  2283. self.worker.terminate();
  2284. }
  2285. });
  2286. },
  2287. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2288. globalScope.PDFJS.disableWorker = true;
  2289. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2290. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2291. // In the developer build load worker_loader which in turn loads all the
  2292. // other files and resolves the promise. In production only the
  2293. // pdf.worker.js file is needed.
  2294. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2295. }
  2296. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2297. warn('Setting up fake worker.');
  2298. // If we don't use a worker, just post/sendMessage to the main thread.
  2299. var fakeWorker = {
  2300. postMessage: function WorkerTransport_postMessage(obj) {
  2301. fakeWorker.onmessage({data: obj});
  2302. },
  2303. terminate: function WorkerTransport_terminate() {}
  2304. };
  2305. var messageHandler = new MessageHandler('main', fakeWorker);
  2306. this.setupMessageHandler(messageHandler);
  2307. // If the main thread is our worker, setup the handling for the messages
  2308. // the main thread sends to it self.
  2309. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2310. this.workerInitializedCapability.resolve();
  2311. }.bind(this));
  2312. },
  2313. setupMessageHandler:
  2314. function WorkerTransport_setupMessageHandler(messageHandler) {
  2315. this.messageHandler = messageHandler;
  2316. function updatePassword(password) {
  2317. messageHandler.send('UpdatePassword', password);
  2318. }
  2319. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2320. if (pdfDataRangeTransport) {
  2321. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2322. messageHandler.send('OnDataRange', {
  2323. begin: begin,
  2324. chunk: chunk
  2325. });
  2326. });
  2327. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2328. messageHandler.send('OnDataProgress', {
  2329. loaded: loaded
  2330. });
  2331. });
  2332. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2333. messageHandler.send('OnDataRange', {
  2334. chunk: chunk
  2335. });
  2336. });
  2337. messageHandler.on('RequestDataRange',
  2338. function transportDataRange(data) {
  2339. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2340. }, this);
  2341. }
  2342. messageHandler.on('GetDoc', function transportDoc(data) {
  2343. var pdfInfo = data.pdfInfo;
  2344. this.numPages = data.pdfInfo.numPages;
  2345. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2346. this.pdfDocument = pdfDocument;
  2347. this.loadingTask._capability.resolve(pdfDocument);
  2348. }, this);
  2349. messageHandler.on('NeedPassword',
  2350. function transportNeedPassword(exception) {
  2351. var loadingTask = this.loadingTask;
  2352. if (loadingTask.onPassword) {
  2353. return loadingTask.onPassword(updatePassword,
  2354. PasswordResponses.NEED_PASSWORD);
  2355. }
  2356. loadingTask._capability.reject(
  2357. new PasswordException(exception.message, exception.code));
  2358. }, this);
  2359. messageHandler.on('IncorrectPassword',
  2360. function transportIncorrectPassword(exception) {
  2361. var loadingTask = this.loadingTask;
  2362. if (loadingTask.onPassword) {
  2363. return loadingTask.onPassword(updatePassword,
  2364. PasswordResponses.INCORRECT_PASSWORD);
  2365. }
  2366. loadingTask._capability.reject(
  2367. new PasswordException(exception.message, exception.code));
  2368. }, this);
  2369. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2370. this.loadingTask._capability.reject(
  2371. new InvalidPDFException(exception.message));
  2372. }, this);
  2373. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2374. this.loadingTask._capability.reject(
  2375. new MissingPDFException(exception.message));
  2376. }, this);
  2377. messageHandler.on('UnexpectedResponse',
  2378. function transportUnexpectedResponse(exception) {
  2379. this.loadingTask._capability.reject(
  2380. new UnexpectedResponseException(exception.message, exception.status));
  2381. }, this);
  2382. messageHandler.on('UnknownError',
  2383. function transportUnknownError(exception) {
  2384. this.loadingTask._capability.reject(
  2385. new UnknownErrorException(exception.message, exception.details));
  2386. }, this);
  2387. messageHandler.on('DataLoaded', function transportPage(data) {
  2388. this.downloadInfoCapability.resolve(data);
  2389. }, this);
  2390. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2391. if (this.pdfDataRangeTransport) {
  2392. this.pdfDataRangeTransport.transportReady();
  2393. }
  2394. }, this);
  2395. messageHandler.on('StartRenderPage', function transportRender(data) {
  2396. var page = this.pageCache[data.pageIndex];
  2397. page.stats.timeEnd('Page Request');
  2398. page._startRenderPage(data.transparency, data.intent);
  2399. }, this);
  2400. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2401. var page = this.pageCache[data.pageIndex];
  2402. page._renderPageChunk(data.operatorList, data.intent);
  2403. }, this);
  2404. messageHandler.on('commonobj', function transportObj(data) {
  2405. var id = data[0];
  2406. var type = data[1];
  2407. if (this.commonObjs.hasData(id)) {
  2408. return;
  2409. }
  2410. switch (type) {
  2411. case 'Font':
  2412. var exportedData = data[2];
  2413. var font;
  2414. if ('error' in exportedData) {
  2415. var error = exportedData.error;
  2416. warn('Error during font loading: ' + error);
  2417. this.commonObjs.resolve(id, error);
  2418. break;
  2419. } else {
  2420. font = new FontFaceObject(exportedData);
  2421. }
  2422. FontLoader.bind(
  2423. [font],
  2424. function fontReady(fontObjs) {
  2425. this.commonObjs.resolve(id, font);
  2426. }.bind(this)
  2427. );
  2428. break;
  2429. case 'FontPath':
  2430. this.commonObjs.resolve(id, data[2]);
  2431. break;
  2432. default:
  2433. error('Got unknown common object type ' + type);
  2434. }
  2435. }, this);
  2436. messageHandler.on('obj', function transportObj(data) {
  2437. var id = data[0];
  2438. var pageIndex = data[1];
  2439. var type = data[2];
  2440. var pageProxy = this.pageCache[pageIndex];
  2441. var imageData;
  2442. if (pageProxy.objs.hasData(id)) {
  2443. return;
  2444. }
  2445. switch (type) {
  2446. case 'JpegStream':
  2447. imageData = data[3];
  2448. loadJpegStream(id, imageData, pageProxy.objs);
  2449. break;
  2450. case 'Image':
  2451. imageData = data[3];
  2452. pageProxy.objs.resolve(id, imageData);
  2453. // heuristics that will allow not to store large data
  2454. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2455. if (imageData && 'data' in imageData &&
  2456. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2457. pageProxy.cleanupAfterRender = true;
  2458. }
  2459. break;
  2460. default:
  2461. error('Got unknown object type ' + type);
  2462. }
  2463. }, this);
  2464. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2465. var loadingTask = this.loadingTask;
  2466. if (loadingTask.onProgress) {
  2467. loadingTask.onProgress({
  2468. loaded: data.loaded,
  2469. total: data.total
  2470. });
  2471. }
  2472. }, this);
  2473. messageHandler.on('PageError', function transportError(data) {
  2474. var page = this.pageCache[data.pageNum - 1];
  2475. var intentState = page.intentStates[data.intent];
  2476. if (intentState.displayReadyCapability) {
  2477. intentState.displayReadyCapability.reject(data.error);
  2478. } else {
  2479. error(data.error);
  2480. }
  2481. }, this);
  2482. messageHandler.on('JpegDecode', function(data) {
  2483. var imageUrl = data[0];
  2484. var components = data[1];
  2485. if (components !== 3 && components !== 1) {
  2486. return Promise.reject(
  2487. new Error('Only 3 components or 1 component can be returned'));
  2488. }
  2489. return new Promise(function (resolve, reject) {
  2490. var img = new Image();
  2491. img.onload = function () {
  2492. var width = img.width;
  2493. var height = img.height;
  2494. var size = width * height;
  2495. var rgbaLength = size * 4;
  2496. var buf = new Uint8Array(size * components);
  2497. var tmpCanvas = createScratchCanvas(width, height);
  2498. var tmpCtx = tmpCanvas.getContext('2d');
  2499. tmpCtx.drawImage(img, 0, 0);
  2500. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2501. var i, j;
  2502. if (components === 3) {
  2503. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2504. buf[j] = data[i];
  2505. buf[j + 1] = data[i + 1];
  2506. buf[j + 2] = data[i + 2];
  2507. }
  2508. } else if (components === 1) {
  2509. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2510. buf[j] = data[i];
  2511. }
  2512. }
  2513. resolve({ data: buf, width: width, height: height});
  2514. };
  2515. img.onerror = function () {
  2516. reject(new Error('JpegDecode failed to load image'));
  2517. };
  2518. img.src = imageUrl;
  2519. });
  2520. });
  2521. },
  2522. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2523. this.loadingTask = loadingTask;
  2524. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2525. source.disableStream = PDFJS.disableStream;
  2526. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2527. if (this.pdfDataRangeTransport) {
  2528. source.length = this.pdfDataRangeTransport.length;
  2529. source.initialData = this.pdfDataRangeTransport.initialData;
  2530. }
  2531. this.messageHandler.send('GetDocRequest', {
  2532. source: source,
  2533. disableRange: PDFJS.disableRange,
  2534. maxImageSize: PDFJS.maxImageSize,
  2535. cMapUrl: PDFJS.cMapUrl,
  2536. cMapPacked: PDFJS.cMapPacked,
  2537. disableFontFace: PDFJS.disableFontFace,
  2538. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2539. verbosity: PDFJS.verbosity
  2540. });
  2541. },
  2542. getData: function WorkerTransport_getData() {
  2543. return this.messageHandler.sendWithPromise('GetData', null);
  2544. },
  2545. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2546. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2547. (pageNumber|0) !== pageNumber) {
  2548. return Promise.reject(new Error('Invalid page request'));
  2549. }
  2550. var pageIndex = pageNumber - 1;
  2551. if (pageIndex in this.pagePromises) {
  2552. return this.pagePromises[pageIndex];
  2553. }
  2554. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2555. pageIndex: pageIndex
  2556. }).then(function (pageInfo) {
  2557. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2558. this.pageCache[pageIndex] = page;
  2559. return page;
  2560. }.bind(this));
  2561. this.pagePromises[pageIndex] = promise;
  2562. return promise;
  2563. },
  2564. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2565. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2566. },
  2567. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2568. return this.messageHandler.sendWithPromise('GetAnnotations',
  2569. { pageIndex: pageIndex });
  2570. },
  2571. getDestinations: function WorkerTransport_getDestinations() {
  2572. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2573. },
  2574. getDestination: function WorkerTransport_getDestination(id) {
  2575. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2576. },
  2577. getAttachments: function WorkerTransport_getAttachments() {
  2578. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2579. },
  2580. getJavaScript: function WorkerTransport_getJavaScript() {
  2581. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2582. },
  2583. getOutline: function WorkerTransport_getOutline() {
  2584. return this.messageHandler.sendWithPromise('GetOutline', null);
  2585. },
  2586. getMetadata: function WorkerTransport_getMetadata() {
  2587. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2588. then(function transportMetadata(results) {
  2589. return {
  2590. info: results[0],
  2591. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2592. };
  2593. });
  2594. },
  2595. getStats: function WorkerTransport_getStats() {
  2596. return this.messageHandler.sendWithPromise('GetStats', null);
  2597. },
  2598. startCleanup: function WorkerTransport_startCleanup() {
  2599. this.messageHandler.sendWithPromise('Cleanup', null).
  2600. then(function endCleanup() {
  2601. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2602. var page = this.pageCache[i];
  2603. if (page) {
  2604. page.destroy();
  2605. }
  2606. }
  2607. this.commonObjs.clear();
  2608. FontLoader.clear();
  2609. }.bind(this));
  2610. }
  2611. };
  2612. return WorkerTransport;
  2613. })();
  2614. /**
  2615. * A PDF document and page is built of many objects. E.g. there are objects
  2616. * for fonts, images, rendering code and such. These objects might get processed
  2617. * inside of a worker. The `PDFObjects` implements some basic functions to
  2618. * manage these objects.
  2619. * @ignore
  2620. */
  2621. var PDFObjects = (function PDFObjectsClosure() {
  2622. function PDFObjects() {
  2623. this.objs = {};
  2624. }
  2625. PDFObjects.prototype = {
  2626. /**
  2627. * Internal function.
  2628. * Ensures there is an object defined for `objId`.
  2629. */
  2630. ensureObj: function PDFObjects_ensureObj(objId) {
  2631. if (this.objs[objId]) {
  2632. return this.objs[objId];
  2633. }
  2634. var obj = {
  2635. capability: createPromiseCapability(),
  2636. data: null,
  2637. resolved: false
  2638. };
  2639. this.objs[objId] = obj;
  2640. return obj;
  2641. },
  2642. /**
  2643. * If called *without* callback, this returns the data of `objId` but the
  2644. * object needs to be resolved. If it isn't, this function throws.
  2645. *
  2646. * If called *with* a callback, the callback is called with the data of the
  2647. * object once the object is resolved. That means, if you call this
  2648. * function and the object is already resolved, the callback gets called
  2649. * right away.
  2650. */
  2651. get: function PDFObjects_get(objId, callback) {
  2652. // If there is a callback, then the get can be async and the object is
  2653. // not required to be resolved right now
  2654. if (callback) {
  2655. this.ensureObj(objId).capability.promise.then(callback);
  2656. return null;
  2657. }
  2658. // If there isn't a callback, the user expects to get the resolved data
  2659. // directly.
  2660. var obj = this.objs[objId];
  2661. // If there isn't an object yet or the object isn't resolved, then the
  2662. // data isn't ready yet!
  2663. if (!obj || !obj.resolved) {
  2664. error('Requesting object that isn\'t resolved yet ' + objId);
  2665. }
  2666. return obj.data;
  2667. },
  2668. /**
  2669. * Resolves the object `objId` with optional `data`.
  2670. */
  2671. resolve: function PDFObjects_resolve(objId, data) {
  2672. var obj = this.ensureObj(objId);
  2673. obj.resolved = true;
  2674. obj.data = data;
  2675. obj.capability.resolve(data);
  2676. },
  2677. isResolved: function PDFObjects_isResolved(objId) {
  2678. var objs = this.objs;
  2679. if (!objs[objId]) {
  2680. return false;
  2681. } else {
  2682. return objs[objId].resolved;
  2683. }
  2684. },
  2685. hasData: function PDFObjects_hasData(objId) {
  2686. return this.isResolved(objId);
  2687. },
  2688. /**
  2689. * Returns the data of `objId` if object exists, null otherwise.
  2690. */
  2691. getData: function PDFObjects_getData(objId) {
  2692. var objs = this.objs;
  2693. if (!objs[objId] || !objs[objId].resolved) {
  2694. return null;
  2695. } else {
  2696. return objs[objId].data;
  2697. }
  2698. },
  2699. clear: function PDFObjects_clear() {
  2700. this.objs = {};
  2701. }
  2702. };
  2703. return PDFObjects;
  2704. })();
  2705. /**
  2706. * Allows controlling of the rendering tasks.
  2707. * @class
  2708. */
  2709. var RenderTask = (function RenderTaskClosure() {
  2710. function RenderTask(internalRenderTask) {
  2711. this._internalRenderTask = internalRenderTask;
  2712. /**
  2713. * Callback for incremental rendering -- a function that will be called
  2714. * each time the rendering is paused. To continue rendering call the
  2715. * function that is the first argument to the callback.
  2716. * @type {function}
  2717. */
  2718. this.onContinue = null;
  2719. }
  2720. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2721. /**
  2722. * Promise for rendering task completion.
  2723. * @return {Promise}
  2724. */
  2725. get promise() {
  2726. return this._internalRenderTask.capability.promise;
  2727. },
  2728. /**
  2729. * Cancels the rendering task. If the task is currently rendering it will
  2730. * not be cancelled until graphics pauses with a timeout. The promise that
  2731. * this object extends will resolved when cancelled.
  2732. */
  2733. cancel: function RenderTask_cancel() {
  2734. this._internalRenderTask.cancel();
  2735. },
  2736. /**
  2737. * Registers callbacks to indicate the rendering task completion.
  2738. *
  2739. * @param {function} onFulfilled The callback for the rendering completion.
  2740. * @param {function} onRejected The callback for the rendering failure.
  2741. * @return {Promise} A promise that is resolved after the onFulfilled or
  2742. * onRejected callback.
  2743. */
  2744. then: function RenderTask_then(onFulfilled, onRejected) {
  2745. return this.promise.then.apply(this.promise, arguments);
  2746. }
  2747. };
  2748. return RenderTask;
  2749. })();
  2750. /**
  2751. * For internal use only.
  2752. * @ignore
  2753. */
  2754. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2755. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2756. pageNumber) {
  2757. this.callback = callback;
  2758. this.params = params;
  2759. this.objs = objs;
  2760. this.commonObjs = commonObjs;
  2761. this.operatorListIdx = null;
  2762. this.operatorList = operatorList;
  2763. this.pageNumber = pageNumber;
  2764. this.running = false;
  2765. this.graphicsReadyCallback = null;
  2766. this.graphicsReady = false;
  2767. this.cancelled = false;
  2768. this.capability = createPromiseCapability();
  2769. this.task = new RenderTask(this);
  2770. // caching this-bound methods
  2771. this._continueBound = this._continue.bind(this);
  2772. this._scheduleNextBound = this._scheduleNext.bind(this);
  2773. this._nextBound = this._next.bind(this);
  2774. }
  2775. InternalRenderTask.prototype = {
  2776. initalizeGraphics:
  2777. function InternalRenderTask_initalizeGraphics(transparency) {
  2778. if (this.cancelled) {
  2779. return;
  2780. }
  2781. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2782. globalScope.StepperManager.enabled) {
  2783. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2784. this.stepper.init(this.operatorList);
  2785. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2786. }
  2787. var params = this.params;
  2788. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2789. this.objs, params.imageLayer);
  2790. this.gfx.beginDrawing(params.viewport, transparency);
  2791. this.operatorListIdx = 0;
  2792. this.graphicsReady = true;
  2793. if (this.graphicsReadyCallback) {
  2794. this.graphicsReadyCallback();
  2795. }
  2796. },
  2797. cancel: function InternalRenderTask_cancel() {
  2798. this.running = false;
  2799. this.cancelled = true;
  2800. this.callback('cancelled');
  2801. },
  2802. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2803. if (!this.graphicsReady) {
  2804. if (!this.graphicsReadyCallback) {
  2805. this.graphicsReadyCallback = this._continueBound;
  2806. }
  2807. return;
  2808. }
  2809. if (this.stepper) {
  2810. this.stepper.updateOperatorList(this.operatorList);
  2811. }
  2812. if (this.running) {
  2813. return;
  2814. }
  2815. this._continue();
  2816. },
  2817. _continue: function InternalRenderTask__continue() {
  2818. this.running = true;
  2819. if (this.cancelled) {
  2820. return;
  2821. }
  2822. if (this.task.onContinue) {
  2823. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2824. } else {
  2825. this._scheduleNext();
  2826. }
  2827. },
  2828. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2829. window.requestAnimationFrame(this._nextBound);
  2830. },
  2831. _next: function InternalRenderTask__next() {
  2832. if (this.cancelled) {
  2833. return;
  2834. }
  2835. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2836. this.operatorListIdx,
  2837. this._continueBound,
  2838. this.stepper);
  2839. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2840. this.running = false;
  2841. if (this.operatorList.lastChunk) {
  2842. this.gfx.endDrawing();
  2843. this.callback();
  2844. }
  2845. }
  2846. }
  2847. };
  2848. return InternalRenderTask;
  2849. })();
  2850. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2851. function fixMetadata(meta) {
  2852. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2853. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2854. function(code, d1, d2, d3) {
  2855. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2856. });
  2857. var chars = '';
  2858. for (var i = 0; i < bytes.length; i += 2) {
  2859. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2860. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2861. code !== 38 && false ? String.fromCharCode(code) :
  2862. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2863. }
  2864. return '>' + chars;
  2865. });
  2866. }
  2867. function Metadata(meta) {
  2868. if (typeof meta === 'string') {
  2869. // Ghostscript produces invalid metadata
  2870. meta = fixMetadata(meta);
  2871. var parser = new DOMParser();
  2872. meta = parser.parseFromString(meta, 'application/xml');
  2873. } else if (!(meta instanceof Document)) {
  2874. error('Metadata: Invalid metadata object');
  2875. }
  2876. this.metaDocument = meta;
  2877. this.metadata = {};
  2878. this.parse();
  2879. }
  2880. Metadata.prototype = {
  2881. parse: function Metadata_parse() {
  2882. var doc = this.metaDocument;
  2883. var rdf = doc.documentElement;
  2884. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2885. rdf = rdf.firstChild;
  2886. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2887. rdf = rdf.nextSibling;
  2888. }
  2889. }
  2890. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2891. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2892. return;
  2893. }
  2894. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2895. for (i = 0, length = children.length; i < length; i++) {
  2896. desc = children[i];
  2897. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2898. continue;
  2899. }
  2900. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2901. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2902. entry = desc.childNodes[ii];
  2903. name = entry.nodeName.toLowerCase();
  2904. this.metadata[name] = entry.textContent.trim();
  2905. }
  2906. }
  2907. }
  2908. },
  2909. get: function Metadata_get(name) {
  2910. return this.metadata[name] || null;
  2911. },
  2912. has: function Metadata_has(name) {
  2913. return typeof this.metadata[name] !== 'undefined';
  2914. }
  2915. };
  2916. return Metadata;
  2917. })();
  2918. // <canvas> contexts store most of the state we need natively.
  2919. // However, PDF needs a bit more state, which we store here.
  2920. // Minimal font size that would be used during canvas fillText operations.
  2921. var MIN_FONT_SIZE = 16;
  2922. // Maximum font size that would be used during canvas fillText operations.
  2923. var MAX_FONT_SIZE = 100;
  2924. var MAX_GROUP_SIZE = 4096;
  2925. // Heuristic value used when enforcing minimum line widths.
  2926. var MIN_WIDTH_FACTOR = 0.65;
  2927. var COMPILE_TYPE3_GLYPHS = true;
  2928. var MAX_SIZE_TO_COMPILE = 1000;
  2929. var FULL_CHUNK_HEIGHT = 16;
  2930. function createScratchCanvas(width, height) {
  2931. var canvas = document.createElement('canvas');
  2932. canvas.width = width;
  2933. canvas.height = height;
  2934. return canvas;
  2935. }
  2936. function addContextCurrentTransform(ctx) {
  2937. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  2938. if (!ctx.mozCurrentTransform) {
  2939. ctx._originalSave = ctx.save;
  2940. ctx._originalRestore = ctx.restore;
  2941. ctx._originalRotate = ctx.rotate;
  2942. ctx._originalScale = ctx.scale;
  2943. ctx._originalTranslate = ctx.translate;
  2944. ctx._originalTransform = ctx.transform;
  2945. ctx._originalSetTransform = ctx.setTransform;
  2946. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  2947. ctx._transformStack = [];
  2948. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2949. get: function getCurrentTransform() {
  2950. return this._transformMatrix;
  2951. }
  2952. });
  2953. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2954. get: function getCurrentTransformInverse() {
  2955. // Calculation done using WolframAlpha:
  2956. // http://www.wolframalpha.com/input/?
  2957. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2958. var m = this._transformMatrix;
  2959. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2960. var ad_bc = a * d - b * c;
  2961. var bc_ad = b * c - a * d;
  2962. return [
  2963. d / ad_bc,
  2964. b / bc_ad,
  2965. c / bc_ad,
  2966. a / ad_bc,
  2967. (d * e - c * f) / bc_ad,
  2968. (b * e - a * f) / ad_bc
  2969. ];
  2970. }
  2971. });
  2972. ctx.save = function ctxSave() {
  2973. var old = this._transformMatrix;
  2974. this._transformStack.push(old);
  2975. this._transformMatrix = old.slice(0, 6);
  2976. this._originalSave();
  2977. };
  2978. ctx.restore = function ctxRestore() {
  2979. var prev = this._transformStack.pop();
  2980. if (prev) {
  2981. this._transformMatrix = prev;
  2982. this._originalRestore();
  2983. }
  2984. };
  2985. ctx.translate = function ctxTranslate(x, y) {
  2986. var m = this._transformMatrix;
  2987. m[4] = m[0] * x + m[2] * y + m[4];
  2988. m[5] = m[1] * x + m[3] * y + m[5];
  2989. this._originalTranslate(x, y);
  2990. };
  2991. ctx.scale = function ctxScale(x, y) {
  2992. var m = this._transformMatrix;
  2993. m[0] = m[0] * x;
  2994. m[1] = m[1] * x;
  2995. m[2] = m[2] * y;
  2996. m[3] = m[3] * y;
  2997. this._originalScale(x, y);
  2998. };
  2999. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3000. var m = this._transformMatrix;
  3001. this._transformMatrix = [
  3002. m[0] * a + m[2] * b,
  3003. m[1] * a + m[3] * b,
  3004. m[0] * c + m[2] * d,
  3005. m[1] * c + m[3] * d,
  3006. m[0] * e + m[2] * f + m[4],
  3007. m[1] * e + m[3] * f + m[5]
  3008. ];
  3009. ctx._originalTransform(a, b, c, d, e, f);
  3010. };
  3011. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3012. this._transformMatrix = [a, b, c, d, e, f];
  3013. ctx._originalSetTransform(a, b, c, d, e, f);
  3014. };
  3015. ctx.rotate = function ctxRotate(angle) {
  3016. var cosValue = Math.cos(angle);
  3017. var sinValue = Math.sin(angle);
  3018. var m = this._transformMatrix;
  3019. this._transformMatrix = [
  3020. m[0] * cosValue + m[2] * sinValue,
  3021. m[1] * cosValue + m[3] * sinValue,
  3022. m[0] * (-sinValue) + m[2] * cosValue,
  3023. m[1] * (-sinValue) + m[3] * cosValue,
  3024. m[4],
  3025. m[5]
  3026. ];
  3027. this._originalRotate(angle);
  3028. };
  3029. }
  3030. }
  3031. var CachedCanvases = (function CachedCanvasesClosure() {
  3032. var cache = {};
  3033. return {
  3034. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3035. trackTransform) {
  3036. var canvasEntry;
  3037. if (cache[id] !== undefined) {
  3038. canvasEntry = cache[id];
  3039. canvasEntry.canvas.width = width;
  3040. canvasEntry.canvas.height = height;
  3041. // reset canvas transform for emulated mozCurrentTransform, if needed
  3042. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3043. } else {
  3044. var canvas = createScratchCanvas(width, height);
  3045. var ctx = canvas.getContext('2d');
  3046. if (trackTransform) {
  3047. addContextCurrentTransform(ctx);
  3048. }
  3049. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3050. }
  3051. return canvasEntry;
  3052. },
  3053. clear: function () {
  3054. for (var id in cache) {
  3055. var canvasEntry = cache[id];
  3056. // Zeroing the width and height causes Firefox to release graphics
  3057. // resources immediately, which can greatly reduce memory consumption.
  3058. canvasEntry.canvas.width = 0;
  3059. canvasEntry.canvas.height = 0;
  3060. delete cache[id];
  3061. }
  3062. }
  3063. };
  3064. })();
  3065. function compileType3Glyph(imgData) {
  3066. var POINT_TO_PROCESS_LIMIT = 1000;
  3067. var width = imgData.width, height = imgData.height;
  3068. var i, j, j0, width1 = width + 1;
  3069. var points = new Uint8Array(width1 * (height + 1));
  3070. var POINT_TYPES =
  3071. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3072. // decodes bit-packed mask data
  3073. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3074. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3075. for (i = 0, ii = data0.length; i < ii; i++) {
  3076. var mask = 128, elem = data0[i];
  3077. while (mask > 0) {
  3078. data[pos++] = (elem & mask) ? 0 : 255;
  3079. mask >>= 1;
  3080. }
  3081. }
  3082. // finding iteresting points: every point is located between mask pixels,
  3083. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3084. // will have flags assigned based on neighboring mask pixels:
  3085. // 4 | 8
  3086. // --P--
  3087. // 2 | 1
  3088. // We are interested only in points with the flags:
  3089. // - outside corners: 1, 2, 4, 8;
  3090. // - inside corners: 7, 11, 13, 14;
  3091. // - and, intersections: 5, 10.
  3092. var count = 0;
  3093. pos = 0;
  3094. if (data[pos] !== 0) {
  3095. points[0] = 1;
  3096. ++count;
  3097. }
  3098. for (j = 1; j < width; j++) {
  3099. if (data[pos] !== data[pos + 1]) {
  3100. points[j] = data[pos] ? 2 : 1;
  3101. ++count;
  3102. }
  3103. pos++;
  3104. }
  3105. if (data[pos] !== 0) {
  3106. points[j] = 2;
  3107. ++count;
  3108. }
  3109. for (i = 1; i < height; i++) {
  3110. pos = i * lineSize;
  3111. j0 = i * width1;
  3112. if (data[pos - lineSize] !== data[pos]) {
  3113. points[j0] = data[pos] ? 1 : 8;
  3114. ++count;
  3115. }
  3116. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3117. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3118. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3119. for (j = 1; j < width; j++) {
  3120. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3121. (data[pos - lineSize + 1] ? 8 : 0);
  3122. if (POINT_TYPES[sum]) {
  3123. points[j0 + j] = POINT_TYPES[sum];
  3124. ++count;
  3125. }
  3126. pos++;
  3127. }
  3128. if (data[pos - lineSize] !== data[pos]) {
  3129. points[j0 + j] = data[pos] ? 2 : 4;
  3130. ++count;
  3131. }
  3132. if (count > POINT_TO_PROCESS_LIMIT) {
  3133. return null;
  3134. }
  3135. }
  3136. pos = lineSize * (height - 1);
  3137. j0 = i * width1;
  3138. if (data[pos] !== 0) {
  3139. points[j0] = 8;
  3140. ++count;
  3141. }
  3142. for (j = 1; j < width; j++) {
  3143. if (data[pos] !== data[pos + 1]) {
  3144. points[j0 + j] = data[pos] ? 4 : 8;
  3145. ++count;
  3146. }
  3147. pos++;
  3148. }
  3149. if (data[pos] !== 0) {
  3150. points[j0 + j] = 4;
  3151. ++count;
  3152. }
  3153. if (count > POINT_TO_PROCESS_LIMIT) {
  3154. return null;
  3155. }
  3156. // building outlines
  3157. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3158. var outlines = [];
  3159. for (i = 0; count && i <= height; i++) {
  3160. var p = i * width1;
  3161. var end = p + width;
  3162. while (p < end && !points[p]) {
  3163. p++;
  3164. }
  3165. if (p === end) {
  3166. continue;
  3167. }
  3168. var coords = [p % width1, i];
  3169. var type = points[p], p0 = p, pp;
  3170. do {
  3171. var step = steps[type];
  3172. do {
  3173. p += step;
  3174. } while (!points[p]);
  3175. pp = points[p];
  3176. if (pp !== 5 && pp !== 10) {
  3177. // set new direction
  3178. type = pp;
  3179. // delete mark
  3180. points[p] = 0;
  3181. } else { // type is 5 or 10, ie, a crossing
  3182. // set new direction
  3183. type = pp & ((0x33 * type) >> 4);
  3184. // set new type for "future hit"
  3185. points[p] &= (type >> 2 | type << 2);
  3186. }
  3187. coords.push(p % width1);
  3188. coords.push((p / width1) | 0);
  3189. --count;
  3190. } while (p0 !== p);
  3191. outlines.push(coords);
  3192. --i;
  3193. }
  3194. var drawOutline = function(c) {
  3195. c.save();
  3196. // the path shall be painted in [0..1]x[0..1] space
  3197. c.scale(1 / width, -1 / height);
  3198. c.translate(0, -height);
  3199. c.beginPath();
  3200. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3201. var o = outlines[i];
  3202. c.moveTo(o[0], o[1]);
  3203. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3204. c.lineTo(o[j], o[j+1]);
  3205. }
  3206. }
  3207. c.fill();
  3208. c.beginPath();
  3209. c.restore();
  3210. };
  3211. return drawOutline;
  3212. }
  3213. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3214. function CanvasExtraState(old) {
  3215. // Are soft masks and alpha values shapes or opacities?
  3216. this.alphaIsShape = false;
  3217. this.fontSize = 0;
  3218. this.fontSizeScale = 1;
  3219. this.textMatrix = IDENTITY_MATRIX;
  3220. this.textMatrixScale = 1;
  3221. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3222. this.leading = 0;
  3223. // Current point (in user coordinates)
  3224. this.x = 0;
  3225. this.y = 0;
  3226. // Start of text line (in text coordinates)
  3227. this.lineX = 0;
  3228. this.lineY = 0;
  3229. // Character and word spacing
  3230. this.charSpacing = 0;
  3231. this.wordSpacing = 0;
  3232. this.textHScale = 1;
  3233. this.textRenderingMode = TextRenderingMode.FILL;
  3234. this.textRise = 0;
  3235. // Default fore and background colors
  3236. this.fillColor = '#000000';
  3237. this.strokeColor = '#000000';
  3238. this.patternFill = false;
  3239. // Note: fill alpha applies to all non-stroking operations
  3240. this.fillAlpha = 1;
  3241. this.strokeAlpha = 1;
  3242. this.lineWidth = 1;
  3243. this.activeSMask = null; // nonclonable field (see the save method below)
  3244. this.old = old;
  3245. }
  3246. CanvasExtraState.prototype = {
  3247. clone: function CanvasExtraState_clone() {
  3248. return Object.create(this);
  3249. },
  3250. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3251. this.x = x;
  3252. this.y = y;
  3253. }
  3254. };
  3255. return CanvasExtraState;
  3256. })();
  3257. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3258. // Defines the time the executeOperatorList is going to be executing
  3259. // before it stops and shedules a continue of execution.
  3260. var EXECUTION_TIME = 15;
  3261. // Defines the number of steps before checking the execution time
  3262. var EXECUTION_STEPS = 10;
  3263. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3264. this.ctx = canvasCtx;
  3265. this.current = new CanvasExtraState();
  3266. this.stateStack = [];
  3267. this.pendingClip = null;
  3268. this.pendingEOFill = false;
  3269. this.res = null;
  3270. this.xobjs = null;
  3271. this.commonObjs = commonObjs;
  3272. this.objs = objs;
  3273. this.imageLayer = imageLayer;
  3274. this.groupStack = [];
  3275. this.processingType3 = null;
  3276. // Patterns are painted relative to the initial page/form transform, see pdf
  3277. // spec 8.7.2 NOTE 1.
  3278. this.baseTransform = null;
  3279. this.baseTransformStack = [];
  3280. this.groupLevel = 0;
  3281. this.smaskStack = [];
  3282. this.smaskCounter = 0;
  3283. this.tempSMask = null;
  3284. if (canvasCtx) {
  3285. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  3286. // the transformation must already be set in canvasCtx._transformMatrix.
  3287. addContextCurrentTransform(canvasCtx);
  3288. }
  3289. this.cachedGetSinglePixelWidth = null;
  3290. }
  3291. function putBinaryImageData(ctx, imgData) {
  3292. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3293. ctx.putImageData(imgData, 0, 0);
  3294. return;
  3295. }
  3296. // Put the image data to the canvas in chunks, rather than putting the
  3297. // whole image at once. This saves JS memory, because the ImageData object
  3298. // is smaller. It also possibly saves C++ memory within the implementation
  3299. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3300. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3301. // because too many putImageData() calls will slow things down.
  3302. //
  3303. // Note: as written, if the last chunk is partial, the putImageData() call
  3304. // will (conceptually) put pixels past the bounds of the canvas. But
  3305. // that's ok; any such pixels are ignored.
  3306. var height = imgData.height, width = imgData.width;
  3307. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3308. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3309. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3310. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3311. var srcPos = 0, destPos;
  3312. var src = imgData.data;
  3313. var dest = chunkImgData.data;
  3314. var i, j, thisChunkHeight, elemsInThisChunk;
  3315. // There are multiple forms in which the pixel data can be passed, and
  3316. // imgData.kind tells us which one this is.
  3317. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3318. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3319. var srcLength = src.byteLength;
  3320. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3321. new Uint32ArrayView(dest);
  3322. var dest32DataLength = dest32.length;
  3323. var fullSrcDiff = (width + 7) >> 3;
  3324. var white = 0xFFFFFFFF;
  3325. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3326. 0xFF000000 : 0x000000FF;
  3327. for (i = 0; i < totalChunks; i++) {
  3328. thisChunkHeight =
  3329. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3330. destPos = 0;
  3331. for (j = 0; j < thisChunkHeight; j++) {
  3332. var srcDiff = srcLength - srcPos;
  3333. var k = 0;
  3334. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3335. var kEndUnrolled = kEnd & ~7;
  3336. var mask = 0;
  3337. var srcByte = 0;
  3338. for (; k < kEndUnrolled; k += 8) {
  3339. srcByte = src[srcPos++];
  3340. dest32[destPos++] = (srcByte & 128) ? white : black;
  3341. dest32[destPos++] = (srcByte & 64) ? white : black;
  3342. dest32[destPos++] = (srcByte & 32) ? white : black;
  3343. dest32[destPos++] = (srcByte & 16) ? white : black;
  3344. dest32[destPos++] = (srcByte & 8) ? white : black;
  3345. dest32[destPos++] = (srcByte & 4) ? white : black;
  3346. dest32[destPos++] = (srcByte & 2) ? white : black;
  3347. dest32[destPos++] = (srcByte & 1) ? white : black;
  3348. }
  3349. for (; k < kEnd; k++) {
  3350. if (mask === 0) {
  3351. srcByte = src[srcPos++];
  3352. mask = 128;
  3353. }
  3354. dest32[destPos++] = (srcByte & mask) ? white : black;
  3355. mask >>= 1;
  3356. }
  3357. }
  3358. // We ran out of input. Make all remaining pixels transparent.
  3359. while (destPos < dest32DataLength) {
  3360. dest32[destPos++] = 0;
  3361. }
  3362. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3363. }
  3364. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3365. // RGBA, 32-bits per pixel.
  3366. j = 0;
  3367. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3368. for (i = 0; i < fullChunks; i++) {
  3369. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3370. srcPos += elemsInThisChunk;
  3371. ctx.putImageData(chunkImgData, 0, j);
  3372. j += FULL_CHUNK_HEIGHT;
  3373. }
  3374. if (i < totalChunks) {
  3375. elemsInThisChunk = width * partialChunkHeight * 4;
  3376. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3377. ctx.putImageData(chunkImgData, 0, j);
  3378. }
  3379. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3380. // RGB, 24-bits per pixel.
  3381. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3382. elemsInThisChunk = width * thisChunkHeight;
  3383. for (i = 0; i < totalChunks; i++) {
  3384. if (i >= fullChunks) {
  3385. thisChunkHeight = partialChunkHeight;
  3386. elemsInThisChunk = width * thisChunkHeight;
  3387. }
  3388. destPos = 0;
  3389. for (j = elemsInThisChunk; j--;) {
  3390. dest[destPos++] = src[srcPos++];
  3391. dest[destPos++] = src[srcPos++];
  3392. dest[destPos++] = src[srcPos++];
  3393. dest[destPos++] = 255;
  3394. }
  3395. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3396. }
  3397. } else {
  3398. error('bad image kind: ' + imgData.kind);
  3399. }
  3400. }
  3401. function putBinaryImageMask(ctx, imgData) {
  3402. var height = imgData.height, width = imgData.width;
  3403. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3404. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3405. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3406. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3407. var srcPos = 0;
  3408. var src = imgData.data;
  3409. var dest = chunkImgData.data;
  3410. for (var i = 0; i < totalChunks; i++) {
  3411. var thisChunkHeight =
  3412. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3413. // Expand the mask so it can be used by the canvas. Any required
  3414. // inversion has already been handled.
  3415. var destPos = 3; // alpha component offset
  3416. for (var j = 0; j < thisChunkHeight; j++) {
  3417. var mask = 0;
  3418. for (var k = 0; k < width; k++) {
  3419. if (!mask) {
  3420. var elem = src[srcPos++];
  3421. mask = 128;
  3422. }
  3423. dest[destPos] = (elem & mask) ? 0 : 255;
  3424. destPos += 4;
  3425. mask >>= 1;
  3426. }
  3427. }
  3428. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3429. }
  3430. }
  3431. function copyCtxState(sourceCtx, destCtx) {
  3432. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3433. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3434. 'globalCompositeOperation', 'font'];
  3435. for (var i = 0, ii = properties.length; i < ii; i++) {
  3436. var property = properties[i];
  3437. if (sourceCtx[property] !== undefined) {
  3438. destCtx[property] = sourceCtx[property];
  3439. }
  3440. }
  3441. if (sourceCtx.setLineDash !== undefined) {
  3442. destCtx.setLineDash(sourceCtx.getLineDash());
  3443. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3444. } else if (sourceCtx.mozDashOffset !== undefined) {
  3445. destCtx.mozDash = sourceCtx.mozDash;
  3446. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3447. }
  3448. }
  3449. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3450. var length = bytes.length;
  3451. for (var i = 3; i < length; i += 4) {
  3452. var alpha = bytes[i];
  3453. if (alpha === 0) {
  3454. bytes[i - 3] = r0;
  3455. bytes[i - 2] = g0;
  3456. bytes[i - 1] = b0;
  3457. } else if (alpha < 255) {
  3458. var alpha_ = 255 - alpha;
  3459. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3460. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3461. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3462. }
  3463. }
  3464. }
  3465. function composeSMaskAlpha(maskData, layerData) {
  3466. var length = maskData.length;
  3467. var scale = 1 / 255;
  3468. for (var i = 3; i < length; i += 4) {
  3469. var alpha = maskData[i];
  3470. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3471. }
  3472. }
  3473. function composeSMaskLuminosity(maskData, layerData) {
  3474. var length = maskData.length;
  3475. for (var i = 3; i < length; i += 4) {
  3476. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3477. (maskData[i - 2] * 152) + // * 0.59 ....
  3478. (maskData[i - 1] * 28); // * 0.11 ....
  3479. layerData[i] = (layerData[i] * y) >> 16;
  3480. }
  3481. }
  3482. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3483. subtype, backdrop) {
  3484. var hasBackdrop = !!backdrop;
  3485. var r0 = hasBackdrop ? backdrop[0] : 0;
  3486. var g0 = hasBackdrop ? backdrop[1] : 0;
  3487. var b0 = hasBackdrop ? backdrop[2] : 0;
  3488. var composeFn;
  3489. if (subtype === 'Luminosity') {
  3490. composeFn = composeSMaskLuminosity;
  3491. } else {
  3492. composeFn = composeSMaskAlpha;
  3493. }
  3494. // processing image in chunks to save memory
  3495. var PIXELS_TO_PROCESS = 1048576;
  3496. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3497. for (var row = 0; row < height; row += chunkSize) {
  3498. var chunkHeight = Math.min(chunkSize, height - row);
  3499. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3500. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3501. if (hasBackdrop) {
  3502. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3503. }
  3504. composeFn(maskData.data, layerData.data);
  3505. maskCtx.putImageData(layerData, 0, row);
  3506. }
  3507. }
  3508. function composeSMask(ctx, smask, layerCtx) {
  3509. var mask = smask.canvas;
  3510. var maskCtx = smask.context;
  3511. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3512. smask.offsetX, smask.offsetY);
  3513. var backdrop = smask.backdrop || null;
  3514. if (WebGLUtils.isEnabled) {
  3515. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3516. {subtype: smask.subtype, backdrop: backdrop});
  3517. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3518. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3519. return;
  3520. }
  3521. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3522. smask.subtype, backdrop);
  3523. ctx.drawImage(mask, 0, 0);
  3524. }
  3525. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3526. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3527. var NORMAL_CLIP = {};
  3528. var EO_CLIP = {};
  3529. CanvasGraphics.prototype = {
  3530. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3531. // For pdfs that use blend modes we have to clear the canvas else certain
  3532. // blend modes can look wrong since we'd be blending with a white
  3533. // backdrop. The problem with a transparent backdrop though is we then
  3534. // don't get sub pixel anti aliasing on text, so we fill with white if
  3535. // we can.
  3536. var width = this.ctx.canvas.width;
  3537. var height = this.ctx.canvas.height;
  3538. if (transparency) {
  3539. this.ctx.clearRect(0, 0, width, height);
  3540. } else {
  3541. this.ctx.mozOpaque = true;
  3542. this.ctx.save();
  3543. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3544. this.ctx.fillRect(0, 0, width, height);
  3545. this.ctx.restore();
  3546. }
  3547. var transform = viewport.transform;
  3548. this.ctx.save();
  3549. this.ctx.transform.apply(this.ctx, transform);
  3550. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3551. if (this.imageLayer) {
  3552. this.imageLayer.beginLayout();
  3553. }
  3554. },
  3555. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3556. operatorList,
  3557. executionStartIdx, continueCallback,
  3558. stepper) {
  3559. var argsArray = operatorList.argsArray;
  3560. var fnArray = operatorList.fnArray;
  3561. var i = executionStartIdx || 0;
  3562. var argsArrayLen = argsArray.length;
  3563. // Sometimes the OperatorList to execute is empty.
  3564. if (argsArrayLen === i) {
  3565. return i;
  3566. }
  3567. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3568. typeof continueCallback === 'function');
  3569. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3570. var steps = 0;
  3571. var commonObjs = this.commonObjs;
  3572. var objs = this.objs;
  3573. var fnId;
  3574. while (true) {
  3575. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3576. stepper.breakIt(i, continueCallback);
  3577. return i;
  3578. }
  3579. fnId = fnArray[i];
  3580. if (fnId !== OPS.dependency) {
  3581. this[fnId].apply(this, argsArray[i]);
  3582. } else {
  3583. var deps = argsArray[i];
  3584. for (var n = 0, nn = deps.length; n < nn; n++) {
  3585. var depObjId = deps[n];
  3586. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3587. var objsPool = common ? commonObjs : objs;
  3588. // If the promise isn't resolved yet, add the continueCallback
  3589. // to the promise and bail out.
  3590. if (!objsPool.isResolved(depObjId)) {
  3591. objsPool.get(depObjId, continueCallback);
  3592. return i;
  3593. }
  3594. }
  3595. }
  3596. i++;
  3597. // If the entire operatorList was executed, stop as were done.
  3598. if (i === argsArrayLen) {
  3599. return i;
  3600. }
  3601. // If the execution took longer then a certain amount of time and
  3602. // `continueCallback` is specified, interrupt the execution.
  3603. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3604. if (Date.now() > endTime) {
  3605. continueCallback();
  3606. return i;
  3607. }
  3608. steps = 0;
  3609. }
  3610. // If the operatorList isn't executed completely yet OR the execution
  3611. // time was short enough, do another execution round.
  3612. }
  3613. },
  3614. endDrawing: function CanvasGraphics_endDrawing() {
  3615. this.ctx.restore();
  3616. CachedCanvases.clear();
  3617. WebGLUtils.clear();
  3618. if (this.imageLayer) {
  3619. this.imageLayer.endLayout();
  3620. }
  3621. },
  3622. // Graphics state
  3623. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3624. this.current.lineWidth = width;
  3625. this.ctx.lineWidth = width;
  3626. },
  3627. setLineCap: function CanvasGraphics_setLineCap(style) {
  3628. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3629. },
  3630. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3631. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3632. },
  3633. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3634. this.ctx.miterLimit = limit;
  3635. },
  3636. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3637. var ctx = this.ctx;
  3638. if (ctx.setLineDash !== undefined) {
  3639. ctx.setLineDash(dashArray);
  3640. ctx.lineDashOffset = dashPhase;
  3641. } else {
  3642. ctx.mozDash = dashArray;
  3643. ctx.mozDashOffset = dashPhase;
  3644. }
  3645. },
  3646. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3647. // Maybe if we one day fully support color spaces this will be important
  3648. // for now we can ignore.
  3649. // TODO set rendering intent?
  3650. },
  3651. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3652. // There's no way to control this with canvas, but we can safely ignore.
  3653. // TODO set flatness?
  3654. },
  3655. setGState: function CanvasGraphics_setGState(states) {
  3656. for (var i = 0, ii = states.length; i < ii; i++) {
  3657. var state = states[i];
  3658. var key = state[0];
  3659. var value = state[1];
  3660. switch (key) {
  3661. case 'LW':
  3662. this.setLineWidth(value);
  3663. break;
  3664. case 'LC':
  3665. this.setLineCap(value);
  3666. break;
  3667. case 'LJ':
  3668. this.setLineJoin(value);
  3669. break;
  3670. case 'ML':
  3671. this.setMiterLimit(value);
  3672. break;
  3673. case 'D':
  3674. this.setDash(value[0], value[1]);
  3675. break;
  3676. case 'RI':
  3677. this.setRenderingIntent(value);
  3678. break;
  3679. case 'FL':
  3680. this.setFlatness(value);
  3681. break;
  3682. case 'Font':
  3683. this.setFont(value[0], value[1]);
  3684. break;
  3685. case 'CA':
  3686. this.current.strokeAlpha = state[1];
  3687. break;
  3688. case 'ca':
  3689. this.current.fillAlpha = state[1];
  3690. this.ctx.globalAlpha = state[1];
  3691. break;
  3692. case 'BM':
  3693. if (value && value.name && (value.name !== 'Normal')) {
  3694. var mode = value.name.replace(/([A-Z])/g,
  3695. function(c) {
  3696. return '-' + c.toLowerCase();
  3697. }
  3698. ).substring(1);
  3699. this.ctx.globalCompositeOperation = mode;
  3700. if (this.ctx.globalCompositeOperation !== mode) {
  3701. warn('globalCompositeOperation "' + mode +
  3702. '" is not supported');
  3703. }
  3704. } else {
  3705. this.ctx.globalCompositeOperation = 'source-over';
  3706. }
  3707. break;
  3708. case 'SMask':
  3709. if (this.current.activeSMask) {
  3710. this.endSMaskGroup();
  3711. }
  3712. this.current.activeSMask = value ? this.tempSMask : null;
  3713. if (this.current.activeSMask) {
  3714. this.beginSMaskGroup();
  3715. }
  3716. this.tempSMask = null;
  3717. break;
  3718. }
  3719. }
  3720. },
  3721. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3722. var activeSMask = this.current.activeSMask;
  3723. var drawnWidth = activeSMask.canvas.width;
  3724. var drawnHeight = activeSMask.canvas.height;
  3725. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3726. var scratchCanvas = CachedCanvases.getCanvas(
  3727. cacheId, drawnWidth, drawnHeight, true);
  3728. var currentCtx = this.ctx;
  3729. var currentTransform = currentCtx.mozCurrentTransform;
  3730. this.ctx.save();
  3731. var groupCtx = scratchCanvas.context;
  3732. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3733. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3734. groupCtx.transform.apply(groupCtx, currentTransform);
  3735. copyCtxState(currentCtx, groupCtx);
  3736. this.ctx = groupCtx;
  3737. this.setGState([
  3738. ['BM', 'Normal'],
  3739. ['ca', 1],
  3740. ['CA', 1]
  3741. ]);
  3742. this.groupStack.push(currentCtx);
  3743. this.groupLevel++;
  3744. },
  3745. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3746. var groupCtx = this.ctx;
  3747. this.groupLevel--;
  3748. this.ctx = this.groupStack.pop();
  3749. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3750. this.ctx.restore();
  3751. },
  3752. save: function CanvasGraphics_save() {
  3753. this.ctx.save();
  3754. var old = this.current;
  3755. this.stateStack.push(old);
  3756. this.current = old.clone();
  3757. this.current.activeSMask = null;
  3758. },
  3759. restore: function CanvasGraphics_restore() {
  3760. if (this.stateStack.length !== 0) {
  3761. if (this.current.activeSMask !== null) {
  3762. this.endSMaskGroup();
  3763. }
  3764. this.current = this.stateStack.pop();
  3765. this.ctx.restore();
  3766. this.cachedGetSinglePixelWidth = null;
  3767. }
  3768. },
  3769. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3770. this.ctx.transform(a, b, c, d, e, f);
  3771. this.cachedGetSinglePixelWidth = null;
  3772. },
  3773. // Path
  3774. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3775. var ctx = this.ctx;
  3776. var current = this.current;
  3777. var x = current.x, y = current.y;
  3778. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3779. switch (ops[i] | 0) {
  3780. case OPS.rectangle:
  3781. x = args[j++];
  3782. y = args[j++];
  3783. var width = args[j++];
  3784. var height = args[j++];
  3785. if (width === 0) {
  3786. width = this.getSinglePixelWidth();
  3787. }
  3788. if (height === 0) {
  3789. height = this.getSinglePixelWidth();
  3790. }
  3791. var xw = x + width;
  3792. var yh = y + height;
  3793. this.ctx.moveTo(x, y);
  3794. this.ctx.lineTo(xw, y);
  3795. this.ctx.lineTo(xw, yh);
  3796. this.ctx.lineTo(x, yh);
  3797. this.ctx.lineTo(x, y);
  3798. this.ctx.closePath();
  3799. break;
  3800. case OPS.moveTo:
  3801. x = args[j++];
  3802. y = args[j++];
  3803. ctx.moveTo(x, y);
  3804. break;
  3805. case OPS.lineTo:
  3806. x = args[j++];
  3807. y = args[j++];
  3808. ctx.lineTo(x, y);
  3809. break;
  3810. case OPS.curveTo:
  3811. x = args[j + 4];
  3812. y = args[j + 5];
  3813. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3814. x, y);
  3815. j += 6;
  3816. break;
  3817. case OPS.curveTo2:
  3818. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3819. args[j + 2], args[j + 3]);
  3820. x = args[j + 2];
  3821. y = args[j + 3];
  3822. j += 4;
  3823. break;
  3824. case OPS.curveTo3:
  3825. x = args[j + 2];
  3826. y = args[j + 3];
  3827. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3828. j += 4;
  3829. break;
  3830. case OPS.closePath:
  3831. ctx.closePath();
  3832. break;
  3833. }
  3834. }
  3835. current.setCurrentPoint(x, y);
  3836. },
  3837. closePath: function CanvasGraphics_closePath() {
  3838. this.ctx.closePath();
  3839. },
  3840. stroke: function CanvasGraphics_stroke(consumePath) {
  3841. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3842. var ctx = this.ctx;
  3843. var strokeColor = this.current.strokeColor;
  3844. // Prevent drawing too thin lines by enforcing a minimum line width.
  3845. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  3846. this.current.lineWidth);
  3847. // For stroke we want to temporarily change the global alpha to the
  3848. // stroking alpha.
  3849. ctx.globalAlpha = this.current.strokeAlpha;
  3850. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3851. strokeColor.type === 'Pattern') {
  3852. // for patterns, we transform to pattern space, calculate
  3853. // the pattern, call stroke, and restore to user space
  3854. ctx.save();
  3855. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3856. ctx.stroke();
  3857. ctx.restore();
  3858. } else {
  3859. ctx.stroke();
  3860. }
  3861. if (consumePath) {
  3862. this.consumePath();
  3863. }
  3864. // Restore the global alpha to the fill alpha
  3865. ctx.globalAlpha = this.current.fillAlpha;
  3866. },
  3867. closeStroke: function CanvasGraphics_closeStroke() {
  3868. this.closePath();
  3869. this.stroke();
  3870. },
  3871. fill: function CanvasGraphics_fill(consumePath) {
  3872. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3873. var ctx = this.ctx;
  3874. var fillColor = this.current.fillColor;
  3875. var isPatternFill = this.current.patternFill;
  3876. var needRestore = false;
  3877. if (isPatternFill) {
  3878. ctx.save();
  3879. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3880. needRestore = true;
  3881. }
  3882. if (this.pendingEOFill) {
  3883. if (ctx.mozFillRule !== undefined) {
  3884. ctx.mozFillRule = 'evenodd';
  3885. ctx.fill();
  3886. ctx.mozFillRule = 'nonzero';
  3887. } else {
  3888. try {
  3889. ctx.fill('evenodd');
  3890. } catch (ex) {
  3891. // shouldn't really happen, but browsers might think differently
  3892. ctx.fill();
  3893. }
  3894. }
  3895. this.pendingEOFill = false;
  3896. } else {
  3897. ctx.fill();
  3898. }
  3899. if (needRestore) {
  3900. ctx.restore();
  3901. }
  3902. if (consumePath) {
  3903. this.consumePath();
  3904. }
  3905. },
  3906. eoFill: function CanvasGraphics_eoFill() {
  3907. this.pendingEOFill = true;
  3908. this.fill();
  3909. },
  3910. fillStroke: function CanvasGraphics_fillStroke() {
  3911. this.fill(false);
  3912. this.stroke(false);
  3913. this.consumePath();
  3914. },
  3915. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3916. this.pendingEOFill = true;
  3917. this.fillStroke();
  3918. },
  3919. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3920. this.closePath();
  3921. this.fillStroke();
  3922. },
  3923. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3924. this.pendingEOFill = true;
  3925. this.closePath();
  3926. this.fillStroke();
  3927. },
  3928. endPath: function CanvasGraphics_endPath() {
  3929. this.consumePath();
  3930. },
  3931. // Clipping
  3932. clip: function CanvasGraphics_clip() {
  3933. this.pendingClip = NORMAL_CLIP;
  3934. },
  3935. eoClip: function CanvasGraphics_eoClip() {
  3936. this.pendingClip = EO_CLIP;
  3937. },
  3938. // Text
  3939. beginText: function CanvasGraphics_beginText() {
  3940. this.current.textMatrix = IDENTITY_MATRIX;
  3941. this.current.textMatrixScale = 1;
  3942. this.current.x = this.current.lineX = 0;
  3943. this.current.y = this.current.lineY = 0;
  3944. },
  3945. endText: function CanvasGraphics_endText() {
  3946. var paths = this.pendingTextPaths;
  3947. var ctx = this.ctx;
  3948. if (paths === undefined) {
  3949. ctx.beginPath();
  3950. return;
  3951. }
  3952. ctx.save();
  3953. ctx.beginPath();
  3954. for (var i = 0; i < paths.length; i++) {
  3955. var path = paths[i];
  3956. ctx.setTransform.apply(ctx, path.transform);
  3957. ctx.translate(path.x, path.y);
  3958. path.addToPath(ctx, path.fontSize);
  3959. }
  3960. ctx.restore();
  3961. ctx.clip();
  3962. ctx.beginPath();
  3963. delete this.pendingTextPaths;
  3964. },
  3965. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3966. this.current.charSpacing = spacing;
  3967. },
  3968. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3969. this.current.wordSpacing = spacing;
  3970. },
  3971. setHScale: function CanvasGraphics_setHScale(scale) {
  3972. this.current.textHScale = scale / 100;
  3973. },
  3974. setLeading: function CanvasGraphics_setLeading(leading) {
  3975. this.current.leading = -leading;
  3976. },
  3977. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3978. var fontObj = this.commonObjs.get(fontRefName);
  3979. var current = this.current;
  3980. if (!fontObj) {
  3981. error('Can\'t find font for ' + fontRefName);
  3982. }
  3983. current.fontMatrix = (fontObj.fontMatrix ?
  3984. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3985. // A valid matrix needs all main diagonal elements to be non-zero
  3986. // This also ensures we bypass FF bugzilla bug #719844.
  3987. if (current.fontMatrix[0] === 0 ||
  3988. current.fontMatrix[3] === 0) {
  3989. warn('Invalid font matrix for font ' + fontRefName);
  3990. }
  3991. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3992. // and in some docs this can be negative (inverted x-y axes).
  3993. if (size < 0) {
  3994. size = -size;
  3995. current.fontDirection = -1;
  3996. } else {
  3997. current.fontDirection = 1;
  3998. }
  3999. this.current.font = fontObj;
  4000. this.current.fontSize = size;
  4001. if (fontObj.isType3Font) {
  4002. return; // we don't need ctx.font for Type3 fonts
  4003. }
  4004. var name = fontObj.loadedName || 'sans-serif';
  4005. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  4006. (fontObj.bold ? 'bold' : 'normal');
  4007. var italic = fontObj.italic ? 'italic' : 'normal';
  4008. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4009. // Some font backends cannot handle fonts below certain size.
  4010. // Keeping the font at minimal size and using the fontSizeScale to change
  4011. // the current transformation matrix before the fillText/strokeText.
  4012. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4013. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4014. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4015. this.current.fontSizeScale = size / browserFontSize;
  4016. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4017. this.ctx.font = rule;
  4018. },
  4019. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4020. this.current.textRenderingMode = mode;
  4021. },
  4022. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4023. this.current.textRise = rise;
  4024. },
  4025. moveText: function CanvasGraphics_moveText(x, y) {
  4026. this.current.x = this.current.lineX += x;
  4027. this.current.y = this.current.lineY += y;
  4028. },
  4029. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4030. this.setLeading(-y);
  4031. this.moveText(x, y);
  4032. },
  4033. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4034. this.current.textMatrix = [a, b, c, d, e, f];
  4035. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4036. this.current.x = this.current.lineX = 0;
  4037. this.current.y = this.current.lineY = 0;
  4038. },
  4039. nextLine: function CanvasGraphics_nextLine() {
  4040. this.moveText(0, this.current.leading);
  4041. },
  4042. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4043. var ctx = this.ctx;
  4044. var current = this.current;
  4045. var font = current.font;
  4046. var textRenderingMode = current.textRenderingMode;
  4047. var fontSize = current.fontSize / current.fontSizeScale;
  4048. var fillStrokeMode = textRenderingMode &
  4049. TextRenderingMode.FILL_STROKE_MASK;
  4050. var isAddToPathSet = !!(textRenderingMode &
  4051. TextRenderingMode.ADD_TO_PATH_FLAG);
  4052. var addToPath;
  4053. if (font.disableFontFace || isAddToPathSet) {
  4054. addToPath = font.getPathGenerator(this.commonObjs, character);
  4055. }
  4056. if (font.disableFontFace) {
  4057. ctx.save();
  4058. ctx.translate(x, y);
  4059. ctx.beginPath();
  4060. addToPath(ctx, fontSize);
  4061. if (fillStrokeMode === TextRenderingMode.FILL ||
  4062. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4063. ctx.fill();
  4064. }
  4065. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4066. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4067. ctx.stroke();
  4068. }
  4069. ctx.restore();
  4070. } else {
  4071. if (fillStrokeMode === TextRenderingMode.FILL ||
  4072. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4073. ctx.fillText(character, x, y);
  4074. }
  4075. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4076. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4077. ctx.strokeText(character, x, y);
  4078. }
  4079. }
  4080. if (isAddToPathSet) {
  4081. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4082. paths.push({
  4083. transform: ctx.mozCurrentTransform,
  4084. x: x,
  4085. y: y,
  4086. fontSize: fontSize,
  4087. addToPath: addToPath
  4088. });
  4089. }
  4090. },
  4091. get isFontSubpixelAAEnabled() {
  4092. // Checks if anti-aliasing is enabled when scaled text is painted.
  4093. // On Windows GDI scaled fonts looks bad.
  4094. var ctx = document.createElement('canvas').getContext('2d');
  4095. ctx.scale(1.5, 1);
  4096. ctx.fillText('I', 0, 10);
  4097. var data = ctx.getImageData(0, 0, 10, 10).data;
  4098. var enabled = false;
  4099. for (var i = 3; i < data.length; i += 4) {
  4100. if (data[i] > 0 && data[i] < 255) {
  4101. enabled = true;
  4102. break;
  4103. }
  4104. }
  4105. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4106. },
  4107. showText: function CanvasGraphics_showText(glyphs) {
  4108. var current = this.current;
  4109. var font = current.font;
  4110. if (font.isType3Font) {
  4111. return this.showType3Text(glyphs);
  4112. }
  4113. var fontSize = current.fontSize;
  4114. if (fontSize === 0) {
  4115. return;
  4116. }
  4117. var ctx = this.ctx;
  4118. var fontSizeScale = current.fontSizeScale;
  4119. var charSpacing = current.charSpacing;
  4120. var wordSpacing = current.wordSpacing;
  4121. var fontDirection = current.fontDirection;
  4122. var textHScale = current.textHScale * fontDirection;
  4123. var glyphsLength = glyphs.length;
  4124. var vertical = font.vertical;
  4125. var defaultVMetrics = font.defaultVMetrics;
  4126. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4127. var simpleFillText =
  4128. current.textRenderingMode === TextRenderingMode.FILL &&
  4129. !font.disableFontFace;
  4130. ctx.save();
  4131. ctx.transform.apply(ctx, current.textMatrix);
  4132. ctx.translate(current.x, current.y + current.textRise);
  4133. if (fontDirection > 0) {
  4134. ctx.scale(textHScale, -1);
  4135. } else {
  4136. ctx.scale(textHScale, 1);
  4137. }
  4138. var lineWidth = current.lineWidth;
  4139. var scale = current.textMatrixScale;
  4140. if (scale === 0 || lineWidth === 0) {
  4141. var fillStrokeMode = current.textRenderingMode &
  4142. TextRenderingMode.FILL_STROKE_MASK;
  4143. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4144. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4145. this.cachedGetSinglePixelWidth = null;
  4146. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4147. }
  4148. } else {
  4149. lineWidth /= scale;
  4150. }
  4151. if (fontSizeScale !== 1.0) {
  4152. ctx.scale(fontSizeScale, fontSizeScale);
  4153. lineWidth /= fontSizeScale;
  4154. }
  4155. ctx.lineWidth = lineWidth;
  4156. var x = 0, i;
  4157. for (i = 0; i < glyphsLength; ++i) {
  4158. var glyph = glyphs[i];
  4159. if (glyph === null) {
  4160. // word break
  4161. x += fontDirection * wordSpacing;
  4162. continue;
  4163. } else if (isNum(glyph)) {
  4164. x += -glyph * fontSize * 0.001;
  4165. continue;
  4166. }
  4167. var restoreNeeded = false;
  4168. var character = glyph.fontChar;
  4169. var accent = glyph.accent;
  4170. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4171. var width = glyph.width;
  4172. if (vertical) {
  4173. var vmetric, vx, vy;
  4174. vmetric = glyph.vmetric || defaultVMetrics;
  4175. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4176. vx = -vx * widthAdvanceScale;
  4177. vy = vmetric[2] * widthAdvanceScale;
  4178. width = vmetric ? -vmetric[0] : width;
  4179. scaledX = vx / fontSizeScale;
  4180. scaledY = (x + vy) / fontSizeScale;
  4181. } else {
  4182. scaledX = x / fontSizeScale;
  4183. scaledY = 0;
  4184. }
  4185. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4186. // some standard fonts may not have the exact width, trying to
  4187. // rescale per character
  4188. var measuredWidth = ctx.measureText(character).width * 1000 /
  4189. fontSize * fontSizeScale;
  4190. var characterScaleX = width / measuredWidth;
  4191. restoreNeeded = true;
  4192. ctx.save();
  4193. ctx.scale(characterScaleX, 1);
  4194. scaledX /= characterScaleX;
  4195. }
  4196. if (simpleFillText && !accent) {
  4197. // common case
  4198. ctx.fillText(character, scaledX, scaledY);
  4199. } else {
  4200. this.paintChar(character, scaledX, scaledY);
  4201. if (accent) {
  4202. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4203. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4204. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4205. }
  4206. }
  4207. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4208. x += charWidth;
  4209. if (restoreNeeded) {
  4210. ctx.restore();
  4211. }
  4212. }
  4213. if (vertical) {
  4214. current.y -= x * textHScale;
  4215. } else {
  4216. current.x += x * textHScale;
  4217. }
  4218. ctx.restore();
  4219. },
  4220. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4221. // Type3 fonts - each glyph is a "mini-PDF"
  4222. var ctx = this.ctx;
  4223. var current = this.current;
  4224. var font = current.font;
  4225. var fontSize = current.fontSize;
  4226. var fontDirection = current.fontDirection;
  4227. var charSpacing = current.charSpacing;
  4228. var wordSpacing = current.wordSpacing;
  4229. var textHScale = current.textHScale * fontDirection;
  4230. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4231. var glyphsLength = glyphs.length;
  4232. var isTextInvisible =
  4233. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4234. var i, glyph, width;
  4235. if (isTextInvisible || fontSize === 0) {
  4236. return;
  4237. }
  4238. ctx.save();
  4239. ctx.transform.apply(ctx, current.textMatrix);
  4240. ctx.translate(current.x, current.y);
  4241. ctx.scale(textHScale, fontDirection);
  4242. for (i = 0; i < glyphsLength; ++i) {
  4243. glyph = glyphs[i];
  4244. if (glyph === null) {
  4245. // word break
  4246. this.ctx.translate(wordSpacing, 0);
  4247. current.x += wordSpacing * textHScale;
  4248. continue;
  4249. } else if (isNum(glyph)) {
  4250. var spacingLength = -glyph * 0.001 * fontSize;
  4251. this.ctx.translate(spacingLength, 0);
  4252. current.x += spacingLength * textHScale;
  4253. continue;
  4254. }
  4255. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4256. if (!operatorList) {
  4257. warn('Type3 character \"' + glyph.operatorListId +
  4258. '\" is not available');
  4259. continue;
  4260. }
  4261. this.processingType3 = glyph;
  4262. this.save();
  4263. ctx.scale(fontSize, fontSize);
  4264. ctx.transform.apply(ctx, fontMatrix);
  4265. this.executeOperatorList(operatorList);
  4266. this.restore();
  4267. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4268. width = transformed[0] * fontSize + charSpacing;
  4269. ctx.translate(width, 0);
  4270. current.x += width * textHScale;
  4271. }
  4272. ctx.restore();
  4273. this.processingType3 = null;
  4274. },
  4275. // Type3 fonts
  4276. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4277. // We can safely ignore this since the width should be the same
  4278. // as the width in the Widths array.
  4279. },
  4280. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4281. yWidth,
  4282. llx,
  4283. lly,
  4284. urx,
  4285. ury) {
  4286. // TODO According to the spec we're also suppose to ignore any operators
  4287. // that set color or include images while processing this type3 font.
  4288. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4289. this.clip();
  4290. this.endPath();
  4291. },
  4292. // Color
  4293. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4294. var pattern;
  4295. if (IR[0] === 'TilingPattern') {
  4296. var color = IR[1];
  4297. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4298. this.commonObjs, this.baseTransform);
  4299. } else {
  4300. pattern = getShadingPatternFromIR(IR);
  4301. }
  4302. return pattern;
  4303. },
  4304. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4305. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4306. },
  4307. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4308. this.current.fillColor = this.getColorN_Pattern(arguments);
  4309. this.current.patternFill = true;
  4310. },
  4311. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4312. var color = Util.makeCssRgb(r, g, b);
  4313. this.ctx.strokeStyle = color;
  4314. this.current.strokeColor = color;
  4315. },
  4316. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4317. var color = Util.makeCssRgb(r, g, b);
  4318. this.ctx.fillStyle = color;
  4319. this.current.fillColor = color;
  4320. this.current.patternFill = false;
  4321. },
  4322. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4323. var ctx = this.ctx;
  4324. this.save();
  4325. var pattern = getShadingPatternFromIR(patternIR);
  4326. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4327. var inv = ctx.mozCurrentTransformInverse;
  4328. if (inv) {
  4329. var canvas = ctx.canvas;
  4330. var width = canvas.width;
  4331. var height = canvas.height;
  4332. var bl = Util.applyTransform([0, 0], inv);
  4333. var br = Util.applyTransform([0, height], inv);
  4334. var ul = Util.applyTransform([width, 0], inv);
  4335. var ur = Util.applyTransform([width, height], inv);
  4336. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4337. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4338. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4339. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4340. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4341. } else {
  4342. // HACK to draw the gradient onto an infinite rectangle.
  4343. // PDF gradients are drawn across the entire image while
  4344. // Canvas only allows gradients to be drawn in a rectangle
  4345. // The following bug should allow us to remove this.
  4346. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4347. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4348. }
  4349. this.restore();
  4350. },
  4351. // Images
  4352. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4353. error('Should not call beginInlineImage');
  4354. },
  4355. beginImageData: function CanvasGraphics_beginImageData() {
  4356. error('Should not call beginImageData');
  4357. },
  4358. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4359. bbox) {
  4360. this.save();
  4361. this.baseTransformStack.push(this.baseTransform);
  4362. if (isArray(matrix) && 6 === matrix.length) {
  4363. this.transform.apply(this, matrix);
  4364. }
  4365. this.baseTransform = this.ctx.mozCurrentTransform;
  4366. if (isArray(bbox) && 4 === bbox.length) {
  4367. var width = bbox[2] - bbox[0];
  4368. var height = bbox[3] - bbox[1];
  4369. this.ctx.rect(bbox[0], bbox[1], width, height);
  4370. this.clip();
  4371. this.endPath();
  4372. }
  4373. },
  4374. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4375. this.restore();
  4376. this.baseTransform = this.baseTransformStack.pop();
  4377. },
  4378. beginGroup: function CanvasGraphics_beginGroup(group) {
  4379. this.save();
  4380. var currentCtx = this.ctx;
  4381. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4382. // group results aren't usually that different and they even have tools
  4383. // that ignore this setting. Notes from Rik on implmenting:
  4384. // - When you encounter an transparency group, create a new canvas with
  4385. // the dimensions of the bbox
  4386. // - copy the content from the previous canvas to the new canvas
  4387. // - draw as usual
  4388. // - remove the backdrop alpha:
  4389. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4390. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4391. // backdrop
  4392. // - remove background color:
  4393. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4394. if (!group.isolated) {
  4395. info('TODO: Support non-isolated groups.');
  4396. }
  4397. // TODO knockout - supposedly possible with the clever use of compositing
  4398. // modes.
  4399. if (group.knockout) {
  4400. warn('Knockout groups not supported.');
  4401. }
  4402. var currentTransform = currentCtx.mozCurrentTransform;
  4403. if (group.matrix) {
  4404. currentCtx.transform.apply(currentCtx, group.matrix);
  4405. }
  4406. assert(group.bbox, 'Bounding box is required.');
  4407. // Based on the current transform figure out how big the bounding box
  4408. // will actually be.
  4409. var bounds = Util.getAxialAlignedBoundingBox(
  4410. group.bbox,
  4411. currentCtx.mozCurrentTransform);
  4412. // Clip the bounding box to the current canvas.
  4413. var canvasBounds = [0,
  4414. 0,
  4415. currentCtx.canvas.width,
  4416. currentCtx.canvas.height];
  4417. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4418. // Use ceil in case we're between sizes so we don't create canvas that is
  4419. // too small and make the canvas at least 1x1 pixels.
  4420. var offsetX = Math.floor(bounds[0]);
  4421. var offsetY = Math.floor(bounds[1]);
  4422. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4423. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4424. var scaleX = 1, scaleY = 1;
  4425. if (drawnWidth > MAX_GROUP_SIZE) {
  4426. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4427. drawnWidth = MAX_GROUP_SIZE;
  4428. }
  4429. if (drawnHeight > MAX_GROUP_SIZE) {
  4430. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4431. drawnHeight = MAX_GROUP_SIZE;
  4432. }
  4433. var cacheId = 'groupAt' + this.groupLevel;
  4434. if (group.smask) {
  4435. // Using two cache entries is case if masks are used one after another.
  4436. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4437. }
  4438. var scratchCanvas = CachedCanvases.getCanvas(
  4439. cacheId, drawnWidth, drawnHeight, true);
  4440. var groupCtx = scratchCanvas.context;
  4441. // Since we created a new canvas that is just the size of the bounding box
  4442. // we have to translate the group ctx.
  4443. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4444. groupCtx.translate(-offsetX, -offsetY);
  4445. groupCtx.transform.apply(groupCtx, currentTransform);
  4446. if (group.smask) {
  4447. // Saving state and cached mask to be used in setGState.
  4448. this.smaskStack.push({
  4449. canvas: scratchCanvas.canvas,
  4450. context: groupCtx,
  4451. offsetX: offsetX,
  4452. offsetY: offsetY,
  4453. scaleX: scaleX,
  4454. scaleY: scaleY,
  4455. subtype: group.smask.subtype,
  4456. backdrop: group.smask.backdrop
  4457. });
  4458. } else {
  4459. // Setup the current ctx so when the group is popped we draw it at the
  4460. // right location.
  4461. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4462. currentCtx.translate(offsetX, offsetY);
  4463. currentCtx.scale(scaleX, scaleY);
  4464. }
  4465. // The transparency group inherits all off the current graphics state
  4466. // except the blend mode, soft mask, and alpha constants.
  4467. copyCtxState(currentCtx, groupCtx);
  4468. this.ctx = groupCtx;
  4469. this.setGState([
  4470. ['BM', 'Normal'],
  4471. ['ca', 1],
  4472. ['CA', 1]
  4473. ]);
  4474. this.groupStack.push(currentCtx);
  4475. this.groupLevel++;
  4476. },
  4477. endGroup: function CanvasGraphics_endGroup(group) {
  4478. this.groupLevel--;
  4479. var groupCtx = this.ctx;
  4480. this.ctx = this.groupStack.pop();
  4481. // Turn off image smoothing to avoid sub pixel interpolation which can
  4482. // look kind of blurry for some pdfs.
  4483. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4484. this.ctx.imageSmoothingEnabled = false;
  4485. } else {
  4486. this.ctx.mozImageSmoothingEnabled = false;
  4487. }
  4488. if (group.smask) {
  4489. this.tempSMask = this.smaskStack.pop();
  4490. } else {
  4491. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4492. }
  4493. this.restore();
  4494. },
  4495. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4496. this.save();
  4497. this.current = new CanvasExtraState();
  4498. },
  4499. endAnnotations: function CanvasGraphics_endAnnotations() {
  4500. this.restore();
  4501. },
  4502. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4503. matrix) {
  4504. this.save();
  4505. if (isArray(rect) && 4 === rect.length) {
  4506. var width = rect[2] - rect[0];
  4507. var height = rect[3] - rect[1];
  4508. this.ctx.rect(rect[0], rect[1], width, height);
  4509. this.clip();
  4510. this.endPath();
  4511. }
  4512. this.transform.apply(this, transform);
  4513. this.transform.apply(this, matrix);
  4514. },
  4515. endAnnotation: function CanvasGraphics_endAnnotation() {
  4516. this.restore();
  4517. },
  4518. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4519. var domImage = this.objs.get(objId);
  4520. if (!domImage) {
  4521. warn('Dependent image isn\'t ready yet');
  4522. return;
  4523. }
  4524. this.save();
  4525. var ctx = this.ctx;
  4526. // scale the image to the unit square
  4527. ctx.scale(1 / w, -1 / h);
  4528. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4529. 0, -h, w, h);
  4530. if (this.imageLayer) {
  4531. var currentTransform = ctx.mozCurrentTransformInverse;
  4532. var position = this.getCanvasPosition(0, 0);
  4533. this.imageLayer.appendImage({
  4534. objId: objId,
  4535. left: position[0],
  4536. top: position[1],
  4537. width: w / currentTransform[0],
  4538. height: h / currentTransform[3]
  4539. });
  4540. }
  4541. this.restore();
  4542. },
  4543. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4544. var ctx = this.ctx;
  4545. var width = img.width, height = img.height;
  4546. var fillColor = this.current.fillColor;
  4547. var isPatternFill = this.current.patternFill;
  4548. var glyph = this.processingType3;
  4549. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4550. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4551. glyph.compiled =
  4552. compileType3Glyph({data: img.data, width: width, height: height});
  4553. } else {
  4554. glyph.compiled = null;
  4555. }
  4556. }
  4557. if (glyph && glyph.compiled) {
  4558. glyph.compiled(ctx);
  4559. return;
  4560. }
  4561. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4562. var maskCtx = maskCanvas.context;
  4563. maskCtx.save();
  4564. putBinaryImageMask(maskCtx, img);
  4565. maskCtx.globalCompositeOperation = 'source-in';
  4566. maskCtx.fillStyle = isPatternFill ?
  4567. fillColor.getPattern(maskCtx, this) : fillColor;
  4568. maskCtx.fillRect(0, 0, width, height);
  4569. maskCtx.restore();
  4570. this.paintInlineImageXObject(maskCanvas.canvas);
  4571. },
  4572. paintImageMaskXObjectRepeat:
  4573. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4574. scaleY, positions) {
  4575. var width = imgData.width;
  4576. var height = imgData.height;
  4577. var fillColor = this.current.fillColor;
  4578. var isPatternFill = this.current.patternFill;
  4579. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4580. var maskCtx = maskCanvas.context;
  4581. maskCtx.save();
  4582. putBinaryImageMask(maskCtx, imgData);
  4583. maskCtx.globalCompositeOperation = 'source-in';
  4584. maskCtx.fillStyle = isPatternFill ?
  4585. fillColor.getPattern(maskCtx, this) : fillColor;
  4586. maskCtx.fillRect(0, 0, width, height);
  4587. maskCtx.restore();
  4588. var ctx = this.ctx;
  4589. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4590. ctx.save();
  4591. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4592. ctx.scale(1, -1);
  4593. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4594. 0, -1, 1, 1);
  4595. ctx.restore();
  4596. }
  4597. },
  4598. paintImageMaskXObjectGroup:
  4599. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4600. var ctx = this.ctx;
  4601. var fillColor = this.current.fillColor;
  4602. var isPatternFill = this.current.patternFill;
  4603. for (var i = 0, ii = images.length; i < ii; i++) {
  4604. var image = images[i];
  4605. var width = image.width, height = image.height;
  4606. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4607. var maskCtx = maskCanvas.context;
  4608. maskCtx.save();
  4609. putBinaryImageMask(maskCtx, image);
  4610. maskCtx.globalCompositeOperation = 'source-in';
  4611. maskCtx.fillStyle = isPatternFill ?
  4612. fillColor.getPattern(maskCtx, this) : fillColor;
  4613. maskCtx.fillRect(0, 0, width, height);
  4614. maskCtx.restore();
  4615. ctx.save();
  4616. ctx.transform.apply(ctx, image.transform);
  4617. ctx.scale(1, -1);
  4618. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4619. 0, -1, 1, 1);
  4620. ctx.restore();
  4621. }
  4622. },
  4623. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4624. var imgData = this.objs.get(objId);
  4625. if (!imgData) {
  4626. warn('Dependent image isn\'t ready yet');
  4627. return;
  4628. }
  4629. this.paintInlineImageXObject(imgData);
  4630. },
  4631. paintImageXObjectRepeat:
  4632. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4633. positions) {
  4634. var imgData = this.objs.get(objId);
  4635. if (!imgData) {
  4636. warn('Dependent image isn\'t ready yet');
  4637. return;
  4638. }
  4639. var width = imgData.width;
  4640. var height = imgData.height;
  4641. var map = [];
  4642. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4643. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4644. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4645. }
  4646. this.paintInlineImageXObjectGroup(imgData, map);
  4647. },
  4648. paintInlineImageXObject:
  4649. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4650. var width = imgData.width;
  4651. var height = imgData.height;
  4652. var ctx = this.ctx;
  4653. this.save();
  4654. // scale the image to the unit square
  4655. ctx.scale(1 / width, -1 / height);
  4656. var currentTransform = ctx.mozCurrentTransformInverse;
  4657. var a = currentTransform[0], b = currentTransform[1];
  4658. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4659. var c = currentTransform[2], d = currentTransform[3];
  4660. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4661. var imgToPaint, tmpCanvas;
  4662. // instanceof HTMLElement does not work in jsdom node.js module
  4663. if (imgData instanceof HTMLElement || !imgData.data) {
  4664. imgToPaint = imgData;
  4665. } else {
  4666. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4667. var tmpCtx = tmpCanvas.context;
  4668. putBinaryImageData(tmpCtx, imgData);
  4669. imgToPaint = tmpCanvas.canvas;
  4670. }
  4671. var paintWidth = width, paintHeight = height;
  4672. var tmpCanvasId = 'prescale1';
  4673. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4674. // pixels during drawImage operation, painting on the temporary canvas(es)
  4675. // that are twice smaller in size
  4676. while ((widthScale > 2 && paintWidth > 1) ||
  4677. (heightScale > 2 && paintHeight > 1)) {
  4678. var newWidth = paintWidth, newHeight = paintHeight;
  4679. if (widthScale > 2 && paintWidth > 1) {
  4680. newWidth = Math.ceil(paintWidth / 2);
  4681. widthScale /= paintWidth / newWidth;
  4682. }
  4683. if (heightScale > 2 && paintHeight > 1) {
  4684. newHeight = Math.ceil(paintHeight / 2);
  4685. heightScale /= paintHeight / newHeight;
  4686. }
  4687. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4688. tmpCtx = tmpCanvas.context;
  4689. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4690. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4691. 0, 0, newWidth, newHeight);
  4692. imgToPaint = tmpCanvas.canvas;
  4693. paintWidth = newWidth;
  4694. paintHeight = newHeight;
  4695. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4696. }
  4697. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4698. 0, -height, width, height);
  4699. if (this.imageLayer) {
  4700. var position = this.getCanvasPosition(0, -height);
  4701. this.imageLayer.appendImage({
  4702. imgData: imgData,
  4703. left: position[0],
  4704. top: position[1],
  4705. width: width / currentTransform[0],
  4706. height: height / currentTransform[3]
  4707. });
  4708. }
  4709. this.restore();
  4710. },
  4711. paintInlineImageXObjectGroup:
  4712. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4713. var ctx = this.ctx;
  4714. var w = imgData.width;
  4715. var h = imgData.height;
  4716. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4717. var tmpCtx = tmpCanvas.context;
  4718. putBinaryImageData(tmpCtx, imgData);
  4719. for (var i = 0, ii = map.length; i < ii; i++) {
  4720. var entry = map[i];
  4721. ctx.save();
  4722. ctx.transform.apply(ctx, entry.transform);
  4723. ctx.scale(1, -1);
  4724. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4725. 0, -1, 1, 1);
  4726. if (this.imageLayer) {
  4727. var position = this.getCanvasPosition(entry.x, entry.y);
  4728. this.imageLayer.appendImage({
  4729. imgData: imgData,
  4730. left: position[0],
  4731. top: position[1],
  4732. width: w,
  4733. height: h
  4734. });
  4735. }
  4736. ctx.restore();
  4737. }
  4738. },
  4739. paintSolidColorImageMask:
  4740. function CanvasGraphics_paintSolidColorImageMask() {
  4741. this.ctx.fillRect(0, 0, 1, 1);
  4742. },
  4743. // Marked content
  4744. markPoint: function CanvasGraphics_markPoint(tag) {
  4745. // TODO Marked content.
  4746. },
  4747. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4748. // TODO Marked content.
  4749. },
  4750. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4751. // TODO Marked content.
  4752. },
  4753. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4754. tag, properties) {
  4755. // TODO Marked content.
  4756. },
  4757. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4758. // TODO Marked content.
  4759. },
  4760. // Compatibility
  4761. beginCompat: function CanvasGraphics_beginCompat() {
  4762. // TODO ignore undefined operators (should we do that anyway?)
  4763. },
  4764. endCompat: function CanvasGraphics_endCompat() {
  4765. // TODO stop ignoring undefined operators
  4766. },
  4767. // Helper functions
  4768. consumePath: function CanvasGraphics_consumePath() {
  4769. var ctx = this.ctx;
  4770. if (this.pendingClip) {
  4771. if (this.pendingClip === EO_CLIP) {
  4772. if (ctx.mozFillRule !== undefined) {
  4773. ctx.mozFillRule = 'evenodd';
  4774. ctx.clip();
  4775. ctx.mozFillRule = 'nonzero';
  4776. } else {
  4777. try {
  4778. ctx.clip('evenodd');
  4779. } catch (ex) {
  4780. // shouldn't really happen, but browsers might think differently
  4781. ctx.clip();
  4782. }
  4783. }
  4784. } else {
  4785. ctx.clip();
  4786. }
  4787. this.pendingClip = null;
  4788. }
  4789. ctx.beginPath();
  4790. },
  4791. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4792. if (this.cachedGetSinglePixelWidth === null) {
  4793. var inverse = this.ctx.mozCurrentTransformInverse;
  4794. // max of the current horizontal and vertical scale
  4795. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4796. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4797. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4798. }
  4799. return this.cachedGetSinglePixelWidth;
  4800. },
  4801. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4802. var transform = this.ctx.mozCurrentTransform;
  4803. return [
  4804. transform[0] * x + transform[2] * y + transform[4],
  4805. transform[1] * x + transform[3] * y + transform[5]
  4806. ];
  4807. }
  4808. };
  4809. for (var op in OPS) {
  4810. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4811. }
  4812. return CanvasGraphics;
  4813. })();
  4814. var WebGLUtils = (function WebGLUtilsClosure() {
  4815. function loadShader(gl, code, shaderType) {
  4816. var shader = gl.createShader(shaderType);
  4817. gl.shaderSource(shader, code);
  4818. gl.compileShader(shader);
  4819. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4820. if (!compiled) {
  4821. var errorMsg = gl.getShaderInfoLog(shader);
  4822. throw new Error('Error during shader compilation: ' + errorMsg);
  4823. }
  4824. return shader;
  4825. }
  4826. function createVertexShader(gl, code) {
  4827. return loadShader(gl, code, gl.VERTEX_SHADER);
  4828. }
  4829. function createFragmentShader(gl, code) {
  4830. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4831. }
  4832. function createProgram(gl, shaders) {
  4833. var program = gl.createProgram();
  4834. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4835. gl.attachShader(program, shaders[i]);
  4836. }
  4837. gl.linkProgram(program);
  4838. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4839. if (!linked) {
  4840. var errorMsg = gl.getProgramInfoLog(program);
  4841. throw new Error('Error during program linking: ' + errorMsg);
  4842. }
  4843. return program;
  4844. }
  4845. function createTexture(gl, image, textureId) {
  4846. gl.activeTexture(textureId);
  4847. var texture = gl.createTexture();
  4848. gl.bindTexture(gl.TEXTURE_2D, texture);
  4849. // Set the parameters so we can render any size image.
  4850. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4851. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4852. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4853. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4854. // Upload the image into the texture.
  4855. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4856. return texture;
  4857. }
  4858. var currentGL, currentCanvas;
  4859. function generateGL() {
  4860. if (currentGL) {
  4861. return;
  4862. }
  4863. currentCanvas = document.createElement('canvas');
  4864. currentGL = currentCanvas.getContext('webgl',
  4865. { premultipliedalpha: false });
  4866. }
  4867. var smaskVertexShaderCode = '\
  4868. attribute vec2 a_position; \
  4869. attribute vec2 a_texCoord; \
  4870. \
  4871. uniform vec2 u_resolution; \
  4872. \
  4873. varying vec2 v_texCoord; \
  4874. \
  4875. void main() { \
  4876. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4877. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4878. \
  4879. v_texCoord = a_texCoord; \
  4880. } ';
  4881. var smaskFragmentShaderCode = '\
  4882. precision mediump float; \
  4883. \
  4884. uniform vec4 u_backdrop; \
  4885. uniform int u_subtype; \
  4886. uniform sampler2D u_image; \
  4887. uniform sampler2D u_mask; \
  4888. \
  4889. varying vec2 v_texCoord; \
  4890. \
  4891. void main() { \
  4892. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4893. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4894. if (u_backdrop.a > 0.0) { \
  4895. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4896. u_backdrop.rgb * (1.0 - maskColor.a); \
  4897. } \
  4898. float lum; \
  4899. if (u_subtype == 0) { \
  4900. lum = maskColor.a; \
  4901. } else { \
  4902. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4903. maskColor.b * 0.11; \
  4904. } \
  4905. imageColor.a *= lum; \
  4906. imageColor.rgb *= imageColor.a; \
  4907. gl_FragColor = imageColor; \
  4908. } ';
  4909. var smaskCache = null;
  4910. function initSmaskGL() {
  4911. var canvas, gl;
  4912. generateGL();
  4913. canvas = currentCanvas;
  4914. currentCanvas = null;
  4915. gl = currentGL;
  4916. currentGL = null;
  4917. // setup a GLSL program
  4918. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4919. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4920. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4921. gl.useProgram(program);
  4922. var cache = {};
  4923. cache.gl = gl;
  4924. cache.canvas = canvas;
  4925. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4926. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4927. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4928. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4929. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4930. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4931. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4932. // provide texture coordinates for the rectangle.
  4933. var texCoordBuffer = gl.createBuffer();
  4934. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4935. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4936. 0.0, 0.0,
  4937. 1.0, 0.0,
  4938. 0.0, 1.0,
  4939. 0.0, 1.0,
  4940. 1.0, 0.0,
  4941. 1.0, 1.0]), gl.STATIC_DRAW);
  4942. gl.enableVertexAttribArray(texCoordLocation);
  4943. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4944. gl.uniform1i(texLayerLocation, 0);
  4945. gl.uniform1i(texMaskLocation, 1);
  4946. smaskCache = cache;
  4947. }
  4948. function composeSMask(layer, mask, properties) {
  4949. var width = layer.width, height = layer.height;
  4950. if (!smaskCache) {
  4951. initSmaskGL();
  4952. }
  4953. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4954. canvas.width = width;
  4955. canvas.height = height;
  4956. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4957. gl.uniform2f(cache.resolutionLocation, width, height);
  4958. if (properties.backdrop) {
  4959. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4960. properties.backdrop[1], properties.backdrop[2], 1);
  4961. } else {
  4962. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4963. }
  4964. gl.uniform1i(cache.subtypeLocation,
  4965. properties.subtype === 'Luminosity' ? 1 : 0);
  4966. // Create a textures
  4967. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4968. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4969. // Create a buffer and put a single clipspace rectangle in
  4970. // it (2 triangles)
  4971. var buffer = gl.createBuffer();
  4972. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4973. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4974. 0, 0,
  4975. width, 0,
  4976. 0, height,
  4977. 0, height,
  4978. width, 0,
  4979. width, height]), gl.STATIC_DRAW);
  4980. gl.enableVertexAttribArray(cache.positionLocation);
  4981. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4982. // draw
  4983. gl.clearColor(0, 0, 0, 0);
  4984. gl.enable(gl.BLEND);
  4985. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4986. gl.clear(gl.COLOR_BUFFER_BIT);
  4987. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4988. gl.flush();
  4989. gl.deleteTexture(texture);
  4990. gl.deleteTexture(maskTexture);
  4991. gl.deleteBuffer(buffer);
  4992. return canvas;
  4993. }
  4994. var figuresVertexShaderCode = '\
  4995. attribute vec2 a_position; \
  4996. attribute vec3 a_color; \
  4997. \
  4998. uniform vec2 u_resolution; \
  4999. uniform vec2 u_scale; \
  5000. uniform vec2 u_offset; \
  5001. \
  5002. varying vec4 v_color; \
  5003. \
  5004. void main() { \
  5005. vec2 position = (a_position + u_offset) * u_scale; \
  5006. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5007. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5008. \
  5009. v_color = vec4(a_color / 255.0, 1.0); \
  5010. } ';
  5011. var figuresFragmentShaderCode = '\
  5012. precision mediump float; \
  5013. \
  5014. varying vec4 v_color; \
  5015. \
  5016. void main() { \
  5017. gl_FragColor = v_color; \
  5018. } ';
  5019. var figuresCache = null;
  5020. function initFiguresGL() {
  5021. var canvas, gl;
  5022. generateGL();
  5023. canvas = currentCanvas;
  5024. currentCanvas = null;
  5025. gl = currentGL;
  5026. currentGL = null;
  5027. // setup a GLSL program
  5028. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5029. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5030. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5031. gl.useProgram(program);
  5032. var cache = {};
  5033. cache.gl = gl;
  5034. cache.canvas = canvas;
  5035. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5036. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5037. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5038. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5039. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5040. figuresCache = cache;
  5041. }
  5042. function drawFigures(width, height, backgroundColor, figures, context) {
  5043. if (!figuresCache) {
  5044. initFiguresGL();
  5045. }
  5046. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5047. canvas.width = width;
  5048. canvas.height = height;
  5049. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5050. gl.uniform2f(cache.resolutionLocation, width, height);
  5051. // count triangle points
  5052. var count = 0;
  5053. var i, ii, rows;
  5054. for (i = 0, ii = figures.length; i < ii; i++) {
  5055. switch (figures[i].type) {
  5056. case 'lattice':
  5057. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5058. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5059. break;
  5060. case 'triangles':
  5061. count += figures[i].coords.length;
  5062. break;
  5063. }
  5064. }
  5065. // transfer data
  5066. var coords = new Float32Array(count * 2);
  5067. var colors = new Uint8Array(count * 3);
  5068. var coordsMap = context.coords, colorsMap = context.colors;
  5069. var pIndex = 0, cIndex = 0;
  5070. for (i = 0, ii = figures.length; i < ii; i++) {
  5071. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5072. switch (figure.type) {
  5073. case 'lattice':
  5074. var cols = figure.verticesPerRow;
  5075. rows = (ps.length / cols) | 0;
  5076. for (var row = 1; row < rows; row++) {
  5077. var offset = row * cols + 1;
  5078. for (var col = 1; col < cols; col++, offset++) {
  5079. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5080. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5081. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5082. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5083. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5084. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5085. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5086. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5087. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5088. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5089. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5090. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5091. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5092. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5093. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5094. coords[pIndex + 6] = coords[pIndex + 2];
  5095. coords[pIndex + 7] = coords[pIndex + 3];
  5096. coords[pIndex + 8] = coords[pIndex + 4];
  5097. coords[pIndex + 9] = coords[pIndex + 5];
  5098. coords[pIndex + 10] = coordsMap[ps[offset]];
  5099. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5100. colors[cIndex + 9] = colors[cIndex + 3];
  5101. colors[cIndex + 10] = colors[cIndex + 4];
  5102. colors[cIndex + 11] = colors[cIndex + 5];
  5103. colors[cIndex + 12] = colors[cIndex + 6];
  5104. colors[cIndex + 13] = colors[cIndex + 7];
  5105. colors[cIndex + 14] = colors[cIndex + 8];
  5106. colors[cIndex + 15] = colorsMap[cs[offset]];
  5107. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5108. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5109. pIndex += 12;
  5110. cIndex += 18;
  5111. }
  5112. }
  5113. break;
  5114. case 'triangles':
  5115. for (var j = 0, jj = ps.length; j < jj; j++) {
  5116. coords[pIndex] = coordsMap[ps[j]];
  5117. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5118. colors[cIndex] = colorsMap[cs[i]];
  5119. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5120. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5121. pIndex += 2;
  5122. cIndex += 3;
  5123. }
  5124. break;
  5125. }
  5126. }
  5127. // draw
  5128. if (backgroundColor) {
  5129. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5130. backgroundColor[2] / 255, 1.0);
  5131. } else {
  5132. gl.clearColor(0, 0, 0, 0);
  5133. }
  5134. gl.clear(gl.COLOR_BUFFER_BIT);
  5135. var coordsBuffer = gl.createBuffer();
  5136. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5137. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5138. gl.enableVertexAttribArray(cache.positionLocation);
  5139. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5140. var colorsBuffer = gl.createBuffer();
  5141. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5142. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5143. gl.enableVertexAttribArray(cache.colorLocation);
  5144. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5145. 0, 0);
  5146. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5147. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5148. gl.drawArrays(gl.TRIANGLES, 0, count);
  5149. gl.flush();
  5150. gl.deleteBuffer(coordsBuffer);
  5151. gl.deleteBuffer(colorsBuffer);
  5152. return canvas;
  5153. }
  5154. function cleanup() {
  5155. if (smaskCache && smaskCache.canvas) {
  5156. smaskCache.canvas.width = 0;
  5157. smaskCache.canvas.height = 0;
  5158. }
  5159. if (figuresCache && figuresCache.canvas) {
  5160. figuresCache.canvas.width = 0;
  5161. figuresCache.canvas.height = 0;
  5162. }
  5163. smaskCache = null;
  5164. figuresCache = null;
  5165. }
  5166. return {
  5167. get isEnabled() {
  5168. if (PDFJS.disableWebGL) {
  5169. return false;
  5170. }
  5171. var enabled = false;
  5172. try {
  5173. generateGL();
  5174. enabled = !!currentGL;
  5175. } catch (e) { }
  5176. return shadow(this, 'isEnabled', enabled);
  5177. },
  5178. composeSMask: composeSMask,
  5179. drawFigures: drawFigures,
  5180. clear: cleanup
  5181. };
  5182. })();
  5183. var ShadingIRs = {};
  5184. ShadingIRs.RadialAxial = {
  5185. fromIR: function RadialAxial_fromIR(raw) {
  5186. var type = raw[1];
  5187. var colorStops = raw[2];
  5188. var p0 = raw[3];
  5189. var p1 = raw[4];
  5190. var r0 = raw[5];
  5191. var r1 = raw[6];
  5192. return {
  5193. type: 'Pattern',
  5194. getPattern: function RadialAxial_getPattern(ctx) {
  5195. var grad;
  5196. if (type === 'axial') {
  5197. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5198. } else if (type === 'radial') {
  5199. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5200. }
  5201. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5202. var c = colorStops[i];
  5203. grad.addColorStop(c[0], c[1]);
  5204. }
  5205. return grad;
  5206. }
  5207. };
  5208. }
  5209. };
  5210. var createMeshCanvas = (function createMeshCanvasClosure() {
  5211. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5212. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5213. var coords = context.coords, colors = context.colors;
  5214. var bytes = data.data, rowSize = data.width * 4;
  5215. var tmp;
  5216. if (coords[p1 + 1] > coords[p2 + 1]) {
  5217. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5218. }
  5219. if (coords[p2 + 1] > coords[p3 + 1]) {
  5220. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5221. }
  5222. if (coords[p1 + 1] > coords[p2 + 1]) {
  5223. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5224. }
  5225. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5226. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5227. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5228. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5229. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5230. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5231. if (y1 >= y3) {
  5232. return;
  5233. }
  5234. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5235. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5236. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5237. var minY = Math.round(y1), maxY = Math.round(y3);
  5238. var xa, car, cag, cab;
  5239. var xb, cbr, cbg, cbb;
  5240. var k;
  5241. for (var y = minY; y <= maxY; y++) {
  5242. if (y < y2) {
  5243. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5244. xa = x1 - (x1 - x2) * k;
  5245. car = c1r - (c1r - c2r) * k;
  5246. cag = c1g - (c1g - c2g) * k;
  5247. cab = c1b - (c1b - c2b) * k;
  5248. } else {
  5249. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5250. xa = x2 - (x2 - x3) * k;
  5251. car = c2r - (c2r - c3r) * k;
  5252. cag = c2g - (c2g - c3g) * k;
  5253. cab = c2b - (c2b - c3b) * k;
  5254. }
  5255. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5256. xb = x1 - (x1 - x3) * k;
  5257. cbr = c1r - (c1r - c3r) * k;
  5258. cbg = c1g - (c1g - c3g) * k;
  5259. cbb = c1b - (c1b - c3b) * k;
  5260. var x1_ = Math.round(Math.min(xa, xb));
  5261. var x2_ = Math.round(Math.max(xa, xb));
  5262. var j = rowSize * y + x1_ * 4;
  5263. for (var x = x1_; x <= x2_; x++) {
  5264. k = (xa - x) / (xa - xb);
  5265. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5266. bytes[j++] = (car - (car - cbr) * k) | 0;
  5267. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5268. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5269. bytes[j++] = 255;
  5270. }
  5271. }
  5272. }
  5273. function drawFigure(data, figure, context) {
  5274. var ps = figure.coords;
  5275. var cs = figure.colors;
  5276. var i, ii;
  5277. switch (figure.type) {
  5278. case 'lattice':
  5279. var verticesPerRow = figure.verticesPerRow;
  5280. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5281. var cols = verticesPerRow - 1;
  5282. for (i = 0; i < rows; i++) {
  5283. var q = i * verticesPerRow;
  5284. for (var j = 0; j < cols; j++, q++) {
  5285. drawTriangle(data, context,
  5286. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5287. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5288. drawTriangle(data, context,
  5289. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5290. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5291. }
  5292. }
  5293. break;
  5294. case 'triangles':
  5295. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5296. drawTriangle(data, context,
  5297. ps[i], ps[i + 1], ps[i + 2],
  5298. cs[i], cs[i + 1], cs[i + 2]);
  5299. }
  5300. break;
  5301. default:
  5302. error('illigal figure');
  5303. break;
  5304. }
  5305. }
  5306. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5307. backgroundColor) {
  5308. // we will increase scale on some weird factor to let antialiasing take
  5309. // care of "rough" edges
  5310. var EXPECTED_SCALE = 1.1;
  5311. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5312. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5313. var offsetX = Math.floor(bounds[0]);
  5314. var offsetY = Math.floor(bounds[1]);
  5315. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5316. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5317. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5318. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5319. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5320. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5321. var scaleX = boundsWidth / width;
  5322. var scaleY = boundsHeight / height;
  5323. var context = {
  5324. coords: coords,
  5325. colors: colors,
  5326. offsetX: -offsetX,
  5327. offsetY: -offsetY,
  5328. scaleX: 1 / scaleX,
  5329. scaleY: 1 / scaleY
  5330. };
  5331. var canvas, tmpCanvas, i, ii;
  5332. if (WebGLUtils.isEnabled) {
  5333. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5334. figures, context);
  5335. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5336. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5337. tmpCanvas.context.drawImage(canvas, 0, 0);
  5338. canvas = tmpCanvas.canvas;
  5339. } else {
  5340. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5341. var tmpCtx = tmpCanvas.context;
  5342. var data = tmpCtx.createImageData(width, height);
  5343. if (backgroundColor) {
  5344. var bytes = data.data;
  5345. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5346. bytes[i] = backgroundColor[0];
  5347. bytes[i + 1] = backgroundColor[1];
  5348. bytes[i + 2] = backgroundColor[2];
  5349. bytes[i + 3] = 255;
  5350. }
  5351. }
  5352. for (i = 0; i < figures.length; i++) {
  5353. drawFigure(data, figures[i], context);
  5354. }
  5355. tmpCtx.putImageData(data, 0, 0);
  5356. canvas = tmpCanvas.canvas;
  5357. }
  5358. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5359. scaleX: scaleX, scaleY: scaleY};
  5360. }
  5361. return createMeshCanvas;
  5362. })();
  5363. ShadingIRs.Mesh = {
  5364. fromIR: function Mesh_fromIR(raw) {
  5365. //var type = raw[1];
  5366. var coords = raw[2];
  5367. var colors = raw[3];
  5368. var figures = raw[4];
  5369. var bounds = raw[5];
  5370. var matrix = raw[6];
  5371. //var bbox = raw[7];
  5372. var background = raw[8];
  5373. return {
  5374. type: 'Pattern',
  5375. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5376. var scale;
  5377. if (shadingFill) {
  5378. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5379. } else {
  5380. // Obtain scale from matrix and current transformation matrix.
  5381. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5382. if (matrix) {
  5383. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5384. scale = [scale[0] * matrixScale[0],
  5385. scale[1] * matrixScale[1]];
  5386. }
  5387. }
  5388. // Rasterizing on the main thread since sending/queue large canvases
  5389. // might cause OOM.
  5390. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5391. colors, figures, shadingFill ? null : background);
  5392. if (!shadingFill) {
  5393. ctx.setTransform.apply(ctx, owner.baseTransform);
  5394. if (matrix) {
  5395. ctx.transform.apply(ctx, matrix);
  5396. }
  5397. }
  5398. ctx.translate(temporaryPatternCanvas.offsetX,
  5399. temporaryPatternCanvas.offsetY);
  5400. ctx.scale(temporaryPatternCanvas.scaleX,
  5401. temporaryPatternCanvas.scaleY);
  5402. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5403. }
  5404. };
  5405. }
  5406. };
  5407. ShadingIRs.Dummy = {
  5408. fromIR: function Dummy_fromIR() {
  5409. return {
  5410. type: 'Pattern',
  5411. getPattern: function Dummy_fromIR_getPattern() {
  5412. return 'hotpink';
  5413. }
  5414. };
  5415. }
  5416. };
  5417. function getShadingPatternFromIR(raw) {
  5418. var shadingIR = ShadingIRs[raw[0]];
  5419. if (!shadingIR) {
  5420. error('Unknown IR type: ' + raw[0]);
  5421. }
  5422. return shadingIR.fromIR(raw);
  5423. }
  5424. var TilingPattern = (function TilingPatternClosure() {
  5425. var PaintType = {
  5426. COLORED: 1,
  5427. UNCOLORED: 2
  5428. };
  5429. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5430. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5431. this.operatorList = IR[2];
  5432. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5433. this.bbox = IR[4];
  5434. this.xstep = IR[5];
  5435. this.ystep = IR[6];
  5436. this.paintType = IR[7];
  5437. this.tilingType = IR[8];
  5438. this.color = color;
  5439. this.objs = objs;
  5440. this.commonObjs = commonObjs;
  5441. this.baseTransform = baseTransform;
  5442. this.type = 'Pattern';
  5443. this.ctx = ctx;
  5444. }
  5445. TilingPattern.prototype = {
  5446. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5447. var operatorList = this.operatorList;
  5448. var bbox = this.bbox;
  5449. var xstep = this.xstep;
  5450. var ystep = this.ystep;
  5451. var paintType = this.paintType;
  5452. var tilingType = this.tilingType;
  5453. var color = this.color;
  5454. var objs = this.objs;
  5455. var commonObjs = this.commonObjs;
  5456. info('TilingType: ' + tilingType);
  5457. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5458. var topLeft = [x0, y0];
  5459. // we want the canvas to be as large as the step size
  5460. var botRight = [x0 + xstep, y0 + ystep];
  5461. var width = botRight[0] - topLeft[0];
  5462. var height = botRight[1] - topLeft[1];
  5463. // Obtain scale from matrix and current transformation matrix.
  5464. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5465. var curMatrixScale = Util.singularValueDecompose2dScale(
  5466. this.baseTransform);
  5467. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5468. matrixScale[1] * curMatrixScale[1]];
  5469. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5470. // Use width and height values that are as close as possible to the end
  5471. // result when the pattern is used. Too low value makes the pattern look
  5472. // blurry. Too large value makes it look too crispy.
  5473. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5474. MAX_PATTERN_SIZE);
  5475. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5476. MAX_PATTERN_SIZE);
  5477. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5478. var tmpCtx = tmpCanvas.context;
  5479. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5480. graphics.groupLevel = owner.groupLevel;
  5481. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5482. this.setScale(width, height, xstep, ystep);
  5483. this.transformToScale(graphics);
  5484. // transform coordinates to pattern space
  5485. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5486. graphics.transform.apply(graphics, tmpTranslate);
  5487. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5488. graphics.executeOperatorList(operatorList);
  5489. return tmpCanvas.canvas;
  5490. },
  5491. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5492. this.scale = [width / xstep, height / ystep];
  5493. },
  5494. transformToScale: function TilingPattern_transformToScale(graphics) {
  5495. var scale = this.scale;
  5496. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5497. graphics.transform.apply(graphics, tmpScale);
  5498. },
  5499. scaleToContext: function TilingPattern_scaleToContext() {
  5500. var scale = this.scale;
  5501. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5502. },
  5503. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5504. if (bbox && isArray(bbox) && bbox.length === 4) {
  5505. var bboxWidth = x1 - x0;
  5506. var bboxHeight = y1 - y0;
  5507. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5508. graphics.clip();
  5509. graphics.endPath();
  5510. }
  5511. },
  5512. setFillAndStrokeStyleToContext:
  5513. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5514. switch (paintType) {
  5515. case PaintType.COLORED:
  5516. var ctx = this.ctx;
  5517. context.fillStyle = ctx.fillStyle;
  5518. context.strokeStyle = ctx.strokeStyle;
  5519. break;
  5520. case PaintType.UNCOLORED:
  5521. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5522. context.fillStyle = cssColor;
  5523. context.strokeStyle = cssColor;
  5524. break;
  5525. default:
  5526. error('Unsupported paint type: ' + paintType);
  5527. }
  5528. },
  5529. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5530. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5531. ctx = this.ctx;
  5532. ctx.setTransform.apply(ctx, this.baseTransform);
  5533. ctx.transform.apply(ctx, this.matrix);
  5534. this.scaleToContext();
  5535. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5536. }
  5537. };
  5538. return TilingPattern;
  5539. })();
  5540. PDFJS.disableFontFace = false;
  5541. var FontLoader = {
  5542. insertRule: function fontLoaderInsertRule(rule) {
  5543. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5544. if (!styleElement) {
  5545. styleElement = document.createElement('style');
  5546. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5547. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5548. styleElement);
  5549. }
  5550. var styleSheet = styleElement.sheet;
  5551. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5552. },
  5553. clear: function fontLoaderClear() {
  5554. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5555. if (styleElement) {
  5556. styleElement.parentNode.removeChild(styleElement);
  5557. }
  5558. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5559. document.fonts.delete(nativeFontFace);
  5560. });
  5561. this.nativeFontFaces.length = 0;
  5562. },
  5563. get loadTestFont() {
  5564. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5565. // height.
  5566. return shadow(this, 'loadTestFont', atob(
  5567. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5568. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5569. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5570. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5571. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5572. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5573. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5574. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5575. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5576. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5577. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5578. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5579. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5580. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5581. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5582. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5583. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5584. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5585. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5586. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5587. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5588. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5589. ));
  5590. },
  5591. loadTestFontId: 0,
  5592. loadingContext: {
  5593. requests: [],
  5594. nextRequestId: 0
  5595. },
  5596. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5597. if (isWorker) {
  5598. return false;
  5599. }
  5600. // User agent string sniffing is bad, but there is no reliable way to tell
  5601. // if font is fully loaded and ready to be used with canvas.
  5602. var userAgent = window.navigator.userAgent;
  5603. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5604. if (m && m[1] >= 14) {
  5605. return true;
  5606. }
  5607. // TODO other browsers
  5608. if (userAgent === 'node') {
  5609. return true;
  5610. }
  5611. return false;
  5612. })(),
  5613. nativeFontFaces: [],
  5614. isFontLoadingAPISupported: (!isWorker && typeof document !== 'undefined' &&
  5615. !!document.fonts),
  5616. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5617. this.nativeFontFaces.push(nativeFontFace);
  5618. document.fonts.add(nativeFontFace);
  5619. },
  5620. bind: function fontLoaderBind(fonts, callback) {
  5621. assert(!isWorker, 'bind() shall be called from main thread');
  5622. var rules = [];
  5623. var fontsToLoad = [];
  5624. var fontLoadPromises = [];
  5625. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5626. var font = fonts[i];
  5627. // Add the font to the DOM only once or skip if the font
  5628. // is already loaded.
  5629. if (font.attached || font.loading === false) {
  5630. continue;
  5631. }
  5632. font.attached = true;
  5633. if (this.isFontLoadingAPISupported) {
  5634. var nativeFontFace = font.createNativeFontFace();
  5635. if (nativeFontFace) {
  5636. fontLoadPromises.push(nativeFontFace.loaded);
  5637. }
  5638. } else {
  5639. var rule = font.bindDOM();
  5640. if (rule) {
  5641. rules.push(rule);
  5642. fontsToLoad.push(font);
  5643. }
  5644. }
  5645. }
  5646. var request = FontLoader.queueLoadingCallback(callback);
  5647. if (this.isFontLoadingAPISupported) {
  5648. Promise.all(fontsToLoad).then(function() {
  5649. request.complete();
  5650. });
  5651. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5652. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5653. } else {
  5654. request.complete();
  5655. }
  5656. },
  5657. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5658. function LoadLoader_completeRequest() {
  5659. assert(!request.end, 'completeRequest() cannot be called twice');
  5660. request.end = Date.now();
  5661. // sending all completed requests in order how they were queued
  5662. while (context.requests.length > 0 && context.requests[0].end) {
  5663. var otherRequest = context.requests.shift();
  5664. setTimeout(otherRequest.callback, 0);
  5665. }
  5666. }
  5667. var context = FontLoader.loadingContext;
  5668. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5669. var request = {
  5670. id: requestId,
  5671. complete: LoadLoader_completeRequest,
  5672. callback: callback,
  5673. started: Date.now()
  5674. };
  5675. context.requests.push(request);
  5676. return request;
  5677. },
  5678. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5679. fonts,
  5680. request) {
  5681. /** Hack begin */
  5682. // There's currently no event when a font has finished downloading so the
  5683. // following code is a dirty hack to 'guess' when a font is
  5684. // ready. It's assumed fonts are loaded in order, so add a known test
  5685. // font after the desired fonts and then test for the loading of that
  5686. // test font.
  5687. function int32(data, offset) {
  5688. return (data.charCodeAt(offset) << 24) |
  5689. (data.charCodeAt(offset + 1) << 16) |
  5690. (data.charCodeAt(offset + 2) << 8) |
  5691. (data.charCodeAt(offset + 3) & 0xff);
  5692. }
  5693. function spliceString(s, offset, remove, insert) {
  5694. var chunk1 = s.substr(0, offset);
  5695. var chunk2 = s.substr(offset + remove);
  5696. return chunk1 + insert + chunk2;
  5697. }
  5698. var i, ii;
  5699. var canvas = document.createElement('canvas');
  5700. canvas.width = 1;
  5701. canvas.height = 1;
  5702. var ctx = canvas.getContext('2d');
  5703. var called = 0;
  5704. function isFontReady(name, callback) {
  5705. called++;
  5706. // With setTimeout clamping this gives the font ~100ms to load.
  5707. if(called > 30) {
  5708. warn('Load test font never loaded.');
  5709. callback();
  5710. return;
  5711. }
  5712. ctx.font = '30px ' + name;
  5713. ctx.fillText('.', 0, 20);
  5714. var imageData = ctx.getImageData(0, 0, 1, 1);
  5715. if (imageData.data[3] > 0) {
  5716. callback();
  5717. return;
  5718. }
  5719. setTimeout(isFontReady.bind(null, name, callback));
  5720. }
  5721. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5722. // Chromium seems to cache fonts based on a hash of the actual font data,
  5723. // so the font must be modified for each load test else it will appear to
  5724. // be loaded already.
  5725. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5726. // font by splitting it in chunks before hand and padding the font id.
  5727. var data = this.loadTestFont;
  5728. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5729. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5730. loadTestFontId);
  5731. // CFF checksum is important for IE, adjusting it
  5732. var CFF_CHECKSUM_OFFSET = 16;
  5733. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5734. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5735. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5736. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5737. }
  5738. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5739. checksum = (checksum - XXXX_VALUE +
  5740. int32(loadTestFontId + 'XXX', i)) | 0;
  5741. }
  5742. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5743. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5744. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5745. url + '}';
  5746. FontLoader.insertRule(rule);
  5747. var names = [];
  5748. for (i = 0, ii = fonts.length; i < ii; i++) {
  5749. names.push(fonts[i].loadedName);
  5750. }
  5751. names.push(loadTestFontId);
  5752. var div = document.createElement('div');
  5753. div.setAttribute('style',
  5754. 'visibility: hidden;' +
  5755. 'width: 10px; height: 10px;' +
  5756. 'position: absolute; top: 0px; left: 0px;');
  5757. for (i = 0, ii = names.length; i < ii; ++i) {
  5758. var span = document.createElement('span');
  5759. span.textContent = 'Hi';
  5760. span.style.fontFamily = names[i];
  5761. div.appendChild(span);
  5762. }
  5763. document.body.appendChild(div);
  5764. isFontReady(loadTestFontId, function() {
  5765. document.body.removeChild(div);
  5766. request.complete();
  5767. });
  5768. /** Hack end */
  5769. }
  5770. };
  5771. var FontFaceObject = (function FontFaceObjectClosure() {
  5772. function FontFaceObject(name, file, properties) {
  5773. this.compiledGlyphs = {};
  5774. if (arguments.length === 1) {
  5775. // importing translated data
  5776. var data = arguments[0];
  5777. for (var i in data) {
  5778. this[i] = data[i];
  5779. }
  5780. return;
  5781. }
  5782. }
  5783. FontFaceObject.prototype = {
  5784. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5785. if (!this.data) {
  5786. return null;
  5787. }
  5788. if (PDFJS.disableFontFace) {
  5789. this.disableFontFace = true;
  5790. return null;
  5791. }
  5792. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5793. FontLoader.addNativeFontFace(nativeFontFace);
  5794. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5795. globalScope['FontInspector'].enabled) {
  5796. globalScope['FontInspector'].fontAdded(this);
  5797. }
  5798. return nativeFontFace;
  5799. },
  5800. bindDOM: function FontFaceObject_bindDOM() {
  5801. if (!this.data) {
  5802. return null;
  5803. }
  5804. if (PDFJS.disableFontFace) {
  5805. this.disableFontFace = true;
  5806. return null;
  5807. }
  5808. var data = bytesToString(new Uint8Array(this.data));
  5809. var fontName = this.loadedName;
  5810. // Add the font-face rule to the document
  5811. var url = ('url(data:' + this.mimetype + ';base64,' +
  5812. window.btoa(data) + ');');
  5813. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5814. FontLoader.insertRule(rule);
  5815. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5816. globalScope['FontInspector'].enabled) {
  5817. globalScope['FontInspector'].fontAdded(this, url);
  5818. }
  5819. return rule;
  5820. },
  5821. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5822. if (!(character in this.compiledGlyphs)) {
  5823. var js = objs.get(this.loadedName + '_path_' + character);
  5824. /*jshint -W054 */
  5825. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5826. }
  5827. return this.compiledGlyphs[character];
  5828. }
  5829. };
  5830. return FontFaceObject;
  5831. })();
  5832. var ANNOT_MIN_SIZE = 10; // px
  5833. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5834. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5835. function setTextStyles(element, item, fontObj) {
  5836. var style = element.style;
  5837. style.fontSize = item.fontSize + 'px';
  5838. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5839. if (!fontObj) {
  5840. return;
  5841. }
  5842. style.fontWeight = fontObj.black ?
  5843. (fontObj.bold ? 'bolder' : 'bold') :
  5844. (fontObj.bold ? 'bold' : 'normal');
  5845. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5846. var fontName = fontObj.loadedName;
  5847. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5848. // Use a reasonable default font if the font doesn't specify a fallback
  5849. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5850. style.fontFamily = fontFamily + fallbackName;
  5851. }
  5852. function initContainer(item, drawBorder) {
  5853. var container = document.createElement('section');
  5854. var cstyle = container.style;
  5855. var width = item.rect[2] - item.rect[0];
  5856. var height = item.rect[3] - item.rect[1];
  5857. var bWidth = item.borderWidth || 0;
  5858. if (bWidth) {
  5859. width = width - 2 * bWidth;
  5860. height = height - 2 * bWidth;
  5861. cstyle.borderWidth = bWidth + 'px';
  5862. var color = item.color;
  5863. if (drawBorder && color) {
  5864. cstyle.borderStyle = 'solid';
  5865. cstyle.borderColor = Util.makeCssRgb(Math.round(color[0] * 255),
  5866. Math.round(color[1] * 255),
  5867. Math.round(color[2] * 255));
  5868. }
  5869. }
  5870. cstyle.width = width + 'px';
  5871. cstyle.height = height + 'px';
  5872. return container;
  5873. }
  5874. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5875. var element = document.createElement('div');
  5876. var width = item.rect[2] - item.rect[0];
  5877. var height = item.rect[3] - item.rect[1];
  5878. element.style.width = width + 'px';
  5879. element.style.height = height + 'px';
  5880. element.style.display = 'table';
  5881. var content = document.createElement('div');
  5882. content.textContent = item.fieldValue;
  5883. var textAlignment = item.textAlignment;
  5884. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5885. content.style.verticalAlign = 'middle';
  5886. content.style.display = 'table-cell';
  5887. var fontObj = item.fontRefName ?
  5888. commonObjs.getData(item.fontRefName) : null;
  5889. setTextStyles(content, item, fontObj);
  5890. element.appendChild(content);
  5891. return element;
  5892. }
  5893. function getHtmlElementForTextAnnotation(item) {
  5894. var rect = item.rect;
  5895. // sanity check because of OOo-generated PDFs
  5896. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5897. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5898. }
  5899. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5900. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5901. }
  5902. var container = initContainer(item, false);
  5903. container.className = 'annotText';
  5904. var image = document.createElement('img');
  5905. image.style.height = container.style.height;
  5906. image.style.width = container.style.width;
  5907. var iconName = item.name;
  5908. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5909. iconName.toLowerCase() + '.svg';
  5910. image.alt = '[{{type}} Annotation]';
  5911. image.dataset.l10nId = 'text_annotation_type';
  5912. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5913. var contentWrapper = document.createElement('div');
  5914. contentWrapper.className = 'annotTextContentWrapper';
  5915. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5916. contentWrapper.style.top = '-10px';
  5917. var content = document.createElement('div');
  5918. content.className = 'annotTextContent';
  5919. content.setAttribute('hidden', true);
  5920. var i, ii;
  5921. if (item.hasBgColor) {
  5922. var color = item.color;
  5923. // Enlighten the color (70%)
  5924. var BACKGROUND_ENLIGHT = 0.7;
  5925. var r = BACKGROUND_ENLIGHT * (1.0 - color[0]) + color[0];
  5926. var g = BACKGROUND_ENLIGHT * (1.0 - color[1]) + color[1];
  5927. var b = BACKGROUND_ENLIGHT * (1.0 - color[2]) + color[2];
  5928. content.style.backgroundColor = Util.makeCssRgb((r * 255) | 0,
  5929. (g * 255) | 0,
  5930. (b * 255) | 0);
  5931. }
  5932. var title = document.createElement('h1');
  5933. var text = document.createElement('p');
  5934. title.textContent = item.title;
  5935. if (!item.content && !item.title) {
  5936. content.setAttribute('hidden', true);
  5937. } else {
  5938. var e = document.createElement('span');
  5939. var lines = item.content.split(/(?:\r\n?|\n)/);
  5940. for (i = 0, ii = lines.length; i < ii; ++i) {
  5941. var line = lines[i];
  5942. e.appendChild(document.createTextNode(line));
  5943. if (i < (ii - 1)) {
  5944. e.appendChild(document.createElement('br'));
  5945. }
  5946. }
  5947. text.appendChild(e);
  5948. var pinned = false;
  5949. var showAnnotation = function showAnnotation(pin) {
  5950. if (pin) {
  5951. pinned = true;
  5952. }
  5953. if (content.hasAttribute('hidden')) {
  5954. container.style.zIndex += 1;
  5955. content.removeAttribute('hidden');
  5956. }
  5957. };
  5958. var hideAnnotation = function hideAnnotation(unpin) {
  5959. if (unpin) {
  5960. pinned = false;
  5961. }
  5962. if (!content.hasAttribute('hidden') && !pinned) {
  5963. container.style.zIndex -= 1;
  5964. content.setAttribute('hidden', true);
  5965. }
  5966. };
  5967. var toggleAnnotation = function toggleAnnotation() {
  5968. if (pinned) {
  5969. hideAnnotation(true);
  5970. } else {
  5971. showAnnotation(true);
  5972. }
  5973. };
  5974. image.addEventListener('click', function image_clickHandler() {
  5975. toggleAnnotation();
  5976. }, false);
  5977. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5978. showAnnotation();
  5979. }, false);
  5980. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5981. hideAnnotation();
  5982. }, false);
  5983. content.addEventListener('click', function content_clickHandler() {
  5984. hideAnnotation(true);
  5985. }, false);
  5986. }
  5987. content.appendChild(title);
  5988. content.appendChild(text);
  5989. contentWrapper.appendChild(content);
  5990. container.appendChild(image);
  5991. container.appendChild(contentWrapper);
  5992. return container;
  5993. }
  5994. function getHtmlElementForLinkAnnotation(item) {
  5995. var container = initContainer(item, true);
  5996. container.className = 'annotLink';
  5997. var link = document.createElement('a');
  5998. link.href = link.title = item.url || '';
  5999. if (item.url && PDFJS.openExternalLinksInNewWindow) {
  6000. link.target = '_blank';
  6001. }
  6002. container.appendChild(link);
  6003. return container;
  6004. }
  6005. function getHtmlElement(data, objs) {
  6006. switch (data.annotationType) {
  6007. case AnnotationType.WIDGET:
  6008. return getHtmlElementForTextWidgetAnnotation(data, objs);
  6009. case AnnotationType.TEXT:
  6010. return getHtmlElementForTextAnnotation(data);
  6011. case AnnotationType.LINK:
  6012. return getHtmlElementForLinkAnnotation(data);
  6013. default:
  6014. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6015. }
  6016. }
  6017. return {
  6018. getHtmlElement: getHtmlElement
  6019. };
  6020. })();
  6021. PDFJS.AnnotationUtils = AnnotationUtils;
  6022. var SVG_DEFAULTS = {
  6023. fontStyle: 'normal',
  6024. fontWeight: 'normal',
  6025. fillColor: '#000000'
  6026. };
  6027. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6028. var PNG_HEADER =
  6029. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6030. var CHUNK_WRAPPER_SIZE = 12;
  6031. var crcTable = new Int32Array(256);
  6032. for (var i = 0; i < 256; i++) {
  6033. var c = i;
  6034. for (var h = 0; h < 8; h++) {
  6035. if (c & 1) {
  6036. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6037. } else {
  6038. c = (c >> 1) & 0x7fffffff;
  6039. }
  6040. }
  6041. crcTable[i] = c;
  6042. }
  6043. function crc32(data, start, end) {
  6044. var crc = -1;
  6045. for (var i = start; i < end; i++) {
  6046. var a = (crc ^ data[i]) & 0xff;
  6047. var b = crcTable[a];
  6048. crc = (crc >>> 8) ^ b;
  6049. }
  6050. return crc ^ -1;
  6051. }
  6052. function writePngChunk(type, body, data, offset) {
  6053. var p = offset;
  6054. var len = body.length;
  6055. data[p] = len >> 24 & 0xff;
  6056. data[p + 1] = len >> 16 & 0xff;
  6057. data[p + 2] = len >> 8 & 0xff;
  6058. data[p + 3] = len & 0xff;
  6059. p += 4;
  6060. data[p] = type.charCodeAt(0) & 0xff;
  6061. data[p + 1] = type.charCodeAt(1) & 0xff;
  6062. data[p + 2] = type.charCodeAt(2) & 0xff;
  6063. data[p + 3] = type.charCodeAt(3) & 0xff;
  6064. p += 4;
  6065. data.set(body, p);
  6066. p += body.length;
  6067. var crc = crc32(data, offset + 4, p);
  6068. data[p] = crc >> 24 & 0xff;
  6069. data[p + 1] = crc >> 16 & 0xff;
  6070. data[p + 2] = crc >> 8 & 0xff;
  6071. data[p + 3] = crc & 0xff;
  6072. }
  6073. function adler32(data, start, end) {
  6074. var a = 1;
  6075. var b = 0;
  6076. for (var i = start; i < end; ++i) {
  6077. a = (a + (data[i] & 0xff)) % 65521;
  6078. b = (b + a) % 65521;
  6079. }
  6080. return (b << 16) | a;
  6081. }
  6082. function encode(imgData, kind) {
  6083. var width = imgData.width;
  6084. var height = imgData.height;
  6085. var bitDepth, colorType, lineSize;
  6086. var bytes = imgData.data;
  6087. switch (kind) {
  6088. case ImageKind.GRAYSCALE_1BPP:
  6089. colorType = 0;
  6090. bitDepth = 1;
  6091. lineSize = (width + 7) >> 3;
  6092. break;
  6093. case ImageKind.RGB_24BPP:
  6094. colorType = 2;
  6095. bitDepth = 8;
  6096. lineSize = width * 3;
  6097. break;
  6098. case ImageKind.RGBA_32BPP:
  6099. colorType = 6;
  6100. bitDepth = 8;
  6101. lineSize = width * 4;
  6102. break;
  6103. default:
  6104. throw new Error('invalid format');
  6105. }
  6106. // prefix every row with predictor 0
  6107. var literals = new Uint8Array((1 + lineSize) * height);
  6108. var offsetLiterals = 0, offsetBytes = 0;
  6109. var y, i;
  6110. for (y = 0; y < height; ++y) {
  6111. literals[offsetLiterals++] = 0; // no prediction
  6112. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6113. offsetLiterals);
  6114. offsetBytes += lineSize;
  6115. offsetLiterals += lineSize;
  6116. }
  6117. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6118. // inverting for B/W
  6119. offsetLiterals = 0;
  6120. for (y = 0; y < height; y++) {
  6121. offsetLiterals++; // skipping predictor
  6122. for (i = 0; i < lineSize; i++) {
  6123. literals[offsetLiterals++] ^= 0xFF;
  6124. }
  6125. }
  6126. }
  6127. var ihdr = new Uint8Array([
  6128. width >> 24 & 0xff,
  6129. width >> 16 & 0xff,
  6130. width >> 8 & 0xff,
  6131. width & 0xff,
  6132. height >> 24 & 0xff,
  6133. height >> 16 & 0xff,
  6134. height >> 8 & 0xff,
  6135. height & 0xff,
  6136. bitDepth, // bit depth
  6137. colorType, // color type
  6138. 0x00, // compression method
  6139. 0x00, // filter method
  6140. 0x00 // interlace method
  6141. ]);
  6142. var len = literals.length;
  6143. var maxBlockLength = 0xFFFF;
  6144. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6145. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6146. var pi = 0;
  6147. idat[pi++] = 0x78; // compression method and flags
  6148. idat[pi++] = 0x9c; // flags
  6149. var pos = 0;
  6150. while (len > maxBlockLength) {
  6151. // writing non-final DEFLATE blocks type 0 and length of 65535
  6152. idat[pi++] = 0x00;
  6153. idat[pi++] = 0xff;
  6154. idat[pi++] = 0xff;
  6155. idat[pi++] = 0x00;
  6156. idat[pi++] = 0x00;
  6157. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6158. pi += maxBlockLength;
  6159. pos += maxBlockLength;
  6160. len -= maxBlockLength;
  6161. }
  6162. // writing non-final DEFLATE blocks type 0
  6163. idat[pi++] = 0x01;
  6164. idat[pi++] = len & 0xff;
  6165. idat[pi++] = len >> 8 & 0xff;
  6166. idat[pi++] = (~len & 0xffff) & 0xff;
  6167. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6168. idat.set(literals.subarray(pos), pi);
  6169. pi += literals.length - pos;
  6170. var adler = adler32(literals, 0, literals.length); // checksum
  6171. idat[pi++] = adler >> 24 & 0xff;
  6172. idat[pi++] = adler >> 16 & 0xff;
  6173. idat[pi++] = adler >> 8 & 0xff;
  6174. idat[pi++] = adler & 0xff;
  6175. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6176. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6177. ihdr.length + idat.length;
  6178. var data = new Uint8Array(pngLength);
  6179. var offset = 0;
  6180. data.set(PNG_HEADER, offset);
  6181. offset += PNG_HEADER.length;
  6182. writePngChunk('IHDR', ihdr, data, offset);
  6183. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6184. writePngChunk('IDATA', idat, data, offset);
  6185. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6186. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6187. return PDFJS.createObjectURL(data, 'image/png');
  6188. }
  6189. return function convertImgDataToPng(imgData) {
  6190. var kind = (imgData.kind === undefined ?
  6191. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6192. return encode(imgData, kind);
  6193. };
  6194. })();
  6195. var SVGExtraState = (function SVGExtraStateClosure() {
  6196. function SVGExtraState() {
  6197. this.fontSizeScale = 1;
  6198. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6199. this.fontSize = 0;
  6200. this.textMatrix = IDENTITY_MATRIX;
  6201. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6202. this.leading = 0;
  6203. // Current point (in user coordinates)
  6204. this.x = 0;
  6205. this.y = 0;
  6206. // Start of text line (in text coordinates)
  6207. this.lineX = 0;
  6208. this.lineY = 0;
  6209. // Character and word spacing
  6210. this.charSpacing = 0;
  6211. this.wordSpacing = 0;
  6212. this.textHScale = 1;
  6213. this.textRise = 0;
  6214. // Default foreground and background colors
  6215. this.fillColor = SVG_DEFAULTS.fillColor;
  6216. this.strokeColor = '#000000';
  6217. this.fillAlpha = 1;
  6218. this.strokeAlpha = 1;
  6219. this.lineWidth = 1;
  6220. this.lineJoin = '';
  6221. this.lineCap = '';
  6222. this.miterLimit = 0;
  6223. this.dashArray = [];
  6224. this.dashPhase = 0;
  6225. this.dependencies = [];
  6226. // Clipping
  6227. this.clipId = '';
  6228. this.pendingClip = false;
  6229. this.maskId = '';
  6230. }
  6231. SVGExtraState.prototype = {
  6232. clone: function SVGExtraState_clone() {
  6233. return Object.create(this);
  6234. },
  6235. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6236. this.x = x;
  6237. this.y = y;
  6238. }
  6239. };
  6240. return SVGExtraState;
  6241. })();
  6242. var SVGGraphics = (function SVGGraphicsClosure() {
  6243. function createScratchSVG(width, height) {
  6244. var NS = 'http://www.w3.org/2000/svg';
  6245. var svg = document.createElementNS(NS, 'svg:svg');
  6246. svg.setAttributeNS(null, 'version', '1.1');
  6247. svg.setAttributeNS(null, 'width', width + 'px');
  6248. svg.setAttributeNS(null, 'height', height + 'px');
  6249. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6250. return svg;
  6251. }
  6252. function opListToTree(opList) {
  6253. var opTree = [];
  6254. var tmp = [];
  6255. var opListLen = opList.length;
  6256. for (var x = 0; x < opListLen; x++) {
  6257. if (opList[x].fn === 'save') {
  6258. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6259. tmp.push(opTree);
  6260. opTree = opTree[opTree.length - 1].items;
  6261. continue;
  6262. }
  6263. if(opList[x].fn === 'restore') {
  6264. opTree = tmp.pop();
  6265. } else {
  6266. opTree.push(opList[x]);
  6267. }
  6268. }
  6269. return opTree;
  6270. }
  6271. /**
  6272. * Formats float number.
  6273. * @param value {number} number to format.
  6274. * @returns {string}
  6275. */
  6276. function pf(value) {
  6277. if (value === (value | 0)) { // integer number
  6278. return value.toString();
  6279. }
  6280. var s = value.toFixed(10);
  6281. var i = s.length - 1;
  6282. if (s[i] !== '0') {
  6283. return s;
  6284. }
  6285. // removing trailing zeros
  6286. do {
  6287. i--;
  6288. } while (s[i] === '0');
  6289. return s.substr(0, s[i] === '.' ? i : i + 1);
  6290. }
  6291. /**
  6292. * Formats transform matrix. The standard rotation, scale and translate
  6293. * matrices are replaced by their shorter forms, and for identity matrix
  6294. * returns empty string to save the memory.
  6295. * @param m {Array} matrix to format.
  6296. * @returns {string}
  6297. */
  6298. function pm(m) {
  6299. if (m[4] === 0 && m[5] === 0) {
  6300. if (m[1] === 0 && m[2] === 0) {
  6301. if (m[0] === 1 && m[3] === 1) {
  6302. return '';
  6303. }
  6304. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6305. }
  6306. if (m[0] === m[3] && m[1] === -m[2]) {
  6307. var a = Math.acos(m[0]) * 180 / Math.PI;
  6308. return 'rotate(' + pf(a) + ')';
  6309. }
  6310. } else {
  6311. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6312. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6313. }
  6314. }
  6315. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6316. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6317. }
  6318. function SVGGraphics(commonObjs, objs) {
  6319. this.current = new SVGExtraState();
  6320. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6321. this.transformStack = [];
  6322. this.extraStack = [];
  6323. this.commonObjs = commonObjs;
  6324. this.objs = objs;
  6325. this.pendingEOFill = false;
  6326. this.embedFonts = false;
  6327. this.embeddedFonts = {};
  6328. this.cssStyle = null;
  6329. }
  6330. var NS = 'http://www.w3.org/2000/svg';
  6331. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6332. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6333. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6334. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6335. var clipCount = 0;
  6336. var maskCount = 0;
  6337. SVGGraphics.prototype = {
  6338. save: function SVGGraphics_save() {
  6339. this.transformStack.push(this.transformMatrix);
  6340. var old = this.current;
  6341. this.extraStack.push(old);
  6342. this.current = old.clone();
  6343. },
  6344. restore: function SVGGraphics_restore() {
  6345. this.transformMatrix = this.transformStack.pop();
  6346. this.current = this.extraStack.pop();
  6347. this.tgrp = document.createElementNS(NS, 'svg:g');
  6348. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6349. this.pgrp.appendChild(this.tgrp);
  6350. },
  6351. group: function SVGGraphics_group(items) {
  6352. this.save();
  6353. this.executeOpTree(items);
  6354. this.restore();
  6355. },
  6356. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6357. var fnArray = operatorList.fnArray;
  6358. var fnArrayLen = fnArray.length;
  6359. var argsArray = operatorList.argsArray;
  6360. var self = this;
  6361. for (var i = 0; i < fnArrayLen; i++) {
  6362. if (OPS.dependency === fnArray[i]) {
  6363. var deps = argsArray[i];
  6364. for (var n = 0, nn = deps.length; n < nn; n++) {
  6365. var obj = deps[n];
  6366. var common = obj.substring(0, 2) === 'g_';
  6367. var promise;
  6368. if (common) {
  6369. promise = new Promise(function(resolve) {
  6370. self.commonObjs.get(obj, resolve);
  6371. });
  6372. } else {
  6373. promise = new Promise(function(resolve) {
  6374. self.objs.get(obj, resolve);
  6375. });
  6376. }
  6377. this.current.dependencies.push(promise);
  6378. }
  6379. }
  6380. }
  6381. return Promise.all(this.current.dependencies);
  6382. },
  6383. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6384. var transformMatrix = [a, b, c, d, e, f];
  6385. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6386. transformMatrix);
  6387. this.tgrp = document.createElementNS(NS, 'svg:g');
  6388. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6389. },
  6390. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6391. this.svg = createScratchSVG(viewport.width, viewport.height);
  6392. this.viewport = viewport;
  6393. return this.loadDependencies(operatorList).then(function () {
  6394. this.transformMatrix = IDENTITY_MATRIX;
  6395. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6396. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6397. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6398. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6399. this.defs = document.createElementNS(NS, 'svg:defs');
  6400. this.pgrp.appendChild(this.defs);
  6401. this.pgrp.appendChild(this.tgrp);
  6402. this.svg.appendChild(this.pgrp);
  6403. var opTree = this.convertOpList(operatorList);
  6404. this.executeOpTree(opTree);
  6405. return this.svg;
  6406. }.bind(this));
  6407. },
  6408. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6409. var argsArray = operatorList.argsArray;
  6410. var fnArray = operatorList.fnArray;
  6411. var fnArrayLen = fnArray.length;
  6412. var REVOPS = [];
  6413. var opList = [];
  6414. for (var op in OPS) {
  6415. REVOPS[OPS[op]] = op;
  6416. }
  6417. for (var x = 0; x < fnArrayLen; x++) {
  6418. var fnId = fnArray[x];
  6419. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6420. }
  6421. return opListToTree(opList);
  6422. },
  6423. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6424. var opTreeLen = opTree.length;
  6425. for(var x = 0; x < opTreeLen; x++) {
  6426. var fn = opTree[x].fn;
  6427. var fnId = opTree[x].fnId;
  6428. var args = opTree[x].args;
  6429. switch (fnId | 0) {
  6430. case OPS.beginText:
  6431. this.beginText();
  6432. break;
  6433. case OPS.setLeading:
  6434. this.setLeading(args);
  6435. break;
  6436. case OPS.setLeadingMoveText:
  6437. this.setLeadingMoveText(args[0], args[1]);
  6438. break;
  6439. case OPS.setFont:
  6440. this.setFont(args);
  6441. break;
  6442. case OPS.showText:
  6443. this.showText(args[0]);
  6444. break;
  6445. case OPS.showSpacedText:
  6446. this.showText(args[0]);
  6447. break;
  6448. case OPS.endText:
  6449. this.endText();
  6450. break;
  6451. case OPS.moveText:
  6452. this.moveText(args[0], args[1]);
  6453. break;
  6454. case OPS.setCharSpacing:
  6455. this.setCharSpacing(args[0]);
  6456. break;
  6457. case OPS.setWordSpacing:
  6458. this.setWordSpacing(args[0]);
  6459. break;
  6460. case OPS.setHScale:
  6461. this.setHScale(args[0]);
  6462. break;
  6463. case OPS.setTextMatrix:
  6464. this.setTextMatrix(args[0], args[1], args[2],
  6465. args[3], args[4], args[5]);
  6466. break;
  6467. case OPS.setLineWidth:
  6468. this.setLineWidth(args[0]);
  6469. break;
  6470. case OPS.setLineJoin:
  6471. this.setLineJoin(args[0]);
  6472. break;
  6473. case OPS.setLineCap:
  6474. this.setLineCap(args[0]);
  6475. break;
  6476. case OPS.setMiterLimit:
  6477. this.setMiterLimit(args[0]);
  6478. break;
  6479. case OPS.setFillRGBColor:
  6480. this.setFillRGBColor(args[0], args[1], args[2]);
  6481. break;
  6482. case OPS.setStrokeRGBColor:
  6483. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6484. break;
  6485. case OPS.setDash:
  6486. this.setDash(args[0], args[1]);
  6487. break;
  6488. case OPS.setGState:
  6489. this.setGState(args[0]);
  6490. break;
  6491. case OPS.fill:
  6492. this.fill();
  6493. break;
  6494. case OPS.eoFill:
  6495. this.eoFill();
  6496. break;
  6497. case OPS.stroke:
  6498. this.stroke();
  6499. break;
  6500. case OPS.fillStroke:
  6501. this.fillStroke();
  6502. break;
  6503. case OPS.eoFillStroke:
  6504. this.eoFillStroke();
  6505. break;
  6506. case OPS.clip:
  6507. this.clip('nonzero');
  6508. break;
  6509. case OPS.eoClip:
  6510. this.clip('evenodd');
  6511. break;
  6512. case OPS.paintSolidColorImageMask:
  6513. this.paintSolidColorImageMask();
  6514. break;
  6515. case OPS.paintJpegXObject:
  6516. this.paintJpegXObject(args[0], args[1], args[2]);
  6517. break;
  6518. case OPS.paintImageXObject:
  6519. this.paintImageXObject(args[0]);
  6520. break;
  6521. case OPS.paintInlineImageXObject:
  6522. this.paintInlineImageXObject(args[0]);
  6523. break;
  6524. case OPS.paintImageMaskXObject:
  6525. this.paintImageMaskXObject(args[0]);
  6526. break;
  6527. case OPS.paintFormXObjectBegin:
  6528. this.paintFormXObjectBegin(args[0], args[1]);
  6529. break;
  6530. case OPS.paintFormXObjectEnd:
  6531. this.paintFormXObjectEnd();
  6532. break;
  6533. case OPS.closePath:
  6534. this.closePath();
  6535. break;
  6536. case OPS.closeStroke:
  6537. this.closeStroke();
  6538. break;
  6539. case OPS.closeFillStroke:
  6540. this.closeFillStroke();
  6541. break;
  6542. case OPS.nextLine:
  6543. this.nextLine();
  6544. break;
  6545. case OPS.transform:
  6546. this.transform(args[0], args[1], args[2], args[3],
  6547. args[4], args[5]);
  6548. break;
  6549. case OPS.constructPath:
  6550. this.constructPath(args[0], args[1]);
  6551. break;
  6552. case OPS.endPath:
  6553. this.endPath();
  6554. break;
  6555. case 92:
  6556. this.group(opTree[x].items);
  6557. break;
  6558. default:
  6559. warn('Unimplemented method '+ fn);
  6560. break;
  6561. }
  6562. }
  6563. },
  6564. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6565. this.current.wordSpacing = wordSpacing;
  6566. },
  6567. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6568. this.current.charSpacing = charSpacing;
  6569. },
  6570. nextLine: function SVGGraphics_nextLine() {
  6571. this.moveText(0, this.current.leading);
  6572. },
  6573. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6574. var current = this.current;
  6575. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6576. this.current.x = this.current.lineX = 0;
  6577. this.current.y = this.current.lineY = 0;
  6578. current.xcoords = [];
  6579. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6580. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6581. current.tspan.setAttributeNS(null, 'font-size',
  6582. pf(current.fontSize) + 'px');
  6583. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6584. current.txtElement = document.createElementNS(NS, 'svg:text');
  6585. current.txtElement.appendChild(current.tspan);
  6586. },
  6587. beginText: function SVGGraphics_beginText() {
  6588. this.current.x = this.current.lineX = 0;
  6589. this.current.y = this.current.lineY = 0;
  6590. this.current.textMatrix = IDENTITY_MATRIX;
  6591. this.current.lineMatrix = IDENTITY_MATRIX;
  6592. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6593. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6594. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6595. this.current.xcoords = [];
  6596. },
  6597. moveText: function SVGGraphics_moveText(x, y) {
  6598. var current = this.current;
  6599. this.current.x = this.current.lineX += x;
  6600. this.current.y = this.current.lineY += y;
  6601. current.xcoords = [];
  6602. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6603. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6604. current.tspan.setAttributeNS(null, 'font-size',
  6605. pf(current.fontSize) + 'px');
  6606. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6607. },
  6608. showText: function SVGGraphics_showText(glyphs) {
  6609. var current = this.current;
  6610. var font = current.font;
  6611. var fontSize = current.fontSize;
  6612. if (fontSize === 0) {
  6613. return;
  6614. }
  6615. var charSpacing = current.charSpacing;
  6616. var wordSpacing = current.wordSpacing;
  6617. var fontDirection = current.fontDirection;
  6618. var textHScale = current.textHScale * fontDirection;
  6619. var glyphsLength = glyphs.length;
  6620. var vertical = font.vertical;
  6621. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6622. var x = 0, i;
  6623. for (i = 0; i < glyphsLength; ++i) {
  6624. var glyph = glyphs[i];
  6625. if (glyph === null) {
  6626. // word break
  6627. x += fontDirection * wordSpacing;
  6628. continue;
  6629. } else if (isNum(glyph)) {
  6630. x += -glyph * fontSize * 0.001;
  6631. continue;
  6632. }
  6633. current.xcoords.push(current.x + x * textHScale);
  6634. var width = glyph.width;
  6635. var character = glyph.fontChar;
  6636. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6637. x += charWidth;
  6638. current.tspan.textContent += character;
  6639. }
  6640. if (vertical) {
  6641. current.y -= x * textHScale;
  6642. } else {
  6643. current.x += x * textHScale;
  6644. }
  6645. current.tspan.setAttributeNS(null, 'x',
  6646. current.xcoords.map(pf).join(' '));
  6647. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6648. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6649. current.tspan.setAttributeNS(null, 'font-size',
  6650. pf(current.fontSize) + 'px');
  6651. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6652. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6653. }
  6654. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6655. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6656. }
  6657. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6658. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6659. }
  6660. current.txtElement.setAttributeNS(null, 'transform',
  6661. pm(current.textMatrix) +
  6662. ' scale(1, -1)' );
  6663. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6664. current.txtElement.appendChild(current.tspan);
  6665. current.txtgrp.appendChild(current.txtElement);
  6666. this.tgrp.appendChild(current.txtElement);
  6667. },
  6668. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6669. this.setLeading(-y);
  6670. this.moveText(x, y);
  6671. },
  6672. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6673. if (!this.cssStyle) {
  6674. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6675. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6676. this.defs.appendChild(this.cssStyle);
  6677. }
  6678. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6679. this.cssStyle.textContent +=
  6680. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6681. ' src: url(' + url + '); }\n';
  6682. },
  6683. setFont: function SVGGraphics_setFont(details) {
  6684. var current = this.current;
  6685. var fontObj = this.commonObjs.get(details[0]);
  6686. var size = details[1];
  6687. this.current.font = fontObj;
  6688. if (this.embedFonts && fontObj.data &&
  6689. !this.embeddedFonts[fontObj.loadedName]) {
  6690. this.addFontStyle(fontObj);
  6691. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6692. }
  6693. current.fontMatrix = (fontObj.fontMatrix ?
  6694. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6695. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6696. (fontObj.bold ? 'bold' : 'normal');
  6697. var italic = fontObj.italic ? 'italic' : 'normal';
  6698. if (size < 0) {
  6699. size = -size;
  6700. current.fontDirection = -1;
  6701. } else {
  6702. current.fontDirection = 1;
  6703. }
  6704. current.fontSize = size;
  6705. current.fontFamily = fontObj.loadedName;
  6706. current.fontWeight = bold;
  6707. current.fontStyle = italic;
  6708. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6709. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6710. current.xcoords = [];
  6711. },
  6712. endText: function SVGGraphics_endText() {
  6713. if (this.current.pendingClip) {
  6714. this.cgrp.appendChild(this.tgrp);
  6715. this.pgrp.appendChild(this.cgrp);
  6716. } else {
  6717. this.pgrp.appendChild(this.tgrp);
  6718. }
  6719. this.tgrp = document.createElementNS(NS, 'svg:g');
  6720. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6721. },
  6722. // Path properties
  6723. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6724. this.current.lineWidth = width;
  6725. },
  6726. setLineCap: function SVGGraphics_setLineCap(style) {
  6727. this.current.lineCap = LINE_CAP_STYLES[style];
  6728. },
  6729. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6730. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6731. },
  6732. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6733. this.current.miterLimit = limit;
  6734. },
  6735. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6736. var color = Util.makeCssRgb(r, g, b);
  6737. this.current.strokeColor = color;
  6738. },
  6739. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6740. var color = Util.makeCssRgb(r, g, b);
  6741. this.current.fillColor = color;
  6742. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6743. this.current.xcoords = [];
  6744. },
  6745. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6746. this.current.dashArray = dashArray;
  6747. this.current.dashPhase = dashPhase;
  6748. },
  6749. constructPath: function SVGGraphics_constructPath(ops, args) {
  6750. var current = this.current;
  6751. var x = current.x, y = current.y;
  6752. current.path = document.createElementNS(NS, 'svg:path');
  6753. var d = [];
  6754. var opLength = ops.length;
  6755. for (var i = 0, j = 0; i < opLength; i++) {
  6756. switch (ops[i] | 0) {
  6757. case OPS.rectangle:
  6758. x = args[j++];
  6759. y = args[j++];
  6760. var width = args[j++];
  6761. var height = args[j++];
  6762. var xw = x + width;
  6763. var yh = y + height;
  6764. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6765. 'L', pf(x), pf(yh), 'Z');
  6766. break;
  6767. case OPS.moveTo:
  6768. x = args[j++];
  6769. y = args[j++];
  6770. d.push('M', pf(x), pf(y));
  6771. break;
  6772. case OPS.lineTo:
  6773. x = args[j++];
  6774. y = args[j++];
  6775. d.push('L', pf(x) , pf(y));
  6776. break;
  6777. case OPS.curveTo:
  6778. x = args[j + 4];
  6779. y = args[j + 5];
  6780. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6781. pf(args[j + 3]), pf(x), pf(y));
  6782. j += 6;
  6783. break;
  6784. case OPS.curveTo2:
  6785. x = args[j + 2];
  6786. y = args[j + 3];
  6787. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6788. pf(args[j + 2]), pf(args[j + 3]));
  6789. j += 4;
  6790. break;
  6791. case OPS.curveTo3:
  6792. x = args[j + 2];
  6793. y = args[j + 3];
  6794. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6795. pf(x), pf(y));
  6796. j += 4;
  6797. break;
  6798. case OPS.closePath:
  6799. d.push('Z');
  6800. break;
  6801. }
  6802. }
  6803. current.path.setAttributeNS(null, 'd', d.join(' '));
  6804. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6805. pf(current.miterLimit));
  6806. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6807. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6808. current.path.setAttributeNS(null, 'stroke-width',
  6809. pf(current.lineWidth) + 'px');
  6810. current.path.setAttributeNS(null, 'stroke-dasharray',
  6811. current.dashArray.map(pf).join(' '));
  6812. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6813. pf(current.dashPhase) + 'px');
  6814. current.path.setAttributeNS(null, 'fill', 'none');
  6815. this.tgrp.appendChild(current.path);
  6816. if (current.pendingClip) {
  6817. this.cgrp.appendChild(this.tgrp);
  6818. this.pgrp.appendChild(this.cgrp);
  6819. } else {
  6820. this.pgrp.appendChild(this.tgrp);
  6821. }
  6822. // Saving a reference in current.element so that it can be addressed
  6823. // in 'fill' and 'stroke'
  6824. current.element = current.path;
  6825. current.setCurrentPoint(x, y);
  6826. },
  6827. endPath: function SVGGraphics_endPath() {
  6828. var current = this.current;
  6829. if (current.pendingClip) {
  6830. this.cgrp.appendChild(this.tgrp);
  6831. this.pgrp.appendChild(this.cgrp);
  6832. } else {
  6833. this.pgrp.appendChild(this.tgrp);
  6834. }
  6835. this.tgrp = document.createElementNS(NS, 'svg:g');
  6836. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6837. },
  6838. clip: function SVGGraphics_clip(type) {
  6839. var current = this.current;
  6840. // Add current path to clipping path
  6841. current.clipId = 'clippath' + clipCount;
  6842. clipCount++;
  6843. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6844. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6845. var clipElement = current.element.cloneNode();
  6846. if (type === 'evenodd') {
  6847. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6848. } else {
  6849. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6850. }
  6851. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6852. this.clippath.appendChild(clipElement);
  6853. this.defs.appendChild(this.clippath);
  6854. // Create a new group with that attribute
  6855. current.pendingClip = true;
  6856. this.cgrp = document.createElementNS(NS, 'svg:g');
  6857. this.cgrp.setAttributeNS(null, 'clip-path',
  6858. 'url(#' + current.clipId + ')');
  6859. this.pgrp.appendChild(this.cgrp);
  6860. },
  6861. closePath: function SVGGraphics_closePath() {
  6862. var current = this.current;
  6863. var d = current.path.getAttributeNS(null, 'd');
  6864. d += 'Z';
  6865. current.path.setAttributeNS(null, 'd', d);
  6866. },
  6867. setLeading: function SVGGraphics_setLeading(leading) {
  6868. this.current.leading = -leading;
  6869. },
  6870. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6871. this.current.textRise = textRise;
  6872. },
  6873. setHScale: function SVGGraphics_setHScale(scale) {
  6874. this.current.textHScale = scale / 100;
  6875. },
  6876. setGState: function SVGGraphics_setGState(states) {
  6877. for (var i = 0, ii = states.length; i < ii; i++) {
  6878. var state = states[i];
  6879. var key = state[0];
  6880. var value = state[1];
  6881. switch (key) {
  6882. case 'LW':
  6883. this.setLineWidth(value);
  6884. break;
  6885. case 'LC':
  6886. this.setLineCap(value);
  6887. break;
  6888. case 'LJ':
  6889. this.setLineJoin(value);
  6890. break;
  6891. case 'ML':
  6892. this.setMiterLimit(value);
  6893. break;
  6894. case 'D':
  6895. this.setDash(value[0], value[1]);
  6896. break;
  6897. case 'RI':
  6898. break;
  6899. case 'FL':
  6900. break;
  6901. case 'Font':
  6902. this.setFont(value);
  6903. break;
  6904. case 'CA':
  6905. break;
  6906. case 'ca':
  6907. break;
  6908. case 'BM':
  6909. break;
  6910. case 'SMask':
  6911. break;
  6912. }
  6913. }
  6914. },
  6915. fill: function SVGGraphics_fill() {
  6916. var current = this.current;
  6917. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6918. },
  6919. stroke: function SVGGraphics_stroke() {
  6920. var current = this.current;
  6921. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6922. current.element.setAttributeNS(null, 'fill', 'none');
  6923. },
  6924. eoFill: function SVGGraphics_eoFill() {
  6925. var current = this.current;
  6926. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6927. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6928. },
  6929. fillStroke: function SVGGraphics_fillStroke() {
  6930. // Order is important since stroke wants fill to be none.
  6931. // First stroke, then if fill needed, it will be overwritten.
  6932. this.stroke();
  6933. this.fill();
  6934. },
  6935. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6936. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6937. this.fillStroke();
  6938. },
  6939. closeStroke: function SVGGraphics_closeStroke() {
  6940. this.closePath();
  6941. this.stroke();
  6942. },
  6943. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6944. this.closePath();
  6945. this.fillStroke();
  6946. },
  6947. paintSolidColorImageMask:
  6948. function SVGGraphics_paintSolidColorImageMask() {
  6949. var current = this.current;
  6950. var rect = document.createElementNS(NS, 'svg:rect');
  6951. rect.setAttributeNS(null, 'x', '0');
  6952. rect.setAttributeNS(null, 'y', '0');
  6953. rect.setAttributeNS(null, 'width', '1px');
  6954. rect.setAttributeNS(null, 'height', '1px');
  6955. rect.setAttributeNS(null, 'fill', current.fillColor);
  6956. this.tgrp.appendChild(rect);
  6957. },
  6958. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6959. var current = this.current;
  6960. var imgObj = this.objs.get(objId);
  6961. var imgEl = document.createElementNS(NS, 'svg:image');
  6962. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6963. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6964. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6965. imgEl.setAttributeNS(null, 'x', '0');
  6966. imgEl.setAttributeNS(null, 'y', pf(-h));
  6967. imgEl.setAttributeNS(null, 'transform',
  6968. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6969. this.tgrp.appendChild(imgEl);
  6970. if (current.pendingClip) {
  6971. this.cgrp.appendChild(this.tgrp);
  6972. this.pgrp.appendChild(this.cgrp);
  6973. } else {
  6974. this.pgrp.appendChild(this.tgrp);
  6975. }
  6976. },
  6977. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6978. var imgData = this.objs.get(objId);
  6979. if (!imgData) {
  6980. warn('Dependent image isn\'t ready yet');
  6981. return;
  6982. }
  6983. this.paintInlineImageXObject(imgData);
  6984. },
  6985. paintInlineImageXObject:
  6986. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6987. var current = this.current;
  6988. var width = imgData.width;
  6989. var height = imgData.height;
  6990. var imgSrc = convertImgDataToPng(imgData);
  6991. var cliprect = document.createElementNS(NS, 'svg:rect');
  6992. cliprect.setAttributeNS(null, 'x', '0');
  6993. cliprect.setAttributeNS(null, 'y', '0');
  6994. cliprect.setAttributeNS(null, 'width', pf(width));
  6995. cliprect.setAttributeNS(null, 'height', pf(height));
  6996. current.element = cliprect;
  6997. this.clip('nonzero');
  6998. var imgEl = document.createElementNS(NS, 'svg:image');
  6999. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  7000. imgEl.setAttributeNS(null, 'x', '0');
  7001. imgEl.setAttributeNS(null, 'y', pf(-height));
  7002. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  7003. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  7004. imgEl.setAttributeNS(null, 'transform',
  7005. 'scale(' + pf(1 / width) + ' ' +
  7006. pf(-1 / height) + ')');
  7007. if (mask) {
  7008. mask.appendChild(imgEl);
  7009. } else {
  7010. this.tgrp.appendChild(imgEl);
  7011. }
  7012. if (current.pendingClip) {
  7013. this.cgrp.appendChild(this.tgrp);
  7014. this.pgrp.appendChild(this.cgrp);
  7015. } else {
  7016. this.pgrp.appendChild(this.tgrp);
  7017. }
  7018. },
  7019. paintImageMaskXObject:
  7020. function SVGGraphics_paintImageMaskXObject(imgData) {
  7021. var current = this.current;
  7022. var width = imgData.width;
  7023. var height = imgData.height;
  7024. var fillColor = current.fillColor;
  7025. current.maskId = 'mask' + maskCount++;
  7026. var mask = document.createElementNS(NS, 'svg:mask');
  7027. mask.setAttributeNS(null, 'id', current.maskId);
  7028. var rect = document.createElementNS(NS, 'svg:rect');
  7029. rect.setAttributeNS(null, 'x', '0');
  7030. rect.setAttributeNS(null, 'y', '0');
  7031. rect.setAttributeNS(null, 'width', pf(width));
  7032. rect.setAttributeNS(null, 'height', pf(height));
  7033. rect.setAttributeNS(null, 'fill', fillColor);
  7034. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7035. this.defs.appendChild(mask);
  7036. this.tgrp.appendChild(rect);
  7037. this.paintInlineImageXObject(imgData, mask);
  7038. },
  7039. paintFormXObjectBegin:
  7040. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7041. this.save();
  7042. if (isArray(matrix) && matrix.length === 6) {
  7043. this.transform(matrix[0], matrix[1], matrix[2],
  7044. matrix[3], matrix[4], matrix[5]);
  7045. }
  7046. if (isArray(bbox) && bbox.length === 4) {
  7047. var width = bbox[2] - bbox[0];
  7048. var height = bbox[3] - bbox[1];
  7049. var cliprect = document.createElementNS(NS, 'svg:rect');
  7050. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7051. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7052. cliprect.setAttributeNS(null, 'width', pf(width));
  7053. cliprect.setAttributeNS(null, 'height', pf(height));
  7054. this.current.element = cliprect;
  7055. this.clip('nonzero');
  7056. this.endPath();
  7057. }
  7058. },
  7059. paintFormXObjectEnd:
  7060. function SVGGraphics_paintFormXObjectEnd() {
  7061. this.restore();
  7062. }
  7063. };
  7064. return SVGGraphics;
  7065. })();
  7066. PDFJS.SVGGraphics = SVGGraphics;
  7067. var NetworkManager = (function NetworkManagerClosure() {
  7068. var OK_RESPONSE = 200;
  7069. var PARTIAL_CONTENT_RESPONSE = 206;
  7070. function NetworkManager(url, args) {
  7071. this.url = url;
  7072. args = args || {};
  7073. this.isHttp = /^https?:/i.test(url);
  7074. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7075. this.withCredentials = args.withCredentials || false;
  7076. this.getXhr = args.getXhr ||
  7077. function NetworkManager_getXhr() {
  7078. return new XMLHttpRequest();
  7079. };
  7080. this.currXhrId = 0;
  7081. this.pendingRequests = {};
  7082. this.loadedRequests = {};
  7083. }
  7084. function getArrayBuffer(xhr) {
  7085. var data = xhr.response;
  7086. if (typeof data !== 'string') {
  7087. return data;
  7088. }
  7089. var length = data.length;
  7090. var array = new Uint8Array(length);
  7091. for (var i = 0; i < length; i++) {
  7092. array[i] = data.charCodeAt(i) & 0xFF;
  7093. }
  7094. return array.buffer;
  7095. }
  7096. NetworkManager.prototype = {
  7097. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7098. var args = {
  7099. begin: begin,
  7100. end: end
  7101. };
  7102. for (var prop in listeners) {
  7103. args[prop] = listeners[prop];
  7104. }
  7105. return this.request(args);
  7106. },
  7107. requestFull: function NetworkManager_requestFull(listeners) {
  7108. return this.request(listeners);
  7109. },
  7110. request: function NetworkManager_request(args) {
  7111. var xhr = this.getXhr();
  7112. var xhrId = this.currXhrId++;
  7113. var pendingRequest = this.pendingRequests[xhrId] = {
  7114. xhr: xhr
  7115. };
  7116. xhr.open('GET', this.url);
  7117. xhr.withCredentials = this.withCredentials;
  7118. for (var property in this.httpHeaders) {
  7119. var value = this.httpHeaders[property];
  7120. if (typeof value === 'undefined') {
  7121. continue;
  7122. }
  7123. xhr.setRequestHeader(property, value);
  7124. }
  7125. if (this.isHttp && 'begin' in args && 'end' in args) {
  7126. var rangeStr = args.begin + '-' + (args.end - 1);
  7127. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7128. pendingRequest.expectedStatus = 206;
  7129. } else {
  7130. pendingRequest.expectedStatus = 200;
  7131. }
  7132. if (args.onProgressiveData) {
  7133. // Some legacy browsers might throw an exception.
  7134. try {
  7135. xhr.responseType = 'moz-chunked-arraybuffer';
  7136. } catch(e) {}
  7137. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  7138. pendingRequest.onProgressiveData = args.onProgressiveData;
  7139. pendingRequest.mozChunked = true;
  7140. } else {
  7141. xhr.responseType = 'arraybuffer';
  7142. }
  7143. } else {
  7144. xhr.responseType = 'arraybuffer';
  7145. }
  7146. if (args.onError) {
  7147. xhr.onerror = function(evt) {
  7148. args.onError(xhr.status);
  7149. };
  7150. }
  7151. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7152. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7153. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7154. pendingRequest.onDone = args.onDone;
  7155. pendingRequest.onError = args.onError;
  7156. pendingRequest.onProgress = args.onProgress;
  7157. xhr.send(null);
  7158. return xhrId;
  7159. },
  7160. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7161. var pendingRequest = this.pendingRequests[xhrId];
  7162. if (!pendingRequest) {
  7163. // Maybe abortRequest was called...
  7164. return;
  7165. }
  7166. if (pendingRequest.mozChunked) {
  7167. var chunk = getArrayBuffer(pendingRequest.xhr);
  7168. pendingRequest.onProgressiveData(chunk);
  7169. }
  7170. var onProgress = pendingRequest.onProgress;
  7171. if (onProgress) {
  7172. onProgress(evt);
  7173. }
  7174. },
  7175. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7176. var pendingRequest = this.pendingRequests[xhrId];
  7177. if (!pendingRequest) {
  7178. // Maybe abortRequest was called...
  7179. return;
  7180. }
  7181. var xhr = pendingRequest.xhr;
  7182. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7183. pendingRequest.onHeadersReceived();
  7184. delete pendingRequest.onHeadersReceived;
  7185. }
  7186. if (xhr.readyState !== 4) {
  7187. return;
  7188. }
  7189. if (!(xhrId in this.pendingRequests)) {
  7190. // The XHR request might have been aborted in onHeadersReceived()
  7191. // callback, in which case we should abort request
  7192. return;
  7193. }
  7194. delete this.pendingRequests[xhrId];
  7195. // success status == 0 can be on ftp, file and other protocols
  7196. if (xhr.status === 0 && this.isHttp) {
  7197. if (pendingRequest.onError) {
  7198. pendingRequest.onError(xhr.status);
  7199. }
  7200. return;
  7201. }
  7202. var xhrStatus = xhr.status || OK_RESPONSE;
  7203. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7204. // "A server MAY ignore the Range header". This means it's possible to
  7205. // get a 200 rather than a 206 response from a range request.
  7206. var ok_response_on_range_request =
  7207. xhrStatus === OK_RESPONSE &&
  7208. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7209. if (!ok_response_on_range_request &&
  7210. xhrStatus !== pendingRequest.expectedStatus) {
  7211. if (pendingRequest.onError) {
  7212. pendingRequest.onError(xhr.status);
  7213. }
  7214. return;
  7215. }
  7216. this.loadedRequests[xhrId] = true;
  7217. var chunk = getArrayBuffer(xhr);
  7218. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7219. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7220. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7221. var begin = parseInt(matches[1], 10);
  7222. pendingRequest.onDone({
  7223. begin: begin,
  7224. chunk: chunk
  7225. });
  7226. } else if (pendingRequest.onProgressiveData) {
  7227. pendingRequest.onDone(null);
  7228. } else {
  7229. pendingRequest.onDone({
  7230. begin: 0,
  7231. chunk: chunk
  7232. });
  7233. }
  7234. },
  7235. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7236. for (var xhrId in this.pendingRequests) {
  7237. return true;
  7238. }
  7239. return false;
  7240. },
  7241. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7242. return this.pendingRequests[xhrId].xhr;
  7243. },
  7244. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7245. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7246. },
  7247. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7248. return xhrId in this.pendingRequests;
  7249. },
  7250. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7251. return xhrId in this.loadedRequests;
  7252. },
  7253. abortAllRequests: function NetworkManager_abortAllRequests() {
  7254. for (var xhrId in this.pendingRequests) {
  7255. this.abortRequest(xhrId | 0);
  7256. }
  7257. },
  7258. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7259. var xhr = this.pendingRequests[xhrId].xhr;
  7260. delete this.pendingRequests[xhrId];
  7261. xhr.abort();
  7262. }
  7263. };
  7264. return NetworkManager;
  7265. })();
  7266. var ChunkedStream = (function ChunkedStreamClosure() {
  7267. function ChunkedStream(length, chunkSize, manager) {
  7268. this.bytes = new Uint8Array(length);
  7269. this.start = 0;
  7270. this.pos = 0;
  7271. this.end = length;
  7272. this.chunkSize = chunkSize;
  7273. this.loadedChunks = [];
  7274. this.numChunksLoaded = 0;
  7275. this.numChunks = Math.ceil(length / chunkSize);
  7276. this.manager = manager;
  7277. this.progressiveDataLength = 0;
  7278. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7279. }
  7280. // required methods for a stream. if a particular stream does not
  7281. // implement these, an error should be thrown
  7282. ChunkedStream.prototype = {
  7283. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7284. var chunks = [];
  7285. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7286. if (!this.loadedChunks[chunk]) {
  7287. chunks.push(chunk);
  7288. }
  7289. }
  7290. return chunks;
  7291. },
  7292. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7293. return [this];
  7294. },
  7295. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7296. return this.numChunksLoaded === this.numChunks;
  7297. },
  7298. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7299. var end = begin + chunk.byteLength;
  7300. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7301. // Using this.length is inaccurate here since this.start can be moved
  7302. // See ChunkedStream.moveStart()
  7303. var length = this.bytes.length;
  7304. assert(end % this.chunkSize === 0 || end === length,
  7305. 'Bad end offset: ' + end);
  7306. this.bytes.set(new Uint8Array(chunk), begin);
  7307. var chunkSize = this.chunkSize;
  7308. var beginChunk = Math.floor(begin / chunkSize);
  7309. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7310. var curChunk;
  7311. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7312. if (!this.loadedChunks[curChunk]) {
  7313. this.loadedChunks[curChunk] = true;
  7314. ++this.numChunksLoaded;
  7315. }
  7316. }
  7317. },
  7318. onReceiveProgressiveData:
  7319. function ChunkedStream_onReceiveProgressiveData(data) {
  7320. var position = this.progressiveDataLength;
  7321. var beginChunk = Math.floor(position / this.chunkSize);
  7322. this.bytes.set(new Uint8Array(data), position);
  7323. position += data.byteLength;
  7324. this.progressiveDataLength = position;
  7325. var endChunk = position >= this.end ? this.numChunks :
  7326. Math.floor(position / this.chunkSize);
  7327. var curChunk;
  7328. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7329. if (!this.loadedChunks[curChunk]) {
  7330. this.loadedChunks[curChunk] = true;
  7331. ++this.numChunksLoaded;
  7332. }
  7333. }
  7334. },
  7335. ensureByte: function ChunkedStream_ensureByte(pos) {
  7336. var chunk = Math.floor(pos / this.chunkSize);
  7337. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7338. return;
  7339. }
  7340. if (!this.loadedChunks[chunk]) {
  7341. throw new MissingDataException(pos, pos + 1);
  7342. }
  7343. this.lastSuccessfulEnsureByteChunk = chunk;
  7344. },
  7345. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7346. if (begin >= end) {
  7347. return;
  7348. }
  7349. if (end <= this.progressiveDataLength) {
  7350. return;
  7351. }
  7352. var chunkSize = this.chunkSize;
  7353. var beginChunk = Math.floor(begin / chunkSize);
  7354. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7355. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7356. if (!this.loadedChunks[chunk]) {
  7357. throw new MissingDataException(begin, end);
  7358. }
  7359. }
  7360. },
  7361. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7362. var chunk, n;
  7363. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7364. if (!this.loadedChunks[chunk]) {
  7365. return chunk;
  7366. }
  7367. }
  7368. // Wrap around to beginning
  7369. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7370. if (!this.loadedChunks[chunk]) {
  7371. return chunk;
  7372. }
  7373. }
  7374. return null;
  7375. },
  7376. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7377. return !!this.loadedChunks[chunk];
  7378. },
  7379. get length() {
  7380. return this.end - this.start;
  7381. },
  7382. get isEmpty() {
  7383. return this.length === 0;
  7384. },
  7385. getByte: function ChunkedStream_getByte() {
  7386. var pos = this.pos;
  7387. if (pos >= this.end) {
  7388. return -1;
  7389. }
  7390. this.ensureByte(pos);
  7391. return this.bytes[this.pos++];
  7392. },
  7393. getUint16: function ChunkedStream_getUint16() {
  7394. var b0 = this.getByte();
  7395. var b1 = this.getByte();
  7396. if (b0 === -1 || b1 === -1) {
  7397. return -1;
  7398. }
  7399. return (b0 << 8) + b1;
  7400. },
  7401. getInt32: function ChunkedStream_getInt32() {
  7402. var b0 = this.getByte();
  7403. var b1 = this.getByte();
  7404. var b2 = this.getByte();
  7405. var b3 = this.getByte();
  7406. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7407. },
  7408. // returns subarray of original buffer
  7409. // should only be read
  7410. getBytes: function ChunkedStream_getBytes(length) {
  7411. var bytes = this.bytes;
  7412. var pos = this.pos;
  7413. var strEnd = this.end;
  7414. if (!length) {
  7415. this.ensureRange(pos, strEnd);
  7416. return bytes.subarray(pos, strEnd);
  7417. }
  7418. var end = pos + length;
  7419. if (end > strEnd) {
  7420. end = strEnd;
  7421. }
  7422. this.ensureRange(pos, end);
  7423. this.pos = end;
  7424. return bytes.subarray(pos, end);
  7425. },
  7426. peekByte: function ChunkedStream_peekByte() {
  7427. var peekedByte = this.getByte();
  7428. this.pos--;
  7429. return peekedByte;
  7430. },
  7431. peekBytes: function ChunkedStream_peekBytes(length) {
  7432. var bytes = this.getBytes(length);
  7433. this.pos -= bytes.length;
  7434. return bytes;
  7435. },
  7436. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7437. this.ensureRange(begin, end);
  7438. return this.bytes.subarray(begin, end);
  7439. },
  7440. skip: function ChunkedStream_skip(n) {
  7441. if (!n) {
  7442. n = 1;
  7443. }
  7444. this.pos += n;
  7445. },
  7446. reset: function ChunkedStream_reset() {
  7447. this.pos = this.start;
  7448. },
  7449. moveStart: function ChunkedStream_moveStart() {
  7450. this.start = this.pos;
  7451. },
  7452. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7453. this.ensureRange(start, start + length);
  7454. function ChunkedStreamSubstream() {}
  7455. ChunkedStreamSubstream.prototype = Object.create(this);
  7456. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7457. var chunkSize = this.chunkSize;
  7458. var beginChunk = Math.floor(this.start / chunkSize);
  7459. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7460. var missingChunks = [];
  7461. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7462. if (!this.loadedChunks[chunk]) {
  7463. missingChunks.push(chunk);
  7464. }
  7465. }
  7466. return missingChunks;
  7467. };
  7468. var subStream = new ChunkedStreamSubstream();
  7469. subStream.pos = subStream.start = start;
  7470. subStream.end = start + length || this.end;
  7471. subStream.dict = dict;
  7472. return subStream;
  7473. },
  7474. isStream: true
  7475. };
  7476. return ChunkedStream;
  7477. })();
  7478. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7479. function ChunkedStreamManager(length, chunkSize, url, args) {
  7480. this.stream = new ChunkedStream(length, chunkSize, this);
  7481. this.length = length;
  7482. this.chunkSize = chunkSize;
  7483. this.url = url;
  7484. this.disableAutoFetch = args.disableAutoFetch;
  7485. var msgHandler = this.msgHandler = args.msgHandler;
  7486. if (args.chunkedViewerLoading) {
  7487. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7488. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7489. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7490. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7491. };
  7492. } else {
  7493. var getXhr = function getXhr() {
  7494. return new XMLHttpRequest();
  7495. };
  7496. this.networkManager = new NetworkManager(this.url, {
  7497. getXhr: getXhr,
  7498. httpHeaders: args.httpHeaders,
  7499. withCredentials: args.withCredentials
  7500. });
  7501. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7502. this.networkManager.requestRange(begin, end, {
  7503. onDone: this.onReceiveData.bind(this),
  7504. onProgress: this.onProgress.bind(this)
  7505. });
  7506. };
  7507. }
  7508. this.currRequestId = 0;
  7509. this.chunksNeededByRequest = {};
  7510. this.requestsByChunk = {};
  7511. this.callbacksByRequest = {};
  7512. this.progressiveDataLength = 0;
  7513. this._loadedStreamCapability = createPromiseCapability();
  7514. if (args.initialData) {
  7515. this.onReceiveData({chunk: args.initialData});
  7516. }
  7517. }
  7518. ChunkedStreamManager.prototype = {
  7519. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7520. return this._loadedStreamCapability.promise;
  7521. },
  7522. // Get all the chunks that are not yet loaded and groups them into
  7523. // contiguous ranges to load in as few requests as possible
  7524. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7525. var missingChunks = this.stream.getMissingChunks();
  7526. this.requestChunks(missingChunks);
  7527. return this._loadedStreamCapability.promise;
  7528. },
  7529. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7530. callback) {
  7531. var requestId = this.currRequestId++;
  7532. var chunksNeeded;
  7533. var i, ii;
  7534. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7535. for (i = 0, ii = chunks.length; i < ii; i++) {
  7536. if (!this.stream.hasChunk(chunks[i])) {
  7537. chunksNeeded[chunks[i]] = true;
  7538. }
  7539. }
  7540. if (isEmptyObj(chunksNeeded)) {
  7541. if (callback) {
  7542. callback();
  7543. }
  7544. return;
  7545. }
  7546. this.callbacksByRequest[requestId] = callback;
  7547. var chunksToRequest = [];
  7548. for (var chunk in chunksNeeded) {
  7549. chunk = chunk | 0;
  7550. if (!(chunk in this.requestsByChunk)) {
  7551. this.requestsByChunk[chunk] = [];
  7552. chunksToRequest.push(chunk);
  7553. }
  7554. this.requestsByChunk[chunk].push(requestId);
  7555. }
  7556. if (!chunksToRequest.length) {
  7557. return;
  7558. }
  7559. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7560. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7561. var groupedChunk = groupedChunksToRequest[i];
  7562. var begin = groupedChunk.beginChunk * this.chunkSize;
  7563. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7564. this.sendRequest(begin, end);
  7565. }
  7566. },
  7567. getStream: function ChunkedStreamManager_getStream() {
  7568. return this.stream;
  7569. },
  7570. // Loads any chunks in the requested range that are not yet loaded
  7571. requestRange: function ChunkedStreamManager_requestRange(
  7572. begin, end, callback) {
  7573. end = Math.min(end, this.length);
  7574. var beginChunk = this.getBeginChunk(begin);
  7575. var endChunk = this.getEndChunk(end);
  7576. var chunks = [];
  7577. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7578. chunks.push(chunk);
  7579. }
  7580. this.requestChunks(chunks, callback);
  7581. },
  7582. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7583. callback) {
  7584. ranges = ranges || [];
  7585. var chunksToRequest = [];
  7586. for (var i = 0; i < ranges.length; i++) {
  7587. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7588. var endChunk = this.getEndChunk(ranges[i].end);
  7589. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7590. if (chunksToRequest.indexOf(chunk) < 0) {
  7591. chunksToRequest.push(chunk);
  7592. }
  7593. }
  7594. }
  7595. chunksToRequest.sort(function(a, b) { return a - b; });
  7596. this.requestChunks(chunksToRequest, callback);
  7597. },
  7598. // Groups a sorted array of chunks into as few continguous larger
  7599. // chunks as possible
  7600. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7601. var groupedChunks = [];
  7602. var beginChunk = -1;
  7603. var prevChunk = -1;
  7604. for (var i = 0; i < chunks.length; ++i) {
  7605. var chunk = chunks[i];
  7606. if (beginChunk < 0) {
  7607. beginChunk = chunk;
  7608. }
  7609. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7610. groupedChunks.push({ beginChunk: beginChunk,
  7611. endChunk: prevChunk + 1 });
  7612. beginChunk = chunk;
  7613. }
  7614. if (i + 1 === chunks.length) {
  7615. groupedChunks.push({ beginChunk: beginChunk,
  7616. endChunk: chunk + 1 });
  7617. }
  7618. prevChunk = chunk;
  7619. }
  7620. return groupedChunks;
  7621. },
  7622. onProgress: function ChunkedStreamManager_onProgress(args) {
  7623. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7624. args.loaded);
  7625. this.msgHandler.send('DocProgress', {
  7626. loaded: bytesLoaded,
  7627. total: this.length
  7628. });
  7629. },
  7630. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7631. var chunk = args.chunk;
  7632. var isProgressive = args.begin === undefined;
  7633. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7634. var end = begin + chunk.byteLength;
  7635. var beginChunk = Math.floor(begin / this.chunkSize);
  7636. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7637. Math.ceil(end / this.chunkSize);
  7638. if (isProgressive) {
  7639. this.stream.onReceiveProgressiveData(chunk);
  7640. this.progressiveDataLength = end;
  7641. } else {
  7642. this.stream.onReceiveData(begin, chunk);
  7643. }
  7644. if (this.stream.allChunksLoaded()) {
  7645. this._loadedStreamCapability.resolve(this.stream);
  7646. }
  7647. var loadedRequests = [];
  7648. var i, requestId;
  7649. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7650. // The server might return more chunks than requested
  7651. var requestIds = this.requestsByChunk[chunk] || [];
  7652. delete this.requestsByChunk[chunk];
  7653. for (i = 0; i < requestIds.length; ++i) {
  7654. requestId = requestIds[i];
  7655. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7656. if (chunk in chunksNeeded) {
  7657. delete chunksNeeded[chunk];
  7658. }
  7659. if (!isEmptyObj(chunksNeeded)) {
  7660. continue;
  7661. }
  7662. loadedRequests.push(requestId);
  7663. }
  7664. }
  7665. // If there are no pending requests, automatically fetch the next
  7666. // unfetched chunk of the PDF
  7667. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7668. var nextEmptyChunk;
  7669. if (this.stream.numChunksLoaded === 1) {
  7670. // This is a special optimization so that after fetching the first
  7671. // chunk, rather than fetching the second chunk, we fetch the last
  7672. // chunk.
  7673. var lastChunk = this.stream.numChunks - 1;
  7674. if (!this.stream.hasChunk(lastChunk)) {
  7675. nextEmptyChunk = lastChunk;
  7676. }
  7677. } else {
  7678. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7679. }
  7680. if (isInt(nextEmptyChunk)) {
  7681. this.requestChunks([nextEmptyChunk]);
  7682. }
  7683. }
  7684. for (i = 0; i < loadedRequests.length; ++i) {
  7685. requestId = loadedRequests[i];
  7686. var callback = this.callbacksByRequest[requestId];
  7687. delete this.callbacksByRequest[requestId];
  7688. if (callback) {
  7689. callback();
  7690. }
  7691. }
  7692. this.msgHandler.send('DocProgress', {
  7693. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7694. total: this.length
  7695. });
  7696. },
  7697. onError: function ChunkedStreamManager_onError(err) {
  7698. this._loadedStreamCapability.reject(err);
  7699. },
  7700. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7701. var chunk = Math.floor(begin / this.chunkSize);
  7702. return chunk;
  7703. },
  7704. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7705. if (end % this.chunkSize === 0) {
  7706. return end / this.chunkSize;
  7707. }
  7708. // 0 -> 0
  7709. // 1 -> 1
  7710. // 99 -> 1
  7711. // 100 -> 1
  7712. // 101 -> 2
  7713. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7714. return chunk;
  7715. }
  7716. };
  7717. return ChunkedStreamManager;
  7718. })();
  7719. // The maximum number of bytes fetched per range request
  7720. var RANGE_CHUNK_SIZE = 65536;
  7721. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7722. var BasePdfManager = (function BasePdfManagerClosure() {
  7723. function BasePdfManager() {
  7724. throw new Error('Cannot initialize BaseManagerManager');
  7725. }
  7726. BasePdfManager.prototype = {
  7727. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7728. throw new NotImplementedException();
  7729. },
  7730. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7731. return this.ensure(this.pdfDocument, prop, args);
  7732. },
  7733. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7734. return this.ensure(this.pdfDocument.xref, prop, args);
  7735. },
  7736. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7737. return this.ensure(this.pdfDocument.catalog, prop, args);
  7738. },
  7739. getPage: function BasePdfManager_pagePage(pageIndex) {
  7740. return this.pdfDocument.getPage(pageIndex);
  7741. },
  7742. cleanup: function BasePdfManager_cleanup() {
  7743. return this.pdfDocument.cleanup();
  7744. },
  7745. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7746. return new NotImplementedException();
  7747. },
  7748. requestRange: function BasePdfManager_ensure(begin, end) {
  7749. return new NotImplementedException();
  7750. },
  7751. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7752. return new NotImplementedException();
  7753. },
  7754. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7755. return new NotImplementedException();
  7756. },
  7757. updatePassword: function BasePdfManager_updatePassword(password) {
  7758. this.pdfDocument.xref.password = this.password = password;
  7759. if (this._passwordChangedCapability) {
  7760. this._passwordChangedCapability.resolve();
  7761. }
  7762. },
  7763. passwordChanged: function BasePdfManager_passwordChanged() {
  7764. this._passwordChangedCapability = createPromiseCapability();
  7765. return this._passwordChangedCapability.promise;
  7766. },
  7767. terminate: function BasePdfManager_terminate() {
  7768. return new NotImplementedException();
  7769. }
  7770. };
  7771. return BasePdfManager;
  7772. })();
  7773. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7774. function LocalPdfManager(data, password) {
  7775. var stream = new Stream(data);
  7776. this.pdfDocument = new PDFDocument(this, stream, password);
  7777. this._loadedStreamCapability = createPromiseCapability();
  7778. this._loadedStreamCapability.resolve(stream);
  7779. }
  7780. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7781. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7782. LocalPdfManager.prototype.ensure =
  7783. function LocalPdfManager_ensure(obj, prop, args) {
  7784. return new Promise(function (resolve, reject) {
  7785. try {
  7786. var value = obj[prop];
  7787. var result;
  7788. if (typeof value === 'function') {
  7789. result = value.apply(obj, args);
  7790. } else {
  7791. result = value;
  7792. }
  7793. resolve(result);
  7794. } catch (e) {
  7795. reject(e);
  7796. }
  7797. });
  7798. };
  7799. LocalPdfManager.prototype.requestRange =
  7800. function LocalPdfManager_requestRange(begin, end) {
  7801. return Promise.resolve();
  7802. };
  7803. LocalPdfManager.prototype.requestLoadedStream =
  7804. function LocalPdfManager_requestLoadedStream() {
  7805. };
  7806. LocalPdfManager.prototype.onLoadedStream =
  7807. function LocalPdfManager_getLoadedStream() {
  7808. return this._loadedStreamCapability.promise;
  7809. };
  7810. LocalPdfManager.prototype.terminate =
  7811. function LocalPdfManager_terminate() {
  7812. return;
  7813. };
  7814. return LocalPdfManager;
  7815. })();
  7816. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7817. function NetworkPdfManager(args, msgHandler) {
  7818. this.msgHandler = msgHandler;
  7819. var params = {
  7820. msgHandler: msgHandler,
  7821. httpHeaders: args.httpHeaders,
  7822. withCredentials: args.withCredentials,
  7823. chunkedViewerLoading: args.chunkedViewerLoading,
  7824. disableAutoFetch: args.disableAutoFetch,
  7825. initialData: args.initialData
  7826. };
  7827. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7828. args.url, params);
  7829. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7830. args.password);
  7831. }
  7832. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7833. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7834. NetworkPdfManager.prototype.ensure =
  7835. function NetworkPdfManager_ensure(obj, prop, args) {
  7836. var pdfManager = this;
  7837. return new Promise(function (resolve, reject) {
  7838. function ensureHelper() {
  7839. try {
  7840. var result;
  7841. var value = obj[prop];
  7842. if (typeof value === 'function') {
  7843. result = value.apply(obj, args);
  7844. } else {
  7845. result = value;
  7846. }
  7847. resolve(result);
  7848. } catch(e) {
  7849. if (!(e instanceof MissingDataException)) {
  7850. reject(e);
  7851. return;
  7852. }
  7853. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7854. }
  7855. }
  7856. ensureHelper();
  7857. });
  7858. };
  7859. NetworkPdfManager.prototype.requestRange =
  7860. function NetworkPdfManager_requestRange(begin, end) {
  7861. return new Promise(function (resolve) {
  7862. this.streamManager.requestRange(begin, end, function() {
  7863. resolve();
  7864. });
  7865. }.bind(this));
  7866. };
  7867. NetworkPdfManager.prototype.requestLoadedStream =
  7868. function NetworkPdfManager_requestLoadedStream() {
  7869. this.streamManager.requestAllChunks();
  7870. };
  7871. NetworkPdfManager.prototype.sendProgressiveData =
  7872. function NetworkPdfManager_sendProgressiveData(chunk) {
  7873. this.streamManager.onReceiveData({ chunk: chunk });
  7874. };
  7875. NetworkPdfManager.prototype.onLoadedStream =
  7876. function NetworkPdfManager_getLoadedStream() {
  7877. return this.streamManager.onLoadedStream();
  7878. };
  7879. NetworkPdfManager.prototype.terminate =
  7880. function NetworkPdfManager_terminate() {
  7881. this.streamManager.networkManager.abortAllRequests();
  7882. };
  7883. return NetworkPdfManager;
  7884. })();
  7885. var Page = (function PageClosure() {
  7886. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7887. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7888. this.pdfManager = pdfManager;
  7889. this.pageIndex = pageIndex;
  7890. this.pageDict = pageDict;
  7891. this.xref = xref;
  7892. this.ref = ref;
  7893. this.fontCache = fontCache;
  7894. this.idCounters = {
  7895. obj: 0
  7896. };
  7897. this.resourcesPromise = null;
  7898. }
  7899. Page.prototype = {
  7900. getPageProp: function Page_getPageProp(key) {
  7901. return this.pageDict.get(key);
  7902. },
  7903. getInheritedPageProp: function Page_inheritPageProp(key) {
  7904. var dict = this.pageDict;
  7905. var value = dict.get(key);
  7906. while (value === undefined) {
  7907. dict = dict.get('Parent');
  7908. if (!dict) {
  7909. break;
  7910. }
  7911. value = dict.get(key);
  7912. }
  7913. return value;
  7914. },
  7915. get content() {
  7916. return this.getPageProp('Contents');
  7917. },
  7918. get resources() {
  7919. var value = this.getInheritedPageProp('Resources');
  7920. // For robustness: The spec states that a \Resources entry has to be
  7921. // present, but can be empty. Some document omit it still. In this case
  7922. // return an empty dictionary:
  7923. if (value === undefined) {
  7924. value = Dict.empty;
  7925. }
  7926. return shadow(this, 'resources', value);
  7927. },
  7928. get mediaBox() {
  7929. var obj = this.getInheritedPageProp('MediaBox');
  7930. // Reset invalid media box to letter size.
  7931. if (!isArray(obj) || obj.length !== 4) {
  7932. obj = LETTER_SIZE_MEDIABOX;
  7933. }
  7934. return shadow(this, 'mediaBox', obj);
  7935. },
  7936. get view() {
  7937. var mediaBox = this.mediaBox;
  7938. var cropBox = this.getInheritedPageProp('CropBox');
  7939. if (!isArray(cropBox) || cropBox.length !== 4) {
  7940. return shadow(this, 'view', mediaBox);
  7941. }
  7942. // From the spec, 6th ed., p.963:
  7943. // "The crop, bleed, trim, and art boxes should not ordinarily
  7944. // extend beyond the boundaries of the media box. If they do, they are
  7945. // effectively reduced to their intersection with the media box."
  7946. cropBox = Util.intersect(cropBox, mediaBox);
  7947. if (!cropBox) {
  7948. return shadow(this, 'view', mediaBox);
  7949. }
  7950. return shadow(this, 'view', cropBox);
  7951. },
  7952. get annotationRefs() {
  7953. return shadow(this, 'annotationRefs',
  7954. this.getInheritedPageProp('Annots'));
  7955. },
  7956. get rotate() {
  7957. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7958. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7959. if (rotate % 90 !== 0) {
  7960. rotate = 0;
  7961. } else if (rotate >= 360) {
  7962. rotate = rotate % 360;
  7963. } else if (rotate < 0) {
  7964. // The spec doesn't cover negatives, assume its counterclockwise
  7965. // rotation. The following is the other implementation of modulo.
  7966. rotate = ((rotate % 360) + 360) % 360;
  7967. }
  7968. return shadow(this, 'rotate', rotate);
  7969. },
  7970. getContentStream: function Page_getContentStream() {
  7971. var content = this.content;
  7972. var stream;
  7973. if (isArray(content)) {
  7974. // fetching items
  7975. var xref = this.xref;
  7976. var i, n = content.length;
  7977. var streams = [];
  7978. for (i = 0; i < n; ++i) {
  7979. streams.push(xref.fetchIfRef(content[i]));
  7980. }
  7981. stream = new StreamsSequenceStream(streams);
  7982. } else if (isStream(content)) {
  7983. stream = content;
  7984. } else {
  7985. // replacing non-existent page content with empty one
  7986. stream = new NullStream();
  7987. }
  7988. return stream;
  7989. },
  7990. loadResources: function Page_loadResources(keys) {
  7991. if (!this.resourcesPromise) {
  7992. // TODO: add async getInheritedPageProp and remove this.
  7993. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  7994. }
  7995. return this.resourcesPromise.then(function resourceSuccess() {
  7996. var objectLoader = new ObjectLoader(this.resources.map,
  7997. keys,
  7998. this.xref);
  7999. return objectLoader.load();
  8000. }.bind(this));
  8001. },
  8002. getOperatorList: function Page_getOperatorList(handler, intent) {
  8003. var self = this;
  8004. var pdfManager = this.pdfManager;
  8005. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8006. []);
  8007. var resourcesPromise = this.loadResources([
  8008. 'ExtGState',
  8009. 'ColorSpace',
  8010. 'Pattern',
  8011. 'Shading',
  8012. 'XObject',
  8013. 'Font'
  8014. // ProcSet
  8015. // Properties
  8016. ]);
  8017. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8018. handler, this.pageIndex,
  8019. 'p' + this.pageIndex + '_',
  8020. this.idCounters,
  8021. this.fontCache);
  8022. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8023. var pageListPromise = dataPromises.then(function(data) {
  8024. var contentStream = data[0];
  8025. var opList = new OperatorList(intent, handler, self.pageIndex);
  8026. handler.send('StartRenderPage', {
  8027. transparency: partialEvaluator.hasBlendModes(self.resources),
  8028. pageIndex: self.pageIndex,
  8029. intent: intent
  8030. });
  8031. return partialEvaluator.getOperatorList(contentStream, self.resources,
  8032. opList).then(function () {
  8033. return opList;
  8034. });
  8035. });
  8036. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8037. return Promise.all([pageListPromise, annotationsPromise]).then(
  8038. function(datas) {
  8039. var pageOpList = datas[0];
  8040. var annotations = datas[1];
  8041. if (annotations.length === 0) {
  8042. pageOpList.flush(true);
  8043. return pageOpList;
  8044. }
  8045. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8046. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  8047. return annotationsReadyPromise.then(function () {
  8048. pageOpList.flush(true);
  8049. return pageOpList;
  8050. });
  8051. });
  8052. },
  8053. extractTextContent: function Page_extractTextContent() {
  8054. var handler = {
  8055. on: function nullHandlerOn() {},
  8056. send: function nullHandlerSend() {}
  8057. };
  8058. var self = this;
  8059. var pdfManager = this.pdfManager;
  8060. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8061. []);
  8062. var resourcesPromise = this.loadResources([
  8063. 'ExtGState',
  8064. 'XObject',
  8065. 'Font'
  8066. ]);
  8067. var dataPromises = Promise.all([contentStreamPromise,
  8068. resourcesPromise]);
  8069. return dataPromises.then(function(data) {
  8070. var contentStream = data[0];
  8071. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8072. handler, self.pageIndex,
  8073. 'p' + self.pageIndex + '_',
  8074. self.idCounters,
  8075. self.fontCache);
  8076. return partialEvaluator.getTextContent(contentStream,
  8077. self.resources);
  8078. });
  8079. },
  8080. getAnnotationsData: function Page_getAnnotationsData() {
  8081. var annotations = this.annotations;
  8082. var annotationsData = [];
  8083. for (var i = 0, n = annotations.length; i < n; ++i) {
  8084. annotationsData.push(annotations[i].getData());
  8085. }
  8086. return annotationsData;
  8087. },
  8088. get annotations() {
  8089. var annotations = [];
  8090. var annotationRefs = (this.annotationRefs || []);
  8091. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8092. var annotationRef = annotationRefs[i];
  8093. var annotation = Annotation.fromRef(this.xref, annotationRef);
  8094. if (annotation) {
  8095. annotations.push(annotation);
  8096. }
  8097. }
  8098. return shadow(this, 'annotations', annotations);
  8099. }
  8100. };
  8101. return Page;
  8102. })();
  8103. /**
  8104. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8105. * `PDFDoc`, this one doesn't have any job management code.
  8106. * Right now there exists one PDFDocument on the main thread + one object
  8107. * for each worker. If there is no worker support enabled, there are two
  8108. * `PDFDocument` objects on the main thread created.
  8109. */
  8110. var PDFDocument = (function PDFDocumentClosure() {
  8111. var FINGERPRINT_FIRST_BYTES = 1024;
  8112. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8113. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8114. function PDFDocument(pdfManager, arg, password) {
  8115. if (isStream(arg)) {
  8116. init.call(this, pdfManager, arg, password);
  8117. } else if (isArrayBuffer(arg)) {
  8118. init.call(this, pdfManager, new Stream(arg), password);
  8119. } else {
  8120. error('PDFDocument: Unknown argument type');
  8121. }
  8122. }
  8123. function init(pdfManager, stream, password) {
  8124. assert(stream.length > 0, 'stream must have data');
  8125. this.pdfManager = pdfManager;
  8126. this.stream = stream;
  8127. var xref = new XRef(this.stream, password, pdfManager);
  8128. this.xref = xref;
  8129. }
  8130. function find(stream, needle, limit, backwards) {
  8131. var pos = stream.pos;
  8132. var end = stream.end;
  8133. var strBuf = [];
  8134. if (pos + limit > end) {
  8135. limit = end - pos;
  8136. }
  8137. for (var n = 0; n < limit; ++n) {
  8138. strBuf.push(String.fromCharCode(stream.getByte()));
  8139. }
  8140. var str = strBuf.join('');
  8141. stream.pos = pos;
  8142. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8143. if (index === -1) {
  8144. return false; /* not found */
  8145. }
  8146. stream.pos += index;
  8147. return true; /* found */
  8148. }
  8149. var DocumentInfoValidators = {
  8150. get entries() {
  8151. // Lazily build this since all the validation functions below are not
  8152. // defined until after this file loads.
  8153. return shadow(this, 'entries', {
  8154. Title: isString,
  8155. Author: isString,
  8156. Subject: isString,
  8157. Keywords: isString,
  8158. Creator: isString,
  8159. Producer: isString,
  8160. CreationDate: isString,
  8161. ModDate: isString,
  8162. Trapped: isName
  8163. });
  8164. }
  8165. };
  8166. PDFDocument.prototype = {
  8167. parse: function PDFDocument_parse(recoveryMode) {
  8168. this.setup(recoveryMode);
  8169. try {
  8170. // checking if AcroForm is present
  8171. this.acroForm = this.catalog.catDict.get('AcroForm');
  8172. if (this.acroForm) {
  8173. this.xfa = this.acroForm.get('XFA');
  8174. var fields = this.acroForm.get('Fields');
  8175. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8176. !this.xfa) {
  8177. // no fields and no XFA -- not a form (?)
  8178. this.acroForm = null;
  8179. }
  8180. }
  8181. } catch (ex) {
  8182. info('Something wrong with AcroForm entry');
  8183. this.acroForm = null;
  8184. }
  8185. },
  8186. get linearization() {
  8187. var linearization = null;
  8188. if (this.stream.length) {
  8189. try {
  8190. linearization = Linearization.create(this.stream);
  8191. } catch (err) {
  8192. if (err instanceof MissingDataException) {
  8193. throw err;
  8194. }
  8195. info(err);
  8196. }
  8197. }
  8198. // shadow the prototype getter with a data property
  8199. return shadow(this, 'linearization', linearization);
  8200. },
  8201. get startXRef() {
  8202. var stream = this.stream;
  8203. var startXRef = 0;
  8204. var linearization = this.linearization;
  8205. if (linearization) {
  8206. // Find end of first obj.
  8207. stream.reset();
  8208. if (find(stream, 'endobj', 1024)) {
  8209. startXRef = stream.pos + 6;
  8210. }
  8211. } else {
  8212. // Find startxref by jumping backward from the end of the file.
  8213. var step = 1024;
  8214. var found = false, pos = stream.end;
  8215. while (!found && pos > 0) {
  8216. pos -= step - 'startxref'.length;
  8217. if (pos < 0) {
  8218. pos = 0;
  8219. }
  8220. stream.pos = pos;
  8221. found = find(stream, 'startxref', step, true);
  8222. }
  8223. if (found) {
  8224. stream.skip(9);
  8225. var ch;
  8226. do {
  8227. ch = stream.getByte();
  8228. } while (Lexer.isSpace(ch));
  8229. var str = '';
  8230. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8231. str += String.fromCharCode(ch);
  8232. ch = stream.getByte();
  8233. }
  8234. startXRef = parseInt(str, 10);
  8235. if (isNaN(startXRef)) {
  8236. startXRef = 0;
  8237. }
  8238. }
  8239. }
  8240. // shadow the prototype getter with a data property
  8241. return shadow(this, 'startXRef', startXRef);
  8242. },
  8243. get mainXRefEntriesOffset() {
  8244. var mainXRefEntriesOffset = 0;
  8245. var linearization = this.linearization;
  8246. if (linearization) {
  8247. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8248. }
  8249. // shadow the prototype getter with a data property
  8250. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8251. },
  8252. // Find the header, remove leading garbage and setup the stream
  8253. // starting from the header.
  8254. checkHeader: function PDFDocument_checkHeader() {
  8255. var stream = this.stream;
  8256. stream.reset();
  8257. if (find(stream, '%PDF-', 1024)) {
  8258. // Found the header, trim off any garbage before it.
  8259. stream.moveStart();
  8260. // Reading file format version
  8261. var MAX_VERSION_LENGTH = 12;
  8262. var version = '', ch;
  8263. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8264. if (version.length >= MAX_VERSION_LENGTH) {
  8265. break;
  8266. }
  8267. version += String.fromCharCode(ch);
  8268. }
  8269. // removing "%PDF-"-prefix
  8270. this.pdfFormatVersion = version.substring(5);
  8271. return;
  8272. }
  8273. // May not be a PDF file, continue anyway.
  8274. },
  8275. parseStartXRef: function PDFDocument_parseStartXRef() {
  8276. var startXRef = this.startXRef;
  8277. this.xref.setStartXRef(startXRef);
  8278. },
  8279. setup: function PDFDocument_setup(recoveryMode) {
  8280. this.xref.parse(recoveryMode);
  8281. this.catalog = new Catalog(this.pdfManager, this.xref);
  8282. },
  8283. get numPages() {
  8284. var linearization = this.linearization;
  8285. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8286. // shadow the prototype getter
  8287. return shadow(this, 'numPages', num);
  8288. },
  8289. get documentInfo() {
  8290. var docInfo = {
  8291. PDFFormatVersion: this.pdfFormatVersion,
  8292. IsAcroFormPresent: !!this.acroForm,
  8293. IsXFAPresent: !!this.xfa
  8294. };
  8295. var infoDict;
  8296. try {
  8297. infoDict = this.xref.trailer.get('Info');
  8298. } catch (err) {
  8299. info('The document information dictionary is invalid.');
  8300. }
  8301. if (infoDict) {
  8302. var validEntries = DocumentInfoValidators.entries;
  8303. // Only fill the document info with valid entries from the spec.
  8304. for (var key in validEntries) {
  8305. if (infoDict.has(key)) {
  8306. var value = infoDict.get(key);
  8307. // Make sure the value conforms to the spec.
  8308. if (validEntries[key](value)) {
  8309. docInfo[key] = (typeof value !== 'string' ?
  8310. value : stringToPDFString(value));
  8311. } else {
  8312. info('Bad value in document info for "' + key + '"');
  8313. }
  8314. }
  8315. }
  8316. }
  8317. return shadow(this, 'documentInfo', docInfo);
  8318. },
  8319. get fingerprint() {
  8320. var xref = this.xref, idArray, hash, fileID = '';
  8321. if (xref.trailer.has('ID')) {
  8322. idArray = xref.trailer.get('ID');
  8323. }
  8324. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  8325. hash = stringToBytes(idArray[0]);
  8326. } else {
  8327. if (this.stream.ensureRange) {
  8328. this.stream.ensureRange(0,
  8329. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8330. }
  8331. hash = calculateMD5(this.stream.bytes.subarray(0,
  8332. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8333. }
  8334. for (var i = 0, n = hash.length; i < n; i++) {
  8335. var hex = hash[i].toString(16);
  8336. fileID += hex.length === 1 ? '0' + hex : hex;
  8337. }
  8338. return shadow(this, 'fingerprint', fileID);
  8339. },
  8340. getPage: function PDFDocument_getPage(pageIndex) {
  8341. return this.catalog.getPage(pageIndex);
  8342. },
  8343. cleanup: function PDFDocument_cleanup() {
  8344. return this.catalog.cleanup();
  8345. }
  8346. };
  8347. return PDFDocument;
  8348. })();
  8349. var Name = (function NameClosure() {
  8350. function Name(name) {
  8351. this.name = name;
  8352. }
  8353. Name.prototype = {};
  8354. var nameCache = {};
  8355. Name.get = function Name_get(name) {
  8356. var nameValue = nameCache[name];
  8357. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8358. };
  8359. return Name;
  8360. })();
  8361. var Cmd = (function CmdClosure() {
  8362. function Cmd(cmd) {
  8363. this.cmd = cmd;
  8364. }
  8365. Cmd.prototype = {};
  8366. var cmdCache = {};
  8367. Cmd.get = function Cmd_get(cmd) {
  8368. var cmdValue = cmdCache[cmd];
  8369. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8370. };
  8371. return Cmd;
  8372. })();
  8373. var Dict = (function DictClosure() {
  8374. var nonSerializable = function nonSerializableClosure() {
  8375. return nonSerializable; // creating closure on some variable
  8376. };
  8377. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8378. 'Background': true,
  8379. 'ExtGState': true,
  8380. 'Halftone': true,
  8381. 'Layout': true,
  8382. 'Mask': true,
  8383. 'Pagination': true,
  8384. 'Printing': true
  8385. };
  8386. function isRecursionAllowedFor(dict) {
  8387. if (!isName(dict.Type)) {
  8388. return true;
  8389. }
  8390. var dictType = dict.Type.name;
  8391. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8392. }
  8393. // xref is optional
  8394. function Dict(xref) {
  8395. // Map should only be used internally, use functions below to access.
  8396. this.map = Object.create(null);
  8397. this.xref = xref;
  8398. this.objId = null;
  8399. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8400. }
  8401. Dict.prototype = {
  8402. assignXref: function Dict_assignXref(newXref) {
  8403. this.xref = newXref;
  8404. },
  8405. // automatically dereferences Ref objects
  8406. get: function Dict_get(key1, key2, key3) {
  8407. var value;
  8408. var xref = this.xref;
  8409. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8410. typeof key2 === 'undefined') {
  8411. return xref ? xref.fetchIfRef(value) : value;
  8412. }
  8413. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8414. typeof key3 === 'undefined') {
  8415. return xref ? xref.fetchIfRef(value) : value;
  8416. }
  8417. value = this.map[key3] || null;
  8418. return xref ? xref.fetchIfRef(value) : value;
  8419. },
  8420. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8421. getAsync: function Dict_getAsync(key1, key2, key3) {
  8422. var value;
  8423. var xref = this.xref;
  8424. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8425. typeof key2 === 'undefined') {
  8426. if (xref) {
  8427. return xref.fetchIfRefAsync(value);
  8428. }
  8429. return Promise.resolve(value);
  8430. }
  8431. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8432. typeof key3 === 'undefined') {
  8433. if (xref) {
  8434. return xref.fetchIfRefAsync(value);
  8435. }
  8436. return Promise.resolve(value);
  8437. }
  8438. value = this.map[key3] || null;
  8439. if (xref) {
  8440. return xref.fetchIfRefAsync(value);
  8441. }
  8442. return Promise.resolve(value);
  8443. },
  8444. // no dereferencing
  8445. getRaw: function Dict_getRaw(key) {
  8446. return this.map[key];
  8447. },
  8448. // creates new map and dereferences all Refs
  8449. getAll: function Dict_getAll() {
  8450. var all = Object.create(null);
  8451. var queue = null;
  8452. var key, obj;
  8453. for (key in this.map) {
  8454. obj = this.get(key);
  8455. if (obj instanceof Dict) {
  8456. if (isRecursionAllowedFor(obj)) {
  8457. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8458. } else {
  8459. all[key] = this.getRaw(key);
  8460. }
  8461. } else {
  8462. all[key] = obj;
  8463. }
  8464. }
  8465. if (!queue) {
  8466. return all;
  8467. }
  8468. // trying to take cyclic references into the account
  8469. var processed = Object.create(null);
  8470. while (queue.length > 0) {
  8471. var item = queue.shift();
  8472. var itemObj = item.obj;
  8473. var objId = itemObj.objId;
  8474. if (objId && objId in processed) {
  8475. item.target[item.key] = processed[objId];
  8476. continue;
  8477. }
  8478. var dereferenced = Object.create(null);
  8479. for (key in itemObj.map) {
  8480. obj = itemObj.get(key);
  8481. if (obj instanceof Dict) {
  8482. if (isRecursionAllowedFor(obj)) {
  8483. queue.push({target: dereferenced, key: key, obj: obj});
  8484. } else {
  8485. dereferenced[key] = itemObj.getRaw(key);
  8486. }
  8487. } else {
  8488. dereferenced[key] = obj;
  8489. }
  8490. }
  8491. if (objId) {
  8492. processed[objId] = dereferenced;
  8493. }
  8494. item.target[item.key] = dereferenced;
  8495. }
  8496. return all;
  8497. },
  8498. set: function Dict_set(key, value) {
  8499. this.map[key] = value;
  8500. },
  8501. has: function Dict_has(key) {
  8502. return key in this.map;
  8503. },
  8504. forEach: function Dict_forEach(callback) {
  8505. for (var key in this.map) {
  8506. callback(key, this.get(key));
  8507. }
  8508. }
  8509. };
  8510. Dict.empty = new Dict(null);
  8511. return Dict;
  8512. })();
  8513. var Ref = (function RefClosure() {
  8514. function Ref(num, gen) {
  8515. this.num = num;
  8516. this.gen = gen;
  8517. }
  8518. Ref.prototype = {
  8519. toString: function Ref_toString() {
  8520. // This function is hot, so we make the string as compact as possible.
  8521. // |this.gen| is almost always zero, so we treat that case specially.
  8522. var str = this.num + 'R';
  8523. if (this.gen !== 0) {
  8524. str += this.gen;
  8525. }
  8526. return str;
  8527. }
  8528. };
  8529. return Ref;
  8530. })();
  8531. // The reference is identified by number and generation.
  8532. // This structure stores only one instance of the reference.
  8533. var RefSet = (function RefSetClosure() {
  8534. function RefSet() {
  8535. this.dict = {};
  8536. }
  8537. RefSet.prototype = {
  8538. has: function RefSet_has(ref) {
  8539. return ref.toString() in this.dict;
  8540. },
  8541. put: function RefSet_put(ref) {
  8542. this.dict[ref.toString()] = true;
  8543. },
  8544. remove: function RefSet_remove(ref) {
  8545. delete this.dict[ref.toString()];
  8546. }
  8547. };
  8548. return RefSet;
  8549. })();
  8550. var RefSetCache = (function RefSetCacheClosure() {
  8551. function RefSetCache() {
  8552. this.dict = Object.create(null);
  8553. }
  8554. RefSetCache.prototype = {
  8555. get: function RefSetCache_get(ref) {
  8556. return this.dict[ref.toString()];
  8557. },
  8558. has: function RefSetCache_has(ref) {
  8559. return ref.toString() in this.dict;
  8560. },
  8561. put: function RefSetCache_put(ref, obj) {
  8562. this.dict[ref.toString()] = obj;
  8563. },
  8564. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8565. this.dict[ref.toString()] = this.get(aliasRef);
  8566. },
  8567. forEach: function RefSetCache_forEach(fn, thisArg) {
  8568. for (var i in this.dict) {
  8569. fn.call(thisArg, this.dict[i]);
  8570. }
  8571. },
  8572. clear: function RefSetCache_clear() {
  8573. this.dict = Object.create(null);
  8574. }
  8575. };
  8576. return RefSetCache;
  8577. })();
  8578. var Catalog = (function CatalogClosure() {
  8579. function Catalog(pdfManager, xref) {
  8580. this.pdfManager = pdfManager;
  8581. this.xref = xref;
  8582. this.catDict = xref.getCatalogObj();
  8583. this.fontCache = new RefSetCache();
  8584. assert(isDict(this.catDict),
  8585. 'catalog object is not a dictionary');
  8586. this.pagePromises = [];
  8587. }
  8588. Catalog.prototype = {
  8589. get metadata() {
  8590. var streamRef = this.catDict.getRaw('Metadata');
  8591. if (!isRef(streamRef)) {
  8592. return shadow(this, 'metadata', null);
  8593. }
  8594. var encryptMetadata = (!this.xref.encrypt ? false :
  8595. this.xref.encrypt.encryptMetadata);
  8596. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8597. var metadata;
  8598. if (stream && isDict(stream.dict)) {
  8599. var type = stream.dict.get('Type');
  8600. var subtype = stream.dict.get('Subtype');
  8601. if (isName(type) && isName(subtype) &&
  8602. type.name === 'Metadata' && subtype.name === 'XML') {
  8603. // XXX: This should examine the charset the XML document defines,
  8604. // however since there are currently no real means to decode
  8605. // arbitrary charsets, let's just hope that the author of the PDF
  8606. // was reasonable enough to stick with the XML default charset,
  8607. // which is UTF-8.
  8608. try {
  8609. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8610. } catch (e) {
  8611. info('Skipping invalid metadata.');
  8612. }
  8613. }
  8614. }
  8615. return shadow(this, 'metadata', metadata);
  8616. },
  8617. get toplevelPagesDict() {
  8618. var pagesObj = this.catDict.get('Pages');
  8619. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8620. // shadow the prototype getter
  8621. return shadow(this, 'toplevelPagesDict', pagesObj);
  8622. },
  8623. get documentOutline() {
  8624. var obj = null;
  8625. try {
  8626. obj = this.readDocumentOutline();
  8627. } catch (ex) {
  8628. if (ex instanceof MissingDataException) {
  8629. throw ex;
  8630. }
  8631. warn('Unable to read document outline');
  8632. }
  8633. return shadow(this, 'documentOutline', obj);
  8634. },
  8635. readDocumentOutline: function Catalog_readDocumentOutline() {
  8636. var xref = this.xref;
  8637. var obj = this.catDict.get('Outlines');
  8638. var root = { items: [] };
  8639. if (isDict(obj)) {
  8640. obj = obj.getRaw('First');
  8641. var processed = new RefSet();
  8642. if (isRef(obj)) {
  8643. var queue = [{obj: obj, parent: root}];
  8644. // to avoid recursion keeping track of the items
  8645. // in the processed dictionary
  8646. processed.put(obj);
  8647. while (queue.length > 0) {
  8648. var i = queue.shift();
  8649. var outlineDict = xref.fetchIfRef(i.obj);
  8650. if (outlineDict === null) {
  8651. continue;
  8652. }
  8653. if (!outlineDict.has('Title')) {
  8654. error('Invalid outline item');
  8655. }
  8656. var dest = outlineDict.get('A');
  8657. if (dest) {
  8658. dest = dest.get('D');
  8659. } else if (outlineDict.has('Dest')) {
  8660. dest = outlineDict.getRaw('Dest');
  8661. if (isName(dest)) {
  8662. dest = dest.name;
  8663. }
  8664. }
  8665. var title = outlineDict.get('Title');
  8666. var outlineItem = {
  8667. dest: dest,
  8668. title: stringToPDFString(title),
  8669. color: outlineDict.get('C') || [0, 0, 0],
  8670. count: outlineDict.get('Count'),
  8671. bold: !!(outlineDict.get('F') & 2),
  8672. italic: !!(outlineDict.get('F') & 1),
  8673. items: []
  8674. };
  8675. i.parent.items.push(outlineItem);
  8676. obj = outlineDict.getRaw('First');
  8677. if (isRef(obj) && !processed.has(obj)) {
  8678. queue.push({obj: obj, parent: outlineItem});
  8679. processed.put(obj);
  8680. }
  8681. obj = outlineDict.getRaw('Next');
  8682. if (isRef(obj) && !processed.has(obj)) {
  8683. queue.push({obj: obj, parent: i.parent});
  8684. processed.put(obj);
  8685. }
  8686. }
  8687. }
  8688. }
  8689. return (root.items.length > 0 ? root.items : null);
  8690. },
  8691. get numPages() {
  8692. var obj = this.toplevelPagesDict.get('Count');
  8693. assert(
  8694. isInt(obj),
  8695. 'page count in top level pages object is not an integer'
  8696. );
  8697. // shadow the prototype getter
  8698. return shadow(this, 'num', obj);
  8699. },
  8700. get destinations() {
  8701. function fetchDestination(dest) {
  8702. return isDict(dest) ? dest.get('D') : dest;
  8703. }
  8704. var xref = this.xref;
  8705. var dests = {}, nameTreeRef, nameDictionaryRef;
  8706. var obj = this.catDict.get('Names');
  8707. if (obj && obj.has('Dests')) {
  8708. nameTreeRef = obj.getRaw('Dests');
  8709. } else if (this.catDict.has('Dests')) {
  8710. nameDictionaryRef = this.catDict.get('Dests');
  8711. }
  8712. if (nameDictionaryRef) {
  8713. // reading simple destination dictionary
  8714. obj = nameDictionaryRef;
  8715. obj.forEach(function catalogForEach(key, value) {
  8716. if (!value) {
  8717. return;
  8718. }
  8719. dests[key] = fetchDestination(value);
  8720. });
  8721. }
  8722. if (nameTreeRef) {
  8723. var nameTree = new NameTree(nameTreeRef, xref);
  8724. var names = nameTree.getAll();
  8725. for (var name in names) {
  8726. if (!names.hasOwnProperty(name)) {
  8727. continue;
  8728. }
  8729. dests[name] = fetchDestination(names[name]);
  8730. }
  8731. }
  8732. return shadow(this, 'destinations', dests);
  8733. },
  8734. getDestination: function Catalog_getDestination(destinationId) {
  8735. function fetchDestination(dest) {
  8736. return isDict(dest) ? dest.get('D') : dest;
  8737. }
  8738. var xref = this.xref;
  8739. var dest, nameTreeRef, nameDictionaryRef;
  8740. var obj = this.catDict.get('Names');
  8741. if (obj && obj.has('Dests')) {
  8742. nameTreeRef = obj.getRaw('Dests');
  8743. } else if (this.catDict.has('Dests')) {
  8744. nameDictionaryRef = this.catDict.get('Dests');
  8745. }
  8746. if (nameDictionaryRef) {
  8747. // reading simple destination dictionary
  8748. obj = nameDictionaryRef;
  8749. obj.forEach(function catalogForEach(key, value) {
  8750. if (!value) {
  8751. return;
  8752. }
  8753. if (key === destinationId) {
  8754. dest = fetchDestination(value);
  8755. }
  8756. });
  8757. }
  8758. if (nameTreeRef) {
  8759. var nameTree = new NameTree(nameTreeRef, xref);
  8760. dest = fetchDestination(nameTree.get(destinationId));
  8761. }
  8762. return dest;
  8763. },
  8764. get attachments() {
  8765. var xref = this.xref;
  8766. var attachments = null, nameTreeRef;
  8767. var obj = this.catDict.get('Names');
  8768. if (obj) {
  8769. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8770. }
  8771. if (nameTreeRef) {
  8772. var nameTree = new NameTree(nameTreeRef, xref);
  8773. var names = nameTree.getAll();
  8774. for (var name in names) {
  8775. if (!names.hasOwnProperty(name)) {
  8776. continue;
  8777. }
  8778. var fs = new FileSpec(names[name], xref);
  8779. if (!attachments) {
  8780. attachments = {};
  8781. }
  8782. attachments[stringToPDFString(name)] = fs.serializable;
  8783. }
  8784. }
  8785. return shadow(this, 'attachments', attachments);
  8786. },
  8787. get javaScript() {
  8788. var xref = this.xref;
  8789. var obj = this.catDict.get('Names');
  8790. var javaScript = [];
  8791. if (obj && obj.has('JavaScript')) {
  8792. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8793. var names = nameTree.getAll();
  8794. for (var name in names) {
  8795. if (!names.hasOwnProperty(name)) {
  8796. continue;
  8797. }
  8798. // We don't really use the JavaScript right now. This code is
  8799. // defensive so we don't cause errors on document load.
  8800. var jsDict = names[name];
  8801. if (!isDict(jsDict)) {
  8802. continue;
  8803. }
  8804. var type = jsDict.get('S');
  8805. if (!isName(type) || type.name !== 'JavaScript') {
  8806. continue;
  8807. }
  8808. var js = jsDict.get('JS');
  8809. if (!isString(js) && !isStream(js)) {
  8810. continue;
  8811. }
  8812. if (isStream(js)) {
  8813. js = bytesToString(js.getBytes());
  8814. }
  8815. javaScript.push(stringToPDFString(js));
  8816. }
  8817. }
  8818. // Append OpenAction actions to javaScript array
  8819. var openactionDict = this.catDict.get('OpenAction');
  8820. if (isDict(openactionDict)) {
  8821. var objType = openactionDict.get('Type');
  8822. var actionType = openactionDict.get('S');
  8823. var action = openactionDict.get('N');
  8824. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8825. isName(actionType) && actionType.name === 'Named' &&
  8826. isName(action) && action.name === 'Print');
  8827. if (isPrintAction) {
  8828. javaScript.push('print(true);');
  8829. }
  8830. }
  8831. return shadow(this, 'javaScript', javaScript);
  8832. },
  8833. cleanup: function Catalog_cleanup() {
  8834. var promises = [];
  8835. this.fontCache.forEach(function (promise) {
  8836. promises.push(promise);
  8837. });
  8838. return Promise.all(promises).then(function (translatedFonts) {
  8839. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8840. var font = translatedFonts[i].dict;
  8841. delete font.translated;
  8842. }
  8843. this.fontCache.clear();
  8844. }.bind(this));
  8845. },
  8846. getPage: function Catalog_getPage(pageIndex) {
  8847. if (!(pageIndex in this.pagePromises)) {
  8848. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8849. function (a) {
  8850. var dict = a[0];
  8851. var ref = a[1];
  8852. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8853. this.fontCache);
  8854. }.bind(this)
  8855. );
  8856. }
  8857. return this.pagePromises[pageIndex];
  8858. },
  8859. getPageDict: function Catalog_getPageDict(pageIndex) {
  8860. var capability = createPromiseCapability();
  8861. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8862. var currentPageIndex = 0;
  8863. var xref = this.xref;
  8864. var checkAllKids = false;
  8865. function next() {
  8866. while (nodesToVisit.length) {
  8867. var currentNode = nodesToVisit.pop();
  8868. if (isRef(currentNode)) {
  8869. xref.fetchAsync(currentNode).then(function (obj) {
  8870. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  8871. if (pageIndex === currentPageIndex) {
  8872. capability.resolve([obj, currentNode]);
  8873. } else {
  8874. currentPageIndex++;
  8875. next();
  8876. }
  8877. return;
  8878. }
  8879. nodesToVisit.push(obj);
  8880. next();
  8881. }, capability.reject);
  8882. return;
  8883. }
  8884. // Must be a child page dictionary.
  8885. assert(
  8886. isDict(currentNode),
  8887. 'page dictionary kid reference points to wrong type of object'
  8888. );
  8889. var count = currentNode.get('Count');
  8890. // If the current node doesn't have any children, avoid getting stuck
  8891. // in an empty node further down in the tree (see issue5644.pdf).
  8892. if (count === 0) {
  8893. checkAllKids = true;
  8894. }
  8895. // Skip nodes where the page can't be.
  8896. if (currentPageIndex + count <= pageIndex) {
  8897. currentPageIndex += count;
  8898. continue;
  8899. }
  8900. var kids = currentNode.get('Kids');
  8901. assert(isArray(kids), 'page dictionary kids object is not an array');
  8902. if (!checkAllKids && count === kids.length) {
  8903. // Nodes that don't have the page have been skipped and this is the
  8904. // bottom of the tree which means the page requested must be a
  8905. // descendant of this pages node. Ideally we would just resolve the
  8906. // promise with the page ref here, but there is the case where more
  8907. // pages nodes could link to single a page (see issue 3666 pdf). To
  8908. // handle this push it back on the queue so if it is a pages node it
  8909. // will be descended into.
  8910. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8911. currentPageIndex = pageIndex;
  8912. continue;
  8913. } else {
  8914. for (var last = kids.length - 1; last >= 0; last--) {
  8915. nodesToVisit.push(kids[last]);
  8916. }
  8917. }
  8918. }
  8919. capability.reject('Page index ' + pageIndex + ' not found.');
  8920. }
  8921. next();
  8922. return capability.promise;
  8923. },
  8924. getPageIndex: function Catalog_getPageIndex(ref) {
  8925. // The page tree nodes have the count of all the leaves below them. To get
  8926. // how many pages are before we just have to walk up the tree and keep
  8927. // adding the count of siblings to the left of the node.
  8928. var xref = this.xref;
  8929. function pagesBeforeRef(kidRef) {
  8930. var total = 0;
  8931. var parentRef;
  8932. return xref.fetchAsync(kidRef).then(function (node) {
  8933. if (!node) {
  8934. return null;
  8935. }
  8936. parentRef = node.getRaw('Parent');
  8937. return node.getAsync('Parent');
  8938. }).then(function (parent) {
  8939. if (!parent) {
  8940. return null;
  8941. }
  8942. return parent.getAsync('Kids');
  8943. }).then(function (kids) {
  8944. if (!kids) {
  8945. return null;
  8946. }
  8947. var kidPromises = [];
  8948. var found = false;
  8949. for (var i = 0; i < kids.length; i++) {
  8950. var kid = kids[i];
  8951. assert(isRef(kid), 'kids must be a ref');
  8952. if (kid.num === kidRef.num) {
  8953. found = true;
  8954. break;
  8955. }
  8956. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8957. if (kid.has('Count')) {
  8958. var count = kid.get('Count');
  8959. total += count;
  8960. } else { // page leaf node
  8961. total++;
  8962. }
  8963. }));
  8964. }
  8965. if (!found) {
  8966. error('kid ref not found in parents kids');
  8967. }
  8968. return Promise.all(kidPromises).then(function () {
  8969. return [total, parentRef];
  8970. });
  8971. });
  8972. }
  8973. var total = 0;
  8974. function next(ref) {
  8975. return pagesBeforeRef(ref).then(function (args) {
  8976. if (!args) {
  8977. return total;
  8978. }
  8979. var count = args[0];
  8980. var parentRef = args[1];
  8981. total += count;
  8982. return next(parentRef);
  8983. });
  8984. }
  8985. return next(ref);
  8986. }
  8987. };
  8988. return Catalog;
  8989. })();
  8990. var XRef = (function XRefClosure() {
  8991. function XRef(stream, password) {
  8992. this.stream = stream;
  8993. this.entries = [];
  8994. this.xrefstms = {};
  8995. // prepare the XRef cache
  8996. this.cache = [];
  8997. this.password = password;
  8998. this.stats = {
  8999. streamTypes: [],
  9000. fontTypes: []
  9001. };
  9002. }
  9003. XRef.prototype = {
  9004. setStartXRef: function XRef_setStartXRef(startXRef) {
  9005. // Store the starting positions of xref tables as we process them
  9006. // so we can recover from missing data errors
  9007. this.startXRefQueue = [startXRef];
  9008. },
  9009. parse: function XRef_parse(recoveryMode) {
  9010. var trailerDict;
  9011. if (!recoveryMode) {
  9012. trailerDict = this.readXRef();
  9013. } else {
  9014. warn('Indexing all PDF objects');
  9015. trailerDict = this.indexObjects();
  9016. }
  9017. trailerDict.assignXref(this);
  9018. this.trailer = trailerDict;
  9019. var encrypt = trailerDict.get('Encrypt');
  9020. if (encrypt) {
  9021. var ids = trailerDict.get('ID');
  9022. var fileId = (ids && ids.length) ? ids[0] : '';
  9023. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9024. this.password);
  9025. }
  9026. // get the root dictionary (catalog) object
  9027. if (!(this.root = trailerDict.get('Root'))) {
  9028. error('Invalid root reference');
  9029. }
  9030. },
  9031. processXRefTable: function XRef_processXRefTable(parser) {
  9032. if (!('tableState' in this)) {
  9033. // Stores state of the table as we process it so we can resume
  9034. // from middle of table in case of missing data error
  9035. this.tableState = {
  9036. entryNum: 0,
  9037. streamPos: parser.lexer.stream.pos,
  9038. parserBuf1: parser.buf1,
  9039. parserBuf2: parser.buf2
  9040. };
  9041. }
  9042. var obj = this.readXRefTable(parser);
  9043. // Sanity check
  9044. if (!isCmd(obj, 'trailer')) {
  9045. error('Invalid XRef table: could not find trailer dictionary');
  9046. }
  9047. // Read trailer dictionary, e.g.
  9048. // trailer
  9049. // << /Size 22
  9050. // /Root 20R
  9051. // /Info 10R
  9052. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9053. // >>
  9054. // The parser goes through the entire stream << ... >> and provides
  9055. // a getter interface for the key-value table
  9056. var dict = parser.getObj();
  9057. // The pdflib PDF generator can generate a nested trailer dictionary
  9058. if (!isDict(dict) && dict.dict) {
  9059. dict = dict.dict;
  9060. }
  9061. if (!isDict(dict)) {
  9062. error('Invalid XRef table: could not parse trailer dictionary');
  9063. }
  9064. delete this.tableState;
  9065. return dict;
  9066. },
  9067. readXRefTable: function XRef_readXRefTable(parser) {
  9068. // Example of cross-reference table:
  9069. // xref
  9070. // 0 1 <-- subsection header (first obj #, obj count)
  9071. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9072. // 23 2 <-- subsection header ... and so on ...
  9073. // 0000025518 00002 n
  9074. // 0000025635 00000 n
  9075. // trailer
  9076. // ...
  9077. var stream = parser.lexer.stream;
  9078. var tableState = this.tableState;
  9079. stream.pos = tableState.streamPos;
  9080. parser.buf1 = tableState.parserBuf1;
  9081. parser.buf2 = tableState.parserBuf2;
  9082. // Outer loop is over subsection headers
  9083. var obj;
  9084. while (true) {
  9085. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9086. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9087. break;
  9088. }
  9089. tableState.firstEntryNum = obj;
  9090. tableState.entryCount = parser.getObj();
  9091. }
  9092. var first = tableState.firstEntryNum;
  9093. var count = tableState.entryCount;
  9094. if (!isInt(first) || !isInt(count)) {
  9095. error('Invalid XRef table: wrong types in subsection header');
  9096. }
  9097. // Inner loop is over objects themselves
  9098. for (var i = tableState.entryNum; i < count; i++) {
  9099. tableState.streamPos = stream.pos;
  9100. tableState.entryNum = i;
  9101. tableState.parserBuf1 = parser.buf1;
  9102. tableState.parserBuf2 = parser.buf2;
  9103. var entry = {};
  9104. entry.offset = parser.getObj();
  9105. entry.gen = parser.getObj();
  9106. var type = parser.getObj();
  9107. if (isCmd(type, 'f')) {
  9108. entry.free = true;
  9109. } else if (isCmd(type, 'n')) {
  9110. entry.uncompressed = true;
  9111. }
  9112. // Validate entry obj
  9113. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9114. !(entry.free || entry.uncompressed)) {
  9115. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9116. }
  9117. if (!this.entries[i + first]) {
  9118. this.entries[i + first] = entry;
  9119. }
  9120. }
  9121. tableState.entryNum = 0;
  9122. tableState.streamPos = stream.pos;
  9123. tableState.parserBuf1 = parser.buf1;
  9124. tableState.parserBuf2 = parser.buf2;
  9125. delete tableState.firstEntryNum;
  9126. delete tableState.entryCount;
  9127. }
  9128. // Per issue 3248: hp scanners generate bad XRef
  9129. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9130. // shifting the entries
  9131. this.entries.shift();
  9132. }
  9133. // Sanity check: as per spec, first object must be free
  9134. if (this.entries[0] && !this.entries[0].free) {
  9135. error('Invalid XRef table: unexpected first object');
  9136. }
  9137. return obj;
  9138. },
  9139. processXRefStream: function XRef_processXRefStream(stream) {
  9140. if (!('streamState' in this)) {
  9141. // Stores state of the stream as we process it so we can resume
  9142. // from middle of stream in case of missing data error
  9143. var streamParameters = stream.dict;
  9144. var byteWidths = streamParameters.get('W');
  9145. var range = streamParameters.get('Index');
  9146. if (!range) {
  9147. range = [0, streamParameters.get('Size')];
  9148. }
  9149. this.streamState = {
  9150. entryRanges: range,
  9151. byteWidths: byteWidths,
  9152. entryNum: 0,
  9153. streamPos: stream.pos
  9154. };
  9155. }
  9156. this.readXRefStream(stream);
  9157. delete this.streamState;
  9158. return stream.dict;
  9159. },
  9160. readXRefStream: function XRef_readXRefStream(stream) {
  9161. var i, j;
  9162. var streamState = this.streamState;
  9163. stream.pos = streamState.streamPos;
  9164. var byteWidths = streamState.byteWidths;
  9165. var typeFieldWidth = byteWidths[0];
  9166. var offsetFieldWidth = byteWidths[1];
  9167. var generationFieldWidth = byteWidths[2];
  9168. var entryRanges = streamState.entryRanges;
  9169. while (entryRanges.length > 0) {
  9170. var first = entryRanges[0];
  9171. var n = entryRanges[1];
  9172. if (!isInt(first) || !isInt(n)) {
  9173. error('Invalid XRef range fields: ' + first + ', ' + n);
  9174. }
  9175. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9176. !isInt(generationFieldWidth)) {
  9177. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9178. }
  9179. for (i = streamState.entryNum; i < n; ++i) {
  9180. streamState.entryNum = i;
  9181. streamState.streamPos = stream.pos;
  9182. var type = 0, offset = 0, generation = 0;
  9183. for (j = 0; j < typeFieldWidth; ++j) {
  9184. type = (type << 8) | stream.getByte();
  9185. }
  9186. // if type field is absent, its default value is 1
  9187. if (typeFieldWidth === 0) {
  9188. type = 1;
  9189. }
  9190. for (j = 0; j < offsetFieldWidth; ++j) {
  9191. offset = (offset << 8) | stream.getByte();
  9192. }
  9193. for (j = 0; j < generationFieldWidth; ++j) {
  9194. generation = (generation << 8) | stream.getByte();
  9195. }
  9196. var entry = {};
  9197. entry.offset = offset;
  9198. entry.gen = generation;
  9199. switch (type) {
  9200. case 0:
  9201. entry.free = true;
  9202. break;
  9203. case 1:
  9204. entry.uncompressed = true;
  9205. break;
  9206. case 2:
  9207. break;
  9208. default:
  9209. error('Invalid XRef entry type: ' + type);
  9210. }
  9211. if (!this.entries[first + i]) {
  9212. this.entries[first + i] = entry;
  9213. }
  9214. }
  9215. streamState.entryNum = 0;
  9216. streamState.streamPos = stream.pos;
  9217. entryRanges.splice(0, 2);
  9218. }
  9219. },
  9220. indexObjects: function XRef_indexObjects() {
  9221. // Simple scan through the PDF content to find objects,
  9222. // trailers and XRef streams.
  9223. function readToken(data, offset) {
  9224. var token = '', ch = data[offset];
  9225. while (ch !== 13 && ch !== 10) {
  9226. if (++offset >= data.length) {
  9227. break;
  9228. }
  9229. token += String.fromCharCode(ch);
  9230. ch = data[offset];
  9231. }
  9232. return token;
  9233. }
  9234. function skipUntil(data, offset, what) {
  9235. var length = what.length, dataLength = data.length;
  9236. var skipped = 0;
  9237. // finding byte sequence
  9238. while (offset < dataLength) {
  9239. var i = 0;
  9240. while (i < length && data[offset + i] === what[i]) {
  9241. ++i;
  9242. }
  9243. if (i >= length) {
  9244. break; // sequence found
  9245. }
  9246. offset++;
  9247. skipped++;
  9248. }
  9249. return skipped;
  9250. }
  9251. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9252. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9253. 101, 102]);
  9254. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9255. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9256. var stream = this.stream;
  9257. stream.pos = 0;
  9258. var buffer = stream.getBytes();
  9259. var position = stream.start, length = buffer.length;
  9260. var trailers = [], xrefStms = [];
  9261. while (position < length) {
  9262. var ch = buffer[position];
  9263. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9264. ++position;
  9265. continue;
  9266. }
  9267. if (ch === 37) { // %-comment
  9268. do {
  9269. ++position;
  9270. if (position >= length) {
  9271. break;
  9272. }
  9273. ch = buffer[position];
  9274. } while (ch !== 13 && ch !== 10);
  9275. continue;
  9276. }
  9277. var token = readToken(buffer, position);
  9278. var m;
  9279. if (token === 'xref') {
  9280. position += skipUntil(buffer, position, trailerBytes);
  9281. trailers.push(position);
  9282. position += skipUntil(buffer, position, startxrefBytes);
  9283. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9284. this.entries[m[1]] = {
  9285. offset: position,
  9286. gen: m[2] | 0,
  9287. uncompressed: true
  9288. };
  9289. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9290. var content = buffer.subarray(position, position + contentLength);
  9291. // checking XRef stream suspect
  9292. // (it shall have '/XRef' and next char is not a letter)
  9293. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9294. if (xrefTagOffset < contentLength &&
  9295. content[xrefTagOffset + 5] < 64) {
  9296. xrefStms.push(position);
  9297. this.xrefstms[position] = 1; // don't read it recursively
  9298. }
  9299. position += contentLength;
  9300. } else {
  9301. position += token.length + 1;
  9302. }
  9303. }
  9304. // reading XRef streams
  9305. var i, ii;
  9306. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9307. this.startXRefQueue.push(xrefStms[i]);
  9308. this.readXRef(/* recoveryMode */ true);
  9309. }
  9310. // finding main trailer
  9311. var dict;
  9312. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9313. stream.pos = trailers[i];
  9314. var parser = new Parser(new Lexer(stream), true, this);
  9315. var obj = parser.getObj();
  9316. if (!isCmd(obj, 'trailer')) {
  9317. continue;
  9318. }
  9319. // read the trailer dictionary
  9320. if (!isDict(dict = parser.getObj())) {
  9321. continue;
  9322. }
  9323. // taking the first one with 'ID'
  9324. if (dict.has('ID')) {
  9325. return dict;
  9326. }
  9327. }
  9328. // no tailer with 'ID', taking last one (if exists)
  9329. if (dict) {
  9330. return dict;
  9331. }
  9332. // nothing helps
  9333. // calling error() would reject worker with an UnknownErrorException.
  9334. throw new InvalidPDFException('Invalid PDF structure');
  9335. },
  9336. readXRef: function XRef_readXRef(recoveryMode) {
  9337. var stream = this.stream;
  9338. try {
  9339. while (this.startXRefQueue.length) {
  9340. var startXRef = this.startXRefQueue[0];
  9341. stream.pos = startXRef + stream.start;
  9342. var parser = new Parser(new Lexer(stream), true, this);
  9343. var obj = parser.getObj();
  9344. var dict;
  9345. // Get dictionary
  9346. if (isCmd(obj, 'xref')) {
  9347. // Parse end-of-file XRef
  9348. dict = this.processXRefTable(parser);
  9349. if (!this.topDict) {
  9350. this.topDict = dict;
  9351. }
  9352. // Recursively get other XRefs 'XRefStm', if any
  9353. obj = dict.get('XRefStm');
  9354. if (isInt(obj)) {
  9355. var pos = obj;
  9356. // ignore previously loaded xref streams
  9357. // (possible infinite recursion)
  9358. if (!(pos in this.xrefstms)) {
  9359. this.xrefstms[pos] = 1;
  9360. this.startXRefQueue.push(pos);
  9361. }
  9362. }
  9363. } else if (isInt(obj)) {
  9364. // Parse in-stream XRef
  9365. if (!isInt(parser.getObj()) ||
  9366. !isCmd(parser.getObj(), 'obj') ||
  9367. !isStream(obj = parser.getObj())) {
  9368. error('Invalid XRef stream');
  9369. }
  9370. dict = this.processXRefStream(obj);
  9371. if (!this.topDict) {
  9372. this.topDict = dict;
  9373. }
  9374. if (!dict) {
  9375. error('Failed to read XRef stream');
  9376. }
  9377. } else {
  9378. error('Invalid XRef stream header');
  9379. }
  9380. // Recursively get previous dictionary, if any
  9381. obj = dict.get('Prev');
  9382. if (isInt(obj)) {
  9383. this.startXRefQueue.push(obj);
  9384. } else if (isRef(obj)) {
  9385. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9386. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9387. this.startXRefQueue.push(obj.num);
  9388. }
  9389. this.startXRefQueue.shift();
  9390. }
  9391. return this.topDict;
  9392. } catch (e) {
  9393. if (e instanceof MissingDataException) {
  9394. throw e;
  9395. }
  9396. info('(while reading XRef): ' + e);
  9397. }
  9398. if (recoveryMode) {
  9399. return;
  9400. }
  9401. throw new XRefParseException();
  9402. },
  9403. getEntry: function XRef_getEntry(i) {
  9404. var xrefEntry = this.entries[i];
  9405. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9406. return xrefEntry;
  9407. }
  9408. return null;
  9409. },
  9410. fetchIfRef: function XRef_fetchIfRef(obj) {
  9411. if (!isRef(obj)) {
  9412. return obj;
  9413. }
  9414. return this.fetch(obj);
  9415. },
  9416. fetch: function XRef_fetch(ref, suppressEncryption) {
  9417. assert(isRef(ref), 'ref object is not a reference');
  9418. var num = ref.num;
  9419. if (num in this.cache) {
  9420. var cacheEntry = this.cache[num];
  9421. return cacheEntry;
  9422. }
  9423. var xrefEntry = this.getEntry(num);
  9424. // the referenced entry can be free
  9425. if (xrefEntry === null) {
  9426. return (this.cache[num] = null);
  9427. }
  9428. if (xrefEntry.uncompressed) {
  9429. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9430. } else {
  9431. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9432. }
  9433. if (isDict(xrefEntry)){
  9434. xrefEntry.objId = ref.toString();
  9435. } else if (isStream(xrefEntry)) {
  9436. xrefEntry.dict.objId = ref.toString();
  9437. }
  9438. return xrefEntry;
  9439. },
  9440. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9441. suppressEncryption) {
  9442. var gen = ref.gen;
  9443. var num = ref.num;
  9444. if (xrefEntry.gen !== gen) {
  9445. error('inconsistent generation in XRef');
  9446. }
  9447. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9448. this.stream.start);
  9449. var parser = new Parser(new Lexer(stream), true, this);
  9450. var obj1 = parser.getObj();
  9451. var obj2 = parser.getObj();
  9452. var obj3 = parser.getObj();
  9453. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9454. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9455. !isCmd(obj3)) {
  9456. error('bad XRef entry');
  9457. }
  9458. if (!isCmd(obj3, 'obj')) {
  9459. // some bad PDFs use "obj1234" and really mean 1234
  9460. if (obj3.cmd.indexOf('obj') === 0) {
  9461. num = parseInt(obj3.cmd.substring(3), 10);
  9462. if (!isNaN(num)) {
  9463. return num;
  9464. }
  9465. }
  9466. error('bad XRef entry');
  9467. }
  9468. if (this.encrypt && !suppressEncryption) {
  9469. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9470. } else {
  9471. xrefEntry = parser.getObj();
  9472. }
  9473. if (!isStream(xrefEntry)) {
  9474. this.cache[num] = xrefEntry;
  9475. }
  9476. return xrefEntry;
  9477. },
  9478. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9479. suppressEncryption) {
  9480. var tableOffset = xrefEntry.offset;
  9481. var stream = this.fetch(new Ref(tableOffset, 0));
  9482. if (!isStream(stream)) {
  9483. error('bad ObjStm stream');
  9484. }
  9485. var first = stream.dict.get('First');
  9486. var n = stream.dict.get('N');
  9487. if (!isInt(first) || !isInt(n)) {
  9488. error('invalid first and n parameters for ObjStm stream');
  9489. }
  9490. var parser = new Parser(new Lexer(stream), false, this);
  9491. parser.allowStreams = true;
  9492. var i, entries = [], num, nums = [];
  9493. // read the object numbers to populate cache
  9494. for (i = 0; i < n; ++i) {
  9495. num = parser.getObj();
  9496. if (!isInt(num)) {
  9497. error('invalid object number in the ObjStm stream: ' + num);
  9498. }
  9499. nums.push(num);
  9500. var offset = parser.getObj();
  9501. if (!isInt(offset)) {
  9502. error('invalid object offset in the ObjStm stream: ' + offset);
  9503. }
  9504. }
  9505. // read stream objects for cache
  9506. for (i = 0; i < n; ++i) {
  9507. entries.push(parser.getObj());
  9508. num = nums[i];
  9509. var entry = this.entries[num];
  9510. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9511. this.cache[num] = entries[i];
  9512. }
  9513. }
  9514. xrefEntry = entries[xrefEntry.gen];
  9515. if (xrefEntry === undefined) {
  9516. error('bad XRef entry for compressed object');
  9517. }
  9518. return xrefEntry;
  9519. },
  9520. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9521. if (!isRef(obj)) {
  9522. return Promise.resolve(obj);
  9523. }
  9524. return this.fetchAsync(obj);
  9525. },
  9526. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9527. var streamManager = this.stream.manager;
  9528. var xref = this;
  9529. return new Promise(function tryFetch(resolve, reject) {
  9530. try {
  9531. resolve(xref.fetch(ref, suppressEncryption));
  9532. } catch (e) {
  9533. if (e instanceof MissingDataException) {
  9534. streamManager.requestRange(e.begin, e.end, function () {
  9535. tryFetch(resolve, reject);
  9536. });
  9537. return;
  9538. }
  9539. reject(e);
  9540. }
  9541. });
  9542. },
  9543. getCatalogObj: function XRef_getCatalogObj() {
  9544. return this.root;
  9545. }
  9546. };
  9547. return XRef;
  9548. })();
  9549. /**
  9550. * A NameTree is like a Dict but has some advantageous properties, see the
  9551. * spec (7.9.6) for more details.
  9552. * TODO: implement all the Dict functions and make this more efficent.
  9553. */
  9554. var NameTree = (function NameTreeClosure() {
  9555. function NameTree(root, xref) {
  9556. this.root = root;
  9557. this.xref = xref;
  9558. }
  9559. NameTree.prototype = {
  9560. getAll: function NameTree_getAll() {
  9561. var dict = {};
  9562. if (!this.root) {
  9563. return dict;
  9564. }
  9565. var xref = this.xref;
  9566. // reading name tree
  9567. var processed = new RefSet();
  9568. processed.put(this.root);
  9569. var queue = [this.root];
  9570. while (queue.length > 0) {
  9571. var i, n;
  9572. var obj = xref.fetchIfRef(queue.shift());
  9573. if (!isDict(obj)) {
  9574. continue;
  9575. }
  9576. if (obj.has('Kids')) {
  9577. var kids = obj.get('Kids');
  9578. for (i = 0, n = kids.length; i < n; i++) {
  9579. var kid = kids[i];
  9580. if (processed.has(kid)) {
  9581. error('invalid destinations');
  9582. }
  9583. queue.push(kid);
  9584. processed.put(kid);
  9585. }
  9586. continue;
  9587. }
  9588. var names = obj.get('Names');
  9589. if (names) {
  9590. for (i = 0, n = names.length; i < n; i += 2) {
  9591. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9592. }
  9593. }
  9594. }
  9595. return dict;
  9596. },
  9597. get: function NameTree_get(destinationId) {
  9598. if (!this.root) {
  9599. return null;
  9600. }
  9601. var xref = this.xref;
  9602. var kidsOrNames = xref.fetchIfRef(this.root);
  9603. var loopCount = 0;
  9604. var MAX_NAMES_LEVELS = 10;
  9605. var l, r, m;
  9606. // Perform a binary search to quickly find the entry that
  9607. // contains the named destination we are looking for.
  9608. while (kidsOrNames.has('Kids')) {
  9609. loopCount++;
  9610. if (loopCount > MAX_NAMES_LEVELS) {
  9611. warn('Search depth limit for named destionations has been reached.');
  9612. return null;
  9613. }
  9614. var kids = kidsOrNames.get('Kids');
  9615. if (!isArray(kids)) {
  9616. return null;
  9617. }
  9618. l = 0;
  9619. r = kids.length - 1;
  9620. while (l <= r) {
  9621. m = (l + r) >> 1;
  9622. var kid = xref.fetchIfRef(kids[m]);
  9623. var limits = kid.get('Limits');
  9624. if (destinationId < limits[0]) {
  9625. r = m - 1;
  9626. } else if (destinationId > limits[1]) {
  9627. l = m + 1;
  9628. } else {
  9629. kidsOrNames = xref.fetchIfRef(kids[m]);
  9630. break;
  9631. }
  9632. }
  9633. if (l > r) {
  9634. return null;
  9635. }
  9636. }
  9637. // If we get here, then we have found the right entry. Now
  9638. // go through the named destinations in the Named dictionary
  9639. // until we find the exact destination we're looking for.
  9640. var names = kidsOrNames.get('Names');
  9641. if (isArray(names)) {
  9642. // Perform a binary search to reduce the lookup time.
  9643. l = 0;
  9644. r = names.length - 2;
  9645. while (l <= r) {
  9646. // Check only even indices (0, 2, 4, ...) because the
  9647. // odd indices contain the actual D array.
  9648. m = (l + r) & ~1;
  9649. if (destinationId < names[m]) {
  9650. r = m - 2;
  9651. } else if (destinationId > names[m]) {
  9652. l = m + 2;
  9653. } else {
  9654. return xref.fetchIfRef(names[m + 1]);
  9655. }
  9656. }
  9657. }
  9658. return null;
  9659. }
  9660. };
  9661. return NameTree;
  9662. })();
  9663. /**
  9664. * "A PDF file can refer to the contents of another file by using a File
  9665. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9666. * NOTE: Only embedded files are supported (as part of the attachments support)
  9667. * TODO: support the 'URL' file system (with caching if !/V), portable
  9668. * collections attributes and related files (/RF)
  9669. */
  9670. var FileSpec = (function FileSpecClosure() {
  9671. function FileSpec(root, xref) {
  9672. if (!root || !isDict(root)) {
  9673. return;
  9674. }
  9675. this.xref = xref;
  9676. this.root = root;
  9677. if (root.has('FS')) {
  9678. this.fs = root.get('FS');
  9679. }
  9680. this.description = root.has('Desc') ?
  9681. stringToPDFString(root.get('Desc')) :
  9682. '';
  9683. if (root.has('RF')) {
  9684. warn('Related file specifications are not supported');
  9685. }
  9686. this.contentAvailable = true;
  9687. if (!root.has('EF')) {
  9688. this.contentAvailable = false;
  9689. warn('Non-embedded file specifications are not supported');
  9690. }
  9691. }
  9692. function pickPlatformItem(dict) {
  9693. // Look for the filename in this order:
  9694. // UF, F, Unix, Mac, DOS
  9695. if (dict.has('UF')) {
  9696. return dict.get('UF');
  9697. } else if (dict.has('F')) {
  9698. return dict.get('F');
  9699. } else if (dict.has('Unix')) {
  9700. return dict.get('Unix');
  9701. } else if (dict.has('Mac')) {
  9702. return dict.get('Mac');
  9703. } else if (dict.has('DOS')) {
  9704. return dict.get('DOS');
  9705. } else {
  9706. return null;
  9707. }
  9708. }
  9709. FileSpec.prototype = {
  9710. get filename() {
  9711. if (!this._filename && this.root) {
  9712. var filename = pickPlatformItem(this.root) || 'unnamed';
  9713. this._filename = stringToPDFString(filename).
  9714. replace(/\\\\/g, '\\').
  9715. replace(/\\\//g, '/').
  9716. replace(/\\/g, '/');
  9717. }
  9718. return this._filename;
  9719. },
  9720. get content() {
  9721. if (!this.contentAvailable) {
  9722. return null;
  9723. }
  9724. if (!this.contentRef && this.root) {
  9725. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9726. }
  9727. var content = null;
  9728. if (this.contentRef) {
  9729. var xref = this.xref;
  9730. var fileObj = xref.fetchIfRef(this.contentRef);
  9731. if (fileObj && isStream(fileObj)) {
  9732. content = fileObj.getBytes();
  9733. } else {
  9734. warn('Embedded file specification points to non-existing/invalid ' +
  9735. 'content');
  9736. }
  9737. } else {
  9738. warn('Embedded file specification does not have a content');
  9739. }
  9740. return content;
  9741. },
  9742. get serializable() {
  9743. return {
  9744. filename: this.filename,
  9745. content: this.content
  9746. };
  9747. }
  9748. };
  9749. return FileSpec;
  9750. })();
  9751. /**
  9752. * A helper for loading missing data in object graphs. It traverses the graph
  9753. * depth first and queues up any objects that have missing data. Once it has
  9754. * has traversed as many objects that are available it attempts to bundle the
  9755. * missing data requests and then resume from the nodes that weren't ready.
  9756. *
  9757. * NOTE: It provides protection from circular references by keeping track of
  9758. * of loaded references. However, you must be careful not to load any graphs
  9759. * that have references to the catalog or other pages since that will cause the
  9760. * entire PDF document object graph to be traversed.
  9761. */
  9762. var ObjectLoader = (function() {
  9763. function mayHaveChildren(value) {
  9764. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9765. }
  9766. function addChildren(node, nodesToVisit) {
  9767. var value;
  9768. if (isDict(node) || isStream(node)) {
  9769. var map;
  9770. if (isDict(node)) {
  9771. map = node.map;
  9772. } else {
  9773. map = node.dict.map;
  9774. }
  9775. for (var key in map) {
  9776. value = map[key];
  9777. if (mayHaveChildren(value)) {
  9778. nodesToVisit.push(value);
  9779. }
  9780. }
  9781. } else if (isArray(node)) {
  9782. for (var i = 0, ii = node.length; i < ii; i++) {
  9783. value = node[i];
  9784. if (mayHaveChildren(value)) {
  9785. nodesToVisit.push(value);
  9786. }
  9787. }
  9788. }
  9789. }
  9790. function ObjectLoader(obj, keys, xref) {
  9791. this.obj = obj;
  9792. this.keys = keys;
  9793. this.xref = xref;
  9794. this.refSet = null;
  9795. }
  9796. ObjectLoader.prototype = {
  9797. load: function ObjectLoader_load() {
  9798. var keys = this.keys;
  9799. this.capability = createPromiseCapability();
  9800. // Don't walk the graph if all the data is already loaded.
  9801. if (!(this.xref.stream instanceof ChunkedStream) ||
  9802. this.xref.stream.getMissingChunks().length === 0) {
  9803. this.capability.resolve();
  9804. return this.capability.promise;
  9805. }
  9806. this.refSet = new RefSet();
  9807. // Setup the initial nodes to visit.
  9808. var nodesToVisit = [];
  9809. for (var i = 0; i < keys.length; i++) {
  9810. nodesToVisit.push(this.obj[keys[i]]);
  9811. }
  9812. this.walk(nodesToVisit);
  9813. return this.capability.promise;
  9814. },
  9815. walk: function ObjectLoader_walk(nodesToVisit) {
  9816. var nodesToRevisit = [];
  9817. var pendingRequests = [];
  9818. // DFS walk of the object graph.
  9819. while (nodesToVisit.length) {
  9820. var currentNode = nodesToVisit.pop();
  9821. // Only references or chunked streams can cause missing data exceptions.
  9822. if (isRef(currentNode)) {
  9823. // Skip nodes that have already been visited.
  9824. if (this.refSet.has(currentNode)) {
  9825. continue;
  9826. }
  9827. try {
  9828. var ref = currentNode;
  9829. this.refSet.put(ref);
  9830. currentNode = this.xref.fetch(currentNode);
  9831. } catch (e) {
  9832. if (!(e instanceof MissingDataException)) {
  9833. throw e;
  9834. }
  9835. nodesToRevisit.push(currentNode);
  9836. pendingRequests.push({ begin: e.begin, end: e.end });
  9837. }
  9838. }
  9839. if (currentNode && currentNode.getBaseStreams) {
  9840. var baseStreams = currentNode.getBaseStreams();
  9841. var foundMissingData = false;
  9842. for (var i = 0; i < baseStreams.length; i++) {
  9843. var stream = baseStreams[i];
  9844. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9845. foundMissingData = true;
  9846. pendingRequests.push({
  9847. begin: stream.start,
  9848. end: stream.end
  9849. });
  9850. }
  9851. }
  9852. if (foundMissingData) {
  9853. nodesToRevisit.push(currentNode);
  9854. }
  9855. }
  9856. addChildren(currentNode, nodesToVisit);
  9857. }
  9858. if (pendingRequests.length) {
  9859. this.xref.stream.manager.requestRanges(pendingRequests,
  9860. function pendingRequestCallback() {
  9861. nodesToVisit = nodesToRevisit;
  9862. for (var i = 0; i < nodesToRevisit.length; i++) {
  9863. var node = nodesToRevisit[i];
  9864. // Remove any reference nodes from the currrent refset so they
  9865. // aren't skipped when we revist them.
  9866. if (isRef(node)) {
  9867. this.refSet.remove(node);
  9868. }
  9869. }
  9870. this.walk(nodesToVisit);
  9871. }.bind(this));
  9872. return;
  9873. }
  9874. // Everything is loaded.
  9875. this.refSet = null;
  9876. this.capability.resolve();
  9877. }
  9878. };
  9879. return ObjectLoader;
  9880. })();
  9881. var ISOAdobeCharset = [
  9882. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9883. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9884. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9885. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9886. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9887. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9888. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9889. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9890. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9891. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9892. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9893. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9894. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9895. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9896. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9897. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9898. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9899. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9900. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9901. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9902. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9903. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9904. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9905. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9906. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9907. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9908. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9909. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9910. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9911. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9912. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9913. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9914. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9915. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9916. ];
  9917. var ExpertCharset = [
  9918. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9919. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9920. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9921. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9922. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9923. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9924. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9925. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9926. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9927. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9928. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9929. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9930. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9931. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9932. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9933. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9934. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9935. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9936. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9937. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9938. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9939. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9940. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9941. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9942. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9943. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9944. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9945. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9946. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9947. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9948. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9949. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9950. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9951. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9952. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9953. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9954. 'Ydieresissmall'
  9955. ];
  9956. var ExpertSubsetCharset = [
  9957. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9958. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9959. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9960. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9961. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9962. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9963. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9964. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9965. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9966. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9967. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9968. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9969. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9970. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9971. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9972. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9973. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9974. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9975. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9976. 'periodinferior', 'commainferior'
  9977. ];
  9978. var DEFAULT_ICON_SIZE = 22; // px
  9979. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9980. var Annotation = (function AnnotationClosure() {
  9981. // 12.5.5: Algorithm: Appearance streams
  9982. function getTransformMatrix(rect, bbox, matrix) {
  9983. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9984. var minX = bounds[0];
  9985. var minY = bounds[1];
  9986. var maxX = bounds[2];
  9987. var maxY = bounds[3];
  9988. if (minX === maxX || minY === maxY) {
  9989. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9990. // just apply the transform for rect
  9991. return [1, 0, 0, 1, rect[0], rect[1]];
  9992. }
  9993. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9994. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9995. return [
  9996. xRatio,
  9997. 0,
  9998. 0,
  9999. yRatio,
  10000. rect[0] - minX * xRatio,
  10001. rect[1] - minY * yRatio
  10002. ];
  10003. }
  10004. function getDefaultAppearance(dict) {
  10005. var appearanceState = dict.get('AP');
  10006. if (!isDict(appearanceState)) {
  10007. return;
  10008. }
  10009. var appearance;
  10010. var appearances = appearanceState.get('N');
  10011. if (isDict(appearances)) {
  10012. var as = dict.get('AS');
  10013. if (as && appearances.has(as.name)) {
  10014. appearance = appearances.get(as.name);
  10015. }
  10016. } else {
  10017. appearance = appearances;
  10018. }
  10019. return appearance;
  10020. }
  10021. function Annotation(params) {
  10022. var dict = params.dict;
  10023. var data = this.data = {};
  10024. data.subtype = dict.get('Subtype').name;
  10025. var rect = dict.get('Rect') || [0, 0, 0, 0];
  10026. data.rect = Util.normalizeRect(rect);
  10027. data.annotationFlags = dict.get('F');
  10028. var color = dict.get('C');
  10029. if (!color) {
  10030. // The PDF spec does not mention how a missing color array is interpreted.
  10031. // Adobe Reader seems to default to black in this case.
  10032. data.color = [0, 0, 0];
  10033. } else if (isArray(color)) {
  10034. switch (color.length) {
  10035. case 0:
  10036. // Empty array denotes transparent border.
  10037. data.color = null;
  10038. break;
  10039. case 1:
  10040. // TODO: implement DeviceGray
  10041. break;
  10042. case 3:
  10043. data.color = color;
  10044. break;
  10045. case 4:
  10046. // TODO: implement DeviceCMYK
  10047. break;
  10048. }
  10049. }
  10050. // Some types of annotations have border style dict which has more
  10051. // info than the border array
  10052. if (dict.has('BS')) {
  10053. var borderStyle = dict.get('BS');
  10054. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  10055. } else {
  10056. var borderArray = dict.get('Border') || [0, 0, 1];
  10057. data.borderWidth = borderArray[2] || 0;
  10058. // TODO: implement proper support for annotations with line dash patterns.
  10059. var dashArray = borderArray[3];
  10060. if (data.borderWidth > 0 && dashArray) {
  10061. if (!isArray(dashArray)) {
  10062. // Ignore the border if dashArray is not actually an array,
  10063. // this is consistent with the behaviour in Adobe Reader.
  10064. data.borderWidth = 0;
  10065. } else {
  10066. var dashArrayLength = dashArray.length;
  10067. if (dashArrayLength > 0) {
  10068. // According to the PDF specification: the elements in a dashArray
  10069. // shall be numbers that are nonnegative and not all equal to zero.
  10070. var isInvalid = false;
  10071. var numPositive = 0;
  10072. for (var i = 0; i < dashArrayLength; i++) {
  10073. var validNumber = (+dashArray[i] >= 0);
  10074. if (!validNumber) {
  10075. isInvalid = true;
  10076. break;
  10077. } else if (dashArray[i] > 0) {
  10078. numPositive++;
  10079. }
  10080. }
  10081. if (isInvalid || numPositive === 0) {
  10082. data.borderWidth = 0;
  10083. }
  10084. }
  10085. }
  10086. }
  10087. }
  10088. this.appearance = getDefaultAppearance(dict);
  10089. data.hasAppearance = !!this.appearance;
  10090. data.id = params.ref.num;
  10091. }
  10092. Annotation.prototype = {
  10093. getData: function Annotation_getData() {
  10094. return this.data;
  10095. },
  10096. isInvisible: function Annotation_isInvisible() {
  10097. var data = this.data;
  10098. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  10099. return false;
  10100. } else {
  10101. return !!(data &&
  10102. data.annotationFlags && // Default: not invisible
  10103. data.annotationFlags & 0x1); // Invisible
  10104. }
  10105. },
  10106. isViewable: function Annotation_isViewable() {
  10107. var data = this.data;
  10108. return !!(!this.isInvisible() &&
  10109. data &&
  10110. (!data.annotationFlags ||
  10111. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10112. data.rect); // rectangle is necessary
  10113. },
  10114. isPrintable: function Annotation_isPrintable() {
  10115. var data = this.data;
  10116. return !!(!this.isInvisible() &&
  10117. data &&
  10118. data.annotationFlags && // Default: not printable
  10119. data.annotationFlags & 0x4 && // Print
  10120. !(data.annotationFlags & 0x2) && // Hidden
  10121. data.rect); // rectangle is necessary
  10122. },
  10123. loadResources: function Annotation_loadResources(keys) {
  10124. return new Promise(function (resolve, reject) {
  10125. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10126. if (!resources) {
  10127. resolve();
  10128. return;
  10129. }
  10130. var objectLoader = new ObjectLoader(resources.map,
  10131. keys,
  10132. resources.xref);
  10133. objectLoader.load().then(function() {
  10134. resolve(resources);
  10135. }, reject);
  10136. }, reject);
  10137. }.bind(this));
  10138. },
  10139. getOperatorList: function Annotation_getOperatorList(evaluator) {
  10140. if (!this.appearance) {
  10141. return Promise.resolve(new OperatorList());
  10142. }
  10143. var data = this.data;
  10144. var appearanceDict = this.appearance.dict;
  10145. var resourcesPromise = this.loadResources([
  10146. 'ExtGState',
  10147. 'ColorSpace',
  10148. 'Pattern',
  10149. 'Shading',
  10150. 'XObject',
  10151. 'Font'
  10152. // ProcSet
  10153. // Properties
  10154. ]);
  10155. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10156. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10157. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10158. var self = this;
  10159. return resourcesPromise.then(function(resources) {
  10160. var opList = new OperatorList();
  10161. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10162. return evaluator.getOperatorList(self.appearance, resources, opList).
  10163. then(function () {
  10164. opList.addOp(OPS.endAnnotation, []);
  10165. self.appearance.reset();
  10166. return opList;
  10167. });
  10168. });
  10169. }
  10170. };
  10171. Annotation.getConstructor =
  10172. function Annotation_getConstructor(subtype, fieldType) {
  10173. if (!subtype) {
  10174. return;
  10175. }
  10176. // TODO(mack): Implement FreeText annotations
  10177. if (subtype === 'Link') {
  10178. return LinkAnnotation;
  10179. } else if (subtype === 'Text') {
  10180. return TextAnnotation;
  10181. } else if (subtype === 'Widget') {
  10182. if (!fieldType) {
  10183. return;
  10184. }
  10185. if (fieldType === 'Tx') {
  10186. return TextWidgetAnnotation;
  10187. } else {
  10188. return WidgetAnnotation;
  10189. }
  10190. } else {
  10191. return Annotation;
  10192. }
  10193. };
  10194. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  10195. var dict = xref.fetchIfRef(ref);
  10196. if (!isDict(dict)) {
  10197. return;
  10198. }
  10199. var subtype = dict.get('Subtype');
  10200. subtype = isName(subtype) ? subtype.name : '';
  10201. if (!subtype) {
  10202. return;
  10203. }
  10204. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10205. fieldType = isName(fieldType) ? fieldType.name : '';
  10206. var Constructor = Annotation.getConstructor(subtype, fieldType);
  10207. if (!Constructor) {
  10208. return;
  10209. }
  10210. var params = {
  10211. dict: dict,
  10212. ref: ref,
  10213. };
  10214. var annotation = new Constructor(params);
  10215. if (annotation.isViewable() || annotation.isPrintable()) {
  10216. return annotation;
  10217. } else {
  10218. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  10219. warn('unimplemented annotation type: ' + subtype);
  10220. }
  10221. }
  10222. };
  10223. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10224. annotations, opList, pdfManager, partialEvaluator, intent) {
  10225. function reject(e) {
  10226. annotationsReadyCapability.reject(e);
  10227. }
  10228. var annotationsReadyCapability = createPromiseCapability();
  10229. var annotationPromises = [];
  10230. for (var i = 0, n = annotations.length; i < n; ++i) {
  10231. if (intent === 'display' && annotations[i].isViewable() ||
  10232. intent === 'print' && annotations[i].isPrintable()) {
  10233. annotationPromises.push(
  10234. annotations[i].getOperatorList(partialEvaluator));
  10235. }
  10236. }
  10237. Promise.all(annotationPromises).then(function(datas) {
  10238. opList.addOp(OPS.beginAnnotations, []);
  10239. for (var i = 0, n = datas.length; i < n; ++i) {
  10240. var annotOpList = datas[i];
  10241. opList.addOpList(annotOpList);
  10242. }
  10243. opList.addOp(OPS.endAnnotations, []);
  10244. annotationsReadyCapability.resolve();
  10245. }, reject);
  10246. return annotationsReadyCapability.promise;
  10247. };
  10248. return Annotation;
  10249. })();
  10250. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10251. function WidgetAnnotation(params) {
  10252. Annotation.call(this, params);
  10253. var dict = params.dict;
  10254. var data = this.data;
  10255. data.fieldValue = stringToPDFString(
  10256. Util.getInheritableProperty(dict, 'V') || '');
  10257. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10258. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10259. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10260. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10261. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10262. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10263. // Building the full field name by collecting the field and
  10264. // its ancestors 'T' data and joining them using '.'.
  10265. var fieldName = [];
  10266. var namedItem = dict;
  10267. var ref = params.ref;
  10268. while (namedItem) {
  10269. var parent = namedItem.get('Parent');
  10270. var parentRef = namedItem.getRaw('Parent');
  10271. var name = namedItem.get('T');
  10272. if (name) {
  10273. fieldName.unshift(stringToPDFString(name));
  10274. } else if (parent && ref) {
  10275. // The field name is absent, that means more than one field
  10276. // with the same name may exist. Replacing the empty name
  10277. // with the '`' plus index in the parent's 'Kids' array.
  10278. // This is not in the PDF spec but necessary to id the
  10279. // the input controls.
  10280. var kids = parent.get('Kids');
  10281. var j, jj;
  10282. for (j = 0, jj = kids.length; j < jj; j++) {
  10283. var kidRef = kids[j];
  10284. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10285. break;
  10286. }
  10287. }
  10288. fieldName.unshift('`' + j);
  10289. }
  10290. namedItem = parent;
  10291. ref = parentRef;
  10292. }
  10293. data.fullName = fieldName.join('.');
  10294. }
  10295. var parent = Annotation.prototype;
  10296. Util.inherit(WidgetAnnotation, Annotation, {
  10297. isViewable: function WidgetAnnotation_isViewable() {
  10298. if (this.data.fieldType === 'Sig') {
  10299. warn('unimplemented annotation type: Widget signature');
  10300. return false;
  10301. }
  10302. return parent.isViewable.call(this);
  10303. }
  10304. });
  10305. return WidgetAnnotation;
  10306. })();
  10307. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10308. function TextWidgetAnnotation(params) {
  10309. WidgetAnnotation.call(this, params);
  10310. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10311. this.data.annotationType = AnnotationType.WIDGET;
  10312. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10313. }
  10314. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10315. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10316. if (this.appearance) {
  10317. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10318. }
  10319. var opList = new OperatorList();
  10320. var data = this.data;
  10321. // Even if there is an appearance stream, ignore it. This is the
  10322. // behaviour used by Adobe Reader.
  10323. if (!data.defaultAppearance) {
  10324. return Promise.resolve(opList);
  10325. }
  10326. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10327. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10328. then(function () {
  10329. return opList;
  10330. });
  10331. }
  10332. });
  10333. return TextWidgetAnnotation;
  10334. })();
  10335. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  10336. function InteractiveAnnotation(params) {
  10337. Annotation.call(this, params);
  10338. this.data.hasHtml = true;
  10339. }
  10340. Util.inherit(InteractiveAnnotation, Annotation, { });
  10341. return InteractiveAnnotation;
  10342. })();
  10343. var TextAnnotation = (function TextAnnotationClosure() {
  10344. function TextAnnotation(params) {
  10345. InteractiveAnnotation.call(this, params);
  10346. var dict = params.dict;
  10347. var data = this.data;
  10348. var content = dict.get('Contents');
  10349. var title = dict.get('T');
  10350. data.annotationType = AnnotationType.TEXT;
  10351. data.content = stringToPDFString(content || '');
  10352. data.title = stringToPDFString(title || '');
  10353. if (data.hasAppearance) {
  10354. data.name = 'NoIcon';
  10355. } else {
  10356. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10357. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10358. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10359. }
  10360. if (dict.has('C')) {
  10361. data.hasBgColor = true;
  10362. }
  10363. }
  10364. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10365. return TextAnnotation;
  10366. })();
  10367. var LinkAnnotation = (function LinkAnnotationClosure() {
  10368. function LinkAnnotation(params) {
  10369. InteractiveAnnotation.call(this, params);
  10370. var dict = params.dict;
  10371. var data = this.data;
  10372. data.annotationType = AnnotationType.LINK;
  10373. var action = dict.get('A');
  10374. if (action && isDict(action)) {
  10375. var linkType = action.get('S').name;
  10376. if (linkType === 'URI') {
  10377. var url = action.get('URI');
  10378. if (isName(url)) {
  10379. // Some bad PDFs do not put parentheses around relative URLs.
  10380. url = '/' + url.name;
  10381. } else if (url) {
  10382. url = addDefaultProtocolToUrl(url);
  10383. }
  10384. // TODO: pdf spec mentions urls can be relative to a Base
  10385. // entry in the dictionary.
  10386. if (!isValidUrl(url, false)) {
  10387. url = '';
  10388. }
  10389. data.url = url;
  10390. } else if (linkType === 'GoTo') {
  10391. data.dest = action.get('D');
  10392. } else if (linkType === 'GoToR') {
  10393. var urlDict = action.get('F');
  10394. if (isDict(urlDict)) {
  10395. // We assume that the 'url' is a Filspec dictionary
  10396. // and fetch the url without checking any further
  10397. url = urlDict.get('F') || '';
  10398. }
  10399. // TODO: pdf reference says that GoToR
  10400. // can also have 'NewWindow' attribute
  10401. if (!isValidUrl(url, false)) {
  10402. url = '';
  10403. }
  10404. data.url = url;
  10405. data.dest = action.get('D');
  10406. } else if (linkType === 'Named') {
  10407. data.action = action.get('N').name;
  10408. } else {
  10409. warn('unrecognized link type: ' + linkType);
  10410. }
  10411. } else if (dict.has('Dest')) {
  10412. // simple destination link
  10413. var dest = dict.get('Dest');
  10414. data.dest = isName(dest) ? dest.name : dest;
  10415. }
  10416. }
  10417. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10418. function addDefaultProtocolToUrl(url) {
  10419. if (url && url.indexOf('www.') === 0) {
  10420. return ('http://' + url);
  10421. }
  10422. return url;
  10423. }
  10424. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  10425. return LinkAnnotation;
  10426. })();
  10427. var PDFFunction = (function PDFFunctionClosure() {
  10428. var CONSTRUCT_SAMPLED = 0;
  10429. var CONSTRUCT_INTERPOLATED = 2;
  10430. var CONSTRUCT_STICHED = 3;
  10431. var CONSTRUCT_POSTSCRIPT = 4;
  10432. return {
  10433. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10434. str) {
  10435. var i, ii;
  10436. var length = 1;
  10437. for (i = 0, ii = size.length; i < ii; i++) {
  10438. length *= size[i];
  10439. }
  10440. length *= outputSize;
  10441. var array = new Array(length);
  10442. var codeSize = 0;
  10443. var codeBuf = 0;
  10444. // 32 is a valid bps so shifting won't work
  10445. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10446. var strBytes = str.getBytes((length * bps + 7) / 8);
  10447. var strIdx = 0;
  10448. for (i = 0; i < length; i++) {
  10449. while (codeSize < bps) {
  10450. codeBuf <<= 8;
  10451. codeBuf |= strBytes[strIdx++];
  10452. codeSize += 8;
  10453. }
  10454. codeSize -= bps;
  10455. array[i] = (codeBuf >> codeSize) * sampleMul;
  10456. codeBuf &= (1 << codeSize) - 1;
  10457. }
  10458. return array;
  10459. },
  10460. getIR: function PDFFunction_getIR(xref, fn) {
  10461. var dict = fn.dict;
  10462. if (!dict) {
  10463. dict = fn;
  10464. }
  10465. var types = [this.constructSampled,
  10466. null,
  10467. this.constructInterpolated,
  10468. this.constructStiched,
  10469. this.constructPostScript];
  10470. var typeNum = dict.get('FunctionType');
  10471. var typeFn = types[typeNum];
  10472. if (!typeFn) {
  10473. error('Unknown type of function');
  10474. }
  10475. return typeFn.call(this, fn, dict, xref);
  10476. },
  10477. fromIR: function PDFFunction_fromIR(IR) {
  10478. var type = IR[0];
  10479. switch (type) {
  10480. case CONSTRUCT_SAMPLED:
  10481. return this.constructSampledFromIR(IR);
  10482. case CONSTRUCT_INTERPOLATED:
  10483. return this.constructInterpolatedFromIR(IR);
  10484. case CONSTRUCT_STICHED:
  10485. return this.constructStichedFromIR(IR);
  10486. //case CONSTRUCT_POSTSCRIPT:
  10487. default:
  10488. return this.constructPostScriptFromIR(IR);
  10489. }
  10490. },
  10491. parse: function PDFFunction_parse(xref, fn) {
  10492. var IR = this.getIR(xref, fn);
  10493. return this.fromIR(IR);
  10494. },
  10495. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10496. if (!isArray(fnObj)) {
  10497. // not an array -- parsing as regular function
  10498. return this.parse(xref, fnObj);
  10499. }
  10500. var fnArray = [];
  10501. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10502. var obj = xref.fetchIfRef(fnObj[j]);
  10503. fnArray.push(PDFFunction.parse(xref, obj));
  10504. }
  10505. return function (src, srcOffset, dest, destOffset) {
  10506. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10507. fnArray[i](src, srcOffset, dest, destOffset + i);
  10508. }
  10509. };
  10510. },
  10511. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10512. function toMultiArray(arr) {
  10513. var inputLength = arr.length;
  10514. var out = [];
  10515. var index = 0;
  10516. for (var i = 0; i < inputLength; i += 2) {
  10517. out[index] = [arr[i], arr[i + 1]];
  10518. ++index;
  10519. }
  10520. return out;
  10521. }
  10522. var domain = dict.get('Domain');
  10523. var range = dict.get('Range');
  10524. if (!domain || !range) {
  10525. error('No domain or range');
  10526. }
  10527. var inputSize = domain.length / 2;
  10528. var outputSize = range.length / 2;
  10529. domain = toMultiArray(domain);
  10530. range = toMultiArray(range);
  10531. var size = dict.get('Size');
  10532. var bps = dict.get('BitsPerSample');
  10533. var order = dict.get('Order') || 1;
  10534. if (order !== 1) {
  10535. // No description how cubic spline interpolation works in PDF32000:2008
  10536. // As in poppler, ignoring order, linear interpolation may work as good
  10537. info('No support for cubic spline interpolation: ' + order);
  10538. }
  10539. var encode = dict.get('Encode');
  10540. if (!encode) {
  10541. encode = [];
  10542. for (var i = 0; i < inputSize; ++i) {
  10543. encode.push(0);
  10544. encode.push(size[i] - 1);
  10545. }
  10546. }
  10547. encode = toMultiArray(encode);
  10548. var decode = dict.get('Decode');
  10549. if (!decode) {
  10550. decode = range;
  10551. } else {
  10552. decode = toMultiArray(decode);
  10553. }
  10554. var samples = this.getSampleArray(size, outputSize, bps, str);
  10555. return [
  10556. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10557. outputSize, Math.pow(2, bps) - 1, range
  10558. ];
  10559. },
  10560. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10561. // See chapter 3, page 109 of the PDF reference
  10562. function interpolate(x, xmin, xmax, ymin, ymax) {
  10563. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10564. }
  10565. return function constructSampledFromIRResult(src, srcOffset,
  10566. dest, destOffset) {
  10567. // See chapter 3, page 110 of the PDF reference.
  10568. var m = IR[1];
  10569. var domain = IR[2];
  10570. var encode = IR[3];
  10571. var decode = IR[4];
  10572. var samples = IR[5];
  10573. var size = IR[6];
  10574. var n = IR[7];
  10575. //var mask = IR[8];
  10576. var range = IR[9];
  10577. // Building the cube vertices: its part and sample index
  10578. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10579. var cubeVertices = 1 << m;
  10580. var cubeN = new Float64Array(cubeVertices);
  10581. var cubeVertex = new Uint32Array(cubeVertices);
  10582. var i, j;
  10583. for (j = 0; j < cubeVertices; j++) {
  10584. cubeN[j] = 1;
  10585. }
  10586. var k = n, pos = 1;
  10587. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10588. for (i = 0; i < m; ++i) {
  10589. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10590. var domain_2i = domain[i][0];
  10591. var domain_2i_1 = domain[i][1];
  10592. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10593. domain_2i_1);
  10594. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10595. // Encode_2i, Encode_2i+1)
  10596. var e = interpolate(xi, domain_2i, domain_2i_1,
  10597. encode[i][0], encode[i][1]);
  10598. // e_i' = min(max(e_i, 0), Size_i - 1)
  10599. var size_i = size[i];
  10600. e = Math.min(Math.max(e, 0), size_i - 1);
  10601. // Adjusting the cube: N and vertex sample index
  10602. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10603. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10604. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10605. var offset0 = e0 * k;
  10606. var offset1 = offset0 + k; // e1 * k
  10607. for (j = 0; j < cubeVertices; j++) {
  10608. if (j & pos) {
  10609. cubeN[j] *= n1;
  10610. cubeVertex[j] += offset1;
  10611. } else {
  10612. cubeN[j] *= n0;
  10613. cubeVertex[j] += offset0;
  10614. }
  10615. }
  10616. k *= size_i;
  10617. pos <<= 1;
  10618. }
  10619. for (j = 0; j < n; ++j) {
  10620. // Sum all cube vertices' samples portions
  10621. var rj = 0;
  10622. for (i = 0; i < cubeVertices; i++) {
  10623. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10624. }
  10625. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10626. // Decode_2j, Decode_2j+1)
  10627. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10628. // y_j = min(max(r_j, range_2j), range_2j+1)
  10629. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10630. range[j][1]);
  10631. }
  10632. };
  10633. },
  10634. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10635. dict) {
  10636. var c0 = dict.get('C0') || [0];
  10637. var c1 = dict.get('C1') || [1];
  10638. var n = dict.get('N');
  10639. if (!isArray(c0) || !isArray(c1)) {
  10640. error('Illegal dictionary for interpolated function');
  10641. }
  10642. var length = c0.length;
  10643. var diff = [];
  10644. for (var i = 0; i < length; ++i) {
  10645. diff.push(c1[i] - c0[i]);
  10646. }
  10647. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10648. },
  10649. constructInterpolatedFromIR:
  10650. function PDFFunction_constructInterpolatedFromIR(IR) {
  10651. var c0 = IR[1];
  10652. var diff = IR[2];
  10653. var n = IR[3];
  10654. var length = diff.length;
  10655. return function constructInterpolatedFromIRResult(src, srcOffset,
  10656. dest, destOffset) {
  10657. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10658. for (var j = 0; j < length; ++j) {
  10659. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10660. }
  10661. };
  10662. },
  10663. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10664. var domain = dict.get('Domain');
  10665. if (!domain) {
  10666. error('No domain');
  10667. }
  10668. var inputSize = domain.length / 2;
  10669. if (inputSize !== 1) {
  10670. error('Bad domain for stiched function');
  10671. }
  10672. var fnRefs = dict.get('Functions');
  10673. var fns = [];
  10674. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10675. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10676. }
  10677. var bounds = dict.get('Bounds');
  10678. var encode = dict.get('Encode');
  10679. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10680. },
  10681. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10682. var domain = IR[1];
  10683. var bounds = IR[2];
  10684. var encode = IR[3];
  10685. var fnsIR = IR[4];
  10686. var fns = [];
  10687. var tmpBuf = new Float32Array(1);
  10688. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10689. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10690. }
  10691. return function constructStichedFromIRResult(src, srcOffset,
  10692. dest, destOffset) {
  10693. var clip = function constructStichedFromIRClip(v, min, max) {
  10694. if (v > max) {
  10695. v = max;
  10696. } else if (v < min) {
  10697. v = min;
  10698. }
  10699. return v;
  10700. };
  10701. // clip to domain
  10702. var v = clip(src[srcOffset], domain[0], domain[1]);
  10703. // calulate which bound the value is in
  10704. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10705. if (v < bounds[i]) {
  10706. break;
  10707. }
  10708. }
  10709. // encode value into domain of function
  10710. var dmin = domain[0];
  10711. if (i > 0) {
  10712. dmin = bounds[i - 1];
  10713. }
  10714. var dmax = domain[1];
  10715. if (i < bounds.length) {
  10716. dmax = bounds[i];
  10717. }
  10718. var rmin = encode[2 * i];
  10719. var rmax = encode[2 * i + 1];
  10720. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10721. // call the appropriate function
  10722. fns[i](tmpBuf, 0, dest, destOffset);
  10723. };
  10724. },
  10725. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10726. xref) {
  10727. var domain = dict.get('Domain');
  10728. var range = dict.get('Range');
  10729. if (!domain) {
  10730. error('No domain.');
  10731. }
  10732. if (!range) {
  10733. error('No range.');
  10734. }
  10735. var lexer = new PostScriptLexer(fn);
  10736. var parser = new PostScriptParser(lexer);
  10737. var code = parser.parse();
  10738. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10739. },
  10740. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10741. IR) {
  10742. var domain = IR[1];
  10743. var range = IR[2];
  10744. var code = IR[3];
  10745. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10746. if (compiled) {
  10747. // Compiled function consists of simple expressions such as addition,
  10748. // subtraction, Math.max, and also contains 'var' and 'return'
  10749. // statements. See the generation in the PostScriptCompiler below.
  10750. /*jshint -W054 */
  10751. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10752. }
  10753. info('Unable to compile PS function');
  10754. var numOutputs = range.length >> 1;
  10755. var numInputs = domain.length >> 1;
  10756. var evaluator = new PostScriptEvaluator(code);
  10757. // Cache the values for a big speed up, the cache size is limited though
  10758. // since the number of possible values can be huge from a PS function.
  10759. var cache = {};
  10760. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10761. // seen in our tests.
  10762. var MAX_CACHE_SIZE = 2048 * 4;
  10763. var cache_available = MAX_CACHE_SIZE;
  10764. var tmpBuf = new Float32Array(numInputs);
  10765. return function constructPostScriptFromIRResult(src, srcOffset,
  10766. dest, destOffset) {
  10767. var i, value;
  10768. var key = '';
  10769. var input = tmpBuf;
  10770. for (i = 0; i < numInputs; i++) {
  10771. value = src[srcOffset + i];
  10772. input[i] = value;
  10773. key += value + '_';
  10774. }
  10775. var cachedValue = cache[key];
  10776. if (cachedValue !== undefined) {
  10777. dest.set(cachedValue, destOffset);
  10778. return;
  10779. }
  10780. var output = new Float32Array(numOutputs);
  10781. var stack = evaluator.execute(input);
  10782. var stackIndex = stack.length - numOutputs;
  10783. for (i = 0; i < numOutputs; i++) {
  10784. value = stack[stackIndex + i];
  10785. var bound = range[i * 2];
  10786. if (value < bound) {
  10787. value = bound;
  10788. } else {
  10789. bound = range[i * 2 +1];
  10790. if (value > bound) {
  10791. value = bound;
  10792. }
  10793. }
  10794. output[i] = value;
  10795. }
  10796. if (cache_available > 0) {
  10797. cache_available--;
  10798. cache[key] = output;
  10799. }
  10800. dest.set(output, destOffset);
  10801. };
  10802. }
  10803. };
  10804. })();
  10805. function isPDFFunction(v) {
  10806. var fnDict;
  10807. if (typeof v !== 'object') {
  10808. return false;
  10809. } else if (isDict(v)) {
  10810. fnDict = v;
  10811. } else if (isStream(v)) {
  10812. fnDict = v.dict;
  10813. } else {
  10814. return false;
  10815. }
  10816. return fnDict.has('FunctionType');
  10817. }
  10818. var PostScriptStack = (function PostScriptStackClosure() {
  10819. var MAX_STACK_SIZE = 100;
  10820. function PostScriptStack(initialStack) {
  10821. this.stack = !initialStack ? [] :
  10822. Array.prototype.slice.call(initialStack, 0);
  10823. }
  10824. PostScriptStack.prototype = {
  10825. push: function PostScriptStack_push(value) {
  10826. if (this.stack.length >= MAX_STACK_SIZE) {
  10827. error('PostScript function stack overflow.');
  10828. }
  10829. this.stack.push(value);
  10830. },
  10831. pop: function PostScriptStack_pop() {
  10832. if (this.stack.length <= 0) {
  10833. error('PostScript function stack underflow.');
  10834. }
  10835. return this.stack.pop();
  10836. },
  10837. copy: function PostScriptStack_copy(n) {
  10838. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10839. error('PostScript function stack overflow.');
  10840. }
  10841. var stack = this.stack;
  10842. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10843. stack.push(stack[i]);
  10844. }
  10845. },
  10846. index: function PostScriptStack_index(n) {
  10847. this.push(this.stack[this.stack.length - n - 1]);
  10848. },
  10849. // rotate the last n stack elements p times
  10850. roll: function PostScriptStack_roll(n, p) {
  10851. var stack = this.stack;
  10852. var l = stack.length - n;
  10853. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10854. for (i = l, j = r; i < j; i++, j--) {
  10855. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10856. }
  10857. for (i = l, j = c - 1; i < j; i++, j--) {
  10858. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10859. }
  10860. for (i = c, j = r; i < j; i++, j--) {
  10861. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10862. }
  10863. }
  10864. };
  10865. return PostScriptStack;
  10866. })();
  10867. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10868. function PostScriptEvaluator(operators) {
  10869. this.operators = operators;
  10870. }
  10871. PostScriptEvaluator.prototype = {
  10872. execute: function PostScriptEvaluator_execute(initialStack) {
  10873. var stack = new PostScriptStack(initialStack);
  10874. var counter = 0;
  10875. var operators = this.operators;
  10876. var length = operators.length;
  10877. var operator, a, b;
  10878. while (counter < length) {
  10879. operator = operators[counter++];
  10880. if (typeof operator === 'number') {
  10881. // Operator is really an operand and should be pushed to the stack.
  10882. stack.push(operator);
  10883. continue;
  10884. }
  10885. switch (operator) {
  10886. // non standard ps operators
  10887. case 'jz': // jump if false
  10888. b = stack.pop();
  10889. a = stack.pop();
  10890. if (!a) {
  10891. counter = b;
  10892. }
  10893. break;
  10894. case 'j': // jump
  10895. a = stack.pop();
  10896. counter = a;
  10897. break;
  10898. // all ps operators in alphabetical order (excluding if/ifelse)
  10899. case 'abs':
  10900. a = stack.pop();
  10901. stack.push(Math.abs(a));
  10902. break;
  10903. case 'add':
  10904. b = stack.pop();
  10905. a = stack.pop();
  10906. stack.push(a + b);
  10907. break;
  10908. case 'and':
  10909. b = stack.pop();
  10910. a = stack.pop();
  10911. if (isBool(a) && isBool(b)) {
  10912. stack.push(a && b);
  10913. } else {
  10914. stack.push(a & b);
  10915. }
  10916. break;
  10917. case 'atan':
  10918. a = stack.pop();
  10919. stack.push(Math.atan(a));
  10920. break;
  10921. case 'bitshift':
  10922. b = stack.pop();
  10923. a = stack.pop();
  10924. if (a > 0) {
  10925. stack.push(a << b);
  10926. } else {
  10927. stack.push(a >> b);
  10928. }
  10929. break;
  10930. case 'ceiling':
  10931. a = stack.pop();
  10932. stack.push(Math.ceil(a));
  10933. break;
  10934. case 'copy':
  10935. a = stack.pop();
  10936. stack.copy(a);
  10937. break;
  10938. case 'cos':
  10939. a = stack.pop();
  10940. stack.push(Math.cos(a));
  10941. break;
  10942. case 'cvi':
  10943. a = stack.pop() | 0;
  10944. stack.push(a);
  10945. break;
  10946. case 'cvr':
  10947. // noop
  10948. break;
  10949. case 'div':
  10950. b = stack.pop();
  10951. a = stack.pop();
  10952. stack.push(a / b);
  10953. break;
  10954. case 'dup':
  10955. stack.copy(1);
  10956. break;
  10957. case 'eq':
  10958. b = stack.pop();
  10959. a = stack.pop();
  10960. stack.push(a === b);
  10961. break;
  10962. case 'exch':
  10963. stack.roll(2, 1);
  10964. break;
  10965. case 'exp':
  10966. b = stack.pop();
  10967. a = stack.pop();
  10968. stack.push(Math.pow(a, b));
  10969. break;
  10970. case 'false':
  10971. stack.push(false);
  10972. break;
  10973. case 'floor':
  10974. a = stack.pop();
  10975. stack.push(Math.floor(a));
  10976. break;
  10977. case 'ge':
  10978. b = stack.pop();
  10979. a = stack.pop();
  10980. stack.push(a >= b);
  10981. break;
  10982. case 'gt':
  10983. b = stack.pop();
  10984. a = stack.pop();
  10985. stack.push(a > b);
  10986. break;
  10987. case 'idiv':
  10988. b = stack.pop();
  10989. a = stack.pop();
  10990. stack.push((a / b) | 0);
  10991. break;
  10992. case 'index':
  10993. a = stack.pop();
  10994. stack.index(a);
  10995. break;
  10996. case 'le':
  10997. b = stack.pop();
  10998. a = stack.pop();
  10999. stack.push(a <= b);
  11000. break;
  11001. case 'ln':
  11002. a = stack.pop();
  11003. stack.push(Math.log(a));
  11004. break;
  11005. case 'log':
  11006. a = stack.pop();
  11007. stack.push(Math.log(a) / Math.LN10);
  11008. break;
  11009. case 'lt':
  11010. b = stack.pop();
  11011. a = stack.pop();
  11012. stack.push(a < b);
  11013. break;
  11014. case 'mod':
  11015. b = stack.pop();
  11016. a = stack.pop();
  11017. stack.push(a % b);
  11018. break;
  11019. case 'mul':
  11020. b = stack.pop();
  11021. a = stack.pop();
  11022. stack.push(a * b);
  11023. break;
  11024. case 'ne':
  11025. b = stack.pop();
  11026. a = stack.pop();
  11027. stack.push(a !== b);
  11028. break;
  11029. case 'neg':
  11030. a = stack.pop();
  11031. stack.push(-a);
  11032. break;
  11033. case 'not':
  11034. a = stack.pop();
  11035. if (isBool(a)) {
  11036. stack.push(!a);
  11037. } else {
  11038. stack.push(~a);
  11039. }
  11040. break;
  11041. case 'or':
  11042. b = stack.pop();
  11043. a = stack.pop();
  11044. if (isBool(a) && isBool(b)) {
  11045. stack.push(a || b);
  11046. } else {
  11047. stack.push(a | b);
  11048. }
  11049. break;
  11050. case 'pop':
  11051. stack.pop();
  11052. break;
  11053. case 'roll':
  11054. b = stack.pop();
  11055. a = stack.pop();
  11056. stack.roll(a, b);
  11057. break;
  11058. case 'round':
  11059. a = stack.pop();
  11060. stack.push(Math.round(a));
  11061. break;
  11062. case 'sin':
  11063. a = stack.pop();
  11064. stack.push(Math.sin(a));
  11065. break;
  11066. case 'sqrt':
  11067. a = stack.pop();
  11068. stack.push(Math.sqrt(a));
  11069. break;
  11070. case 'sub':
  11071. b = stack.pop();
  11072. a = stack.pop();
  11073. stack.push(a - b);
  11074. break;
  11075. case 'true':
  11076. stack.push(true);
  11077. break;
  11078. case 'truncate':
  11079. a = stack.pop();
  11080. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11081. stack.push(a);
  11082. break;
  11083. case 'xor':
  11084. b = stack.pop();
  11085. a = stack.pop();
  11086. if (isBool(a) && isBool(b)) {
  11087. stack.push(a !== b);
  11088. } else {
  11089. stack.push(a ^ b);
  11090. }
  11091. break;
  11092. default:
  11093. error('Unknown operator ' + operator);
  11094. break;
  11095. }
  11096. }
  11097. return stack.stack;
  11098. }
  11099. };
  11100. return PostScriptEvaluator;
  11101. })();
  11102. // Most of the PDFs functions consist of simple operations such as:
  11103. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11104. //
  11105. // We can compile most of such programs, and at the same moment, we can
  11106. // optimize some expressions using basic math properties. Keeping track of
  11107. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11108. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11109. function AstNode(type) {
  11110. this.type = type;
  11111. }
  11112. AstNode.prototype.visit = function (visitor) {
  11113. throw new Error('abstract method');
  11114. };
  11115. function AstArgument(index, min, max) {
  11116. AstNode.call(this, 'args');
  11117. this.index = index;
  11118. this.min = min;
  11119. this.max = max;
  11120. }
  11121. AstArgument.prototype = Object.create(AstNode.prototype);
  11122. AstArgument.prototype.visit = function (visitor) {
  11123. visitor.visitArgument(this);
  11124. };
  11125. function AstLiteral(number) {
  11126. AstNode.call(this, 'literal');
  11127. this.number = number;
  11128. this.min = number;
  11129. this.max = number;
  11130. }
  11131. AstLiteral.prototype = Object.create(AstNode.prototype);
  11132. AstLiteral.prototype.visit = function (visitor) {
  11133. visitor.visitLiteral(this);
  11134. };
  11135. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11136. AstNode.call(this, 'binary');
  11137. this.op = op;
  11138. this.arg1 = arg1;
  11139. this.arg2 = arg2;
  11140. this.min = min;
  11141. this.max = max;
  11142. }
  11143. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11144. AstBinaryOperation.prototype.visit = function (visitor) {
  11145. visitor.visitBinaryOperation(this);
  11146. };
  11147. function AstMin(arg, max) {
  11148. AstNode.call(this, 'max');
  11149. this.arg = arg;
  11150. this.min = arg.min;
  11151. this.max = max;
  11152. }
  11153. AstMin.prototype = Object.create(AstNode.prototype);
  11154. AstMin.prototype.visit = function (visitor) {
  11155. visitor.visitMin(this);
  11156. };
  11157. function AstVariable(index, min, max) {
  11158. AstNode.call(this, 'var');
  11159. this.index = index;
  11160. this.min = min;
  11161. this.max = max;
  11162. }
  11163. AstVariable.prototype = Object.create(AstNode.prototype);
  11164. AstVariable.prototype.visit = function (visitor) {
  11165. visitor.visitVariable(this);
  11166. };
  11167. function AstVariableDefinition(variable, arg) {
  11168. AstNode.call(this, 'definition');
  11169. this.variable = variable;
  11170. this.arg = arg;
  11171. }
  11172. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11173. AstVariableDefinition.prototype.visit = function (visitor) {
  11174. visitor.visitVariableDefinition(this);
  11175. };
  11176. function ExpressionBuilderVisitor() {
  11177. this.parts = [];
  11178. }
  11179. ExpressionBuilderVisitor.prototype = {
  11180. visitArgument: function (arg) {
  11181. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11182. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11183. },
  11184. visitVariable: function (variable) {
  11185. this.parts.push('v', variable.index);
  11186. },
  11187. visitLiteral: function (literal) {
  11188. this.parts.push(literal.number);
  11189. },
  11190. visitBinaryOperation: function (operation) {
  11191. this.parts.push('(');
  11192. operation.arg1.visit(this);
  11193. this.parts.push(' ', operation.op, ' ');
  11194. operation.arg2.visit(this);
  11195. this.parts.push(')');
  11196. },
  11197. visitVariableDefinition: function (definition) {
  11198. this.parts.push('var ');
  11199. definition.variable.visit(this);
  11200. this.parts.push(' = ');
  11201. definition.arg.visit(this);
  11202. this.parts.push(';');
  11203. },
  11204. visitMin: function (max) {
  11205. this.parts.push('Math.min(');
  11206. max.arg.visit(this);
  11207. this.parts.push(', ', max.max, ')');
  11208. },
  11209. toString: function () {
  11210. return this.parts.join('');
  11211. }
  11212. };
  11213. function buildAddOperation(num1, num2) {
  11214. if (num2.type === 'literal' && num2.number === 0) {
  11215. // optimization: second operand is 0
  11216. return num1;
  11217. }
  11218. if (num1.type === 'literal' && num1.number === 0) {
  11219. // optimization: first operand is 0
  11220. return num2;
  11221. }
  11222. if (num2.type === 'literal' && num1.type === 'literal') {
  11223. // optimization: operands operand are literals
  11224. return new AstLiteral(num1.number + num2.number);
  11225. }
  11226. return new AstBinaryOperation('+', num1, num2,
  11227. num1.min + num2.min, num1.max + num2.max);
  11228. }
  11229. function buildMulOperation(num1, num2) {
  11230. if (num2.type === 'literal') {
  11231. // optimization: second operands is a literal...
  11232. if (num2.number === 0) {
  11233. return new AstLiteral(0); // and it's 0
  11234. } else if (num2.number === 1) {
  11235. return num1; // and it's 1
  11236. } else if (num1.type === 'literal') {
  11237. // ... and first operands is a literal too
  11238. return new AstLiteral(num1.number * num2.number);
  11239. }
  11240. }
  11241. if (num1.type === 'literal') {
  11242. // optimization: first operands is a literal...
  11243. if (num1.number === 0) {
  11244. return new AstLiteral(0); // and it's 0
  11245. } else if (num1.number === 1) {
  11246. return num2; // and it's 1
  11247. }
  11248. }
  11249. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11250. num1.max * num2.min, num1.max * num2.max);
  11251. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11252. num1.max * num2.min, num1.max * num2.max);
  11253. return new AstBinaryOperation('*', num1, num2, min, max);
  11254. }
  11255. function buildSubOperation(num1, num2) {
  11256. if (num2.type === 'literal') {
  11257. // optimization: second operands is a literal...
  11258. if (num2.number === 0) {
  11259. return num1; // ... and it's 0
  11260. } else if (num1.type === 'literal') {
  11261. // ... and first operands is a literal too
  11262. return new AstLiteral(num1.number - num2.number);
  11263. }
  11264. }
  11265. if (num2.type === 'binary' && num2.op === '-' &&
  11266. num1.type === 'literal' && num1.number === 1 &&
  11267. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11268. // optimization for case: 1 - (1 - x)
  11269. return num2.arg2;
  11270. }
  11271. return new AstBinaryOperation('-', num1, num2,
  11272. num1.min - num2.max, num1.max - num2.min);
  11273. }
  11274. function buildMinOperation(num1, max) {
  11275. if (num1.min >= max) {
  11276. // optimization: num1 min value is not less than required max
  11277. return new AstLiteral(max); // just returning max
  11278. } else if (num1.max <= max) {
  11279. // optimization: num1 max value is not greater than required max
  11280. return num1; // just returning an argument
  11281. }
  11282. return new AstMin(num1, max);
  11283. }
  11284. function PostScriptCompiler() {}
  11285. PostScriptCompiler.prototype = {
  11286. compile: function PostScriptCompiler_compile(code, domain, range) {
  11287. var stack = [];
  11288. var i, ii;
  11289. var instructions = [];
  11290. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11291. var lastRegister = 0;
  11292. var n, j, min, max;
  11293. var num1, num2, ast1, ast2, tmpVar, item;
  11294. for (i = 0; i < inputSize; i++) {
  11295. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11296. }
  11297. for (i = 0, ii = code.length; i < ii; i++) {
  11298. item = code[i];
  11299. if (typeof item === 'number') {
  11300. stack.push(new AstLiteral(item));
  11301. continue;
  11302. }
  11303. switch (item) {
  11304. case 'add':
  11305. if (stack.length < 2) {
  11306. return null;
  11307. }
  11308. num2 = stack.pop();
  11309. num1 = stack.pop();
  11310. stack.push(buildAddOperation(num1, num2));
  11311. break;
  11312. case 'cvr':
  11313. if (stack.length < 1) {
  11314. return null;
  11315. }
  11316. break;
  11317. case 'mul':
  11318. if (stack.length < 2) {
  11319. return null;
  11320. }
  11321. num2 = stack.pop();
  11322. num1 = stack.pop();
  11323. stack.push(buildMulOperation(num1, num2));
  11324. break;
  11325. case 'sub':
  11326. if (stack.length < 2) {
  11327. return null;
  11328. }
  11329. num2 = stack.pop();
  11330. num1 = stack.pop();
  11331. stack.push(buildSubOperation(num1, num2));
  11332. break;
  11333. case 'exch':
  11334. if (stack.length < 2) {
  11335. return null;
  11336. }
  11337. ast1 = stack.pop(); ast2 = stack.pop();
  11338. stack.push(ast1, ast2);
  11339. break;
  11340. case 'pop':
  11341. if (stack.length < 1) {
  11342. return null;
  11343. }
  11344. stack.pop();
  11345. break;
  11346. case 'index':
  11347. if (stack.length < 1) {
  11348. return null;
  11349. }
  11350. num1 = stack.pop();
  11351. if (num1.type !== 'literal') {
  11352. return null;
  11353. }
  11354. n = num1.number;
  11355. if (n < 0 || (n|0) !== n || stack.length < n) {
  11356. return null;
  11357. }
  11358. ast1 = stack[stack.length - n - 1];
  11359. if (ast1.type === 'literal' || ast1.type === 'var') {
  11360. stack.push(ast1);
  11361. break;
  11362. }
  11363. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11364. stack[stack.length - n - 1] = tmpVar;
  11365. stack.push(tmpVar);
  11366. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11367. break;
  11368. case 'dup':
  11369. if (stack.length < 1) {
  11370. return null;
  11371. }
  11372. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11373. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11374. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11375. // special case of the commands sequence for the min operation
  11376. num1 = stack.pop();
  11377. stack.push(buildMinOperation(num1, code[i + 1]));
  11378. i += 6;
  11379. break;
  11380. }
  11381. ast1 = stack[stack.length - 1];
  11382. if (ast1.type === 'literal' || ast1.type === 'var') {
  11383. // we don't have to save into intermediate variable a literal or
  11384. // variable.
  11385. stack.push(ast1);
  11386. break;
  11387. }
  11388. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11389. stack[stack.length - 1] = tmpVar;
  11390. stack.push(tmpVar);
  11391. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11392. break;
  11393. case 'roll':
  11394. if (stack.length < 2) {
  11395. return null;
  11396. }
  11397. num2 = stack.pop();
  11398. num1 = stack.pop();
  11399. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11400. // both roll operands must be numbers
  11401. return null;
  11402. }
  11403. j = num2.number;
  11404. n = num1.number;
  11405. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11406. // ... and integers
  11407. return null;
  11408. }
  11409. j = ((j % n) + n) % n;
  11410. if (j === 0) {
  11411. break; // just skipping -- there are nothing to rotate
  11412. }
  11413. Array.prototype.push.apply(stack,
  11414. stack.splice(stack.length - n, n - j));
  11415. break;
  11416. default:
  11417. return null; // unsupported operator
  11418. }
  11419. }
  11420. if (stack.length !== outputSize) {
  11421. return null;
  11422. }
  11423. var result = [];
  11424. instructions.forEach(function (instruction) {
  11425. var statementBuilder = new ExpressionBuilderVisitor();
  11426. instruction.visit(statementBuilder);
  11427. result.push(statementBuilder.toString());
  11428. });
  11429. stack.forEach(function (expr, i) {
  11430. var statementBuilder = new ExpressionBuilderVisitor();
  11431. expr.visit(statementBuilder);
  11432. var min = range[i * 2], max = range[i * 2 + 1];
  11433. var out = [statementBuilder.toString()];
  11434. if (min > expr.min) {
  11435. out.unshift('Math.max(', min, ', ');
  11436. out.push(')');
  11437. }
  11438. if (max < expr.max) {
  11439. out.unshift('Math.min(', max, ', ');
  11440. out.push(')');
  11441. }
  11442. out.unshift('dest[destOffset + ', i, '] = ');
  11443. out.push(';');
  11444. result.push(out.join(''));
  11445. });
  11446. return result.join('\n');
  11447. }
  11448. };
  11449. return PostScriptCompiler;
  11450. })();
  11451. var ColorSpace = (function ColorSpaceClosure() {
  11452. // Constructor should define this.numComps, this.defaultColor, this.name
  11453. function ColorSpace() {
  11454. error('should not call ColorSpace constructor');
  11455. }
  11456. ColorSpace.prototype = {
  11457. /**
  11458. * Converts the color value to the RGB color. The color components are
  11459. * located in the src array starting from the srcOffset. Returns the array
  11460. * of the rgb components, each value ranging from [0,255].
  11461. */
  11462. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11463. var rgb = new Uint8Array(3);
  11464. this.getRgbItem(src, srcOffset, rgb, 0);
  11465. return rgb;
  11466. },
  11467. /**
  11468. * Converts the color value to the RGB color, similar to the getRgb method.
  11469. * The result placed into the dest array starting from the destOffset.
  11470. */
  11471. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11472. dest, destOffset) {
  11473. error('Should not call ColorSpace.getRgbItem');
  11474. },
  11475. /**
  11476. * Converts the specified number of the color values to the RGB colors.
  11477. * The colors are located in the src array starting from the srcOffset.
  11478. * The result is placed into the dest array starting from the destOffset.
  11479. * The src array items shall be in [0,2^bits) range, the dest array items
  11480. * will be in [0,255] range. alpha01 indicates how many alpha components
  11481. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11482. * array).
  11483. */
  11484. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11485. dest, destOffset, bits,
  11486. alpha01) {
  11487. error('Should not call ColorSpace.getRgbBuffer');
  11488. },
  11489. /**
  11490. * Determines the number of bytes required to store the result of the
  11491. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11492. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11493. */
  11494. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11495. alpha01) {
  11496. error('Should not call ColorSpace.getOutputLength');
  11497. },
  11498. /**
  11499. * Returns true if source data will be equal the result/output data.
  11500. */
  11501. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11502. return false;
  11503. },
  11504. /**
  11505. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11506. * how many alpha components there are in the dest array; it will be either
  11507. * 0 (RGB array) or 1 (RGBA array).
  11508. */
  11509. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11510. originalHeight, width, height,
  11511. actualHeight, bpc, comps, alpha01) {
  11512. var count = originalWidth * originalHeight;
  11513. var rgbBuf = null;
  11514. var numComponentColors = 1 << bpc;
  11515. var needsResizing = originalHeight !== height || originalWidth !== width;
  11516. var i, ii;
  11517. if (this.isPassthrough(bpc)) {
  11518. rgbBuf = comps;
  11519. } else if (this.numComps === 1 && count > numComponentColors &&
  11520. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11521. // Optimization: create a color map when there is just one component and
  11522. // we are converting more colors than the size of the color map. We
  11523. // don't build the map if the colorspace is gray or rgb since those
  11524. // methods are faster than building a map. This mainly offers big speed
  11525. // ups for indexed and alternate colorspaces.
  11526. //
  11527. // TODO it may be worth while to cache the color map. While running
  11528. // testing I never hit a cache so I will leave that out for now (perhaps
  11529. // we are reparsing colorspaces too much?).
  11530. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11531. new Uint16Array(numComponentColors);
  11532. var key;
  11533. for (i = 0; i < numComponentColors; i++) {
  11534. allColors[i] = i;
  11535. }
  11536. var colorMap = new Uint8Array(numComponentColors * 3);
  11537. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11538. /* alpha01 = */ 0);
  11539. var destPos, rgbPos;
  11540. if (!needsResizing) {
  11541. // Fill in the RGB values directly into |dest|.
  11542. destPos = 0;
  11543. for (i = 0; i < count; ++i) {
  11544. key = comps[i] * 3;
  11545. dest[destPos++] = colorMap[key];
  11546. dest[destPos++] = colorMap[key + 1];
  11547. dest[destPos++] = colorMap[key + 2];
  11548. destPos += alpha01;
  11549. }
  11550. } else {
  11551. rgbBuf = new Uint8Array(count * 3);
  11552. rgbPos = 0;
  11553. for (i = 0; i < count; ++i) {
  11554. key = comps[i] * 3;
  11555. rgbBuf[rgbPos++] = colorMap[key];
  11556. rgbBuf[rgbPos++] = colorMap[key + 1];
  11557. rgbBuf[rgbPos++] = colorMap[key + 2];
  11558. }
  11559. }
  11560. } else {
  11561. if (!needsResizing) {
  11562. // Fill in the RGB values directly into |dest|.
  11563. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11564. alpha01);
  11565. } else {
  11566. rgbBuf = new Uint8Array(count * 3);
  11567. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11568. /* alpha01 = */ 0);
  11569. }
  11570. }
  11571. if (rgbBuf) {
  11572. if (needsResizing) {
  11573. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11574. height, dest, alpha01);
  11575. } else {
  11576. rgbPos = 0;
  11577. destPos = 0;
  11578. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11579. dest[destPos++] = rgbBuf[rgbPos++];
  11580. dest[destPos++] = rgbBuf[rgbPos++];
  11581. dest[destPos++] = rgbBuf[rgbPos++];
  11582. destPos += alpha01;
  11583. }
  11584. }
  11585. }
  11586. },
  11587. /**
  11588. * True if the colorspace has components in the default range of [0, 1].
  11589. * This should be true for all colorspaces except for lab color spaces
  11590. * which are [0,100], [-128, 127], [-128, 127].
  11591. */
  11592. usesZeroToOneRange: true
  11593. };
  11594. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11595. var IR = ColorSpace.parseToIR(cs, xref, res);
  11596. if (IR instanceof AlternateCS) {
  11597. return IR;
  11598. }
  11599. return ColorSpace.fromIR(IR);
  11600. };
  11601. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11602. var name = isArray(IR) ? IR[0] : IR;
  11603. var whitePoint, blackPoint, gamma;
  11604. switch (name) {
  11605. case 'DeviceGrayCS':
  11606. return this.singletons.gray;
  11607. case 'DeviceRgbCS':
  11608. return this.singletons.rgb;
  11609. case 'DeviceCmykCS':
  11610. return this.singletons.cmyk;
  11611. case 'CalGrayCS':
  11612. whitePoint = IR[1].WhitePoint;
  11613. blackPoint = IR[1].BlackPoint;
  11614. gamma = IR[1].Gamma;
  11615. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11616. case 'CalRGBCS':
  11617. whitePoint = IR[1].WhitePoint;
  11618. blackPoint = IR[1].BlackPoint;
  11619. gamma = IR[1].Gamma;
  11620. var matrix = IR[1].Matrix;
  11621. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11622. case 'PatternCS':
  11623. var basePatternCS = IR[1];
  11624. if (basePatternCS) {
  11625. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11626. }
  11627. return new PatternCS(basePatternCS);
  11628. case 'IndexedCS':
  11629. var baseIndexedCS = IR[1];
  11630. var hiVal = IR[2];
  11631. var lookup = IR[3];
  11632. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11633. case 'AlternateCS':
  11634. var numComps = IR[1];
  11635. var alt = IR[2];
  11636. var tintFnIR = IR[3];
  11637. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11638. PDFFunction.fromIR(tintFnIR));
  11639. case 'LabCS':
  11640. whitePoint = IR[1].WhitePoint;
  11641. blackPoint = IR[1].BlackPoint;
  11642. var range = IR[1].Range;
  11643. return new LabCS(whitePoint, blackPoint, range);
  11644. default:
  11645. error('Unknown name ' + name);
  11646. }
  11647. return null;
  11648. };
  11649. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11650. if (isName(cs)) {
  11651. var colorSpaces = res.get('ColorSpace');
  11652. if (isDict(colorSpaces)) {
  11653. var refcs = colorSpaces.get(cs.name);
  11654. if (refcs) {
  11655. cs = refcs;
  11656. }
  11657. }
  11658. }
  11659. cs = xref.fetchIfRef(cs);
  11660. var mode;
  11661. if (isName(cs)) {
  11662. mode = cs.name;
  11663. this.mode = mode;
  11664. switch (mode) {
  11665. case 'DeviceGray':
  11666. case 'G':
  11667. return 'DeviceGrayCS';
  11668. case 'DeviceRGB':
  11669. case 'RGB':
  11670. return 'DeviceRgbCS';
  11671. case 'DeviceCMYK':
  11672. case 'CMYK':
  11673. return 'DeviceCmykCS';
  11674. case 'Pattern':
  11675. return ['PatternCS', null];
  11676. default:
  11677. error('unrecognized colorspace ' + mode);
  11678. }
  11679. } else if (isArray(cs)) {
  11680. mode = cs[0].name;
  11681. this.mode = mode;
  11682. var numComps, params;
  11683. switch (mode) {
  11684. case 'DeviceGray':
  11685. case 'G':
  11686. return 'DeviceGrayCS';
  11687. case 'DeviceRGB':
  11688. case 'RGB':
  11689. return 'DeviceRgbCS';
  11690. case 'DeviceCMYK':
  11691. case 'CMYK':
  11692. return 'DeviceCmykCS';
  11693. case 'CalGray':
  11694. params = xref.fetchIfRef(cs[1]).getAll();
  11695. return ['CalGrayCS', params];
  11696. case 'CalRGB':
  11697. params = xref.fetchIfRef(cs[1]).getAll();
  11698. return ['CalRGBCS', params];
  11699. case 'ICCBased':
  11700. var stream = xref.fetchIfRef(cs[1]);
  11701. var dict = stream.dict;
  11702. numComps = dict.get('N');
  11703. if (numComps === 1) {
  11704. return 'DeviceGrayCS';
  11705. } else if (numComps === 3) {
  11706. return 'DeviceRgbCS';
  11707. } else if (numComps === 4) {
  11708. return 'DeviceCmykCS';
  11709. }
  11710. break;
  11711. case 'Pattern':
  11712. var basePatternCS = cs[1];
  11713. if (basePatternCS) {
  11714. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11715. }
  11716. return ['PatternCS', basePatternCS];
  11717. case 'Indexed':
  11718. case 'I':
  11719. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11720. var hiVal = cs[2] + 1;
  11721. var lookup = xref.fetchIfRef(cs[3]);
  11722. if (isStream(lookup)) {
  11723. lookup = lookup.getBytes();
  11724. }
  11725. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11726. case 'Separation':
  11727. case 'DeviceN':
  11728. var name = cs[1];
  11729. numComps = 1;
  11730. if (isName(name)) {
  11731. numComps = 1;
  11732. } else if (isArray(name)) {
  11733. numComps = name.length;
  11734. }
  11735. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11736. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11737. return ['AlternateCS', numComps, alt, tintFnIR];
  11738. case 'Lab':
  11739. params = cs[1].getAll();
  11740. return ['LabCS', params];
  11741. default:
  11742. error('unimplemented color space object "' + mode + '"');
  11743. }
  11744. } else {
  11745. error('unrecognized color space object: "' + cs + '"');
  11746. }
  11747. return null;
  11748. };
  11749. /**
  11750. * Checks if a decode map matches the default decode map for a color space.
  11751. * This handles the general decode maps where there are two values per
  11752. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11753. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11754. * slightly different.
  11755. * @param {Array} decode Decode map (usually from an image).
  11756. * @param {Number} n Number of components the color space has.
  11757. */
  11758. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11759. if (!decode) {
  11760. return true;
  11761. }
  11762. if (n * 2 !== decode.length) {
  11763. warn('The decode map is not the correct length');
  11764. return true;
  11765. }
  11766. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11767. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11768. return false;
  11769. }
  11770. }
  11771. return true;
  11772. };
  11773. ColorSpace.singletons = {
  11774. get gray() {
  11775. return shadow(this, 'gray', new DeviceGrayCS());
  11776. },
  11777. get rgb() {
  11778. return shadow(this, 'rgb', new DeviceRgbCS());
  11779. },
  11780. get cmyk() {
  11781. return shadow(this, 'cmyk', new DeviceCmykCS());
  11782. }
  11783. };
  11784. return ColorSpace;
  11785. })();
  11786. /**
  11787. * Alternate color space handles both Separation and DeviceN color spaces. A
  11788. * Separation color space is actually just a DeviceN with one color component.
  11789. * Both color spaces use a tinting function to convert colors to a base color
  11790. * space.
  11791. */
  11792. var AlternateCS = (function AlternateCSClosure() {
  11793. function AlternateCS(numComps, base, tintFn) {
  11794. this.name = 'Alternate';
  11795. this.numComps = numComps;
  11796. this.defaultColor = new Float32Array(numComps);
  11797. for (var i = 0; i < numComps; ++i) {
  11798. this.defaultColor[i] = 1;
  11799. }
  11800. this.base = base;
  11801. this.tintFn = tintFn;
  11802. this.tmpBuf = new Float32Array(base.numComps);
  11803. }
  11804. AlternateCS.prototype = {
  11805. getRgb: ColorSpace.prototype.getRgb,
  11806. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11807. dest, destOffset) {
  11808. var tmpBuf = this.tmpBuf;
  11809. this.tintFn(src, srcOffset, tmpBuf, 0);
  11810. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11811. },
  11812. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11813. dest, destOffset, bits,
  11814. alpha01) {
  11815. var tintFn = this.tintFn;
  11816. var base = this.base;
  11817. var scale = 1 / ((1 << bits) - 1);
  11818. var baseNumComps = base.numComps;
  11819. var usesZeroToOneRange = base.usesZeroToOneRange;
  11820. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11821. alpha01 === 0;
  11822. var pos = isPassthrough ? destOffset : 0;
  11823. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11824. var numComps = this.numComps;
  11825. var scaled = new Float32Array(numComps);
  11826. var tinted = new Float32Array(baseNumComps);
  11827. var i, j;
  11828. if (usesZeroToOneRange) {
  11829. for (i = 0; i < count; i++) {
  11830. for (j = 0; j < numComps; j++) {
  11831. scaled[j] = src[srcOffset++] * scale;
  11832. }
  11833. tintFn(scaled, 0, tinted, 0);
  11834. for (j = 0; j < baseNumComps; j++) {
  11835. baseBuf[pos++] = tinted[j] * 255;
  11836. }
  11837. }
  11838. } else {
  11839. for (i = 0; i < count; i++) {
  11840. for (j = 0; j < numComps; j++) {
  11841. scaled[j] = src[srcOffset++] * scale;
  11842. }
  11843. tintFn(scaled, 0, tinted, 0);
  11844. base.getRgbItem(tinted, 0, baseBuf, pos);
  11845. pos += baseNumComps;
  11846. }
  11847. }
  11848. if (!isPassthrough) {
  11849. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11850. }
  11851. },
  11852. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11853. alpha01) {
  11854. return this.base.getOutputLength(inputLength *
  11855. this.base.numComps / this.numComps,
  11856. alpha01);
  11857. },
  11858. isPassthrough: ColorSpace.prototype.isPassthrough,
  11859. fillRgb: ColorSpace.prototype.fillRgb,
  11860. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11861. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11862. },
  11863. usesZeroToOneRange: true
  11864. };
  11865. return AlternateCS;
  11866. })();
  11867. var PatternCS = (function PatternCSClosure() {
  11868. function PatternCS(baseCS) {
  11869. this.name = 'Pattern';
  11870. this.base = baseCS;
  11871. }
  11872. PatternCS.prototype = {};
  11873. return PatternCS;
  11874. })();
  11875. var IndexedCS = (function IndexedCSClosure() {
  11876. function IndexedCS(base, highVal, lookup) {
  11877. this.name = 'Indexed';
  11878. this.numComps = 1;
  11879. this.defaultColor = new Uint8Array([0]);
  11880. this.base = base;
  11881. this.highVal = highVal;
  11882. var baseNumComps = base.numComps;
  11883. var length = baseNumComps * highVal;
  11884. var lookupArray;
  11885. if (isStream(lookup)) {
  11886. lookupArray = new Uint8Array(length);
  11887. var bytes = lookup.getBytes(length);
  11888. lookupArray.set(bytes);
  11889. } else if (isString(lookup)) {
  11890. lookupArray = new Uint8Array(length);
  11891. for (var i = 0; i < length; ++i) {
  11892. lookupArray[i] = lookup.charCodeAt(i);
  11893. }
  11894. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11895. lookupArray = lookup;
  11896. } else {
  11897. error('Unrecognized lookup table: ' + lookup);
  11898. }
  11899. this.lookup = lookupArray;
  11900. }
  11901. IndexedCS.prototype = {
  11902. getRgb: ColorSpace.prototype.getRgb,
  11903. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11904. dest, destOffset) {
  11905. var numComps = this.base.numComps;
  11906. var start = src[srcOffset] * numComps;
  11907. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11908. },
  11909. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11910. dest, destOffset, bits,
  11911. alpha01) {
  11912. var base = this.base;
  11913. var numComps = base.numComps;
  11914. var outputDelta = base.getOutputLength(numComps, alpha01);
  11915. var lookup = this.lookup;
  11916. for (var i = 0; i < count; ++i) {
  11917. var lookupPos = src[srcOffset++] * numComps;
  11918. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11919. destOffset += outputDelta;
  11920. }
  11921. },
  11922. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11923. return this.base.getOutputLength(inputLength * this.base.numComps,
  11924. alpha01);
  11925. },
  11926. isPassthrough: ColorSpace.prototype.isPassthrough,
  11927. fillRgb: ColorSpace.prototype.fillRgb,
  11928. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11929. // indexed color maps shouldn't be changed
  11930. return true;
  11931. },
  11932. usesZeroToOneRange: true
  11933. };
  11934. return IndexedCS;
  11935. })();
  11936. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11937. function DeviceGrayCS() {
  11938. this.name = 'DeviceGray';
  11939. this.numComps = 1;
  11940. this.defaultColor = new Float32Array([0]);
  11941. }
  11942. DeviceGrayCS.prototype = {
  11943. getRgb: ColorSpace.prototype.getRgb,
  11944. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11945. dest, destOffset) {
  11946. var c = (src[srcOffset] * 255) | 0;
  11947. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11948. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11949. },
  11950. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11951. dest, destOffset, bits,
  11952. alpha01) {
  11953. var scale = 255 / ((1 << bits) - 1);
  11954. var j = srcOffset, q = destOffset;
  11955. for (var i = 0; i < count; ++i) {
  11956. var c = (scale * src[j++]) | 0;
  11957. dest[q++] = c;
  11958. dest[q++] = c;
  11959. dest[q++] = c;
  11960. q += alpha01;
  11961. }
  11962. },
  11963. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11964. alpha01) {
  11965. return inputLength * (3 + alpha01);
  11966. },
  11967. isPassthrough: ColorSpace.prototype.isPassthrough,
  11968. fillRgb: ColorSpace.prototype.fillRgb,
  11969. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11970. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11971. },
  11972. usesZeroToOneRange: true
  11973. };
  11974. return DeviceGrayCS;
  11975. })();
  11976. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11977. function DeviceRgbCS() {
  11978. this.name = 'DeviceRGB';
  11979. this.numComps = 3;
  11980. this.defaultColor = new Float32Array([0, 0, 0]);
  11981. }
  11982. DeviceRgbCS.prototype = {
  11983. getRgb: ColorSpace.prototype.getRgb,
  11984. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11985. dest, destOffset) {
  11986. var r = (src[srcOffset] * 255) | 0;
  11987. var g = (src[srcOffset + 1] * 255) | 0;
  11988. var b = (src[srcOffset + 2] * 255) | 0;
  11989. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11990. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11991. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11992. },
  11993. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11994. dest, destOffset, bits,
  11995. alpha01) {
  11996. if (bits === 8 && alpha01 === 0) {
  11997. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  11998. return;
  11999. }
  12000. var scale = 255 / ((1 << bits) - 1);
  12001. var j = srcOffset, q = destOffset;
  12002. for (var i = 0; i < count; ++i) {
  12003. dest[q++] = (scale * src[j++]) | 0;
  12004. dest[q++] = (scale * src[j++]) | 0;
  12005. dest[q++] = (scale * src[j++]) | 0;
  12006. q += alpha01;
  12007. }
  12008. },
  12009. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  12010. alpha01) {
  12011. return (inputLength * (3 + alpha01) / 3) | 0;
  12012. },
  12013. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  12014. return bits === 8;
  12015. },
  12016. fillRgb: ColorSpace.prototype.fillRgb,
  12017. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  12018. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12019. },
  12020. usesZeroToOneRange: true
  12021. };
  12022. return DeviceRgbCS;
  12023. })();
  12024. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12025. // The coefficients below was found using numerical analysis: the method of
  12026. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12027. // where color_value is the tabular value from the table of sampled RGB colors
  12028. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12029. // CMYK color conversion using the estimation below:
  12030. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12031. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12032. var c = src[srcOffset + 0] * srcScale;
  12033. var m = src[srcOffset + 1] * srcScale;
  12034. var y = src[srcOffset + 2] * srcScale;
  12035. var k = src[srcOffset + 3] * srcScale;
  12036. var r =
  12037. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12038. 18.82290502165302 * y + 212.25662451639585 * k +
  12039. -285.2331026137004) +
  12040. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12041. -17.873870861415444 * k - 5.497006427196366) +
  12042. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12043. 17.5119270841813) +
  12044. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12045. var g =
  12046. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12047. 6.871425592049007 * y + 31.159100130055922 * k +
  12048. -79.2970844816548) +
  12049. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12050. 131.35250912493976 * k - 190.9453302588951) +
  12051. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12052. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12053. var b =
  12054. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12055. 30.89978309703729 * y - 0.23883238689178934 * k +
  12056. -14.183576799673286) +
  12057. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12058. 50.606957656360734 * k - 112.23884253719248) +
  12059. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12060. -193.58209356861505) +
  12061. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12062. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12063. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12064. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12065. }
  12066. function DeviceCmykCS() {
  12067. this.name = 'DeviceCMYK';
  12068. this.numComps = 4;
  12069. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12070. }
  12071. DeviceCmykCS.prototype = {
  12072. getRgb: ColorSpace.prototype.getRgb,
  12073. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12074. dest, destOffset) {
  12075. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12076. },
  12077. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12078. dest, destOffset, bits,
  12079. alpha01) {
  12080. var scale = 1 / ((1 << bits) - 1);
  12081. for (var i = 0; i < count; i++) {
  12082. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12083. srcOffset += 4;
  12084. destOffset += 3 + alpha01;
  12085. }
  12086. },
  12087. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12088. alpha01) {
  12089. return (inputLength / 4 * (3 + alpha01)) | 0;
  12090. },
  12091. isPassthrough: ColorSpace.prototype.isPassthrough,
  12092. fillRgb: ColorSpace.prototype.fillRgb,
  12093. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12094. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12095. },
  12096. usesZeroToOneRange: true
  12097. };
  12098. return DeviceCmykCS;
  12099. })();
  12100. //
  12101. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12102. //
  12103. var CalGrayCS = (function CalGrayCSClosure() {
  12104. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12105. this.name = 'CalGray';
  12106. this.numComps = 1;
  12107. this.defaultColor = new Float32Array([0]);
  12108. if (!whitePoint) {
  12109. error('WhitePoint missing - required for color space CalGray');
  12110. }
  12111. blackPoint = blackPoint || [0, 0, 0];
  12112. gamma = gamma || 1;
  12113. // Translate arguments to spec variables.
  12114. this.XW = whitePoint[0];
  12115. this.YW = whitePoint[1];
  12116. this.ZW = whitePoint[2];
  12117. this.XB = blackPoint[0];
  12118. this.YB = blackPoint[1];
  12119. this.ZB = blackPoint[2];
  12120. this.G = gamma;
  12121. // Validate variables as per spec.
  12122. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12123. error('Invalid WhitePoint components for ' + this.name +
  12124. ', no fallback available');
  12125. }
  12126. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12127. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12128. this.XB = this.YB = this.ZB = 0;
  12129. }
  12130. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12131. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12132. ', ZB: ' + this.ZB + ', only default values are supported.');
  12133. }
  12134. if (this.G < 1) {
  12135. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12136. ', falling back to default');
  12137. this.G = 1;
  12138. }
  12139. }
  12140. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12141. // A represents a gray component of a calibrated gray space.
  12142. // A <---> AG in the spec
  12143. var A = src[srcOffset] * scale;
  12144. var AG = Math.pow(A, cs.G);
  12145. // Computes L as per spec. ( = cs.YW * AG )
  12146. // Except if other than default BlackPoint values are used.
  12147. var L = cs.YW * AG;
  12148. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12149. // Convert values to rgb range [0, 255].
  12150. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12151. dest[destOffset] = val;
  12152. dest[destOffset + 1] = val;
  12153. dest[destOffset + 2] = val;
  12154. }
  12155. CalGrayCS.prototype = {
  12156. getRgb: ColorSpace.prototype.getRgb,
  12157. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12158. dest, destOffset) {
  12159. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12160. },
  12161. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12162. dest, destOffset, bits,
  12163. alpha01) {
  12164. var scale = 1 / ((1 << bits) - 1);
  12165. for (var i = 0; i < count; ++i) {
  12166. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12167. srcOffset += 1;
  12168. destOffset += 3 + alpha01;
  12169. }
  12170. },
  12171. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12172. return inputLength * (3 + alpha01);
  12173. },
  12174. isPassthrough: ColorSpace.prototype.isPassthrough,
  12175. fillRgb: ColorSpace.prototype.fillRgb,
  12176. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12177. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12178. },
  12179. usesZeroToOneRange: true
  12180. };
  12181. return CalGrayCS;
  12182. })();
  12183. //
  12184. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12185. //
  12186. var CalRGBCS = (function CalRGBCSClosure() {
  12187. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12188. // matrices.
  12189. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12190. 0.8951, 0.2664, -0.1614,
  12191. -0.7502, 1.7135, 0.0367,
  12192. 0.0389, -0.0685, 1.0296]);
  12193. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12194. 0.9869929, -0.1470543, 0.1599627,
  12195. 0.4323053, 0.5183603, 0.0492912,
  12196. -0.0085287, 0.0400428, 0.9684867]);
  12197. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12198. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12199. 3.2404542, -1.5371385, -0.4985314,
  12200. -0.9692660, 1.8760108, 0.0415560,
  12201. 0.0556434, -0.2040259, 1.0572252]);
  12202. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12203. var tempNormalizeMatrix = new Float32Array(3);
  12204. var tempConvertMatrix1 = new Float32Array(3);
  12205. var tempConvertMatrix2 = new Float32Array(3);
  12206. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12207. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12208. this.name = 'CalRGB';
  12209. this.numComps = 3;
  12210. this.defaultColor = new Float32Array(3);
  12211. if (!whitePoint) {
  12212. error('WhitePoint missing - required for color space CalRGB');
  12213. }
  12214. blackPoint = blackPoint || new Float32Array(3);
  12215. gamma = gamma || new Float32Array([1, 1, 1]);
  12216. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12217. // Translate arguments to spec variables.
  12218. var XW = whitePoint[0];
  12219. var YW = whitePoint[1];
  12220. var ZW = whitePoint[2];
  12221. this.whitePoint = whitePoint;
  12222. var XB = blackPoint[0];
  12223. var YB = blackPoint[1];
  12224. var ZB = blackPoint[2];
  12225. this.blackPoint = blackPoint;
  12226. this.GR = gamma[0];
  12227. this.GG = gamma[1];
  12228. this.GB = gamma[2];
  12229. this.MXA = matrix[0];
  12230. this.MYA = matrix[1];
  12231. this.MZA = matrix[2];
  12232. this.MXB = matrix[3];
  12233. this.MYB = matrix[4];
  12234. this.MZB = matrix[5];
  12235. this.MXC = matrix[6];
  12236. this.MYC = matrix[7];
  12237. this.MZC = matrix[8];
  12238. // Validate variables as per spec.
  12239. if (XW < 0 || ZW < 0 || YW !== 1) {
  12240. error('Invalid WhitePoint components for ' + this.name +
  12241. ', no fallback available');
  12242. }
  12243. if (XB < 0 || YB < 0 || ZB < 0) {
  12244. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12245. ', ' + ZB + '], falling back to default');
  12246. this.blackPoint = new Float32Array(3);
  12247. }
  12248. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12249. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12250. '] for ' + this.name + ', falling back to default');
  12251. this.GR = this.GG = this.GB = 1;
  12252. }
  12253. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12254. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12255. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12256. info('Invalid Matrix for ' + this.name + ' [' +
  12257. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12258. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12259. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12260. '], falling back to default');
  12261. this.MXA = this.MYB = this.MZC = 1;
  12262. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12263. }
  12264. }
  12265. function matrixProduct(a, b, result) {
  12266. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12267. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12268. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12269. }
  12270. function convertToFlat(sourceWhitePoint, LMS, result) {
  12271. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12272. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12273. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12274. }
  12275. function convertToD65(sourceWhitePoint, LMS, result) {
  12276. var D65X = 0.95047;
  12277. var D65Y = 1;
  12278. var D65Z = 1.08883;
  12279. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12280. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12281. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12282. }
  12283. function sRGBTransferFunction(color) {
  12284. // See http://en.wikipedia.org/wiki/SRGB.
  12285. if (color <= 0.0031308){
  12286. return adjustToRange(0, 1, 12.92 * color);
  12287. }
  12288. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12289. }
  12290. function adjustToRange(min, max, value) {
  12291. return Math.max(min, Math.min(max, value));
  12292. }
  12293. function decodeL(L) {
  12294. if (L < 0) {
  12295. return -decodeL(-L);
  12296. }
  12297. if (L > 8.0) {
  12298. return Math.pow(((L + 16) / 116), 3);
  12299. }
  12300. return L * DECODE_L_CONSTANT;
  12301. }
  12302. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12303. // In case the blackPoint is already the default blackPoint then there is
  12304. // no need to do compensation.
  12305. if (sourceBlackPoint[0] === 0 &&
  12306. sourceBlackPoint[1] === 0 &&
  12307. sourceBlackPoint[2] === 0) {
  12308. result[0] = XYZ_Flat[0];
  12309. result[1] = XYZ_Flat[1];
  12310. result[2] = XYZ_Flat[2];
  12311. return;
  12312. }
  12313. // For the blackPoint calculation details, please see
  12314. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12315. // AdobeBPC.pdf.
  12316. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12317. var zeroDecodeL = decodeL(0);
  12318. var X_DST = zeroDecodeL;
  12319. var X_SRC = decodeL(sourceBlackPoint[0]);
  12320. var Y_DST = zeroDecodeL;
  12321. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12322. var Z_DST = zeroDecodeL;
  12323. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12324. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12325. var X_Offset = 1 - X_Scale;
  12326. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12327. var Y_Offset = 1 - Y_Scale;
  12328. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12329. var Z_Offset = 1 - Z_Scale;
  12330. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12331. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12332. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12333. }
  12334. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12335. // In case the whitePoint is already flat then there is no need to do
  12336. // normalization.
  12337. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12338. result[0] = XYZ_In[0];
  12339. result[1] = XYZ_In[1];
  12340. result[2] = XYZ_In[2];
  12341. return;
  12342. }
  12343. var LMS = result;
  12344. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12345. var LMS_Flat = tempNormalizeMatrix;
  12346. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12347. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12348. }
  12349. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12350. var LMS = result;
  12351. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12352. var LMS_D65 = tempNormalizeMatrix;
  12353. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12354. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12355. }
  12356. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12357. // A, B and C represent a red, green and blue components of a calibrated
  12358. // rgb space.
  12359. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12360. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12361. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12362. // A <---> AGR in the spec
  12363. // B <---> BGG in the spec
  12364. // C <---> CGB in the spec
  12365. var AGR = Math.pow(A, cs.GR);
  12366. var BGG = Math.pow(B, cs.GG);
  12367. var CGB = Math.pow(C, cs.GB);
  12368. // Computes intermediate variables L, M, N as per spec.
  12369. // To decode X, Y, Z values map L, M, N directly to them.
  12370. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12371. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12372. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12373. // The following calculations are based on this document:
  12374. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12375. // AdobeBPC.pdf.
  12376. var XYZ = tempConvertMatrix1;
  12377. XYZ[0] = X;
  12378. XYZ[1] = Y;
  12379. XYZ[2] = Z;
  12380. var XYZ_Flat = tempConvertMatrix2;
  12381. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12382. var XYZ_Black = tempConvertMatrix1;
  12383. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12384. var XYZ_D65 = tempConvertMatrix2;
  12385. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12386. var SRGB = tempConvertMatrix1;
  12387. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12388. var sR = sRGBTransferFunction(SRGB[0]);
  12389. var sG = sRGBTransferFunction(SRGB[1]);
  12390. var sB = sRGBTransferFunction(SRGB[2]);
  12391. // Convert the values to rgb range [0, 255].
  12392. dest[destOffset] = Math.round(sR * 255);
  12393. dest[destOffset + 1] = Math.round(sG * 255);
  12394. dest[destOffset + 2] = Math.round(sB * 255);
  12395. }
  12396. CalRGBCS.prototype = {
  12397. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12398. var rgb = new Uint8Array(3);
  12399. this.getRgbItem(src, srcOffset, rgb, 0);
  12400. return rgb;
  12401. },
  12402. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12403. dest, destOffset) {
  12404. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12405. },
  12406. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12407. dest, destOffset, bits,
  12408. alpha01) {
  12409. var scale = 1 / ((1 << bits) - 1);
  12410. for (var i = 0; i < count; ++i) {
  12411. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12412. srcOffset += 3;
  12413. destOffset += 3 + alpha01;
  12414. }
  12415. },
  12416. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12417. return (inputLength * (3 + alpha01) / 3) | 0;
  12418. },
  12419. isPassthrough: ColorSpace.prototype.isPassthrough,
  12420. fillRgb: ColorSpace.prototype.fillRgb,
  12421. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12422. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12423. },
  12424. usesZeroToOneRange: true
  12425. };
  12426. return CalRGBCS;
  12427. })();
  12428. //
  12429. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12430. //
  12431. var LabCS = (function LabCSClosure() {
  12432. function LabCS(whitePoint, blackPoint, range) {
  12433. this.name = 'Lab';
  12434. this.numComps = 3;
  12435. this.defaultColor = new Float32Array([0, 0, 0]);
  12436. if (!whitePoint) {
  12437. error('WhitePoint missing - required for color space Lab');
  12438. }
  12439. blackPoint = blackPoint || [0, 0, 0];
  12440. range = range || [-100, 100, -100, 100];
  12441. // Translate args to spec variables
  12442. this.XW = whitePoint[0];
  12443. this.YW = whitePoint[1];
  12444. this.ZW = whitePoint[2];
  12445. this.amin = range[0];
  12446. this.amax = range[1];
  12447. this.bmin = range[2];
  12448. this.bmax = range[3];
  12449. // These are here just for completeness - the spec doesn't offer any
  12450. // formulas that use BlackPoint in Lab
  12451. this.XB = blackPoint[0];
  12452. this.YB = blackPoint[1];
  12453. this.ZB = blackPoint[2];
  12454. // Validate vars as per spec
  12455. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12456. error('Invalid WhitePoint components, no fallback available');
  12457. }
  12458. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12459. info('Invalid BlackPoint, falling back to default');
  12460. this.XB = this.YB = this.ZB = 0;
  12461. }
  12462. if (this.amin > this.amax || this.bmin > this.bmax) {
  12463. info('Invalid Range, falling back to defaults');
  12464. this.amin = -100;
  12465. this.amax = 100;
  12466. this.bmin = -100;
  12467. this.bmax = 100;
  12468. }
  12469. }
  12470. // Function g(x) from spec
  12471. function fn_g(x) {
  12472. if (x >= 6 / 29) {
  12473. return x * x * x;
  12474. } else {
  12475. return (108 / 841) * (x - 4 / 29);
  12476. }
  12477. }
  12478. function decode(value, high1, low2, high2) {
  12479. return low2 + (value) * (high2 - low2) / (high1);
  12480. }
  12481. // If decoding is needed maxVal should be 2^bits per component - 1.
  12482. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12483. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12484. // not the usual [0, 1]. If a command like setFillColor is used the src
  12485. // values will already be within the correct range. However, if we are
  12486. // converting an image we have to map the values to the correct range given
  12487. // above.
  12488. // Ls,as,bs <---> L*,a*,b* in the spec
  12489. var Ls = src[srcOffset];
  12490. var as = src[srcOffset + 1];
  12491. var bs = src[srcOffset + 2];
  12492. if (maxVal !== false) {
  12493. Ls = decode(Ls, maxVal, 0, 100);
  12494. as = decode(as, maxVal, cs.amin, cs.amax);
  12495. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12496. }
  12497. // Adjust limits of 'as' and 'bs'
  12498. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12499. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12500. // Computes intermediate variables X,Y,Z as per spec
  12501. var M = (Ls + 16) / 116;
  12502. var L = M + (as / 500);
  12503. var N = M - (bs / 200);
  12504. var X = cs.XW * fn_g(L);
  12505. var Y = cs.YW * fn_g(M);
  12506. var Z = cs.ZW * fn_g(N);
  12507. var r, g, b;
  12508. // Using different conversions for D50 and D65 white points,
  12509. // per http://www.color.org/srgb.pdf
  12510. if (cs.ZW < 1) {
  12511. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12512. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12513. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12514. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12515. } else {
  12516. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12517. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12518. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12519. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12520. }
  12521. // clamp color values to [0,1] range then convert to [0,255] range.
  12522. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12523. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12524. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12525. }
  12526. LabCS.prototype = {
  12527. getRgb: ColorSpace.prototype.getRgb,
  12528. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12529. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12530. },
  12531. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12532. dest, destOffset, bits,
  12533. alpha01) {
  12534. var maxVal = (1 << bits) - 1;
  12535. for (var i = 0; i < count; i++) {
  12536. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12537. srcOffset += 3;
  12538. destOffset += 3 + alpha01;
  12539. }
  12540. },
  12541. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12542. return (inputLength * (3 + alpha01) / 3) | 0;
  12543. },
  12544. isPassthrough: ColorSpace.prototype.isPassthrough,
  12545. fillRgb: ColorSpace.prototype.fillRgb,
  12546. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12547. // XXX: Decoding is handled with the lab conversion because of the strange
  12548. // ranges that are used.
  12549. return true;
  12550. },
  12551. usesZeroToOneRange: false
  12552. };
  12553. return LabCS;
  12554. })();
  12555. var ARCFourCipher = (function ARCFourCipherClosure() {
  12556. function ARCFourCipher(key) {
  12557. this.a = 0;
  12558. this.b = 0;
  12559. var s = new Uint8Array(256);
  12560. var i, j = 0, tmp, keyLength = key.length;
  12561. for (i = 0; i < 256; ++i) {
  12562. s[i] = i;
  12563. }
  12564. for (i = 0; i < 256; ++i) {
  12565. tmp = s[i];
  12566. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12567. s[i] = s[j];
  12568. s[j] = tmp;
  12569. }
  12570. this.s = s;
  12571. }
  12572. ARCFourCipher.prototype = {
  12573. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12574. var i, n = data.length, tmp, tmp2;
  12575. var a = this.a, b = this.b, s = this.s;
  12576. var output = new Uint8Array(n);
  12577. for (i = 0; i < n; ++i) {
  12578. a = (a + 1) & 0xFF;
  12579. tmp = s[a];
  12580. b = (b + tmp) & 0xFF;
  12581. tmp2 = s[b];
  12582. s[a] = tmp2;
  12583. s[b] = tmp;
  12584. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12585. }
  12586. this.a = a;
  12587. this.b = b;
  12588. return output;
  12589. }
  12590. };
  12591. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12592. return ARCFourCipher;
  12593. })();
  12594. var calculateMD5 = (function calculateMD5Closure() {
  12595. var r = new Uint8Array([
  12596. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12597. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12598. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12599. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12600. var k = new Int32Array([
  12601. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12602. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12603. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12604. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12605. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12606. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12607. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12608. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12609. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12610. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12611. -145523070, -1120210379, 718787259, -343485551]);
  12612. function hash(data, offset, length) {
  12613. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12614. // pre-processing
  12615. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12616. var padded = new Uint8Array(paddedLength);
  12617. var i, j, n;
  12618. for (i = 0; i < length; ++i) {
  12619. padded[i] = data[offset++];
  12620. }
  12621. padded[i++] = 0x80;
  12622. n = paddedLength - 8;
  12623. while (i < n) {
  12624. padded[i++] = 0;
  12625. }
  12626. padded[i++] = (length << 3) & 0xFF;
  12627. padded[i++] = (length >> 5) & 0xFF;
  12628. padded[i++] = (length >> 13) & 0xFF;
  12629. padded[i++] = (length >> 21) & 0xFF;
  12630. padded[i++] = (length >>> 29) & 0xFF;
  12631. padded[i++] = 0;
  12632. padded[i++] = 0;
  12633. padded[i++] = 0;
  12634. var w = new Int32Array(16);
  12635. for (i = 0; i < paddedLength;) {
  12636. for (j = 0; j < 16; ++j, i += 4) {
  12637. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12638. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12639. }
  12640. var a = h0, b = h1, c = h2, d = h3, f, g;
  12641. for (j = 0; j < 64; ++j) {
  12642. if (j < 16) {
  12643. f = (b & c) | ((~b) & d);
  12644. g = j;
  12645. } else if (j < 32) {
  12646. f = (d & b) | ((~d) & c);
  12647. g = (5 * j + 1) & 15;
  12648. } else if (j < 48) {
  12649. f = b ^ c ^ d;
  12650. g = (3 * j + 5) & 15;
  12651. } else {
  12652. f = c ^ (b | (~d));
  12653. g = (7 * j) & 15;
  12654. }
  12655. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12656. d = c;
  12657. c = b;
  12658. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12659. a = tmp;
  12660. }
  12661. h0 = (h0 + a) | 0;
  12662. h1 = (h1 + b) | 0;
  12663. h2 = (h2 + c) | 0;
  12664. h3 = (h3 + d) | 0;
  12665. }
  12666. return new Uint8Array([
  12667. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12668. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12669. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12670. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12671. ]);
  12672. }
  12673. return hash;
  12674. })();
  12675. var Word64 = (function Word64Closure() {
  12676. function Word64(highInteger, lowInteger) {
  12677. this.high = highInteger | 0;
  12678. this.low = lowInteger | 0;
  12679. }
  12680. Word64.prototype = {
  12681. and: function Word64_and(word) {
  12682. this.high &= word.high;
  12683. this.low &= word.low;
  12684. },
  12685. xor: function Word64_xor(word) {
  12686. this.high ^= word.high;
  12687. this.low ^= word.low;
  12688. },
  12689. or: function Word64_or(word) {
  12690. this.high |= word.high;
  12691. this.low |= word.low;
  12692. },
  12693. shiftRight: function Word64_shiftRight(places) {
  12694. if (places >= 32) {
  12695. this.low = (this.high >>> (places - 32)) | 0;
  12696. this.high = 0;
  12697. } else {
  12698. this.low = (this.low >>> places) | (this.high << (32 - places));
  12699. this.high = (this.high >>> places) | 0;
  12700. }
  12701. },
  12702. shiftLeft: function Word64_shiftLeft(places) {
  12703. if (places >= 32) {
  12704. this.high = this.low << (places - 32);
  12705. this.low = 0;
  12706. } else {
  12707. this.high = (this.high << places) | (this.low >>> (32 - places));
  12708. this.low = this.low << places;
  12709. }
  12710. },
  12711. rotateRight: function Word64_rotateRight(places) {
  12712. var low, high;
  12713. if (places & 32) {
  12714. high = this.low;
  12715. low = this.high;
  12716. } else {
  12717. low = this.low;
  12718. high = this.high;
  12719. }
  12720. places &= 31;
  12721. this.low = (low >>> places) | (high << (32 - places));
  12722. this.high = (high >>> places) | (low << (32 - places));
  12723. },
  12724. not: function Word64_not() {
  12725. this.high = ~this.high;
  12726. this.low = ~this.low;
  12727. },
  12728. add: function Word64_add(word) {
  12729. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12730. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12731. if (lowAdd > 0xFFFFFFFF) {
  12732. highAdd += 1;
  12733. }
  12734. this.low = lowAdd | 0;
  12735. this.high = highAdd | 0;
  12736. },
  12737. copyTo: function Word64_copyTo(bytes, offset) {
  12738. bytes[offset] = (this.high >>> 24) & 0xFF;
  12739. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12740. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12741. bytes[offset + 3] = this.high & 0xFF;
  12742. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12743. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12744. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12745. bytes[offset + 7] = this.low & 0xFF;
  12746. },
  12747. assign: function Word64_assign(word) {
  12748. this.high = word.high;
  12749. this.low = word.low;
  12750. }
  12751. };
  12752. return Word64;
  12753. })();
  12754. var calculateSHA256 = (function calculateSHA256Closure() {
  12755. function rotr(x, n) {
  12756. return (x >>> n) | (x << 32 - n);
  12757. }
  12758. function ch(x, y, z) {
  12759. return (x & y) ^ (~x & z);
  12760. }
  12761. function maj(x, y, z) {
  12762. return (x & y) ^ (x & z) ^ (y & z);
  12763. }
  12764. function sigma(x) {
  12765. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12766. }
  12767. function sigmaPrime(x) {
  12768. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12769. }
  12770. function littleSigma(x) {
  12771. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12772. }
  12773. function littleSigmaPrime(x) {
  12774. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12775. }
  12776. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12777. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12778. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12779. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12780. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12781. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12782. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12783. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12784. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12785. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12786. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12787. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12788. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12789. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12790. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12791. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12792. function hash(data, offset, length) {
  12793. // initial hash values
  12794. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12795. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12796. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12797. // pre-processing
  12798. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12799. var padded = new Uint8Array(paddedLength);
  12800. var i, j, n;
  12801. for (i = 0; i < length; ++i) {
  12802. padded[i] = data[offset++];
  12803. }
  12804. padded[i++] = 0x80;
  12805. n = paddedLength - 8;
  12806. while (i < n) {
  12807. padded[i++] = 0;
  12808. }
  12809. padded[i++] = 0;
  12810. padded[i++] = 0;
  12811. padded[i++] = 0;
  12812. padded[i++] = (length >>> 29) & 0xFF;
  12813. padded[i++] = (length >> 21) & 0xFF;
  12814. padded[i++] = (length >> 13) & 0xFF;
  12815. padded[i++] = (length >> 5) & 0xFF;
  12816. padded[i++] = (length << 3) & 0xFF;
  12817. var w = new Uint32Array(64);
  12818. // for each 512 bit block
  12819. for (i = 0; i < paddedLength;) {
  12820. for (j = 0; j < 16; ++j) {
  12821. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12822. (padded[i + 2] << 8) | (padded[i + 3]));
  12823. i += 4;
  12824. }
  12825. for (j = 16; j < 64; ++j) {
  12826. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12827. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12828. }
  12829. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12830. f = h5, g = h6, h = h7, t1, t2;
  12831. for (j = 0; j < 64; ++j) {
  12832. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12833. t2 = sigma(a) + maj(a, b, c);
  12834. h = g;
  12835. g = f;
  12836. f = e;
  12837. e = (d + t1) | 0;
  12838. d = c;
  12839. c = b;
  12840. b = a;
  12841. a = (t1 + t2) | 0;
  12842. }
  12843. h0 = (h0 + a) | 0;
  12844. h1 = (h1 + b) | 0;
  12845. h2 = (h2 + c) | 0;
  12846. h3 = (h3 + d) | 0;
  12847. h4 = (h4 + e) | 0;
  12848. h5 = (h5 + f) | 0;
  12849. h6 = (h6 + g) | 0;
  12850. h7 = (h7 + h) | 0;
  12851. }
  12852. return new Uint8Array([
  12853. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12854. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12855. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12856. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12857. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12858. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12859. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12860. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12861. ]);
  12862. }
  12863. return hash;
  12864. })();
  12865. var calculateSHA512 = (function calculateSHA512Closure() {
  12866. function ch(result, x, y, z, tmp) {
  12867. result.assign(x);
  12868. result.and(y);
  12869. tmp.assign(x);
  12870. tmp.not();
  12871. tmp.and(z);
  12872. result.xor(tmp);
  12873. }
  12874. function maj(result, x, y, z, tmp) {
  12875. result.assign(x);
  12876. result.and(y);
  12877. tmp.assign(x);
  12878. tmp.and(z);
  12879. result.xor(tmp);
  12880. tmp.assign(y);
  12881. tmp.and(z);
  12882. result.xor(tmp);
  12883. }
  12884. function sigma(result, x, tmp) {
  12885. result.assign(x);
  12886. result.rotateRight(28);
  12887. tmp.assign(x);
  12888. tmp.rotateRight(34);
  12889. result.xor(tmp);
  12890. tmp.assign(x);
  12891. tmp.rotateRight(39);
  12892. result.xor(tmp);
  12893. }
  12894. function sigmaPrime(result, x, tmp) {
  12895. result.assign(x);
  12896. result.rotateRight(14);
  12897. tmp.assign(x);
  12898. tmp.rotateRight(18);
  12899. result.xor(tmp);
  12900. tmp.assign(x);
  12901. tmp.rotateRight(41);
  12902. result.xor(tmp);
  12903. }
  12904. function littleSigma(result, x, tmp) {
  12905. result.assign(x);
  12906. result.rotateRight(1);
  12907. tmp.assign(x);
  12908. tmp.rotateRight(8);
  12909. result.xor(tmp);
  12910. tmp.assign(x);
  12911. tmp.shiftRight(7);
  12912. result.xor(tmp);
  12913. }
  12914. function littleSigmaPrime(result, x, tmp) {
  12915. result.assign(x);
  12916. result.rotateRight(19);
  12917. tmp.assign(x);
  12918. tmp.rotateRight(61);
  12919. result.xor(tmp);
  12920. tmp.assign(x);
  12921. tmp.shiftRight(6);
  12922. result.xor(tmp);
  12923. }
  12924. var k = [
  12925. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12926. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12927. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12928. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12929. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12930. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12931. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12932. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12933. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12934. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12935. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12936. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12937. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12938. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12939. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12940. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12941. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12942. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12943. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12944. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12945. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12946. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12947. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12948. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12949. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12950. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12951. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12952. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12953. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12954. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12955. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12956. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12957. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12958. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12959. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12960. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12961. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12962. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12963. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12964. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12965. function hash(data, offset, length, mode384) {
  12966. mode384 = !!mode384;
  12967. // initial hash values
  12968. var h0, h1, h2, h3, h4, h5, h6, h7;
  12969. if (!mode384) {
  12970. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12971. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12972. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12973. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12974. h4 = new Word64(0x510e527f, 0xade682d1);
  12975. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12976. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12977. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12978. }
  12979. else {
  12980. // SHA384 is exactly the same
  12981. // except with different starting values and a trimmed result
  12982. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12983. h1 = new Word64(0x629a292a, 0x367cd507);
  12984. h2 = new Word64(0x9159015a, 0x3070dd17);
  12985. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12986. h4 = new Word64(0x67332667, 0xffc00b31);
  12987. h5 = new Word64(0x8eb44a87, 0x68581511);
  12988. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12989. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12990. }
  12991. // pre-processing
  12992. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12993. var padded = new Uint8Array(paddedLength);
  12994. var i, j, n;
  12995. for (i = 0; i < length; ++i) {
  12996. padded[i] = data[offset++];
  12997. }
  12998. padded[i++] = 0x80;
  12999. n = paddedLength - 16;
  13000. while (i < n) {
  13001. padded[i++] = 0;
  13002. }
  13003. padded[i++] = 0;
  13004. padded[i++] = 0;
  13005. padded[i++] = 0;
  13006. padded[i++] = 0;
  13007. padded[i++] = 0;
  13008. padded[i++] = 0;
  13009. padded[i++] = 0;
  13010. padded[i++] = 0;
  13011. padded[i++] = 0;
  13012. padded[i++] = 0;
  13013. padded[i++] = 0;
  13014. padded[i++] = (length >>> 29) & 0xFF;
  13015. padded[i++] = (length >> 21) & 0xFF;
  13016. padded[i++] = (length >> 13) & 0xFF;
  13017. padded[i++] = (length >> 5) & 0xFF;
  13018. padded[i++] = (length << 3) & 0xFF;
  13019. var w = new Array(80);
  13020. for (i = 0; i < 80; i++) {
  13021. w[i] = new Word64(0, 0);
  13022. }
  13023. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13024. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13025. var g = new Word64(0, 0), h = new Word64(0, 0);
  13026. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13027. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13028. // for each 1024 bit block
  13029. for (i = 0; i < paddedLength;) {
  13030. for (j = 0; j < 16; ++j) {
  13031. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13032. (padded[i + 2] << 8) | (padded[i + 3]);
  13033. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13034. (padded[i + 6]) << 8 | (padded[i + 7]);
  13035. i += 8;
  13036. }
  13037. for (j = 16; j < 80; ++j) {
  13038. tmp3 = w[j];
  13039. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13040. tmp3.add(w[j - 7]);
  13041. littleSigma(tmp1, w[j - 15], tmp2);
  13042. tmp3.add(tmp1);
  13043. tmp3.add(w[j - 16]);
  13044. }
  13045. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13046. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13047. for (j = 0; j < 80; ++j) {
  13048. t1.assign(h);
  13049. sigmaPrime(tmp1, e, tmp2);
  13050. t1.add(tmp1);
  13051. ch(tmp1, e, f, g, tmp2);
  13052. t1.add(tmp1);
  13053. t1.add(k[j]);
  13054. t1.add(w[j]);
  13055. sigma(t2, a, tmp2);
  13056. maj(tmp1, a, b, c, tmp2);
  13057. t2.add(tmp1);
  13058. tmp3 = h;
  13059. h = g;
  13060. g = f;
  13061. f = e;
  13062. d.add(t1);
  13063. e = d;
  13064. d = c;
  13065. c = b;
  13066. b = a;
  13067. tmp3.assign(t1);
  13068. tmp3.add(t2);
  13069. a = tmp3;
  13070. }
  13071. h0.add(a);
  13072. h1.add(b);
  13073. h2.add(c);
  13074. h3.add(d);
  13075. h4.add(e);
  13076. h5.add(f);
  13077. h6.add(g);
  13078. h7.add(h);
  13079. }
  13080. var result;
  13081. if (!mode384) {
  13082. result = new Uint8Array(64);
  13083. h0.copyTo(result,0);
  13084. h1.copyTo(result,8);
  13085. h2.copyTo(result,16);
  13086. h3.copyTo(result,24);
  13087. h4.copyTo(result,32);
  13088. h5.copyTo(result,40);
  13089. h6.copyTo(result,48);
  13090. h7.copyTo(result,56);
  13091. }
  13092. else {
  13093. result = new Uint8Array(48);
  13094. h0.copyTo(result,0);
  13095. h1.copyTo(result,8);
  13096. h2.copyTo(result,16);
  13097. h3.copyTo(result,24);
  13098. h4.copyTo(result,32);
  13099. h5.copyTo(result,40);
  13100. }
  13101. return result;
  13102. }
  13103. return hash;
  13104. })();
  13105. var calculateSHA384 = (function calculateSHA384Closure() {
  13106. function hash(data, offset, length) {
  13107. return calculateSHA512(data, offset, length, true);
  13108. }
  13109. return hash;
  13110. })();
  13111. var NullCipher = (function NullCipherClosure() {
  13112. function NullCipher() {
  13113. }
  13114. NullCipher.prototype = {
  13115. decryptBlock: function NullCipher_decryptBlock(data) {
  13116. return data;
  13117. }
  13118. };
  13119. return NullCipher;
  13120. })();
  13121. var AES128Cipher = (function AES128CipherClosure() {
  13122. var rcon = new Uint8Array([
  13123. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13124. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13125. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13126. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13127. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13128. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13129. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13130. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13131. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13132. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13133. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13134. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13135. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13136. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13137. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13138. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13139. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13140. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13141. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13142. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13143. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13144. 0x74, 0xe8, 0xcb, 0x8d]);
  13145. var s = new Uint8Array([
  13146. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13147. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13148. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13149. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13150. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13151. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13152. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13153. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13154. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13155. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13156. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13157. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13158. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13159. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13160. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13161. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13162. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13163. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13164. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13165. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13166. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13167. 0xb0, 0x54, 0xbb, 0x16]);
  13168. var inv_s = new Uint8Array([
  13169. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13170. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13171. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13172. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13173. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13174. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13175. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13176. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13177. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13178. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13179. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13180. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13181. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13182. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13183. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13184. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13185. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13186. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13187. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13188. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13189. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13190. 0x55, 0x21, 0x0c, 0x7d]);
  13191. var mixCol = new Uint8Array(256);
  13192. for (var i = 0; i < 256; i++) {
  13193. if (i < 128) {
  13194. mixCol[i] = i << 1;
  13195. } else {
  13196. mixCol[i] = (i << 1) ^ 0x1b;
  13197. }
  13198. }
  13199. var mix = new Uint32Array([
  13200. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13201. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13202. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13203. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13204. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13205. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13206. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13207. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13208. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13209. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13210. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13211. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13212. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13213. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13214. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13215. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13216. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13217. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13218. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13219. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13220. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13221. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13222. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13223. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13224. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13225. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13226. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13227. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13228. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13229. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13230. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13231. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13232. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13233. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13234. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13235. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13236. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13237. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13238. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13239. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13240. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13241. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13242. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13243. function expandKey128(cipherKey) {
  13244. var b = 176, result = new Uint8Array(b);
  13245. result.set(cipherKey);
  13246. for (var j = 16, i = 1; j < b; ++i) {
  13247. // RotWord
  13248. var t1 = result[j - 3], t2 = result[j - 2],
  13249. t3 = result[j - 1], t4 = result[j - 4];
  13250. // SubWord
  13251. t1 = s[t1];
  13252. t2 = s[t2];
  13253. t3 = s[t3];
  13254. t4 = s[t4];
  13255. // Rcon
  13256. t1 = t1 ^ rcon[i];
  13257. for (var n = 0; n < 4; ++n) {
  13258. result[j] = (t1 ^= result[j - 16]);
  13259. j++;
  13260. result[j] = (t2 ^= result[j - 16]);
  13261. j++;
  13262. result[j] = (t3 ^= result[j - 16]);
  13263. j++;
  13264. result[j] = (t4 ^= result[j - 16]);
  13265. j++;
  13266. }
  13267. }
  13268. return result;
  13269. }
  13270. function decrypt128(input, key) {
  13271. var state = new Uint8Array(16);
  13272. state.set(input);
  13273. var i, j, k;
  13274. var t, u, v;
  13275. // AddRoundKey
  13276. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13277. state[j] ^= key[k];
  13278. }
  13279. for (i = 9; i >= 1; --i) {
  13280. // InvShiftRows
  13281. t = state[13];
  13282. state[13] = state[9];
  13283. state[9] = state[5];
  13284. state[5] = state[1];
  13285. state[1] = t;
  13286. t = state[14];
  13287. u = state[10];
  13288. state[14] = state[6];
  13289. state[10] = state[2];
  13290. state[6] = t;
  13291. state[2] = u;
  13292. t = state[15];
  13293. u = state[11];
  13294. v = state[7];
  13295. state[15] = state[3];
  13296. state[11] = t;
  13297. state[7] = u;
  13298. state[3] = v;
  13299. // InvSubBytes
  13300. for (j = 0; j < 16; ++j) {
  13301. state[j] = inv_s[state[j]];
  13302. }
  13303. // AddRoundKey
  13304. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13305. state[j] ^= key[k];
  13306. }
  13307. // InvMixColumns
  13308. for (j = 0; j < 16; j += 4) {
  13309. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13310. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13311. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13312. (s3 >>> 24) ^ (s3 << 8));
  13313. state[j] = (t >>> 24) & 0xFF;
  13314. state[j + 1] = (t >> 16) & 0xFF;
  13315. state[j + 2] = (t >> 8) & 0xFF;
  13316. state[j + 3] = t & 0xFF;
  13317. }
  13318. }
  13319. // InvShiftRows
  13320. t = state[13];
  13321. state[13] = state[9];
  13322. state[9] = state[5];
  13323. state[5] = state[1];
  13324. state[1] = t;
  13325. t = state[14];
  13326. u = state[10];
  13327. state[14] = state[6];
  13328. state[10] = state[2];
  13329. state[6] = t;
  13330. state[2] = u;
  13331. t = state[15];
  13332. u = state[11];
  13333. v = state[7];
  13334. state[15] = state[3];
  13335. state[11] = t;
  13336. state[7] = u;
  13337. state[3] = v;
  13338. for (j = 0; j < 16; ++j) {
  13339. // InvSubBytes
  13340. state[j] = inv_s[state[j]];
  13341. // AddRoundKey
  13342. state[j] ^= key[j];
  13343. }
  13344. return state;
  13345. }
  13346. function encrypt128(input, key) {
  13347. var t, u, v, k;
  13348. var state = new Uint8Array(16);
  13349. state.set(input);
  13350. for (j = 0; j < 16; ++j) {
  13351. // AddRoundKey
  13352. state[j] ^= key[j];
  13353. }
  13354. for (i = 1; i < 10; i++) {
  13355. //SubBytes
  13356. for (j = 0; j < 16; ++j) {
  13357. state[j] = s[state[j]];
  13358. }
  13359. //ShiftRows
  13360. v = state[1];
  13361. state[1] = state[5];
  13362. state[5] = state[9];
  13363. state[9] = state[13];
  13364. state[13] = v;
  13365. v = state[2];
  13366. u = state[6];
  13367. state[2] = state[10];
  13368. state[6] = state[14];
  13369. state[10] = v;
  13370. state[14] = u;
  13371. v = state[3];
  13372. u = state[7];
  13373. t = state[11];
  13374. state[3] = state[15];
  13375. state[7] = v;
  13376. state[11] = u;
  13377. state[15] = t;
  13378. //MixColumns
  13379. for (var j = 0; j < 16; j += 4) {
  13380. var s0 = state[j + 0], s1 = state[j + 1];
  13381. var s2 = state[j + 2], s3 = state[j + 3];
  13382. t = s0 ^ s1 ^ s2 ^ s3;
  13383. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13384. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13385. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13386. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13387. }
  13388. //AddRoundKey
  13389. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13390. state[j] ^= key[k];
  13391. }
  13392. }
  13393. //SubBytes
  13394. for (j = 0; j < 16; ++j) {
  13395. state[j] = s[state[j]];
  13396. }
  13397. //ShiftRows
  13398. v = state[1];
  13399. state[1] = state[5];
  13400. state[5] = state[9];
  13401. state[9] = state[13];
  13402. state[13] = v;
  13403. v = state[2];
  13404. u = state[6];
  13405. state[2] = state[10];
  13406. state[6] = state[14];
  13407. state[10] = v;
  13408. state[14] = u;
  13409. v = state[3];
  13410. u = state[7];
  13411. t = state[11];
  13412. state[3] = state[15];
  13413. state[7] = v;
  13414. state[11] = u;
  13415. state[15] = t;
  13416. //AddRoundKey
  13417. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13418. state[j] ^= key[k];
  13419. }
  13420. return state;
  13421. }
  13422. function AES128Cipher(key) {
  13423. this.key = expandKey128(key);
  13424. this.buffer = new Uint8Array(16);
  13425. this.bufferPosition = 0;
  13426. }
  13427. function decryptBlock2(data, finalize) {
  13428. var i, j, ii, sourceLength = data.length,
  13429. buffer = this.buffer, bufferLength = this.bufferPosition,
  13430. result = [], iv = this.iv;
  13431. for (i = 0; i < sourceLength; ++i) {
  13432. buffer[bufferLength] = data[i];
  13433. ++bufferLength;
  13434. if (bufferLength < 16) {
  13435. continue;
  13436. }
  13437. // buffer is full, decrypting
  13438. var plain = decrypt128(buffer, this.key);
  13439. // xor-ing the IV vector to get plain text
  13440. for (j = 0; j < 16; ++j) {
  13441. plain[j] ^= iv[j];
  13442. }
  13443. iv = buffer;
  13444. result.push(plain);
  13445. buffer = new Uint8Array(16);
  13446. bufferLength = 0;
  13447. }
  13448. // saving incomplete buffer
  13449. this.buffer = buffer;
  13450. this.bufferLength = bufferLength;
  13451. this.iv = iv;
  13452. if (result.length === 0) {
  13453. return new Uint8Array([]);
  13454. }
  13455. // combining plain text blocks into one
  13456. var outputLength = 16 * result.length;
  13457. if (finalize) {
  13458. // undo a padding that is described in RFC 2898
  13459. var lastBlock = result[result.length - 1];
  13460. var psLen = lastBlock[15];
  13461. if (psLen <= 16) {
  13462. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13463. if (lastBlock[i] !== psLen) {
  13464. // Invalid padding, assume that the block has no padding.
  13465. psLen = 0;
  13466. break;
  13467. }
  13468. }
  13469. outputLength -= psLen;
  13470. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13471. }
  13472. }
  13473. var output = new Uint8Array(outputLength);
  13474. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13475. output.set(result[i], j);
  13476. }
  13477. return output;
  13478. }
  13479. AES128Cipher.prototype = {
  13480. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13481. var i, sourceLength = data.length;
  13482. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13483. // waiting for IV values -- they are at the start of the stream
  13484. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13485. buffer[bufferLength] = data[i];
  13486. }
  13487. if (bufferLength < 16) {
  13488. // need more data
  13489. this.bufferLength = bufferLength;
  13490. return new Uint8Array([]);
  13491. }
  13492. this.iv = buffer;
  13493. this.buffer = new Uint8Array(16);
  13494. this.bufferLength = 0;
  13495. // starting decryption
  13496. this.decryptBlock = decryptBlock2;
  13497. return this.decryptBlock(data.subarray(16), finalize);
  13498. },
  13499. encrypt: function AES128Cipher_encrypt(data, iv) {
  13500. var i, j, ii, sourceLength = data.length,
  13501. buffer = this.buffer, bufferLength = this.bufferPosition,
  13502. result = [];
  13503. if (!iv) {
  13504. iv = new Uint8Array(16);
  13505. }
  13506. for (i = 0; i < sourceLength; ++i) {
  13507. buffer[bufferLength] = data[i];
  13508. ++bufferLength;
  13509. if (bufferLength < 16) {
  13510. continue;
  13511. }
  13512. for (j = 0; j < 16; ++j) {
  13513. buffer[j] ^= iv[j];
  13514. }
  13515. // buffer is full, encrypting
  13516. var cipher = encrypt128(buffer, this.key);
  13517. iv = cipher;
  13518. result.push(cipher);
  13519. buffer = new Uint8Array(16);
  13520. bufferLength = 0;
  13521. }
  13522. // saving incomplete buffer
  13523. this.buffer = buffer;
  13524. this.bufferLength = bufferLength;
  13525. this.iv = iv;
  13526. if (result.length === 0) {
  13527. return new Uint8Array([]);
  13528. }
  13529. // combining plain text blocks into one
  13530. var outputLength = 16 * result.length;
  13531. var output = new Uint8Array(outputLength);
  13532. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13533. output.set(result[i], j);
  13534. }
  13535. return output;
  13536. }
  13537. };
  13538. return AES128Cipher;
  13539. })();
  13540. var AES256Cipher = (function AES256CipherClosure() {
  13541. var rcon = new Uint8Array([
  13542. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13543. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13544. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13545. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13546. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13547. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13548. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13549. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13550. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13551. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13552. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13553. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13554. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13555. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13556. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13557. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13558. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13559. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13560. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13561. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13562. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13563. 0x74, 0xe8, 0xcb, 0x8d]);
  13564. var s = new Uint8Array([
  13565. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13566. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13567. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13568. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13569. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13570. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13571. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13572. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13573. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13574. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13575. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13576. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13577. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13578. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13579. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13580. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13581. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13582. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13583. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13584. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13585. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13586. 0xb0, 0x54, 0xbb, 0x16]);
  13587. var inv_s = new Uint8Array([
  13588. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13589. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13590. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13591. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13592. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13593. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13594. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13595. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13596. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13597. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13598. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13599. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13600. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13601. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13602. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13603. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13604. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13605. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13606. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13607. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13608. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13609. 0x55, 0x21, 0x0c, 0x7d]);
  13610. var mixCol = new Uint8Array(256);
  13611. for (var i = 0; i < 256; i++) {
  13612. if (i < 128) {
  13613. mixCol[i] = i << 1;
  13614. } else {
  13615. mixCol[i] = (i << 1) ^ 0x1b;
  13616. }
  13617. }
  13618. var mix = new Uint32Array([
  13619. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13620. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13621. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13622. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13623. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13624. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13625. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13626. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13627. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13628. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13629. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13630. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13631. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13632. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13633. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13634. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13635. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13636. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13637. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13638. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13639. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13640. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13641. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13642. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13643. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13644. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13645. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13646. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13647. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13648. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13649. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13650. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13651. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13652. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13653. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13654. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13655. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13656. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13657. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13658. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13659. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13660. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13661. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13662. function expandKey256(cipherKey) {
  13663. var b = 240, result = new Uint8Array(b);
  13664. var r = 1;
  13665. result.set(cipherKey);
  13666. for (var j = 32, i = 1; j < b; ++i) {
  13667. if (j % 32 === 16) {
  13668. t1 = s[t1];
  13669. t2 = s[t2];
  13670. t3 = s[t3];
  13671. t4 = s[t4];
  13672. } else if (j % 32 === 0) {
  13673. // RotWord
  13674. var t1 = result[j - 3], t2 = result[j - 2],
  13675. t3 = result[j - 1], t4 = result[j - 4];
  13676. // SubWord
  13677. t1 = s[t1];
  13678. t2 = s[t2];
  13679. t3 = s[t3];
  13680. t4 = s[t4];
  13681. // Rcon
  13682. t1 = t1 ^ r;
  13683. if ((r <<= 1) >= 256) {
  13684. r = (r ^ 0x1b) & 0xFF;
  13685. }
  13686. }
  13687. for (var n = 0; n < 4; ++n) {
  13688. result[j] = (t1 ^= result[j - 32]);
  13689. j++;
  13690. result[j] = (t2 ^= result[j - 32]);
  13691. j++;
  13692. result[j] = (t3 ^= result[j - 32]);
  13693. j++;
  13694. result[j] = (t4 ^= result[j - 32]);
  13695. j++;
  13696. }
  13697. }
  13698. return result;
  13699. }
  13700. function decrypt256(input, key) {
  13701. var state = new Uint8Array(16);
  13702. state.set(input);
  13703. var i, j, k;
  13704. var t, u, v;
  13705. // AddRoundKey
  13706. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13707. state[j] ^= key[k];
  13708. }
  13709. for (i = 13; i >= 1; --i) {
  13710. // InvShiftRows
  13711. t = state[13];
  13712. state[13] = state[9];
  13713. state[9] = state[5];
  13714. state[5] = state[1];
  13715. state[1] = t;
  13716. t = state[14];
  13717. u = state[10];
  13718. state[14] = state[6];
  13719. state[10] = state[2];
  13720. state[6] = t;
  13721. state[2] = u;
  13722. t = state[15];
  13723. u = state[11];
  13724. v = state[7];
  13725. state[15] = state[3];
  13726. state[11] = t;
  13727. state[7] = u;
  13728. state[3] = v;
  13729. // InvSubBytes
  13730. for (j = 0; j < 16; ++j) {
  13731. state[j] = inv_s[state[j]];
  13732. }
  13733. // AddRoundKey
  13734. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13735. state[j] ^= key[k];
  13736. }
  13737. // InvMixColumns
  13738. for (j = 0; j < 16; j += 4) {
  13739. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13740. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13741. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13742. (s3 >>> 24) ^ (s3 << 8));
  13743. state[j] = (t >>> 24) & 0xFF;
  13744. state[j + 1] = (t >> 16) & 0xFF;
  13745. state[j + 2] = (t >> 8) & 0xFF;
  13746. state[j + 3] = t & 0xFF;
  13747. }
  13748. }
  13749. // InvShiftRows
  13750. t = state[13];
  13751. state[13] = state[9];
  13752. state[9] = state[5];
  13753. state[5] = state[1];
  13754. state[1] = t;
  13755. t = state[14];
  13756. u = state[10];
  13757. state[14] = state[6];
  13758. state[10] = state[2];
  13759. state[6] = t;
  13760. state[2] = u;
  13761. t = state[15];
  13762. u = state[11];
  13763. v = state[7];
  13764. state[15] = state[3];
  13765. state[11] = t;
  13766. state[7] = u;
  13767. state[3] = v;
  13768. for (j = 0; j < 16; ++j) {
  13769. // InvSubBytes
  13770. state[j] = inv_s[state[j]];
  13771. // AddRoundKey
  13772. state[j] ^= key[j];
  13773. }
  13774. return state;
  13775. }
  13776. function encrypt256(input, key) {
  13777. var t, u, v, k;
  13778. var state = new Uint8Array(16);
  13779. state.set(input);
  13780. for (j = 0; j < 16; ++j) {
  13781. // AddRoundKey
  13782. state[j] ^= key[j];
  13783. }
  13784. for (i = 1; i < 14; i++) {
  13785. //SubBytes
  13786. for (j = 0; j < 16; ++j) {
  13787. state[j] = s[state[j]];
  13788. }
  13789. //ShiftRows
  13790. v = state[1];
  13791. state[1] = state[5];
  13792. state[5] = state[9];
  13793. state[9] = state[13];
  13794. state[13] = v;
  13795. v = state[2];
  13796. u = state[6];
  13797. state[2] = state[10];
  13798. state[6] = state[14];
  13799. state[10] = v;
  13800. state[14] = u;
  13801. v = state[3];
  13802. u = state[7];
  13803. t = state[11];
  13804. state[3] = state[15];
  13805. state[7] = v;
  13806. state[11] = u;
  13807. state[15] = t;
  13808. //MixColumns
  13809. for (var j = 0; j < 16; j += 4) {
  13810. var s0 = state[j + 0], s1 = state[j + 1];
  13811. var s2 = state[j + 2], s3 = state[j + 3];
  13812. t = s0 ^ s1 ^ s2 ^ s3;
  13813. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13814. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13815. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13816. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13817. }
  13818. //AddRoundKey
  13819. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13820. state[j] ^= key[k];
  13821. }
  13822. }
  13823. //SubBytes
  13824. for (j = 0; j < 16; ++j) {
  13825. state[j] = s[state[j]];
  13826. }
  13827. //ShiftRows
  13828. v = state[1];
  13829. state[1] = state[5];
  13830. state[5] = state[9];
  13831. state[9] = state[13];
  13832. state[13] = v;
  13833. v = state[2];
  13834. u = state[6];
  13835. state[2] = state[10];
  13836. state[6] = state[14];
  13837. state[10] = v;
  13838. state[14] = u;
  13839. v = state[3];
  13840. u = state[7];
  13841. t = state[11];
  13842. state[3] = state[15];
  13843. state[7] = v;
  13844. state[11] = u;
  13845. state[15] = t;
  13846. //AddRoundKey
  13847. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13848. state[j] ^= key[k];
  13849. }
  13850. return state;
  13851. }
  13852. function AES256Cipher(key) {
  13853. this.key = expandKey256(key);
  13854. this.buffer = new Uint8Array(16);
  13855. this.bufferPosition = 0;
  13856. }
  13857. function decryptBlock2(data, finalize) {
  13858. var i, j, ii, sourceLength = data.length,
  13859. buffer = this.buffer, bufferLength = this.bufferPosition,
  13860. result = [], iv = this.iv;
  13861. for (i = 0; i < sourceLength; ++i) {
  13862. buffer[bufferLength] = data[i];
  13863. ++bufferLength;
  13864. if (bufferLength < 16) {
  13865. continue;
  13866. }
  13867. // buffer is full, decrypting
  13868. var plain = decrypt256(buffer, this.key);
  13869. // xor-ing the IV vector to get plain text
  13870. for (j = 0; j < 16; ++j) {
  13871. plain[j] ^= iv[j];
  13872. }
  13873. iv = buffer;
  13874. result.push(plain);
  13875. buffer = new Uint8Array(16);
  13876. bufferLength = 0;
  13877. }
  13878. // saving incomplete buffer
  13879. this.buffer = buffer;
  13880. this.bufferLength = bufferLength;
  13881. this.iv = iv;
  13882. if (result.length === 0) {
  13883. return new Uint8Array([]);
  13884. }
  13885. // combining plain text blocks into one
  13886. var outputLength = 16 * result.length;
  13887. if (finalize) {
  13888. // undo a padding that is described in RFC 2898
  13889. var lastBlock = result[result.length - 1];
  13890. var psLen = lastBlock[15];
  13891. if (psLen <= 16) {
  13892. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13893. if (lastBlock[i] !== psLen) {
  13894. // Invalid padding, assume that the block has no padding.
  13895. psLen = 0;
  13896. break;
  13897. }
  13898. }
  13899. outputLength -= psLen;
  13900. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13901. }
  13902. }
  13903. var output = new Uint8Array(outputLength);
  13904. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13905. output.set(result[i], j);
  13906. }
  13907. return output;
  13908. }
  13909. AES256Cipher.prototype = {
  13910. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13911. var i, sourceLength = data.length;
  13912. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13913. // if not supplied an IV wait for IV values
  13914. // they are at the start of the stream
  13915. if (iv) {
  13916. this.iv = iv;
  13917. } else {
  13918. for (i = 0; bufferLength < 16 &&
  13919. i < sourceLength; ++i, ++bufferLength) {
  13920. buffer[bufferLength] = data[i];
  13921. }
  13922. if (bufferLength < 16) {
  13923. //need more data
  13924. this.bufferLength = bufferLength;
  13925. return new Uint8Array([]);
  13926. }
  13927. this.iv = buffer;
  13928. data = data.subarray(16);
  13929. }
  13930. this.buffer = new Uint8Array(16);
  13931. this.bufferLength = 0;
  13932. // starting decryption
  13933. this.decryptBlock = decryptBlock2;
  13934. return this.decryptBlock(data, finalize);
  13935. },
  13936. encrypt: function AES256Cipher_encrypt(data, iv) {
  13937. var i, j, ii, sourceLength = data.length,
  13938. buffer = this.buffer, bufferLength = this.bufferPosition,
  13939. result = [];
  13940. if (!iv) {
  13941. iv = new Uint8Array(16);
  13942. }
  13943. for (i = 0; i < sourceLength; ++i) {
  13944. buffer[bufferLength] = data[i];
  13945. ++bufferLength;
  13946. if (bufferLength < 16) {
  13947. continue;
  13948. }
  13949. for (j = 0; j < 16; ++j) {
  13950. buffer[j] ^= iv[j];
  13951. }
  13952. // buffer is full, encrypting
  13953. var cipher = encrypt256(buffer, this.key);
  13954. this.iv = cipher;
  13955. result.push(cipher);
  13956. buffer = new Uint8Array(16);
  13957. bufferLength = 0;
  13958. }
  13959. // saving incomplete buffer
  13960. this.buffer = buffer;
  13961. this.bufferLength = bufferLength;
  13962. this.iv = iv;
  13963. if (result.length === 0) {
  13964. return new Uint8Array([]);
  13965. }
  13966. // combining plain text blocks into one
  13967. var outputLength = 16 * result.length;
  13968. var output = new Uint8Array(outputLength);
  13969. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13970. output.set(result[i], j);
  13971. }
  13972. return output;
  13973. }
  13974. };
  13975. return AES256Cipher;
  13976. })();
  13977. var PDF17 = (function PDF17Closure() {
  13978. function compareByteArrays(array1, array2) {
  13979. if (array1.length !== array2.length) {
  13980. return false;
  13981. }
  13982. for (var i = 0; i < array1.length; i++) {
  13983. if (array1[i] !== array2[i]) {
  13984. return false;
  13985. }
  13986. }
  13987. return true;
  13988. }
  13989. function PDF17() {
  13990. }
  13991. PDF17.prototype = {
  13992. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13993. ownerValidationSalt,
  13994. userBytes,
  13995. ownerPassword) {
  13996. var hashData = new Uint8Array(password.length + 56);
  13997. hashData.set(password, 0);
  13998. hashData.set(ownerValidationSalt, password.length);
  13999. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14000. var result = calculateSHA256(hashData, 0, hashData.length);
  14001. return compareByteArrays(result, ownerPassword);
  14002. },
  14003. checkUserPassword: function PDF17_checkUserPassword(password,
  14004. userValidationSalt,
  14005. userPassword) {
  14006. var hashData = new Uint8Array(password.length + 8);
  14007. hashData.set(password, 0);
  14008. hashData.set(userValidationSalt, password.length);
  14009. var result = calculateSHA256(hashData, 0, hashData.length);
  14010. return compareByteArrays(result, userPassword);
  14011. },
  14012. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  14013. ownerEncryption) {
  14014. var hashData = new Uint8Array(password.length + 56);
  14015. hashData.set(password, 0);
  14016. hashData.set(ownerKeySalt, password.length);
  14017. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14018. var key = calculateSHA256(hashData, 0, hashData.length);
  14019. var cipher = new AES256Cipher(key);
  14020. return cipher.decryptBlock(ownerEncryption,
  14021. false,
  14022. new Uint8Array(16));
  14023. },
  14024. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14025. userEncryption) {
  14026. var hashData = new Uint8Array(password.length + 8);
  14027. hashData.set(password, 0);
  14028. hashData.set(userKeySalt, password.length);
  14029. //key is the decryption key for the UE string
  14030. var key = calculateSHA256(hashData, 0, hashData.length);
  14031. var cipher = new AES256Cipher(key);
  14032. return cipher.decryptBlock(userEncryption,
  14033. false,
  14034. new Uint8Array(16));
  14035. }
  14036. };
  14037. return PDF17;
  14038. })();
  14039. var PDF20 = (function PDF20Closure() {
  14040. function concatArrays(array1, array2) {
  14041. var t = new Uint8Array(array1.length + array2.length);
  14042. t.set(array1, 0);
  14043. t.set(array2, array1.length);
  14044. return t;
  14045. }
  14046. function calculatePDF20Hash(password, input, userBytes) {
  14047. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14048. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14049. var e = [0];
  14050. var i = 0;
  14051. while (i < 64 || e[e.length - 1] > i - 32) {
  14052. var arrayLength = password.length + k.length + userBytes.length;
  14053. var k1 = new Uint8Array(arrayLength * 64);
  14054. var array = concatArrays(password, k);
  14055. array = concatArrays(array, userBytes);
  14056. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14057. k1.set(array, pos);
  14058. }
  14059. //AES128 CBC NO PADDING with
  14060. //first 16 bytes of k as the key and the second 16 as the iv.
  14061. var cipher = new AES128Cipher(k.subarray(0, 16));
  14062. e = cipher.encrypt(k1, k.subarray(16, 32));
  14063. //Now we have to take the first 16 bytes of an unsigned
  14064. //big endian integer... and compute the remainder
  14065. //modulo 3.... That is a fairly large number and
  14066. //JavaScript isn't going to handle that well...
  14067. //So we're using a trick that allows us to perform
  14068. //modulo math byte by byte
  14069. var remainder = 0;
  14070. for (var z = 0; z < 16; z++) {
  14071. remainder *= (256 % 3);
  14072. remainder %= 3;
  14073. remainder += ((e[z] >>> 0) % 3);
  14074. remainder %= 3;
  14075. }
  14076. if (remainder === 0) {
  14077. k = calculateSHA256(e, 0, e.length);
  14078. }
  14079. else if (remainder === 1) {
  14080. k = calculateSHA384(e, 0, e.length);
  14081. }
  14082. else if (remainder === 2) {
  14083. k = calculateSHA512(e, 0, e.length);
  14084. }
  14085. i++;
  14086. }
  14087. return k.subarray(0, 32);
  14088. }
  14089. function PDF20() {
  14090. }
  14091. function compareByteArrays(array1, array2) {
  14092. if (array1.length !== array2.length) {
  14093. return false;
  14094. }
  14095. for (var i = 0; i < array1.length; i++) {
  14096. if (array1[i] !== array2[i]) {
  14097. return false;
  14098. }
  14099. }
  14100. return true;
  14101. }
  14102. PDF20.prototype = {
  14103. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14104. return calculatePDF20Hash(password, concatBytes, userBytes);
  14105. },
  14106. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14107. ownerValidationSalt,
  14108. userBytes,
  14109. ownerPassword) {
  14110. var hashData = new Uint8Array(password.length + 56);
  14111. hashData.set(password, 0);
  14112. hashData.set(ownerValidationSalt, password.length);
  14113. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14114. var result = calculatePDF20Hash(password, hashData, userBytes);
  14115. return compareByteArrays(result, ownerPassword);
  14116. },
  14117. checkUserPassword: function PDF20_checkUserPassword(password,
  14118. userValidationSalt,
  14119. userPassword) {
  14120. var hashData = new Uint8Array(password.length + 8);
  14121. hashData.set(password, 0);
  14122. hashData.set(userValidationSalt, password.length);
  14123. var result = calculatePDF20Hash(password, hashData, []);
  14124. return compareByteArrays(result, userPassword);
  14125. },
  14126. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14127. ownerEncryption) {
  14128. var hashData = new Uint8Array(password.length + 56);
  14129. hashData.set(password, 0);
  14130. hashData.set(ownerKeySalt, password.length);
  14131. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14132. var key = calculatePDF20Hash(password, hashData, userBytes);
  14133. var cipher = new AES256Cipher(key);
  14134. return cipher.decryptBlock(ownerEncryption,
  14135. false,
  14136. new Uint8Array(16));
  14137. },
  14138. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14139. userEncryption) {
  14140. var hashData = new Uint8Array(password.length + 8);
  14141. hashData.set(password, 0);
  14142. hashData.set(userKeySalt, password.length);
  14143. //key is the decryption key for the UE string
  14144. var key = calculatePDF20Hash(password, hashData, []);
  14145. var cipher = new AES256Cipher(key);
  14146. return cipher.decryptBlock(userEncryption,
  14147. false,
  14148. new Uint8Array(16));
  14149. }
  14150. };
  14151. return PDF20;
  14152. })();
  14153. var CipherTransform = (function CipherTransformClosure() {
  14154. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14155. this.stringCipherConstructor = stringCipherConstructor;
  14156. this.streamCipherConstructor = streamCipherConstructor;
  14157. }
  14158. CipherTransform.prototype = {
  14159. createStream: function CipherTransform_createStream(stream, length) {
  14160. var cipher = new this.streamCipherConstructor();
  14161. return new DecryptStream(stream, length,
  14162. function cipherTransformDecryptStream(data, finalize) {
  14163. return cipher.decryptBlock(data, finalize);
  14164. }
  14165. );
  14166. },
  14167. decryptString: function CipherTransform_decryptString(s) {
  14168. var cipher = new this.stringCipherConstructor();
  14169. var data = stringToBytes(s);
  14170. data = cipher.decryptBlock(data, true);
  14171. return bytesToString(data);
  14172. }
  14173. };
  14174. return CipherTransform;
  14175. })();
  14176. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14177. var defaultPasswordBytes = new Uint8Array([
  14178. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14179. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14180. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14181. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14182. function createEncryptionKey20(revision, password, ownerPassword,
  14183. ownerValidationSalt, ownerKeySalt, uBytes,
  14184. userPassword, userValidationSalt, userKeySalt,
  14185. ownerEncryption, userEncryption, perms) {
  14186. if (password) {
  14187. var passwordLength = Math.min(127, password.length);
  14188. password = password.subarray(0, passwordLength);
  14189. } else {
  14190. password = [];
  14191. }
  14192. var pdfAlgorithm;
  14193. if (revision === 6) {
  14194. pdfAlgorithm = new PDF20();
  14195. } else {
  14196. pdfAlgorithm = new PDF17();
  14197. }
  14198. if (pdfAlgorithm) {
  14199. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14200. userPassword)) {
  14201. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14202. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  14203. uBytes,
  14204. ownerPassword)) {
  14205. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14206. ownerEncryption);
  14207. }
  14208. }
  14209. return null;
  14210. }
  14211. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14212. flags, revision, keyLength, encryptMetadata) {
  14213. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14214. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14215. if (password) {
  14216. n = Math.min(32, password.length);
  14217. for (; i < n; ++i) {
  14218. hashData[i] = password[i];
  14219. }
  14220. }
  14221. j = 0;
  14222. while (i < 32) {
  14223. hashData[i++] = defaultPasswordBytes[j++];
  14224. }
  14225. // as now the padded password in the hashData[0..i]
  14226. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14227. hashData[i++] = ownerPassword[j];
  14228. }
  14229. hashData[i++] = flags & 0xFF;
  14230. hashData[i++] = (flags >> 8) & 0xFF;
  14231. hashData[i++] = (flags >> 16) & 0xFF;
  14232. hashData[i++] = (flags >>> 24) & 0xFF;
  14233. for (j = 0, n = fileId.length; j < n; ++j) {
  14234. hashData[i++] = fileId[j];
  14235. }
  14236. if (revision >= 4 && !encryptMetadata) {
  14237. hashData[i++] = 0xFF;
  14238. hashData[i++] = 0xFF;
  14239. hashData[i++] = 0xFF;
  14240. hashData[i++] = 0xFF;
  14241. }
  14242. var hash = calculateMD5(hashData, 0, i);
  14243. var keyLengthInBytes = keyLength >> 3;
  14244. if (revision >= 3) {
  14245. for (j = 0; j < 50; ++j) {
  14246. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14247. }
  14248. }
  14249. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14250. var cipher, checkData;
  14251. if (revision >= 3) {
  14252. for (i = 0; i < 32; ++i) {
  14253. hashData[i] = defaultPasswordBytes[i];
  14254. }
  14255. for (j = 0, n = fileId.length; j < n; ++j) {
  14256. hashData[i++] = fileId[j];
  14257. }
  14258. cipher = new ARCFourCipher(encryptionKey);
  14259. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14260. n = encryptionKey.length;
  14261. var derivedKey = new Uint8Array(n), k;
  14262. for (j = 1; j <= 19; ++j) {
  14263. for (k = 0; k < n; ++k) {
  14264. derivedKey[k] = encryptionKey[k] ^ j;
  14265. }
  14266. cipher = new ARCFourCipher(derivedKey);
  14267. checkData = cipher.encryptBlock(checkData);
  14268. }
  14269. for (j = 0, n = checkData.length; j < n; ++j) {
  14270. if (userPassword[j] !== checkData[j]) {
  14271. return null;
  14272. }
  14273. }
  14274. } else {
  14275. cipher = new ARCFourCipher(encryptionKey);
  14276. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14277. for (j = 0, n = checkData.length; j < n; ++j) {
  14278. if (userPassword[j] !== checkData[j]) {
  14279. return null;
  14280. }
  14281. }
  14282. }
  14283. return encryptionKey;
  14284. }
  14285. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14286. var hashData = new Uint8Array(32), i = 0, j, n;
  14287. n = Math.min(32, password.length);
  14288. for (; i < n; ++i) {
  14289. hashData[i] = password[i];
  14290. }
  14291. j = 0;
  14292. while (i < 32) {
  14293. hashData[i++] = defaultPasswordBytes[j++];
  14294. }
  14295. var hash = calculateMD5(hashData, 0, i);
  14296. var keyLengthInBytes = keyLength >> 3;
  14297. if (revision >= 3) {
  14298. for (j = 0; j < 50; ++j) {
  14299. hash = calculateMD5(hash, 0, hash.length);
  14300. }
  14301. }
  14302. var cipher, userPassword;
  14303. if (revision >= 3) {
  14304. userPassword = ownerPassword;
  14305. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14306. for (j = 19; j >= 0; j--) {
  14307. for (k = 0; k < keyLengthInBytes; ++k) {
  14308. derivedKey[k] = hash[k] ^ j;
  14309. }
  14310. cipher = new ARCFourCipher(derivedKey);
  14311. userPassword = cipher.encryptBlock(userPassword);
  14312. }
  14313. } else {
  14314. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14315. userPassword = cipher.encryptBlock(ownerPassword);
  14316. }
  14317. return userPassword;
  14318. }
  14319. var identityName = Name.get('Identity');
  14320. function CipherTransformFactory(dict, fileId, password) {
  14321. var filter = dict.get('Filter');
  14322. if (!isName(filter) || filter.name !== 'Standard') {
  14323. error('unknown encryption method');
  14324. }
  14325. this.dict = dict;
  14326. var algorithm = dict.get('V');
  14327. if (!isInt(algorithm) ||
  14328. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14329. algorithm !== 5)) {
  14330. error('unsupported encryption algorithm');
  14331. }
  14332. this.algorithm = algorithm;
  14333. var keyLength = dict.get('Length') || 40;
  14334. if (!isInt(keyLength) ||
  14335. keyLength < 40 || (keyLength % 8) !== 0) {
  14336. error('invalid key length');
  14337. }
  14338. // prepare keys
  14339. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14340. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14341. var flags = dict.get('P');
  14342. var revision = dict.get('R');
  14343. // meaningful when V is 4 or 5
  14344. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14345. dict.get('EncryptMetadata') !== false);
  14346. this.encryptMetadata = encryptMetadata;
  14347. var fileIdBytes = stringToBytes(fileId);
  14348. var passwordBytes;
  14349. if (password) {
  14350. passwordBytes = stringToBytes(password);
  14351. }
  14352. var encryptionKey;
  14353. if (algorithm !== 5) {
  14354. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14355. ownerPassword, userPassword, flags,
  14356. revision, keyLength, encryptMetadata);
  14357. }
  14358. else {
  14359. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14360. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14361. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14362. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14363. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14364. var ownerEncryption = stringToBytes(dict.get('OE'));
  14365. var userEncryption = stringToBytes(dict.get('UE'));
  14366. var perms = stringToBytes(dict.get('Perms'));
  14367. encryptionKey =
  14368. createEncryptionKey20(revision, passwordBytes,
  14369. ownerPassword, ownerValidationSalt,
  14370. ownerKeySalt, uBytes,
  14371. userPassword, userValidationSalt,
  14372. userKeySalt, ownerEncryption,
  14373. userEncryption, perms);
  14374. }
  14375. if (!encryptionKey && !password) {
  14376. throw new PasswordException('No password given',
  14377. PasswordResponses.NEED_PASSWORD);
  14378. } else if (!encryptionKey && password) {
  14379. // Attempting use the password as an owner password
  14380. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14381. revision, keyLength);
  14382. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14383. ownerPassword, userPassword, flags,
  14384. revision, keyLength, encryptMetadata);
  14385. }
  14386. if (!encryptionKey) {
  14387. throw new PasswordException('Incorrect Password',
  14388. PasswordResponses.INCORRECT_PASSWORD);
  14389. }
  14390. this.encryptionKey = encryptionKey;
  14391. if (algorithm >= 4) {
  14392. this.cf = dict.get('CF');
  14393. this.stmf = dict.get('StmF') || identityName;
  14394. this.strf = dict.get('StrF') || identityName;
  14395. this.eff = dict.get('EFF') || this.stmf;
  14396. }
  14397. }
  14398. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14399. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14400. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14401. key[i] = encryptionKey[i];
  14402. }
  14403. key[i++] = num & 0xFF;
  14404. key[i++] = (num >> 8) & 0xFF;
  14405. key[i++] = (num >> 16) & 0xFF;
  14406. key[i++] = gen & 0xFF;
  14407. key[i++] = (gen >> 8) & 0xFF;
  14408. if (isAes) {
  14409. key[i++] = 0x73;
  14410. key[i++] = 0x41;
  14411. key[i++] = 0x6C;
  14412. key[i++] = 0x54;
  14413. }
  14414. var hash = calculateMD5(key, 0, i);
  14415. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14416. }
  14417. function buildCipherConstructor(cf, name, num, gen, key) {
  14418. var cryptFilter = cf.get(name.name);
  14419. var cfm;
  14420. if (cryptFilter !== null && cryptFilter !== undefined) {
  14421. cfm = cryptFilter.get('CFM');
  14422. }
  14423. if (!cfm || cfm.name === 'None') {
  14424. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14425. return new NullCipher();
  14426. };
  14427. }
  14428. if ('V2' === cfm.name) {
  14429. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14430. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14431. };
  14432. }
  14433. if ('AESV2' === cfm.name) {
  14434. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14435. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14436. };
  14437. }
  14438. if ('AESV3' === cfm.name) {
  14439. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14440. return new AES256Cipher(key);
  14441. };
  14442. }
  14443. error('Unknown crypto method');
  14444. }
  14445. CipherTransformFactory.prototype = {
  14446. createCipherTransform:
  14447. function CipherTransformFactory_createCipherTransform(num, gen) {
  14448. if (this.algorithm === 4 || this.algorithm === 5) {
  14449. return new CipherTransform(
  14450. buildCipherConstructor(this.cf, this.stmf,
  14451. num, gen, this.encryptionKey),
  14452. buildCipherConstructor(this.cf, this.strf,
  14453. num, gen, this.encryptionKey));
  14454. }
  14455. // algorithms 1 and 2
  14456. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14457. var cipherConstructor = function buildCipherCipherConstructor() {
  14458. return new ARCFourCipher(key);
  14459. };
  14460. return new CipherTransform(cipherConstructor, cipherConstructor);
  14461. }
  14462. };
  14463. return CipherTransformFactory;
  14464. })();
  14465. var PatternType = {
  14466. FUNCTION_BASED: 1,
  14467. AXIAL: 2,
  14468. RADIAL: 3,
  14469. FREE_FORM_MESH: 4,
  14470. LATTICE_FORM_MESH: 5,
  14471. COONS_PATCH_MESH: 6,
  14472. TENSOR_PATCH_MESH: 7
  14473. };
  14474. var Pattern = (function PatternClosure() {
  14475. // Constructor should define this.getPattern
  14476. function Pattern() {
  14477. error('should not call Pattern constructor');
  14478. }
  14479. Pattern.prototype = {
  14480. // Input: current Canvas context
  14481. // Output: the appropriate fillStyle or strokeStyle
  14482. getPattern: function Pattern_getPattern(ctx) {
  14483. error('Should not call Pattern.getStyle: ' + ctx);
  14484. }
  14485. };
  14486. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14487. res) {
  14488. var dict = isStream(shading) ? shading.dict : shading;
  14489. var type = dict.get('ShadingType');
  14490. try {
  14491. switch (type) {
  14492. case PatternType.AXIAL:
  14493. case PatternType.RADIAL:
  14494. // Both radial and axial shadings are handled by RadialAxial shading.
  14495. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14496. case PatternType.FREE_FORM_MESH:
  14497. case PatternType.LATTICE_FORM_MESH:
  14498. case PatternType.COONS_PATCH_MESH:
  14499. case PatternType.TENSOR_PATCH_MESH:
  14500. return new Shadings.Mesh(shading, matrix, xref, res);
  14501. default:
  14502. throw new Error('Unknown PatternType: ' + type);
  14503. }
  14504. } catch (ex) {
  14505. if (ex instanceof MissingDataException) {
  14506. throw ex;
  14507. }
  14508. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14509. warn(ex);
  14510. return new Shadings.Dummy();
  14511. }
  14512. };
  14513. return Pattern;
  14514. })();
  14515. var Shadings = {};
  14516. // A small number to offset the first/last color stops so we can insert ones to
  14517. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14518. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14519. // internally so we have to go bigger.
  14520. Shadings.SMALL_NUMBER = 1e-2;
  14521. // Radial and axial shading have very similar implementations
  14522. // If needed, the implementations can be broken into two classes
  14523. Shadings.RadialAxial = (function RadialAxialClosure() {
  14524. function RadialAxial(dict, matrix, xref, res) {
  14525. this.matrix = matrix;
  14526. this.coordsArr = dict.get('Coords');
  14527. this.shadingType = dict.get('ShadingType');
  14528. this.type = 'Pattern';
  14529. var cs = dict.get('ColorSpace', 'CS');
  14530. cs = ColorSpace.parse(cs, xref, res);
  14531. this.cs = cs;
  14532. var t0 = 0.0, t1 = 1.0;
  14533. if (dict.has('Domain')) {
  14534. var domainArr = dict.get('Domain');
  14535. t0 = domainArr[0];
  14536. t1 = domainArr[1];
  14537. }
  14538. var extendStart = false, extendEnd = false;
  14539. if (dict.has('Extend')) {
  14540. var extendArr = dict.get('Extend');
  14541. extendStart = extendArr[0];
  14542. extendEnd = extendArr[1];
  14543. }
  14544. if (this.shadingType === PatternType.RADIAL &&
  14545. (!extendStart || !extendEnd)) {
  14546. // Radial gradient only currently works if either circle is fully within
  14547. // the other circle.
  14548. var x1 = this.coordsArr[0];
  14549. var y1 = this.coordsArr[1];
  14550. var r1 = this.coordsArr[2];
  14551. var x2 = this.coordsArr[3];
  14552. var y2 = this.coordsArr[4];
  14553. var r2 = this.coordsArr[5];
  14554. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14555. if (r1 <= r2 + distance &&
  14556. r2 <= r1 + distance) {
  14557. warn('Unsupported radial gradient.');
  14558. }
  14559. }
  14560. this.extendStart = extendStart;
  14561. this.extendEnd = extendEnd;
  14562. var fnObj = dict.get('Function');
  14563. var fn = PDFFunction.parseArray(xref, fnObj);
  14564. // 10 samples seems good enough for now, but probably won't work
  14565. // if there are sharp color changes. Ideally, we would implement
  14566. // the spec faithfully and add lossless optimizations.
  14567. var diff = t1 - t0;
  14568. var step = diff / 10;
  14569. var colorStops = this.colorStops = [];
  14570. // Protect against bad domains so we don't end up in an infinte loop below.
  14571. if (t0 >= t1 || step <= 0) {
  14572. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14573. // now.
  14574. info('Bad shading domain.');
  14575. return;
  14576. }
  14577. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14578. var rgbColor;
  14579. for (var i = t0; i <= t1; i += step) {
  14580. ratio[0] = i;
  14581. fn(ratio, 0, color, 0);
  14582. rgbColor = cs.getRgb(color, 0);
  14583. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14584. colorStops.push([(i - t0) / diff, cssColor]);
  14585. }
  14586. var background = 'transparent';
  14587. if (dict.has('Background')) {
  14588. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14589. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14590. }
  14591. if (!extendStart) {
  14592. // Insert a color stop at the front and offset the first real color stop
  14593. // so it doesn't conflict with the one we insert.
  14594. colorStops.unshift([0, background]);
  14595. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14596. }
  14597. if (!extendEnd) {
  14598. // Same idea as above in extendStart but for the end.
  14599. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14600. colorStops.push([1, background]);
  14601. }
  14602. this.colorStops = colorStops;
  14603. }
  14604. RadialAxial.prototype = {
  14605. getIR: function RadialAxial_getIR() {
  14606. var coordsArr = this.coordsArr;
  14607. var shadingType = this.shadingType;
  14608. var type, p0, p1, r0, r1;
  14609. if (shadingType === PatternType.AXIAL) {
  14610. p0 = [coordsArr[0], coordsArr[1]];
  14611. p1 = [coordsArr[2], coordsArr[3]];
  14612. r0 = null;
  14613. r1 = null;
  14614. type = 'axial';
  14615. } else if (shadingType === PatternType.RADIAL) {
  14616. p0 = [coordsArr[0], coordsArr[1]];
  14617. p1 = [coordsArr[3], coordsArr[4]];
  14618. r0 = coordsArr[2];
  14619. r1 = coordsArr[5];
  14620. type = 'radial';
  14621. } else {
  14622. error('getPattern type unknown: ' + shadingType);
  14623. }
  14624. var matrix = this.matrix;
  14625. if (matrix) {
  14626. p0 = Util.applyTransform(p0, matrix);
  14627. p1 = Util.applyTransform(p1, matrix);
  14628. }
  14629. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14630. }
  14631. };
  14632. return RadialAxial;
  14633. })();
  14634. // All mesh shading. For now, they will be presented as set of the triangles
  14635. // to be drawn on the canvas and rgb color for each vertex.
  14636. Shadings.Mesh = (function MeshClosure() {
  14637. function MeshStreamReader(stream, context) {
  14638. this.stream = stream;
  14639. this.context = context;
  14640. this.buffer = 0;
  14641. this.bufferLength = 0;
  14642. var numComps = context.numComps;
  14643. this.tmpCompsBuf = new Float32Array(numComps);
  14644. var csNumComps = context.colorSpace;
  14645. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14646. this.tmpCompsBuf;
  14647. }
  14648. MeshStreamReader.prototype = {
  14649. get hasData() {
  14650. if (this.stream.end) {
  14651. return this.stream.pos < this.stream.end;
  14652. }
  14653. if (this.bufferLength > 0) {
  14654. return true;
  14655. }
  14656. var nextByte = this.stream.getByte();
  14657. if (nextByte < 0) {
  14658. return false;
  14659. }
  14660. this.buffer = nextByte;
  14661. this.bufferLength = 8;
  14662. return true;
  14663. },
  14664. readBits: function MeshStreamReader_readBits(n) {
  14665. var buffer = this.buffer;
  14666. var bufferLength = this.bufferLength;
  14667. if (n === 32) {
  14668. if (bufferLength === 0) {
  14669. return ((this.stream.getByte() << 24) |
  14670. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14671. this.stream.getByte()) >>> 0;
  14672. }
  14673. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14674. (this.stream.getByte() << 8) | this.stream.getByte();
  14675. var nextByte = this.stream.getByte();
  14676. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14677. return ((buffer << (8 - bufferLength)) |
  14678. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14679. }
  14680. if (n === 8 && bufferLength === 0) {
  14681. return this.stream.getByte();
  14682. }
  14683. while (bufferLength < n) {
  14684. buffer = (buffer << 8) | this.stream.getByte();
  14685. bufferLength += 8;
  14686. }
  14687. bufferLength -= n;
  14688. this.bufferLength = bufferLength;
  14689. this.buffer = buffer & ((1 << bufferLength) - 1);
  14690. return buffer >> bufferLength;
  14691. },
  14692. align: function MeshStreamReader_align() {
  14693. this.buffer = 0;
  14694. this.bufferLength = 0;
  14695. },
  14696. readFlag: function MeshStreamReader_readFlag() {
  14697. return this.readBits(this.context.bitsPerFlag);
  14698. },
  14699. readCoordinate: function MeshStreamReader_readCoordinate() {
  14700. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14701. var xi = this.readBits(bitsPerCoordinate);
  14702. var yi = this.readBits(bitsPerCoordinate);
  14703. var decode = this.context.decode;
  14704. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14705. 2.3283064365386963e-10; // 2 ^ -32
  14706. return [
  14707. xi * scale * (decode[1] - decode[0]) + decode[0],
  14708. yi * scale * (decode[3] - decode[2]) + decode[2]
  14709. ];
  14710. },
  14711. readComponents: function MeshStreamReader_readComponents() {
  14712. var numComps = this.context.numComps;
  14713. var bitsPerComponent = this.context.bitsPerComponent;
  14714. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14715. 2.3283064365386963e-10; // 2 ^ -32
  14716. var decode = this.context.decode;
  14717. var components = this.tmpCompsBuf;
  14718. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14719. var ci = this.readBits(bitsPerComponent);
  14720. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14721. }
  14722. var color = this.tmpCsCompsBuf;
  14723. if (this.context.colorFn) {
  14724. this.context.colorFn(components, 0, color, 0);
  14725. }
  14726. return this.context.colorSpace.getRgb(color, 0);
  14727. }
  14728. };
  14729. function decodeType4Shading(mesh, reader) {
  14730. var coords = mesh.coords;
  14731. var colors = mesh.colors;
  14732. var operators = [];
  14733. var ps = []; // not maintaining cs since that will match ps
  14734. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14735. while (reader.hasData) {
  14736. var f = reader.readFlag();
  14737. var coord = reader.readCoordinate();
  14738. var color = reader.readComponents();
  14739. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14740. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14741. switch (f) {
  14742. case 0:
  14743. verticesLeft = 3;
  14744. break;
  14745. case 1:
  14746. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14747. verticesLeft = 1;
  14748. break;
  14749. case 2:
  14750. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14751. verticesLeft = 1;
  14752. break;
  14753. }
  14754. operators.push(f);
  14755. }
  14756. ps.push(coords.length);
  14757. coords.push(coord);
  14758. colors.push(color);
  14759. verticesLeft--;
  14760. reader.align();
  14761. }
  14762. var psPacked = new Int32Array(ps);
  14763. mesh.figures.push({
  14764. type: 'triangles',
  14765. coords: psPacked,
  14766. colors: psPacked
  14767. });
  14768. }
  14769. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14770. var coords = mesh.coords;
  14771. var colors = mesh.colors;
  14772. var ps = []; // not maintaining cs since that will match ps
  14773. while (reader.hasData) {
  14774. var coord = reader.readCoordinate();
  14775. var color = reader.readComponents();
  14776. ps.push(coords.length);
  14777. coords.push(coord);
  14778. colors.push(color);
  14779. }
  14780. var psPacked = new Int32Array(ps);
  14781. mesh.figures.push({
  14782. type: 'lattice',
  14783. coords: psPacked,
  14784. colors: psPacked,
  14785. verticesPerRow: verticesPerRow
  14786. });
  14787. }
  14788. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14789. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14790. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14791. var getB = (function getBClosure() {
  14792. function buildB(count) {
  14793. var lut = [];
  14794. for (var i = 0; i <= count; i++) {
  14795. var t = i / count, t_ = 1 - t;
  14796. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14797. 3 * t * t * t_, t * t * t]));
  14798. }
  14799. return lut;
  14800. }
  14801. var cache = [];
  14802. return function getB(count) {
  14803. if (!cache[count]) {
  14804. cache[count] = buildB(count);
  14805. }
  14806. return cache[count];
  14807. };
  14808. })();
  14809. function buildFigureFromPatch(mesh, index) {
  14810. var figure = mesh.figures[index];
  14811. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14812. var coords = mesh.coords, colors = mesh.colors;
  14813. var pi = figure.coords;
  14814. var ci = figure.colors;
  14815. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14816. coords[pi[12]][0], coords[pi[15]][0]);
  14817. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14818. coords[pi[12]][1], coords[pi[15]][1]);
  14819. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14820. coords[pi[12]][0], coords[pi[15]][0]);
  14821. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14822. coords[pi[12]][1], coords[pi[15]][1]);
  14823. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14824. (mesh.bounds[2] - mesh.bounds[0]));
  14825. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14826. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14827. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14828. (mesh.bounds[3] - mesh.bounds[1]));
  14829. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14830. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14831. var verticesPerRow = splitXBy + 1;
  14832. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14833. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14834. var k = 0;
  14835. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14836. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14837. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14838. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14839. for (var row = 0; row <= splitYBy; row++) {
  14840. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14841. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14842. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14843. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14844. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14845. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14846. for (var col = 0; col <= splitXBy; col++, k++) {
  14847. if ((row === 0 || row === splitYBy) &&
  14848. (col === 0 || col === splitXBy)) {
  14849. continue;
  14850. }
  14851. var x = 0, y = 0;
  14852. var q = 0;
  14853. for (var i = 0; i <= 3; i++) {
  14854. for (var j = 0; j <= 3; j++, q++) {
  14855. var m = bRow[row][i] * bCol[col][j];
  14856. x += coords[pi[q]][0] * m;
  14857. y += coords[pi[q]][1] * m;
  14858. }
  14859. }
  14860. figureCoords[k] = coords.length;
  14861. coords.push([x, y]);
  14862. figureColors[k] = colors.length;
  14863. var newColor = new Uint8Array(3);
  14864. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14865. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14866. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14867. colors.push(newColor);
  14868. }
  14869. }
  14870. figureCoords[0] = pi[0];
  14871. figureColors[0] = ci[0];
  14872. figureCoords[splitXBy] = pi[3];
  14873. figureColors[splitXBy] = ci[1];
  14874. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14875. figureColors[verticesPerRow * splitYBy] = ci[2];
  14876. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14877. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14878. mesh.figures[index] = {
  14879. type: 'lattice',
  14880. coords: figureCoords,
  14881. colors: figureColors,
  14882. verticesPerRow: verticesPerRow
  14883. };
  14884. }
  14885. function decodeType6Shading(mesh, reader) {
  14886. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14887. var coords = mesh.coords;
  14888. var colors = mesh.colors;
  14889. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14890. var cs = new Int32Array(4); // c00, c30, c03, c33
  14891. while (reader.hasData) {
  14892. var f = reader.readFlag();
  14893. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14894. var i, ii;
  14895. var pi = coords.length;
  14896. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14897. coords.push(reader.readCoordinate());
  14898. }
  14899. var ci = colors.length;
  14900. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14901. colors.push(reader.readComponents());
  14902. }
  14903. var tmp1, tmp2, tmp3, tmp4;
  14904. switch (f) {
  14905. case 0:
  14906. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14907. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14908. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14909. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14910. cs[2] = ci + 1; cs[3] = ci + 2;
  14911. cs[0] = ci; cs[1] = ci + 3;
  14912. break;
  14913. case 1:
  14914. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14915. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14916. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14917. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14918. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14919. tmp1 = cs[2]; tmp2 = cs[3];
  14920. cs[2] = ci + 1; cs[3] = ci;
  14921. cs[0] = tmp1; cs[1] = tmp2;
  14922. break;
  14923. case 2:
  14924. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14925. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14926. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14927. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14928. cs[2] = cs[3]; cs[3] = ci + 1;
  14929. cs[0] = cs[1]; cs[1] = ci;
  14930. break;
  14931. case 3:
  14932. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14933. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14934. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14935. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14936. cs[2] = cs[0]; cs[3] = cs[1];
  14937. cs[0] = ci; cs[1] = ci + 1;
  14938. break;
  14939. }
  14940. // set p11, p12, p21, p22
  14941. ps[5] = coords.length;
  14942. coords.push([
  14943. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14944. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14945. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14946. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14947. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14948. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14949. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14950. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14951. ]);
  14952. ps[6] = coords.length;
  14953. coords.push([
  14954. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14955. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14956. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14957. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14958. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14959. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14960. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14961. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14962. ]);
  14963. ps[9] = coords.length;
  14964. coords.push([
  14965. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14966. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14967. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14968. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14969. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14970. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14971. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14972. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14973. ]);
  14974. ps[10] = coords.length;
  14975. coords.push([
  14976. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14977. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14978. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14979. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14980. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14981. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14982. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14983. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14984. ]);
  14985. mesh.figures.push({
  14986. type: 'patch',
  14987. coords: new Int32Array(ps), // making copies of ps and cs
  14988. colors: new Int32Array(cs)
  14989. });
  14990. }
  14991. }
  14992. function decodeType7Shading(mesh, reader) {
  14993. var coords = mesh.coords;
  14994. var colors = mesh.colors;
  14995. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14996. var cs = new Int32Array(4); // c00, c30, c03, c33
  14997. while (reader.hasData) {
  14998. var f = reader.readFlag();
  14999. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  15000. var i, ii;
  15001. var pi = coords.length;
  15002. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  15003. coords.push(reader.readCoordinate());
  15004. }
  15005. var ci = colors.length;
  15006. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15007. colors.push(reader.readComponents());
  15008. }
  15009. var tmp1, tmp2, tmp3, tmp4;
  15010. switch (f) {
  15011. case 0:
  15012. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15013. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  15014. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  15015. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15016. cs[2] = ci + 1; cs[3] = ci + 2;
  15017. cs[0] = ci; cs[1] = ci + 3;
  15018. break;
  15019. case 1:
  15020. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15021. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  15022. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  15023. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  15024. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  15025. tmp1 = cs[2]; tmp2 = cs[3];
  15026. cs[2] = ci + 1; cs[3] = ci;
  15027. cs[0] = tmp1; cs[1] = tmp2;
  15028. break;
  15029. case 2:
  15030. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  15031. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  15032. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  15033. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  15034. cs[2] = cs[3]; cs[3] = ci + 1;
  15035. cs[0] = cs[1]; cs[1] = ci;
  15036. break;
  15037. case 3:
  15038. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  15039. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  15040. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  15041. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  15042. cs[2] = cs[0]; cs[3] = cs[1];
  15043. cs[0] = ci; cs[1] = ci + 1;
  15044. break;
  15045. }
  15046. mesh.figures.push({
  15047. type: 'patch',
  15048. coords: new Int32Array(ps), // making copies of ps and cs
  15049. colors: new Int32Array(cs)
  15050. });
  15051. }
  15052. }
  15053. function updateBounds(mesh) {
  15054. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15055. maxX = minX, maxY = minY;
  15056. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15057. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15058. minX = minX > x ? x : minX;
  15059. minY = minY > y ? y : minY;
  15060. maxX = maxX < x ? x : maxX;
  15061. maxY = maxY < y ? y : maxY;
  15062. }
  15063. mesh.bounds = [minX, minY, maxX, maxY];
  15064. }
  15065. function packData(mesh) {
  15066. var i, ii, j, jj;
  15067. var coords = mesh.coords;
  15068. var coordsPacked = new Float32Array(coords.length * 2);
  15069. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15070. var xy = coords[i];
  15071. coordsPacked[j++] = xy[0];
  15072. coordsPacked[j++] = xy[1];
  15073. }
  15074. mesh.coords = coordsPacked;
  15075. var colors = mesh.colors;
  15076. var colorsPacked = new Uint8Array(colors.length * 3);
  15077. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15078. var c = colors[i];
  15079. colorsPacked[j++] = c[0];
  15080. colorsPacked[j++] = c[1];
  15081. colorsPacked[j++] = c[2];
  15082. }
  15083. mesh.colors = colorsPacked;
  15084. var figures = mesh.figures;
  15085. for (i = 0, ii = figures.length; i < ii; i++) {
  15086. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15087. for (j = 0, jj = ps.length; j < jj; j++) {
  15088. ps[j] *= 2;
  15089. cs[j] *= 3;
  15090. }
  15091. }
  15092. }
  15093. function Mesh(stream, matrix, xref, res) {
  15094. assert(isStream(stream), 'Mesh data is not a stream');
  15095. var dict = stream.dict;
  15096. this.matrix = matrix;
  15097. this.shadingType = dict.get('ShadingType');
  15098. this.type = 'Pattern';
  15099. this.bbox = dict.get('BBox');
  15100. var cs = dict.get('ColorSpace', 'CS');
  15101. cs = ColorSpace.parse(cs, xref, res);
  15102. this.cs = cs;
  15103. this.background = dict.has('Background') ?
  15104. cs.getRgb(dict.get('Background'), 0) : null;
  15105. var fnObj = dict.get('Function');
  15106. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15107. this.coords = [];
  15108. this.colors = [];
  15109. this.figures = [];
  15110. var decodeContext = {
  15111. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15112. bitsPerComponent: dict.get('BitsPerComponent'),
  15113. bitsPerFlag: dict.get('BitsPerFlag'),
  15114. decode: dict.get('Decode'),
  15115. colorFn: fn,
  15116. colorSpace: cs,
  15117. numComps: fn ? 1 : cs.numComps
  15118. };
  15119. var reader = new MeshStreamReader(stream, decodeContext);
  15120. var patchMesh = false;
  15121. switch (this.shadingType) {
  15122. case PatternType.FREE_FORM_MESH:
  15123. decodeType4Shading(this, reader);
  15124. break;
  15125. case PatternType.LATTICE_FORM_MESH:
  15126. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15127. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15128. decodeType5Shading(this, reader, verticesPerRow);
  15129. break;
  15130. case PatternType.COONS_PATCH_MESH:
  15131. decodeType6Shading(this, reader);
  15132. patchMesh = true;
  15133. break;
  15134. case PatternType.TENSOR_PATCH_MESH:
  15135. decodeType7Shading(this, reader);
  15136. patchMesh = true;
  15137. break;
  15138. default:
  15139. error('Unsupported mesh type.');
  15140. break;
  15141. }
  15142. if (patchMesh) {
  15143. // dirty bounds calculation for determining, how dense shall be triangles
  15144. updateBounds(this);
  15145. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15146. buildFigureFromPatch(this, i);
  15147. }
  15148. }
  15149. // calculate bounds
  15150. updateBounds(this);
  15151. packData(this);
  15152. }
  15153. Mesh.prototype = {
  15154. getIR: function Mesh_getIR() {
  15155. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15156. this.bounds, this.matrix, this.bbox, this.background];
  15157. }
  15158. };
  15159. return Mesh;
  15160. })();
  15161. Shadings.Dummy = (function DummyClosure() {
  15162. function Dummy() {
  15163. this.type = 'Pattern';
  15164. }
  15165. Dummy.prototype = {
  15166. getIR: function Dummy_getIR() {
  15167. return ['Dummy'];
  15168. }
  15169. };
  15170. return Dummy;
  15171. })();
  15172. function getTilingPatternIR(operatorList, dict, args) {
  15173. var matrix = dict.get('Matrix');
  15174. var bbox = dict.get('BBox');
  15175. var xstep = dict.get('XStep');
  15176. var ystep = dict.get('YStep');
  15177. var paintType = dict.get('PaintType');
  15178. var tilingType = dict.get('TilingType');
  15179. return [
  15180. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15181. paintType, tilingType
  15182. ];
  15183. }
  15184. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15185. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15186. uniquePrefix, idCounters, fontCache) {
  15187. this.pdfManager = pdfManager;
  15188. this.xref = xref;
  15189. this.handler = handler;
  15190. this.pageIndex = pageIndex;
  15191. this.uniquePrefix = uniquePrefix;
  15192. this.idCounters = idCounters;
  15193. this.fontCache = fontCache;
  15194. }
  15195. // Trying to minimize Date.now() usage and check every 100 time
  15196. var TIME_SLOT_DURATION_MS = 20;
  15197. var CHECK_TIME_EVERY = 100;
  15198. function TimeSlotManager() {
  15199. this.reset();
  15200. }
  15201. TimeSlotManager.prototype = {
  15202. check: function TimeSlotManager_check() {
  15203. if (++this.checked < CHECK_TIME_EVERY) {
  15204. return false;
  15205. }
  15206. this.checked = 0;
  15207. return this.endTime <= Date.now();
  15208. },
  15209. reset: function TimeSlotManager_reset() {
  15210. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15211. this.checked = 0;
  15212. }
  15213. };
  15214. var deferred = Promise.resolve();
  15215. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15216. PartialEvaluator.prototype = {
  15217. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15218. if (!isDict(resources)) {
  15219. return false;
  15220. }
  15221. var processed = Object.create(null);
  15222. if (resources.objId) {
  15223. processed[resources.objId] = true;
  15224. }
  15225. var nodes = [resources];
  15226. while (nodes.length) {
  15227. var key;
  15228. var node = nodes.shift();
  15229. // First check the current resources for blend modes.
  15230. var graphicStates = node.get('ExtGState');
  15231. if (isDict(graphicStates)) {
  15232. graphicStates = graphicStates.getAll();
  15233. for (key in graphicStates) {
  15234. var graphicState = graphicStates[key];
  15235. var bm = graphicState['BM'];
  15236. if (isName(bm) && bm.name !== 'Normal') {
  15237. return true;
  15238. }
  15239. }
  15240. }
  15241. // Descend into the XObjects to look for more resources and blend modes.
  15242. var xObjects = node.get('XObject');
  15243. if (!isDict(xObjects)) {
  15244. continue;
  15245. }
  15246. xObjects = xObjects.getAll();
  15247. for (key in xObjects) {
  15248. var xObject = xObjects[key];
  15249. if (!isStream(xObject)) {
  15250. continue;
  15251. }
  15252. if (xObject.dict.objId) {
  15253. if (processed[xObject.dict.objId]) {
  15254. // stream has objId and is processed already
  15255. continue;
  15256. }
  15257. processed[xObject.dict.objId] = true;
  15258. }
  15259. var xResources = xObject.dict.get('Resources');
  15260. // Checking objId to detect an infinite loop.
  15261. if (isDict(xResources) &&
  15262. (!xResources.objId || !processed[xResources.objId])) {
  15263. nodes.push(xResources);
  15264. if (xResources.objId) {
  15265. processed[xResources.objId] = true;
  15266. }
  15267. }
  15268. }
  15269. }
  15270. return false;
  15271. },
  15272. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15273. xobj, smask,
  15274. operatorList,
  15275. initialState) {
  15276. var matrix = xobj.dict.get('Matrix');
  15277. var bbox = xobj.dict.get('BBox');
  15278. var group = xobj.dict.get('Group');
  15279. if (group) {
  15280. var groupOptions = {
  15281. matrix: matrix,
  15282. bbox: bbox,
  15283. smask: smask,
  15284. isolated: false,
  15285. knockout: false
  15286. };
  15287. var groupSubtype = group.get('S');
  15288. var colorSpace;
  15289. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15290. groupOptions.isolated = (group.get('I') || false);
  15291. groupOptions.knockout = (group.get('K') || false);
  15292. colorSpace = (group.has('CS') ?
  15293. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15294. }
  15295. if (smask && smask.backdrop) {
  15296. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15297. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15298. }
  15299. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15300. }
  15301. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15302. return this.getOperatorList(xobj,
  15303. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15304. then(function () {
  15305. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15306. if (group) {
  15307. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15308. }
  15309. });
  15310. },
  15311. buildPaintImageXObject:
  15312. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15313. inline, operatorList,
  15314. cacheKey, imageCache) {
  15315. var self = this;
  15316. var dict = image.dict;
  15317. var w = dict.get('Width', 'W');
  15318. var h = dict.get('Height', 'H');
  15319. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15320. warn('Image dimensions are missing, or not numbers.');
  15321. return;
  15322. }
  15323. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15324. warn('Image exceeded maximum allowed size and was removed.');
  15325. return;
  15326. }
  15327. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15328. var imgData, args;
  15329. if (imageMask) {
  15330. // This depends on a tmpCanvas being filled with the
  15331. // current fillStyle, such that processing the pixel
  15332. // data can't be done here. Instead of creating a
  15333. // complete PDFImage, only read the information needed
  15334. // for later.
  15335. var width = dict.get('Width', 'W');
  15336. var height = dict.get('Height', 'H');
  15337. var bitStrideLength = (width + 7) >> 3;
  15338. var imgArray = image.getBytes(bitStrideLength * height);
  15339. var decode = dict.get('Decode', 'D');
  15340. var inverseDecode = (!!decode && decode[0] > 0);
  15341. imgData = PDFImage.createMask(imgArray, width, height,
  15342. image instanceof DecodeStream,
  15343. inverseDecode);
  15344. imgData.cached = true;
  15345. args = [imgData];
  15346. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15347. if (cacheKey) {
  15348. imageCache[cacheKey] = {
  15349. fn: OPS.paintImageMaskXObject,
  15350. args: args
  15351. };
  15352. }
  15353. return;
  15354. }
  15355. var softMask = (dict.get('SMask', 'SM') || false);
  15356. var mask = (dict.get('Mask') || false);
  15357. var SMALL_IMAGE_DIMENSIONS = 200;
  15358. // Inlining small images into the queue as RGB data
  15359. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15360. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15361. var imageObj = new PDFImage(this.xref, resources, image,
  15362. inline, null, null);
  15363. // We force the use of RGBA_32BPP images here, because we can't handle
  15364. // any other kind.
  15365. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15366. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15367. return;
  15368. }
  15369. // If there is no imageMask, create the PDFImage and a lot
  15370. // of image processing can be done here.
  15371. var uniquePrefix = (this.uniquePrefix || '');
  15372. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15373. operatorList.addDependency(objId);
  15374. args = [objId, w, h];
  15375. if (!softMask && !mask && image instanceof JpegStream &&
  15376. image.isNativelySupported(this.xref, resources)) {
  15377. // These JPEGs don't need any more processing so we can just send it.
  15378. operatorList.addOp(OPS.paintJpegXObject, args);
  15379. this.handler.send('obj',
  15380. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15381. return;
  15382. }
  15383. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15384. then(function(imageObj) {
  15385. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15386. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15387. [imgData.data.buffer]);
  15388. }).then(undefined, function (reason) {
  15389. warn('Unable to decode image: ' + reason);
  15390. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15391. });
  15392. operatorList.addOp(OPS.paintImageXObject, args);
  15393. if (cacheKey) {
  15394. imageCache[cacheKey] = {
  15395. fn: OPS.paintImageXObject,
  15396. args: args
  15397. };
  15398. }
  15399. },
  15400. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15401. operatorList,
  15402. stateManager) {
  15403. var smaskContent = smask.get('G');
  15404. var smaskOptions = {
  15405. subtype: smask.get('S').name,
  15406. backdrop: smask.get('BC')
  15407. };
  15408. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15409. operatorList, stateManager.state.clone());
  15410. },
  15411. handleTilingType:
  15412. function PartialEvaluator_handleTilingType(fn, args, resources,
  15413. pattern, patternDict,
  15414. operatorList) {
  15415. // Create an IR of the pattern code.
  15416. var tilingOpList = new OperatorList();
  15417. return this.getOperatorList(pattern,
  15418. (patternDict.get('Resources') || resources), tilingOpList).
  15419. then(function () {
  15420. // Add the dependencies to the parent operator list so they are
  15421. // resolved before sub operator list is executed synchronously.
  15422. operatorList.addDependencies(tilingOpList.dependencies);
  15423. operatorList.addOp(fn, getTilingPatternIR({
  15424. fnArray: tilingOpList.fnArray,
  15425. argsArray: tilingOpList.argsArray
  15426. }, patternDict, args));
  15427. });
  15428. },
  15429. handleSetFont:
  15430. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15431. operatorList, state) {
  15432. // TODO(mack): Not needed?
  15433. var fontName;
  15434. if (fontArgs) {
  15435. fontArgs = fontArgs.slice();
  15436. fontName = fontArgs[0].name;
  15437. }
  15438. var self = this;
  15439. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15440. function (translated) {
  15441. if (!translated.font.isType3Font) {
  15442. return translated;
  15443. }
  15444. return translated.loadType3Data(self, resources, operatorList).then(
  15445. function () {
  15446. return translated;
  15447. });
  15448. }).then(function (translated) {
  15449. state.font = translated.font;
  15450. translated.send(self.handler);
  15451. return translated.loadedName;
  15452. });
  15453. },
  15454. handleText: function PartialEvaluator_handleText(chars, state) {
  15455. var font = state.font;
  15456. var glyphs = font.charsToGlyphs(chars);
  15457. var isAddToPathSet = !!(state.textRenderingMode &
  15458. TextRenderingMode.ADD_TO_PATH_FLAG);
  15459. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15460. var buildPath = function (fontChar) {
  15461. if (!font.renderer.hasBuiltPath(fontChar)) {
  15462. var path = font.renderer.getPathJs(fontChar);
  15463. this.handler.send('commonobj', [
  15464. font.loadedName + '_path_' + fontChar,
  15465. 'FontPath',
  15466. path
  15467. ]);
  15468. }
  15469. }.bind(this);
  15470. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15471. var glyph = glyphs[i];
  15472. if (glyph === null) {
  15473. continue;
  15474. }
  15475. buildPath(glyph.fontChar);
  15476. // If the glyph has an accent we need to build a path for its
  15477. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15478. var accent = glyph.accent;
  15479. if (accent && accent.fontChar) {
  15480. buildPath(accent.fontChar);
  15481. }
  15482. }
  15483. }
  15484. return glyphs;
  15485. },
  15486. setGState: function PartialEvaluator_setGState(resources, gState,
  15487. operatorList, xref,
  15488. stateManager) {
  15489. // This array holds the converted/processed state data.
  15490. var gStateObj = [];
  15491. var gStateMap = gState.map;
  15492. var self = this;
  15493. var promise = Promise.resolve();
  15494. for (var key in gStateMap) {
  15495. var value = gStateMap[key];
  15496. switch (key) {
  15497. case 'Type':
  15498. break;
  15499. case 'LW':
  15500. case 'LC':
  15501. case 'LJ':
  15502. case 'ML':
  15503. case 'D':
  15504. case 'RI':
  15505. case 'FL':
  15506. case 'CA':
  15507. case 'ca':
  15508. gStateObj.push([key, value]);
  15509. break;
  15510. case 'Font':
  15511. promise = promise.then(function () {
  15512. return self.handleSetFont(resources, null, value[0],
  15513. operatorList, stateManager.state).
  15514. then(function (loadedName) {
  15515. operatorList.addDependency(loadedName);
  15516. gStateObj.push([key, [loadedName, value[1]]]);
  15517. });
  15518. });
  15519. break;
  15520. case 'BM':
  15521. gStateObj.push([key, value]);
  15522. break;
  15523. case 'SMask':
  15524. if (isName(value) && value.name === 'None') {
  15525. gStateObj.push([key, false]);
  15526. break;
  15527. }
  15528. var dict = xref.fetchIfRef(value);
  15529. if (isDict(dict)) {
  15530. promise = promise.then(function () {
  15531. return self.handleSMask(dict, resources, operatorList,
  15532. stateManager);
  15533. });
  15534. gStateObj.push([key, true]);
  15535. } else {
  15536. warn('Unsupported SMask type');
  15537. }
  15538. break;
  15539. // Only generate info log messages for the following since
  15540. // they are unlikely to have a big impact on the rendering.
  15541. case 'OP':
  15542. case 'op':
  15543. case 'OPM':
  15544. case 'BG':
  15545. case 'BG2':
  15546. case 'UCR':
  15547. case 'UCR2':
  15548. case 'TR':
  15549. case 'TR2':
  15550. case 'HT':
  15551. case 'SM':
  15552. case 'SA':
  15553. case 'AIS':
  15554. case 'TK':
  15555. // TODO implement these operators.
  15556. info('graphic state operator ' + key);
  15557. break;
  15558. default:
  15559. info('Unknown graphic state operator ' + key);
  15560. break;
  15561. }
  15562. }
  15563. return promise.then(function () {
  15564. if (gStateObj.length >= 0) {
  15565. operatorList.addOp(OPS.setGState, [gStateObj]);
  15566. }
  15567. });
  15568. },
  15569. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15570. resources) {
  15571. function errorFont() {
  15572. return Promise.resolve(new TranslatedFont('g_font_error',
  15573. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15574. }
  15575. var fontRef;
  15576. if (font) { // Loading by ref.
  15577. assert(isRef(font));
  15578. fontRef = font;
  15579. } else { // Loading by name.
  15580. var fontRes = resources.get('Font');
  15581. if (fontRes) {
  15582. fontRef = fontRes.getRaw(fontName);
  15583. } else {
  15584. warn('fontRes not available');
  15585. return errorFont();
  15586. }
  15587. }
  15588. if (!fontRef) {
  15589. warn('fontRef not available');
  15590. return errorFont();
  15591. }
  15592. if (this.fontCache.has(fontRef)) {
  15593. return this.fontCache.get(fontRef);
  15594. }
  15595. font = xref.fetchIfRef(fontRef);
  15596. if (!isDict(font)) {
  15597. return errorFont();
  15598. }
  15599. // We are holding font.translated references just for fontRef that are not
  15600. // dictionaries (Dict). See explanation below.
  15601. if (font.translated) {
  15602. return font.translated;
  15603. }
  15604. var fontCapability = createPromiseCapability();
  15605. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15606. var descriptor = preEvaluatedFont.descriptor;
  15607. var fontID = fontRef.num + '_' + fontRef.gen;
  15608. if (isDict(descriptor)) {
  15609. if (!descriptor.fontAliases) {
  15610. descriptor.fontAliases = Object.create(null);
  15611. }
  15612. var fontAliases = descriptor.fontAliases;
  15613. var hash = preEvaluatedFont.hash;
  15614. if (fontAliases[hash]) {
  15615. var aliasFontRef = fontAliases[hash].aliasRef;
  15616. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15617. this.fontCache.putAlias(fontRef, aliasFontRef);
  15618. return this.fontCache.get(fontRef);
  15619. }
  15620. }
  15621. if (!fontAliases[hash]) {
  15622. fontAliases[hash] = {
  15623. fontID: Font.getFontID()
  15624. };
  15625. }
  15626. fontAliases[hash].aliasRef = fontRef;
  15627. fontID = fontAliases[hash].fontID;
  15628. }
  15629. // Workaround for bad PDF generators that don't reference fonts
  15630. // properly, i.e. by not using an object identifier.
  15631. // Check if the fontRef is a Dict (as opposed to a standard object),
  15632. // in which case we don't cache the font and instead reference it by
  15633. // fontName in font.loadedName below.
  15634. var fontRefIsDict = isDict(fontRef);
  15635. if (!fontRefIsDict) {
  15636. this.fontCache.put(fontRef, fontCapability.promise);
  15637. }
  15638. // Keep track of each font we translated so the caller can
  15639. // load them asynchronously before calling display on a page.
  15640. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15641. fontName.replace(/\W/g, '') : fontID);
  15642. font.translated = fontCapability.promise;
  15643. // TODO move promises into translate font
  15644. var translatedPromise;
  15645. try {
  15646. translatedPromise = Promise.resolve(
  15647. this.translateFont(preEvaluatedFont, xref));
  15648. } catch (e) {
  15649. translatedPromise = Promise.reject(e);
  15650. }
  15651. translatedPromise.then(function (translatedFont) {
  15652. if (translatedFont.fontType !== undefined) {
  15653. var xrefFontStats = xref.stats.fontTypes;
  15654. xrefFontStats[translatedFont.fontType] = true;
  15655. }
  15656. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15657. translatedFont, font));
  15658. }, function (reason) {
  15659. // TODO fontCapability.reject?
  15660. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15661. try {
  15662. // error, but it's still nice to have font type reported
  15663. var descriptor = preEvaluatedFont.descriptor;
  15664. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15665. var subtype = fontFile3 && fontFile3.get('Subtype');
  15666. var fontType = getFontType(preEvaluatedFont.type,
  15667. subtype && subtype.name);
  15668. var xrefFontStats = xref.stats.fontTypes;
  15669. xrefFontStats[fontType] = true;
  15670. } catch (ex) { }
  15671. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15672. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15673. font));
  15674. });
  15675. return fontCapability.promise;
  15676. },
  15677. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15678. var lastIndex = operatorList.length - 1;
  15679. if (!args) {
  15680. args = [];
  15681. }
  15682. if (lastIndex < 0 ||
  15683. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15684. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15685. } else {
  15686. var opArgs = operatorList.argsArray[lastIndex];
  15687. opArgs[0].push(fn);
  15688. Array.prototype.push.apply(opArgs[1], args);
  15689. }
  15690. },
  15691. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15692. cs, patterns, resources, xref) {
  15693. // compile tiling patterns
  15694. var patternName = args[args.length - 1];
  15695. // SCN/scn applies patterns along with normal colors
  15696. var pattern;
  15697. if (isName(patternName) &&
  15698. (pattern = patterns.get(patternName.name))) {
  15699. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15700. var typeNum = dict.get('PatternType');
  15701. if (typeNum === TILING_PATTERN) {
  15702. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15703. return this.handleTilingType(fn, color, resources, pattern,
  15704. dict, operatorList);
  15705. } else if (typeNum === SHADING_PATTERN) {
  15706. var shading = dict.get('Shading');
  15707. var matrix = dict.get('Matrix');
  15708. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15709. operatorList.addOp(fn, pattern.getIR());
  15710. return Promise.resolve();
  15711. } else {
  15712. return Promise.reject('Unknown PatternType: ' + typeNum);
  15713. }
  15714. }
  15715. // TODO shall we fail here?
  15716. operatorList.addOp(fn, args);
  15717. return Promise.resolve();
  15718. },
  15719. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15720. resources,
  15721. operatorList,
  15722. initialState) {
  15723. var self = this;
  15724. var xref = this.xref;
  15725. var imageCache = {};
  15726. assert(operatorList);
  15727. resources = (resources || Dict.empty);
  15728. var xobjs = (resources.get('XObject') || Dict.empty);
  15729. var patterns = (resources.get('Pattern') || Dict.empty);
  15730. var stateManager = new StateManager(initialState || new EvalState());
  15731. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15732. var timeSlotManager = new TimeSlotManager();
  15733. return new Promise(function next(resolve, reject) {
  15734. timeSlotManager.reset();
  15735. var stop, operation = {}, i, ii, cs;
  15736. while (!(stop = timeSlotManager.check())) {
  15737. // The arguments parsed by read() are used beyond this loop, so we
  15738. // cannot reuse the same array on each iteration. Therefore we pass
  15739. // in |null| as the initial value (see the comment on
  15740. // EvaluatorPreprocessor_read() for why).
  15741. operation.args = null;
  15742. if (!(preprocessor.read(operation))) {
  15743. break;
  15744. }
  15745. var args = operation.args;
  15746. var fn = operation.fn;
  15747. switch (fn | 0) {
  15748. case OPS.paintXObject:
  15749. if (args[0].code) {
  15750. break;
  15751. }
  15752. // eagerly compile XForm objects
  15753. var name = args[0].name;
  15754. if (imageCache[name] !== undefined) {
  15755. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  15756. args = null;
  15757. continue;
  15758. }
  15759. var xobj = xobjs.get(name);
  15760. if (xobj) {
  15761. assert(isStream(xobj), 'XObject should be a stream');
  15762. var type = xobj.dict.get('Subtype');
  15763. assert(isName(type),
  15764. 'XObject should have a Name subtype');
  15765. if (type.name === 'Form') {
  15766. stateManager.save();
  15767. return self.buildFormXObject(resources, xobj, null,
  15768. operatorList,
  15769. stateManager.state.clone()).
  15770. then(function () {
  15771. stateManager.restore();
  15772. next(resolve, reject);
  15773. }, reject);
  15774. } else if (type.name === 'Image') {
  15775. self.buildPaintImageXObject(resources, xobj, false,
  15776. operatorList, name, imageCache);
  15777. args = null;
  15778. continue;
  15779. } else if (type.name === 'PS') {
  15780. // PostScript XObjects are unused when viewing documents.
  15781. // See section 4.7.1 of Adobe's PDF reference.
  15782. info('Ignored XObject subtype PS');
  15783. continue;
  15784. } else {
  15785. error('Unhandled XObject subtype ' + type.name);
  15786. }
  15787. }
  15788. break;
  15789. case OPS.setFont:
  15790. var fontSize = args[1];
  15791. // eagerly collect all fonts
  15792. return self.handleSetFont(resources, args, null,
  15793. operatorList, stateManager.state).
  15794. then(function (loadedName) {
  15795. operatorList.addDependency(loadedName);
  15796. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15797. next(resolve, reject);
  15798. }, reject);
  15799. case OPS.endInlineImage:
  15800. var cacheKey = args[0].cacheKey;
  15801. if (cacheKey) {
  15802. var cacheEntry = imageCache[cacheKey];
  15803. if (cacheEntry !== undefined) {
  15804. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  15805. args = null;
  15806. continue;
  15807. }
  15808. }
  15809. self.buildPaintImageXObject(resources, args[0], true,
  15810. operatorList, cacheKey, imageCache);
  15811. args = null;
  15812. continue;
  15813. case OPS.showText:
  15814. args[0] = self.handleText(args[0], stateManager.state);
  15815. break;
  15816. case OPS.showSpacedText:
  15817. var arr = args[0];
  15818. var combinedGlyphs = [];
  15819. var arrLength = arr.length;
  15820. for (i = 0; i < arrLength; ++i) {
  15821. var arrItem = arr[i];
  15822. if (isString(arrItem)) {
  15823. Array.prototype.push.apply(combinedGlyphs,
  15824. self.handleText(arrItem, stateManager.state));
  15825. } else if (isNum(arrItem)) {
  15826. combinedGlyphs.push(arrItem);
  15827. }
  15828. }
  15829. args[0] = combinedGlyphs;
  15830. fn = OPS.showText;
  15831. break;
  15832. case OPS.nextLineShowText:
  15833. operatorList.addOp(OPS.nextLine);
  15834. args[0] = self.handleText(args[0], stateManager.state);
  15835. fn = OPS.showText;
  15836. break;
  15837. case OPS.nextLineSetSpacingShowText:
  15838. operatorList.addOp(OPS.nextLine);
  15839. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15840. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15841. args[0] = self.handleText(args[0], stateManager.state);
  15842. fn = OPS.showText;
  15843. break;
  15844. case OPS.setTextRenderingMode:
  15845. stateManager.state.textRenderingMode = args[0];
  15846. break;
  15847. case OPS.setFillColorSpace:
  15848. stateManager.state.fillColorSpace =
  15849. ColorSpace.parse(args[0], xref, resources);
  15850. continue;
  15851. case OPS.setStrokeColorSpace:
  15852. stateManager.state.strokeColorSpace =
  15853. ColorSpace.parse(args[0], xref, resources);
  15854. continue;
  15855. case OPS.setFillColor:
  15856. cs = stateManager.state.fillColorSpace;
  15857. args = cs.getRgb(args, 0);
  15858. fn = OPS.setFillRGBColor;
  15859. break;
  15860. case OPS.setStrokeColor:
  15861. cs = stateManager.state.strokeColorSpace;
  15862. args = cs.getRgb(args, 0);
  15863. fn = OPS.setStrokeRGBColor;
  15864. break;
  15865. case OPS.setFillGray:
  15866. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15867. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15868. fn = OPS.setFillRGBColor;
  15869. break;
  15870. case OPS.setStrokeGray:
  15871. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15872. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15873. fn = OPS.setStrokeRGBColor;
  15874. break;
  15875. case OPS.setFillCMYKColor:
  15876. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15877. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15878. fn = OPS.setFillRGBColor;
  15879. break;
  15880. case OPS.setStrokeCMYKColor:
  15881. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15882. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15883. fn = OPS.setStrokeRGBColor;
  15884. break;
  15885. case OPS.setFillRGBColor:
  15886. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15887. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15888. break;
  15889. case OPS.setStrokeRGBColor:
  15890. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15891. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15892. break;
  15893. case OPS.setFillColorN:
  15894. cs = stateManager.state.fillColorSpace;
  15895. if (cs.name === 'Pattern') {
  15896. return self.handleColorN(operatorList, OPS.setFillColorN,
  15897. args, cs, patterns, resources, xref).then(function() {
  15898. next(resolve, reject);
  15899. }, reject);
  15900. }
  15901. args = cs.getRgb(args, 0);
  15902. fn = OPS.setFillRGBColor;
  15903. break;
  15904. case OPS.setStrokeColorN:
  15905. cs = stateManager.state.strokeColorSpace;
  15906. if (cs.name === 'Pattern') {
  15907. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15908. args, cs, patterns, resources, xref).then(function() {
  15909. next(resolve, reject);
  15910. }, reject);
  15911. }
  15912. args = cs.getRgb(args, 0);
  15913. fn = OPS.setStrokeRGBColor;
  15914. break;
  15915. case OPS.shadingFill:
  15916. var shadingRes = resources.get('Shading');
  15917. if (!shadingRes) {
  15918. error('No shading resource found');
  15919. }
  15920. var shading = shadingRes.get(args[0].name);
  15921. if (!shading) {
  15922. error('No shading object found');
  15923. }
  15924. var shadingFill = Pattern.parseShading(shading, null, xref,
  15925. resources);
  15926. var patternIR = shadingFill.getIR();
  15927. args = [patternIR];
  15928. fn = OPS.shadingFill;
  15929. break;
  15930. case OPS.setGState:
  15931. var dictName = args[0];
  15932. var extGState = resources.get('ExtGState');
  15933. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15934. break;
  15935. }
  15936. var gState = extGState.get(dictName.name);
  15937. return self.setGState(resources, gState, operatorList, xref,
  15938. stateManager).then(function() {
  15939. next(resolve, reject);
  15940. }, reject);
  15941. case OPS.moveTo:
  15942. case OPS.lineTo:
  15943. case OPS.curveTo:
  15944. case OPS.curveTo2:
  15945. case OPS.curveTo3:
  15946. case OPS.closePath:
  15947. self.buildPath(operatorList, fn, args);
  15948. continue;
  15949. case OPS.rectangle:
  15950. self.buildPath(operatorList, fn, args);
  15951. continue;
  15952. }
  15953. operatorList.addOp(fn, args);
  15954. }
  15955. if (stop) {
  15956. deferred.then(function () {
  15957. next(resolve, reject);
  15958. });
  15959. return;
  15960. }
  15961. // Some PDFs don't close all restores inside object/form.
  15962. // Closing those for them.
  15963. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15964. operatorList.addOp(OPS.restore, []);
  15965. }
  15966. resolve();
  15967. });
  15968. },
  15969. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15970. stateManager) {
  15971. stateManager = (stateManager || new StateManager(new TextState()));
  15972. var textContent = {
  15973. items: [],
  15974. styles: Object.create(null)
  15975. };
  15976. var bidiTexts = textContent.items;
  15977. var SPACE_FACTOR = 0.3;
  15978. var MULTI_SPACE_FACTOR = 1.5;
  15979. var self = this;
  15980. var xref = this.xref;
  15981. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15982. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15983. var xobjs = null;
  15984. var xobjsCache = {};
  15985. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15986. var textState;
  15987. function newTextChunk() {
  15988. var font = textState.font;
  15989. if (!(font.loadedName in textContent.styles)) {
  15990. textContent.styles[font.loadedName] = {
  15991. fontFamily: font.fallbackName,
  15992. ascent: font.ascent,
  15993. descent: font.descent,
  15994. vertical: font.vertical
  15995. };
  15996. }
  15997. return {
  15998. // |str| is initially an array which we push individual chars to, and
  15999. // then runBidi() overwrites it with the final string.
  16000. str: [],
  16001. dir: null,
  16002. width: 0,
  16003. height: 0,
  16004. transform: null,
  16005. fontName: font.loadedName
  16006. };
  16007. }
  16008. function runBidi(textChunk) {
  16009. var str = textChunk.str.join('');
  16010. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  16011. textChunk.str = bidiResult.str;
  16012. textChunk.dir = bidiResult.dir;
  16013. return textChunk;
  16014. }
  16015. function handleSetFont(fontName, fontRef) {
  16016. return self.loadFont(fontName, fontRef, xref, resources).
  16017. then(function (translated) {
  16018. textState.font = translated.font;
  16019. textState.fontMatrix = translated.font.fontMatrix ||
  16020. FONT_IDENTITY_MATRIX;
  16021. });
  16022. }
  16023. function buildTextGeometry(chars, textChunk) {
  16024. var font = textState.font;
  16025. textChunk = textChunk || newTextChunk();
  16026. if (!textChunk.transform) {
  16027. // 9.4.4 Text Space Details
  16028. var tsm = [textState.fontSize * textState.textHScale, 0,
  16029. 0, textState.fontSize,
  16030. 0, textState.textRise];
  16031. var trm = textChunk.transform = Util.transform(textState.ctm,
  16032. Util.transform(textState.textMatrix, tsm));
  16033. if (!font.vertical) {
  16034. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16035. } else {
  16036. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16037. }
  16038. }
  16039. var width = 0;
  16040. var height = 0;
  16041. var glyphs = font.charsToGlyphs(chars);
  16042. var defaultVMetrics = font.defaultVMetrics;
  16043. for (var i = 0; i < glyphs.length; i++) {
  16044. var glyph = glyphs[i];
  16045. if (!glyph) { // Previous glyph was a space.
  16046. width += textState.wordSpacing * textState.textHScale;
  16047. continue;
  16048. }
  16049. var vMetricX = null;
  16050. var vMetricY = null;
  16051. var glyphWidth = null;
  16052. if (font.vertical) {
  16053. if (glyph.vmetric) {
  16054. glyphWidth = glyph.vmetric[0];
  16055. vMetricX = glyph.vmetric[1];
  16056. vMetricY = glyph.vmetric[2];
  16057. } else {
  16058. glyphWidth = glyph.width;
  16059. vMetricX = glyph.width * 0.5;
  16060. vMetricY = defaultVMetrics[2];
  16061. }
  16062. } else {
  16063. glyphWidth = glyph.width;
  16064. }
  16065. var glyphUnicode = glyph.unicode;
  16066. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16067. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16068. }
  16069. glyphUnicode = reverseIfRtl(glyphUnicode);
  16070. // The following will calculate the x and y of the individual glyphs.
  16071. // if (font.vertical) {
  16072. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16073. // textState.fontMatrix[0];
  16074. // tsm[5] -= vMetricY * textState.fontSize *
  16075. // textState.fontMatrix[0];
  16076. // }
  16077. // var trm = Util.transform(textState.textMatrix, tsm);
  16078. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16079. // var x = pt[0];
  16080. // var y = pt[1];
  16081. var tx = 0;
  16082. var ty = 0;
  16083. if (!font.vertical) {
  16084. var w0 = glyphWidth * textState.fontMatrix[0];
  16085. tx = (w0 * textState.fontSize + textState.charSpacing) *
  16086. textState.textHScale;
  16087. width += tx;
  16088. } else {
  16089. var w1 = glyphWidth * textState.fontMatrix[0];
  16090. ty = w1 * textState.fontSize + textState.charSpacing;
  16091. height += ty;
  16092. }
  16093. textState.translateTextMatrix(tx, ty);
  16094. textChunk.str.push(glyphUnicode);
  16095. }
  16096. var a = textState.textLineMatrix[0];
  16097. var b = textState.textLineMatrix[1];
  16098. var scaleLineX = Math.sqrt(a * a + b * b);
  16099. a = textState.ctm[0];
  16100. b = textState.ctm[1];
  16101. var scaleCtmX = Math.sqrt(a * a + b * b);
  16102. if (!font.vertical) {
  16103. textChunk.width += width * scaleCtmX * scaleLineX;
  16104. } else {
  16105. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  16106. }
  16107. return textChunk;
  16108. }
  16109. var timeSlotManager = new TimeSlotManager();
  16110. return new Promise(function next(resolve, reject) {
  16111. timeSlotManager.reset();
  16112. var stop, operation = {}, args = [];
  16113. while (!(stop = timeSlotManager.check())) {
  16114. // The arguments parsed by read() are not used beyond this loop, so
  16115. // we can reuse the same array on every iteration, thus avoiding
  16116. // unnecessary allocations.
  16117. args.length = 0;
  16118. operation.args = args;
  16119. if (!(preprocessor.read(operation))) {
  16120. break;
  16121. }
  16122. textState = stateManager.state;
  16123. var fn = operation.fn;
  16124. args = operation.args;
  16125. switch (fn | 0) {
  16126. case OPS.setFont:
  16127. textState.fontSize = args[1];
  16128. return handleSetFont(args[0].name).then(function() {
  16129. next(resolve, reject);
  16130. }, reject);
  16131. case OPS.setTextRise:
  16132. textState.textRise = args[0];
  16133. break;
  16134. case OPS.setHScale:
  16135. textState.textHScale = args[0] / 100;
  16136. break;
  16137. case OPS.setLeading:
  16138. textState.leading = args[0];
  16139. break;
  16140. case OPS.moveText:
  16141. textState.translateTextLineMatrix(args[0], args[1]);
  16142. textState.textMatrix = textState.textLineMatrix.slice();
  16143. break;
  16144. case OPS.setLeadingMoveText:
  16145. textState.leading = -args[1];
  16146. textState.translateTextLineMatrix(args[0], args[1]);
  16147. textState.textMatrix = textState.textLineMatrix.slice();
  16148. break;
  16149. case OPS.nextLine:
  16150. textState.carriageReturn();
  16151. break;
  16152. case OPS.setTextMatrix:
  16153. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  16154. args[4], args[5]);
  16155. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  16156. args[4], args[5]);
  16157. break;
  16158. case OPS.setCharSpacing:
  16159. textState.charSpacing = args[0];
  16160. break;
  16161. case OPS.setWordSpacing:
  16162. textState.wordSpacing = args[0];
  16163. break;
  16164. case OPS.beginText:
  16165. textState.textMatrix = IDENTITY_MATRIX.slice();
  16166. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  16167. break;
  16168. case OPS.showSpacedText:
  16169. var items = args[0];
  16170. var textChunk = newTextChunk();
  16171. var offset;
  16172. for (var j = 0, jj = items.length; j < jj; j++) {
  16173. if (typeof items[j] === 'string') {
  16174. buildTextGeometry(items[j], textChunk);
  16175. } else {
  16176. var val = items[j] / 1000;
  16177. if (!textState.font.vertical) {
  16178. offset = -val * textState.fontSize * textState.textHScale *
  16179. textState.textMatrix[0];
  16180. textState.translateTextMatrix(offset, 0);
  16181. textChunk.width += offset;
  16182. } else {
  16183. offset = -val * textState.fontSize *
  16184. textState.textMatrix[3];
  16185. textState.translateTextMatrix(0, offset);
  16186. textChunk.height += offset;
  16187. }
  16188. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  16189. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  16190. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  16191. fakeSpaces = Math.round(fakeSpaces);
  16192. while (fakeSpaces--) {
  16193. textChunk.str.push(' ');
  16194. }
  16195. } else if (fakeSpaces > SPACE_FACTOR) {
  16196. textChunk.str.push(' ');
  16197. }
  16198. }
  16199. }
  16200. }
  16201. bidiTexts.push(runBidi(textChunk));
  16202. break;
  16203. case OPS.showText:
  16204. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16205. break;
  16206. case OPS.nextLineShowText:
  16207. textState.carriageReturn();
  16208. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16209. break;
  16210. case OPS.nextLineSetSpacingShowText:
  16211. textState.wordSpacing = args[0];
  16212. textState.charSpacing = args[1];
  16213. textState.carriageReturn();
  16214. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  16215. break;
  16216. case OPS.paintXObject:
  16217. if (args[0].code) {
  16218. break;
  16219. }
  16220. if (!xobjs) {
  16221. xobjs = (resources.get('XObject') || Dict.empty);
  16222. }
  16223. var name = args[0].name;
  16224. if (xobjsCache.key === name) {
  16225. if (xobjsCache.texts) {
  16226. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  16227. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  16228. }
  16229. break;
  16230. }
  16231. var xobj = xobjs.get(name);
  16232. if (!xobj) {
  16233. break;
  16234. }
  16235. assert(isStream(xobj), 'XObject should be a stream');
  16236. var type = xobj.dict.get('Subtype');
  16237. assert(isName(type),
  16238. 'XObject should have a Name subtype');
  16239. if ('Form' !== type.name) {
  16240. xobjsCache.key = name;
  16241. xobjsCache.texts = null;
  16242. break;
  16243. }
  16244. stateManager.save();
  16245. var matrix = xobj.dict.get('Matrix');
  16246. if (isArray(matrix) && matrix.length === 6) {
  16247. stateManager.transform(matrix);
  16248. }
  16249. return self.getTextContent(xobj,
  16250. xobj.dict.get('Resources') || resources, stateManager).
  16251. then(function (formTextContent) {
  16252. Util.appendToArray(bidiTexts, formTextContent.items);
  16253. Util.extendObj(textContent.styles, formTextContent.styles);
  16254. stateManager.restore();
  16255. xobjsCache.key = name;
  16256. xobjsCache.texts = formTextContent;
  16257. next(resolve, reject);
  16258. }, reject);
  16259. case OPS.setGState:
  16260. var dictName = args[0];
  16261. var extGState = resources.get('ExtGState');
  16262. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16263. break;
  16264. }
  16265. var gsStateMap = extGState.get(dictName.name);
  16266. var gsStateFont = null;
  16267. for (var key in gsStateMap) {
  16268. if (key === 'Font') {
  16269. assert(!gsStateFont);
  16270. gsStateFont = gsStateMap[key];
  16271. }
  16272. }
  16273. if (gsStateFont) {
  16274. textState.fontSize = gsStateFont[1];
  16275. return handleSetFont(gsStateFont[0]).then(function() {
  16276. next(resolve, reject);
  16277. }, reject);
  16278. }
  16279. break;
  16280. } // switch
  16281. } // while
  16282. if (stop) {
  16283. deferred.then(function () {
  16284. next(resolve, reject);
  16285. });
  16286. return;
  16287. }
  16288. resolve(textContent);
  16289. });
  16290. },
  16291. extractDataStructures: function
  16292. partialEvaluatorExtractDataStructures(dict, baseDict,
  16293. xref, properties) {
  16294. // 9.10.2
  16295. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16296. if (toUnicode) {
  16297. properties.toUnicode = this.readToUnicode(toUnicode);
  16298. }
  16299. if (properties.composite) {
  16300. // CIDSystemInfo helps to match CID to glyphs
  16301. var cidSystemInfo = dict.get('CIDSystemInfo');
  16302. if (isDict(cidSystemInfo)) {
  16303. properties.cidSystemInfo = {
  16304. registry: cidSystemInfo.get('Registry'),
  16305. ordering: cidSystemInfo.get('Ordering'),
  16306. supplement: cidSystemInfo.get('Supplement')
  16307. };
  16308. }
  16309. var cidToGidMap = dict.get('CIDToGIDMap');
  16310. if (isStream(cidToGidMap)) {
  16311. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16312. }
  16313. }
  16314. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16315. // and depends on the font type. The base encoding and differences are
  16316. // read here, but the encoding that is actually used is chosen during
  16317. // glyph mapping in the font.
  16318. // TODO: Loading the built in encoding in the font would allow the
  16319. // differences to be merged in here not require us to hold on to it.
  16320. var differences = [];
  16321. var baseEncodingName = null;
  16322. var encoding;
  16323. if (dict.has('Encoding')) {
  16324. encoding = dict.get('Encoding');
  16325. if (isDict(encoding)) {
  16326. baseEncodingName = encoding.get('BaseEncoding');
  16327. baseEncodingName = (isName(baseEncodingName) ?
  16328. baseEncodingName.name : null);
  16329. // Load the differences between the base and original
  16330. if (encoding.has('Differences')) {
  16331. var diffEncoding = encoding.get('Differences');
  16332. var index = 0;
  16333. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16334. var data = diffEncoding[j];
  16335. if (isNum(data)) {
  16336. index = data;
  16337. } else {
  16338. differences[index++] = data.name;
  16339. }
  16340. }
  16341. }
  16342. } else if (isName(encoding)) {
  16343. baseEncodingName = encoding.name;
  16344. } else {
  16345. error('Encoding is not a Name nor a Dict');
  16346. }
  16347. // According to table 114 if the encoding is a named encoding it must be
  16348. // one of these predefined encodings.
  16349. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16350. baseEncodingName !== 'MacExpertEncoding' &&
  16351. baseEncodingName !== 'WinAnsiEncoding')) {
  16352. baseEncodingName = null;
  16353. }
  16354. }
  16355. if (baseEncodingName) {
  16356. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16357. } else {
  16358. encoding = (properties.type === 'TrueType' ?
  16359. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16360. // The Symbolic attribute can be misused for regular fonts
  16361. // Heuristic: we have to check if the font is a standard one also
  16362. if (!!(properties.flags & FontFlags.Symbolic)) {
  16363. encoding = Encodings.MacRomanEncoding;
  16364. if (!properties.file) {
  16365. if (/Symbol/i.test(properties.name)) {
  16366. encoding = Encodings.SymbolSetEncoding;
  16367. } else if (/Dingbats/i.test(properties.name)) {
  16368. encoding = Encodings.ZapfDingbatsEncoding;
  16369. }
  16370. }
  16371. }
  16372. properties.defaultEncoding = encoding;
  16373. }
  16374. properties.differences = differences;
  16375. properties.baseEncodingName = baseEncodingName;
  16376. properties.dict = dict;
  16377. },
  16378. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16379. var cmap, cmapObj = toUnicode;
  16380. if (isName(cmapObj)) {
  16381. cmap = CMapFactory.create(cmapObj,
  16382. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16383. if (cmap instanceof IdentityCMap) {
  16384. return new IdentityToUnicodeMap(0, 0xFFFF);
  16385. }
  16386. return new ToUnicodeMap(cmap.getMap());
  16387. } else if (isStream(cmapObj)) {
  16388. cmap = CMapFactory.create(cmapObj,
  16389. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16390. if (cmap instanceof IdentityCMap) {
  16391. return new IdentityToUnicodeMap(0, 0xFFFF);
  16392. }
  16393. cmap = cmap.getMap();
  16394. // Convert UTF-16BE
  16395. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16396. // to iterate over all keys.
  16397. cmap.forEach(function(token, i) {
  16398. var str = [];
  16399. for (var k = 0; k < token.length; k += 2) {
  16400. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16401. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16402. str.push(w1);
  16403. continue;
  16404. }
  16405. k += 2;
  16406. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16407. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16408. }
  16409. cmap[i] = String.fromCharCode.apply(String, str);
  16410. });
  16411. return new ToUnicodeMap(cmap);
  16412. }
  16413. return null;
  16414. },
  16415. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16416. // Extract the encoding from the CIDToGIDMap
  16417. var glyphsData = cidToGidStream.getBytes();
  16418. // Set encoding 0 to later verify the font has an encoding
  16419. var result = [];
  16420. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16421. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16422. if (glyphID === 0) {
  16423. continue;
  16424. }
  16425. var code = j >> 1;
  16426. result[code] = glyphID;
  16427. }
  16428. return result;
  16429. },
  16430. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16431. descriptor,
  16432. properties) {
  16433. var glyphsWidths = [];
  16434. var defaultWidth = 0;
  16435. var glyphsVMetrics = [];
  16436. var defaultVMetrics;
  16437. var i, ii, j, jj, start, code, widths;
  16438. if (properties.composite) {
  16439. defaultWidth = dict.get('DW') || 1000;
  16440. widths = dict.get('W');
  16441. if (widths) {
  16442. for (i = 0, ii = widths.length; i < ii; i++) {
  16443. start = widths[i++];
  16444. code = xref.fetchIfRef(widths[i]);
  16445. if (isArray(code)) {
  16446. for (j = 0, jj = code.length; j < jj; j++) {
  16447. glyphsWidths[start++] = code[j];
  16448. }
  16449. } else {
  16450. var width = widths[++i];
  16451. for (j = start; j <= code; j++) {
  16452. glyphsWidths[j] = width;
  16453. }
  16454. }
  16455. }
  16456. }
  16457. if (properties.vertical) {
  16458. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16459. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16460. vmetrics = dict.get('W2');
  16461. if (vmetrics) {
  16462. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16463. start = vmetrics[i++];
  16464. code = xref.fetchIfRef(vmetrics[i]);
  16465. if (isArray(code)) {
  16466. for (j = 0, jj = code.length; j < jj; j++) {
  16467. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16468. }
  16469. } else {
  16470. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16471. for (j = start; j <= code; j++) {
  16472. glyphsVMetrics[j] = vmetric;
  16473. }
  16474. }
  16475. }
  16476. }
  16477. }
  16478. } else {
  16479. var firstChar = properties.firstChar;
  16480. widths = dict.get('Widths');
  16481. if (widths) {
  16482. j = firstChar;
  16483. for (i = 0, ii = widths.length; i < ii; i++) {
  16484. glyphsWidths[j++] = widths[i];
  16485. }
  16486. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16487. } else {
  16488. // Trying get the BaseFont metrics (see comment above).
  16489. var baseFontName = dict.get('BaseFont');
  16490. if (isName(baseFontName)) {
  16491. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16492. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16493. properties);
  16494. defaultWidth = metrics.defaultWidth;
  16495. }
  16496. }
  16497. }
  16498. // Heuristic: detection of monospace font by checking all non-zero widths
  16499. var isMonospace = true;
  16500. var firstWidth = defaultWidth;
  16501. for (var glyph in glyphsWidths) {
  16502. var glyphWidth = glyphsWidths[glyph];
  16503. if (!glyphWidth) {
  16504. continue;
  16505. }
  16506. if (!firstWidth) {
  16507. firstWidth = glyphWidth;
  16508. continue;
  16509. }
  16510. if (firstWidth !== glyphWidth) {
  16511. isMonospace = false;
  16512. break;
  16513. }
  16514. }
  16515. if (isMonospace) {
  16516. properties.flags |= FontFlags.FixedPitch;
  16517. }
  16518. properties.defaultWidth = defaultWidth;
  16519. properties.widths = glyphsWidths;
  16520. properties.defaultVMetrics = defaultVMetrics;
  16521. properties.vmetrics = glyphsVMetrics;
  16522. },
  16523. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16524. // Simulating descriptor flags attribute
  16525. var fontNameWoStyle = baseFontName.split('-')[0];
  16526. return (fontNameWoStyle in serifFonts) ||
  16527. (fontNameWoStyle.search(/serif/gi) !== -1);
  16528. },
  16529. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16530. var defaultWidth = 0;
  16531. var widths = [];
  16532. var monospace = false;
  16533. var lookupName = (stdFontMap[name] || name);
  16534. if (!(lookupName in Metrics)) {
  16535. // Use default fonts for looking up font metrics if the passed
  16536. // font is not a base font
  16537. if (this.isSerifFont(name)) {
  16538. lookupName = 'Times-Roman';
  16539. } else {
  16540. lookupName = 'Helvetica';
  16541. }
  16542. }
  16543. var glyphWidths = Metrics[lookupName];
  16544. if (isNum(glyphWidths)) {
  16545. defaultWidth = glyphWidths;
  16546. monospace = true;
  16547. } else {
  16548. widths = glyphWidths;
  16549. }
  16550. return {
  16551. defaultWidth: defaultWidth,
  16552. monospace: monospace,
  16553. widths: widths
  16554. };
  16555. },
  16556. buildCharCodeToWidth:
  16557. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16558. properties) {
  16559. var widths = Object.create(null);
  16560. var differences = properties.differences;
  16561. var encoding = properties.defaultEncoding;
  16562. for (var charCode = 0; charCode < 256; charCode++) {
  16563. if (charCode in differences &&
  16564. widthsByGlyphName[differences[charCode]]) {
  16565. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16566. continue;
  16567. }
  16568. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16569. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16570. continue;
  16571. }
  16572. }
  16573. return widths;
  16574. },
  16575. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16576. var baseDict = dict;
  16577. var type = dict.get('Subtype');
  16578. assert(isName(type), 'invalid font Subtype');
  16579. var composite = false;
  16580. var uint8array;
  16581. if (type.name === 'Type0') {
  16582. // If font is a composite
  16583. // - get the descendant font
  16584. // - set the type according to the descendant font
  16585. // - get the FontDescriptor from the descendant font
  16586. var df = dict.get('DescendantFonts');
  16587. if (!df) {
  16588. error('Descendant fonts are not specified');
  16589. }
  16590. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16591. type = dict.get('Subtype');
  16592. assert(isName(type), 'invalid font Subtype');
  16593. composite = true;
  16594. }
  16595. var descriptor = dict.get('FontDescriptor');
  16596. if (descriptor) {
  16597. var hash = new MurmurHash3_64();
  16598. var encoding = baseDict.getRaw('Encoding');
  16599. if (isName(encoding)) {
  16600. hash.update(encoding.name);
  16601. } else if (isRef(encoding)) {
  16602. hash.update(encoding.num + '_' + encoding.gen);
  16603. }
  16604. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16605. if (isStream(toUnicode)) {
  16606. var stream = toUnicode.str || toUnicode;
  16607. uint8array = stream.buffer ?
  16608. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16609. new Uint8Array(stream.bytes.buffer,
  16610. stream.start, stream.end - stream.start);
  16611. hash.update(uint8array);
  16612. } else if (isName(toUnicode)) {
  16613. hash.update(toUnicode.name);
  16614. }
  16615. var widths = dict.get('Widths') || baseDict.get('Widths');
  16616. if (widths) {
  16617. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16618. hash.update(uint8array);
  16619. }
  16620. }
  16621. return {
  16622. descriptor: descriptor,
  16623. dict: dict,
  16624. baseDict: baseDict,
  16625. composite: composite,
  16626. type: type.name,
  16627. hash: hash ? hash.hexdigest() : ''
  16628. };
  16629. },
  16630. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16631. xref) {
  16632. var baseDict = preEvaluatedFont.baseDict;
  16633. var dict = preEvaluatedFont.dict;
  16634. var composite = preEvaluatedFont.composite;
  16635. var descriptor = preEvaluatedFont.descriptor;
  16636. var type = preEvaluatedFont.type;
  16637. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16638. var properties;
  16639. if (!descriptor) {
  16640. if (type === 'Type3') {
  16641. // FontDescriptor is only required for Type3 fonts when the document
  16642. // is a tagged pdf. Create a barbebones one to get by.
  16643. descriptor = new Dict(null);
  16644. descriptor.set('FontName', Name.get(type));
  16645. } else {
  16646. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16647. // FontDescriptor was not required.
  16648. // This case is here for compatibility.
  16649. var baseFontName = dict.get('BaseFont');
  16650. if (!isName(baseFontName)) {
  16651. error('Base font is not specified');
  16652. }
  16653. // Using base font name as a font name.
  16654. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16655. var metrics = this.getBaseFontMetrics(baseFontName);
  16656. // Simulating descriptor flags attribute
  16657. var fontNameWoStyle = baseFontName.split('-')[0];
  16658. var flags =
  16659. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16660. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16661. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16662. FontFlags.Nonsymbolic);
  16663. properties = {
  16664. type: type,
  16665. name: baseFontName,
  16666. widths: metrics.widths,
  16667. defaultWidth: metrics.defaultWidth,
  16668. flags: flags,
  16669. firstChar: 0,
  16670. lastChar: maxCharIndex
  16671. };
  16672. this.extractDataStructures(dict, dict, xref, properties);
  16673. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16674. properties);
  16675. return new Font(baseFontName, null, properties);
  16676. }
  16677. }
  16678. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16679. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16680. // to ignore this rule when a variant of a standart font is used.
  16681. // TODO Fill the width array depending on which of the base font this is
  16682. // a variant.
  16683. var firstChar = (dict.get('FirstChar') || 0);
  16684. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16685. var fontName = descriptor.get('FontName');
  16686. var baseFont = dict.get('BaseFont');
  16687. // Some bad PDFs have a string as the font name.
  16688. if (isString(fontName)) {
  16689. fontName = Name.get(fontName);
  16690. }
  16691. if (isString(baseFont)) {
  16692. baseFont = Name.get(baseFont);
  16693. }
  16694. if (type !== 'Type3') {
  16695. var fontNameStr = fontName && fontName.name;
  16696. var baseFontStr = baseFont && baseFont.name;
  16697. if (fontNameStr !== baseFontStr) {
  16698. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16699. '" but should be the same as the Font\'s BaseFont "' +
  16700. baseFontStr + '"');
  16701. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16702. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16703. if (fontNameStr && baseFontStr &&
  16704. baseFontStr.indexOf(fontNameStr) === 0) {
  16705. fontName = baseFont;
  16706. }
  16707. }
  16708. }
  16709. fontName = (fontName || baseFont);
  16710. assert(isName(fontName), 'invalid font name');
  16711. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16712. if (fontFile) {
  16713. if (fontFile.dict) {
  16714. var subtype = fontFile.dict.get('Subtype');
  16715. if (subtype) {
  16716. subtype = subtype.name;
  16717. }
  16718. var length1 = fontFile.dict.get('Length1');
  16719. var length2 = fontFile.dict.get('Length2');
  16720. }
  16721. }
  16722. properties = {
  16723. type: type,
  16724. name: fontName.name,
  16725. subtype: subtype,
  16726. file: fontFile,
  16727. length1: length1,
  16728. length2: length2,
  16729. loadedName: baseDict.loadedName,
  16730. composite: composite,
  16731. wideChars: composite,
  16732. fixedPitch: false,
  16733. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16734. firstChar: firstChar || 0,
  16735. lastChar: (lastChar || maxCharIndex),
  16736. bbox: descriptor.get('FontBBox'),
  16737. ascent: descriptor.get('Ascent'),
  16738. descent: descriptor.get('Descent'),
  16739. xHeight: descriptor.get('XHeight'),
  16740. capHeight: descriptor.get('CapHeight'),
  16741. flags: descriptor.get('Flags'),
  16742. italicAngle: descriptor.get('ItalicAngle'),
  16743. coded: false
  16744. };
  16745. if (composite) {
  16746. var cidEncoding = baseDict.get('Encoding');
  16747. if (isName(cidEncoding)) {
  16748. properties.cidEncoding = cidEncoding.name;
  16749. }
  16750. properties.cMap = CMapFactory.create(cidEncoding,
  16751. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16752. properties.vertical = properties.cMap.vertical;
  16753. }
  16754. this.extractDataStructures(dict, baseDict, xref, properties);
  16755. this.extractWidths(dict, xref, descriptor, properties);
  16756. if (type === 'Type3') {
  16757. properties.isType3Font = true;
  16758. }
  16759. return new Font(fontName.name, fontFile, properties);
  16760. }
  16761. };
  16762. return PartialEvaluator;
  16763. })();
  16764. var TranslatedFont = (function TranslatedFontClosure() {
  16765. function TranslatedFont(loadedName, font, dict) {
  16766. this.loadedName = loadedName;
  16767. this.font = font;
  16768. this.dict = dict;
  16769. this.type3Loaded = null;
  16770. this.sent = false;
  16771. }
  16772. TranslatedFont.prototype = {
  16773. send: function (handler) {
  16774. if (this.sent) {
  16775. return;
  16776. }
  16777. var fontData = this.font.exportData();
  16778. handler.send('commonobj', [
  16779. this.loadedName,
  16780. 'Font',
  16781. fontData
  16782. ]);
  16783. this.sent = true;
  16784. },
  16785. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16786. assert(this.font.isType3Font);
  16787. if (this.type3Loaded) {
  16788. return this.type3Loaded;
  16789. }
  16790. var translatedFont = this.font;
  16791. var loadCharProcsPromise = Promise.resolve();
  16792. var charProcs = this.dict.get('CharProcs').getAll();
  16793. var fontResources = this.dict.get('Resources') || resources;
  16794. var charProcKeys = Object.keys(charProcs);
  16795. var charProcOperatorList = {};
  16796. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16797. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16798. var glyphStream = charProcs[key];
  16799. var operatorList = new OperatorList();
  16800. return evaluator.getOperatorList(glyphStream, fontResources,
  16801. operatorList).then(function () {
  16802. charProcOperatorList[key] = operatorList.getIR();
  16803. // Add the dependencies to the parent operator list so they are
  16804. // resolved before sub operator list is executed synchronously.
  16805. parentOperatorList.addDependencies(operatorList.dependencies);
  16806. }, function (reason) {
  16807. warn('Type3 font resource \"' + key + '\" is not available');
  16808. var operatorList = new OperatorList();
  16809. charProcOperatorList[key] = operatorList.getIR();
  16810. });
  16811. }.bind(this, charProcKeys[i]));
  16812. }
  16813. this.type3Loaded = loadCharProcsPromise.then(function () {
  16814. translatedFont.charProcOperatorList = charProcOperatorList;
  16815. });
  16816. return this.type3Loaded;
  16817. }
  16818. };
  16819. return TranslatedFont;
  16820. })();
  16821. var OperatorList = (function OperatorListClosure() {
  16822. var CHUNK_SIZE = 1000;
  16823. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16824. function getTransfers(queue) {
  16825. var transfers = [];
  16826. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16827. for (var i = 0, ii = queue.length; i < ii; i++) {
  16828. switch (fnArray[i]) {
  16829. case OPS.paintInlineImageXObject:
  16830. case OPS.paintInlineImageXObjectGroup:
  16831. case OPS.paintImageMaskXObject:
  16832. var arg = argsArray[i][0]; // first param in imgData
  16833. if (!arg.cached) {
  16834. transfers.push(arg.data.buffer);
  16835. }
  16836. break;
  16837. }
  16838. }
  16839. return transfers;
  16840. }
  16841. function OperatorList(intent, messageHandler, pageIndex) {
  16842. this.messageHandler = messageHandler;
  16843. this.fnArray = [];
  16844. this.argsArray = [];
  16845. this.dependencies = {};
  16846. this.pageIndex = pageIndex;
  16847. this.intent = intent;
  16848. }
  16849. OperatorList.prototype = {
  16850. get length() {
  16851. return this.argsArray.length;
  16852. },
  16853. addOp: function(fn, args) {
  16854. this.fnArray.push(fn);
  16855. this.argsArray.push(args);
  16856. if (this.messageHandler) {
  16857. if (this.fnArray.length >= CHUNK_SIZE) {
  16858. this.flush();
  16859. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16860. (fn === OPS.restore || fn === OPS.endText)) {
  16861. // heuristic to flush on boundary of restore or endText
  16862. this.flush();
  16863. }
  16864. }
  16865. },
  16866. addDependency: function(dependency) {
  16867. if (dependency in this.dependencies) {
  16868. return;
  16869. }
  16870. this.dependencies[dependency] = true;
  16871. this.addOp(OPS.dependency, [dependency]);
  16872. },
  16873. addDependencies: function(dependencies) {
  16874. for (var key in dependencies) {
  16875. this.addDependency(key);
  16876. }
  16877. },
  16878. addOpList: function(opList) {
  16879. Util.extendObj(this.dependencies, opList.dependencies);
  16880. for (var i = 0, ii = opList.length; i < ii; i++) {
  16881. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16882. }
  16883. },
  16884. getIR: function() {
  16885. return {
  16886. fnArray: this.fnArray,
  16887. argsArray: this.argsArray,
  16888. length: this.length
  16889. };
  16890. },
  16891. flush: function(lastChunk) {
  16892. if (this.intent !== 'oplist') {
  16893. new QueueOptimizer().optimize(this);
  16894. }
  16895. var transfers = getTransfers(this);
  16896. this.messageHandler.send('RenderPageChunk', {
  16897. operatorList: {
  16898. fnArray: this.fnArray,
  16899. argsArray: this.argsArray,
  16900. lastChunk: lastChunk,
  16901. length: this.length
  16902. },
  16903. pageIndex: this.pageIndex,
  16904. intent: this.intent
  16905. }, transfers);
  16906. this.dependencies = {};
  16907. this.fnArray.length = 0;
  16908. this.argsArray.length = 0;
  16909. }
  16910. };
  16911. return OperatorList;
  16912. })();
  16913. var StateManager = (function StateManagerClosure() {
  16914. function StateManager(initialState) {
  16915. this.state = initialState;
  16916. this.stateStack = [];
  16917. }
  16918. StateManager.prototype = {
  16919. save: function () {
  16920. var old = this.state;
  16921. this.stateStack.push(this.state);
  16922. this.state = old.clone();
  16923. },
  16924. restore: function () {
  16925. var prev = this.stateStack.pop();
  16926. if (prev) {
  16927. this.state = prev;
  16928. }
  16929. },
  16930. transform: function (args) {
  16931. this.state.ctm = Util.transform(this.state.ctm, args);
  16932. }
  16933. };
  16934. return StateManager;
  16935. })();
  16936. var TextState = (function TextStateClosure() {
  16937. function TextState() {
  16938. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16939. this.fontSize = 0;
  16940. this.font = null;
  16941. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16942. this.textMatrix = IDENTITY_MATRIX.slice();
  16943. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16944. this.charSpacing = 0;
  16945. this.wordSpacing = 0;
  16946. this.leading = 0;
  16947. this.textHScale = 1;
  16948. this.textRise = 0;
  16949. }
  16950. TextState.prototype = {
  16951. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16952. var m = this.textMatrix;
  16953. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16954. },
  16955. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16956. var m = this.textLineMatrix;
  16957. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16958. },
  16959. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16960. var m = this.textMatrix;
  16961. m[4] = m[0] * x + m[2] * y + m[4];
  16962. m[5] = m[1] * x + m[3] * y + m[5];
  16963. },
  16964. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16965. var m = this.textLineMatrix;
  16966. m[4] = m[0] * x + m[2] * y + m[4];
  16967. m[5] = m[1] * x + m[3] * y + m[5];
  16968. },
  16969. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16970. // 9.4.4 Text Space Details
  16971. var tsm = [this.fontSize * this.textHScale, 0,
  16972. 0, this.fontSize,
  16973. 0, this.textRise];
  16974. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16975. },
  16976. carriageReturn: function TextState_carriageReturn() {
  16977. this.translateTextLineMatrix(0, -this.leading);
  16978. this.textMatrix = this.textLineMatrix.slice();
  16979. },
  16980. clone: function TextState_clone() {
  16981. var clone = Object.create(this);
  16982. clone.textMatrix = this.textMatrix.slice();
  16983. clone.textLineMatrix = this.textLineMatrix.slice();
  16984. clone.fontMatrix = this.fontMatrix.slice();
  16985. return clone;
  16986. }
  16987. };
  16988. return TextState;
  16989. })();
  16990. var EvalState = (function EvalStateClosure() {
  16991. function EvalState() {
  16992. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16993. this.font = null;
  16994. this.textRenderingMode = TextRenderingMode.FILL;
  16995. this.fillColorSpace = ColorSpace.singletons.gray;
  16996. this.strokeColorSpace = ColorSpace.singletons.gray;
  16997. }
  16998. EvalState.prototype = {
  16999. clone: function CanvasExtraState_clone() {
  17000. return Object.create(this);
  17001. },
  17002. };
  17003. return EvalState;
  17004. })();
  17005. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  17006. // Specifies properties for each command
  17007. //
  17008. // If variableArgs === true: [0, `numArgs`] expected
  17009. // If variableArgs === false: exactly `numArgs` expected
  17010. var OP_MAP = {
  17011. // Graphic state
  17012. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  17013. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  17014. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  17015. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  17016. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  17017. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  17018. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  17019. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  17020. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  17021. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  17022. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  17023. // Path
  17024. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  17025. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  17026. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  17027. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17028. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17029. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17030. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17031. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17032. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17033. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17034. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17035. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17036. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17037. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17038. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17039. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17040. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17041. // Clipping
  17042. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17043. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17044. // Text
  17045. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17046. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17047. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17048. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17049. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17050. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17051. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17052. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17053. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17054. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17055. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17056. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17057. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17058. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17059. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17060. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17061. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17062. variableArgs: false },
  17063. // Type3 fonts
  17064. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17065. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17066. // Color
  17067. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17068. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17069. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17070. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17071. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17072. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17073. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17074. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17075. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17076. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  17077. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  17078. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  17079. // Shading
  17080. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  17081. // Images
  17082. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  17083. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  17084. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  17085. // XObjects
  17086. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  17087. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  17088. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  17089. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  17090. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  17091. variableArgs: false },
  17092. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  17093. // Compatibility
  17094. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  17095. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  17096. // (reserved partial commands for the lexer)
  17097. BM: null,
  17098. BD: null,
  17099. 'true': null,
  17100. fa: null,
  17101. fal: null,
  17102. fals: null,
  17103. 'false': null,
  17104. nu: null,
  17105. nul: null,
  17106. 'null': null
  17107. };
  17108. function EvaluatorPreprocessor(stream, xref, stateManager) {
  17109. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  17110. // dictionary
  17111. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  17112. this.stateManager = stateManager;
  17113. this.nonProcessedArgs = [];
  17114. }
  17115. EvaluatorPreprocessor.prototype = {
  17116. get savedStatesDepth() {
  17117. return this.stateManager.stateStack.length;
  17118. },
  17119. // |operation| is an object with two fields:
  17120. //
  17121. // - |fn| is an out param.
  17122. //
  17123. // - |args| is an inout param. On entry, it should have one of two values.
  17124. //
  17125. // - An empty array. This indicates that the caller is providing the
  17126. // array in which the args will be stored in. The caller should use
  17127. // this value if it can reuse a single array for each call to read().
  17128. //
  17129. // - |null|. This indicates that the caller needs this function to create
  17130. // the array in which any args are stored in. If there are zero args,
  17131. // this function will leave |operation.args| as |null| (thus avoiding
  17132. // allocations that would occur if we used an empty array to represent
  17133. // zero arguments). Otherwise, it will replace |null| with a new array
  17134. // containing the arguments. The caller should use this value if it
  17135. // cannot reuse an array for each call to read().
  17136. //
  17137. // These two modes are present because this function is very hot and so
  17138. // avoiding allocations where possible is worthwhile.
  17139. //
  17140. read: function EvaluatorPreprocessor_read(operation) {
  17141. var args = operation.args;
  17142. while (true) {
  17143. var obj = this.parser.getObj();
  17144. if (isCmd(obj)) {
  17145. var cmd = obj.cmd;
  17146. // Check that the command is valid
  17147. var opSpec = OP_MAP[cmd];
  17148. if (!opSpec) {
  17149. warn('Unknown command "' + cmd + '"');
  17150. continue;
  17151. }
  17152. var fn = opSpec.id;
  17153. var numArgs = opSpec.numArgs;
  17154. var argsLength = args !== null ? args.length : 0;
  17155. if (!opSpec.variableArgs) {
  17156. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  17157. if (argsLength !== numArgs) {
  17158. var nonProcessedArgs = this.nonProcessedArgs;
  17159. while (argsLength > numArgs) {
  17160. nonProcessedArgs.push(args.shift());
  17161. argsLength--;
  17162. }
  17163. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  17164. if (!args) {
  17165. args = [];
  17166. }
  17167. args.unshift(nonProcessedArgs.pop());
  17168. argsLength++;
  17169. }
  17170. }
  17171. if (argsLength < numArgs) {
  17172. // If we receive too few args, it's not possible to possible
  17173. // to execute the command, so skip the command
  17174. info('Command ' + fn + ': because expected ' +
  17175. numArgs + ' args, but received ' + argsLength +
  17176. ' args; skipping');
  17177. args = null;
  17178. continue;
  17179. }
  17180. } else if (argsLength > numArgs) {
  17181. info('Command ' + fn + ': expected [0,' + numArgs +
  17182. '] args, but received ' + argsLength + ' args');
  17183. }
  17184. // TODO figure out how to type-check vararg functions
  17185. this.preprocessCommand(fn, args);
  17186. operation.fn = fn;
  17187. operation.args = args;
  17188. return true;
  17189. } else {
  17190. if (isEOF(obj)) {
  17191. return false; // no more commands
  17192. }
  17193. // argument
  17194. if (obj !== null) {
  17195. if (!args) {
  17196. args = [];
  17197. }
  17198. args.push((obj instanceof Dict ? obj.getAll() : obj));
  17199. assert(args.length <= 33, 'Too many arguments');
  17200. }
  17201. }
  17202. }
  17203. },
  17204. preprocessCommand:
  17205. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  17206. switch (fn | 0) {
  17207. case OPS.save:
  17208. this.stateManager.save();
  17209. break;
  17210. case OPS.restore:
  17211. this.stateManager.restore();
  17212. break;
  17213. case OPS.transform:
  17214. this.stateManager.transform(args);
  17215. break;
  17216. }
  17217. }
  17218. };
  17219. return EvaluatorPreprocessor;
  17220. })();
  17221. var QueueOptimizer = (function QueueOptimizerClosure() {
  17222. function addState(parentState, pattern, fn) {
  17223. var state = parentState;
  17224. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  17225. var item = pattern[i];
  17226. state = (state[item] || (state[item] = []));
  17227. }
  17228. state[pattern[pattern.length - 1]] = fn;
  17229. }
  17230. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17231. argsArray) {
  17232. // Handles special case of mainly LaTeX documents which use image masks to
  17233. // draw lines with the current fill style.
  17234. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  17235. // have been found at iFirstSave.
  17236. var iFirstPIMXO = iFirstSave + 2;
  17237. for (var i = 0; i < count; i++) {
  17238. var arg = argsArray[iFirstPIMXO + 4 * i];
  17239. var imageMask = arg.length === 1 && arg[0];
  17240. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  17241. (!imageMask.data.length ||
  17242. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  17243. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  17244. continue;
  17245. }
  17246. break;
  17247. }
  17248. return count - i;
  17249. }
  17250. var InitialState = [];
  17251. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17252. // sequences with one |paintInlineImageXObjectGroup| operation.
  17253. addState(InitialState,
  17254. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17255. function foundInlineImageGroup(context) {
  17256. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17257. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17258. var MAX_WIDTH = 1000;
  17259. var IMAGE_PADDING = 1;
  17260. var fnArray = context.fnArray, argsArray = context.argsArray;
  17261. var curr = context.iCurr;
  17262. var iFirstSave = curr - 3;
  17263. var iFirstTransform = curr - 2;
  17264. var iFirstPIIXO = curr - 1;
  17265. // Look for the quartets.
  17266. var i = iFirstSave + 4;
  17267. var ii = fnArray.length;
  17268. while (i + 3 < ii) {
  17269. if (fnArray[i] !== OPS.save ||
  17270. fnArray[i + 1] !== OPS.transform ||
  17271. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17272. fnArray[i + 3] !== OPS.restore) {
  17273. break; // ops don't match
  17274. }
  17275. i += 4;
  17276. }
  17277. // At this point, i is the index of the first op past the last valid
  17278. // quartet.
  17279. var count = Math.min((i - iFirstSave) / 4,
  17280. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17281. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17282. return i;
  17283. }
  17284. // assuming that heights of those image is too small (~1 pixel)
  17285. // packing as much as possible by lines
  17286. var maxX = 0;
  17287. var map = [], maxLineHeight = 0;
  17288. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17289. var q;
  17290. for (q = 0; q < count; q++) {
  17291. var transform = argsArray[iFirstTransform + (q << 2)];
  17292. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17293. if (currentX + img.width > MAX_WIDTH) {
  17294. // starting new line
  17295. maxX = Math.max(maxX, currentX);
  17296. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17297. currentX = 0;
  17298. maxLineHeight = 0;
  17299. }
  17300. map.push({
  17301. transform: transform,
  17302. x: currentX, y: currentY,
  17303. w: img.width, h: img.height
  17304. });
  17305. currentX += img.width + 2 * IMAGE_PADDING;
  17306. maxLineHeight = Math.max(maxLineHeight, img.height);
  17307. }
  17308. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17309. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17310. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17311. var imgRowSize = imgWidth << 2;
  17312. for (q = 0; q < count; q++) {
  17313. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17314. // Copy image by lines and extends pixels into padding.
  17315. var rowSize = map[q].w << 2;
  17316. var dataOffset = 0;
  17317. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17318. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17319. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17320. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17321. dataOffset += rowSize;
  17322. offset += imgRowSize;
  17323. }
  17324. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17325. while (offset >= 0) {
  17326. data[offset - 4] = data[offset];
  17327. data[offset - 3] = data[offset + 1];
  17328. data[offset - 2] = data[offset + 2];
  17329. data[offset - 1] = data[offset + 3];
  17330. data[offset + rowSize] = data[offset + rowSize - 4];
  17331. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17332. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17333. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17334. offset -= imgRowSize;
  17335. }
  17336. }
  17337. // Replace queue items.
  17338. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17339. argsArray.splice(iFirstSave, count * 4,
  17340. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17341. data: imgData }, map]);
  17342. return iFirstSave + 1;
  17343. });
  17344. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17345. // sequences with one |paintImageMaskXObjectGroup| or one
  17346. // |paintImageMaskXObjectRepeat| operation.
  17347. addState(InitialState,
  17348. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17349. function foundImageMaskGroup(context) {
  17350. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17351. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17352. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17353. var fnArray = context.fnArray, argsArray = context.argsArray;
  17354. var curr = context.iCurr;
  17355. var iFirstSave = curr - 3;
  17356. var iFirstTransform = curr - 2;
  17357. var iFirstPIMXO = curr - 1;
  17358. // Look for the quartets.
  17359. var i = iFirstSave + 4;
  17360. var ii = fnArray.length;
  17361. while (i + 3 < ii) {
  17362. if (fnArray[i] !== OPS.save ||
  17363. fnArray[i + 1] !== OPS.transform ||
  17364. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17365. fnArray[i + 3] !== OPS.restore) {
  17366. break; // ops don't match
  17367. }
  17368. i += 4;
  17369. }
  17370. // At this point, i is the index of the first op past the last valid
  17371. // quartet.
  17372. var count = (i - iFirstSave) / 4;
  17373. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17374. argsArray);
  17375. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17376. return i;
  17377. }
  17378. var q;
  17379. var isSameImage = false;
  17380. var iTransform, transformArgs;
  17381. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17382. if (argsArray[iFirstTransform][1] === 0 &&
  17383. argsArray[iFirstTransform][2] === 0) {
  17384. isSameImage = true;
  17385. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17386. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17387. iTransform = iFirstTransform + 4;
  17388. var iPIMXO = iFirstPIMXO + 4;
  17389. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17390. transformArgs = argsArray[iTransform];
  17391. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17392. transformArgs[0] !== firstTransformArg0 ||
  17393. transformArgs[1] !== 0 ||
  17394. transformArgs[2] !== 0 ||
  17395. transformArgs[3] !== firstTransformArg3) {
  17396. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17397. isSameImage = false;
  17398. } else {
  17399. count = q;
  17400. }
  17401. break; // different image or transform
  17402. }
  17403. }
  17404. }
  17405. if (isSameImage) {
  17406. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17407. var positions = new Float32Array(count * 2);
  17408. iTransform = iFirstTransform;
  17409. for (q = 0; q < count; q++, iTransform += 4) {
  17410. transformArgs = argsArray[iTransform];
  17411. positions[(q << 1)] = transformArgs[4];
  17412. positions[(q << 1) + 1] = transformArgs[5];
  17413. }
  17414. // Replace queue items.
  17415. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17416. argsArray.splice(iFirstSave, count * 4,
  17417. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17418. } else {
  17419. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17420. var images = [];
  17421. for (q = 0; q < count; q++) {
  17422. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17423. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17424. images.push({ data: maskParams.data, width: maskParams.width,
  17425. height: maskParams.height,
  17426. transform: transformArgs });
  17427. }
  17428. // Replace queue items.
  17429. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17430. argsArray.splice(iFirstSave, count * 4, [images]);
  17431. }
  17432. return iFirstSave + 1;
  17433. });
  17434. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17435. // with one paintImageXObjectRepeat operation, if the |transform| and
  17436. // |paintImageXObjectRepeat| ops are appropriate.
  17437. addState(InitialState,
  17438. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17439. function (context) {
  17440. var MIN_IMAGES_IN_BLOCK = 3;
  17441. var MAX_IMAGES_IN_BLOCK = 1000;
  17442. var fnArray = context.fnArray, argsArray = context.argsArray;
  17443. var curr = context.iCurr;
  17444. var iFirstSave = curr - 3;
  17445. var iFirstTransform = curr - 2;
  17446. var iFirstPIXO = curr - 1;
  17447. var iFirstRestore = curr;
  17448. if (argsArray[iFirstTransform][1] !== 0 ||
  17449. argsArray[iFirstTransform][2] !== 0) {
  17450. return iFirstRestore + 1; // transform has the wrong form
  17451. }
  17452. // Look for the quartets.
  17453. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17454. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17455. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17456. var i = iFirstSave + 4;
  17457. var ii = fnArray.length;
  17458. while (i + 3 < ii) {
  17459. if (fnArray[i] !== OPS.save ||
  17460. fnArray[i + 1] !== OPS.transform ||
  17461. fnArray[i + 2] !== OPS.paintImageXObject ||
  17462. fnArray[i + 3] !== OPS.restore) {
  17463. break; // ops don't match
  17464. }
  17465. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17466. argsArray[i + 1][1] !== 0 ||
  17467. argsArray[i + 1][2] !== 0 ||
  17468. argsArray[i + 1][3] !== firstTransformArg3) {
  17469. break; // transforms don't match
  17470. }
  17471. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17472. break; // images don't match
  17473. }
  17474. i += 4;
  17475. }
  17476. // At this point, i is the index of the first op past the last valid
  17477. // quartet.
  17478. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17479. if (count < MIN_IMAGES_IN_BLOCK) {
  17480. return i;
  17481. }
  17482. // Extract the (x,y) positions from all of the matching transforms.
  17483. var positions = new Float32Array(count * 2);
  17484. var iTransform = iFirstTransform;
  17485. for (var q = 0; q < count; q++, iTransform += 4) {
  17486. var transformArgs = argsArray[iTransform];
  17487. positions[(q << 1)] = transformArgs[4];
  17488. positions[(q << 1) + 1] = transformArgs[5];
  17489. }
  17490. // Replace queue items.
  17491. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17492. positions];
  17493. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17494. argsArray.splice(iFirstSave, count * 4, args);
  17495. return iFirstSave + 1;
  17496. });
  17497. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17498. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17499. // sequences, if the font for each one is the same.
  17500. addState(InitialState,
  17501. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17502. function (context) {
  17503. var MIN_CHARS_IN_BLOCK = 3;
  17504. var MAX_CHARS_IN_BLOCK = 1000;
  17505. var fnArray = context.fnArray, argsArray = context.argsArray;
  17506. var curr = context.iCurr;
  17507. var iFirstBeginText = curr - 4;
  17508. var iFirstSetFont = curr - 3;
  17509. var iFirstSetTextMatrix = curr - 2;
  17510. var iFirstShowText = curr - 1;
  17511. var iFirstEndText = curr;
  17512. // Look for the quintets.
  17513. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17514. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17515. var i = iFirstBeginText + 5;
  17516. var ii = fnArray.length;
  17517. while (i + 4 < ii) {
  17518. if (fnArray[i] !== OPS.beginText ||
  17519. fnArray[i + 1] !== OPS.setFont ||
  17520. fnArray[i + 2] !== OPS.setTextMatrix ||
  17521. fnArray[i + 3] !== OPS.showText ||
  17522. fnArray[i + 4] !== OPS.endText) {
  17523. break; // ops don't match
  17524. }
  17525. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17526. argsArray[i + 1][1] !== firstSetFontArg1) {
  17527. break; // fonts don't match
  17528. }
  17529. i += 5;
  17530. }
  17531. // At this point, i is the index of the first op past the last valid
  17532. // quintet.
  17533. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17534. if (count < MIN_CHARS_IN_BLOCK) {
  17535. return i;
  17536. }
  17537. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17538. // showText, endText), include that as well. (E.g. <something> might be
  17539. // |dependency|.)
  17540. var iFirst = iFirstBeginText;
  17541. if (iFirstBeginText >= 4 &&
  17542. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17543. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17544. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17545. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17546. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17547. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17548. count++;
  17549. iFirst -= 5;
  17550. }
  17551. // Remove (endText, beginText, setFont) trios.
  17552. var iEndText = iFirst + 4;
  17553. for (var q = 1; q < count; q++) {
  17554. fnArray.splice(iEndText, 3);
  17555. argsArray.splice(iEndText, 3);
  17556. iEndText += 2;
  17557. }
  17558. return iEndText + 1;
  17559. });
  17560. function QueueOptimizer() {}
  17561. QueueOptimizer.prototype = {
  17562. optimize: function QueueOptimizer_optimize(queue) {
  17563. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17564. var context = {
  17565. iCurr: 0,
  17566. fnArray: fnArray,
  17567. argsArray: argsArray
  17568. };
  17569. var state;
  17570. var i = 0, ii = fnArray.length;
  17571. while (i < ii) {
  17572. state = (state || InitialState)[fnArray[i]];
  17573. if (typeof state === 'function') { // we found some handler
  17574. context.iCurr = i;
  17575. // state() returns the index of the first non-matching op (if we
  17576. // didn't match) or the first op past the modified ops (if we did
  17577. // match and replace).
  17578. i = state(context);
  17579. state = undefined; // reset the state machine
  17580. ii = context.fnArray.length;
  17581. } else {
  17582. i++;
  17583. }
  17584. }
  17585. }
  17586. };
  17587. return QueueOptimizer;
  17588. })();
  17589. var BUILT_IN_CMAPS = [
  17590. // << Start unicode maps.
  17591. 'Adobe-GB1-UCS2',
  17592. 'Adobe-CNS1-UCS2',
  17593. 'Adobe-Japan1-UCS2',
  17594. 'Adobe-Korea1-UCS2',
  17595. // >> End unicode maps.
  17596. '78-EUC-H',
  17597. '78-EUC-V',
  17598. '78-H',
  17599. '78-RKSJ-H',
  17600. '78-RKSJ-V',
  17601. '78-V',
  17602. '78ms-RKSJ-H',
  17603. '78ms-RKSJ-V',
  17604. '83pv-RKSJ-H',
  17605. '90ms-RKSJ-H',
  17606. '90ms-RKSJ-V',
  17607. '90msp-RKSJ-H',
  17608. '90msp-RKSJ-V',
  17609. '90pv-RKSJ-H',
  17610. '90pv-RKSJ-V',
  17611. 'Add-H',
  17612. 'Add-RKSJ-H',
  17613. 'Add-RKSJ-V',
  17614. 'Add-V',
  17615. 'Adobe-CNS1-0',
  17616. 'Adobe-CNS1-1',
  17617. 'Adobe-CNS1-2',
  17618. 'Adobe-CNS1-3',
  17619. 'Adobe-CNS1-4',
  17620. 'Adobe-CNS1-5',
  17621. 'Adobe-CNS1-6',
  17622. 'Adobe-GB1-0',
  17623. 'Adobe-GB1-1',
  17624. 'Adobe-GB1-2',
  17625. 'Adobe-GB1-3',
  17626. 'Adobe-GB1-4',
  17627. 'Adobe-GB1-5',
  17628. 'Adobe-Japan1-0',
  17629. 'Adobe-Japan1-1',
  17630. 'Adobe-Japan1-2',
  17631. 'Adobe-Japan1-3',
  17632. 'Adobe-Japan1-4',
  17633. 'Adobe-Japan1-5',
  17634. 'Adobe-Japan1-6',
  17635. 'Adobe-Korea1-0',
  17636. 'Adobe-Korea1-1',
  17637. 'Adobe-Korea1-2',
  17638. 'B5-H',
  17639. 'B5-V',
  17640. 'B5pc-H',
  17641. 'B5pc-V',
  17642. 'CNS-EUC-H',
  17643. 'CNS-EUC-V',
  17644. 'CNS1-H',
  17645. 'CNS1-V',
  17646. 'CNS2-H',
  17647. 'CNS2-V',
  17648. 'ETHK-B5-H',
  17649. 'ETHK-B5-V',
  17650. 'ETen-B5-H',
  17651. 'ETen-B5-V',
  17652. 'ETenms-B5-H',
  17653. 'ETenms-B5-V',
  17654. 'EUC-H',
  17655. 'EUC-V',
  17656. 'Ext-H',
  17657. 'Ext-RKSJ-H',
  17658. 'Ext-RKSJ-V',
  17659. 'Ext-V',
  17660. 'GB-EUC-H',
  17661. 'GB-EUC-V',
  17662. 'GB-H',
  17663. 'GB-V',
  17664. 'GBK-EUC-H',
  17665. 'GBK-EUC-V',
  17666. 'GBK2K-H',
  17667. 'GBK2K-V',
  17668. 'GBKp-EUC-H',
  17669. 'GBKp-EUC-V',
  17670. 'GBT-EUC-H',
  17671. 'GBT-EUC-V',
  17672. 'GBT-H',
  17673. 'GBT-V',
  17674. 'GBTpc-EUC-H',
  17675. 'GBTpc-EUC-V',
  17676. 'GBpc-EUC-H',
  17677. 'GBpc-EUC-V',
  17678. 'H',
  17679. 'HKdla-B5-H',
  17680. 'HKdla-B5-V',
  17681. 'HKdlb-B5-H',
  17682. 'HKdlb-B5-V',
  17683. 'HKgccs-B5-H',
  17684. 'HKgccs-B5-V',
  17685. 'HKm314-B5-H',
  17686. 'HKm314-B5-V',
  17687. 'HKm471-B5-H',
  17688. 'HKm471-B5-V',
  17689. 'HKscs-B5-H',
  17690. 'HKscs-B5-V',
  17691. 'Hankaku',
  17692. 'Hiragana',
  17693. 'KSC-EUC-H',
  17694. 'KSC-EUC-V',
  17695. 'KSC-H',
  17696. 'KSC-Johab-H',
  17697. 'KSC-Johab-V',
  17698. 'KSC-V',
  17699. 'KSCms-UHC-H',
  17700. 'KSCms-UHC-HW-H',
  17701. 'KSCms-UHC-HW-V',
  17702. 'KSCms-UHC-V',
  17703. 'KSCpc-EUC-H',
  17704. 'KSCpc-EUC-V',
  17705. 'Katakana',
  17706. 'NWP-H',
  17707. 'NWP-V',
  17708. 'RKSJ-H',
  17709. 'RKSJ-V',
  17710. 'Roman',
  17711. 'UniCNS-UCS2-H',
  17712. 'UniCNS-UCS2-V',
  17713. 'UniCNS-UTF16-H',
  17714. 'UniCNS-UTF16-V',
  17715. 'UniCNS-UTF32-H',
  17716. 'UniCNS-UTF32-V',
  17717. 'UniCNS-UTF8-H',
  17718. 'UniCNS-UTF8-V',
  17719. 'UniGB-UCS2-H',
  17720. 'UniGB-UCS2-V',
  17721. 'UniGB-UTF16-H',
  17722. 'UniGB-UTF16-V',
  17723. 'UniGB-UTF32-H',
  17724. 'UniGB-UTF32-V',
  17725. 'UniGB-UTF8-H',
  17726. 'UniGB-UTF8-V',
  17727. 'UniJIS-UCS2-H',
  17728. 'UniJIS-UCS2-HW-H',
  17729. 'UniJIS-UCS2-HW-V',
  17730. 'UniJIS-UCS2-V',
  17731. 'UniJIS-UTF16-H',
  17732. 'UniJIS-UTF16-V',
  17733. 'UniJIS-UTF32-H',
  17734. 'UniJIS-UTF32-V',
  17735. 'UniJIS-UTF8-H',
  17736. 'UniJIS-UTF8-V',
  17737. 'UniJIS2004-UTF16-H',
  17738. 'UniJIS2004-UTF16-V',
  17739. 'UniJIS2004-UTF32-H',
  17740. 'UniJIS2004-UTF32-V',
  17741. 'UniJIS2004-UTF8-H',
  17742. 'UniJIS2004-UTF8-V',
  17743. 'UniJISPro-UCS2-HW-V',
  17744. 'UniJISPro-UCS2-V',
  17745. 'UniJISPro-UTF8-V',
  17746. 'UniJISX0213-UTF32-H',
  17747. 'UniJISX0213-UTF32-V',
  17748. 'UniJISX02132004-UTF32-H',
  17749. 'UniJISX02132004-UTF32-V',
  17750. 'UniKS-UCS2-H',
  17751. 'UniKS-UCS2-V',
  17752. 'UniKS-UTF16-H',
  17753. 'UniKS-UTF16-V',
  17754. 'UniKS-UTF32-H',
  17755. 'UniKS-UTF32-V',
  17756. 'UniKS-UTF8-H',
  17757. 'UniKS-UTF8-V',
  17758. 'V',
  17759. 'WP-Symbol'];
  17760. // CMap, not to be confused with TrueType's cmap.
  17761. var CMap = (function CMapClosure() {
  17762. function CMap(builtInCMap) {
  17763. // Codespace ranges are stored as follows:
  17764. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17765. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17766. this.codespaceRanges = [[], [], [], []];
  17767. this.numCodespaceRanges = 0;
  17768. // Map entries have one of two forms.
  17769. // - cid chars are 16-bit unsigned integers, stored as integers.
  17770. // - bf chars are variable-length byte sequences, stored as strings, with
  17771. // one byte per character.
  17772. this._map = [];
  17773. this.name = '';
  17774. this.vertical = false;
  17775. this.useCMap = null;
  17776. this.builtInCMap = builtInCMap;
  17777. }
  17778. CMap.prototype = {
  17779. addCodespaceRange: function(n, low, high) {
  17780. this.codespaceRanges[n - 1].push(low, high);
  17781. this.numCodespaceRanges++;
  17782. },
  17783. mapCidRange: function(low, high, dstLow) {
  17784. while (low <= high) {
  17785. this._map[low++] = dstLow++;
  17786. }
  17787. },
  17788. mapBfRange: function(low, high, dstLow) {
  17789. var lastByte = dstLow.length - 1;
  17790. while (low <= high) {
  17791. this._map[low++] = dstLow;
  17792. // Only the last byte has to be incremented.
  17793. dstLow = dstLow.substr(0, lastByte) +
  17794. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17795. }
  17796. },
  17797. mapBfRangeToArray: function(low, high, array) {
  17798. var i = 0, ii = array.length;
  17799. while (low <= high && i < ii) {
  17800. this._map[low] = array[i++];
  17801. ++low;
  17802. }
  17803. },
  17804. // This is used for both bf and cid chars.
  17805. mapOne: function(src, dst) {
  17806. this._map[src] = dst;
  17807. },
  17808. lookup: function(code) {
  17809. return this._map[code];
  17810. },
  17811. contains: function(code) {
  17812. return this._map[code] !== undefined;
  17813. },
  17814. forEach: function(callback) {
  17815. // Most maps have fewer than 65536 entries, and for those we use normal
  17816. // array iteration. But really sparse tables are possible -- e.g. with
  17817. // indices in the *billions*. For such tables we use for..in, which isn't
  17818. // ideal because it stringifies the indices for all present elements, but
  17819. // it does avoid iterating over every undefined entry.
  17820. var map = this._map;
  17821. var length = map.length;
  17822. var i;
  17823. if (length <= 0x10000) {
  17824. for (i = 0; i < length; i++) {
  17825. if (map[i] !== undefined) {
  17826. callback(i, map[i]);
  17827. }
  17828. }
  17829. } else {
  17830. for (i in this._map) {
  17831. callback(i, map[i]);
  17832. }
  17833. }
  17834. },
  17835. charCodeOf: function(value) {
  17836. return this._map.indexOf(value);
  17837. },
  17838. getMap: function() {
  17839. return this._map;
  17840. },
  17841. readCharCode: function(str, offset, out) {
  17842. var c = 0;
  17843. var codespaceRanges = this.codespaceRanges;
  17844. var codespaceRangesLen = this.codespaceRanges.length;
  17845. // 9.7.6.2 CMap Mapping
  17846. // The code length is at most 4.
  17847. for (var n = 0; n < codespaceRangesLen; n++) {
  17848. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17849. // Check each codespace range to see if it falls within.
  17850. var codespaceRange = codespaceRanges[n];
  17851. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17852. var low = codespaceRange[k++];
  17853. var high = codespaceRange[k++];
  17854. if (c >= low && c <= high) {
  17855. out.charcode = c;
  17856. out.length = n + 1;
  17857. return;
  17858. }
  17859. }
  17860. }
  17861. out.charcode = 0;
  17862. out.length = 1;
  17863. },
  17864. get isIdentityCMap() {
  17865. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  17866. return false;
  17867. }
  17868. if (this._map.length !== 0x10000) {
  17869. return false;
  17870. }
  17871. for (var i = 0; i < 0x10000; i++) {
  17872. if (this._map[i] !== i) {
  17873. return false;
  17874. }
  17875. }
  17876. return true;
  17877. }
  17878. };
  17879. return CMap;
  17880. })();
  17881. // A special case of CMap, where the _map array implicitly has a length of
  17882. // 65536 and each element is equal to its index.
  17883. var IdentityCMap = (function IdentityCMapClosure() {
  17884. function IdentityCMap(vertical, n) {
  17885. CMap.call(this);
  17886. this.vertical = vertical;
  17887. this.addCodespaceRange(n, 0, 0xffff);
  17888. }
  17889. Util.inherit(IdentityCMap, CMap, {});
  17890. IdentityCMap.prototype = {
  17891. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17892. mapCidRange: function(low, high, dstLow) {
  17893. error('should not call mapCidRange');
  17894. },
  17895. mapBfRange: function(low, high, dstLow) {
  17896. error('should not call mapBfRange');
  17897. },
  17898. mapBfRangeToArray: function(low, high, array) {
  17899. error('should not call mapBfRangeToArray');
  17900. },
  17901. mapOne: function(src, dst) {
  17902. error('should not call mapCidOne');
  17903. },
  17904. lookup: function(code) {
  17905. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17906. },
  17907. contains: function(code) {
  17908. return isInt(code) && code <= 0xffff;
  17909. },
  17910. forEach: function(callback) {
  17911. for (var i = 0; i <= 0xffff; i++) {
  17912. callback(i, i);
  17913. }
  17914. },
  17915. charCodeOf: function(value) {
  17916. return (isInt(value) && value <= 0xffff) ? value : -1;
  17917. },
  17918. getMap: function() {
  17919. // Sometimes identity maps must be instantiated, but it's rare.
  17920. var map = new Array(0x10000);
  17921. for (var i = 0; i <= 0xffff; i++) {
  17922. map[i] = i;
  17923. }
  17924. return map;
  17925. },
  17926. readCharCode: CMap.prototype.readCharCode,
  17927. get isIdentityCMap() {
  17928. error('should not access .isIdentityCMap');
  17929. }
  17930. };
  17931. return IdentityCMap;
  17932. })();
  17933. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17934. function fetchBinaryData(url) {
  17935. var nonBinaryRequest = PDFJS.disableWorker;
  17936. var request = new XMLHttpRequest();
  17937. request.open('GET', url, false);
  17938. if (!nonBinaryRequest) {
  17939. try {
  17940. request.responseType = 'arraybuffer';
  17941. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17942. } catch (e) {
  17943. nonBinaryRequest = true;
  17944. }
  17945. }
  17946. if (nonBinaryRequest && request.overrideMimeType) {
  17947. request.overrideMimeType('text/plain; charset=x-user-defined');
  17948. }
  17949. request.send(null);
  17950. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17951. error('Unable to get binary cMap at: ' + url);
  17952. }
  17953. if (nonBinaryRequest) {
  17954. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17955. return ch.charCodeAt(0) & 255;
  17956. });
  17957. return new Uint8Array(data);
  17958. }
  17959. return new Uint8Array(request.response);
  17960. }
  17961. function hexToInt(a, size) {
  17962. var n = 0;
  17963. for (var i = 0; i <= size; i++) {
  17964. n = (n << 8) | a[i];
  17965. }
  17966. return n >>> 0;
  17967. }
  17968. function hexToStr(a, size) {
  17969. // This code is hot. Special-case some common values to avoid creating an
  17970. // object with subarray().
  17971. if (size === 1) {
  17972. return String.fromCharCode(a[0], a[1]);
  17973. }
  17974. if (size === 3) {
  17975. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17976. }
  17977. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17978. }
  17979. function addHex(a, b, size) {
  17980. var c = 0;
  17981. for (var i = size; i >= 0; i--) {
  17982. c += a[i] + b[i];
  17983. a[i] = c & 255;
  17984. c >>= 8;
  17985. }
  17986. }
  17987. function incHex(a, size) {
  17988. var c = 1;
  17989. for (var i = size; i >= 0 && c > 0; i--) {
  17990. c += a[i];
  17991. a[i] = c & 255;
  17992. c >>= 8;
  17993. }
  17994. }
  17995. var MAX_NUM_SIZE = 16;
  17996. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17997. function BinaryCMapStream(data) {
  17998. this.buffer = data;
  17999. this.pos = 0;
  18000. this.end = data.length;
  18001. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  18002. }
  18003. BinaryCMapStream.prototype = {
  18004. readByte: function () {
  18005. if (this.pos >= this.end) {
  18006. return -1;
  18007. }
  18008. return this.buffer[this.pos++];
  18009. },
  18010. readNumber: function () {
  18011. var n = 0;
  18012. var last;
  18013. do {
  18014. var b = this.readByte();
  18015. if (b < 0) {
  18016. error('unexpected EOF in bcmap');
  18017. }
  18018. last = !(b & 0x80);
  18019. n = (n << 7) | (b & 0x7F);
  18020. } while (!last);
  18021. return n;
  18022. },
  18023. readSigned: function () {
  18024. var n = this.readNumber();
  18025. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  18026. },
  18027. readHex: function (num, size) {
  18028. num.set(this.buffer.subarray(this.pos,
  18029. this.pos + size + 1));
  18030. this.pos += size + 1;
  18031. },
  18032. readHexNumber: function (num, size) {
  18033. var last;
  18034. var stack = this.tmpBuf, sp = 0;
  18035. do {
  18036. var b = this.readByte();
  18037. if (b < 0) {
  18038. error('unexpected EOF in bcmap');
  18039. }
  18040. last = !(b & 0x80);
  18041. stack[sp++] = b & 0x7F;
  18042. } while (!last);
  18043. var i = size, buffer = 0, bufferSize = 0;
  18044. while (i >= 0) {
  18045. while (bufferSize < 8 && stack.length > 0) {
  18046. buffer = (stack[--sp] << bufferSize) | buffer;
  18047. bufferSize += 7;
  18048. }
  18049. num[i] = buffer & 255;
  18050. i--;
  18051. buffer >>= 8;
  18052. bufferSize -= 8;
  18053. }
  18054. },
  18055. readHexSigned: function (num, size) {
  18056. this.readHexNumber(num, size);
  18057. var sign = num[size] & 1 ? 255 : 0;
  18058. var c = 0;
  18059. for (var i = 0; i <= size; i++) {
  18060. c = ((c & 1) << 8) | num[i];
  18061. num[i] = (c >> 1) ^ sign;
  18062. }
  18063. },
  18064. readString: function () {
  18065. var len = this.readNumber();
  18066. var s = '';
  18067. for (var i = 0; i < len; i++) {
  18068. s += String.fromCharCode(this.readNumber());
  18069. }
  18070. return s;
  18071. }
  18072. };
  18073. function processBinaryCMap(url, cMap, extend) {
  18074. var data = fetchBinaryData(url);
  18075. var stream = new BinaryCMapStream(data);
  18076. var header = stream.readByte();
  18077. cMap.vertical = !!(header & 1);
  18078. var useCMap = null;
  18079. var start = new Uint8Array(MAX_NUM_SIZE);
  18080. var end = new Uint8Array(MAX_NUM_SIZE);
  18081. var char = new Uint8Array(MAX_NUM_SIZE);
  18082. var charCode = new Uint8Array(MAX_NUM_SIZE);
  18083. var tmp = new Uint8Array(MAX_NUM_SIZE);
  18084. var code;
  18085. var b;
  18086. while ((b = stream.readByte()) >= 0) {
  18087. var type = b >> 5;
  18088. if (type === 7) { // metadata, e.g. comment or usecmap
  18089. switch (b & 0x1F) {
  18090. case 0:
  18091. stream.readString(); // skipping comment
  18092. break;
  18093. case 1:
  18094. useCMap = stream.readString();
  18095. break;
  18096. }
  18097. continue;
  18098. }
  18099. var sequence = !!(b & 0x10);
  18100. var dataSize = b & 15;
  18101. assert(dataSize + 1 <= MAX_NUM_SIZE);
  18102. var ucs2DataSize = 1;
  18103. var subitemsCount = stream.readNumber();
  18104. var i;
  18105. switch (type) {
  18106. case 0: // codespacerange
  18107. stream.readHex(start, dataSize);
  18108. stream.readHexNumber(end, dataSize);
  18109. addHex(end, start, dataSize);
  18110. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18111. hexToInt(end, dataSize));
  18112. for (i = 1; i < subitemsCount; i++) {
  18113. incHex(end, dataSize);
  18114. stream.readHexNumber(start, dataSize);
  18115. addHex(start, end, dataSize);
  18116. stream.readHexNumber(end, dataSize);
  18117. addHex(end, start, dataSize);
  18118. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18119. hexToInt(end, dataSize));
  18120. }
  18121. break;
  18122. case 1: // notdefrange
  18123. stream.readHex(start, dataSize);
  18124. stream.readHexNumber(end, dataSize);
  18125. addHex(end, start, dataSize);
  18126. code = stream.readNumber();
  18127. // undefined range, skipping
  18128. for (i = 1; i < subitemsCount; i++) {
  18129. incHex(end, dataSize);
  18130. stream.readHexNumber(start, dataSize);
  18131. addHex(start, end, dataSize);
  18132. stream.readHexNumber(end, dataSize);
  18133. addHex(end, start, dataSize);
  18134. code = stream.readNumber();
  18135. // nop
  18136. }
  18137. break;
  18138. case 2: // cidchar
  18139. stream.readHex(char, dataSize);
  18140. code = stream.readNumber();
  18141. cMap.mapOne(hexToInt(char, dataSize), code);
  18142. for (i = 1; i < subitemsCount; i++) {
  18143. incHex(char, dataSize);
  18144. if (!sequence) {
  18145. stream.readHexNumber(tmp, dataSize);
  18146. addHex(char, tmp, dataSize);
  18147. }
  18148. code = stream.readSigned() + (code + 1);
  18149. cMap.mapOne(hexToInt(char, dataSize), code);
  18150. }
  18151. break;
  18152. case 3: // cidrange
  18153. stream.readHex(start, dataSize);
  18154. stream.readHexNumber(end, dataSize);
  18155. addHex(end, start, dataSize);
  18156. code = stream.readNumber();
  18157. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18158. code);
  18159. for (i = 1; i < subitemsCount; i++) {
  18160. incHex(end, dataSize);
  18161. if (!sequence) {
  18162. stream.readHexNumber(start, dataSize);
  18163. addHex(start, end, dataSize);
  18164. } else {
  18165. start.set(end);
  18166. }
  18167. stream.readHexNumber(end, dataSize);
  18168. addHex(end, start, dataSize);
  18169. code = stream.readNumber();
  18170. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18171. code);
  18172. }
  18173. break;
  18174. case 4: // bfchar
  18175. stream.readHex(char, ucs2DataSize);
  18176. stream.readHex(charCode, dataSize);
  18177. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18178. hexToStr(charCode, dataSize));
  18179. for (i = 1; i < subitemsCount; i++) {
  18180. incHex(char, ucs2DataSize);
  18181. if (!sequence) {
  18182. stream.readHexNumber(tmp, ucs2DataSize);
  18183. addHex(char, tmp, ucs2DataSize);
  18184. }
  18185. incHex(charCode, dataSize);
  18186. stream.readHexSigned(tmp, dataSize);
  18187. addHex(charCode, tmp, dataSize);
  18188. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18189. hexToStr(charCode, dataSize));
  18190. }
  18191. break;
  18192. case 5: // bfrange
  18193. stream.readHex(start, ucs2DataSize);
  18194. stream.readHexNumber(end, ucs2DataSize);
  18195. addHex(end, start, ucs2DataSize);
  18196. stream.readHex(charCode, dataSize);
  18197. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18198. hexToInt(end, ucs2DataSize),
  18199. hexToStr(charCode, dataSize));
  18200. for (i = 1; i < subitemsCount; i++) {
  18201. incHex(end, ucs2DataSize);
  18202. if (!sequence) {
  18203. stream.readHexNumber(start, ucs2DataSize);
  18204. addHex(start, end, ucs2DataSize);
  18205. } else {
  18206. start.set(end);
  18207. }
  18208. stream.readHexNumber(end, ucs2DataSize);
  18209. addHex(end, start, ucs2DataSize);
  18210. stream.readHex(charCode, dataSize);
  18211. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18212. hexToInt(end, ucs2DataSize),
  18213. hexToStr(charCode, dataSize));
  18214. }
  18215. break;
  18216. default:
  18217. error('Unknown type: ' + type);
  18218. break;
  18219. }
  18220. }
  18221. if (useCMap) {
  18222. extend(useCMap);
  18223. }
  18224. return cMap;
  18225. }
  18226. function BinaryCMapReader() {}
  18227. BinaryCMapReader.prototype = {
  18228. read: processBinaryCMap
  18229. };
  18230. return BinaryCMapReader;
  18231. })();
  18232. var CMapFactory = (function CMapFactoryClosure() {
  18233. function strToInt(str) {
  18234. var a = 0;
  18235. for (var i = 0; i < str.length; i++) {
  18236. a = (a << 8) | str.charCodeAt(i);
  18237. }
  18238. return a >>> 0;
  18239. }
  18240. function expectString(obj) {
  18241. if (!isString(obj)) {
  18242. error('Malformed CMap: expected string.');
  18243. }
  18244. }
  18245. function expectInt(obj) {
  18246. if (!isInt(obj)) {
  18247. error('Malformed CMap: expected int.');
  18248. }
  18249. }
  18250. function parseBfChar(cMap, lexer) {
  18251. while (true) {
  18252. var obj = lexer.getObj();
  18253. if (isEOF(obj)) {
  18254. break;
  18255. }
  18256. if (isCmd(obj, 'endbfchar')) {
  18257. return;
  18258. }
  18259. expectString(obj);
  18260. var src = strToInt(obj);
  18261. obj = lexer.getObj();
  18262. // TODO are /dstName used?
  18263. expectString(obj);
  18264. var dst = obj;
  18265. cMap.mapOne(src, dst);
  18266. }
  18267. }
  18268. function parseBfRange(cMap, lexer) {
  18269. while (true) {
  18270. var obj = lexer.getObj();
  18271. if (isEOF(obj)) {
  18272. break;
  18273. }
  18274. if (isCmd(obj, 'endbfrange')) {
  18275. return;
  18276. }
  18277. expectString(obj);
  18278. var low = strToInt(obj);
  18279. obj = lexer.getObj();
  18280. expectString(obj);
  18281. var high = strToInt(obj);
  18282. obj = lexer.getObj();
  18283. if (isInt(obj) || isString(obj)) {
  18284. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18285. cMap.mapBfRange(low, high, dstLow);
  18286. } else if (isCmd(obj, '[')) {
  18287. obj = lexer.getObj();
  18288. var array = [];
  18289. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18290. array.push(obj);
  18291. obj = lexer.getObj();
  18292. }
  18293. cMap.mapBfRangeToArray(low, high, array);
  18294. } else {
  18295. break;
  18296. }
  18297. }
  18298. error('Invalid bf range.');
  18299. }
  18300. function parseCidChar(cMap, lexer) {
  18301. while (true) {
  18302. var obj = lexer.getObj();
  18303. if (isEOF(obj)) {
  18304. break;
  18305. }
  18306. if (isCmd(obj, 'endcidchar')) {
  18307. return;
  18308. }
  18309. expectString(obj);
  18310. var src = strToInt(obj);
  18311. obj = lexer.getObj();
  18312. expectInt(obj);
  18313. var dst = obj;
  18314. cMap.mapOne(src, dst);
  18315. }
  18316. }
  18317. function parseCidRange(cMap, lexer) {
  18318. while (true) {
  18319. var obj = lexer.getObj();
  18320. if (isEOF(obj)) {
  18321. break;
  18322. }
  18323. if (isCmd(obj, 'endcidrange')) {
  18324. return;
  18325. }
  18326. expectString(obj);
  18327. var low = strToInt(obj);
  18328. obj = lexer.getObj();
  18329. expectString(obj);
  18330. var high = strToInt(obj);
  18331. obj = lexer.getObj();
  18332. expectInt(obj);
  18333. var dstLow = obj;
  18334. cMap.mapCidRange(low, high, dstLow);
  18335. }
  18336. }
  18337. function parseCodespaceRange(cMap, lexer) {
  18338. while (true) {
  18339. var obj = lexer.getObj();
  18340. if (isEOF(obj)) {
  18341. break;
  18342. }
  18343. if (isCmd(obj, 'endcodespacerange')) {
  18344. return;
  18345. }
  18346. if (!isString(obj)) {
  18347. break;
  18348. }
  18349. var low = strToInt(obj);
  18350. obj = lexer.getObj();
  18351. if (!isString(obj)) {
  18352. break;
  18353. }
  18354. var high = strToInt(obj);
  18355. cMap.addCodespaceRange(obj.length, low, high);
  18356. }
  18357. error('Invalid codespace range.');
  18358. }
  18359. function parseWMode(cMap, lexer) {
  18360. var obj = lexer.getObj();
  18361. if (isInt(obj)) {
  18362. cMap.vertical = !!obj;
  18363. }
  18364. }
  18365. function parseCMapName(cMap, lexer) {
  18366. var obj = lexer.getObj();
  18367. if (isName(obj) && isString(obj.name)) {
  18368. cMap.name = obj.name;
  18369. }
  18370. }
  18371. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18372. var previous;
  18373. var embededUseCMap;
  18374. objLoop: while (true) {
  18375. var obj = lexer.getObj();
  18376. if (isEOF(obj)) {
  18377. break;
  18378. } else if (isName(obj)) {
  18379. if (obj.name === 'WMode') {
  18380. parseWMode(cMap, lexer);
  18381. } else if (obj.name === 'CMapName') {
  18382. parseCMapName(cMap, lexer);
  18383. }
  18384. previous = obj;
  18385. } else if (isCmd(obj)) {
  18386. switch (obj.cmd) {
  18387. case 'endcmap':
  18388. break objLoop;
  18389. case 'usecmap':
  18390. if (isName(previous)) {
  18391. embededUseCMap = previous.name;
  18392. }
  18393. break;
  18394. case 'begincodespacerange':
  18395. parseCodespaceRange(cMap, lexer);
  18396. break;
  18397. case 'beginbfchar':
  18398. parseBfChar(cMap, lexer);
  18399. break;
  18400. case 'begincidchar':
  18401. parseCidChar(cMap, lexer);
  18402. break;
  18403. case 'beginbfrange':
  18404. parseBfRange(cMap, lexer);
  18405. break;
  18406. case 'begincidrange':
  18407. parseCidRange(cMap, lexer);
  18408. break;
  18409. }
  18410. }
  18411. }
  18412. if (!useCMap && embededUseCMap) {
  18413. // Load the usecmap definition from the file only if there wasn't one
  18414. // specified.
  18415. useCMap = embededUseCMap;
  18416. }
  18417. if (useCMap) {
  18418. extendCMap(cMap, builtInCMapParams, useCMap);
  18419. }
  18420. }
  18421. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18422. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18423. // If there aren't any code space ranges defined clone all the parent ones
  18424. // into this cMap.
  18425. if (cMap.numCodespaceRanges === 0) {
  18426. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18427. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18428. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18429. }
  18430. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18431. }
  18432. // Merge the map into the current one, making sure not to override
  18433. // any previously defined entries.
  18434. cMap.useCMap.forEach(function(key, value) {
  18435. if (!cMap.contains(key)) {
  18436. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18437. }
  18438. });
  18439. }
  18440. function parseBinaryCMap(name, builtInCMapParams) {
  18441. var url = builtInCMapParams.url + name + '.bcmap';
  18442. var cMap = new CMap(true);
  18443. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18444. extendCMap(cMap, builtInCMapParams, useCMap);
  18445. });
  18446. return cMap;
  18447. }
  18448. function createBuiltInCMap(name, builtInCMapParams) {
  18449. if (name === 'Identity-H') {
  18450. return new IdentityCMap(false, 2);
  18451. } else if (name === 'Identity-V') {
  18452. return new IdentityCMap(true, 2);
  18453. }
  18454. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18455. error('Unknown cMap name: ' + name);
  18456. }
  18457. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18458. if (builtInCMapParams.packed) {
  18459. return parseBinaryCMap(name, builtInCMapParams);
  18460. }
  18461. var request = new XMLHttpRequest();
  18462. var url = builtInCMapParams.url + name;
  18463. request.open('GET', url, false);
  18464. request.send(null);
  18465. if (!request.responseText) {
  18466. error('Unable to get cMap at: ' + url);
  18467. }
  18468. var cMap = new CMap(true);
  18469. var lexer = new Lexer(new StringStream(request.responseText));
  18470. parseCMap(cMap, lexer, builtInCMapParams, null);
  18471. return cMap;
  18472. }
  18473. return {
  18474. create: function (encoding, builtInCMapParams, useCMap) {
  18475. if (isName(encoding)) {
  18476. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18477. } else if (isStream(encoding)) {
  18478. var cMap = new CMap();
  18479. var lexer = new Lexer(encoding);
  18480. try {
  18481. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18482. } catch (e) {
  18483. warn('Invalid CMap data. ' + e);
  18484. }
  18485. if (cMap.isIdentityCMap) {
  18486. return createBuiltInCMap(cMap.name, builtInCMapParams);
  18487. }
  18488. return cMap;
  18489. }
  18490. error('Encoding required.');
  18491. }
  18492. };
  18493. })();
  18494. // Unicode Private Use Area
  18495. var PRIVATE_USE_OFFSET_START = 0xE000;
  18496. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18497. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18498. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18499. // except for Type 3 fonts
  18500. var PDF_GLYPH_SPACE_UNITS = 1000;
  18501. // Hinting is currently disabled due to unknown problems on windows
  18502. // in tracemonkey and various other pdfs with type1 fonts.
  18503. var HINTING_ENABLED = false;
  18504. // Accented charactars are not displayed properly on windows, using this flag
  18505. // to control analysis of seac charstrings.
  18506. var SEAC_ANALYSIS_ENABLED = false;
  18507. var FontFlags = {
  18508. FixedPitch: 1,
  18509. Serif: 2,
  18510. Symbolic: 4,
  18511. Script: 8,
  18512. Nonsymbolic: 32,
  18513. Italic: 64,
  18514. AllCap: 65536,
  18515. SmallCap: 131072,
  18516. ForceBold: 262144
  18517. };
  18518. var Encodings = {
  18519. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18520. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18521. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18522. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18523. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18524. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18525. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18526. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18527. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18528. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18529. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18530. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18531. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18532. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18533. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18534. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18535. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18536. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18537. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18538. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18539. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18540. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18541. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18542. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18543. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18544. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18545. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18546. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18547. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18548. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18549. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18550. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18551. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18552. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18553. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18554. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18555. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18556. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18557. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18558. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18559. 'Ydieresissmall'],
  18560. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18561. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18562. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18563. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18564. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18565. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18566. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18567. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18568. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18569. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18570. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18571. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18572. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18573. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18574. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18575. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18576. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18577. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18578. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18579. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18580. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18581. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18582. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18583. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18584. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18585. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18586. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18587. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18588. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18589. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18590. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18591. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18592. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18593. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18594. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18595. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18596. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18597. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18598. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18599. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18600. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18601. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18602. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18603. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18604. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18605. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18606. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18607. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18608. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18609. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18610. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18611. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18612. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18613. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18614. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18615. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18616. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18617. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18618. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18619. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18620. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18621. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18622. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18623. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18624. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18625. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18626. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18627. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18628. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18629. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18630. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18631. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18632. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18633. 'ogonek', 'caron'],
  18634. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18635. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18636. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18637. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18638. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18639. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18640. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18641. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18642. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18643. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18644. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18645. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18646. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18647. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18648. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18649. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18650. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18651. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18652. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18653. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18654. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18655. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18656. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18657. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18658. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18659. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18660. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18661. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18662. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18663. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18664. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18665. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18666. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18667. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18668. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18669. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18670. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18671. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18672. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18673. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18674. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18675. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18676. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18677. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18678. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18679. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18680. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18681. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18682. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18683. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18684. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18685. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18686. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18687. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18688. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18689. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18690. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18691. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18692. 'ydieresis'],
  18693. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18694. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18695. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18696. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18697. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18698. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18699. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18700. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18701. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18702. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18703. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18704. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18705. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18706. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18707. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18708. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18709. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18710. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18711. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18712. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18713. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18714. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18715. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18716. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18717. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18718. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18719. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18720. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18721. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18722. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18723. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18724. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18725. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18726. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18727. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18728. 'bracerightbt'],
  18729. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18730. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18731. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18732. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18733. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18734. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18735. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18736. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18737. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18738. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18739. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18740. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18741. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18742. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18743. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18744. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18745. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18746. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18747. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18748. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18749. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18750. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18751. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18752. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18753. };
  18754. /**
  18755. * Hold a map of decoded fonts and of the standard fourteen Type1
  18756. * fonts and their acronyms.
  18757. */
  18758. var stdFontMap = {
  18759. 'ArialNarrow': 'Helvetica',
  18760. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18761. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18762. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18763. 'ArialBlack': 'Helvetica',
  18764. 'ArialBlack-Bold': 'Helvetica-Bold',
  18765. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18766. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18767. 'Arial': 'Helvetica',
  18768. 'Arial-Bold': 'Helvetica-Bold',
  18769. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18770. 'Arial-Italic': 'Helvetica-Oblique',
  18771. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18772. 'Arial-BoldMT': 'Helvetica-Bold',
  18773. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18774. 'ArialMT': 'Helvetica',
  18775. 'Courier-Bold': 'Courier-Bold',
  18776. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18777. 'Courier-Italic': 'Courier-Oblique',
  18778. 'CourierNew': 'Courier',
  18779. 'CourierNew-Bold': 'Courier-Bold',
  18780. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18781. 'CourierNew-Italic': 'Courier-Oblique',
  18782. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18783. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18784. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18785. 'CourierNewPSMT': 'Courier',
  18786. 'Helvetica': 'Helvetica',
  18787. 'Helvetica-Bold': 'Helvetica-Bold',
  18788. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18789. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  18790. 'Helvetica-Italic': 'Helvetica-Oblique',
  18791. 'Helvetica-Oblique':'Helvetica-Oblique',
  18792. 'Symbol-Bold': 'Symbol',
  18793. 'Symbol-BoldItalic': 'Symbol',
  18794. 'Symbol-Italic': 'Symbol',
  18795. 'TimesNewRoman': 'Times-Roman',
  18796. 'TimesNewRoman-Bold': 'Times-Bold',
  18797. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18798. 'TimesNewRoman-Italic': 'Times-Italic',
  18799. 'TimesNewRomanPS': 'Times-Roman',
  18800. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18801. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18802. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18803. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18804. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18805. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18806. 'TimesNewRomanPSMT': 'Times-Roman',
  18807. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18808. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18809. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18810. };
  18811. /**
  18812. * Holds the map of the non-standard fonts that might be included as a standard
  18813. * fonts without glyph data.
  18814. */
  18815. var nonStdFontMap = {
  18816. 'CenturyGothic': 'Helvetica',
  18817. 'CenturyGothic-Bold': 'Helvetica-Bold',
  18818. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  18819. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  18820. 'ComicSansMS': 'Comic Sans MS',
  18821. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18822. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18823. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18824. 'LucidaConsole': 'Courier',
  18825. 'LucidaConsole-Bold': 'Courier-Bold',
  18826. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18827. 'LucidaConsole-Italic': 'Courier-Oblique',
  18828. 'MS-Gothic': 'MS Gothic',
  18829. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18830. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18831. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18832. 'MS-Mincho': 'MS Mincho',
  18833. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18834. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18835. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18836. 'MS-PGothic': 'MS PGothic',
  18837. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18838. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18839. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18840. 'MS-PMincho': 'MS PMincho',
  18841. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18842. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18843. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  18844. 'Wingdings': 'ZapfDingbats'
  18845. };
  18846. var serifFonts = {
  18847. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18848. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18849. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18850. 'Arno': true, 'Aster': true, 'Aurora': true,
  18851. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18852. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18853. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18854. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18855. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18856. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18857. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18858. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18859. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18860. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18861. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18862. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18863. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18864. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18865. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18866. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18867. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18868. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18869. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18870. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18871. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18872. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18873. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18874. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18875. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18876. 'Miller': true, 'Minion': true, 'Modern': true,
  18877. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18878. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18879. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18880. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18881. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18882. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18883. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18884. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18885. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18886. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18887. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18888. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18889. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18890. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18891. };
  18892. var symbolsFonts = {
  18893. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18894. };
  18895. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18896. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18897. // glyphs, but common for some set of the standard fonts.
  18898. var GlyphMapForStandardFonts = {
  18899. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18900. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18901. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18902. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18903. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18904. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18905. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18906. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18907. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18908. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18909. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18910. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18911. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18912. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18913. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18914. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18915. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18916. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18917. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18918. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18919. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18920. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18921. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18922. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18923. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18924. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18925. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18926. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18927. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18928. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18929. '298': 380, '305': 963,
  18930. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18931. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18932. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18933. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18934. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18935. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18936. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18937. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18938. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18939. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18940. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18941. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18942. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18943. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18944. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18945. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18946. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18947. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18948. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18949. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18950. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18951. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18952. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18953. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18954. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18955. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18956. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18957. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18958. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18959. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18960. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18961. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18962. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18963. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18964. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18965. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18966. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18967. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18968. };
  18969. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  18970. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18971. // to the similar equivalents in the normal characters range.
  18972. var SpecialPUASymbols = {
  18973. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  18974. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  18975. '63720': 0x00AE, // registersans (0xF8E8) => registered
  18976. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  18977. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  18978. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  18979. '63729': 0x23A7, // bracelefttp (0xF8F1)
  18980. '63730': 0x23A8, // braceleftmid (0xF8F2)
  18981. '63731': 0x23A9, // braceleftbt (0xF8F3)
  18982. '63740': 0x23AB, // bracerighttp (0xF8FC)
  18983. '63741': 0x23AC, // bracerightmid (0xF8FD)
  18984. '63742': 0x23AD, // bracerightbt (0xF8FE)
  18985. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  18986. '63727': 0x23A2, // bracketleftex (0xF8EF)
  18987. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  18988. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  18989. '63738': 0x23A5, // bracketrightex (0xF8FA)
  18990. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  18991. '63723': 0x239B, // parenlefttp (0xF8EB)
  18992. '63724': 0x239C, // parenleftex (0xF8EC)
  18993. '63725': 0x239D, // parenleftbt (0xF8ED)
  18994. '63734': 0x239E, // parenrighttp (0xF8F6)
  18995. '63735': 0x239F, // parenrightex (0xF8F7)
  18996. '63736': 0x23A0, // parenrightbt (0xF8F8)
  18997. };
  18998. function mapSpecialUnicodeValues(code) {
  18999. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  19000. return 0;
  19001. } else if (code >= 0xF600 && code <= 0xF8FF) {
  19002. return (SpecialPUASymbols[code] || code);
  19003. }
  19004. return code;
  19005. }
  19006. var UnicodeRanges = [
  19007. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  19008. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  19009. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  19010. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  19011. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  19012. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  19013. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  19014. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  19015. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  19016. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  19017. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  19018. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  19019. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  19020. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  19021. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  19022. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  19023. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  19024. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  19025. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  19026. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  19027. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  19028. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  19029. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  19030. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  19031. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  19032. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  19033. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  19034. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  19035. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  19036. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  19037. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  19038. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  19039. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  19040. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  19041. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  19042. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  19043. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  19044. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  19045. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  19046. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  19047. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  19048. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  19049. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  19050. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  19051. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  19052. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  19053. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  19054. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  19055. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  19056. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19057. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19058. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19059. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19060. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19061. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19062. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19063. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19064. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  19065. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  19066. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  19067. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  19068. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  19069. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  19070. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  19071. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  19072. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  19073. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  19074. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  19075. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  19076. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  19077. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  19078. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  19079. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  19080. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  19081. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  19082. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  19083. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  19084. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  19085. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  19086. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  19087. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  19088. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  19089. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  19090. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  19091. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  19092. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  19093. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  19094. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  19095. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  19096. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  19097. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  19098. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  19099. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  19100. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  19101. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  19102. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  19103. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  19104. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  19105. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  19106. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  19107. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  19108. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  19109. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  19110. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  19111. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  19112. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  19113. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  19114. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  19115. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  19116. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  19117. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  19118. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  19119. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  19120. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  19121. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  19122. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  19123. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  19124. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  19125. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  19126. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  19127. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  19128. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  19129. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  19130. ];
  19131. var MacStandardGlyphOrdering = [
  19132. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  19133. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  19134. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  19135. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  19136. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  19137. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  19138. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  19139. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  19140. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  19141. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  19142. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  19143. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  19144. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19145. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  19146. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  19147. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  19148. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  19149. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  19150. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  19151. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  19152. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  19153. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  19154. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  19155. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  19156. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  19157. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  19158. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  19159. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  19160. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  19161. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  19162. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  19163. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  19164. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  19165. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  19166. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  19167. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  19168. function getUnicodeRangeFor(value) {
  19169. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  19170. var range = UnicodeRanges[i];
  19171. if (value >= range.begin && value < range.end) {
  19172. return i;
  19173. }
  19174. }
  19175. return -1;
  19176. }
  19177. function isRTLRangeFor(value) {
  19178. var range = UnicodeRanges[13];
  19179. if (value >= range.begin && value < range.end) {
  19180. return true;
  19181. }
  19182. range = UnicodeRanges[11];
  19183. if (value >= range.begin && value < range.end) {
  19184. return true;
  19185. }
  19186. return false;
  19187. }
  19188. // The normalization table is obtained by filtering the Unicode characters
  19189. // database with <compat> entries.
  19190. var NormalizedUnicodes = {
  19191. '\u00A8': '\u0020\u0308',
  19192. '\u00AF': '\u0020\u0304',
  19193. '\u00B4': '\u0020\u0301',
  19194. '\u00B5': '\u03BC',
  19195. '\u00B8': '\u0020\u0327',
  19196. '\u0132': '\u0049\u004A',
  19197. '\u0133': '\u0069\u006A',
  19198. '\u013F': '\u004C\u00B7',
  19199. '\u0140': '\u006C\u00B7',
  19200. '\u0149': '\u02BC\u006E',
  19201. '\u017F': '\u0073',
  19202. '\u01C4': '\u0044\u017D',
  19203. '\u01C5': '\u0044\u017E',
  19204. '\u01C6': '\u0064\u017E',
  19205. '\u01C7': '\u004C\u004A',
  19206. '\u01C8': '\u004C\u006A',
  19207. '\u01C9': '\u006C\u006A',
  19208. '\u01CA': '\u004E\u004A',
  19209. '\u01CB': '\u004E\u006A',
  19210. '\u01CC': '\u006E\u006A',
  19211. '\u01F1': '\u0044\u005A',
  19212. '\u01F2': '\u0044\u007A',
  19213. '\u01F3': '\u0064\u007A',
  19214. '\u02D8': '\u0020\u0306',
  19215. '\u02D9': '\u0020\u0307',
  19216. '\u02DA': '\u0020\u030A',
  19217. '\u02DB': '\u0020\u0328',
  19218. '\u02DC': '\u0020\u0303',
  19219. '\u02DD': '\u0020\u030B',
  19220. '\u037A': '\u0020\u0345',
  19221. '\u0384': '\u0020\u0301',
  19222. '\u03D0': '\u03B2',
  19223. '\u03D1': '\u03B8',
  19224. '\u03D2': '\u03A5',
  19225. '\u03D5': '\u03C6',
  19226. '\u03D6': '\u03C0',
  19227. '\u03F0': '\u03BA',
  19228. '\u03F1': '\u03C1',
  19229. '\u03F2': '\u03C2',
  19230. '\u03F4': '\u0398',
  19231. '\u03F5': '\u03B5',
  19232. '\u03F9': '\u03A3',
  19233. '\u0587': '\u0565\u0582',
  19234. '\u0675': '\u0627\u0674',
  19235. '\u0676': '\u0648\u0674',
  19236. '\u0677': '\u06C7\u0674',
  19237. '\u0678': '\u064A\u0674',
  19238. '\u0E33': '\u0E4D\u0E32',
  19239. '\u0EB3': '\u0ECD\u0EB2',
  19240. '\u0EDC': '\u0EAB\u0E99',
  19241. '\u0EDD': '\u0EAB\u0EA1',
  19242. '\u0F77': '\u0FB2\u0F81',
  19243. '\u0F79': '\u0FB3\u0F81',
  19244. '\u1E9A': '\u0061\u02BE',
  19245. '\u1FBD': '\u0020\u0313',
  19246. '\u1FBF': '\u0020\u0313',
  19247. '\u1FC0': '\u0020\u0342',
  19248. '\u1FFE': '\u0020\u0314',
  19249. '\u2002': '\u0020',
  19250. '\u2003': '\u0020',
  19251. '\u2004': '\u0020',
  19252. '\u2005': '\u0020',
  19253. '\u2006': '\u0020',
  19254. '\u2008': '\u0020',
  19255. '\u2009': '\u0020',
  19256. '\u200A': '\u0020',
  19257. '\u2017': '\u0020\u0333',
  19258. '\u2024': '\u002E',
  19259. '\u2025': '\u002E\u002E',
  19260. '\u2026': '\u002E\u002E\u002E',
  19261. '\u2033': '\u2032\u2032',
  19262. '\u2034': '\u2032\u2032\u2032',
  19263. '\u2036': '\u2035\u2035',
  19264. '\u2037': '\u2035\u2035\u2035',
  19265. '\u203C': '\u0021\u0021',
  19266. '\u203E': '\u0020\u0305',
  19267. '\u2047': '\u003F\u003F',
  19268. '\u2048': '\u003F\u0021',
  19269. '\u2049': '\u0021\u003F',
  19270. '\u2057': '\u2032\u2032\u2032\u2032',
  19271. '\u205F': '\u0020',
  19272. '\u20A8': '\u0052\u0073',
  19273. '\u2100': '\u0061\u002F\u0063',
  19274. '\u2101': '\u0061\u002F\u0073',
  19275. '\u2103': '\u00B0\u0043',
  19276. '\u2105': '\u0063\u002F\u006F',
  19277. '\u2106': '\u0063\u002F\u0075',
  19278. '\u2107': '\u0190',
  19279. '\u2109': '\u00B0\u0046',
  19280. '\u2116': '\u004E\u006F',
  19281. '\u2121': '\u0054\u0045\u004C',
  19282. '\u2135': '\u05D0',
  19283. '\u2136': '\u05D1',
  19284. '\u2137': '\u05D2',
  19285. '\u2138': '\u05D3',
  19286. '\u213B': '\u0046\u0041\u0058',
  19287. '\u2160': '\u0049',
  19288. '\u2161': '\u0049\u0049',
  19289. '\u2162': '\u0049\u0049\u0049',
  19290. '\u2163': '\u0049\u0056',
  19291. '\u2164': '\u0056',
  19292. '\u2165': '\u0056\u0049',
  19293. '\u2166': '\u0056\u0049\u0049',
  19294. '\u2167': '\u0056\u0049\u0049\u0049',
  19295. '\u2168': '\u0049\u0058',
  19296. '\u2169': '\u0058',
  19297. '\u216A': '\u0058\u0049',
  19298. '\u216B': '\u0058\u0049\u0049',
  19299. '\u216C': '\u004C',
  19300. '\u216D': '\u0043',
  19301. '\u216E': '\u0044',
  19302. '\u216F': '\u004D',
  19303. '\u2170': '\u0069',
  19304. '\u2171': '\u0069\u0069',
  19305. '\u2172': '\u0069\u0069\u0069',
  19306. '\u2173': '\u0069\u0076',
  19307. '\u2174': '\u0076',
  19308. '\u2175': '\u0076\u0069',
  19309. '\u2176': '\u0076\u0069\u0069',
  19310. '\u2177': '\u0076\u0069\u0069\u0069',
  19311. '\u2178': '\u0069\u0078',
  19312. '\u2179': '\u0078',
  19313. '\u217A': '\u0078\u0069',
  19314. '\u217B': '\u0078\u0069\u0069',
  19315. '\u217C': '\u006C',
  19316. '\u217D': '\u0063',
  19317. '\u217E': '\u0064',
  19318. '\u217F': '\u006D',
  19319. '\u222C': '\u222B\u222B',
  19320. '\u222D': '\u222B\u222B\u222B',
  19321. '\u222F': '\u222E\u222E',
  19322. '\u2230': '\u222E\u222E\u222E',
  19323. '\u2474': '\u0028\u0031\u0029',
  19324. '\u2475': '\u0028\u0032\u0029',
  19325. '\u2476': '\u0028\u0033\u0029',
  19326. '\u2477': '\u0028\u0034\u0029',
  19327. '\u2478': '\u0028\u0035\u0029',
  19328. '\u2479': '\u0028\u0036\u0029',
  19329. '\u247A': '\u0028\u0037\u0029',
  19330. '\u247B': '\u0028\u0038\u0029',
  19331. '\u247C': '\u0028\u0039\u0029',
  19332. '\u247D': '\u0028\u0031\u0030\u0029',
  19333. '\u247E': '\u0028\u0031\u0031\u0029',
  19334. '\u247F': '\u0028\u0031\u0032\u0029',
  19335. '\u2480': '\u0028\u0031\u0033\u0029',
  19336. '\u2481': '\u0028\u0031\u0034\u0029',
  19337. '\u2482': '\u0028\u0031\u0035\u0029',
  19338. '\u2483': '\u0028\u0031\u0036\u0029',
  19339. '\u2484': '\u0028\u0031\u0037\u0029',
  19340. '\u2485': '\u0028\u0031\u0038\u0029',
  19341. '\u2486': '\u0028\u0031\u0039\u0029',
  19342. '\u2487': '\u0028\u0032\u0030\u0029',
  19343. '\u2488': '\u0031\u002E',
  19344. '\u2489': '\u0032\u002E',
  19345. '\u248A': '\u0033\u002E',
  19346. '\u248B': '\u0034\u002E',
  19347. '\u248C': '\u0035\u002E',
  19348. '\u248D': '\u0036\u002E',
  19349. '\u248E': '\u0037\u002E',
  19350. '\u248F': '\u0038\u002E',
  19351. '\u2490': '\u0039\u002E',
  19352. '\u2491': '\u0031\u0030\u002E',
  19353. '\u2492': '\u0031\u0031\u002E',
  19354. '\u2493': '\u0031\u0032\u002E',
  19355. '\u2494': '\u0031\u0033\u002E',
  19356. '\u2495': '\u0031\u0034\u002E',
  19357. '\u2496': '\u0031\u0035\u002E',
  19358. '\u2497': '\u0031\u0036\u002E',
  19359. '\u2498': '\u0031\u0037\u002E',
  19360. '\u2499': '\u0031\u0038\u002E',
  19361. '\u249A': '\u0031\u0039\u002E',
  19362. '\u249B': '\u0032\u0030\u002E',
  19363. '\u249C': '\u0028\u0061\u0029',
  19364. '\u249D': '\u0028\u0062\u0029',
  19365. '\u249E': '\u0028\u0063\u0029',
  19366. '\u249F': '\u0028\u0064\u0029',
  19367. '\u24A0': '\u0028\u0065\u0029',
  19368. '\u24A1': '\u0028\u0066\u0029',
  19369. '\u24A2': '\u0028\u0067\u0029',
  19370. '\u24A3': '\u0028\u0068\u0029',
  19371. '\u24A4': '\u0028\u0069\u0029',
  19372. '\u24A5': '\u0028\u006A\u0029',
  19373. '\u24A6': '\u0028\u006B\u0029',
  19374. '\u24A7': '\u0028\u006C\u0029',
  19375. '\u24A8': '\u0028\u006D\u0029',
  19376. '\u24A9': '\u0028\u006E\u0029',
  19377. '\u24AA': '\u0028\u006F\u0029',
  19378. '\u24AB': '\u0028\u0070\u0029',
  19379. '\u24AC': '\u0028\u0071\u0029',
  19380. '\u24AD': '\u0028\u0072\u0029',
  19381. '\u24AE': '\u0028\u0073\u0029',
  19382. '\u24AF': '\u0028\u0074\u0029',
  19383. '\u24B0': '\u0028\u0075\u0029',
  19384. '\u24B1': '\u0028\u0076\u0029',
  19385. '\u24B2': '\u0028\u0077\u0029',
  19386. '\u24B3': '\u0028\u0078\u0029',
  19387. '\u24B4': '\u0028\u0079\u0029',
  19388. '\u24B5': '\u0028\u007A\u0029',
  19389. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19390. '\u2A74': '\u003A\u003A\u003D',
  19391. '\u2A75': '\u003D\u003D',
  19392. '\u2A76': '\u003D\u003D\u003D',
  19393. '\u2E9F': '\u6BCD',
  19394. '\u2EF3': '\u9F9F',
  19395. '\u2F00': '\u4E00',
  19396. '\u2F01': '\u4E28',
  19397. '\u2F02': '\u4E36',
  19398. '\u2F03': '\u4E3F',
  19399. '\u2F04': '\u4E59',
  19400. '\u2F05': '\u4E85',
  19401. '\u2F06': '\u4E8C',
  19402. '\u2F07': '\u4EA0',
  19403. '\u2F08': '\u4EBA',
  19404. '\u2F09': '\u513F',
  19405. '\u2F0A': '\u5165',
  19406. '\u2F0B': '\u516B',
  19407. '\u2F0C': '\u5182',
  19408. '\u2F0D': '\u5196',
  19409. '\u2F0E': '\u51AB',
  19410. '\u2F0F': '\u51E0',
  19411. '\u2F10': '\u51F5',
  19412. '\u2F11': '\u5200',
  19413. '\u2F12': '\u529B',
  19414. '\u2F13': '\u52F9',
  19415. '\u2F14': '\u5315',
  19416. '\u2F15': '\u531A',
  19417. '\u2F16': '\u5338',
  19418. '\u2F17': '\u5341',
  19419. '\u2F18': '\u535C',
  19420. '\u2F19': '\u5369',
  19421. '\u2F1A': '\u5382',
  19422. '\u2F1B': '\u53B6',
  19423. '\u2F1C': '\u53C8',
  19424. '\u2F1D': '\u53E3',
  19425. '\u2F1E': '\u56D7',
  19426. '\u2F1F': '\u571F',
  19427. '\u2F20': '\u58EB',
  19428. '\u2F21': '\u5902',
  19429. '\u2F22': '\u590A',
  19430. '\u2F23': '\u5915',
  19431. '\u2F24': '\u5927',
  19432. '\u2F25': '\u5973',
  19433. '\u2F26': '\u5B50',
  19434. '\u2F27': '\u5B80',
  19435. '\u2F28': '\u5BF8',
  19436. '\u2F29': '\u5C0F',
  19437. '\u2F2A': '\u5C22',
  19438. '\u2F2B': '\u5C38',
  19439. '\u2F2C': '\u5C6E',
  19440. '\u2F2D': '\u5C71',
  19441. '\u2F2E': '\u5DDB',
  19442. '\u2F2F': '\u5DE5',
  19443. '\u2F30': '\u5DF1',
  19444. '\u2F31': '\u5DFE',
  19445. '\u2F32': '\u5E72',
  19446. '\u2F33': '\u5E7A',
  19447. '\u2F34': '\u5E7F',
  19448. '\u2F35': '\u5EF4',
  19449. '\u2F36': '\u5EFE',
  19450. '\u2F37': '\u5F0B',
  19451. '\u2F38': '\u5F13',
  19452. '\u2F39': '\u5F50',
  19453. '\u2F3A': '\u5F61',
  19454. '\u2F3B': '\u5F73',
  19455. '\u2F3C': '\u5FC3',
  19456. '\u2F3D': '\u6208',
  19457. '\u2F3E': '\u6236',
  19458. '\u2F3F': '\u624B',
  19459. '\u2F40': '\u652F',
  19460. '\u2F41': '\u6534',
  19461. '\u2F42': '\u6587',
  19462. '\u2F43': '\u6597',
  19463. '\u2F44': '\u65A4',
  19464. '\u2F45': '\u65B9',
  19465. '\u2F46': '\u65E0',
  19466. '\u2F47': '\u65E5',
  19467. '\u2F48': '\u66F0',
  19468. '\u2F49': '\u6708',
  19469. '\u2F4A': '\u6728',
  19470. '\u2F4B': '\u6B20',
  19471. '\u2F4C': '\u6B62',
  19472. '\u2F4D': '\u6B79',
  19473. '\u2F4E': '\u6BB3',
  19474. '\u2F4F': '\u6BCB',
  19475. '\u2F50': '\u6BD4',
  19476. '\u2F51': '\u6BDB',
  19477. '\u2F52': '\u6C0F',
  19478. '\u2F53': '\u6C14',
  19479. '\u2F54': '\u6C34',
  19480. '\u2F55': '\u706B',
  19481. '\u2F56': '\u722A',
  19482. '\u2F57': '\u7236',
  19483. '\u2F58': '\u723B',
  19484. '\u2F59': '\u723F',
  19485. '\u2F5A': '\u7247',
  19486. '\u2F5B': '\u7259',
  19487. '\u2F5C': '\u725B',
  19488. '\u2F5D': '\u72AC',
  19489. '\u2F5E': '\u7384',
  19490. '\u2F5F': '\u7389',
  19491. '\u2F60': '\u74DC',
  19492. '\u2F61': '\u74E6',
  19493. '\u2F62': '\u7518',
  19494. '\u2F63': '\u751F',
  19495. '\u2F64': '\u7528',
  19496. '\u2F65': '\u7530',
  19497. '\u2F66': '\u758B',
  19498. '\u2F67': '\u7592',
  19499. '\u2F68': '\u7676',
  19500. '\u2F69': '\u767D',
  19501. '\u2F6A': '\u76AE',
  19502. '\u2F6B': '\u76BF',
  19503. '\u2F6C': '\u76EE',
  19504. '\u2F6D': '\u77DB',
  19505. '\u2F6E': '\u77E2',
  19506. '\u2F6F': '\u77F3',
  19507. '\u2F70': '\u793A',
  19508. '\u2F71': '\u79B8',
  19509. '\u2F72': '\u79BE',
  19510. '\u2F73': '\u7A74',
  19511. '\u2F74': '\u7ACB',
  19512. '\u2F75': '\u7AF9',
  19513. '\u2F76': '\u7C73',
  19514. '\u2F77': '\u7CF8',
  19515. '\u2F78': '\u7F36',
  19516. '\u2F79': '\u7F51',
  19517. '\u2F7A': '\u7F8A',
  19518. '\u2F7B': '\u7FBD',
  19519. '\u2F7C': '\u8001',
  19520. '\u2F7D': '\u800C',
  19521. '\u2F7E': '\u8012',
  19522. '\u2F7F': '\u8033',
  19523. '\u2F80': '\u807F',
  19524. '\u2F81': '\u8089',
  19525. '\u2F82': '\u81E3',
  19526. '\u2F83': '\u81EA',
  19527. '\u2F84': '\u81F3',
  19528. '\u2F85': '\u81FC',
  19529. '\u2F86': '\u820C',
  19530. '\u2F87': '\u821B',
  19531. '\u2F88': '\u821F',
  19532. '\u2F89': '\u826E',
  19533. '\u2F8A': '\u8272',
  19534. '\u2F8B': '\u8278',
  19535. '\u2F8C': '\u864D',
  19536. '\u2F8D': '\u866B',
  19537. '\u2F8E': '\u8840',
  19538. '\u2F8F': '\u884C',
  19539. '\u2F90': '\u8863',
  19540. '\u2F91': '\u897E',
  19541. '\u2F92': '\u898B',
  19542. '\u2F93': '\u89D2',
  19543. '\u2F94': '\u8A00',
  19544. '\u2F95': '\u8C37',
  19545. '\u2F96': '\u8C46',
  19546. '\u2F97': '\u8C55',
  19547. '\u2F98': '\u8C78',
  19548. '\u2F99': '\u8C9D',
  19549. '\u2F9A': '\u8D64',
  19550. '\u2F9B': '\u8D70',
  19551. '\u2F9C': '\u8DB3',
  19552. '\u2F9D': '\u8EAB',
  19553. '\u2F9E': '\u8ECA',
  19554. '\u2F9F': '\u8F9B',
  19555. '\u2FA0': '\u8FB0',
  19556. '\u2FA1': '\u8FB5',
  19557. '\u2FA2': '\u9091',
  19558. '\u2FA3': '\u9149',
  19559. '\u2FA4': '\u91C6',
  19560. '\u2FA5': '\u91CC',
  19561. '\u2FA6': '\u91D1',
  19562. '\u2FA7': '\u9577',
  19563. '\u2FA8': '\u9580',
  19564. '\u2FA9': '\u961C',
  19565. '\u2FAA': '\u96B6',
  19566. '\u2FAB': '\u96B9',
  19567. '\u2FAC': '\u96E8',
  19568. '\u2FAD': '\u9751',
  19569. '\u2FAE': '\u975E',
  19570. '\u2FAF': '\u9762',
  19571. '\u2FB0': '\u9769',
  19572. '\u2FB1': '\u97CB',
  19573. '\u2FB2': '\u97ED',
  19574. '\u2FB3': '\u97F3',
  19575. '\u2FB4': '\u9801',
  19576. '\u2FB5': '\u98A8',
  19577. '\u2FB6': '\u98DB',
  19578. '\u2FB7': '\u98DF',
  19579. '\u2FB8': '\u9996',
  19580. '\u2FB9': '\u9999',
  19581. '\u2FBA': '\u99AC',
  19582. '\u2FBB': '\u9AA8',
  19583. '\u2FBC': '\u9AD8',
  19584. '\u2FBD': '\u9ADF',
  19585. '\u2FBE': '\u9B25',
  19586. '\u2FBF': '\u9B2F',
  19587. '\u2FC0': '\u9B32',
  19588. '\u2FC1': '\u9B3C',
  19589. '\u2FC2': '\u9B5A',
  19590. '\u2FC3': '\u9CE5',
  19591. '\u2FC4': '\u9E75',
  19592. '\u2FC5': '\u9E7F',
  19593. '\u2FC6': '\u9EA5',
  19594. '\u2FC7': '\u9EBB',
  19595. '\u2FC8': '\u9EC3',
  19596. '\u2FC9': '\u9ECD',
  19597. '\u2FCA': '\u9ED1',
  19598. '\u2FCB': '\u9EF9',
  19599. '\u2FCC': '\u9EFD',
  19600. '\u2FCD': '\u9F0E',
  19601. '\u2FCE': '\u9F13',
  19602. '\u2FCF': '\u9F20',
  19603. '\u2FD0': '\u9F3B',
  19604. '\u2FD1': '\u9F4A',
  19605. '\u2FD2': '\u9F52',
  19606. '\u2FD3': '\u9F8D',
  19607. '\u2FD4': '\u9F9C',
  19608. '\u2FD5': '\u9FA0',
  19609. '\u3036': '\u3012',
  19610. '\u3038': '\u5341',
  19611. '\u3039': '\u5344',
  19612. '\u303A': '\u5345',
  19613. '\u309B': '\u0020\u3099',
  19614. '\u309C': '\u0020\u309A',
  19615. '\u3131': '\u1100',
  19616. '\u3132': '\u1101',
  19617. '\u3133': '\u11AA',
  19618. '\u3134': '\u1102',
  19619. '\u3135': '\u11AC',
  19620. '\u3136': '\u11AD',
  19621. '\u3137': '\u1103',
  19622. '\u3138': '\u1104',
  19623. '\u3139': '\u1105',
  19624. '\u313A': '\u11B0',
  19625. '\u313B': '\u11B1',
  19626. '\u313C': '\u11B2',
  19627. '\u313D': '\u11B3',
  19628. '\u313E': '\u11B4',
  19629. '\u313F': '\u11B5',
  19630. '\u3140': '\u111A',
  19631. '\u3141': '\u1106',
  19632. '\u3142': '\u1107',
  19633. '\u3143': '\u1108',
  19634. '\u3144': '\u1121',
  19635. '\u3145': '\u1109',
  19636. '\u3146': '\u110A',
  19637. '\u3147': '\u110B',
  19638. '\u3148': '\u110C',
  19639. '\u3149': '\u110D',
  19640. '\u314A': '\u110E',
  19641. '\u314B': '\u110F',
  19642. '\u314C': '\u1110',
  19643. '\u314D': '\u1111',
  19644. '\u314E': '\u1112',
  19645. '\u314F': '\u1161',
  19646. '\u3150': '\u1162',
  19647. '\u3151': '\u1163',
  19648. '\u3152': '\u1164',
  19649. '\u3153': '\u1165',
  19650. '\u3154': '\u1166',
  19651. '\u3155': '\u1167',
  19652. '\u3156': '\u1168',
  19653. '\u3157': '\u1169',
  19654. '\u3158': '\u116A',
  19655. '\u3159': '\u116B',
  19656. '\u315A': '\u116C',
  19657. '\u315B': '\u116D',
  19658. '\u315C': '\u116E',
  19659. '\u315D': '\u116F',
  19660. '\u315E': '\u1170',
  19661. '\u315F': '\u1171',
  19662. '\u3160': '\u1172',
  19663. '\u3161': '\u1173',
  19664. '\u3162': '\u1174',
  19665. '\u3163': '\u1175',
  19666. '\u3164': '\u1160',
  19667. '\u3165': '\u1114',
  19668. '\u3166': '\u1115',
  19669. '\u3167': '\u11C7',
  19670. '\u3168': '\u11C8',
  19671. '\u3169': '\u11CC',
  19672. '\u316A': '\u11CE',
  19673. '\u316B': '\u11D3',
  19674. '\u316C': '\u11D7',
  19675. '\u316D': '\u11D9',
  19676. '\u316E': '\u111C',
  19677. '\u316F': '\u11DD',
  19678. '\u3170': '\u11DF',
  19679. '\u3171': '\u111D',
  19680. '\u3172': '\u111E',
  19681. '\u3173': '\u1120',
  19682. '\u3174': '\u1122',
  19683. '\u3175': '\u1123',
  19684. '\u3176': '\u1127',
  19685. '\u3177': '\u1129',
  19686. '\u3178': '\u112B',
  19687. '\u3179': '\u112C',
  19688. '\u317A': '\u112D',
  19689. '\u317B': '\u112E',
  19690. '\u317C': '\u112F',
  19691. '\u317D': '\u1132',
  19692. '\u317E': '\u1136',
  19693. '\u317F': '\u1140',
  19694. '\u3180': '\u1147',
  19695. '\u3181': '\u114C',
  19696. '\u3182': '\u11F1',
  19697. '\u3183': '\u11F2',
  19698. '\u3184': '\u1157',
  19699. '\u3185': '\u1158',
  19700. '\u3186': '\u1159',
  19701. '\u3187': '\u1184',
  19702. '\u3188': '\u1185',
  19703. '\u3189': '\u1188',
  19704. '\u318A': '\u1191',
  19705. '\u318B': '\u1192',
  19706. '\u318C': '\u1194',
  19707. '\u318D': '\u119E',
  19708. '\u318E': '\u11A1',
  19709. '\u3200': '\u0028\u1100\u0029',
  19710. '\u3201': '\u0028\u1102\u0029',
  19711. '\u3202': '\u0028\u1103\u0029',
  19712. '\u3203': '\u0028\u1105\u0029',
  19713. '\u3204': '\u0028\u1106\u0029',
  19714. '\u3205': '\u0028\u1107\u0029',
  19715. '\u3206': '\u0028\u1109\u0029',
  19716. '\u3207': '\u0028\u110B\u0029',
  19717. '\u3208': '\u0028\u110C\u0029',
  19718. '\u3209': '\u0028\u110E\u0029',
  19719. '\u320A': '\u0028\u110F\u0029',
  19720. '\u320B': '\u0028\u1110\u0029',
  19721. '\u320C': '\u0028\u1111\u0029',
  19722. '\u320D': '\u0028\u1112\u0029',
  19723. '\u320E': '\u0028\u1100\u1161\u0029',
  19724. '\u320F': '\u0028\u1102\u1161\u0029',
  19725. '\u3210': '\u0028\u1103\u1161\u0029',
  19726. '\u3211': '\u0028\u1105\u1161\u0029',
  19727. '\u3212': '\u0028\u1106\u1161\u0029',
  19728. '\u3213': '\u0028\u1107\u1161\u0029',
  19729. '\u3214': '\u0028\u1109\u1161\u0029',
  19730. '\u3215': '\u0028\u110B\u1161\u0029',
  19731. '\u3216': '\u0028\u110C\u1161\u0029',
  19732. '\u3217': '\u0028\u110E\u1161\u0029',
  19733. '\u3218': '\u0028\u110F\u1161\u0029',
  19734. '\u3219': '\u0028\u1110\u1161\u0029',
  19735. '\u321A': '\u0028\u1111\u1161\u0029',
  19736. '\u321B': '\u0028\u1112\u1161\u0029',
  19737. '\u321C': '\u0028\u110C\u116E\u0029',
  19738. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19739. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19740. '\u3220': '\u0028\u4E00\u0029',
  19741. '\u3221': '\u0028\u4E8C\u0029',
  19742. '\u3222': '\u0028\u4E09\u0029',
  19743. '\u3223': '\u0028\u56DB\u0029',
  19744. '\u3224': '\u0028\u4E94\u0029',
  19745. '\u3225': '\u0028\u516D\u0029',
  19746. '\u3226': '\u0028\u4E03\u0029',
  19747. '\u3227': '\u0028\u516B\u0029',
  19748. '\u3228': '\u0028\u4E5D\u0029',
  19749. '\u3229': '\u0028\u5341\u0029',
  19750. '\u322A': '\u0028\u6708\u0029',
  19751. '\u322B': '\u0028\u706B\u0029',
  19752. '\u322C': '\u0028\u6C34\u0029',
  19753. '\u322D': '\u0028\u6728\u0029',
  19754. '\u322E': '\u0028\u91D1\u0029',
  19755. '\u322F': '\u0028\u571F\u0029',
  19756. '\u3230': '\u0028\u65E5\u0029',
  19757. '\u3231': '\u0028\u682A\u0029',
  19758. '\u3232': '\u0028\u6709\u0029',
  19759. '\u3233': '\u0028\u793E\u0029',
  19760. '\u3234': '\u0028\u540D\u0029',
  19761. '\u3235': '\u0028\u7279\u0029',
  19762. '\u3236': '\u0028\u8CA1\u0029',
  19763. '\u3237': '\u0028\u795D\u0029',
  19764. '\u3238': '\u0028\u52B4\u0029',
  19765. '\u3239': '\u0028\u4EE3\u0029',
  19766. '\u323A': '\u0028\u547C\u0029',
  19767. '\u323B': '\u0028\u5B66\u0029',
  19768. '\u323C': '\u0028\u76E3\u0029',
  19769. '\u323D': '\u0028\u4F01\u0029',
  19770. '\u323E': '\u0028\u8CC7\u0029',
  19771. '\u323F': '\u0028\u5354\u0029',
  19772. '\u3240': '\u0028\u796D\u0029',
  19773. '\u3241': '\u0028\u4F11\u0029',
  19774. '\u3242': '\u0028\u81EA\u0029',
  19775. '\u3243': '\u0028\u81F3\u0029',
  19776. '\u32C0': '\u0031\u6708',
  19777. '\u32C1': '\u0032\u6708',
  19778. '\u32C2': '\u0033\u6708',
  19779. '\u32C3': '\u0034\u6708',
  19780. '\u32C4': '\u0035\u6708',
  19781. '\u32C5': '\u0036\u6708',
  19782. '\u32C6': '\u0037\u6708',
  19783. '\u32C7': '\u0038\u6708',
  19784. '\u32C8': '\u0039\u6708',
  19785. '\u32C9': '\u0031\u0030\u6708',
  19786. '\u32CA': '\u0031\u0031\u6708',
  19787. '\u32CB': '\u0031\u0032\u6708',
  19788. '\u3358': '\u0030\u70B9',
  19789. '\u3359': '\u0031\u70B9',
  19790. '\u335A': '\u0032\u70B9',
  19791. '\u335B': '\u0033\u70B9',
  19792. '\u335C': '\u0034\u70B9',
  19793. '\u335D': '\u0035\u70B9',
  19794. '\u335E': '\u0036\u70B9',
  19795. '\u335F': '\u0037\u70B9',
  19796. '\u3360': '\u0038\u70B9',
  19797. '\u3361': '\u0039\u70B9',
  19798. '\u3362': '\u0031\u0030\u70B9',
  19799. '\u3363': '\u0031\u0031\u70B9',
  19800. '\u3364': '\u0031\u0032\u70B9',
  19801. '\u3365': '\u0031\u0033\u70B9',
  19802. '\u3366': '\u0031\u0034\u70B9',
  19803. '\u3367': '\u0031\u0035\u70B9',
  19804. '\u3368': '\u0031\u0036\u70B9',
  19805. '\u3369': '\u0031\u0037\u70B9',
  19806. '\u336A': '\u0031\u0038\u70B9',
  19807. '\u336B': '\u0031\u0039\u70B9',
  19808. '\u336C': '\u0032\u0030\u70B9',
  19809. '\u336D': '\u0032\u0031\u70B9',
  19810. '\u336E': '\u0032\u0032\u70B9',
  19811. '\u336F': '\u0032\u0033\u70B9',
  19812. '\u3370': '\u0032\u0034\u70B9',
  19813. '\u33E0': '\u0031\u65E5',
  19814. '\u33E1': '\u0032\u65E5',
  19815. '\u33E2': '\u0033\u65E5',
  19816. '\u33E3': '\u0034\u65E5',
  19817. '\u33E4': '\u0035\u65E5',
  19818. '\u33E5': '\u0036\u65E5',
  19819. '\u33E6': '\u0037\u65E5',
  19820. '\u33E7': '\u0038\u65E5',
  19821. '\u33E8': '\u0039\u65E5',
  19822. '\u33E9': '\u0031\u0030\u65E5',
  19823. '\u33EA': '\u0031\u0031\u65E5',
  19824. '\u33EB': '\u0031\u0032\u65E5',
  19825. '\u33EC': '\u0031\u0033\u65E5',
  19826. '\u33ED': '\u0031\u0034\u65E5',
  19827. '\u33EE': '\u0031\u0035\u65E5',
  19828. '\u33EF': '\u0031\u0036\u65E5',
  19829. '\u33F0': '\u0031\u0037\u65E5',
  19830. '\u33F1': '\u0031\u0038\u65E5',
  19831. '\u33F2': '\u0031\u0039\u65E5',
  19832. '\u33F3': '\u0032\u0030\u65E5',
  19833. '\u33F4': '\u0032\u0031\u65E5',
  19834. '\u33F5': '\u0032\u0032\u65E5',
  19835. '\u33F6': '\u0032\u0033\u65E5',
  19836. '\u33F7': '\u0032\u0034\u65E5',
  19837. '\u33F8': '\u0032\u0035\u65E5',
  19838. '\u33F9': '\u0032\u0036\u65E5',
  19839. '\u33FA': '\u0032\u0037\u65E5',
  19840. '\u33FB': '\u0032\u0038\u65E5',
  19841. '\u33FC': '\u0032\u0039\u65E5',
  19842. '\u33FD': '\u0033\u0030\u65E5',
  19843. '\u33FE': '\u0033\u0031\u65E5',
  19844. '\uFB00': '\u0066\u0066',
  19845. '\uFB01': '\u0066\u0069',
  19846. '\uFB02': '\u0066\u006C',
  19847. '\uFB03': '\u0066\u0066\u0069',
  19848. '\uFB04': '\u0066\u0066\u006C',
  19849. '\uFB05': '\u017F\u0074',
  19850. '\uFB06': '\u0073\u0074',
  19851. '\uFB13': '\u0574\u0576',
  19852. '\uFB14': '\u0574\u0565',
  19853. '\uFB15': '\u0574\u056B',
  19854. '\uFB16': '\u057E\u0576',
  19855. '\uFB17': '\u0574\u056D',
  19856. '\uFB4F': '\u05D0\u05DC',
  19857. '\uFB50': '\u0671',
  19858. '\uFB51': '\u0671',
  19859. '\uFB52': '\u067B',
  19860. '\uFB53': '\u067B',
  19861. '\uFB54': '\u067B',
  19862. '\uFB55': '\u067B',
  19863. '\uFB56': '\u067E',
  19864. '\uFB57': '\u067E',
  19865. '\uFB58': '\u067E',
  19866. '\uFB59': '\u067E',
  19867. '\uFB5A': '\u0680',
  19868. '\uFB5B': '\u0680',
  19869. '\uFB5C': '\u0680',
  19870. '\uFB5D': '\u0680',
  19871. '\uFB5E': '\u067A',
  19872. '\uFB5F': '\u067A',
  19873. '\uFB60': '\u067A',
  19874. '\uFB61': '\u067A',
  19875. '\uFB62': '\u067F',
  19876. '\uFB63': '\u067F',
  19877. '\uFB64': '\u067F',
  19878. '\uFB65': '\u067F',
  19879. '\uFB66': '\u0679',
  19880. '\uFB67': '\u0679',
  19881. '\uFB68': '\u0679',
  19882. '\uFB69': '\u0679',
  19883. '\uFB6A': '\u06A4',
  19884. '\uFB6B': '\u06A4',
  19885. '\uFB6C': '\u06A4',
  19886. '\uFB6D': '\u06A4',
  19887. '\uFB6E': '\u06A6',
  19888. '\uFB6F': '\u06A6',
  19889. '\uFB70': '\u06A6',
  19890. '\uFB71': '\u06A6',
  19891. '\uFB72': '\u0684',
  19892. '\uFB73': '\u0684',
  19893. '\uFB74': '\u0684',
  19894. '\uFB75': '\u0684',
  19895. '\uFB76': '\u0683',
  19896. '\uFB77': '\u0683',
  19897. '\uFB78': '\u0683',
  19898. '\uFB79': '\u0683',
  19899. '\uFB7A': '\u0686',
  19900. '\uFB7B': '\u0686',
  19901. '\uFB7C': '\u0686',
  19902. '\uFB7D': '\u0686',
  19903. '\uFB7E': '\u0687',
  19904. '\uFB7F': '\u0687',
  19905. '\uFB80': '\u0687',
  19906. '\uFB81': '\u0687',
  19907. '\uFB82': '\u068D',
  19908. '\uFB83': '\u068D',
  19909. '\uFB84': '\u068C',
  19910. '\uFB85': '\u068C',
  19911. '\uFB86': '\u068E',
  19912. '\uFB87': '\u068E',
  19913. '\uFB88': '\u0688',
  19914. '\uFB89': '\u0688',
  19915. '\uFB8A': '\u0698',
  19916. '\uFB8B': '\u0698',
  19917. '\uFB8C': '\u0691',
  19918. '\uFB8D': '\u0691',
  19919. '\uFB8E': '\u06A9',
  19920. '\uFB8F': '\u06A9',
  19921. '\uFB90': '\u06A9',
  19922. '\uFB91': '\u06A9',
  19923. '\uFB92': '\u06AF',
  19924. '\uFB93': '\u06AF',
  19925. '\uFB94': '\u06AF',
  19926. '\uFB95': '\u06AF',
  19927. '\uFB96': '\u06B3',
  19928. '\uFB97': '\u06B3',
  19929. '\uFB98': '\u06B3',
  19930. '\uFB99': '\u06B3',
  19931. '\uFB9A': '\u06B1',
  19932. '\uFB9B': '\u06B1',
  19933. '\uFB9C': '\u06B1',
  19934. '\uFB9D': '\u06B1',
  19935. '\uFB9E': '\u06BA',
  19936. '\uFB9F': '\u06BA',
  19937. '\uFBA0': '\u06BB',
  19938. '\uFBA1': '\u06BB',
  19939. '\uFBA2': '\u06BB',
  19940. '\uFBA3': '\u06BB',
  19941. '\uFBA4': '\u06C0',
  19942. '\uFBA5': '\u06C0',
  19943. '\uFBA6': '\u06C1',
  19944. '\uFBA7': '\u06C1',
  19945. '\uFBA8': '\u06C1',
  19946. '\uFBA9': '\u06C1',
  19947. '\uFBAA': '\u06BE',
  19948. '\uFBAB': '\u06BE',
  19949. '\uFBAC': '\u06BE',
  19950. '\uFBAD': '\u06BE',
  19951. '\uFBAE': '\u06D2',
  19952. '\uFBAF': '\u06D2',
  19953. '\uFBB0': '\u06D3',
  19954. '\uFBB1': '\u06D3',
  19955. '\uFBD3': '\u06AD',
  19956. '\uFBD4': '\u06AD',
  19957. '\uFBD5': '\u06AD',
  19958. '\uFBD6': '\u06AD',
  19959. '\uFBD7': '\u06C7',
  19960. '\uFBD8': '\u06C7',
  19961. '\uFBD9': '\u06C6',
  19962. '\uFBDA': '\u06C6',
  19963. '\uFBDB': '\u06C8',
  19964. '\uFBDC': '\u06C8',
  19965. '\uFBDD': '\u0677',
  19966. '\uFBDE': '\u06CB',
  19967. '\uFBDF': '\u06CB',
  19968. '\uFBE0': '\u06C5',
  19969. '\uFBE1': '\u06C5',
  19970. '\uFBE2': '\u06C9',
  19971. '\uFBE3': '\u06C9',
  19972. '\uFBE4': '\u06D0',
  19973. '\uFBE5': '\u06D0',
  19974. '\uFBE6': '\u06D0',
  19975. '\uFBE7': '\u06D0',
  19976. '\uFBE8': '\u0649',
  19977. '\uFBE9': '\u0649',
  19978. '\uFBEA': '\u0626\u0627',
  19979. '\uFBEB': '\u0626\u0627',
  19980. '\uFBEC': '\u0626\u06D5',
  19981. '\uFBED': '\u0626\u06D5',
  19982. '\uFBEE': '\u0626\u0648',
  19983. '\uFBEF': '\u0626\u0648',
  19984. '\uFBF0': '\u0626\u06C7',
  19985. '\uFBF1': '\u0626\u06C7',
  19986. '\uFBF2': '\u0626\u06C6',
  19987. '\uFBF3': '\u0626\u06C6',
  19988. '\uFBF4': '\u0626\u06C8',
  19989. '\uFBF5': '\u0626\u06C8',
  19990. '\uFBF6': '\u0626\u06D0',
  19991. '\uFBF7': '\u0626\u06D0',
  19992. '\uFBF8': '\u0626\u06D0',
  19993. '\uFBF9': '\u0626\u0649',
  19994. '\uFBFA': '\u0626\u0649',
  19995. '\uFBFB': '\u0626\u0649',
  19996. '\uFBFC': '\u06CC',
  19997. '\uFBFD': '\u06CC',
  19998. '\uFBFE': '\u06CC',
  19999. '\uFBFF': '\u06CC',
  20000. '\uFC00': '\u0626\u062C',
  20001. '\uFC01': '\u0626\u062D',
  20002. '\uFC02': '\u0626\u0645',
  20003. '\uFC03': '\u0626\u0649',
  20004. '\uFC04': '\u0626\u064A',
  20005. '\uFC05': '\u0628\u062C',
  20006. '\uFC06': '\u0628\u062D',
  20007. '\uFC07': '\u0628\u062E',
  20008. '\uFC08': '\u0628\u0645',
  20009. '\uFC09': '\u0628\u0649',
  20010. '\uFC0A': '\u0628\u064A',
  20011. '\uFC0B': '\u062A\u062C',
  20012. '\uFC0C': '\u062A\u062D',
  20013. '\uFC0D': '\u062A\u062E',
  20014. '\uFC0E': '\u062A\u0645',
  20015. '\uFC0F': '\u062A\u0649',
  20016. '\uFC10': '\u062A\u064A',
  20017. '\uFC11': '\u062B\u062C',
  20018. '\uFC12': '\u062B\u0645',
  20019. '\uFC13': '\u062B\u0649',
  20020. '\uFC14': '\u062B\u064A',
  20021. '\uFC15': '\u062C\u062D',
  20022. '\uFC16': '\u062C\u0645',
  20023. '\uFC17': '\u062D\u062C',
  20024. '\uFC18': '\u062D\u0645',
  20025. '\uFC19': '\u062E\u062C',
  20026. '\uFC1A': '\u062E\u062D',
  20027. '\uFC1B': '\u062E\u0645',
  20028. '\uFC1C': '\u0633\u062C',
  20029. '\uFC1D': '\u0633\u062D',
  20030. '\uFC1E': '\u0633\u062E',
  20031. '\uFC1F': '\u0633\u0645',
  20032. '\uFC20': '\u0635\u062D',
  20033. '\uFC21': '\u0635\u0645',
  20034. '\uFC22': '\u0636\u062C',
  20035. '\uFC23': '\u0636\u062D',
  20036. '\uFC24': '\u0636\u062E',
  20037. '\uFC25': '\u0636\u0645',
  20038. '\uFC26': '\u0637\u062D',
  20039. '\uFC27': '\u0637\u0645',
  20040. '\uFC28': '\u0638\u0645',
  20041. '\uFC29': '\u0639\u062C',
  20042. '\uFC2A': '\u0639\u0645',
  20043. '\uFC2B': '\u063A\u062C',
  20044. '\uFC2C': '\u063A\u0645',
  20045. '\uFC2D': '\u0641\u062C',
  20046. '\uFC2E': '\u0641\u062D',
  20047. '\uFC2F': '\u0641\u062E',
  20048. '\uFC30': '\u0641\u0645',
  20049. '\uFC31': '\u0641\u0649',
  20050. '\uFC32': '\u0641\u064A',
  20051. '\uFC33': '\u0642\u062D',
  20052. '\uFC34': '\u0642\u0645',
  20053. '\uFC35': '\u0642\u0649',
  20054. '\uFC36': '\u0642\u064A',
  20055. '\uFC37': '\u0643\u0627',
  20056. '\uFC38': '\u0643\u062C',
  20057. '\uFC39': '\u0643\u062D',
  20058. '\uFC3A': '\u0643\u062E',
  20059. '\uFC3B': '\u0643\u0644',
  20060. '\uFC3C': '\u0643\u0645',
  20061. '\uFC3D': '\u0643\u0649',
  20062. '\uFC3E': '\u0643\u064A',
  20063. '\uFC3F': '\u0644\u062C',
  20064. '\uFC40': '\u0644\u062D',
  20065. '\uFC41': '\u0644\u062E',
  20066. '\uFC42': '\u0644\u0645',
  20067. '\uFC43': '\u0644\u0649',
  20068. '\uFC44': '\u0644\u064A',
  20069. '\uFC45': '\u0645\u062C',
  20070. '\uFC46': '\u0645\u062D',
  20071. '\uFC47': '\u0645\u062E',
  20072. '\uFC48': '\u0645\u0645',
  20073. '\uFC49': '\u0645\u0649',
  20074. '\uFC4A': '\u0645\u064A',
  20075. '\uFC4B': '\u0646\u062C',
  20076. '\uFC4C': '\u0646\u062D',
  20077. '\uFC4D': '\u0646\u062E',
  20078. '\uFC4E': '\u0646\u0645',
  20079. '\uFC4F': '\u0646\u0649',
  20080. '\uFC50': '\u0646\u064A',
  20081. '\uFC51': '\u0647\u062C',
  20082. '\uFC52': '\u0647\u0645',
  20083. '\uFC53': '\u0647\u0649',
  20084. '\uFC54': '\u0647\u064A',
  20085. '\uFC55': '\u064A\u062C',
  20086. '\uFC56': '\u064A\u062D',
  20087. '\uFC57': '\u064A\u062E',
  20088. '\uFC58': '\u064A\u0645',
  20089. '\uFC59': '\u064A\u0649',
  20090. '\uFC5A': '\u064A\u064A',
  20091. '\uFC5B': '\u0630\u0670',
  20092. '\uFC5C': '\u0631\u0670',
  20093. '\uFC5D': '\u0649\u0670',
  20094. '\uFC5E': '\u0020\u064C\u0651',
  20095. '\uFC5F': '\u0020\u064D\u0651',
  20096. '\uFC60': '\u0020\u064E\u0651',
  20097. '\uFC61': '\u0020\u064F\u0651',
  20098. '\uFC62': '\u0020\u0650\u0651',
  20099. '\uFC63': '\u0020\u0651\u0670',
  20100. '\uFC64': '\u0626\u0631',
  20101. '\uFC65': '\u0626\u0632',
  20102. '\uFC66': '\u0626\u0645',
  20103. '\uFC67': '\u0626\u0646',
  20104. '\uFC68': '\u0626\u0649',
  20105. '\uFC69': '\u0626\u064A',
  20106. '\uFC6A': '\u0628\u0631',
  20107. '\uFC6B': '\u0628\u0632',
  20108. '\uFC6C': '\u0628\u0645',
  20109. '\uFC6D': '\u0628\u0646',
  20110. '\uFC6E': '\u0628\u0649',
  20111. '\uFC6F': '\u0628\u064A',
  20112. '\uFC70': '\u062A\u0631',
  20113. '\uFC71': '\u062A\u0632',
  20114. '\uFC72': '\u062A\u0645',
  20115. '\uFC73': '\u062A\u0646',
  20116. '\uFC74': '\u062A\u0649',
  20117. '\uFC75': '\u062A\u064A',
  20118. '\uFC76': '\u062B\u0631',
  20119. '\uFC77': '\u062B\u0632',
  20120. '\uFC78': '\u062B\u0645',
  20121. '\uFC79': '\u062B\u0646',
  20122. '\uFC7A': '\u062B\u0649',
  20123. '\uFC7B': '\u062B\u064A',
  20124. '\uFC7C': '\u0641\u0649',
  20125. '\uFC7D': '\u0641\u064A',
  20126. '\uFC7E': '\u0642\u0649',
  20127. '\uFC7F': '\u0642\u064A',
  20128. '\uFC80': '\u0643\u0627',
  20129. '\uFC81': '\u0643\u0644',
  20130. '\uFC82': '\u0643\u0645',
  20131. '\uFC83': '\u0643\u0649',
  20132. '\uFC84': '\u0643\u064A',
  20133. '\uFC85': '\u0644\u0645',
  20134. '\uFC86': '\u0644\u0649',
  20135. '\uFC87': '\u0644\u064A',
  20136. '\uFC88': '\u0645\u0627',
  20137. '\uFC89': '\u0645\u0645',
  20138. '\uFC8A': '\u0646\u0631',
  20139. '\uFC8B': '\u0646\u0632',
  20140. '\uFC8C': '\u0646\u0645',
  20141. '\uFC8D': '\u0646\u0646',
  20142. '\uFC8E': '\u0646\u0649',
  20143. '\uFC8F': '\u0646\u064A',
  20144. '\uFC90': '\u0649\u0670',
  20145. '\uFC91': '\u064A\u0631',
  20146. '\uFC92': '\u064A\u0632',
  20147. '\uFC93': '\u064A\u0645',
  20148. '\uFC94': '\u064A\u0646',
  20149. '\uFC95': '\u064A\u0649',
  20150. '\uFC96': '\u064A\u064A',
  20151. '\uFC97': '\u0626\u062C',
  20152. '\uFC98': '\u0626\u062D',
  20153. '\uFC99': '\u0626\u062E',
  20154. '\uFC9A': '\u0626\u0645',
  20155. '\uFC9B': '\u0626\u0647',
  20156. '\uFC9C': '\u0628\u062C',
  20157. '\uFC9D': '\u0628\u062D',
  20158. '\uFC9E': '\u0628\u062E',
  20159. '\uFC9F': '\u0628\u0645',
  20160. '\uFCA0': '\u0628\u0647',
  20161. '\uFCA1': '\u062A\u062C',
  20162. '\uFCA2': '\u062A\u062D',
  20163. '\uFCA3': '\u062A\u062E',
  20164. '\uFCA4': '\u062A\u0645',
  20165. '\uFCA5': '\u062A\u0647',
  20166. '\uFCA6': '\u062B\u0645',
  20167. '\uFCA7': '\u062C\u062D',
  20168. '\uFCA8': '\u062C\u0645',
  20169. '\uFCA9': '\u062D\u062C',
  20170. '\uFCAA': '\u062D\u0645',
  20171. '\uFCAB': '\u062E\u062C',
  20172. '\uFCAC': '\u062E\u0645',
  20173. '\uFCAD': '\u0633\u062C',
  20174. '\uFCAE': '\u0633\u062D',
  20175. '\uFCAF': '\u0633\u062E',
  20176. '\uFCB0': '\u0633\u0645',
  20177. '\uFCB1': '\u0635\u062D',
  20178. '\uFCB2': '\u0635\u062E',
  20179. '\uFCB3': '\u0635\u0645',
  20180. '\uFCB4': '\u0636\u062C',
  20181. '\uFCB5': '\u0636\u062D',
  20182. '\uFCB6': '\u0636\u062E',
  20183. '\uFCB7': '\u0636\u0645',
  20184. '\uFCB8': '\u0637\u062D',
  20185. '\uFCB9': '\u0638\u0645',
  20186. '\uFCBA': '\u0639\u062C',
  20187. '\uFCBB': '\u0639\u0645',
  20188. '\uFCBC': '\u063A\u062C',
  20189. '\uFCBD': '\u063A\u0645',
  20190. '\uFCBE': '\u0641\u062C',
  20191. '\uFCBF': '\u0641\u062D',
  20192. '\uFCC0': '\u0641\u062E',
  20193. '\uFCC1': '\u0641\u0645',
  20194. '\uFCC2': '\u0642\u062D',
  20195. '\uFCC3': '\u0642\u0645',
  20196. '\uFCC4': '\u0643\u062C',
  20197. '\uFCC5': '\u0643\u062D',
  20198. '\uFCC6': '\u0643\u062E',
  20199. '\uFCC7': '\u0643\u0644',
  20200. '\uFCC8': '\u0643\u0645',
  20201. '\uFCC9': '\u0644\u062C',
  20202. '\uFCCA': '\u0644\u062D',
  20203. '\uFCCB': '\u0644\u062E',
  20204. '\uFCCC': '\u0644\u0645',
  20205. '\uFCCD': '\u0644\u0647',
  20206. '\uFCCE': '\u0645\u062C',
  20207. '\uFCCF': '\u0645\u062D',
  20208. '\uFCD0': '\u0645\u062E',
  20209. '\uFCD1': '\u0645\u0645',
  20210. '\uFCD2': '\u0646\u062C',
  20211. '\uFCD3': '\u0646\u062D',
  20212. '\uFCD4': '\u0646\u062E',
  20213. '\uFCD5': '\u0646\u0645',
  20214. '\uFCD6': '\u0646\u0647',
  20215. '\uFCD7': '\u0647\u062C',
  20216. '\uFCD8': '\u0647\u0645',
  20217. '\uFCD9': '\u0647\u0670',
  20218. '\uFCDA': '\u064A\u062C',
  20219. '\uFCDB': '\u064A\u062D',
  20220. '\uFCDC': '\u064A\u062E',
  20221. '\uFCDD': '\u064A\u0645',
  20222. '\uFCDE': '\u064A\u0647',
  20223. '\uFCDF': '\u0626\u0645',
  20224. '\uFCE0': '\u0626\u0647',
  20225. '\uFCE1': '\u0628\u0645',
  20226. '\uFCE2': '\u0628\u0647',
  20227. '\uFCE3': '\u062A\u0645',
  20228. '\uFCE4': '\u062A\u0647',
  20229. '\uFCE5': '\u062B\u0645',
  20230. '\uFCE6': '\u062B\u0647',
  20231. '\uFCE7': '\u0633\u0645',
  20232. '\uFCE8': '\u0633\u0647',
  20233. '\uFCE9': '\u0634\u0645',
  20234. '\uFCEA': '\u0634\u0647',
  20235. '\uFCEB': '\u0643\u0644',
  20236. '\uFCEC': '\u0643\u0645',
  20237. '\uFCED': '\u0644\u0645',
  20238. '\uFCEE': '\u0646\u0645',
  20239. '\uFCEF': '\u0646\u0647',
  20240. '\uFCF0': '\u064A\u0645',
  20241. '\uFCF1': '\u064A\u0647',
  20242. '\uFCF2': '\u0640\u064E\u0651',
  20243. '\uFCF3': '\u0640\u064F\u0651',
  20244. '\uFCF4': '\u0640\u0650\u0651',
  20245. '\uFCF5': '\u0637\u0649',
  20246. '\uFCF6': '\u0637\u064A',
  20247. '\uFCF7': '\u0639\u0649',
  20248. '\uFCF8': '\u0639\u064A',
  20249. '\uFCF9': '\u063A\u0649',
  20250. '\uFCFA': '\u063A\u064A',
  20251. '\uFCFB': '\u0633\u0649',
  20252. '\uFCFC': '\u0633\u064A',
  20253. '\uFCFD': '\u0634\u0649',
  20254. '\uFCFE': '\u0634\u064A',
  20255. '\uFCFF': '\u062D\u0649',
  20256. '\uFD00': '\u062D\u064A',
  20257. '\uFD01': '\u062C\u0649',
  20258. '\uFD02': '\u062C\u064A',
  20259. '\uFD03': '\u062E\u0649',
  20260. '\uFD04': '\u062E\u064A',
  20261. '\uFD05': '\u0635\u0649',
  20262. '\uFD06': '\u0635\u064A',
  20263. '\uFD07': '\u0636\u0649',
  20264. '\uFD08': '\u0636\u064A',
  20265. '\uFD09': '\u0634\u062C',
  20266. '\uFD0A': '\u0634\u062D',
  20267. '\uFD0B': '\u0634\u062E',
  20268. '\uFD0C': '\u0634\u0645',
  20269. '\uFD0D': '\u0634\u0631',
  20270. '\uFD0E': '\u0633\u0631',
  20271. '\uFD0F': '\u0635\u0631',
  20272. '\uFD10': '\u0636\u0631',
  20273. '\uFD11': '\u0637\u0649',
  20274. '\uFD12': '\u0637\u064A',
  20275. '\uFD13': '\u0639\u0649',
  20276. '\uFD14': '\u0639\u064A',
  20277. '\uFD15': '\u063A\u0649',
  20278. '\uFD16': '\u063A\u064A',
  20279. '\uFD17': '\u0633\u0649',
  20280. '\uFD18': '\u0633\u064A',
  20281. '\uFD19': '\u0634\u0649',
  20282. '\uFD1A': '\u0634\u064A',
  20283. '\uFD1B': '\u062D\u0649',
  20284. '\uFD1C': '\u062D\u064A',
  20285. '\uFD1D': '\u062C\u0649',
  20286. '\uFD1E': '\u062C\u064A',
  20287. '\uFD1F': '\u062E\u0649',
  20288. '\uFD20': '\u062E\u064A',
  20289. '\uFD21': '\u0635\u0649',
  20290. '\uFD22': '\u0635\u064A',
  20291. '\uFD23': '\u0636\u0649',
  20292. '\uFD24': '\u0636\u064A',
  20293. '\uFD25': '\u0634\u062C',
  20294. '\uFD26': '\u0634\u062D',
  20295. '\uFD27': '\u0634\u062E',
  20296. '\uFD28': '\u0634\u0645',
  20297. '\uFD29': '\u0634\u0631',
  20298. '\uFD2A': '\u0633\u0631',
  20299. '\uFD2B': '\u0635\u0631',
  20300. '\uFD2C': '\u0636\u0631',
  20301. '\uFD2D': '\u0634\u062C',
  20302. '\uFD2E': '\u0634\u062D',
  20303. '\uFD2F': '\u0634\u062E',
  20304. '\uFD30': '\u0634\u0645',
  20305. '\uFD31': '\u0633\u0647',
  20306. '\uFD32': '\u0634\u0647',
  20307. '\uFD33': '\u0637\u0645',
  20308. '\uFD34': '\u0633\u062C',
  20309. '\uFD35': '\u0633\u062D',
  20310. '\uFD36': '\u0633\u062E',
  20311. '\uFD37': '\u0634\u062C',
  20312. '\uFD38': '\u0634\u062D',
  20313. '\uFD39': '\u0634\u062E',
  20314. '\uFD3A': '\u0637\u0645',
  20315. '\uFD3B': '\u0638\u0645',
  20316. '\uFD3C': '\u0627\u064B',
  20317. '\uFD3D': '\u0627\u064B',
  20318. '\uFD50': '\u062A\u062C\u0645',
  20319. '\uFD51': '\u062A\u062D\u062C',
  20320. '\uFD52': '\u062A\u062D\u062C',
  20321. '\uFD53': '\u062A\u062D\u0645',
  20322. '\uFD54': '\u062A\u062E\u0645',
  20323. '\uFD55': '\u062A\u0645\u062C',
  20324. '\uFD56': '\u062A\u0645\u062D',
  20325. '\uFD57': '\u062A\u0645\u062E',
  20326. '\uFD58': '\u062C\u0645\u062D',
  20327. '\uFD59': '\u062C\u0645\u062D',
  20328. '\uFD5A': '\u062D\u0645\u064A',
  20329. '\uFD5B': '\u062D\u0645\u0649',
  20330. '\uFD5C': '\u0633\u062D\u062C',
  20331. '\uFD5D': '\u0633\u062C\u062D',
  20332. '\uFD5E': '\u0633\u062C\u0649',
  20333. '\uFD5F': '\u0633\u0645\u062D',
  20334. '\uFD60': '\u0633\u0645\u062D',
  20335. '\uFD61': '\u0633\u0645\u062C',
  20336. '\uFD62': '\u0633\u0645\u0645',
  20337. '\uFD63': '\u0633\u0645\u0645',
  20338. '\uFD64': '\u0635\u062D\u062D',
  20339. '\uFD65': '\u0635\u062D\u062D',
  20340. '\uFD66': '\u0635\u0645\u0645',
  20341. '\uFD67': '\u0634\u062D\u0645',
  20342. '\uFD68': '\u0634\u062D\u0645',
  20343. '\uFD69': '\u0634\u062C\u064A',
  20344. '\uFD6A': '\u0634\u0645\u062E',
  20345. '\uFD6B': '\u0634\u0645\u062E',
  20346. '\uFD6C': '\u0634\u0645\u0645',
  20347. '\uFD6D': '\u0634\u0645\u0645',
  20348. '\uFD6E': '\u0636\u062D\u0649',
  20349. '\uFD6F': '\u0636\u062E\u0645',
  20350. '\uFD70': '\u0636\u062E\u0645',
  20351. '\uFD71': '\u0637\u0645\u062D',
  20352. '\uFD72': '\u0637\u0645\u062D',
  20353. '\uFD73': '\u0637\u0645\u0645',
  20354. '\uFD74': '\u0637\u0645\u064A',
  20355. '\uFD75': '\u0639\u062C\u0645',
  20356. '\uFD76': '\u0639\u0645\u0645',
  20357. '\uFD77': '\u0639\u0645\u0645',
  20358. '\uFD78': '\u0639\u0645\u0649',
  20359. '\uFD79': '\u063A\u0645\u0645',
  20360. '\uFD7A': '\u063A\u0645\u064A',
  20361. '\uFD7B': '\u063A\u0645\u0649',
  20362. '\uFD7C': '\u0641\u062E\u0645',
  20363. '\uFD7D': '\u0641\u062E\u0645',
  20364. '\uFD7E': '\u0642\u0645\u062D',
  20365. '\uFD7F': '\u0642\u0645\u0645',
  20366. '\uFD80': '\u0644\u062D\u0645',
  20367. '\uFD81': '\u0644\u062D\u064A',
  20368. '\uFD82': '\u0644\u062D\u0649',
  20369. '\uFD83': '\u0644\u062C\u062C',
  20370. '\uFD84': '\u0644\u062C\u062C',
  20371. '\uFD85': '\u0644\u062E\u0645',
  20372. '\uFD86': '\u0644\u062E\u0645',
  20373. '\uFD87': '\u0644\u0645\u062D',
  20374. '\uFD88': '\u0644\u0645\u062D',
  20375. '\uFD89': '\u0645\u062D\u062C',
  20376. '\uFD8A': '\u0645\u062D\u0645',
  20377. '\uFD8B': '\u0645\u062D\u064A',
  20378. '\uFD8C': '\u0645\u062C\u062D',
  20379. '\uFD8D': '\u0645\u062C\u0645',
  20380. '\uFD8E': '\u0645\u062E\u062C',
  20381. '\uFD8F': '\u0645\u062E\u0645',
  20382. '\uFD92': '\u0645\u062C\u062E',
  20383. '\uFD93': '\u0647\u0645\u062C',
  20384. '\uFD94': '\u0647\u0645\u0645',
  20385. '\uFD95': '\u0646\u062D\u0645',
  20386. '\uFD96': '\u0646\u062D\u0649',
  20387. '\uFD97': '\u0646\u062C\u0645',
  20388. '\uFD98': '\u0646\u062C\u0645',
  20389. '\uFD99': '\u0646\u062C\u0649',
  20390. '\uFD9A': '\u0646\u0645\u064A',
  20391. '\uFD9B': '\u0646\u0645\u0649',
  20392. '\uFD9C': '\u064A\u0645\u0645',
  20393. '\uFD9D': '\u064A\u0645\u0645',
  20394. '\uFD9E': '\u0628\u062E\u064A',
  20395. '\uFD9F': '\u062A\u062C\u064A',
  20396. '\uFDA0': '\u062A\u062C\u0649',
  20397. '\uFDA1': '\u062A\u062E\u064A',
  20398. '\uFDA2': '\u062A\u062E\u0649',
  20399. '\uFDA3': '\u062A\u0645\u064A',
  20400. '\uFDA4': '\u062A\u0645\u0649',
  20401. '\uFDA5': '\u062C\u0645\u064A',
  20402. '\uFDA6': '\u062C\u062D\u0649',
  20403. '\uFDA7': '\u062C\u0645\u0649',
  20404. '\uFDA8': '\u0633\u062E\u0649',
  20405. '\uFDA9': '\u0635\u062D\u064A',
  20406. '\uFDAA': '\u0634\u062D\u064A',
  20407. '\uFDAB': '\u0636\u062D\u064A',
  20408. '\uFDAC': '\u0644\u062C\u064A',
  20409. '\uFDAD': '\u0644\u0645\u064A',
  20410. '\uFDAE': '\u064A\u062D\u064A',
  20411. '\uFDAF': '\u064A\u062C\u064A',
  20412. '\uFDB0': '\u064A\u0645\u064A',
  20413. '\uFDB1': '\u0645\u0645\u064A',
  20414. '\uFDB2': '\u0642\u0645\u064A',
  20415. '\uFDB3': '\u0646\u062D\u064A',
  20416. '\uFDB4': '\u0642\u0645\u062D',
  20417. '\uFDB5': '\u0644\u062D\u0645',
  20418. '\uFDB6': '\u0639\u0645\u064A',
  20419. '\uFDB7': '\u0643\u0645\u064A',
  20420. '\uFDB8': '\u0646\u062C\u062D',
  20421. '\uFDB9': '\u0645\u062E\u064A',
  20422. '\uFDBA': '\u0644\u062C\u0645',
  20423. '\uFDBB': '\u0643\u0645\u0645',
  20424. '\uFDBC': '\u0644\u062C\u0645',
  20425. '\uFDBD': '\u0646\u062C\u062D',
  20426. '\uFDBE': '\u062C\u062D\u064A',
  20427. '\uFDBF': '\u062D\u062C\u064A',
  20428. '\uFDC0': '\u0645\u062C\u064A',
  20429. '\uFDC1': '\u0641\u0645\u064A',
  20430. '\uFDC2': '\u0628\u062D\u064A',
  20431. '\uFDC3': '\u0643\u0645\u0645',
  20432. '\uFDC4': '\u0639\u062C\u0645',
  20433. '\uFDC5': '\u0635\u0645\u0645',
  20434. '\uFDC6': '\u0633\u062E\u064A',
  20435. '\uFDC7': '\u0646\u062C\u064A',
  20436. '\uFE49': '\u203E',
  20437. '\uFE4A': '\u203E',
  20438. '\uFE4B': '\u203E',
  20439. '\uFE4C': '\u203E',
  20440. '\uFE4D': '\u005F',
  20441. '\uFE4E': '\u005F',
  20442. '\uFE4F': '\u005F',
  20443. '\uFE80': '\u0621',
  20444. '\uFE81': '\u0622',
  20445. '\uFE82': '\u0622',
  20446. '\uFE83': '\u0623',
  20447. '\uFE84': '\u0623',
  20448. '\uFE85': '\u0624',
  20449. '\uFE86': '\u0624',
  20450. '\uFE87': '\u0625',
  20451. '\uFE88': '\u0625',
  20452. '\uFE89': '\u0626',
  20453. '\uFE8A': '\u0626',
  20454. '\uFE8B': '\u0626',
  20455. '\uFE8C': '\u0626',
  20456. '\uFE8D': '\u0627',
  20457. '\uFE8E': '\u0627',
  20458. '\uFE8F': '\u0628',
  20459. '\uFE90': '\u0628',
  20460. '\uFE91': '\u0628',
  20461. '\uFE92': '\u0628',
  20462. '\uFE93': '\u0629',
  20463. '\uFE94': '\u0629',
  20464. '\uFE95': '\u062A',
  20465. '\uFE96': '\u062A',
  20466. '\uFE97': '\u062A',
  20467. '\uFE98': '\u062A',
  20468. '\uFE99': '\u062B',
  20469. '\uFE9A': '\u062B',
  20470. '\uFE9B': '\u062B',
  20471. '\uFE9C': '\u062B',
  20472. '\uFE9D': '\u062C',
  20473. '\uFE9E': '\u062C',
  20474. '\uFE9F': '\u062C',
  20475. '\uFEA0': '\u062C',
  20476. '\uFEA1': '\u062D',
  20477. '\uFEA2': '\u062D',
  20478. '\uFEA3': '\u062D',
  20479. '\uFEA4': '\u062D',
  20480. '\uFEA5': '\u062E',
  20481. '\uFEA6': '\u062E',
  20482. '\uFEA7': '\u062E',
  20483. '\uFEA8': '\u062E',
  20484. '\uFEA9': '\u062F',
  20485. '\uFEAA': '\u062F',
  20486. '\uFEAB': '\u0630',
  20487. '\uFEAC': '\u0630',
  20488. '\uFEAD': '\u0631',
  20489. '\uFEAE': '\u0631',
  20490. '\uFEAF': '\u0632',
  20491. '\uFEB0': '\u0632',
  20492. '\uFEB1': '\u0633',
  20493. '\uFEB2': '\u0633',
  20494. '\uFEB3': '\u0633',
  20495. '\uFEB4': '\u0633',
  20496. '\uFEB5': '\u0634',
  20497. '\uFEB6': '\u0634',
  20498. '\uFEB7': '\u0634',
  20499. '\uFEB8': '\u0634',
  20500. '\uFEB9': '\u0635',
  20501. '\uFEBA': '\u0635',
  20502. '\uFEBB': '\u0635',
  20503. '\uFEBC': '\u0635',
  20504. '\uFEBD': '\u0636',
  20505. '\uFEBE': '\u0636',
  20506. '\uFEBF': '\u0636',
  20507. '\uFEC0': '\u0636',
  20508. '\uFEC1': '\u0637',
  20509. '\uFEC2': '\u0637',
  20510. '\uFEC3': '\u0637',
  20511. '\uFEC4': '\u0637',
  20512. '\uFEC5': '\u0638',
  20513. '\uFEC6': '\u0638',
  20514. '\uFEC7': '\u0638',
  20515. '\uFEC8': '\u0638',
  20516. '\uFEC9': '\u0639',
  20517. '\uFECA': '\u0639',
  20518. '\uFECB': '\u0639',
  20519. '\uFECC': '\u0639',
  20520. '\uFECD': '\u063A',
  20521. '\uFECE': '\u063A',
  20522. '\uFECF': '\u063A',
  20523. '\uFED0': '\u063A',
  20524. '\uFED1': '\u0641',
  20525. '\uFED2': '\u0641',
  20526. '\uFED3': '\u0641',
  20527. '\uFED4': '\u0641',
  20528. '\uFED5': '\u0642',
  20529. '\uFED6': '\u0642',
  20530. '\uFED7': '\u0642',
  20531. '\uFED8': '\u0642',
  20532. '\uFED9': '\u0643',
  20533. '\uFEDA': '\u0643',
  20534. '\uFEDB': '\u0643',
  20535. '\uFEDC': '\u0643',
  20536. '\uFEDD': '\u0644',
  20537. '\uFEDE': '\u0644',
  20538. '\uFEDF': '\u0644',
  20539. '\uFEE0': '\u0644',
  20540. '\uFEE1': '\u0645',
  20541. '\uFEE2': '\u0645',
  20542. '\uFEE3': '\u0645',
  20543. '\uFEE4': '\u0645',
  20544. '\uFEE5': '\u0646',
  20545. '\uFEE6': '\u0646',
  20546. '\uFEE7': '\u0646',
  20547. '\uFEE8': '\u0646',
  20548. '\uFEE9': '\u0647',
  20549. '\uFEEA': '\u0647',
  20550. '\uFEEB': '\u0647',
  20551. '\uFEEC': '\u0647',
  20552. '\uFEED': '\u0648',
  20553. '\uFEEE': '\u0648',
  20554. '\uFEEF': '\u0649',
  20555. '\uFEF0': '\u0649',
  20556. '\uFEF1': '\u064A',
  20557. '\uFEF2': '\u064A',
  20558. '\uFEF3': '\u064A',
  20559. '\uFEF4': '\u064A',
  20560. '\uFEF5': '\u0644\u0622',
  20561. '\uFEF6': '\u0644\u0622',
  20562. '\uFEF7': '\u0644\u0623',
  20563. '\uFEF8': '\u0644\u0623',
  20564. '\uFEF9': '\u0644\u0625',
  20565. '\uFEFA': '\u0644\u0625',
  20566. '\uFEFB': '\u0644\u0627',
  20567. '\uFEFC': '\u0644\u0627'
  20568. };
  20569. function reverseIfRtl(chars) {
  20570. var charsLength = chars.length;
  20571. //reverse an arabic ligature
  20572. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20573. return chars;
  20574. }
  20575. var s = '';
  20576. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20577. s += chars[ii];
  20578. }
  20579. return s;
  20580. }
  20581. function adjustWidths(properties) {
  20582. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20583. return;
  20584. }
  20585. // adjusting width to fontMatrix scale
  20586. var scale = 0.001 / properties.fontMatrix[0];
  20587. var glyphsWidths = properties.widths;
  20588. for (var glyph in glyphsWidths) {
  20589. glyphsWidths[glyph] *= scale;
  20590. }
  20591. properties.defaultWidth *= scale;
  20592. }
  20593. function getFontType(type, subtype) {
  20594. switch (type) {
  20595. case 'Type1':
  20596. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20597. case 'CIDFontType0':
  20598. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20599. FontType.CIDFONTTYPE0;
  20600. case 'OpenType':
  20601. return FontType.OPENTYPE;
  20602. case 'TrueType':
  20603. return FontType.TRUETYPE;
  20604. case 'CIDFontType2':
  20605. return FontType.CIDFONTTYPE2;
  20606. case 'MMType1':
  20607. return FontType.MMTYPE1;
  20608. case 'Type0':
  20609. return FontType.TYPE0;
  20610. default:
  20611. return FontType.UNKNOWN;
  20612. }
  20613. }
  20614. var Glyph = (function GlyphClosure() {
  20615. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20616. this.fontChar = fontChar;
  20617. this.unicode = unicode;
  20618. this.accent = accent;
  20619. this.width = width;
  20620. this.vmetric = vmetric;
  20621. this.operatorListId = operatorListId;
  20622. }
  20623. Glyph.prototype.matchesForCache =
  20624. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20625. return this.fontChar === fontChar &&
  20626. this.unicode === unicode &&
  20627. this.accent === accent &&
  20628. this.width === width &&
  20629. this.vmetric === vmetric &&
  20630. this.operatorListId === operatorListId;
  20631. };
  20632. return Glyph;
  20633. })();
  20634. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20635. function ToUnicodeMap(cmap) {
  20636. // The elements of this._map can be integers or strings, depending on how
  20637. // |cmap| was created.
  20638. this._map = cmap;
  20639. }
  20640. ToUnicodeMap.prototype = {
  20641. get length() {
  20642. return this._map.length;
  20643. },
  20644. forEach: function(callback) {
  20645. for (var charCode in this._map) {
  20646. callback(charCode, this._map[charCode].charCodeAt(0));
  20647. }
  20648. },
  20649. has: function(i) {
  20650. return this._map[i] !== undefined;
  20651. },
  20652. get: function(i) {
  20653. return this._map[i];
  20654. },
  20655. charCodeOf: function(v) {
  20656. return this._map.indexOf(v);
  20657. }
  20658. };
  20659. return ToUnicodeMap;
  20660. })();
  20661. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20662. function IdentityToUnicodeMap(firstChar, lastChar) {
  20663. this.firstChar = firstChar;
  20664. this.lastChar = lastChar;
  20665. }
  20666. IdentityToUnicodeMap.prototype = {
  20667. get length() {
  20668. return (this.lastChar + 1) - this.firstChar;
  20669. },
  20670. forEach: function (callback) {
  20671. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20672. callback(i, i);
  20673. }
  20674. },
  20675. has: function (i) {
  20676. return this.firstChar <= i && i <= this.lastChar;
  20677. },
  20678. get: function (i) {
  20679. if (this.firstChar <= i && i <= this.lastChar) {
  20680. return String.fromCharCode(i);
  20681. }
  20682. return undefined;
  20683. },
  20684. charCodeOf: function (v) {
  20685. error('should not call .charCodeOf');
  20686. }
  20687. };
  20688. return IdentityToUnicodeMap;
  20689. })();
  20690. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20691. function writeInt16(dest, offset, num) {
  20692. dest[offset] = (num >> 8) & 0xFF;
  20693. dest[offset + 1] = num & 0xFF;
  20694. }
  20695. function writeInt32(dest, offset, num) {
  20696. dest[offset] = (num >> 24) & 0xFF;
  20697. dest[offset + 1] = (num >> 16) & 0xFF;
  20698. dest[offset + 2] = (num >> 8) & 0xFF;
  20699. dest[offset + 3] = num & 0xFF;
  20700. }
  20701. function writeData(dest, offset, data) {
  20702. var i, ii;
  20703. if (data instanceof Uint8Array) {
  20704. dest.set(data, offset);
  20705. } else if (typeof data === 'string') {
  20706. for (i = 0, ii = data.length; i < ii; i++) {
  20707. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20708. }
  20709. } else {
  20710. // treating everything else as array
  20711. for (i = 0, ii = data.length; i < ii; i++) {
  20712. dest[offset++] = data[i] & 0xFF;
  20713. }
  20714. }
  20715. }
  20716. function OpenTypeFileBuilder(sfnt) {
  20717. this.sfnt = sfnt;
  20718. this.tables = Object.create(null);
  20719. }
  20720. OpenTypeFileBuilder.getSearchParams =
  20721. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20722. var maxPower2 = 1, log2 = 0;
  20723. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20724. maxPower2 <<= 1;
  20725. log2++;
  20726. }
  20727. var searchRange = maxPower2 * entrySize;
  20728. return {
  20729. range: searchRange,
  20730. entry: log2,
  20731. rangeShift: entrySize * entriesCount - searchRange
  20732. };
  20733. };
  20734. var OTF_HEADER_SIZE = 12;
  20735. var OTF_TABLE_ENTRY_SIZE = 16;
  20736. OpenTypeFileBuilder.prototype = {
  20737. toArray: function OpenTypeFileBuilder_toArray() {
  20738. var sfnt = this.sfnt;
  20739. // Tables needs to be written by ascendant alphabetic order
  20740. var tables = this.tables;
  20741. var tablesNames = Object.keys(tables);
  20742. tablesNames.sort();
  20743. var numTables = tablesNames.length;
  20744. var i, j, jj, table, tableName;
  20745. // layout the tables data
  20746. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20747. var tableOffsets = [offset];
  20748. for (i = 0; i < numTables; i++) {
  20749. table = tables[tablesNames[i]];
  20750. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20751. offset += paddedLength;
  20752. tableOffsets.push(offset);
  20753. }
  20754. var file = new Uint8Array(offset);
  20755. // write the table data first (mostly for checksum)
  20756. for (i = 0; i < numTables; i++) {
  20757. table = tables[tablesNames[i]];
  20758. writeData(file, tableOffsets[i], table);
  20759. }
  20760. // sfnt version (4 bytes)
  20761. if (sfnt === 'true') {
  20762. // Windows hates the Mac TrueType sfnt version number
  20763. sfnt = string32(0x00010000);
  20764. }
  20765. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20766. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20767. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20768. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20769. // numTables (2 bytes)
  20770. writeInt16(file, 4, numTables);
  20771. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20772. // searchRange (2 bytes)
  20773. writeInt16(file, 6, searchParams.range);
  20774. // entrySelector (2 bytes)
  20775. writeInt16(file, 8, searchParams.entry);
  20776. // rangeShift (2 bytes)
  20777. writeInt16(file, 10, searchParams.rangeShift);
  20778. offset = OTF_HEADER_SIZE;
  20779. // writing table entries
  20780. for (i = 0; i < numTables; i++) {
  20781. tableName = tablesNames[i];
  20782. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20783. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20784. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20785. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20786. // checksum
  20787. var checksum = 0;
  20788. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20789. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20790. (file[j + 2] << 8) + file[j + 3];
  20791. checksum = (checksum + quad) | 0;
  20792. }
  20793. writeInt32(file, offset + 4, checksum);
  20794. // offset
  20795. writeInt32(file, offset + 8, tableOffsets[i]);
  20796. // length
  20797. writeInt32(file, offset + 12, tables[tableName].length);
  20798. offset += OTF_TABLE_ENTRY_SIZE;
  20799. }
  20800. return file;
  20801. },
  20802. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20803. if (tag in this.tables) {
  20804. throw new Error('Table ' + tag + ' already exists');
  20805. }
  20806. this.tables[tag] = data;
  20807. }
  20808. };
  20809. return OpenTypeFileBuilder;
  20810. })();
  20811. /**
  20812. * 'Font' is the class the outside world should use, it encapsulate all the font
  20813. * decoding logics whatever type it is (assuming the font type is supported).
  20814. *
  20815. * For example to read a Type1 font and to attach it to the document:
  20816. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20817. * type1Font.bind();
  20818. */
  20819. var Font = (function FontClosure() {
  20820. function Font(name, file, properties) {
  20821. var charCode, glyphName, fontChar;
  20822. this.name = name;
  20823. this.loadedName = properties.loadedName;
  20824. this.isType3Font = properties.isType3Font;
  20825. this.sizes = [];
  20826. this.glyphCache = {};
  20827. var names = name.split('+');
  20828. names = names.length > 1 ? names[1] : names[0];
  20829. names = names.split(/[-,_]/g)[0];
  20830. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20831. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20832. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20833. var type = properties.type;
  20834. var subtype = properties.subtype;
  20835. this.type = type;
  20836. this.fallbackName = (this.isMonospace ? 'monospace' :
  20837. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20838. this.differences = properties.differences;
  20839. this.widths = properties.widths;
  20840. this.defaultWidth = properties.defaultWidth;
  20841. this.composite = properties.composite;
  20842. this.wideChars = properties.wideChars;
  20843. this.cMap = properties.cMap;
  20844. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20845. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20846. this.fontMatrix = properties.fontMatrix;
  20847. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20848. this.toFontChar = [];
  20849. if (properties.type === 'Type3') {
  20850. for (charCode = 0; charCode < 256; charCode++) {
  20851. this.toFontChar[charCode] = (this.differences[charCode] ||
  20852. properties.defaultEncoding[charCode]);
  20853. }
  20854. this.fontType = FontType.TYPE3;
  20855. return;
  20856. }
  20857. this.cidEncoding = properties.cidEncoding;
  20858. this.vertical = properties.vertical;
  20859. if (this.vertical) {
  20860. this.vmetrics = properties.vmetrics;
  20861. this.defaultVMetrics = properties.defaultVMetrics;
  20862. }
  20863. if (!file || file.isEmpty) {
  20864. if (file) {
  20865. // Some bad PDF generators will include empty font files,
  20866. // attempting to recover by assuming that no file exists.
  20867. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20868. }
  20869. this.missingFile = true;
  20870. // The file data is not specified. Trying to fix the font name
  20871. // to be used with the canvas.font.
  20872. var fontName = name.replace(/[,_]/g, '-');
  20873. var isStandardFont = !!stdFontMap[fontName] ||
  20874. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  20875. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20876. this.bold = (fontName.search(/bold/gi) !== -1);
  20877. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20878. (fontName.search(/italic/gi) !== -1));
  20879. // Use 'name' instead of 'fontName' here because the original
  20880. // name ArialBlack for example will be replaced by Helvetica.
  20881. this.black = (name.search(/Black/g) !== -1);
  20882. // if at least one width is present, remeasure all chars when exists
  20883. this.remeasure = Object.keys(this.widths).length > 0;
  20884. if (isStandardFont && type === 'CIDFontType2' &&
  20885. properties.cidEncoding.indexOf('Identity-') === 0) {
  20886. // Standard fonts might be embedded as CID font without glyph mapping.
  20887. // Building one based on GlyphMapForStandardFonts.
  20888. var map = [];
  20889. for (var code in GlyphMapForStandardFonts) {
  20890. map[+code] = GlyphMapForStandardFonts[code];
  20891. }
  20892. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  20893. if (!isIdentityUnicode) {
  20894. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20895. map[+charCode] = unicodeCharCode;
  20896. });
  20897. }
  20898. this.toFontChar = map;
  20899. this.toUnicode = new ToUnicodeMap(map);
  20900. } else if (/Symbol/i.test(fontName)) {
  20901. var symbols = Encodings.SymbolSetEncoding;
  20902. for (charCode in symbols) {
  20903. fontChar = GlyphsUnicode[symbols[charCode]];
  20904. if (!fontChar) {
  20905. continue;
  20906. }
  20907. this.toFontChar[charCode] = fontChar;
  20908. }
  20909. for (charCode in properties.differences) {
  20910. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20911. if (!fontChar) {
  20912. continue;
  20913. }
  20914. this.toFontChar[charCode] = fontChar;
  20915. }
  20916. } else if (/Dingbats/i.test(fontName)) {
  20917. if (/Wingdings/i.test(name)) {
  20918. warn('Wingdings font without embedded font file, ' +
  20919. 'falling back to the ZapfDingbats encoding.');
  20920. }
  20921. var dingbats = Encodings.ZapfDingbatsEncoding;
  20922. for (charCode in dingbats) {
  20923. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20924. if (!fontChar) {
  20925. continue;
  20926. }
  20927. this.toFontChar[charCode] = fontChar;
  20928. }
  20929. for (charCode in properties.differences) {
  20930. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20931. if (!fontChar) {
  20932. continue;
  20933. }
  20934. this.toFontChar[charCode] = fontChar;
  20935. }
  20936. } else if (isStandardFont) {
  20937. this.toFontChar = [];
  20938. for (charCode in properties.defaultEncoding) {
  20939. glyphName = (properties.differences[charCode] ||
  20940. properties.defaultEncoding[charCode]);
  20941. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20942. }
  20943. } else {
  20944. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20945. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20946. if (notCidFont) {
  20947. glyphName = (properties.differences[charCode] ||
  20948. properties.defaultEncoding[charCode]);
  20949. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20950. }
  20951. this.toFontChar[charCode] = unicodeCharCode;
  20952. }.bind(this));
  20953. }
  20954. this.loadedName = fontName.split('-')[0];
  20955. this.loading = false;
  20956. this.fontType = getFontType(type, subtype);
  20957. return;
  20958. }
  20959. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20960. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20961. // Some TrueType fonts by mistake claim Type1C
  20962. if (isTrueTypeFile(file)) {
  20963. subtype = 'TrueType';
  20964. } else {
  20965. type = 'Type1';
  20966. }
  20967. }
  20968. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20969. type = 'CIDFontType0';
  20970. }
  20971. if (subtype === 'OpenType') {
  20972. type = 'OpenType';
  20973. }
  20974. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  20975. if (type === 'CIDFontType0') {
  20976. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  20977. }
  20978. var data;
  20979. switch (type) {
  20980. case 'MMType1':
  20981. info('MMType1 font (' + name + '), falling back to Type1.');
  20982. /* falls through */
  20983. case 'Type1':
  20984. case 'CIDFontType0':
  20985. this.mimetype = 'font/opentype';
  20986. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20987. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20988. adjustWidths(properties);
  20989. // Wrap the CFF data inside an OTF font file
  20990. data = this.convert(name, cff, properties);
  20991. break;
  20992. case 'OpenType':
  20993. case 'TrueType':
  20994. case 'CIDFontType2':
  20995. this.mimetype = 'font/opentype';
  20996. // Repair the TrueType file. It is can be damaged in the point of
  20997. // view of the sanitizer
  20998. data = this.checkAndRepair(name, file, properties);
  20999. if (this.isOpenType) {
  21000. type = 'OpenType';
  21001. }
  21002. break;
  21003. default:
  21004. error('Font ' + type + ' is not supported');
  21005. break;
  21006. }
  21007. this.data = data;
  21008. this.fontType = getFontType(type, subtype);
  21009. // Transfer some properties again that could change during font conversion
  21010. this.fontMatrix = properties.fontMatrix;
  21011. this.widths = properties.widths;
  21012. this.defaultWidth = properties.defaultWidth;
  21013. this.encoding = properties.baseEncoding;
  21014. this.seacMap = properties.seacMap;
  21015. this.loading = true;
  21016. }
  21017. Font.getFontID = (function () {
  21018. var ID = 1;
  21019. return function Font_getFontID() {
  21020. return String(ID++);
  21021. };
  21022. })();
  21023. function int16(b0, b1) {
  21024. return (b0 << 8) + b1;
  21025. }
  21026. function int32(b0, b1, b2, b3) {
  21027. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21028. }
  21029. function string16(value) {
  21030. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  21031. }
  21032. function safeString16(value) {
  21033. // clamp value to the 16-bit int range
  21034. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  21035. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  21036. }
  21037. function isTrueTypeFile(file) {
  21038. var header = file.peekBytes(4);
  21039. return readUint32(header, 0) === 0x00010000;
  21040. }
  21041. function isType1File(file) {
  21042. var header = file.peekBytes(2);
  21043. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  21044. if (header[0] === 0x25 && header[1] === 0x21) {
  21045. return true;
  21046. }
  21047. // ... obviously some fonts violate that part of the specification,
  21048. // please refer to the comment in |Type1Font| below.
  21049. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  21050. return true;
  21051. }
  21052. return false;
  21053. }
  21054. /**
  21055. * Helper function for |adjustMapping|.
  21056. * @return {boolean}
  21057. */
  21058. function isProblematicUnicodeLocation(code) {
  21059. if (code <= 0x1F) { // Control chars
  21060. return true;
  21061. }
  21062. if (code >= 0x80 && code <= 0x9F) { // Control chars
  21063. return true;
  21064. }
  21065. if ((code >= 0x2000 && code <= 0x200F) || // General punctuation chars
  21066. (code >= 0x2028 && code <= 0x202F) ||
  21067. (code >= 0x2060 && code <= 0x206F)) {
  21068. return true;
  21069. }
  21070. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials Unicode block
  21071. return true;
  21072. }
  21073. switch (code) {
  21074. case 0x7F: // Control char
  21075. case 0xA0: // Non breaking space
  21076. case 0xAD: // Soft hyphen
  21077. case 0x0E33: // Thai character SARA AM
  21078. case 0x2011: // Non breaking hyphen
  21079. case 0x205F: // Medium mathematical space
  21080. case 0x25CC: // Dotted circle (combining mark)
  21081. return true;
  21082. }
  21083. return false;
  21084. }
  21085. /**
  21086. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  21087. * with their unicode value. It also moves char codes that are in known
  21088. * problematic locations.
  21089. * @return {Object} Two properties:
  21090. * 'toFontChar' - maps original char codes(the value that will be read
  21091. * from commands such as show text) to the char codes that will be used in the
  21092. * font that we build
  21093. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  21094. */
  21095. function adjustMapping(charCodeToGlyphId, properties) {
  21096. var toUnicode = properties.toUnicode;
  21097. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  21098. var isIdentityUnicode =
  21099. properties.toUnicode instanceof IdentityToUnicodeMap;
  21100. var newMap = Object.create(null);
  21101. var toFontChar = [];
  21102. var usedFontCharCodes = [];
  21103. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  21104. for (var originalCharCode in charCodeToGlyphId) {
  21105. originalCharCode |= 0;
  21106. var glyphId = charCodeToGlyphId[originalCharCode];
  21107. var fontCharCode = originalCharCode;
  21108. // First try to map the value to a unicode position if a non identity map
  21109. // was created.
  21110. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  21111. var unicode = toUnicode.get(fontCharCode);
  21112. // TODO: Try to map ligatures to the correct spot.
  21113. if (unicode.length === 1) {
  21114. fontCharCode = unicode.charCodeAt(0);
  21115. }
  21116. }
  21117. // Try to move control characters, special characters and already mapped
  21118. // characters to the private use area since they will not be drawn by
  21119. // canvas if left in their current position. Also, move characters if the
  21120. // font was symbolic and there is only an identity unicode map since the
  21121. // characters probably aren't in the correct position (fixes an issue
  21122. // with firefox and thuluthfont).
  21123. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  21124. isProblematicUnicodeLocation(fontCharCode) ||
  21125. (isSymbolic && isIdentityUnicode)) &&
  21126. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  21127. // Loop to try and find a free spot in the private use area.
  21128. do {
  21129. fontCharCode = nextAvailableFontCharCode++;
  21130. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  21131. fontCharCode = 0xF020;
  21132. nextAvailableFontCharCode = fontCharCode + 1;
  21133. }
  21134. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  21135. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  21136. }
  21137. newMap[fontCharCode] = glyphId;
  21138. toFontChar[originalCharCode] = fontCharCode;
  21139. usedFontCharCodes[fontCharCode] = true;
  21140. }
  21141. return {
  21142. toFontChar: toFontChar,
  21143. charCodeToGlyphId: newMap,
  21144. nextAvailableFontCharCode: nextAvailableFontCharCode
  21145. };
  21146. }
  21147. function getRanges(glyphs) {
  21148. // Array.sort() sorts by characters, not numerically, so convert to an
  21149. // array of characters.
  21150. var codes = [];
  21151. for (var charCode in glyphs) {
  21152. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  21153. }
  21154. codes.sort(function fontGetRangesSort(a, b) {
  21155. return a.fontCharCode - b.fontCharCode;
  21156. });
  21157. // Split the sorted codes into ranges.
  21158. var ranges = [];
  21159. var length = codes.length;
  21160. for (var n = 0; n < length; ) {
  21161. var start = codes[n].fontCharCode;
  21162. var codeIndices = [codes[n].glyphId];
  21163. ++n;
  21164. var end = start;
  21165. while (n < length && end + 1 === codes[n].fontCharCode) {
  21166. codeIndices.push(codes[n].glyphId);
  21167. ++end;
  21168. ++n;
  21169. if (end === 0xFFFF) {
  21170. break;
  21171. }
  21172. }
  21173. ranges.push([start, end, codeIndices]);
  21174. }
  21175. return ranges;
  21176. }
  21177. function createCmapTable(glyphs) {
  21178. var ranges = getRanges(glyphs);
  21179. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  21180. var cmap = '\x00\x00' + // version
  21181. string16(numTables) + // numTables
  21182. '\x00\x03' + // platformID
  21183. '\x00\x01' + // encodingID
  21184. string32(4 + numTables * 8); // start of the table record
  21185. var i, ii, j, jj;
  21186. for (i = ranges.length - 1; i >= 0; --i) {
  21187. if (ranges[i][0] <= 0xFFFF) { break; }
  21188. }
  21189. var bmpLength = i + 1;
  21190. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  21191. ranges[i][1] = 0xFFFE;
  21192. }
  21193. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  21194. var segCount = bmpLength + trailingRangesCount;
  21195. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  21196. // Fill up the 4 parallel arrays describing the segments.
  21197. var startCount = '';
  21198. var endCount = '';
  21199. var idDeltas = '';
  21200. var idRangeOffsets = '';
  21201. var glyphsIds = '';
  21202. var bias = 0;
  21203. var range, start, end, codes;
  21204. for (i = 0, ii = bmpLength; i < ii; i++) {
  21205. range = ranges[i];
  21206. start = range[0];
  21207. end = range[1];
  21208. startCount += string16(start);
  21209. endCount += string16(end);
  21210. codes = range[2];
  21211. var contiguous = true;
  21212. for (j = 1, jj = codes.length; j < jj; ++j) {
  21213. if (codes[j] !== codes[j - 1] + 1) {
  21214. contiguous = false;
  21215. break;
  21216. }
  21217. }
  21218. if (!contiguous) {
  21219. var offset = (segCount - i) * 2 + bias * 2;
  21220. bias += (end - start + 1);
  21221. idDeltas += string16(0);
  21222. idRangeOffsets += string16(offset);
  21223. for (j = 0, jj = codes.length; j < jj; ++j) {
  21224. glyphsIds += string16(codes[j]);
  21225. }
  21226. } else {
  21227. var startCode = codes[0];
  21228. idDeltas += string16((startCode - start) & 0xFFFF);
  21229. idRangeOffsets += string16(0);
  21230. }
  21231. }
  21232. if (trailingRangesCount > 0) {
  21233. endCount += '\xFF\xFF';
  21234. startCount += '\xFF\xFF';
  21235. idDeltas += '\x00\x01';
  21236. idRangeOffsets += '\x00\x00';
  21237. }
  21238. var format314 = '\x00\x00' + // language
  21239. string16(2 * segCount) +
  21240. string16(searchParams.range) +
  21241. string16(searchParams.entry) +
  21242. string16(searchParams.rangeShift) +
  21243. endCount + '\x00\x00' + startCount +
  21244. idDeltas + idRangeOffsets + glyphsIds;
  21245. var format31012 = '';
  21246. var header31012 = '';
  21247. if (numTables > 1) {
  21248. cmap += '\x00\x03' + // platformID
  21249. '\x00\x0A' + // encodingID
  21250. string32(4 + numTables * 8 +
  21251. 4 + format314.length); // start of the table record
  21252. format31012 = '';
  21253. for (i = 0, ii = ranges.length; i < ii; i++) {
  21254. range = ranges[i];
  21255. start = range[0];
  21256. codes = range[2];
  21257. var code = codes[0];
  21258. for (j = 1, jj = codes.length; j < jj; ++j) {
  21259. if (codes[j] !== codes[j - 1] + 1) {
  21260. end = range[0] + j - 1;
  21261. format31012 += string32(start) + // startCharCode
  21262. string32(end) + // endCharCode
  21263. string32(code); // startGlyphID
  21264. start = end + 1;
  21265. code = codes[j];
  21266. }
  21267. }
  21268. format31012 += string32(start) + // startCharCode
  21269. string32(range[1]) + // endCharCode
  21270. string32(code); // startGlyphID
  21271. }
  21272. header31012 = '\x00\x0C' + // format
  21273. '\x00\x00' + // reserved
  21274. string32(format31012.length + 16) + // length
  21275. '\x00\x00\x00\x00' + // language
  21276. string32(format31012.length / 12); // nGroups
  21277. }
  21278. return cmap + '\x00\x04' + // format
  21279. string16(format314.length + 4) + // length
  21280. format314 + header31012 + format31012;
  21281. }
  21282. function validateOS2Table(os2) {
  21283. var stream = new Stream(os2.data);
  21284. var version = stream.getUint16();
  21285. // TODO verify all OS/2 tables fields, but currently we validate only those
  21286. // that give us issues
  21287. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  21288. var selection = stream.getUint16();
  21289. if (version < 4 && (selection & 0x0300)) {
  21290. return false;
  21291. }
  21292. var firstChar = stream.getUint16();
  21293. var lastChar = stream.getUint16();
  21294. if (firstChar > lastChar) {
  21295. return false;
  21296. }
  21297. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  21298. var usWinAscent = stream.getUint16();
  21299. if (usWinAscent === 0) { // makes font unreadable by windows
  21300. return false;
  21301. }
  21302. // OS/2 appears to be valid, resetting some fields
  21303. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  21304. return true;
  21305. }
  21306. function createOS2Table(properties, charstrings, override) {
  21307. override = override || {
  21308. unitsPerEm: 0,
  21309. yMax: 0,
  21310. yMin: 0,
  21311. ascent: 0,
  21312. descent: 0
  21313. };
  21314. var ulUnicodeRange1 = 0;
  21315. var ulUnicodeRange2 = 0;
  21316. var ulUnicodeRange3 = 0;
  21317. var ulUnicodeRange4 = 0;
  21318. var firstCharIndex = null;
  21319. var lastCharIndex = 0;
  21320. if (charstrings) {
  21321. for (var code in charstrings) {
  21322. code |= 0;
  21323. if (firstCharIndex > code || !firstCharIndex) {
  21324. firstCharIndex = code;
  21325. }
  21326. if (lastCharIndex < code) {
  21327. lastCharIndex = code;
  21328. }
  21329. var position = getUnicodeRangeFor(code);
  21330. if (position < 32) {
  21331. ulUnicodeRange1 |= 1 << position;
  21332. } else if (position < 64) {
  21333. ulUnicodeRange2 |= 1 << position - 32;
  21334. } else if (position < 96) {
  21335. ulUnicodeRange3 |= 1 << position - 64;
  21336. } else if (position < 123) {
  21337. ulUnicodeRange4 |= 1 << position - 96;
  21338. } else {
  21339. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21340. }
  21341. }
  21342. } else {
  21343. // TODO
  21344. firstCharIndex = 0;
  21345. lastCharIndex = 255;
  21346. }
  21347. var bbox = properties.bbox || [0, 0, 0, 0];
  21348. var unitsPerEm = (override.unitsPerEm ||
  21349. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21350. // if the font units differ to the PDF glyph space units
  21351. // then scale up the values
  21352. var scale = (properties.ascentScaled ? 1.0 :
  21353. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21354. var typoAscent = (override.ascent ||
  21355. Math.round(scale * (properties.ascent || bbox[3])));
  21356. var typoDescent = (override.descent ||
  21357. Math.round(scale * (properties.descent || bbox[1])));
  21358. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21359. typoDescent = -typoDescent; // fixing incorrect descent
  21360. }
  21361. var winAscent = override.yMax || typoAscent;
  21362. var winDescent = -override.yMin || -typoDescent;
  21363. return '\x00\x03' + // version
  21364. '\x02\x24' + // xAvgCharWidth
  21365. '\x01\xF4' + // usWeightClass
  21366. '\x00\x05' + // usWidthClass
  21367. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21368. '\x02\x8A' + // ySubscriptXSize
  21369. '\x02\xBB' + // ySubscriptYSize
  21370. '\x00\x00' + // ySubscriptXOffset
  21371. '\x00\x8C' + // ySubscriptYOffset
  21372. '\x02\x8A' + // ySuperScriptXSize
  21373. '\x02\xBB' + // ySuperScriptYSize
  21374. '\x00\x00' + // ySuperScriptXOffset
  21375. '\x01\xDF' + // ySuperScriptYOffset
  21376. '\x00\x31' + // yStrikeOutSize
  21377. '\x01\x02' + // yStrikeOutPosition
  21378. '\x00\x00' + // sFamilyClass
  21379. '\x00\x00\x06' +
  21380. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21381. '\x00\x00\x00\x00\x00\x00' + // Panose
  21382. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21383. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21384. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21385. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21386. '\x2A\x32\x31\x2A' + // achVendID
  21387. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21388. string16(firstCharIndex ||
  21389. properties.firstChar) + // usFirstCharIndex
  21390. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21391. string16(typoAscent) + // sTypoAscender
  21392. string16(typoDescent) + // sTypoDescender
  21393. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21394. string16(winAscent) + // usWinAscent
  21395. string16(winDescent) + // usWinDescent
  21396. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21397. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21398. string16(properties.xHeight) + // sxHeight
  21399. string16(properties.capHeight) + // sCapHeight
  21400. string16(0) + // usDefaultChar
  21401. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21402. '\x00\x03'; // usMaxContext
  21403. }
  21404. function createPostTable(properties) {
  21405. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21406. return ('\x00\x03\x00\x00' + // Version number
  21407. string32(angle) + // italicAngle
  21408. '\x00\x00' + // underlinePosition
  21409. '\x00\x00' + // underlineThickness
  21410. string32(properties.fixedPitch) + // isFixedPitch
  21411. '\x00\x00\x00\x00' + // minMemType42
  21412. '\x00\x00\x00\x00' + // maxMemType42
  21413. '\x00\x00\x00\x00' + // minMemType1
  21414. '\x00\x00\x00\x00'); // maxMemType1
  21415. }
  21416. function createNameTable(name, proto) {
  21417. if (!proto) {
  21418. proto = [[], []]; // no strings and unicode strings
  21419. }
  21420. var strings = [
  21421. proto[0][0] || 'Original licence', // 0.Copyright
  21422. proto[0][1] || name, // 1.Font family
  21423. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21424. proto[0][3] || 'uniqueID', // 3.Unique ID
  21425. proto[0][4] || name, // 4.Full font name
  21426. proto[0][5] || 'Version 0.11', // 5.Version
  21427. proto[0][6] || '', // 6.Postscript name
  21428. proto[0][7] || 'Unknown', // 7.Trademark
  21429. proto[0][8] || 'Unknown', // 8.Manufacturer
  21430. proto[0][9] || 'Unknown' // 9.Designer
  21431. ];
  21432. // Mac want 1-byte per character strings while Windows want
  21433. // 2-bytes per character, so duplicate the names table
  21434. var stringsUnicode = [];
  21435. var i, ii, j, jj, str;
  21436. for (i = 0, ii = strings.length; i < ii; i++) {
  21437. str = proto[1][i] || strings[i];
  21438. var strBufUnicode = [];
  21439. for (j = 0, jj = str.length; j < jj; j++) {
  21440. strBufUnicode.push(string16(str.charCodeAt(j)));
  21441. }
  21442. stringsUnicode.push(strBufUnicode.join(''));
  21443. }
  21444. var names = [strings, stringsUnicode];
  21445. var platforms = ['\x00\x01', '\x00\x03'];
  21446. var encodings = ['\x00\x00', '\x00\x01'];
  21447. var languages = ['\x00\x00', '\x04\x09'];
  21448. var namesRecordCount = strings.length * platforms.length;
  21449. var nameTable =
  21450. '\x00\x00' + // format
  21451. string16(namesRecordCount) + // Number of names Record
  21452. string16(namesRecordCount * 12 + 6); // Storage
  21453. // Build the name records field
  21454. var strOffset = 0;
  21455. for (i = 0, ii = platforms.length; i < ii; i++) {
  21456. var strs = names[i];
  21457. for (j = 0, jj = strs.length; j < jj; j++) {
  21458. str = strs[j];
  21459. var nameRecord =
  21460. platforms[i] + // platform ID
  21461. encodings[i] + // encoding ID
  21462. languages[i] + // language ID
  21463. string16(j) + // name ID
  21464. string16(str.length) +
  21465. string16(strOffset);
  21466. nameTable += nameRecord;
  21467. strOffset += str.length;
  21468. }
  21469. }
  21470. nameTable += strings.join('') + stringsUnicode.join('');
  21471. return nameTable;
  21472. }
  21473. Font.prototype = {
  21474. name: null,
  21475. font: null,
  21476. mimetype: null,
  21477. encoding: null,
  21478. get renderer() {
  21479. var renderer = FontRendererFactory.create(this);
  21480. return shadow(this, 'renderer', renderer);
  21481. },
  21482. exportData: function Font_exportData() {
  21483. var data = {};
  21484. for (var i in this) {
  21485. if (this.hasOwnProperty(i)) {
  21486. data[i] = this[i];
  21487. }
  21488. }
  21489. return data;
  21490. },
  21491. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21492. function readTableEntry(file) {
  21493. var tag = bytesToString(file.getBytes(4));
  21494. var checksum = file.getInt32();
  21495. var offset = file.getInt32() >>> 0;
  21496. var length = file.getInt32() >>> 0;
  21497. // Read the table associated data
  21498. var previousPosition = file.pos;
  21499. file.pos = file.start ? file.start : 0;
  21500. file.skip(offset);
  21501. var data = file.getBytes(length);
  21502. file.pos = previousPosition;
  21503. if (tag === 'head') {
  21504. // clearing checksum adjustment
  21505. data[8] = data[9] = data[10] = data[11] = 0;
  21506. data[17] |= 0x20; //Set font optimized for cleartype flag
  21507. }
  21508. return {
  21509. tag: tag,
  21510. checksum: checksum,
  21511. length: length,
  21512. offset: offset,
  21513. data: data
  21514. };
  21515. }
  21516. function readOpenTypeHeader(ttf) {
  21517. return {
  21518. version: bytesToString(ttf.getBytes(4)),
  21519. numTables: ttf.getUint16(),
  21520. searchRange: ttf.getUint16(),
  21521. entrySelector: ttf.getUint16(),
  21522. rangeShift: ttf.getUint16()
  21523. };
  21524. }
  21525. /**
  21526. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21527. * PDF spec
  21528. */
  21529. function readCmapTable(cmap, font, isSymbolicFont) {
  21530. var segment;
  21531. var start = (font.start ? font.start : 0) + cmap.offset;
  21532. font.pos = start;
  21533. var version = font.getUint16();
  21534. var numTables = font.getUint16();
  21535. var potentialTable;
  21536. var canBreak = false;
  21537. // There's an order of preference in terms of which cmap subtable to
  21538. // use:
  21539. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21540. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21541. // The following takes advantage of the fact that the tables are sorted
  21542. // to work.
  21543. for (var i = 0; i < numTables; i++) {
  21544. var platformId = font.getUint16();
  21545. var encodingId = font.getUint16();
  21546. var offset = font.getInt32() >>> 0;
  21547. var useTable = false;
  21548. if (platformId === 0 && encodingId === 0) {
  21549. useTable = true;
  21550. // Continue the loop since there still may be a higher priority
  21551. // table.
  21552. } else if (platformId === 1 && encodingId === 0) {
  21553. useTable = true;
  21554. // Continue the loop since there still may be a higher priority
  21555. // table.
  21556. } else if (platformId === 3 && encodingId === 1 &&
  21557. (!isSymbolicFont || !potentialTable)) {
  21558. useTable = true;
  21559. if (!isSymbolicFont) {
  21560. canBreak = true;
  21561. }
  21562. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21563. useTable = true;
  21564. canBreak = true;
  21565. }
  21566. if (useTable) {
  21567. potentialTable = {
  21568. platformId: platformId,
  21569. encodingId: encodingId,
  21570. offset: offset
  21571. };
  21572. }
  21573. if (canBreak) {
  21574. break;
  21575. }
  21576. }
  21577. if (!potentialTable) {
  21578. warn('Could not find a preferred cmap table.');
  21579. return {
  21580. platformId: -1,
  21581. encodingId: -1,
  21582. mappings: [],
  21583. hasShortCmap: false
  21584. };
  21585. }
  21586. font.pos = start + potentialTable.offset;
  21587. var format = font.getUint16();
  21588. var length = font.getUint16();
  21589. var language = font.getUint16();
  21590. var hasShortCmap = false;
  21591. var mappings = [];
  21592. var j, glyphId;
  21593. // TODO(mack): refactor this cmap subtable reading logic out
  21594. if (format === 0) {
  21595. for (j = 0; j < 256; j++) {
  21596. var index = font.getByte();
  21597. if (!index) {
  21598. continue;
  21599. }
  21600. mappings.push({
  21601. charCode: j,
  21602. glyphId: index
  21603. });
  21604. }
  21605. hasShortCmap = true;
  21606. } else if (format === 4) {
  21607. // re-creating the table in format 4 since the encoding
  21608. // might be changed
  21609. var segCount = (font.getUint16() >> 1);
  21610. font.getBytes(6); // skipping range fields
  21611. var segIndex, segments = [];
  21612. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21613. segments.push({ end: font.getUint16() });
  21614. }
  21615. font.getUint16();
  21616. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21617. segments[segIndex].start = font.getUint16();
  21618. }
  21619. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21620. segments[segIndex].delta = font.getUint16();
  21621. }
  21622. var offsetsCount = 0;
  21623. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21624. segment = segments[segIndex];
  21625. var rangeOffset = font.getUint16();
  21626. if (!rangeOffset) {
  21627. segment.offsetIndex = -1;
  21628. continue;
  21629. }
  21630. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21631. segment.offsetIndex = offsetIndex;
  21632. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21633. segment.end - segment.start + 1);
  21634. }
  21635. var offsets = [];
  21636. for (j = 0; j < offsetsCount; j++) {
  21637. offsets.push(font.getUint16());
  21638. }
  21639. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21640. segment = segments[segIndex];
  21641. start = segment.start;
  21642. var end = segment.end;
  21643. var delta = segment.delta;
  21644. offsetIndex = segment.offsetIndex;
  21645. for (j = start; j <= end; j++) {
  21646. if (j === 0xFFFF) {
  21647. continue;
  21648. }
  21649. glyphId = (offsetIndex < 0 ?
  21650. j : offsets[offsetIndex + j - start]);
  21651. glyphId = (glyphId + delta) & 0xFFFF;
  21652. if (glyphId === 0) {
  21653. continue;
  21654. }
  21655. mappings.push({
  21656. charCode: j,
  21657. glyphId: glyphId
  21658. });
  21659. }
  21660. }
  21661. } else if (format === 6) {
  21662. // Format 6 is a 2-bytes dense mapping, which means the font data
  21663. // lives glue together even if they are pretty far in the unicode
  21664. // table. (This looks weird, so I can have missed something), this
  21665. // works on Linux but seems to fails on Mac so let's rewrite the
  21666. // cmap table to a 3-1-4 style
  21667. var firstCode = font.getUint16();
  21668. var entryCount = font.getUint16();
  21669. for (j = 0; j < entryCount; j++) {
  21670. glyphId = font.getUint16();
  21671. var charCode = firstCode + j;
  21672. mappings.push({
  21673. charCode: charCode,
  21674. glyphId: glyphId
  21675. });
  21676. }
  21677. } else {
  21678. error('cmap table has unsupported format: ' + format);
  21679. }
  21680. // removing duplicate entries
  21681. mappings.sort(function (a, b) {
  21682. return a.charCode - b.charCode;
  21683. });
  21684. for (i = 1; i < mappings.length; i++) {
  21685. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21686. mappings.splice(i, 1);
  21687. i--;
  21688. }
  21689. }
  21690. return {
  21691. platformId: potentialTable.platformId,
  21692. encodingId: potentialTable.encodingId,
  21693. mappings: mappings,
  21694. hasShortCmap: hasShortCmap
  21695. };
  21696. }
  21697. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21698. if (!header) {
  21699. if (metrics) {
  21700. metrics.data = null;
  21701. }
  21702. return;
  21703. }
  21704. font.pos = (font.start ? font.start : 0) + header.offset;
  21705. font.pos += header.length - 2;
  21706. var numOfMetrics = font.getUint16();
  21707. if (numOfMetrics > numGlyphs) {
  21708. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21709. 'greater than the numGlyphs (' + numGlyphs + ')');
  21710. // Reduce numOfMetrics if it is greater than numGlyphs
  21711. numOfMetrics = numGlyphs;
  21712. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21713. header.data[35] = numOfMetrics & 0x00ff;
  21714. }
  21715. var numOfSidebearings = numGlyphs - numOfMetrics;
  21716. var numMissing = numOfSidebearings -
  21717. ((metrics.length - numOfMetrics * 4) >> 1);
  21718. if (numMissing > 0) {
  21719. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21720. // Since we need to add two properties for each glyph, this explains
  21721. // the use of |numMissing * 2| when initializing the typed array.
  21722. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21723. entries.set(metrics.data);
  21724. metrics.data = entries;
  21725. }
  21726. }
  21727. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21728. hintsValid) {
  21729. if (sourceEnd - sourceStart <= 12) {
  21730. // glyph with data less than 12 is invalid one
  21731. return 0;
  21732. }
  21733. var glyf = source.subarray(sourceStart, sourceEnd);
  21734. var contoursCount = (glyf[0] << 8) | glyf[1];
  21735. if (contoursCount & 0x8000) {
  21736. // complex glyph, writing as is
  21737. dest.set(glyf, destStart);
  21738. return glyf.length;
  21739. }
  21740. var i, j = 10, flagsCount = 0;
  21741. for (i = 0; i < contoursCount; i++) {
  21742. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21743. flagsCount = endPoint + 1;
  21744. j += 2;
  21745. }
  21746. // skipping instructions
  21747. var instructionsStart = j;
  21748. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21749. j += 2 + instructionsLength;
  21750. var instructionsEnd = j;
  21751. // validating flags
  21752. var coordinatesLength = 0;
  21753. for (i = 0; i < flagsCount; i++) {
  21754. var flag = glyf[j++];
  21755. if (flag & 0xC0) {
  21756. // reserved flags must be zero, cleaning up
  21757. glyf[j - 1] = flag & 0x3F;
  21758. }
  21759. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21760. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21761. coordinatesLength += xyLength;
  21762. if (flag & 8) {
  21763. var repeat = glyf[j++];
  21764. i += repeat;
  21765. coordinatesLength += repeat * xyLength;
  21766. }
  21767. }
  21768. // glyph without coordinates will be rejected
  21769. if (coordinatesLength === 0) {
  21770. return 0;
  21771. }
  21772. var glyphDataLength = j + coordinatesLength;
  21773. if (glyphDataLength > glyf.length) {
  21774. // not enough data for coordinates
  21775. return 0;
  21776. }
  21777. if (!hintsValid && instructionsLength > 0) {
  21778. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21779. dest.set([0, 0], destStart + instructionsStart);
  21780. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21781. destStart + instructionsStart + 2);
  21782. glyphDataLength -= instructionsLength;
  21783. if (glyf.length - glyphDataLength > 3) {
  21784. glyphDataLength = (glyphDataLength + 3) & ~3;
  21785. }
  21786. return glyphDataLength;
  21787. }
  21788. if (glyf.length - glyphDataLength > 3) {
  21789. // truncating and aligning to 4 bytes the long glyph data
  21790. glyphDataLength = (glyphDataLength + 3) & ~3;
  21791. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21792. return glyphDataLength;
  21793. }
  21794. // glyph data is fine
  21795. dest.set(glyf, destStart);
  21796. return glyf.length;
  21797. }
  21798. function sanitizeHead(head, numGlyphs, locaLength) {
  21799. var data = head.data;
  21800. // Validate version:
  21801. // Should always be 0x00010000
  21802. var version = int32(data[0], data[1], data[2], data[3]);
  21803. if (version >> 16 !== 1) {
  21804. info('Attempting to fix invalid version in head table: ' + version);
  21805. data[0] = 0;
  21806. data[1] = 1;
  21807. data[2] = 0;
  21808. data[3] = 0;
  21809. }
  21810. var indexToLocFormat = int16(data[50], data[51]);
  21811. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21812. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21813. indexToLocFormat);
  21814. // The value of indexToLocFormat should be 0 if the loca table
  21815. // consists of short offsets, and should be 1 if the loca table
  21816. // consists of long offsets.
  21817. //
  21818. // The number of entries in the loca table should be numGlyphs + 1.
  21819. //
  21820. // Using this information, we can work backwards to deduce if the
  21821. // size of each offset in the loca table, and thus figure out the
  21822. // appropriate value for indexToLocFormat.
  21823. var numGlyphsPlusOne = numGlyphs + 1;
  21824. if (locaLength === numGlyphsPlusOne << 1) {
  21825. // 0x0000 indicates the loca table consists of short offsets
  21826. data[50] = 0;
  21827. data[51] = 0;
  21828. } else if (locaLength === numGlyphsPlusOne << 2) {
  21829. // 0x0001 indicates the loca table consists of long offsets
  21830. data[50] = 0;
  21831. data[51] = 1;
  21832. } else {
  21833. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21834. }
  21835. }
  21836. }
  21837. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21838. isGlyphLocationsLong, hintsValid,
  21839. dupFirstEntry) {
  21840. var itemSize, itemDecode, itemEncode;
  21841. if (isGlyphLocationsLong) {
  21842. itemSize = 4;
  21843. itemDecode = function fontItemDecodeLong(data, offset) {
  21844. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21845. (data[offset + 2] << 8) | data[offset + 3];
  21846. };
  21847. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21848. data[offset] = (value >>> 24) & 0xFF;
  21849. data[offset + 1] = (value >> 16) & 0xFF;
  21850. data[offset + 2] = (value >> 8) & 0xFF;
  21851. data[offset + 3] = value & 0xFF;
  21852. };
  21853. } else {
  21854. itemSize = 2;
  21855. itemDecode = function fontItemDecode(data, offset) {
  21856. return (data[offset] << 9) | (data[offset + 1] << 1);
  21857. };
  21858. itemEncode = function fontItemEncode(data, offset, value) {
  21859. data[offset] = (value >> 9) & 0xFF;
  21860. data[offset + 1] = (value >> 1) & 0xFF;
  21861. };
  21862. }
  21863. var locaData = loca.data;
  21864. var locaDataSize = itemSize * (1 + numGlyphs);
  21865. // is loca.data too short or long?
  21866. if (locaData.length !== locaDataSize) {
  21867. locaData = new Uint8Array(locaDataSize);
  21868. locaData.set(loca.data.subarray(0, locaDataSize));
  21869. loca.data = locaData;
  21870. }
  21871. // removing the invalid glyphs
  21872. var oldGlyfData = glyf.data;
  21873. var oldGlyfDataLength = oldGlyfData.length;
  21874. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21875. var startOffset = itemDecode(locaData, 0);
  21876. var writeOffset = 0;
  21877. var missingGlyphData = {};
  21878. itemEncode(locaData, 0, writeOffset);
  21879. var i, j;
  21880. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21881. var endOffset = itemDecode(locaData, j);
  21882. if (endOffset > oldGlyfDataLength &&
  21883. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21884. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21885. // the glyf table size, which makes last glyph out of range.
  21886. endOffset = oldGlyfDataLength;
  21887. }
  21888. if (endOffset > oldGlyfDataLength) {
  21889. // glyph end offset points outside glyf data, rejecting the glyph
  21890. itemEncode(locaData, j, writeOffset);
  21891. startOffset = endOffset;
  21892. continue;
  21893. }
  21894. if (startOffset === endOffset) {
  21895. missingGlyphData[i] = true;
  21896. }
  21897. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21898. newGlyfData, writeOffset, hintsValid);
  21899. writeOffset += newLength;
  21900. itemEncode(locaData, j, writeOffset);
  21901. startOffset = endOffset;
  21902. }
  21903. if (writeOffset === 0) {
  21904. // glyf table cannot be empty -- redoing the glyf and loca tables
  21905. // to have single glyph with one point
  21906. var simpleGlyph = new Uint8Array(
  21907. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21908. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21909. itemEncode(locaData, j, simpleGlyph.length);
  21910. }
  21911. glyf.data = simpleGlyph;
  21912. return missingGlyphData;
  21913. }
  21914. if (dupFirstEntry) {
  21915. var firstEntryLength = itemDecode(locaData, itemSize);
  21916. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21917. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21918. } else {
  21919. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21920. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21921. }
  21922. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21923. itemEncode(loca.data, locaData.length - itemSize,
  21924. writeOffset + firstEntryLength);
  21925. } else {
  21926. glyf.data = newGlyfData.subarray(0, writeOffset);
  21927. }
  21928. return missingGlyphData;
  21929. }
  21930. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21931. var start = (font.start ? font.start : 0) + post.offset;
  21932. font.pos = start;
  21933. var length = post.length, end = start + length;
  21934. var version = font.getInt32();
  21935. // skip rest to the tables
  21936. font.getBytes(28);
  21937. var glyphNames;
  21938. var valid = true;
  21939. var i;
  21940. switch (version) {
  21941. case 0x00010000:
  21942. glyphNames = MacStandardGlyphOrdering;
  21943. break;
  21944. case 0x00020000:
  21945. var numGlyphs = font.getUint16();
  21946. if (numGlyphs !== maxpNumGlyphs) {
  21947. valid = false;
  21948. break;
  21949. }
  21950. var glyphNameIndexes = [];
  21951. for (i = 0; i < numGlyphs; ++i) {
  21952. var index = font.getUint16();
  21953. if (index >= 32768) {
  21954. valid = false;
  21955. break;
  21956. }
  21957. glyphNameIndexes.push(index);
  21958. }
  21959. if (!valid) {
  21960. break;
  21961. }
  21962. var customNames = [];
  21963. var strBuf = [];
  21964. while (font.pos < end) {
  21965. var stringLength = font.getByte();
  21966. strBuf.length = stringLength;
  21967. for (i = 0; i < stringLength; ++i) {
  21968. strBuf[i] = String.fromCharCode(font.getByte());
  21969. }
  21970. customNames.push(strBuf.join(''));
  21971. }
  21972. glyphNames = [];
  21973. for (i = 0; i < numGlyphs; ++i) {
  21974. var j = glyphNameIndexes[i];
  21975. if (j < 258) {
  21976. glyphNames.push(MacStandardGlyphOrdering[j]);
  21977. continue;
  21978. }
  21979. glyphNames.push(customNames[j - 258]);
  21980. }
  21981. break;
  21982. case 0x00030000:
  21983. break;
  21984. default:
  21985. warn('Unknown/unsupported post table version ' + version);
  21986. valid = false;
  21987. break;
  21988. }
  21989. properties.glyphNames = glyphNames;
  21990. return valid;
  21991. }
  21992. function readNameTable(nameTable) {
  21993. var start = (font.start ? font.start : 0) + nameTable.offset;
  21994. font.pos = start;
  21995. var names = [[], []];
  21996. var length = nameTable.length, end = start + length;
  21997. var format = font.getUint16();
  21998. var FORMAT_0_HEADER_LENGTH = 6;
  21999. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  22000. // unsupported name table format or table "too" small
  22001. return names;
  22002. }
  22003. var numRecords = font.getUint16();
  22004. var stringsStart = font.getUint16();
  22005. var records = [];
  22006. var NAME_RECORD_LENGTH = 12;
  22007. var i, ii;
  22008. for (i = 0; i < numRecords &&
  22009. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  22010. var r = {
  22011. platform: font.getUint16(),
  22012. encoding: font.getUint16(),
  22013. language: font.getUint16(),
  22014. name: font.getUint16(),
  22015. length: font.getUint16(),
  22016. offset: font.getUint16()
  22017. };
  22018. // using only Macintosh and Windows platform/encoding names
  22019. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  22020. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  22021. records.push(r);
  22022. }
  22023. }
  22024. for (i = 0, ii = records.length; i < ii; i++) {
  22025. var record = records[i];
  22026. var pos = start + stringsStart + record.offset;
  22027. if (pos + record.length > end) {
  22028. continue; // outside of name table, ignoring
  22029. }
  22030. font.pos = pos;
  22031. var nameIndex = record.name;
  22032. if (record.encoding) {
  22033. // unicode
  22034. var str = '';
  22035. for (var j = 0, jj = record.length; j < jj; j += 2) {
  22036. str += String.fromCharCode(font.getUint16());
  22037. }
  22038. names[1][nameIndex] = str;
  22039. } else {
  22040. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  22041. }
  22042. }
  22043. return names;
  22044. }
  22045. var TTOpsStackDeltas = [
  22046. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  22047. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  22048. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  22049. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  22050. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  22051. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  22052. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22053. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  22054. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  22055. // 0xC0-DF == -1 and 0xE0-FF == -2
  22056. function sanitizeTTProgram(table, ttContext) {
  22057. var data = table.data;
  22058. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  22059. var stack = [];
  22060. var callstack = [];
  22061. var functionsCalled = [];
  22062. var tooComplexToFollowFunctions =
  22063. ttContext.tooComplexToFollowFunctions;
  22064. var inFDEF = false, ifLevel = 0, inELSE = 0;
  22065. for (var ii = data.length; i < ii;) {
  22066. var op = data[i++];
  22067. // The TrueType instruction set docs can be found at
  22068. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  22069. if (op === 0x40) { // NPUSHB - pushes n bytes
  22070. n = data[i++];
  22071. if (inFDEF || inELSE) {
  22072. i += n;
  22073. } else {
  22074. for (j = 0; j < n; j++) {
  22075. stack.push(data[i++]);
  22076. }
  22077. }
  22078. } else if (op === 0x41) { // NPUSHW - pushes n words
  22079. n = data[i++];
  22080. if (inFDEF || inELSE) {
  22081. i += n * 2;
  22082. } else {
  22083. for (j = 0; j < n; j++) {
  22084. b = data[i++];
  22085. stack.push((b << 8) | data[i++]);
  22086. }
  22087. }
  22088. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  22089. n = op - 0xB0 + 1;
  22090. if (inFDEF || inELSE) {
  22091. i += n;
  22092. } else {
  22093. for (j = 0; j < n; j++) {
  22094. stack.push(data[i++]);
  22095. }
  22096. }
  22097. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  22098. n = op - 0xB8 + 1;
  22099. if (inFDEF || inELSE) {
  22100. i += n * 2;
  22101. } else {
  22102. for (j = 0; j < n; j++) {
  22103. b = data[i++];
  22104. stack.push((b << 8) | data[i++]);
  22105. }
  22106. }
  22107. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  22108. if (!inFDEF && !inELSE) {
  22109. // collecting inforamtion about which functions are used
  22110. funcId = stack[stack.length - 1];
  22111. ttContext.functionsUsed[funcId] = true;
  22112. if (funcId in ttContext.functionsStackDeltas) {
  22113. stack.length += ttContext.functionsStackDeltas[funcId];
  22114. } else if (funcId in ttContext.functionsDefined &&
  22115. functionsCalled.indexOf(funcId) < 0) {
  22116. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  22117. functionsCalled.push(funcId);
  22118. pc = ttContext.functionsDefined[funcId];
  22119. if (!pc) {
  22120. warn('TT: CALL non-existent function');
  22121. ttContext.hintsValid = false;
  22122. return;
  22123. }
  22124. data = pc.data;
  22125. i = pc.i;
  22126. }
  22127. }
  22128. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  22129. if (inFDEF || inELSE) {
  22130. warn('TT: nested FDEFs not allowed');
  22131. tooComplexToFollowFunctions = true;
  22132. }
  22133. inFDEF = true;
  22134. // collecting inforamtion about which functions are defined
  22135. lastDeff = i;
  22136. funcId = stack.pop();
  22137. ttContext.functionsDefined[funcId] = {data: data, i: i};
  22138. } else if (op === 0x2D) { // ENDF - end of function
  22139. if (inFDEF) {
  22140. inFDEF = false;
  22141. lastEndf = i;
  22142. } else {
  22143. pc = callstack.pop();
  22144. if (!pc) {
  22145. warn('TT: ENDF bad stack');
  22146. ttContext.hintsValid = false;
  22147. return;
  22148. }
  22149. funcId = functionsCalled.pop();
  22150. data = pc.data;
  22151. i = pc.i;
  22152. ttContext.functionsStackDeltas[funcId] =
  22153. stack.length - pc.stackTop;
  22154. }
  22155. } else if (op === 0x89) { // IDEF - instruction definition
  22156. if (inFDEF || inELSE) {
  22157. warn('TT: nested IDEFs not allowed');
  22158. tooComplexToFollowFunctions = true;
  22159. }
  22160. inFDEF = true;
  22161. // recording it as a function to track ENDF
  22162. lastDeff = i;
  22163. } else if (op === 0x58) { // IF
  22164. ++ifLevel;
  22165. } else if (op === 0x1B) { // ELSE
  22166. inELSE = ifLevel;
  22167. } else if (op === 0x59) { // EIF
  22168. if (inELSE === ifLevel) {
  22169. inELSE = 0;
  22170. }
  22171. --ifLevel;
  22172. } else if (op === 0x1C) { // JMPR
  22173. if (!inFDEF && !inELSE) {
  22174. var offset = stack[stack.length - 1];
  22175. // only jumping forward to prevent infinite loop
  22176. if (offset > 0) {
  22177. i += offset - 1;
  22178. }
  22179. }
  22180. }
  22181. // Adjusting stack not extactly, but just enough to get function id
  22182. if (!inFDEF && !inELSE) {
  22183. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  22184. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  22185. if (op >= 0x71 && op <= 0x75) {
  22186. n = stack.pop();
  22187. if (n === n) {
  22188. stackDelta = -n * 2;
  22189. }
  22190. }
  22191. while (stackDelta < 0 && stack.length > 0) {
  22192. stack.pop();
  22193. stackDelta++;
  22194. }
  22195. while (stackDelta > 0) {
  22196. stack.push(NaN); // pushing any number into stack
  22197. stackDelta--;
  22198. }
  22199. }
  22200. }
  22201. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  22202. var content = [data];
  22203. if (i > data.length) {
  22204. content.push(new Uint8Array(i - data.length));
  22205. }
  22206. if (lastDeff > lastEndf) {
  22207. warn('TT: complementing a missing function tail');
  22208. // new function definition started, but not finished
  22209. // complete function by [CLEAR, ENDF]
  22210. content.push(new Uint8Array([0x22, 0x2D]));
  22211. }
  22212. foldTTTable(table, content);
  22213. }
  22214. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  22215. if (ttContext.tooComplexToFollowFunctions) {
  22216. return;
  22217. }
  22218. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  22219. warn('TT: more functions defined than expected');
  22220. ttContext.hintsValid = false;
  22221. return;
  22222. }
  22223. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  22224. if (j > maxFunctionDefs) {
  22225. warn('TT: invalid function id: ' + j);
  22226. ttContext.hintsValid = false;
  22227. return;
  22228. }
  22229. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  22230. warn('TT: undefined function: ' + j);
  22231. ttContext.hintsValid = false;
  22232. return;
  22233. }
  22234. }
  22235. }
  22236. function foldTTTable(table, content) {
  22237. if (content.length > 1) {
  22238. // concatenating the content items
  22239. var newLength = 0;
  22240. var j, jj;
  22241. for (j = 0, jj = content.length; j < jj; j++) {
  22242. newLength += content[j].length;
  22243. }
  22244. newLength = (newLength + 3) & ~3;
  22245. var result = new Uint8Array(newLength);
  22246. var pos = 0;
  22247. for (j = 0, jj = content.length; j < jj; j++) {
  22248. result.set(content[j], pos);
  22249. pos += content[j].length;
  22250. }
  22251. table.data = result;
  22252. table.length = newLength;
  22253. }
  22254. }
  22255. function sanitizeTTPrograms(fpgm, prep, cvt) {
  22256. var ttContext = {
  22257. functionsDefined: [],
  22258. functionsUsed: [],
  22259. functionsStackDeltas: [],
  22260. tooComplexToFollowFunctions: false,
  22261. hintsValid: true
  22262. };
  22263. if (fpgm) {
  22264. sanitizeTTProgram(fpgm, ttContext);
  22265. }
  22266. if (prep) {
  22267. sanitizeTTProgram(prep, ttContext);
  22268. }
  22269. if (fpgm) {
  22270. checkInvalidFunctions(ttContext, maxFunctionDefs);
  22271. }
  22272. if (cvt && (cvt.length & 1)) {
  22273. var cvtData = new Uint8Array(cvt.length + 1);
  22274. cvtData.set(cvt.data);
  22275. cvt.data = cvtData;
  22276. }
  22277. return ttContext.hintsValid;
  22278. }
  22279. // The following steps modify the original font data, making copy
  22280. font = new Stream(new Uint8Array(font.getBytes()));
  22281. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  22282. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  22283. var header = readOpenTypeHeader(font);
  22284. var numTables = header.numTables;
  22285. var cff, cffFile;
  22286. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  22287. hmtx: null, maxp: null, name: null, post: null };
  22288. var table;
  22289. for (var i = 0; i < numTables; i++) {
  22290. table = readTableEntry(font);
  22291. if (VALID_TABLES.indexOf(table.tag) < 0) {
  22292. continue; // skipping table if it's not a required or optional table
  22293. }
  22294. if (table.length === 0) {
  22295. continue; // skipping empty tables
  22296. }
  22297. tables[table.tag] = table;
  22298. }
  22299. var isTrueType = !tables['CFF '];
  22300. if (!isTrueType) {
  22301. // OpenType font
  22302. if (header.version === 'OTTO' ||
  22303. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  22304. // no major tables: throwing everything at CFFFont
  22305. cffFile = new Stream(tables['CFF '].data);
  22306. cff = new CFFFont(cffFile, properties);
  22307. return this.convert(name, cff, properties);
  22308. }
  22309. delete tables.glyf;
  22310. delete tables.loca;
  22311. delete tables.fpgm;
  22312. delete tables.prep;
  22313. delete tables['cvt '];
  22314. this.isOpenType = true;
  22315. } else {
  22316. if (!tables.glyf || !tables.loca) {
  22317. error('Required "glyf" or "loca" tables are not found');
  22318. }
  22319. this.isOpenType = false;
  22320. }
  22321. if (!tables.maxp) {
  22322. error('Required "maxp" table is not found');
  22323. }
  22324. font.pos = (font.start || 0) + tables.maxp.offset;
  22325. var version = font.getInt32();
  22326. var numGlyphs = font.getUint16();
  22327. var maxFunctionDefs = 0;
  22328. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  22329. // maxZones can be invalid
  22330. font.pos += 8;
  22331. var maxZones = font.getUint16();
  22332. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  22333. tables.maxp.data[14] = 0;
  22334. tables.maxp.data[15] = 2;
  22335. }
  22336. font.pos += 4;
  22337. maxFunctionDefs = font.getUint16();
  22338. }
  22339. var dupFirstEntry = false;
  22340. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  22341. properties.toUnicode.get(0) > '\u0000') {
  22342. // oracle's defect (see 3427), duplicating first entry
  22343. dupFirstEntry = true;
  22344. numGlyphs++;
  22345. tables.maxp.data[4] = numGlyphs >> 8;
  22346. tables.maxp.data[5] = numGlyphs & 255;
  22347. }
  22348. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22349. tables['cvt '], maxFunctionDefs);
  22350. if (!hintsValid) {
  22351. delete tables.fpgm;
  22352. delete tables.prep;
  22353. delete tables['cvt '];
  22354. }
  22355. // Ensure the hmtx table contains the advance width and
  22356. // sidebearings information for numGlyphs in the maxp table
  22357. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22358. if (!tables.head) {
  22359. error('Required "head" table is not found');
  22360. }
  22361. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22362. var missingGlyphs = {};
  22363. if (isTrueType) {
  22364. var isGlyphLocationsLong = int16(tables.head.data[50],
  22365. tables.head.data[51]);
  22366. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  22367. numGlyphs, isGlyphLocationsLong,
  22368. hintsValid, dupFirstEntry);
  22369. }
  22370. if (!tables.hhea) {
  22371. error('Required "hhea" table is not found');
  22372. }
  22373. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22374. // Sometimes it's 0. That needs to be fixed
  22375. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22376. tables.hhea.data[10] = 0xFF;
  22377. tables.hhea.data[11] = 0xFF;
  22378. }
  22379. // The 'post' table has glyphs names.
  22380. if (tables.post) {
  22381. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22382. if (!valid) {
  22383. tables.post = null;
  22384. }
  22385. }
  22386. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  22387. function hasGlyph(glyphId, charCode) {
  22388. if (!missingGlyphs[glyphId]) {
  22389. return true;
  22390. }
  22391. if (charCode >= 0 && toUnicode.has(charCode)) {
  22392. return true;
  22393. }
  22394. return false;
  22395. }
  22396. if (properties.type === 'CIDFontType2') {
  22397. var cidToGidMap = properties.cidToGidMap || [];
  22398. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  22399. properties.cMap.forEach(function(charCode, cid) {
  22400. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22401. var glyphId = -1;
  22402. if (isCidToGidMapEmpty) {
  22403. glyphId = charCode;
  22404. } else if (cidToGidMap[cid] !== undefined) {
  22405. glyphId = cidToGidMap[cid];
  22406. }
  22407. if (glyphId >= 0 && glyphId < numGlyphs &&
  22408. hasGlyph(glyphId, charCode)) {
  22409. charCodeToGlyphId[charCode] = glyphId;
  22410. }
  22411. });
  22412. if (dupFirstEntry) {
  22413. charCodeToGlyphId[0] = numGlyphs - 1;
  22414. }
  22415. } else {
  22416. // Most of the following logic in this code branch is based on the
  22417. // 9.6.6.4 of the PDF spec.
  22418. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  22419. var cmapPlatformId = cmapTable.platformId;
  22420. var cmapEncodingId = cmapTable.encodingId;
  22421. var cmapMappings = cmapTable.mappings;
  22422. var cmapMappingsLength = cmapMappings.length;
  22423. var hasEncoding = properties.differences.length ||
  22424. !!properties.baseEncodingName;
  22425. // The spec seems to imply that if the font is symbolic the encoding
  22426. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22427. // where the the font is symbolic and it has an encoding.
  22428. if (hasEncoding &&
  22429. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22430. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22431. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22432. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22433. // When no preferred cmap table was found and |baseEncodingName| is
  22434. // one of the predefined encodings, we seem to obtain a better
  22435. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22436. // TODO: Note that this is a hack which should be removed as soon as
  22437. // we have proper support for more exotic cmap tables.
  22438. var baseEncoding = [];
  22439. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22440. properties.baseEncodingName === 'WinAnsiEncoding') {
  22441. baseEncoding = Encodings[properties.baseEncodingName];
  22442. }
  22443. for (charCode = 0; charCode < 256; charCode++) {
  22444. var glyphName;
  22445. if (this.differences && charCode in this.differences) {
  22446. glyphName = this.differences[charCode];
  22447. } else if (charCode in baseEncoding &&
  22448. baseEncoding[charCode] !== '') {
  22449. glyphName = baseEncoding[charCode];
  22450. } else {
  22451. glyphName = Encodings.StandardEncoding[charCode];
  22452. }
  22453. if (!glyphName) {
  22454. continue;
  22455. }
  22456. var unicodeOrCharCode;
  22457. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22458. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22459. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22460. // TODO: the encoding needs to be updated with mac os table.
  22461. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22462. }
  22463. var found = false;
  22464. for (i = 0; i < cmapMappingsLength; ++i) {
  22465. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  22466. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  22467. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22468. found = true;
  22469. break;
  22470. }
  22471. }
  22472. if (!found && properties.glyphNames) {
  22473. // Try to map using the post table. There are currently no known
  22474. // pdfs that this fixes.
  22475. var glyphId = properties.glyphNames.indexOf(glyphName);
  22476. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  22477. charCodeToGlyphId[charCode] = glyphId;
  22478. }
  22479. }
  22480. }
  22481. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  22482. // Default Unicode semantics, use the charcodes as is.
  22483. for (i = 0; i < cmapMappingsLength; ++i) {
  22484. charCodeToGlyphId[cmapMappings[i].charCode] =
  22485. cmapMappings[i].glyphId;
  22486. }
  22487. } else {
  22488. // For (3, 0) cmap tables:
  22489. // The charcode key being stored in charCodeToGlyphId is the lower
  22490. // byte of the two-byte charcodes of the cmap table since according to
  22491. // the spec: 'each byte from the string shall be prepended with the
  22492. // high byte of the range [of charcodes in the cmap table], to form
  22493. // a two-byte character, which shall be used to select the
  22494. // associated glyph description from the subtable'.
  22495. //
  22496. // For (1, 0) cmap tables:
  22497. // 'single bytes from the string shall be used to look up the
  22498. // associated glyph descriptions from the subtable'. This means
  22499. // charcodes in the cmap will be single bytes, so no-op since
  22500. // glyph.charCode & 0xFF === glyph.charCode
  22501. for (i = 0; i < cmapMappingsLength; ++i) {
  22502. charCode = cmapMappings[i].charCode & 0xFF;
  22503. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22504. }
  22505. }
  22506. }
  22507. if (charCodeToGlyphId.length === 0) {
  22508. // defines at least one glyph
  22509. charCodeToGlyphId[0] = 0;
  22510. }
  22511. // Converting glyphs and ids into font's cmap table
  22512. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22513. this.toFontChar = newMapping.toFontChar;
  22514. tables.cmap = {
  22515. tag: 'cmap',
  22516. data: createCmapTable(newMapping.charCodeToGlyphId)
  22517. };
  22518. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22519. // extract some more font properties from the OpenType head and
  22520. // hhea tables; yMin and descent value are always negative
  22521. var override = {
  22522. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22523. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22524. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22525. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22526. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22527. };
  22528. tables['OS/2'] = {
  22529. tag: 'OS/2',
  22530. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22531. override)
  22532. };
  22533. }
  22534. // Rewrite the 'post' table if needed
  22535. if (!tables.post) {
  22536. tables.post = {
  22537. tag: 'post',
  22538. data: createPostTable(properties)
  22539. };
  22540. }
  22541. if (!isTrueType) {
  22542. try {
  22543. // Trying to repair CFF file
  22544. cffFile = new Stream(tables['CFF '].data);
  22545. var parser = new CFFParser(cffFile, properties);
  22546. cff = parser.parse();
  22547. var compiler = new CFFCompiler(cff);
  22548. tables['CFF '].data = compiler.compile();
  22549. } catch (e) {
  22550. warn('Failed to compile font ' + properties.loadedName);
  22551. }
  22552. }
  22553. // Re-creating 'name' table
  22554. if (!tables.name) {
  22555. tables.name = {
  22556. tag: 'name',
  22557. data: createNameTable(this.name)
  22558. };
  22559. } else {
  22560. // ... using existing 'name' table as prototype
  22561. var namePrototype = readNameTable(tables.name);
  22562. tables.name.data = createNameTable(name, namePrototype);
  22563. }
  22564. var builder = new OpenTypeFileBuilder(header.version);
  22565. for (var tableTag in tables) {
  22566. builder.addTable(tableTag, tables[tableTag].data);
  22567. }
  22568. return builder.toArray();
  22569. },
  22570. convert: function Font_convert(fontName, font, properties) {
  22571. // TODO: Check the charstring widths to determine this.
  22572. properties.fixedPitch = false;
  22573. var mapping = font.getGlyphMapping(properties);
  22574. var newMapping = adjustMapping(mapping, properties);
  22575. this.toFontChar = newMapping.toFontChar;
  22576. var numGlyphs = font.numGlyphs;
  22577. function getCharCodes(charCodeToGlyphId, glyphId) {
  22578. var charCodes = null;
  22579. for (var charCode in charCodeToGlyphId) {
  22580. if (glyphId === charCodeToGlyphId[charCode]) {
  22581. if (!charCodes) {
  22582. charCodes = [];
  22583. }
  22584. charCodes.push(charCode | 0);
  22585. }
  22586. }
  22587. return charCodes;
  22588. }
  22589. function createCharCode(charCodeToGlyphId, glyphId) {
  22590. for (var charCode in charCodeToGlyphId) {
  22591. if (glyphId === charCodeToGlyphId[charCode]) {
  22592. return charCode | 0;
  22593. }
  22594. }
  22595. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22596. glyphId;
  22597. return newMapping.nextAvailableFontCharCode++;
  22598. }
  22599. var seacs = font.seacs;
  22600. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22601. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22602. var charset = font.getCharset();
  22603. var seacMap = Object.create(null);
  22604. for (var glyphId in seacs) {
  22605. glyphId |= 0;
  22606. var seac = seacs[glyphId];
  22607. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22608. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22609. var baseGlyphId = charset.indexOf(baseGlyphName);
  22610. var accentGlyphId = charset.indexOf(accentGlyphName);
  22611. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22612. continue;
  22613. }
  22614. var accentOffset = {
  22615. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22616. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22617. };
  22618. var charCodes = getCharCodes(mapping, glyphId);
  22619. if (!charCodes) {
  22620. // There's no point in mapping it if the char code was never mapped
  22621. // to begin with.
  22622. continue;
  22623. }
  22624. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22625. var charCode = charCodes[i];
  22626. // Find a fontCharCode that maps to the base and accent glyphs.
  22627. // If one doesn't exists, create it.
  22628. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22629. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22630. baseGlyphId);
  22631. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22632. accentGlyphId);
  22633. seacMap[charCode] = {
  22634. baseFontCharCode: baseFontCharCode,
  22635. accentFontCharCode: accentFontCharCode,
  22636. accentOffset: accentOffset
  22637. };
  22638. }
  22639. }
  22640. properties.seacMap = seacMap;
  22641. }
  22642. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22643. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22644. // PostScript Font Program
  22645. builder.addTable('CFF ', font.data);
  22646. // OS/2 and Windows Specific metrics
  22647. builder.addTable('OS/2', createOS2Table(properties,
  22648. newMapping.charCodeToGlyphId));
  22649. // Character to glyphs mapping
  22650. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22651. // Font header
  22652. builder.addTable('head',
  22653. '\x00\x01\x00\x00' + // Version number
  22654. '\x00\x00\x10\x00' + // fontRevision
  22655. '\x00\x00\x00\x00' + // checksumAdjustement
  22656. '\x5F\x0F\x3C\xF5' + // magicNumber
  22657. '\x00\x00' + // Flags
  22658. safeString16(unitsPerEm) + // unitsPerEM
  22659. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22660. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22661. '\x00\x00' + // xMin
  22662. safeString16(properties.descent) + // yMin
  22663. '\x0F\xFF' + // xMax
  22664. safeString16(properties.ascent) + // yMax
  22665. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22666. '\x00\x11' + // lowestRecPPEM
  22667. '\x00\x00' + // fontDirectionHint
  22668. '\x00\x00' + // indexToLocFormat
  22669. '\x00\x00'); // glyphDataFormat
  22670. // Horizontal header
  22671. builder.addTable('hhea',
  22672. '\x00\x01\x00\x00' + // Version number
  22673. safeString16(properties.ascent) + // Typographic Ascent
  22674. safeString16(properties.descent) + // Typographic Descent
  22675. '\x00\x00' + // Line Gap
  22676. '\xFF\xFF' + // advanceWidthMax
  22677. '\x00\x00' + // minLeftSidebearing
  22678. '\x00\x00' + // minRightSidebearing
  22679. '\x00\x00' + // xMaxExtent
  22680. safeString16(properties.capHeight) + // caretSlopeRise
  22681. safeString16(Math.tan(properties.italicAngle) *
  22682. properties.xHeight) + // caretSlopeRun
  22683. '\x00\x00' + // caretOffset
  22684. '\x00\x00' + // -reserved-
  22685. '\x00\x00' + // -reserved-
  22686. '\x00\x00' + // -reserved-
  22687. '\x00\x00' + // -reserved-
  22688. '\x00\x00' + // metricDataFormat
  22689. string16(numGlyphs)); // Number of HMetrics
  22690. // Horizontal metrics
  22691. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22692. var charstrings = font.charstrings;
  22693. var cffWidths = font.cff ? font.cff.widths : null;
  22694. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22695. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22696. var width = 0;
  22697. if (charstrings) {
  22698. var charstring = charstrings[i - 1];
  22699. width = 'width' in charstring ? charstring.width : 0;
  22700. } else if (cffWidths) {
  22701. width = Math.ceil(cffWidths[i] || 0);
  22702. }
  22703. hmtx += string16(width) + string16(0);
  22704. }
  22705. return hmtx;
  22706. })());
  22707. // Maximum profile
  22708. builder.addTable('maxp',
  22709. '\x00\x00\x50\x00' + // Version number
  22710. string16(numGlyphs)); // Num of glyphs
  22711. // Naming tables
  22712. builder.addTable('name', createNameTable(fontName));
  22713. // PostScript informations
  22714. builder.addTable('post', createPostTable(properties));
  22715. return builder.toArray();
  22716. },
  22717. /**
  22718. * Builds a char code to unicode map based on section 9.10 of the spec.
  22719. * @param {Object} properties Font properties object.
  22720. * @return {Object} A ToUnicodeMap object.
  22721. */
  22722. buildToUnicode: function Font_buildToUnicode(properties) {
  22723. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22724. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22725. return properties.toUnicode;
  22726. }
  22727. // According to the spec if the font is a simple font we should only map
  22728. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22729. // the differences array only contains adobe standard or symbol set names,
  22730. // in pratice it seems better to always try to create a toUnicode
  22731. // map based of the default encoding.
  22732. var toUnicode, charcode;
  22733. if (!properties.composite /* is simple font */) {
  22734. toUnicode = [];
  22735. var encoding = properties.defaultEncoding.slice();
  22736. var baseEncodingName = properties.baseEncodingName;
  22737. // Merge in the differences array.
  22738. var differences = properties.differences;
  22739. for (charcode in differences) {
  22740. encoding[charcode] = differences[charcode];
  22741. }
  22742. for (charcode in encoding) {
  22743. // a) Map the character code to a character name.
  22744. var glyphName = encoding[charcode];
  22745. // b) Look up the character name in the Adobe Glyph List (see the
  22746. // Bibliography) to obtain the corresponding Unicode value.
  22747. if (glyphName === '') {
  22748. continue;
  22749. } else if (GlyphsUnicode[glyphName] === undefined) {
  22750. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22751. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22752. var code = 0;
  22753. switch (glyphName[0]) {
  22754. case 'G': // Gxx glyph
  22755. if (glyphName.length === 3) {
  22756. code = parseInt(glyphName.substr(1), 16);
  22757. }
  22758. break;
  22759. case 'g': // g00xx glyph
  22760. if (glyphName.length === 5) {
  22761. code = parseInt(glyphName.substr(1), 16);
  22762. }
  22763. break;
  22764. case 'C': // Cddd glyph
  22765. case 'c': // cddd glyph
  22766. if (glyphName.length >= 3) {
  22767. code = +glyphName.substr(1);
  22768. }
  22769. break;
  22770. }
  22771. if (code) {
  22772. // If |baseEncodingName| is one the predefined encodings,
  22773. // and |code| equals |charcode|, using the glyph defined in the
  22774. // baseEncoding seems to yield a better |toUnicode| mapping
  22775. // (fixes issue 5070).
  22776. if (baseEncodingName && code === +charcode) {
  22777. var baseEncoding = Encodings[baseEncodingName];
  22778. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22779. toUnicode[charcode] =
  22780. String.fromCharCode(GlyphsUnicode[glyphName]);
  22781. continue;
  22782. }
  22783. }
  22784. toUnicode[charcode] = String.fromCharCode(code);
  22785. }
  22786. continue;
  22787. }
  22788. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22789. }
  22790. return new ToUnicodeMap(toUnicode);
  22791. }
  22792. // If the font is a composite font that uses one of the predefined CMaps
  22793. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22794. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22795. // Adobe-Korea1 character collection:
  22796. if (properties.composite && (
  22797. (properties.cMap.builtInCMap &&
  22798. !(properties.cMap instanceof IdentityCMap)) ||
  22799. (properties.cidSystemInfo.registry === 'Adobe' &&
  22800. (properties.cidSystemInfo.ordering === 'GB1' ||
  22801. properties.cidSystemInfo.ordering === 'CNS1' ||
  22802. properties.cidSystemInfo.ordering === 'Japan1' ||
  22803. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22804. // Then:
  22805. // a) Map the character code to a character identifier (CID) according
  22806. // to the font’s CMap.
  22807. // b) Obtain the registry and ordering of the character collection used
  22808. // by the font’s CMap (for example, Adobe and Japan1) from its
  22809. // CIDSystemInfo dictionary.
  22810. var registry = properties.cidSystemInfo.registry;
  22811. var ordering = properties.cidSystemInfo.ordering;
  22812. // c) Construct a second CMap name by concatenating the registry and
  22813. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22814. // (for example, Adobe–Japan1–UCS2).
  22815. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22816. // d) Obtain the CMap with the name constructed in step (c) (available
  22817. // from the ASN Web site; see the Bibliography).
  22818. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22819. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22820. var cMap = properties.cMap;
  22821. toUnicode = [];
  22822. cMap.forEach(function(charcode, cid) {
  22823. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22824. // e) Map the CID obtained in step (a) according to the CMap obtained
  22825. // in step (d), producing a Unicode value.
  22826. var ucs2 = ucs2CMap.lookup(cid);
  22827. if (ucs2) {
  22828. toUnicode[charcode] =
  22829. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22830. ucs2.charCodeAt(1));
  22831. }
  22832. });
  22833. return new ToUnicodeMap(toUnicode);
  22834. }
  22835. // The viewer's choice, just use an identity map.
  22836. return new IdentityToUnicodeMap(properties.firstChar,
  22837. properties.lastChar);
  22838. },
  22839. get spaceWidth() {
  22840. if ('_shadowWidth' in this) {
  22841. return this._shadowWidth;
  22842. }
  22843. // trying to estimate space character width
  22844. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22845. var width;
  22846. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22847. var glyphName = possibleSpaceReplacements[i];
  22848. // if possible, getting width by glyph name
  22849. if (glyphName in this.widths) {
  22850. width = this.widths[glyphName];
  22851. break;
  22852. }
  22853. var glyphUnicode = GlyphsUnicode[glyphName];
  22854. // finding the charcode via unicodeToCID map
  22855. var charcode = 0;
  22856. if (this.composite) {
  22857. if (this.cMap.contains(glyphUnicode)) {
  22858. charcode = this.cMap.lookup(glyphUnicode);
  22859. }
  22860. }
  22861. // ... via toUnicode map
  22862. if (!charcode && 'toUnicode' in this) {
  22863. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22864. }
  22865. // setting it to unicode if negative or undefined
  22866. if (charcode <= 0) {
  22867. charcode = glyphUnicode;
  22868. }
  22869. // trying to get width via charcode
  22870. width = this.widths[charcode];
  22871. if (width) {
  22872. break; // the non-zero width found
  22873. }
  22874. }
  22875. width = width || this.defaultWidth;
  22876. // Do not shadow the property here. See discussion:
  22877. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22878. this._shadowWidth = width;
  22879. return width;
  22880. },
  22881. charToGlyph: function Font_charToGlyph(charcode) {
  22882. var fontCharCode, width, operatorListId;
  22883. var widthCode = charcode;
  22884. if (this.cMap && this.cMap.contains(charcode)) {
  22885. widthCode = this.cMap.lookup(charcode);
  22886. }
  22887. width = this.widths[widthCode];
  22888. width = isNum(width) ? width : this.defaultWidth;
  22889. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22890. var unicode = this.toUnicode.get(charcode) || charcode;
  22891. if (typeof unicode === 'number') {
  22892. unicode = String.fromCharCode(unicode);
  22893. }
  22894. // First try the toFontChar map, if it's not there then try falling
  22895. // back to the char code.
  22896. fontCharCode = this.toFontChar[charcode] || charcode;
  22897. if (this.missingFile) {
  22898. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22899. }
  22900. if (this.isType3Font) {
  22901. // Font char code in this case is actually a glyph name.
  22902. operatorListId = fontCharCode;
  22903. }
  22904. var accent = null;
  22905. if (this.seacMap && this.seacMap[charcode]) {
  22906. var seac = this.seacMap[charcode];
  22907. fontCharCode = seac.baseFontCharCode;
  22908. accent = {
  22909. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22910. offset: seac.accentOffset
  22911. };
  22912. }
  22913. var fontChar = String.fromCharCode(fontCharCode);
  22914. var glyph = this.glyphCache[charcode];
  22915. if (!glyph ||
  22916. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22917. operatorListId)) {
  22918. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22919. operatorListId);
  22920. this.glyphCache[charcode] = glyph;
  22921. }
  22922. return glyph;
  22923. },
  22924. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22925. var charsCache = this.charsCache;
  22926. var glyphs, glyph, charcode;
  22927. // if we translated this string before, just grab it from the cache
  22928. if (charsCache) {
  22929. glyphs = charsCache[chars];
  22930. if (glyphs) {
  22931. return glyphs;
  22932. }
  22933. }
  22934. // lazily create the translation cache
  22935. if (!charsCache) {
  22936. charsCache = this.charsCache = Object.create(null);
  22937. }
  22938. glyphs = [];
  22939. var charsCacheKey = chars;
  22940. var i = 0, ii;
  22941. if (this.cMap) {
  22942. // composite fonts have multi-byte strings convert the string from
  22943. // single-byte to multi-byte
  22944. var c = {};
  22945. while (i < chars.length) {
  22946. this.cMap.readCharCode(chars, i, c);
  22947. charcode = c.charcode;
  22948. var length = c.length;
  22949. i += length;
  22950. glyph = this.charToGlyph(charcode);
  22951. glyphs.push(glyph);
  22952. // placing null after each word break charcode (ASCII SPACE)
  22953. // Ignore occurences of 0x20 in multiple-byte codes.
  22954. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22955. glyphs.push(null);
  22956. }
  22957. }
  22958. } else {
  22959. for (i = 0, ii = chars.length; i < ii; ++i) {
  22960. charcode = chars.charCodeAt(i);
  22961. glyph = this.charToGlyph(charcode);
  22962. glyphs.push(glyph);
  22963. if (charcode === 0x20) {
  22964. glyphs.push(null);
  22965. }
  22966. }
  22967. }
  22968. // Enter the translated string into the cache
  22969. return (charsCache[charsCacheKey] = glyphs);
  22970. }
  22971. };
  22972. return Font;
  22973. })();
  22974. var ErrorFont = (function ErrorFontClosure() {
  22975. function ErrorFont(error) {
  22976. this.error = error;
  22977. this.loadedName = 'g_font_error';
  22978. this.loading = false;
  22979. }
  22980. ErrorFont.prototype = {
  22981. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22982. return [];
  22983. },
  22984. exportData: function ErrorFont_exportData() {
  22985. return {error: this.error};
  22986. }
  22987. };
  22988. return ErrorFont;
  22989. })();
  22990. /**
  22991. * Shared logic for building a char code to glyph id mapping for Type1 and
  22992. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22993. * @param {Object} properties Font properties object.
  22994. * @param {Object} builtInEncoding The encoding contained within the actual font
  22995. * data.
  22996. * @param {Array} Array of glyph names where the index is the glyph ID.
  22997. * @returns {Object} A char code to glyph ID map.
  22998. */
  22999. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  23000. var charCodeToGlyphId = Object.create(null);
  23001. var glyphId, charCode, baseEncoding;
  23002. if (properties.baseEncodingName) {
  23003. // If a valid base encoding name was used, the mapping is initialized with
  23004. // that.
  23005. baseEncoding = Encodings[properties.baseEncodingName];
  23006. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  23007. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  23008. if (glyphId >= 0) {
  23009. charCodeToGlyphId[charCode] = glyphId;
  23010. } else {
  23011. charCodeToGlyphId[charCode] = 0; // notdef
  23012. }
  23013. }
  23014. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  23015. // For a symbolic font the encoding should be the fonts built-in
  23016. // encoding.
  23017. for (charCode in builtInEncoding) {
  23018. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  23019. }
  23020. } else {
  23021. // For non-symbolic fonts that don't have a base encoding the standard
  23022. // encoding should be used.
  23023. baseEncoding = Encodings.StandardEncoding;
  23024. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  23025. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  23026. if (glyphId >= 0) {
  23027. charCodeToGlyphId[charCode] = glyphId;
  23028. } else {
  23029. charCodeToGlyphId[charCode] = 0; // notdef
  23030. }
  23031. }
  23032. }
  23033. // Lastly, merge in the differences.
  23034. var differences = properties.differences;
  23035. if (differences) {
  23036. for (charCode in differences) {
  23037. var glyphName = differences[charCode];
  23038. glyphId = glyphNames.indexOf(glyphName);
  23039. if (glyphId >= 0) {
  23040. charCodeToGlyphId[charCode] = glyphId;
  23041. } else {
  23042. charCodeToGlyphId[charCode] = 0; // notdef
  23043. }
  23044. }
  23045. }
  23046. return charCodeToGlyphId;
  23047. }
  23048. /*
  23049. * CharStrings are encoded following the the CharString Encoding sequence
  23050. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  23051. * The value in a byte indicates a command, a number, or subsequent bytes
  23052. * that are to be interpreted in a special way.
  23053. *
  23054. * CharString Number Encoding:
  23055. * A CharString byte containing the values from 32 through 255 inclusive
  23056. * indicate an integer. These values are decoded in four ranges.
  23057. *
  23058. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  23059. * indicate the integer v - 139. Thus, the integer values from -107 through
  23060. * 107 inclusive may be encoded in single byte.
  23061. *
  23062. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  23063. * indicates an integer involving the next byte, w, according to the formula:
  23064. * [(v - 247) x 256] + w + 108
  23065. *
  23066. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  23067. * indicates an integer involving the next byte, w, according to the formula:
  23068. * -[(v - 251) * 256] - w - 108
  23069. *
  23070. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  23071. * are a two complement signed integer. The first of these bytes contains the
  23072. * highest order bits, the second byte contains the next higher order bits
  23073. * and the fourth byte contain the lowest order bits.
  23074. *
  23075. *
  23076. * CharString Command Encoding:
  23077. * CharStrings commands are encoded in 1 or 2 bytes.
  23078. *
  23079. * Single byte commands are encoded in 1 byte that contains a value between
  23080. * 0 and 31 inclusive.
  23081. * If a command byte contains the value 12, then the value in the next byte
  23082. * indicates a command. This "escape" mechanism allows many extra commands
  23083. * to be encoded and this encoding technique helps to minimize the length of
  23084. * the charStrings.
  23085. */
  23086. var Type1CharString = (function Type1CharStringClosure() {
  23087. var COMMAND_MAP = {
  23088. 'hstem': [1],
  23089. 'vstem': [3],
  23090. 'vmoveto': [4],
  23091. 'rlineto': [5],
  23092. 'hlineto': [6],
  23093. 'vlineto': [7],
  23094. 'rrcurveto': [8],
  23095. 'callsubr': [10],
  23096. 'flex': [12, 35],
  23097. 'drop' : [12, 18],
  23098. 'endchar': [14],
  23099. 'rmoveto': [21],
  23100. 'hmoveto': [22],
  23101. 'vhcurveto': [30],
  23102. 'hvcurveto': [31]
  23103. };
  23104. function Type1CharString() {
  23105. this.width = 0;
  23106. this.lsb = 0;
  23107. this.flexing = false;
  23108. this.output = [];
  23109. this.stack = [];
  23110. }
  23111. Type1CharString.prototype = {
  23112. convert: function Type1CharString_convert(encoded, subrs) {
  23113. var count = encoded.length;
  23114. var error = false;
  23115. var wx, sbx, subrNumber;
  23116. for (var i = 0; i < count; i++) {
  23117. var value = encoded[i];
  23118. if (value < 32) {
  23119. if (value === 12) {
  23120. value = (value << 8) + encoded[++i];
  23121. }
  23122. switch (value) {
  23123. case 1: // hstem
  23124. if (!HINTING_ENABLED) {
  23125. this.stack = [];
  23126. break;
  23127. }
  23128. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23129. break;
  23130. case 3: // vstem
  23131. if (!HINTING_ENABLED) {
  23132. this.stack = [];
  23133. break;
  23134. }
  23135. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23136. break;
  23137. case 4: // vmoveto
  23138. if (this.flexing) {
  23139. if (this.stack.length < 1) {
  23140. error = true;
  23141. break;
  23142. }
  23143. // Add the dx for flex and but also swap the values so they are
  23144. // the right order.
  23145. var dy = this.stack.pop();
  23146. this.stack.push(0, dy);
  23147. break;
  23148. }
  23149. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  23150. break;
  23151. case 5: // rlineto
  23152. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  23153. break;
  23154. case 6: // hlineto
  23155. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  23156. break;
  23157. case 7: // vlineto
  23158. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  23159. break;
  23160. case 8: // rrcurveto
  23161. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  23162. break;
  23163. case 9: // closepath
  23164. // closepath is a Type1 command that does not take argument and is
  23165. // useless in Type2 and it can simply be ignored.
  23166. this.stack = [];
  23167. break;
  23168. case 10: // callsubr
  23169. if (this.stack.length < 1) {
  23170. error = true;
  23171. break;
  23172. }
  23173. subrNumber = this.stack.pop();
  23174. error = this.convert(subrs[subrNumber], subrs);
  23175. break;
  23176. case 11: // return
  23177. return error;
  23178. case 13: // hsbw
  23179. if (this.stack.length < 2) {
  23180. error = true;
  23181. break;
  23182. }
  23183. // To convert to type2 we have to move the width value to the
  23184. // first part of the charstring and then use hmoveto with lsb.
  23185. wx = this.stack.pop();
  23186. sbx = this.stack.pop();
  23187. this.lsb = sbx;
  23188. this.width = wx;
  23189. this.stack.push(wx, sbx);
  23190. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23191. break;
  23192. case 14: // endchar
  23193. this.output.push(COMMAND_MAP.endchar[0]);
  23194. break;
  23195. case 21: // rmoveto
  23196. if (this.flexing) {
  23197. break;
  23198. }
  23199. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23200. break;
  23201. case 22: // hmoveto
  23202. if (this.flexing) {
  23203. // Add the dy for flex.
  23204. this.stack.push(0);
  23205. break;
  23206. }
  23207. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23208. break;
  23209. case 30: // vhcurveto
  23210. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23211. break;
  23212. case 31: // hvcurveto
  23213. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23214. break;
  23215. case (12 << 8) + 0: // dotsection
  23216. // dotsection is a Type1 command to specify some hinting feature
  23217. // for dots that do not take a parameter and it can safely be
  23218. // ignored for Type2.
  23219. this.stack = [];
  23220. break;
  23221. case (12 << 8) + 1: // vstem3
  23222. if (!HINTING_ENABLED) {
  23223. this.stack = [];
  23224. break;
  23225. }
  23226. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  23227. // multiple parameters, so instead of returning [vh]stem3 take a
  23228. // shortcut and return [vhstem] instead.
  23229. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23230. break;
  23231. case (12 << 8) + 2: // hstem3
  23232. if (!HINTING_ENABLED) {
  23233. this.stack = [];
  23234. break;
  23235. }
  23236. // See vstem3.
  23237. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23238. break;
  23239. case (12 << 8) + 6: // seac
  23240. // seac is like type 2's special endchar but it doesn't use the
  23241. // first argument asb, so remove it.
  23242. if (SEAC_ANALYSIS_ENABLED) {
  23243. this.seac = this.stack.splice(-4, 4);
  23244. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23245. } else {
  23246. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23247. }
  23248. break;
  23249. case (12 << 8) + 7: // sbw
  23250. if (this.stack.length < 4) {
  23251. error = true;
  23252. break;
  23253. }
  23254. // To convert to type2 we have to move the width value to the
  23255. // first part of the charstring and then use rmoveto with
  23256. // (dx, dy). The height argument will not be used for vmtx and
  23257. // vhea tables reconstruction -- ignoring it.
  23258. var wy = this.stack.pop();
  23259. wx = this.stack.pop();
  23260. var sby = this.stack.pop();
  23261. sbx = this.stack.pop();
  23262. this.lsb = sbx;
  23263. this.width = wx;
  23264. this.stack.push(wx, sbx, sby);
  23265. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23266. break;
  23267. case (12 << 8) + 12: // div
  23268. if (this.stack.length < 2) {
  23269. error = true;
  23270. break;
  23271. }
  23272. var num2 = this.stack.pop();
  23273. var num1 = this.stack.pop();
  23274. this.stack.push(num1 / num2);
  23275. break;
  23276. case (12 << 8) + 16: // callothersubr
  23277. if (this.stack.length < 2) {
  23278. error = true;
  23279. break;
  23280. }
  23281. subrNumber = this.stack.pop();
  23282. var numArgs = this.stack.pop();
  23283. if (subrNumber === 0 && numArgs === 3) {
  23284. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  23285. this.stack.push(
  23286. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  23287. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  23288. flexArgs[4], // bcp2x
  23289. flexArgs[5], // bcp2y
  23290. flexArgs[6], // p2x
  23291. flexArgs[7], // p2y
  23292. flexArgs[8], // bcp3x
  23293. flexArgs[9], // bcp3y
  23294. flexArgs[10], // bcp4x
  23295. flexArgs[11], // bcp4y
  23296. flexArgs[12], // p3x
  23297. flexArgs[13], // p3y
  23298. flexArgs[14] // flexDepth
  23299. // 15 = finalx unused by flex
  23300. // 16 = finaly unused by flex
  23301. );
  23302. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23303. this.flexing = false;
  23304. this.stack.push(flexArgs[15], flexArgs[16]);
  23305. } else if (subrNumber === 1 && numArgs === 0) {
  23306. this.flexing = true;
  23307. }
  23308. break;
  23309. case (12 << 8) + 17: // pop
  23310. // Ignore this since it is only used with othersubr.
  23311. break;
  23312. case (12 << 8) + 33: // setcurrentpoint
  23313. // Ignore for now.
  23314. this.stack = [];
  23315. break;
  23316. default:
  23317. warn('Unknown type 1 charstring command of "' + value + '"');
  23318. break;
  23319. }
  23320. if (error) {
  23321. break;
  23322. }
  23323. continue;
  23324. } else if (value <= 246) {
  23325. value = value - 139;
  23326. } else if (value <= 250) {
  23327. value = ((value - 247) * 256) + encoded[++i] + 108;
  23328. } else if (value <= 254) {
  23329. value = -((value - 251) * 256) - encoded[++i] - 108;
  23330. } else {
  23331. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  23332. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23333. }
  23334. this.stack.push(value);
  23335. }
  23336. return error;
  23337. },
  23338. executeCommand: function(howManyArgs, command, keepStack) {
  23339. var stackLength = this.stack.length;
  23340. if (howManyArgs > stackLength) {
  23341. return true;
  23342. }
  23343. var start = stackLength - howManyArgs;
  23344. for (var i = start; i < stackLength; i++) {
  23345. var value = this.stack[i];
  23346. if (value === (value | 0)) { // int
  23347. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  23348. } else { // fixed point
  23349. value = (65536 * value) | 0;
  23350. this.output.push(255,
  23351. (value >> 24) & 0xFF,
  23352. (value >> 16) & 0xFF,
  23353. (value >> 8) & 0xFF,
  23354. value & 0xFF);
  23355. }
  23356. }
  23357. this.output.push.apply(this.output, command);
  23358. if (keepStack) {
  23359. this.stack.splice(start, howManyArgs);
  23360. } else {
  23361. this.stack.length = 0;
  23362. }
  23363. return false;
  23364. }
  23365. };
  23366. return Type1CharString;
  23367. })();
  23368. /*
  23369. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23370. * program. Some of its logic depends on the Type2 charstrings
  23371. * structure.
  23372. * Note: this doesn't really parse the font since that would require evaluation
  23373. * of PostScript, but it is possible in most cases to extract what we need
  23374. * without a full parse.
  23375. */
  23376. var Type1Parser = (function Type1ParserClosure() {
  23377. /*
  23378. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23379. * of Plaintext Bytes. The function took a key as a parameter which can be
  23380. * for decrypting the eexec block of for decoding charStrings.
  23381. */
  23382. var EEXEC_ENCRYPT_KEY = 55665;
  23383. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23384. function isHexDigit(code) {
  23385. return code >= 48 && code <= 57 || // '0'-'9'
  23386. code >= 65 && code <= 70 || // 'A'-'F'
  23387. code >= 97 && code <= 102; // 'a'-'f'
  23388. }
  23389. function decrypt(data, key, discardNumber) {
  23390. var r = key | 0, c1 = 52845, c2 = 22719;
  23391. var count = data.length;
  23392. var decrypted = new Uint8Array(count);
  23393. for (var i = 0; i < count; i++) {
  23394. var value = data[i];
  23395. decrypted[i] = value ^ (r >> 8);
  23396. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23397. }
  23398. return Array.prototype.slice.call(decrypted, discardNumber);
  23399. }
  23400. function decryptAscii(data, key, discardNumber) {
  23401. var r = key | 0, c1 = 52845, c2 = 22719;
  23402. var count = data.length, maybeLength = count >>> 1;
  23403. var decrypted = new Uint8Array(maybeLength);
  23404. var i, j;
  23405. for (i = 0, j = 0; i < count; i++) {
  23406. var digit1 = data[i];
  23407. if (!isHexDigit(digit1)) {
  23408. continue;
  23409. }
  23410. i++;
  23411. var digit2;
  23412. while (i < count && !isHexDigit(digit2 = data[i])) {
  23413. i++;
  23414. }
  23415. if (i < count) {
  23416. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23417. decrypted[j++] = value ^ (r >> 8);
  23418. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23419. }
  23420. }
  23421. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23422. }
  23423. function isSpecial(c) {
  23424. return c === 0x2F || // '/'
  23425. c === 0x5B || c === 0x5D || // '[', ']'
  23426. c === 0x7B || c === 0x7D || // '{', '}'
  23427. c === 0x28 || c === 0x29; // '(', ')'
  23428. }
  23429. function Type1Parser(stream, encrypted) {
  23430. if (encrypted) {
  23431. var data = stream.getBytes();
  23432. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23433. isHexDigit(data[2]) && isHexDigit(data[3]));
  23434. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23435. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23436. }
  23437. this.stream = stream;
  23438. this.nextChar();
  23439. }
  23440. Type1Parser.prototype = {
  23441. readNumberArray: function Type1Parser_readNumberArray() {
  23442. this.getToken(); // read '[' or '{' (arrays can start with either)
  23443. var array = [];
  23444. while (true) {
  23445. var token = this.getToken();
  23446. if (token === null || token === ']' || token === '}') {
  23447. break;
  23448. }
  23449. array.push(parseFloat(token || 0));
  23450. }
  23451. return array;
  23452. },
  23453. readNumber: function Type1Parser_readNumber() {
  23454. var token = this.getToken();
  23455. return parseFloat(token || 0);
  23456. },
  23457. readInt: function Type1Parser_readInt() {
  23458. // Use '| 0' to prevent setting a double into length such as the double
  23459. // does not flow into the loop variable.
  23460. var token = this.getToken();
  23461. return parseInt(token || 0, 10) | 0;
  23462. },
  23463. readBoolean: function Type1Parser_readBoolean() {
  23464. var token = this.getToken();
  23465. // Use 1 and 0 since that's what type2 charstrings use.
  23466. return token === 'true' ? 1 : 0;
  23467. },
  23468. nextChar : function Type1_nextChar() {
  23469. return (this.currentChar = this.stream.getByte());
  23470. },
  23471. getToken: function Type1Parser_getToken() {
  23472. // Eat whitespace and comments.
  23473. var comment = false;
  23474. var ch = this.currentChar;
  23475. while (true) {
  23476. if (ch === -1) {
  23477. return null;
  23478. }
  23479. if (comment) {
  23480. if (ch === 0x0A || ch === 0x0D) {
  23481. comment = false;
  23482. }
  23483. } else if (ch === 0x25) { // '%'
  23484. comment = true;
  23485. } else if (!Lexer.isSpace(ch)) {
  23486. break;
  23487. }
  23488. ch = this.nextChar();
  23489. }
  23490. if (isSpecial(ch)) {
  23491. this.nextChar();
  23492. return String.fromCharCode(ch);
  23493. }
  23494. var token = '';
  23495. do {
  23496. token += String.fromCharCode(ch);
  23497. ch = this.nextChar();
  23498. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23499. return token;
  23500. },
  23501. /*
  23502. * Returns an object containing a Subrs array and a CharStrings
  23503. * array extracted from and eexec encrypted block of data
  23504. */
  23505. extractFontProgram: function Type1Parser_extractFontProgram() {
  23506. var stream = this.stream;
  23507. var subrs = [], charstrings = [];
  23508. var program = {
  23509. subrs: [],
  23510. charstrings: [],
  23511. properties: {
  23512. 'privateData': {
  23513. 'lenIV': 4
  23514. }
  23515. }
  23516. };
  23517. var token, length, data, lenIV, encoded;
  23518. while ((token = this.getToken()) !== null) {
  23519. if (token !== '/') {
  23520. continue;
  23521. }
  23522. token = this.getToken();
  23523. switch (token) {
  23524. case 'CharStrings':
  23525. // The number immediately following CharStrings must be greater or
  23526. // equal to the number of CharStrings.
  23527. this.getToken();
  23528. this.getToken(); // read in 'dict'
  23529. this.getToken(); // read in 'dup'
  23530. this.getToken(); // read in 'begin'
  23531. while(true) {
  23532. token = this.getToken();
  23533. if (token === null || token === 'end') {
  23534. break;
  23535. }
  23536. if (token !== '/') {
  23537. continue;
  23538. }
  23539. var glyph = this.getToken();
  23540. length = this.readInt();
  23541. this.getToken(); // read in 'RD' or '-|'
  23542. data = stream.makeSubStream(stream.pos, length);
  23543. lenIV = program.properties.privateData['lenIV'];
  23544. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23545. // Skip past the required space and binary data.
  23546. stream.skip(length);
  23547. this.nextChar();
  23548. token = this.getToken(); // read in 'ND' or '|-'
  23549. if (token === 'noaccess') {
  23550. this.getToken(); // read in 'def'
  23551. }
  23552. charstrings.push({
  23553. glyph: glyph,
  23554. encoded: encoded
  23555. });
  23556. }
  23557. break;
  23558. case 'Subrs':
  23559. var num = this.readInt();
  23560. this.getToken(); // read in 'array'
  23561. while ((token = this.getToken()) === 'dup') {
  23562. var index = this.readInt();
  23563. length = this.readInt();
  23564. this.getToken(); // read in 'RD' or '-|'
  23565. data = stream.makeSubStream(stream.pos, length);
  23566. lenIV = program.properties.privateData['lenIV'];
  23567. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23568. // Skip past the required space and binary data.
  23569. stream.skip(length);
  23570. this.nextChar();
  23571. token = this.getToken(); // read in 'NP' or '|'
  23572. if (token === 'noaccess') {
  23573. this.getToken(); // read in 'put'
  23574. }
  23575. subrs[index] = encoded;
  23576. }
  23577. break;
  23578. case 'BlueValues':
  23579. case 'OtherBlues':
  23580. case 'FamilyBlues':
  23581. case 'FamilyOtherBlues':
  23582. var blueArray = this.readNumberArray();
  23583. // *Blue* values may contain invalid data: disables reading of
  23584. // those values when hinting is disabled.
  23585. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23586. HINTING_ENABLED) {
  23587. program.properties.privateData[token] = blueArray;
  23588. }
  23589. break;
  23590. case 'StemSnapH':
  23591. case 'StemSnapV':
  23592. program.properties.privateData[token] = this.readNumberArray();
  23593. break;
  23594. case 'StdHW':
  23595. case 'StdVW':
  23596. program.properties.privateData[token] =
  23597. this.readNumberArray()[0];
  23598. break;
  23599. case 'BlueShift':
  23600. case 'lenIV':
  23601. case 'BlueFuzz':
  23602. case 'BlueScale':
  23603. case 'LanguageGroup':
  23604. case 'ExpansionFactor':
  23605. program.properties.privateData[token] = this.readNumber();
  23606. break;
  23607. case 'ForceBold':
  23608. program.properties.privateData[token] = this.readBoolean();
  23609. break;
  23610. }
  23611. }
  23612. for (var i = 0; i < charstrings.length; i++) {
  23613. glyph = charstrings[i].glyph;
  23614. encoded = charstrings[i].encoded;
  23615. var charString = new Type1CharString();
  23616. var error = charString.convert(encoded, subrs);
  23617. var output = charString.output;
  23618. if (error) {
  23619. // It seems when FreeType encounters an error while evaluating a glyph
  23620. // that it completely ignores the glyph so we'll mimic that behaviour
  23621. // here and put an endchar to make the validator happy.
  23622. output = [14];
  23623. }
  23624. program.charstrings.push({
  23625. glyphName: glyph,
  23626. charstring: output,
  23627. width: charString.width,
  23628. lsb: charString.lsb,
  23629. seac: charString.seac
  23630. });
  23631. }
  23632. return program;
  23633. },
  23634. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23635. var token;
  23636. while ((token = this.getToken()) !== null) {
  23637. if (token !== '/') {
  23638. continue;
  23639. }
  23640. token = this.getToken();
  23641. switch (token) {
  23642. case 'FontMatrix':
  23643. var matrix = this.readNumberArray();
  23644. properties.fontMatrix = matrix;
  23645. break;
  23646. case 'Encoding':
  23647. var encodingArg = this.getToken();
  23648. var encoding;
  23649. if (!/^\d+$/.test(encodingArg)) {
  23650. // encoding name is specified
  23651. encoding = Encodings[encodingArg];
  23652. } else {
  23653. encoding = [];
  23654. var size = parseInt(encodingArg, 10) | 0;
  23655. this.getToken(); // read in 'array'
  23656. for (var j = 0; j < size; j++) {
  23657. token = this.getToken();
  23658. // skipping till first dup or def (e.g. ignoring for statement)
  23659. while (token !== 'dup' && token !== 'def') {
  23660. token = this.getToken();
  23661. if (token === null) {
  23662. return; // invalid header
  23663. }
  23664. }
  23665. if (token === 'def') {
  23666. break; // read all array data
  23667. }
  23668. var index = this.readInt();
  23669. this.getToken(); // read in '/'
  23670. var glyph = this.getToken();
  23671. encoding[index] = glyph;
  23672. this.getToken(); // read the in 'put'
  23673. }
  23674. }
  23675. properties.builtInEncoding = encoding;
  23676. break;
  23677. case 'FontBBox':
  23678. var fontBBox = this.readNumberArray();
  23679. // adjusting ascent/descent
  23680. properties.ascent = fontBBox[3];
  23681. properties.descent = fontBBox[1];
  23682. properties.ascentScaled = true;
  23683. break;
  23684. }
  23685. }
  23686. }
  23687. };
  23688. return Type1Parser;
  23689. })();
  23690. /**
  23691. * The CFF class takes a Type1 file and wrap it into a
  23692. * 'Compact Font Format' which itself embed Type2 charstrings.
  23693. */
  23694. var CFFStandardStrings = [
  23695. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23696. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23697. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23698. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23699. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23700. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23701. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23702. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23703. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23704. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23705. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23706. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23707. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23708. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23709. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23710. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23711. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23712. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23713. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23714. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23715. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23716. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23717. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23718. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23719. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23720. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23721. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23722. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23723. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23724. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23725. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23726. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23727. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23728. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23729. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23730. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23731. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23732. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23733. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23734. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23735. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23736. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23737. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23738. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23739. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23740. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23741. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23742. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23743. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23744. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23745. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23746. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23747. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23748. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23749. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23750. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23751. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23752. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23753. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23754. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23755. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23756. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23757. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23758. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23759. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23760. ];
  23761. // Type1Font is also a CIDFontType0.
  23762. var Type1Font = function Type1Font(name, file, properties) {
  23763. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23764. // Also, length1 and length2 might be off by 6 bytes as well.
  23765. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23766. var PFB_HEADER_SIZE = 6;
  23767. var headerBlockLength = properties.length1;
  23768. var eexecBlockLength = properties.length2;
  23769. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23770. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23771. if (pfbHeaderPresent) {
  23772. file.skip(PFB_HEADER_SIZE);
  23773. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23774. (pfbHeader[3] << 8) | pfbHeader[2];
  23775. }
  23776. // Get the data block containing glyphs and subrs informations
  23777. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23778. var headerBlockParser = new Type1Parser(headerBlock);
  23779. headerBlockParser.extractFontHeader(properties);
  23780. if (pfbHeaderPresent) {
  23781. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23782. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23783. (pfbHeader[3] << 8) | pfbHeader[2];
  23784. }
  23785. // Decrypt the data blocks and retrieve it's content
  23786. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23787. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23788. var data = eexecBlockParser.extractFontProgram();
  23789. for (var info in data.properties) {
  23790. properties[info] = data.properties[info];
  23791. }
  23792. var charstrings = data.charstrings;
  23793. var type2Charstrings = this.getType2Charstrings(charstrings);
  23794. var subrs = this.getType2Subrs(data.subrs);
  23795. this.charstrings = charstrings;
  23796. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23797. subrs, properties);
  23798. this.seacs = this.getSeacs(data.charstrings);
  23799. };
  23800. Type1Font.prototype = {
  23801. get numGlyphs() {
  23802. return this.charstrings.length + 1;
  23803. },
  23804. getCharset: function Type1Font_getCharset() {
  23805. var charset = ['.notdef'];
  23806. var charstrings = this.charstrings;
  23807. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23808. charset.push(charstrings[glyphId].glyphName);
  23809. }
  23810. return charset;
  23811. },
  23812. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23813. var charstrings = this.charstrings;
  23814. var glyphNames = ['.notdef'], glyphId;
  23815. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23816. glyphNames.push(charstrings[glyphId].glyphName);
  23817. }
  23818. var encoding = properties.builtInEncoding;
  23819. if (encoding) {
  23820. var builtInEncoding = {};
  23821. for (var charCode in encoding) {
  23822. glyphId = glyphNames.indexOf(encoding[charCode]);
  23823. if (glyphId >= 0) {
  23824. builtInEncoding[charCode] = glyphId;
  23825. }
  23826. }
  23827. }
  23828. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23829. },
  23830. getSeacs: function Type1Font_getSeacs(charstrings) {
  23831. var i, ii;
  23832. var seacMap = [];
  23833. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23834. var charstring = charstrings[i];
  23835. if (charstring.seac) {
  23836. // Offset by 1 for .notdef
  23837. seacMap[i + 1] = charstring.seac;
  23838. }
  23839. }
  23840. return seacMap;
  23841. },
  23842. getType2Charstrings: function Type1Font_getType2Charstrings(
  23843. type1Charstrings) {
  23844. var type2Charstrings = [];
  23845. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23846. type2Charstrings.push(type1Charstrings[i].charstring);
  23847. }
  23848. return type2Charstrings;
  23849. },
  23850. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23851. var bias = 0;
  23852. var count = type1Subrs.length;
  23853. if (count < 1133) {
  23854. bias = 107;
  23855. } else if (count < 33769) {
  23856. bias = 1131;
  23857. } else {
  23858. bias = 32768;
  23859. }
  23860. // Add a bunch of empty subrs to deal with the Type2 bias
  23861. var type2Subrs = [];
  23862. var i;
  23863. for (i = 0; i < bias; i++) {
  23864. type2Subrs.push([0x0B]);
  23865. }
  23866. for (i = 0; i < count; i++) {
  23867. type2Subrs.push(type1Subrs[i]);
  23868. }
  23869. return type2Subrs;
  23870. },
  23871. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23872. var cff = new CFF();
  23873. cff.header = new CFFHeader(1, 0, 4, 4);
  23874. cff.names = [name];
  23875. var topDict = new CFFTopDict();
  23876. // CFF strings IDs 0...390 are predefined names, so refering
  23877. // to entries in our own String INDEX starts at SID 391.
  23878. topDict.setByName('version', 391);
  23879. topDict.setByName('Notice', 392);
  23880. topDict.setByName('FullName', 393);
  23881. topDict.setByName('FamilyName', 394);
  23882. topDict.setByName('Weight', 395);
  23883. topDict.setByName('Encoding', null); // placeholder
  23884. topDict.setByName('FontMatrix', properties.fontMatrix);
  23885. topDict.setByName('FontBBox', properties.bbox);
  23886. topDict.setByName('charset', null); // placeholder
  23887. topDict.setByName('CharStrings', null); // placeholder
  23888. topDict.setByName('Private', null); // placeholder
  23889. cff.topDict = topDict;
  23890. var strings = new CFFStrings();
  23891. strings.add('Version 0.11'); // Version
  23892. strings.add('See original notice'); // Notice
  23893. strings.add(name); // FullName
  23894. strings.add(name); // FamilyName
  23895. strings.add('Medium'); // Weight
  23896. cff.strings = strings;
  23897. cff.globalSubrIndex = new CFFIndex();
  23898. var count = glyphs.length;
  23899. var charsetArray = [0];
  23900. var i, ii;
  23901. for (i = 0; i < count; i++) {
  23902. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23903. // TODO: Insert the string and correctly map it. Previously it was
  23904. // thought mapping names that aren't in the standard strings to .notdef
  23905. // was fine, however in issue818 when mapping them all to .notdef the
  23906. // adieresis glyph no longer worked.
  23907. if (index === -1) {
  23908. index = 0;
  23909. }
  23910. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23911. }
  23912. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23913. var charStringsIndex = new CFFIndex();
  23914. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23915. for (i = 0; i < count; i++) {
  23916. charStringsIndex.add(glyphs[i]);
  23917. }
  23918. cff.charStrings = charStringsIndex;
  23919. var privateDict = new CFFPrivateDict();
  23920. privateDict.setByName('Subrs', null); // placeholder
  23921. var fields = [
  23922. 'BlueValues',
  23923. 'OtherBlues',
  23924. 'FamilyBlues',
  23925. 'FamilyOtherBlues',
  23926. 'StemSnapH',
  23927. 'StemSnapV',
  23928. 'BlueShift',
  23929. 'BlueFuzz',
  23930. 'BlueScale',
  23931. 'LanguageGroup',
  23932. 'ExpansionFactor',
  23933. 'ForceBold',
  23934. 'StdHW',
  23935. 'StdVW'
  23936. ];
  23937. for (i = 0, ii = fields.length; i < ii; i++) {
  23938. var field = fields[i];
  23939. if (!properties.privateData.hasOwnProperty(field)) {
  23940. continue;
  23941. }
  23942. var value = properties.privateData[field];
  23943. if (isArray(value)) {
  23944. // All of the private dictionary array data in CFF must be stored as
  23945. // "delta-encoded" numbers.
  23946. for (var j = value.length - 1; j > 0; j--) {
  23947. value[j] -= value[j - 1]; // ... difference from previous value
  23948. }
  23949. }
  23950. privateDict.setByName(field, value);
  23951. }
  23952. cff.topDict.privateDict = privateDict;
  23953. var subrIndex = new CFFIndex();
  23954. for (i = 0, ii = subrs.length; i < ii; i++) {
  23955. subrIndex.add(subrs[i]);
  23956. }
  23957. privateDict.subrsIndex = subrIndex;
  23958. var compiler = new CFFCompiler(cff);
  23959. return compiler.compile();
  23960. }
  23961. };
  23962. var CFFFont = (function CFFFontClosure() {
  23963. function CFFFont(file, properties) {
  23964. this.properties = properties;
  23965. var parser = new CFFParser(file, properties);
  23966. this.cff = parser.parse();
  23967. var compiler = new CFFCompiler(this.cff);
  23968. this.seacs = this.cff.seacs;
  23969. try {
  23970. this.data = compiler.compile();
  23971. } catch (e) {
  23972. warn('Failed to compile font ' + properties.loadedName);
  23973. // There may have just been an issue with the compiler, set the data
  23974. // anyway and hope the font loaded.
  23975. this.data = file;
  23976. }
  23977. }
  23978. CFFFont.prototype = {
  23979. get numGlyphs() {
  23980. return this.cff.charStrings.count;
  23981. },
  23982. getCharset: function CFFFont_getCharset() {
  23983. return this.cff.charset.charset;
  23984. },
  23985. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23986. var cff = this.cff;
  23987. var properties = this.properties;
  23988. var charsets = cff.charset.charset;
  23989. var charCodeToGlyphId;
  23990. var glyphId;
  23991. if (properties.composite) {
  23992. charCodeToGlyphId = Object.create(null);
  23993. if (cff.isCIDFont) {
  23994. // If the font is actually a CID font then we should use the charset
  23995. // to map CIDs to GIDs.
  23996. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23997. var cid = charsets[glyphId];
  23998. var charCode = properties.cMap.charCodeOf(cid);
  23999. charCodeToGlyphId[charCode] = glyphId;
  24000. }
  24001. } else {
  24002. // If it is NOT actually a CID font then CIDs should be mapped
  24003. // directly to GIDs.
  24004. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  24005. charCodeToGlyphId[glyphId] = glyphId;
  24006. }
  24007. }
  24008. return charCodeToGlyphId;
  24009. }
  24010. var encoding = cff.encoding ? cff.encoding.encoding : null;
  24011. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  24012. return charCodeToGlyphId;
  24013. }
  24014. };
  24015. return CFFFont;
  24016. })();
  24017. var CFFParser = (function CFFParserClosure() {
  24018. var CharstringValidationData = [
  24019. null,
  24020. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  24021. null,
  24022. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  24023. { id: 'vmoveto', min: 1, stackClearing: true },
  24024. { id: 'rlineto', min: 2, resetStack: true },
  24025. { id: 'hlineto', min: 1, resetStack: true },
  24026. { id: 'vlineto', min: 1, resetStack: true },
  24027. { id: 'rrcurveto', min: 6, resetStack: true },
  24028. null,
  24029. { id: 'callsubr', min: 1, undefStack: true },
  24030. { id: 'return', min: 0, undefStack: true },
  24031. null, // 12
  24032. null,
  24033. { id: 'endchar', min: 0, stackClearing: true },
  24034. null,
  24035. null,
  24036. null,
  24037. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  24038. { id: 'hintmask', min: 0, stackClearing: true },
  24039. { id: 'cntrmask', min: 0, stackClearing: true },
  24040. { id: 'rmoveto', min: 2, stackClearing: true },
  24041. { id: 'hmoveto', min: 1, stackClearing: true },
  24042. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  24043. { id: 'rcurveline', min: 8, resetStack: true },
  24044. { id: 'rlinecurve', min: 8, resetStack: true },
  24045. { id: 'vvcurveto', min: 4, resetStack: true },
  24046. { id: 'hhcurveto', min: 4, resetStack: true },
  24047. null, // shortint
  24048. { id: 'callgsubr', min: 1, undefStack: true },
  24049. { id: 'vhcurveto', min: 4, resetStack: true },
  24050. { id: 'hvcurveto', min: 4, resetStack: true }
  24051. ];
  24052. var CharstringValidationData12 = [
  24053. null,
  24054. null,
  24055. null,
  24056. { id: 'and', min: 2, stackDelta: -1 },
  24057. { id: 'or', min: 2, stackDelta: -1 },
  24058. { id: 'not', min: 1, stackDelta: 0 },
  24059. null,
  24060. null,
  24061. null,
  24062. { id: 'abs', min: 1, stackDelta: 0 },
  24063. { id: 'add', min: 2, stackDelta: -1,
  24064. stackFn: function stack_div(stack, index) {
  24065. stack[index - 2] = stack[index - 2] + stack[index - 1];
  24066. }
  24067. },
  24068. { id: 'sub', min: 2, stackDelta: -1,
  24069. stackFn: function stack_div(stack, index) {
  24070. stack[index - 2] = stack[index - 2] - stack[index - 1];
  24071. }
  24072. },
  24073. { id: 'div', min: 2, stackDelta: -1,
  24074. stackFn: function stack_div(stack, index) {
  24075. stack[index - 2] = stack[index - 2] / stack[index - 1];
  24076. }
  24077. },
  24078. null,
  24079. { id: 'neg', min: 1, stackDelta: 0,
  24080. stackFn: function stack_div(stack, index) {
  24081. stack[index - 1] = -stack[index - 1];
  24082. }
  24083. },
  24084. { id: 'eq', min: 2, stackDelta: -1 },
  24085. null,
  24086. null,
  24087. { id: 'drop', min: 1, stackDelta: -1 },
  24088. null,
  24089. { id: 'put', min: 2, stackDelta: -2 },
  24090. { id: 'get', min: 1, stackDelta: 0 },
  24091. { id: 'ifelse', min: 4, stackDelta: -3 },
  24092. { id: 'random', min: 0, stackDelta: 1 },
  24093. { id: 'mul', min: 2, stackDelta: -1,
  24094. stackFn: function stack_div(stack, index) {
  24095. stack[index - 2] = stack[index - 2] * stack[index - 1];
  24096. }
  24097. },
  24098. null,
  24099. { id: 'sqrt', min: 1, stackDelta: 0 },
  24100. { id: 'dup', min: 1, stackDelta: 1 },
  24101. { id: 'exch', min: 2, stackDelta: 0 },
  24102. { id: 'index', min: 2, stackDelta: 0 },
  24103. { id: 'roll', min: 3, stackDelta: -2 },
  24104. null,
  24105. null,
  24106. null,
  24107. { id: 'hflex', min: 7, resetStack: true },
  24108. { id: 'flex', min: 13, resetStack: true },
  24109. { id: 'hflex1', min: 9, resetStack: true },
  24110. { id: 'flex1', min: 11, resetStack: true }
  24111. ];
  24112. function CFFParser(file, properties) {
  24113. this.bytes = file.getBytes();
  24114. this.properties = properties;
  24115. }
  24116. CFFParser.prototype = {
  24117. parse: function CFFParser_parse() {
  24118. var properties = this.properties;
  24119. var cff = new CFF();
  24120. this.cff = cff;
  24121. // The first five sections must be in order, all the others are reached
  24122. // via offsets contained in one of the below.
  24123. var header = this.parseHeader();
  24124. var nameIndex = this.parseIndex(header.endPos);
  24125. var topDictIndex = this.parseIndex(nameIndex.endPos);
  24126. var stringIndex = this.parseIndex(topDictIndex.endPos);
  24127. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  24128. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  24129. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  24130. cff.header = header.obj;
  24131. cff.names = this.parseNameIndex(nameIndex.obj);
  24132. cff.strings = this.parseStringIndex(stringIndex.obj);
  24133. cff.topDict = topDict;
  24134. cff.globalSubrIndex = globalSubrIndex.obj;
  24135. this.parsePrivateDict(cff.topDict);
  24136. cff.isCIDFont = topDict.hasName('ROS');
  24137. var charStringOffset = topDict.getByName('CharStrings');
  24138. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  24139. cff.charStrings = charStringsAndSeacs.charStrings;
  24140. cff.seacs = charStringsAndSeacs.seacs;
  24141. cff.widths = charStringsAndSeacs.widths;
  24142. var fontMatrix = topDict.getByName('FontMatrix');
  24143. if (fontMatrix) {
  24144. properties.fontMatrix = fontMatrix;
  24145. }
  24146. var fontBBox = topDict.getByName('FontBBox');
  24147. if (fontBBox) {
  24148. // adjusting ascent/descent
  24149. properties.ascent = fontBBox[3];
  24150. properties.descent = fontBBox[1];
  24151. properties.ascentScaled = true;
  24152. }
  24153. var charset, encoding;
  24154. if (cff.isCIDFont) {
  24155. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  24156. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  24157. var dictRaw = fdArrayIndex.get(i);
  24158. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  24159. cff.strings);
  24160. this.parsePrivateDict(fontDict);
  24161. cff.fdArray.push(fontDict);
  24162. }
  24163. // cid fonts don't have an encoding
  24164. encoding = null;
  24165. charset = this.parseCharsets(topDict.getByName('charset'),
  24166. cff.charStrings.count, cff.strings, true);
  24167. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  24168. cff.charStrings.count);
  24169. } else {
  24170. charset = this.parseCharsets(topDict.getByName('charset'),
  24171. cff.charStrings.count, cff.strings, false);
  24172. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  24173. properties,
  24174. cff.strings, charset.charset);
  24175. }
  24176. cff.charset = charset;
  24177. cff.encoding = encoding;
  24178. return cff;
  24179. },
  24180. parseHeader: function CFFParser_parseHeader() {
  24181. var bytes = this.bytes;
  24182. var bytesLength = bytes.length;
  24183. var offset = 0;
  24184. // Prevent an infinite loop, by checking that the offset is within the
  24185. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  24186. while (offset < bytesLength && bytes[offset] !== 1) {
  24187. ++offset;
  24188. }
  24189. if (offset >= bytesLength) {
  24190. error('Invalid CFF header');
  24191. } else if (offset !== 0) {
  24192. info('cff data is shifted');
  24193. bytes = bytes.subarray(offset);
  24194. this.bytes = bytes;
  24195. }
  24196. var major = bytes[0];
  24197. var minor = bytes[1];
  24198. var hdrSize = bytes[2];
  24199. var offSize = bytes[3];
  24200. var header = new CFFHeader(major, minor, hdrSize, offSize);
  24201. return { obj: header, endPos: hdrSize };
  24202. },
  24203. parseDict: function CFFParser_parseDict(dict) {
  24204. var pos = 0;
  24205. function parseOperand() {
  24206. var value = dict[pos++];
  24207. if (value === 30) {
  24208. return parseFloatOperand(pos);
  24209. } else if (value === 28) {
  24210. value = dict[pos++];
  24211. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  24212. return value;
  24213. } else if (value === 29) {
  24214. value = dict[pos++];
  24215. value = (value << 8) | dict[pos++];
  24216. value = (value << 8) | dict[pos++];
  24217. value = (value << 8) | dict[pos++];
  24218. return value;
  24219. } else if (value >= 32 && value <= 246) {
  24220. return value - 139;
  24221. } else if (value >= 247 && value <= 250) {
  24222. return ((value - 247) * 256) + dict[pos++] + 108;
  24223. } else if (value >= 251 && value <= 254) {
  24224. return -((value - 251) * 256) - dict[pos++] - 108;
  24225. } else {
  24226. error('255 is not a valid DICT command');
  24227. }
  24228. return -1;
  24229. }
  24230. function parseFloatOperand() {
  24231. var str = '';
  24232. var eof = 15;
  24233. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  24234. '9', '.', 'E', 'E-', null, '-'];
  24235. var length = dict.length;
  24236. while (pos < length) {
  24237. var b = dict[pos++];
  24238. var b1 = b >> 4;
  24239. var b2 = b & 15;
  24240. if (b1 === eof) {
  24241. break;
  24242. }
  24243. str += lookup[b1];
  24244. if (b2 === eof) {
  24245. break;
  24246. }
  24247. str += lookup[b2];
  24248. }
  24249. return parseFloat(str);
  24250. }
  24251. var operands = [];
  24252. var entries = [];
  24253. pos = 0;
  24254. var end = dict.length;
  24255. while (pos < end) {
  24256. var b = dict[pos];
  24257. if (b <= 21) {
  24258. if (b === 12) {
  24259. b = (b << 8) | dict[++pos];
  24260. }
  24261. entries.push([b, operands]);
  24262. operands = [];
  24263. ++pos;
  24264. } else {
  24265. operands.push(parseOperand());
  24266. }
  24267. }
  24268. return entries;
  24269. },
  24270. parseIndex: function CFFParser_parseIndex(pos) {
  24271. var cffIndex = new CFFIndex();
  24272. var bytes = this.bytes;
  24273. var count = (bytes[pos++] << 8) | bytes[pos++];
  24274. var offsets = [];
  24275. var end = pos;
  24276. var i, ii;
  24277. if (count !== 0) {
  24278. var offsetSize = bytes[pos++];
  24279. // add 1 for offset to determine size of last object
  24280. var startPos = pos + ((count + 1) * offsetSize) - 1;
  24281. for (i = 0, ii = count + 1; i < ii; ++i) {
  24282. var offset = 0;
  24283. for (var j = 0; j < offsetSize; ++j) {
  24284. offset <<= 8;
  24285. offset += bytes[pos++];
  24286. }
  24287. offsets.push(startPos + offset);
  24288. }
  24289. end = offsets[count];
  24290. }
  24291. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  24292. var offsetStart = offsets[i];
  24293. var offsetEnd = offsets[i + 1];
  24294. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  24295. }
  24296. return {obj: cffIndex, endPos: end};
  24297. },
  24298. parseNameIndex: function CFFParser_parseNameIndex(index) {
  24299. var names = [];
  24300. for (var i = 0, ii = index.count; i < ii; ++i) {
  24301. var name = index.get(i);
  24302. // OTS doesn't allow names to be over 127 characters.
  24303. var length = Math.min(name.length, 127);
  24304. var data = [];
  24305. // OTS also only permits certain characters in the name.
  24306. for (var j = 0; j < length; ++j) {
  24307. var c = name[j];
  24308. if (j === 0 && c === 0) {
  24309. data[j] = c;
  24310. continue;
  24311. }
  24312. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  24313. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  24314. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  24315. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  24316. data[j] = 95;
  24317. continue;
  24318. }
  24319. data[j] = c;
  24320. }
  24321. names.push(bytesToString(data));
  24322. }
  24323. return names;
  24324. },
  24325. parseStringIndex: function CFFParser_parseStringIndex(index) {
  24326. var strings = new CFFStrings();
  24327. for (var i = 0, ii = index.count; i < ii; ++i) {
  24328. var data = index.get(i);
  24329. strings.add(bytesToString(data));
  24330. }
  24331. return strings;
  24332. },
  24333. createDict: function CFFParser_createDict(Type, dict, strings) {
  24334. var cffDict = new Type(strings);
  24335. for (var i = 0, ii = dict.length; i < ii; ++i) {
  24336. var pair = dict[i];
  24337. var key = pair[0];
  24338. var value = pair[1];
  24339. cffDict.setByKey(key, value);
  24340. }
  24341. return cffDict;
  24342. },
  24343. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  24344. var charStrings = this.parseIndex(charStringOffset).obj;
  24345. var seacs = [];
  24346. var widths = [];
  24347. var count = charStrings.count;
  24348. for (var i = 0; i < count; i++) {
  24349. var charstring = charStrings.get(i);
  24350. var stackSize = 0;
  24351. var stack = [];
  24352. var undefStack = true;
  24353. var hints = 0;
  24354. var valid = true;
  24355. var data = charstring;
  24356. var length = data.length;
  24357. var firstStackClearing = true;
  24358. for (var j = 0; j < length;) {
  24359. var value = data[j++];
  24360. var validationCommand = null;
  24361. if (value === 12) {
  24362. var q = data[j++];
  24363. if (q === 0) {
  24364. // The CFF specification state that the 'dotsection' command
  24365. // (12, 0) is deprecated and treated as a no-op, but all Type2
  24366. // charstrings processors should support them. Unfortunately
  24367. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24368. // is replaced by a useless (0, hmoveto).
  24369. data[j - 2] = 139;
  24370. data[j - 1] = 22;
  24371. stackSize = 0;
  24372. } else {
  24373. validationCommand = CharstringValidationData12[q];
  24374. }
  24375. } else if (value === 28) { // number (16 bit)
  24376. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24377. j += 2;
  24378. stackSize++;
  24379. } else if (value === 14) {
  24380. if (stackSize >= 4) {
  24381. stackSize -= 4;
  24382. if (SEAC_ANALYSIS_ENABLED) {
  24383. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24384. valid = false;
  24385. }
  24386. }
  24387. validationCommand = CharstringValidationData[value];
  24388. } else if (value >= 32 && value <= 246) { // number
  24389. stack[stackSize] = value - 139;
  24390. stackSize++;
  24391. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24392. stack[stackSize] = (value < 251 ?
  24393. ((value - 247) << 8) + data[j] + 108 :
  24394. -((value - 251) << 8) - data[j] - 108);
  24395. j++;
  24396. stackSize++;
  24397. } else if (value === 255) { // number (32 bit)
  24398. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24399. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24400. j += 4;
  24401. stackSize++;
  24402. } else if (value === 19 || value === 20) {
  24403. hints += stackSize >> 1;
  24404. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24405. stackSize %= 2;
  24406. validationCommand = CharstringValidationData[value];
  24407. } else {
  24408. validationCommand = CharstringValidationData[value];
  24409. }
  24410. if (validationCommand) {
  24411. if (validationCommand.stem) {
  24412. hints += stackSize >> 1;
  24413. }
  24414. if ('min' in validationCommand) {
  24415. if (!undefStack && stackSize < validationCommand.min) {
  24416. warn('Not enough parameters for ' + validationCommand.id +
  24417. '; actual: ' + stackSize +
  24418. ', expected: ' + validationCommand.min);
  24419. valid = false;
  24420. break;
  24421. }
  24422. }
  24423. if (firstStackClearing && validationCommand.stackClearing) {
  24424. firstStackClearing = false;
  24425. // the optional character width can be found before the first
  24426. // stack-clearing command arguments
  24427. stackSize -= validationCommand.min;
  24428. if (stackSize >= 2 && validationCommand.stem) {
  24429. // there are even amount of arguments for stem commands
  24430. stackSize %= 2;
  24431. } else if (stackSize > 1) {
  24432. warn('Found too many parameters for stack-clearing command');
  24433. }
  24434. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24435. widths[i] = stack[stackSize - 1];
  24436. }
  24437. }
  24438. if ('stackDelta' in validationCommand) {
  24439. if ('stackFn' in validationCommand) {
  24440. validationCommand.stackFn(stack, stackSize);
  24441. }
  24442. stackSize += validationCommand.stackDelta;
  24443. } else if (validationCommand.stackClearing) {
  24444. stackSize = 0;
  24445. } else if (validationCommand.resetStack) {
  24446. stackSize = 0;
  24447. undefStack = false;
  24448. } else if (validationCommand.undefStack) {
  24449. stackSize = 0;
  24450. undefStack = true;
  24451. firstStackClearing = false;
  24452. }
  24453. }
  24454. }
  24455. if (!valid) {
  24456. // resetting invalid charstring to single 'endchar'
  24457. charStrings.set(i, new Uint8Array([14]));
  24458. }
  24459. }
  24460. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24461. },
  24462. emptyPrivateDictionary:
  24463. function CFFParser_emptyPrivateDictionary(parentDict) {
  24464. var privateDict = this.createDict(CFFPrivateDict, [],
  24465. parentDict.strings);
  24466. parentDict.setByKey(18, [0, 0]);
  24467. parentDict.privateDict = privateDict;
  24468. },
  24469. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24470. // no private dict, do nothing
  24471. if (!parentDict.hasName('Private')) {
  24472. this.emptyPrivateDictionary(parentDict);
  24473. return;
  24474. }
  24475. var privateOffset = parentDict.getByName('Private');
  24476. // make sure the params are formatted correctly
  24477. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24478. parentDict.removeByName('Private');
  24479. return;
  24480. }
  24481. var size = privateOffset[0];
  24482. var offset = privateOffset[1];
  24483. // remove empty dicts or ones that refer to invalid location
  24484. if (size === 0 || offset >= this.bytes.length) {
  24485. this.emptyPrivateDictionary(parentDict);
  24486. return;
  24487. }
  24488. var privateDictEnd = offset + size;
  24489. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24490. var dict = this.parseDict(dictData);
  24491. var privateDict = this.createDict(CFFPrivateDict, dict,
  24492. parentDict.strings);
  24493. parentDict.privateDict = privateDict;
  24494. // Parse the Subrs index also since it's relative to the private dict.
  24495. if (!privateDict.getByName('Subrs')) {
  24496. return;
  24497. }
  24498. var subrsOffset = privateDict.getByName('Subrs');
  24499. var relativeOffset = offset + subrsOffset;
  24500. // Validate the offset.
  24501. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24502. this.emptyPrivateDictionary(parentDict);
  24503. return;
  24504. }
  24505. var subrsIndex = this.parseIndex(relativeOffset);
  24506. privateDict.subrsIndex = subrsIndex.obj;
  24507. },
  24508. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24509. if (pos === 0) {
  24510. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24511. ISOAdobeCharset);
  24512. } else if (pos === 1) {
  24513. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24514. ExpertCharset);
  24515. } else if (pos === 2) {
  24516. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24517. ExpertSubsetCharset);
  24518. }
  24519. var bytes = this.bytes;
  24520. var start = pos;
  24521. var format = bytes[pos++];
  24522. var charset = ['.notdef'];
  24523. var id, count, i;
  24524. // subtract 1 for the .notdef glyph
  24525. length -= 1;
  24526. switch (format) {
  24527. case 0:
  24528. for (i = 0; i < length; i++) {
  24529. id = (bytes[pos++] << 8) | bytes[pos++];
  24530. charset.push(cid ? id : strings.get(id));
  24531. }
  24532. break;
  24533. case 1:
  24534. while (charset.length <= length) {
  24535. id = (bytes[pos++] << 8) | bytes[pos++];
  24536. count = bytes[pos++];
  24537. for (i = 0; i <= count; i++) {
  24538. charset.push(cid ? id++ : strings.get(id++));
  24539. }
  24540. }
  24541. break;
  24542. case 2:
  24543. while (charset.length <= length) {
  24544. id = (bytes[pos++] << 8) | bytes[pos++];
  24545. count = (bytes[pos++] << 8) | bytes[pos++];
  24546. for (i = 0; i <= count; i++) {
  24547. charset.push(cid ? id++ : strings.get(id++));
  24548. }
  24549. }
  24550. break;
  24551. default:
  24552. error('Unknown charset format');
  24553. }
  24554. // Raw won't be needed if we actually compile the charset.
  24555. var end = pos;
  24556. var raw = bytes.subarray(start, end);
  24557. return new CFFCharset(false, format, charset, raw);
  24558. },
  24559. parseEncoding: function CFFParser_parseEncoding(pos,
  24560. properties,
  24561. strings,
  24562. charset) {
  24563. var encoding = {};
  24564. var bytes = this.bytes;
  24565. var predefined = false;
  24566. var hasSupplement = false;
  24567. var format, i, ii;
  24568. var raw = null;
  24569. function readSupplement() {
  24570. var supplementsCount = bytes[pos++];
  24571. for (i = 0; i < supplementsCount; i++) {
  24572. var code = bytes[pos++];
  24573. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24574. encoding[code] = charset.indexOf(strings.get(sid));
  24575. }
  24576. }
  24577. if (pos === 0 || pos === 1) {
  24578. predefined = true;
  24579. format = pos;
  24580. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24581. Encodings.StandardEncoding;
  24582. for (i = 0, ii = charset.length; i < ii; i++) {
  24583. var index = baseEncoding.indexOf(charset[i]);
  24584. if (index !== -1) {
  24585. encoding[index] = i;
  24586. }
  24587. }
  24588. } else {
  24589. var dataStart = pos;
  24590. format = bytes[pos++];
  24591. switch (format & 0x7f) {
  24592. case 0:
  24593. var glyphsCount = bytes[pos++];
  24594. for (i = 1; i <= glyphsCount; i++) {
  24595. encoding[bytes[pos++]] = i;
  24596. }
  24597. break;
  24598. case 1:
  24599. var rangesCount = bytes[pos++];
  24600. var gid = 1;
  24601. for (i = 0; i < rangesCount; i++) {
  24602. var start = bytes[pos++];
  24603. var left = bytes[pos++];
  24604. for (var j = start; j <= start + left; j++) {
  24605. encoding[j] = gid++;
  24606. }
  24607. }
  24608. break;
  24609. default:
  24610. error('Unknow encoding format: ' + format + ' in CFF');
  24611. break;
  24612. }
  24613. var dataEnd = pos;
  24614. if (format & 0x80) {
  24615. // The font sanitizer does not support CFF encoding with a
  24616. // supplement, since the encoding is not really used to map
  24617. // between gid to glyph, let's overwrite what is declared in
  24618. // the top dictionary to let the sanitizer think the font use
  24619. // StandardEncoding, that's a lie but that's ok.
  24620. bytes[dataStart] &= 0x7f;
  24621. readSupplement();
  24622. hasSupplement = true;
  24623. }
  24624. raw = bytes.subarray(dataStart, dataEnd);
  24625. }
  24626. format = format & 0x7f;
  24627. return new CFFEncoding(predefined, format, encoding, raw);
  24628. },
  24629. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24630. var start = pos;
  24631. var bytes = this.bytes;
  24632. var format = bytes[pos++];
  24633. var fdSelect = [];
  24634. var i;
  24635. switch (format) {
  24636. case 0:
  24637. for (i = 0; i < length; ++i) {
  24638. var id = bytes[pos++];
  24639. fdSelect.push(id);
  24640. }
  24641. break;
  24642. case 3:
  24643. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24644. for (i = 0; i < rangesCount; ++i) {
  24645. var first = (bytes[pos++] << 8) | bytes[pos++];
  24646. var fdIndex = bytes[pos++];
  24647. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24648. for (var j = first; j < next; ++j) {
  24649. fdSelect.push(fdIndex);
  24650. }
  24651. }
  24652. // Advance past the sentinel(next).
  24653. pos += 2;
  24654. break;
  24655. default:
  24656. error('Unknown fdselect format ' + format);
  24657. break;
  24658. }
  24659. var end = pos;
  24660. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24661. }
  24662. };
  24663. return CFFParser;
  24664. })();
  24665. // Compact Font Format
  24666. var CFF = (function CFFClosure() {
  24667. function CFF() {
  24668. this.header = null;
  24669. this.names = [];
  24670. this.topDict = null;
  24671. this.strings = new CFFStrings();
  24672. this.globalSubrIndex = null;
  24673. // The following could really be per font, but since we only have one font
  24674. // store them here.
  24675. this.encoding = null;
  24676. this.charset = null;
  24677. this.charStrings = null;
  24678. this.fdArray = [];
  24679. this.fdSelect = null;
  24680. this.isCIDFont = false;
  24681. }
  24682. return CFF;
  24683. })();
  24684. var CFFHeader = (function CFFHeaderClosure() {
  24685. function CFFHeader(major, minor, hdrSize, offSize) {
  24686. this.major = major;
  24687. this.minor = minor;
  24688. this.hdrSize = hdrSize;
  24689. this.offSize = offSize;
  24690. }
  24691. return CFFHeader;
  24692. })();
  24693. var CFFStrings = (function CFFStringsClosure() {
  24694. function CFFStrings() {
  24695. this.strings = [];
  24696. }
  24697. CFFStrings.prototype = {
  24698. get: function CFFStrings_get(index) {
  24699. if (index >= 0 && index <= 390) {
  24700. return CFFStandardStrings[index];
  24701. }
  24702. if (index - 391 <= this.strings.length) {
  24703. return this.strings[index - 391];
  24704. }
  24705. return CFFStandardStrings[0];
  24706. },
  24707. add: function CFFStrings_add(value) {
  24708. this.strings.push(value);
  24709. },
  24710. get count() {
  24711. return this.strings.length;
  24712. }
  24713. };
  24714. return CFFStrings;
  24715. })();
  24716. var CFFIndex = (function CFFIndexClosure() {
  24717. function CFFIndex() {
  24718. this.objects = [];
  24719. this.length = 0;
  24720. }
  24721. CFFIndex.prototype = {
  24722. add: function CFFIndex_add(data) {
  24723. this.length += data.length;
  24724. this.objects.push(data);
  24725. },
  24726. set: function CFFIndex_set(index, data) {
  24727. this.length += data.length - this.objects[index].length;
  24728. this.objects[index] = data;
  24729. },
  24730. get: function CFFIndex_get(index) {
  24731. return this.objects[index];
  24732. },
  24733. get count() {
  24734. return this.objects.length;
  24735. }
  24736. };
  24737. return CFFIndex;
  24738. })();
  24739. var CFFDict = (function CFFDictClosure() {
  24740. function CFFDict(tables, strings) {
  24741. this.keyToNameMap = tables.keyToNameMap;
  24742. this.nameToKeyMap = tables.nameToKeyMap;
  24743. this.defaults = tables.defaults;
  24744. this.types = tables.types;
  24745. this.opcodes = tables.opcodes;
  24746. this.order = tables.order;
  24747. this.strings = strings;
  24748. this.values = {};
  24749. }
  24750. CFFDict.prototype = {
  24751. // value should always be an array
  24752. setByKey: function CFFDict_setByKey(key, value) {
  24753. if (!(key in this.keyToNameMap)) {
  24754. return false;
  24755. }
  24756. // ignore empty values
  24757. if (value.length === 0) {
  24758. return true;
  24759. }
  24760. var type = this.types[key];
  24761. // remove the array wrapping these types of values
  24762. if (type === 'num' || type === 'sid' || type === 'offset') {
  24763. value = value[0];
  24764. }
  24765. this.values[key] = value;
  24766. return true;
  24767. },
  24768. setByName: function CFFDict_setByName(name, value) {
  24769. if (!(name in this.nameToKeyMap)) {
  24770. error('Invalid dictionary name "' + name + '"');
  24771. }
  24772. this.values[this.nameToKeyMap[name]] = value;
  24773. },
  24774. hasName: function CFFDict_hasName(name) {
  24775. return this.nameToKeyMap[name] in this.values;
  24776. },
  24777. getByName: function CFFDict_getByName(name) {
  24778. if (!(name in this.nameToKeyMap)) {
  24779. error('Invalid dictionary name "' + name + '"');
  24780. }
  24781. var key = this.nameToKeyMap[name];
  24782. if (!(key in this.values)) {
  24783. return this.defaults[key];
  24784. }
  24785. return this.values[key];
  24786. },
  24787. removeByName: function CFFDict_removeByName(name) {
  24788. delete this.values[this.nameToKeyMap[name]];
  24789. }
  24790. };
  24791. CFFDict.createTables = function CFFDict_createTables(layout) {
  24792. var tables = {
  24793. keyToNameMap: {},
  24794. nameToKeyMap: {},
  24795. defaults: {},
  24796. types: {},
  24797. opcodes: {},
  24798. order: []
  24799. };
  24800. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24801. var entry = layout[i];
  24802. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24803. tables.keyToNameMap[key] = entry[1];
  24804. tables.nameToKeyMap[entry[1]] = key;
  24805. tables.types[key] = entry[2];
  24806. tables.defaults[key] = entry[3];
  24807. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24808. tables.order.push(key);
  24809. }
  24810. return tables;
  24811. };
  24812. return CFFDict;
  24813. })();
  24814. var CFFTopDict = (function CFFTopDictClosure() {
  24815. var layout = [
  24816. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24817. [[12, 20], 'SyntheticBase', 'num', null],
  24818. [0, 'version', 'sid', null],
  24819. [1, 'Notice', 'sid', null],
  24820. [[12, 0], 'Copyright', 'sid', null],
  24821. [2, 'FullName', 'sid', null],
  24822. [3, 'FamilyName', 'sid', null],
  24823. [4, 'Weight', 'sid', null],
  24824. [[12, 1], 'isFixedPitch', 'num', 0],
  24825. [[12, 2], 'ItalicAngle', 'num', 0],
  24826. [[12, 3], 'UnderlinePosition', 'num', -100],
  24827. [[12, 4], 'UnderlineThickness', 'num', 50],
  24828. [[12, 5], 'PaintType', 'num', 0],
  24829. [[12, 6], 'CharstringType', 'num', 2],
  24830. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24831. [0.001, 0, 0, 0.001, 0, 0]],
  24832. [13, 'UniqueID', 'num', null],
  24833. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24834. [[12, 8], 'StrokeWidth', 'num', 0],
  24835. [14, 'XUID', 'array', null],
  24836. [15, 'charset', 'offset', 0],
  24837. [16, 'Encoding', 'offset', 0],
  24838. [17, 'CharStrings', 'offset', 0],
  24839. [18, 'Private', ['offset', 'offset'], null],
  24840. [[12, 21], 'PostScript', 'sid', null],
  24841. [[12, 22], 'BaseFontName', 'sid', null],
  24842. [[12, 23], 'BaseFontBlend', 'delta', null],
  24843. [[12, 31], 'CIDFontVersion', 'num', 0],
  24844. [[12, 32], 'CIDFontRevision', 'num', 0],
  24845. [[12, 33], 'CIDFontType', 'num', 0],
  24846. [[12, 34], 'CIDCount', 'num', 8720],
  24847. [[12, 35], 'UIDBase', 'num', null],
  24848. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24849. // before FDArray.
  24850. [[12, 37], 'FDSelect', 'offset', null],
  24851. [[12, 36], 'FDArray', 'offset', null],
  24852. [[12, 38], 'FontName', 'sid', null]
  24853. ];
  24854. var tables = null;
  24855. function CFFTopDict(strings) {
  24856. if (tables === null) {
  24857. tables = CFFDict.createTables(layout);
  24858. }
  24859. CFFDict.call(this, tables, strings);
  24860. this.privateDict = null;
  24861. }
  24862. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24863. return CFFTopDict;
  24864. })();
  24865. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24866. var layout = [
  24867. [6, 'BlueValues', 'delta', null],
  24868. [7, 'OtherBlues', 'delta', null],
  24869. [8, 'FamilyBlues', 'delta', null],
  24870. [9, 'FamilyOtherBlues', 'delta', null],
  24871. [[12, 9], 'BlueScale', 'num', 0.039625],
  24872. [[12, 10], 'BlueShift', 'num', 7],
  24873. [[12, 11], 'BlueFuzz', 'num', 1],
  24874. [10, 'StdHW', 'num', null],
  24875. [11, 'StdVW', 'num', null],
  24876. [[12, 12], 'StemSnapH', 'delta', null],
  24877. [[12, 13], 'StemSnapV', 'delta', null],
  24878. [[12, 14], 'ForceBold', 'num', 0],
  24879. [[12, 17], 'LanguageGroup', 'num', 0],
  24880. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24881. [[12, 19], 'initialRandomSeed', 'num', 0],
  24882. [20, 'defaultWidthX', 'num', 0],
  24883. [21, 'nominalWidthX', 'num', 0],
  24884. [19, 'Subrs', 'offset', null]
  24885. ];
  24886. var tables = null;
  24887. function CFFPrivateDict(strings) {
  24888. if (tables === null) {
  24889. tables = CFFDict.createTables(layout);
  24890. }
  24891. CFFDict.call(this, tables, strings);
  24892. this.subrsIndex = null;
  24893. }
  24894. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24895. return CFFPrivateDict;
  24896. })();
  24897. var CFFCharsetPredefinedTypes = {
  24898. ISO_ADOBE: 0,
  24899. EXPERT: 1,
  24900. EXPERT_SUBSET: 2
  24901. };
  24902. var CFFCharset = (function CFFCharsetClosure() {
  24903. function CFFCharset(predefined, format, charset, raw) {
  24904. this.predefined = predefined;
  24905. this.format = format;
  24906. this.charset = charset;
  24907. this.raw = raw;
  24908. }
  24909. return CFFCharset;
  24910. })();
  24911. var CFFEncoding = (function CFFEncodingClosure() {
  24912. function CFFEncoding(predefined, format, encoding, raw) {
  24913. this.predefined = predefined;
  24914. this.format = format;
  24915. this.encoding = encoding;
  24916. this.raw = raw;
  24917. }
  24918. return CFFEncoding;
  24919. })();
  24920. var CFFFDSelect = (function CFFFDSelectClosure() {
  24921. function CFFFDSelect(fdSelect, raw) {
  24922. this.fdSelect = fdSelect;
  24923. this.raw = raw;
  24924. }
  24925. return CFFFDSelect;
  24926. })();
  24927. // Helper class to keep track of where an offset is within the data and helps
  24928. // filling in that offset once it's known.
  24929. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24930. function CFFOffsetTracker() {
  24931. this.offsets = {};
  24932. }
  24933. CFFOffsetTracker.prototype = {
  24934. isTracking: function CFFOffsetTracker_isTracking(key) {
  24935. return key in this.offsets;
  24936. },
  24937. track: function CFFOffsetTracker_track(key, location) {
  24938. if (key in this.offsets) {
  24939. error('Already tracking location of ' + key);
  24940. }
  24941. this.offsets[key] = location;
  24942. },
  24943. offset: function CFFOffsetTracker_offset(value) {
  24944. for (var key in this.offsets) {
  24945. this.offsets[key] += value;
  24946. }
  24947. },
  24948. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  24949. values,
  24950. output) {
  24951. if (!(key in this.offsets)) {
  24952. error('Not tracking location of ' + key);
  24953. }
  24954. var data = output.data;
  24955. var dataOffset = this.offsets[key];
  24956. var size = 5;
  24957. for (var i = 0, ii = values.length; i < ii; ++i) {
  24958. var offset0 = i * size + dataOffset;
  24959. var offset1 = offset0 + 1;
  24960. var offset2 = offset0 + 2;
  24961. var offset3 = offset0 + 3;
  24962. var offset4 = offset0 + 4;
  24963. // It's easy to screw up offsets so perform this sanity check.
  24964. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24965. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24966. error('writing to an offset that is not empty');
  24967. }
  24968. var value = values[i];
  24969. data[offset0] = 0x1d;
  24970. data[offset1] = (value >> 24) & 0xFF;
  24971. data[offset2] = (value >> 16) & 0xFF;
  24972. data[offset3] = (value >> 8) & 0xFF;
  24973. data[offset4] = value & 0xFF;
  24974. }
  24975. }
  24976. };
  24977. return CFFOffsetTracker;
  24978. })();
  24979. // Takes a CFF and converts it to the binary representation.
  24980. var CFFCompiler = (function CFFCompilerClosure() {
  24981. function CFFCompiler(cff) {
  24982. this.cff = cff;
  24983. }
  24984. CFFCompiler.prototype = {
  24985. compile: function CFFCompiler_compile() {
  24986. var cff = this.cff;
  24987. var output = {
  24988. data: [],
  24989. length: 0,
  24990. add: function CFFCompiler_add(data) {
  24991. this.data = this.data.concat(data);
  24992. this.length = this.data.length;
  24993. }
  24994. };
  24995. // Compile the five entries that must be in order.
  24996. var header = this.compileHeader(cff.header);
  24997. output.add(header);
  24998. var nameIndex = this.compileNameIndex(cff.names);
  24999. output.add(nameIndex);
  25000. if (cff.isCIDFont) {
  25001. // The spec is unclear on how font matrices should relate to each other
  25002. // when there is one in the main top dict and the sub top dicts.
  25003. // Windows handles this differently than linux and osx so we have to
  25004. // normalize to work on all.
  25005. // Rules based off of some mailing list discussions:
  25006. // - If main font has a matrix and subfont doesn't, use the main matrix.
  25007. // - If no main font matrix and there is a subfont matrix, use the
  25008. // subfont matrix.
  25009. // - If both have matrices, concat together.
  25010. // - If neither have matrices, use default.
  25011. // To make this work on all platforms we move the top matrix into each
  25012. // sub top dict and concat if necessary.
  25013. if (cff.topDict.hasName('FontMatrix')) {
  25014. var base = cff.topDict.getByName('FontMatrix');
  25015. cff.topDict.removeByName('FontMatrix');
  25016. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  25017. var subDict = cff.fdArray[i];
  25018. var matrix = base.slice(0);
  25019. if (subDict.hasName('FontMatrix')) {
  25020. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  25021. }
  25022. subDict.setByName('FontMatrix', matrix);
  25023. }
  25024. }
  25025. }
  25026. var compiled = this.compileTopDicts([cff.topDict],
  25027. output.length,
  25028. cff.isCIDFont);
  25029. output.add(compiled.output);
  25030. var topDictTracker = compiled.trackers[0];
  25031. var stringIndex = this.compileStringIndex(cff.strings.strings);
  25032. output.add(stringIndex);
  25033. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  25034. output.add(globalSubrIndex);
  25035. // Now start on the other entries that have no specfic order.
  25036. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  25037. if (cff.encoding.predefined) {
  25038. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  25039. output);
  25040. } else {
  25041. var encoding = this.compileEncoding(cff.encoding);
  25042. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  25043. output.add(encoding);
  25044. }
  25045. }
  25046. if (cff.charset && cff.topDict.hasName('charset')) {
  25047. if (cff.charset.predefined) {
  25048. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  25049. output);
  25050. } else {
  25051. var charset = this.compileCharset(cff.charset);
  25052. topDictTracker.setEntryLocation('charset', [output.length], output);
  25053. output.add(charset);
  25054. }
  25055. }
  25056. var charStrings = this.compileCharStrings(cff.charStrings);
  25057. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  25058. output.add(charStrings);
  25059. if (cff.isCIDFont) {
  25060. // For some reason FDSelect must be in front of FDArray on windows. OSX
  25061. // and linux don't seem to care.
  25062. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  25063. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  25064. output.add(fdSelect);
  25065. // It is unclear if the sub font dictionary can have CID related
  25066. // dictionary keys, but the sanitizer doesn't like them so remove them.
  25067. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  25068. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  25069. output.add(compiled.output);
  25070. var fontDictTrackers = compiled.trackers;
  25071. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  25072. }
  25073. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  25074. // If the font data ends with INDEX whose object data is zero-length,
  25075. // the sanitizer will bail out. Add a dummy byte to avoid that.
  25076. output.add([0]);
  25077. return output.data;
  25078. },
  25079. encodeNumber: function CFFCompiler_encodeNumber(value) {
  25080. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  25081. return this.encodeInteger(value);
  25082. } else {
  25083. return this.encodeFloat(value);
  25084. }
  25085. },
  25086. encodeFloat: function CFFCompiler_encodeFloat(num) {
  25087. var value = num.toString();
  25088. // rounding inaccurate doubles
  25089. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  25090. if (m) {
  25091. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  25092. value = (Math.round(num * epsilon) / epsilon).toString();
  25093. }
  25094. var nibbles = '';
  25095. var i, ii;
  25096. for (i = 0, ii = value.length; i < ii; ++i) {
  25097. var a = value[i];
  25098. if (a === 'e') {
  25099. nibbles += value[++i] === '-' ? 'c' : 'b';
  25100. } else if (a === '.') {
  25101. nibbles += 'a';
  25102. } else if (a === '-') {
  25103. nibbles += 'e';
  25104. } else {
  25105. nibbles += a;
  25106. }
  25107. }
  25108. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  25109. var out = [30];
  25110. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  25111. out.push(parseInt(nibbles.substr(i, 2), 16));
  25112. }
  25113. return out;
  25114. },
  25115. encodeInteger: function CFFCompiler_encodeInteger(value) {
  25116. var code;
  25117. if (value >= -107 && value <= 107) {
  25118. code = [value + 139];
  25119. } else if (value >= 108 && value <= 1131) {
  25120. value = [value - 108];
  25121. code = [(value >> 8) + 247, value & 0xFF];
  25122. } else if (value >= -1131 && value <= -108) {
  25123. value = -value - 108;
  25124. code = [(value >> 8) + 251, value & 0xFF];
  25125. } else if (value >= -32768 && value <= 32767) {
  25126. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  25127. } else {
  25128. code = [0x1d,
  25129. (value >> 24) & 0xFF,
  25130. (value >> 16) & 0xFF,
  25131. (value >> 8) & 0xFF,
  25132. value & 0xFF];
  25133. }
  25134. return code;
  25135. },
  25136. compileHeader: function CFFCompiler_compileHeader(header) {
  25137. return [
  25138. header.major,
  25139. header.minor,
  25140. header.hdrSize,
  25141. header.offSize
  25142. ];
  25143. },
  25144. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  25145. var nameIndex = new CFFIndex();
  25146. for (var i = 0, ii = names.length; i < ii; ++i) {
  25147. nameIndex.add(stringToBytes(names[i]));
  25148. }
  25149. return this.compileIndex(nameIndex);
  25150. },
  25151. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  25152. length,
  25153. removeCidKeys) {
  25154. var fontDictTrackers = [];
  25155. var fdArrayIndex = new CFFIndex();
  25156. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25157. var fontDict = dicts[i];
  25158. if (removeCidKeys) {
  25159. fontDict.removeByName('CIDFontVersion');
  25160. fontDict.removeByName('CIDFontRevision');
  25161. fontDict.removeByName('CIDFontType');
  25162. fontDict.removeByName('CIDCount');
  25163. fontDict.removeByName('UIDBase');
  25164. }
  25165. var fontDictTracker = new CFFOffsetTracker();
  25166. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  25167. fontDictTrackers.push(fontDictTracker);
  25168. fdArrayIndex.add(fontDictData);
  25169. fontDictTracker.offset(length);
  25170. }
  25171. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  25172. return {
  25173. trackers: fontDictTrackers,
  25174. output: fdArrayIndex
  25175. };
  25176. },
  25177. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  25178. trackers,
  25179. output) {
  25180. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25181. var fontDict = dicts[i];
  25182. assert(fontDict.privateDict && fontDict.hasName('Private'),
  25183. 'There must be an private dictionary.');
  25184. var privateDict = fontDict.privateDict;
  25185. var privateDictTracker = new CFFOffsetTracker();
  25186. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  25187. var outputLength = output.length;
  25188. privateDictTracker.offset(outputLength);
  25189. if (!privateDictData.length) {
  25190. // The private dictionary was empty, set the output length to zero to
  25191. // ensure the offset length isn't out of bounds in the eyes of the
  25192. // sanitizer.
  25193. outputLength = 0;
  25194. }
  25195. trackers[i].setEntryLocation('Private',
  25196. [privateDictData.length, outputLength],
  25197. output);
  25198. output.add(privateDictData);
  25199. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  25200. var subrs = this.compileIndex(privateDict.subrsIndex);
  25201. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  25202. output);
  25203. output.add(subrs);
  25204. }
  25205. }
  25206. },
  25207. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  25208. var out = [];
  25209. // The dictionary keys must be in a certain order.
  25210. var order = dict.order;
  25211. for (var i = 0; i < order.length; ++i) {
  25212. var key = order[i];
  25213. if (!(key in dict.values)) {
  25214. continue;
  25215. }
  25216. var values = dict.values[key];
  25217. var types = dict.types[key];
  25218. if (!isArray(types)) {
  25219. types = [types];
  25220. }
  25221. if (!isArray(values)) {
  25222. values = [values];
  25223. }
  25224. // Remove any empty dict values.
  25225. if (values.length === 0) {
  25226. continue;
  25227. }
  25228. for (var j = 0, jj = types.length; j < jj; ++j) {
  25229. var type = types[j];
  25230. var value = values[j];
  25231. switch (type) {
  25232. case 'num':
  25233. case 'sid':
  25234. out = out.concat(this.encodeNumber(value));
  25235. break;
  25236. case 'offset':
  25237. // For offsets we just insert a 32bit integer so we don't have to
  25238. // deal with figuring out the length of the offset when it gets
  25239. // replaced later on by the compiler.
  25240. var name = dict.keyToNameMap[key];
  25241. // Some offsets have the offset and the length, so just record the
  25242. // position of the first one.
  25243. if (!offsetTracker.isTracking(name)) {
  25244. offsetTracker.track(name, out.length);
  25245. }
  25246. out = out.concat([0x1d, 0, 0, 0, 0]);
  25247. break;
  25248. case 'array':
  25249. case 'delta':
  25250. out = out.concat(this.encodeNumber(value));
  25251. for (var k = 1, kk = values.length; k < kk; ++k) {
  25252. out = out.concat(this.encodeNumber(values[k]));
  25253. }
  25254. break;
  25255. default:
  25256. error('Unknown data type of ' + type);
  25257. break;
  25258. }
  25259. }
  25260. out = out.concat(dict.opcodes[key]);
  25261. }
  25262. return out;
  25263. },
  25264. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  25265. var stringIndex = new CFFIndex();
  25266. for (var i = 0, ii = strings.length; i < ii; ++i) {
  25267. stringIndex.add(stringToBytes(strings[i]));
  25268. }
  25269. return this.compileIndex(stringIndex);
  25270. },
  25271. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  25272. var globalSubrIndex = this.cff.globalSubrIndex;
  25273. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  25274. },
  25275. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  25276. return this.compileIndex(charStrings);
  25277. },
  25278. compileCharset: function CFFCompiler_compileCharset(charset) {
  25279. return this.compileTypedArray(charset.raw);
  25280. },
  25281. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  25282. return this.compileTypedArray(encoding.raw);
  25283. },
  25284. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  25285. return this.compileTypedArray(fdSelect);
  25286. },
  25287. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  25288. var out = [];
  25289. for (var i = 0, ii = data.length; i < ii; ++i) {
  25290. out[i] = data[i];
  25291. }
  25292. return out;
  25293. },
  25294. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  25295. trackers = trackers || [];
  25296. var objects = index.objects;
  25297. // First 2 bytes contains the number of objects contained into this index
  25298. var count = objects.length;
  25299. // If there is no object, just create an index. This technically
  25300. // should just be [0, 0] but OTS has an issue with that.
  25301. if (count === 0) {
  25302. return [0, 0, 0];
  25303. }
  25304. var data = [(count >> 8) & 0xFF, count & 0xff];
  25305. var lastOffset = 1, i;
  25306. for (i = 0; i < count; ++i) {
  25307. lastOffset += objects[i].length;
  25308. }
  25309. var offsetSize;
  25310. if (lastOffset < 0x100) {
  25311. offsetSize = 1;
  25312. } else if (lastOffset < 0x10000) {
  25313. offsetSize = 2;
  25314. } else if (lastOffset < 0x1000000) {
  25315. offsetSize = 3;
  25316. } else {
  25317. offsetSize = 4;
  25318. }
  25319. // Next byte contains the offset size use to reference object in the file
  25320. data.push(offsetSize);
  25321. // Add another offset after this one because we need a new offset
  25322. var relativeOffset = 1;
  25323. for (i = 0; i < count + 1; i++) {
  25324. if (offsetSize === 1) {
  25325. data.push(relativeOffset & 0xFF);
  25326. } else if (offsetSize === 2) {
  25327. data.push((relativeOffset >> 8) & 0xFF,
  25328. relativeOffset & 0xFF);
  25329. } else if (offsetSize === 3) {
  25330. data.push((relativeOffset >> 16) & 0xFF,
  25331. (relativeOffset >> 8) & 0xFF,
  25332. relativeOffset & 0xFF);
  25333. } else {
  25334. data.push((relativeOffset >>> 24) & 0xFF,
  25335. (relativeOffset >> 16) & 0xFF,
  25336. (relativeOffset >> 8) & 0xFF,
  25337. relativeOffset & 0xFF);
  25338. }
  25339. if (objects[i]) {
  25340. relativeOffset += objects[i].length;
  25341. }
  25342. }
  25343. for (i = 0; i < count; i++) {
  25344. // Notify the tracker where the object will be offset in the data.
  25345. if (trackers[i]) {
  25346. trackers[i].offset(data.length);
  25347. }
  25348. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  25349. data.push(objects[i][j]);
  25350. }
  25351. }
  25352. return data;
  25353. }
  25354. };
  25355. return CFFCompiler;
  25356. })();
  25357. // Workaround for seac on Windows.
  25358. (function checkSeacSupport() {
  25359. if (/Windows/.test(navigator.userAgent)) {
  25360. SEAC_ANALYSIS_ENABLED = true;
  25361. }
  25362. })();
  25363. // Workaround for Private Use Area characters in Chrome on Windows
  25364. // http://code.google.com/p/chromium/issues/detail?id=122465
  25365. // https://github.com/mozilla/pdf.js/issues/1689
  25366. (function checkChromeWindows() {
  25367. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25368. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25369. }
  25370. })();
  25371. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25372. function getLong(data, offset) {
  25373. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25374. (data[offset + 2] << 8) | data[offset + 3];
  25375. }
  25376. function getUshort(data, offset) {
  25377. return (data[offset] << 8) | data[offset + 1];
  25378. }
  25379. function parseCmap(data, start, end) {
  25380. var offset = (getUshort(data, start + 2) === 1 ?
  25381. getLong(data, start + 8) : getLong(data, start + 16));
  25382. var format = getUshort(data, start + offset);
  25383. var length, ranges, p, i;
  25384. if (format === 4) {
  25385. length = getUshort(data, start + offset + 2);
  25386. var segCount = getUshort(data, start + offset + 6) >> 1;
  25387. p = start + offset + 14;
  25388. ranges = [];
  25389. for (i = 0; i < segCount; i++, p += 2) {
  25390. ranges[i] = {end: getUshort(data, p)};
  25391. }
  25392. p += 2;
  25393. for (i = 0; i < segCount; i++, p += 2) {
  25394. ranges[i].start = getUshort(data, p);
  25395. }
  25396. for (i = 0; i < segCount; i++, p += 2) {
  25397. ranges[i].idDelta = getUshort(data, p);
  25398. }
  25399. for (i = 0; i < segCount; i++, p += 2) {
  25400. var idOffset = getUshort(data, p);
  25401. if (idOffset === 0) {
  25402. continue;
  25403. }
  25404. ranges[i].ids = [];
  25405. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25406. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25407. idOffset += 2;
  25408. }
  25409. }
  25410. return ranges;
  25411. } else if (format === 12) {
  25412. length = getLong(data, start + offset + 4);
  25413. var groups = getLong(data, start + offset + 12);
  25414. p = start + offset + 16;
  25415. ranges = [];
  25416. for (i = 0; i < groups; i++) {
  25417. ranges.push({
  25418. start: getLong(data, p),
  25419. end: getLong(data, p + 4),
  25420. idDelta: getLong(data, p + 8) - getLong(data, p)
  25421. });
  25422. p += 12;
  25423. }
  25424. return ranges;
  25425. }
  25426. error('not supported cmap: ' + format);
  25427. }
  25428. function parseCff(data, start, end) {
  25429. var properties = {};
  25430. var parser = new CFFParser(new Stream(data, start, end - start),
  25431. properties);
  25432. var cff = parser.parse();
  25433. return {
  25434. glyphs: cff.charStrings.objects,
  25435. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25436. cff.topDict.privateDict.subrsIndex.objects),
  25437. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25438. };
  25439. }
  25440. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25441. var itemSize, itemDecode;
  25442. if (isGlyphLocationsLong) {
  25443. itemSize = 4;
  25444. itemDecode = function fontItemDecodeLong(data, offset) {
  25445. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25446. (data[offset + 2] << 8) | data[offset + 3];
  25447. };
  25448. } else {
  25449. itemSize = 2;
  25450. itemDecode = function fontItemDecode(data, offset) {
  25451. return (data[offset] << 9) | (data[offset + 1] << 1);
  25452. };
  25453. }
  25454. var glyphs = [];
  25455. var startOffset = itemDecode(loca, 0);
  25456. for (var j = itemSize; j < loca.length; j += itemSize) {
  25457. var endOffset = itemDecode(loca, j);
  25458. glyphs.push(glyf.subarray(startOffset, endOffset));
  25459. startOffset = endOffset;
  25460. }
  25461. return glyphs;
  25462. }
  25463. function lookupCmap(ranges, unicode) {
  25464. var code = unicode.charCodeAt(0);
  25465. var l = 0, r = ranges.length - 1;
  25466. while (l < r) {
  25467. var c = (l + r + 1) >> 1;
  25468. if (code < ranges[c].start) {
  25469. r = c - 1;
  25470. } else {
  25471. l = c;
  25472. }
  25473. }
  25474. if (ranges[l].start <= code && code <= ranges[l].end) {
  25475. return (ranges[l].idDelta + (ranges[l].ids ?
  25476. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25477. }
  25478. return 0;
  25479. }
  25480. function compileGlyf(code, js, font) {
  25481. function moveTo(x, y) {
  25482. js.push('c.moveTo(' + x + ',' + y + ');');
  25483. }
  25484. function lineTo(x, y) {
  25485. js.push('c.lineTo(' + x + ',' + y + ');');
  25486. }
  25487. function quadraticCurveTo(xa, ya, x, y) {
  25488. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25489. x + ',' + y + ');');
  25490. }
  25491. var i = 0;
  25492. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25493. var flags;
  25494. var x = 0, y = 0;
  25495. i += 10;
  25496. if (numberOfContours < 0) {
  25497. // composite glyph
  25498. do {
  25499. flags = (code[i] << 8) | code[i + 1];
  25500. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25501. i += 4;
  25502. var arg1, arg2;
  25503. if ((flags & 0x01)) {
  25504. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25505. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25506. i += 4;
  25507. } else {
  25508. arg1 = code[i++]; arg2 = code[i++];
  25509. }
  25510. if ((flags & 0x02)) {
  25511. x = arg1;
  25512. y = arg2;
  25513. } else {
  25514. x = 0; y = 0; // TODO "they are points" ?
  25515. }
  25516. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25517. if ((flags & 0x08)) {
  25518. scaleX =
  25519. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25520. i += 2;
  25521. } else if ((flags & 0x40)) {
  25522. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25523. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25524. i += 4;
  25525. } else if ((flags & 0x80)) {
  25526. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25527. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25528. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25529. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25530. i += 8;
  25531. }
  25532. var subglyph = font.glyphs[glyphIndex];
  25533. if (subglyph) {
  25534. js.push('c.save();');
  25535. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25536. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25537. compileGlyf(subglyph, js, font);
  25538. js.push('c.restore();');
  25539. }
  25540. } while ((flags & 0x20));
  25541. } else {
  25542. // simple glyph
  25543. var endPtsOfContours = [];
  25544. var j, jj;
  25545. for (j = 0; j < numberOfContours; j++) {
  25546. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25547. i += 2;
  25548. }
  25549. var instructionLength = (code[i] << 8) | code[i + 1];
  25550. i += 2 + instructionLength; // skipping the instructions
  25551. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25552. var points = [];
  25553. while (points.length < numberOfPoints) {
  25554. flags = code[i++];
  25555. var repeat = 1;
  25556. if ((flags & 0x08)) {
  25557. repeat += code[i++];
  25558. }
  25559. while (repeat-- > 0) {
  25560. points.push({flags: flags});
  25561. }
  25562. }
  25563. for (j = 0; j < numberOfPoints; j++) {
  25564. switch (points[j].flags & 0x12) {
  25565. case 0x00:
  25566. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25567. i += 2;
  25568. break;
  25569. case 0x02:
  25570. x -= code[i++];
  25571. break;
  25572. case 0x12:
  25573. x += code[i++];
  25574. break;
  25575. }
  25576. points[j].x = x;
  25577. }
  25578. for (j = 0; j < numberOfPoints; j++) {
  25579. switch (points[j].flags & 0x24) {
  25580. case 0x00:
  25581. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25582. i += 2;
  25583. break;
  25584. case 0x04:
  25585. y -= code[i++];
  25586. break;
  25587. case 0x24:
  25588. y += code[i++];
  25589. break;
  25590. }
  25591. points[j].y = y;
  25592. }
  25593. var startPoint = 0;
  25594. for (i = 0; i < numberOfContours; i++) {
  25595. var endPoint = endPtsOfContours[i];
  25596. // contours might have implicit points, which is located in the middle
  25597. // between two neighboring off-curve points
  25598. var contour = points.slice(startPoint, endPoint + 1);
  25599. if ((contour[0].flags & 1)) {
  25600. contour.push(contour[0]); // using start point at the contour end
  25601. } else if ((contour[contour.length - 1].flags & 1)) {
  25602. // first is off-curve point, trying to use one from the end
  25603. contour.unshift(contour[contour.length - 1]);
  25604. } else {
  25605. // start and end are off-curve points, creating implicit one
  25606. var p = {
  25607. flags: 1,
  25608. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25609. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25610. };
  25611. contour.unshift(p);
  25612. contour.push(p);
  25613. }
  25614. moveTo(contour[0].x, contour[0].y);
  25615. for (j = 1, jj = contour.length; j < jj; j++) {
  25616. if ((contour[j].flags & 1)) {
  25617. lineTo(contour[j].x, contour[j].y);
  25618. } else if ((contour[j + 1].flags & 1)){
  25619. quadraticCurveTo(contour[j].x, contour[j].y,
  25620. contour[j + 1].x, contour[j + 1].y);
  25621. j++;
  25622. } else {
  25623. quadraticCurveTo(contour[j].x, contour[j].y,
  25624. (contour[j].x + contour[j + 1].x) / 2,
  25625. (contour[j].y + contour[j + 1].y) / 2);
  25626. }
  25627. }
  25628. startPoint = endPoint + 1;
  25629. }
  25630. }
  25631. }
  25632. function compileCharString(code, js, font) {
  25633. var stack = [];
  25634. var x = 0, y = 0;
  25635. var stems = 0;
  25636. function moveTo(x, y) {
  25637. js.push('c.moveTo(' + x + ',' + y + ');');
  25638. }
  25639. function lineTo(x, y) {
  25640. js.push('c.lineTo(' + x + ',' + y + ');');
  25641. }
  25642. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25643. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25644. x + ',' + y + ');');
  25645. }
  25646. function parse(code) {
  25647. var i = 0;
  25648. while (i < code.length) {
  25649. var stackClean = false;
  25650. var v = code[i++];
  25651. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25652. switch (v) {
  25653. case 1: // hstem
  25654. stems += stack.length >> 1;
  25655. stackClean = true;
  25656. break;
  25657. case 3: // vstem
  25658. stems += stack.length >> 1;
  25659. stackClean = true;
  25660. break;
  25661. case 4: // vmoveto
  25662. y += stack.pop();
  25663. moveTo(x, y);
  25664. stackClean = true;
  25665. break;
  25666. case 5: // rlineto
  25667. while (stack.length > 0) {
  25668. x += stack.shift();
  25669. y += stack.shift();
  25670. lineTo(x, y);
  25671. }
  25672. break;
  25673. case 6: // hlineto
  25674. while (stack.length > 0) {
  25675. x += stack.shift();
  25676. lineTo(x, y);
  25677. if (stack.length === 0) {
  25678. break;
  25679. }
  25680. y += stack.shift();
  25681. lineTo(x, y);
  25682. }
  25683. break;
  25684. case 7: // vlineto
  25685. while (stack.length > 0) {
  25686. y += stack.shift();
  25687. lineTo(x, y);
  25688. if (stack.length === 0) {
  25689. break;
  25690. }
  25691. x += stack.shift();
  25692. lineTo(x, y);
  25693. }
  25694. break;
  25695. case 8: // rrcurveto
  25696. while (stack.length > 0) {
  25697. xa = x + stack.shift(); ya = y + stack.shift();
  25698. xb = xa + stack.shift(); yb = ya + stack.shift();
  25699. x = xb + stack.shift(); y = yb + stack.shift();
  25700. bezierCurveTo(xa, ya, xb, yb, x, y);
  25701. }
  25702. break;
  25703. case 10: // callsubr
  25704. n = stack.pop() + font.subrsBias;
  25705. subrCode = font.subrs[n];
  25706. if (subrCode) {
  25707. parse(subrCode);
  25708. }
  25709. break;
  25710. case 11: // return
  25711. return;
  25712. case 12:
  25713. v = code[i++];
  25714. switch (v) {
  25715. case 34: // flex
  25716. xa = x + stack.shift();
  25717. xb = xa + stack.shift(); y1 = y + stack.shift();
  25718. x = xb + stack.shift();
  25719. bezierCurveTo(xa, y, xb, y1, x, y1);
  25720. xa = x + stack.shift();
  25721. xb = xa + stack.shift();
  25722. x = xb + stack.shift();
  25723. bezierCurveTo(xa, y1, xb, y, x, y);
  25724. break;
  25725. case 35: // flex
  25726. xa = x + stack.shift(); ya = y + stack.shift();
  25727. xb = xa + stack.shift(); yb = ya + stack.shift();
  25728. x = xb + stack.shift(); y = yb + stack.shift();
  25729. bezierCurveTo(xa, ya, xb, yb, x, y);
  25730. xa = x + stack.shift(); ya = y + stack.shift();
  25731. xb = xa + stack.shift(); yb = ya + stack.shift();
  25732. x = xb + stack.shift(); y = yb + stack.shift();
  25733. bezierCurveTo(xa, ya, xb, yb, x, y);
  25734. stack.pop(); // fd
  25735. break;
  25736. case 36: // hflex1
  25737. xa = x + stack.shift(); y1 = y + stack.shift();
  25738. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25739. x = xb + stack.shift();
  25740. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25741. xa = x + stack.shift();
  25742. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25743. x = xb + stack.shift();
  25744. bezierCurveTo(xa, y2, xb, y3, x, y);
  25745. break;
  25746. case 37: // flex1
  25747. var x0 = x, y0 = y;
  25748. xa = x + stack.shift(); ya = y + stack.shift();
  25749. xb = xa + stack.shift(); yb = ya + stack.shift();
  25750. x = xb + stack.shift(); y = yb + stack.shift();
  25751. bezierCurveTo(xa, ya, xb, yb, x, y);
  25752. xa = x + stack.shift(); ya = y + stack.shift();
  25753. xb = xa + stack.shift(); yb = ya + stack.shift();
  25754. x = xb; y = yb;
  25755. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25756. x += stack.shift();
  25757. } else {
  25758. y += stack.shift();
  25759. }
  25760. bezierCurveTo(xa, ya, xb, yb, x, y);
  25761. break;
  25762. default:
  25763. error('unknown operator: 12 ' + v);
  25764. }
  25765. break;
  25766. case 14: // endchar
  25767. if (stack.length >= 4) {
  25768. var achar = stack.pop();
  25769. var bchar = stack.pop();
  25770. y = stack.pop();
  25771. x = stack.pop();
  25772. js.push('c.save();');
  25773. js.push('c.translate('+ x + ',' + y + ');');
  25774. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25775. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25776. compileCharString(font.glyphs[gid], js, font);
  25777. js.push('c.restore();');
  25778. gid = lookupCmap(font.cmap, String.fromCharCode(
  25779. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25780. compileCharString(font.glyphs[gid], js, font);
  25781. }
  25782. return;
  25783. case 18: // hstemhm
  25784. stems += stack.length >> 1;
  25785. stackClean = true;
  25786. break;
  25787. case 19: // hintmask
  25788. stems += stack.length >> 1;
  25789. i += (stems + 7) >> 3;
  25790. stackClean = true;
  25791. break;
  25792. case 20: // cntrmask
  25793. stems += stack.length >> 1;
  25794. i += (stems + 7) >> 3;
  25795. stackClean = true;
  25796. break;
  25797. case 21: // rmoveto
  25798. y += stack.pop();
  25799. x += stack.pop();
  25800. moveTo(x, y);
  25801. stackClean = true;
  25802. break;
  25803. case 22: // hmoveto
  25804. x += stack.pop();
  25805. moveTo(x, y);
  25806. stackClean = true;
  25807. break;
  25808. case 23: // vstemhm
  25809. stems += stack.length >> 1;
  25810. stackClean = true;
  25811. break;
  25812. case 24: // rcurveline
  25813. while (stack.length > 2) {
  25814. xa = x + stack.shift(); ya = y + stack.shift();
  25815. xb = xa + stack.shift(); yb = ya + stack.shift();
  25816. x = xb + stack.shift(); y = yb + stack.shift();
  25817. bezierCurveTo(xa, ya, xb, yb, x, y);
  25818. }
  25819. x += stack.shift();
  25820. y += stack.shift();
  25821. lineTo(x, y);
  25822. break;
  25823. case 25: // rlinecurve
  25824. while (stack.length > 6) {
  25825. x += stack.shift();
  25826. y += stack.shift();
  25827. lineTo(x, y);
  25828. }
  25829. xa = x + stack.shift(); ya = y + stack.shift();
  25830. xb = xa + stack.shift(); yb = ya + stack.shift();
  25831. x = xb + stack.shift(); y = yb + stack.shift();
  25832. bezierCurveTo(xa, ya, xb, yb, x, y);
  25833. break;
  25834. case 26: // vvcurveto
  25835. if (stack.length % 2) {
  25836. x += stack.shift();
  25837. }
  25838. while (stack.length > 0) {
  25839. xa = x; ya = y + stack.shift();
  25840. xb = xa + stack.shift(); yb = ya + stack.shift();
  25841. x = xb; y = yb + stack.shift();
  25842. bezierCurveTo(xa, ya, xb, yb, x, y);
  25843. }
  25844. break;
  25845. case 27: // hhcurveto
  25846. if (stack.length % 2) {
  25847. y += stack.shift();
  25848. }
  25849. while (stack.length > 0) {
  25850. xa = x + stack.shift(); ya = y;
  25851. xb = xa + stack.shift(); yb = ya + stack.shift();
  25852. x = xb + stack.shift(); y = yb;
  25853. bezierCurveTo(xa, ya, xb, yb, x, y);
  25854. }
  25855. break;
  25856. case 28:
  25857. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25858. i += 2;
  25859. break;
  25860. case 29: // callgsubr
  25861. n = stack.pop() + font.gsubrsBias;
  25862. subrCode = font.gsubrs[n];
  25863. if (subrCode) {
  25864. parse(subrCode);
  25865. }
  25866. break;
  25867. case 30: // vhcurveto
  25868. while (stack.length > 0) {
  25869. xa = x; ya = y + stack.shift();
  25870. xb = xa + stack.shift(); yb = ya + stack.shift();
  25871. x = xb + stack.shift();
  25872. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25873. bezierCurveTo(xa, ya, xb, yb, x, y);
  25874. if (stack.length === 0) {
  25875. break;
  25876. }
  25877. xa = x + stack.shift(); ya = y;
  25878. xb = xa + stack.shift(); yb = ya + stack.shift();
  25879. y = yb + stack.shift();
  25880. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25881. bezierCurveTo(xa, ya, xb, yb, x, y);
  25882. }
  25883. break;
  25884. case 31: // hvcurveto
  25885. while (stack.length > 0) {
  25886. xa = x + stack.shift(); ya = y;
  25887. xb = xa + stack.shift(); yb = ya + stack.shift();
  25888. y = yb + stack.shift();
  25889. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25890. bezierCurveTo(xa, ya, xb, yb, x, y);
  25891. if (stack.length === 0) {
  25892. break;
  25893. }
  25894. xa = x; ya = y + stack.shift();
  25895. xb = xa + stack.shift(); yb = ya + stack.shift();
  25896. x = xb + stack.shift();
  25897. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25898. bezierCurveTo(xa, ya, xb, yb, x, y);
  25899. }
  25900. break;
  25901. default:
  25902. if (v < 32) {
  25903. error('unknown operator: ' + v);
  25904. }
  25905. if (v < 247) {
  25906. stack.push(v - 139);
  25907. } else if (v < 251) {
  25908. stack.push((v - 247) * 256 + code[i++] + 108);
  25909. } else if (v < 255) {
  25910. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25911. } else {
  25912. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25913. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25914. i += 4;
  25915. }
  25916. break;
  25917. }
  25918. if (stackClean) {
  25919. stack.length = 0;
  25920. }
  25921. }
  25922. }
  25923. parse(code);
  25924. }
  25925. var noop = '';
  25926. function CompiledFont(fontMatrix) {
  25927. this.compiledGlyphs = {};
  25928. this.fontMatrix = fontMatrix;
  25929. }
  25930. CompiledFont.prototype = {
  25931. getPathJs: function (unicode) {
  25932. var gid = lookupCmap(this.cmap, unicode);
  25933. var fn = this.compiledGlyphs[gid];
  25934. if (!fn) {
  25935. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25936. }
  25937. return fn;
  25938. },
  25939. compileGlyph: function (code) {
  25940. if (!code || code.length === 0 || code[0] === 14) {
  25941. return noop;
  25942. }
  25943. var js = [];
  25944. js.push('c.save();');
  25945. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  25946. js.push('c.scale(size, -size);');
  25947. this.compileGlyphImpl(code, js);
  25948. js.push('c.restore();');
  25949. return js.join('\n');
  25950. },
  25951. compileGlyphImpl: function () {
  25952. error('Children classes should implement this.');
  25953. },
  25954. hasBuiltPath: function (unicode) {
  25955. var gid = lookupCmap(this.cmap, unicode);
  25956. return gid in this.compiledGlyphs;
  25957. }
  25958. };
  25959. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25960. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25961. CompiledFont.call(this, fontMatrix);
  25962. this.glyphs = glyphs;
  25963. this.cmap = cmap;
  25964. this.compiledGlyphs = [];
  25965. }
  25966. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25967. compileGlyphImpl: function (code, js) {
  25968. compileGlyf(code, js, this);
  25969. }
  25970. });
  25971. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25972. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25973. CompiledFont.call(this, fontMatrix);
  25974. this.glyphs = cffInfo.glyphs;
  25975. this.gsubrs = cffInfo.gsubrs || [];
  25976. this.subrs = cffInfo.subrs || [];
  25977. this.cmap = cmap;
  25978. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25979. this.compiledGlyphs = [];
  25980. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25981. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25982. this.subrsBias = (this.subrs.length < 1240 ?
  25983. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25984. }
  25985. Util.inherit(Type2Compiled, CompiledFont, {
  25986. compileGlyphImpl: function (code, js) {
  25987. compileCharString(code, js, this);
  25988. }
  25989. });
  25990. return {
  25991. create: function FontRendererFactory_create(font) {
  25992. var data = new Uint8Array(font.data);
  25993. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25994. var numTables = getUshort(data, 4);
  25995. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25996. var tag = bytesToString(data.subarray(p, p + 4));
  25997. var offset = getLong(data, p + 8);
  25998. var length = getLong(data, p + 12);
  25999. switch (tag) {
  26000. case 'cmap':
  26001. cmap = parseCmap(data, offset, offset + length);
  26002. break;
  26003. case 'glyf':
  26004. glyf = data.subarray(offset, offset + length);
  26005. break;
  26006. case 'loca':
  26007. loca = data.subarray(offset, offset + length);
  26008. break;
  26009. case 'head':
  26010. unitsPerEm = getUshort(data, offset + 18);
  26011. indexToLocFormat = getUshort(data, offset + 50);
  26012. break;
  26013. case 'CFF ':
  26014. cff = parseCff(data, offset, offset + length);
  26015. break;
  26016. }
  26017. }
  26018. if (glyf) {
  26019. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  26020. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  26021. return new TrueTypeCompiled(
  26022. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  26023. } else {
  26024. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  26025. }
  26026. }
  26027. };
  26028. })();
  26029. var GlyphsUnicode = {
  26030. A: 0x0041,
  26031. AE: 0x00C6,
  26032. AEacute: 0x01FC,
  26033. AEmacron: 0x01E2,
  26034. AEsmall: 0xF7E6,
  26035. Aacute: 0x00C1,
  26036. Aacutesmall: 0xF7E1,
  26037. Abreve: 0x0102,
  26038. Abreveacute: 0x1EAE,
  26039. Abrevecyrillic: 0x04D0,
  26040. Abrevedotbelow: 0x1EB6,
  26041. Abrevegrave: 0x1EB0,
  26042. Abrevehookabove: 0x1EB2,
  26043. Abrevetilde: 0x1EB4,
  26044. Acaron: 0x01CD,
  26045. Acircle: 0x24B6,
  26046. Acircumflex: 0x00C2,
  26047. Acircumflexacute: 0x1EA4,
  26048. Acircumflexdotbelow: 0x1EAC,
  26049. Acircumflexgrave: 0x1EA6,
  26050. Acircumflexhookabove: 0x1EA8,
  26051. Acircumflexsmall: 0xF7E2,
  26052. Acircumflextilde: 0x1EAA,
  26053. Acute: 0xF6C9,
  26054. Acutesmall: 0xF7B4,
  26055. Acyrillic: 0x0410,
  26056. Adblgrave: 0x0200,
  26057. Adieresis: 0x00C4,
  26058. Adieresiscyrillic: 0x04D2,
  26059. Adieresismacron: 0x01DE,
  26060. Adieresissmall: 0xF7E4,
  26061. Adotbelow: 0x1EA0,
  26062. Adotmacron: 0x01E0,
  26063. Agrave: 0x00C0,
  26064. Agravesmall: 0xF7E0,
  26065. Ahookabove: 0x1EA2,
  26066. Aiecyrillic: 0x04D4,
  26067. Ainvertedbreve: 0x0202,
  26068. Alpha: 0x0391,
  26069. Alphatonos: 0x0386,
  26070. Amacron: 0x0100,
  26071. Amonospace: 0xFF21,
  26072. Aogonek: 0x0104,
  26073. Aring: 0x00C5,
  26074. Aringacute: 0x01FA,
  26075. Aringbelow: 0x1E00,
  26076. Aringsmall: 0xF7E5,
  26077. Asmall: 0xF761,
  26078. Atilde: 0x00C3,
  26079. Atildesmall: 0xF7E3,
  26080. Aybarmenian: 0x0531,
  26081. B: 0x0042,
  26082. Bcircle: 0x24B7,
  26083. Bdotaccent: 0x1E02,
  26084. Bdotbelow: 0x1E04,
  26085. Becyrillic: 0x0411,
  26086. Benarmenian: 0x0532,
  26087. Beta: 0x0392,
  26088. Bhook: 0x0181,
  26089. Blinebelow: 0x1E06,
  26090. Bmonospace: 0xFF22,
  26091. Brevesmall: 0xF6F4,
  26092. Bsmall: 0xF762,
  26093. Btopbar: 0x0182,
  26094. C: 0x0043,
  26095. Caarmenian: 0x053E,
  26096. Cacute: 0x0106,
  26097. Caron: 0xF6CA,
  26098. Caronsmall: 0xF6F5,
  26099. Ccaron: 0x010C,
  26100. Ccedilla: 0x00C7,
  26101. Ccedillaacute: 0x1E08,
  26102. Ccedillasmall: 0xF7E7,
  26103. Ccircle: 0x24B8,
  26104. Ccircumflex: 0x0108,
  26105. Cdot: 0x010A,
  26106. Cdotaccent: 0x010A,
  26107. Cedillasmall: 0xF7B8,
  26108. Chaarmenian: 0x0549,
  26109. Cheabkhasiancyrillic: 0x04BC,
  26110. Checyrillic: 0x0427,
  26111. Chedescenderabkhasiancyrillic: 0x04BE,
  26112. Chedescendercyrillic: 0x04B6,
  26113. Chedieresiscyrillic: 0x04F4,
  26114. Cheharmenian: 0x0543,
  26115. Chekhakassiancyrillic: 0x04CB,
  26116. Cheverticalstrokecyrillic: 0x04B8,
  26117. Chi: 0x03A7,
  26118. Chook: 0x0187,
  26119. Circumflexsmall: 0xF6F6,
  26120. Cmonospace: 0xFF23,
  26121. Coarmenian: 0x0551,
  26122. Csmall: 0xF763,
  26123. D: 0x0044,
  26124. DZ: 0x01F1,
  26125. DZcaron: 0x01C4,
  26126. Daarmenian: 0x0534,
  26127. Dafrican: 0x0189,
  26128. Dcaron: 0x010E,
  26129. Dcedilla: 0x1E10,
  26130. Dcircle: 0x24B9,
  26131. Dcircumflexbelow: 0x1E12,
  26132. Dcroat: 0x0110,
  26133. Ddotaccent: 0x1E0A,
  26134. Ddotbelow: 0x1E0C,
  26135. Decyrillic: 0x0414,
  26136. Deicoptic: 0x03EE,
  26137. Delta: 0x2206,
  26138. Deltagreek: 0x0394,
  26139. Dhook: 0x018A,
  26140. Dieresis: 0xF6CB,
  26141. DieresisAcute: 0xF6CC,
  26142. DieresisGrave: 0xF6CD,
  26143. Dieresissmall: 0xF7A8,
  26144. Digammagreek: 0x03DC,
  26145. Djecyrillic: 0x0402,
  26146. Dlinebelow: 0x1E0E,
  26147. Dmonospace: 0xFF24,
  26148. Dotaccentsmall: 0xF6F7,
  26149. Dslash: 0x0110,
  26150. Dsmall: 0xF764,
  26151. Dtopbar: 0x018B,
  26152. Dz: 0x01F2,
  26153. Dzcaron: 0x01C5,
  26154. Dzeabkhasiancyrillic: 0x04E0,
  26155. Dzecyrillic: 0x0405,
  26156. Dzhecyrillic: 0x040F,
  26157. E: 0x0045,
  26158. Eacute: 0x00C9,
  26159. Eacutesmall: 0xF7E9,
  26160. Ebreve: 0x0114,
  26161. Ecaron: 0x011A,
  26162. Ecedillabreve: 0x1E1C,
  26163. Echarmenian: 0x0535,
  26164. Ecircle: 0x24BA,
  26165. Ecircumflex: 0x00CA,
  26166. Ecircumflexacute: 0x1EBE,
  26167. Ecircumflexbelow: 0x1E18,
  26168. Ecircumflexdotbelow: 0x1EC6,
  26169. Ecircumflexgrave: 0x1EC0,
  26170. Ecircumflexhookabove: 0x1EC2,
  26171. Ecircumflexsmall: 0xF7EA,
  26172. Ecircumflextilde: 0x1EC4,
  26173. Ecyrillic: 0x0404,
  26174. Edblgrave: 0x0204,
  26175. Edieresis: 0x00CB,
  26176. Edieresissmall: 0xF7EB,
  26177. Edot: 0x0116,
  26178. Edotaccent: 0x0116,
  26179. Edotbelow: 0x1EB8,
  26180. Efcyrillic: 0x0424,
  26181. Egrave: 0x00C8,
  26182. Egravesmall: 0xF7E8,
  26183. Eharmenian: 0x0537,
  26184. Ehookabove: 0x1EBA,
  26185. Eightroman: 0x2167,
  26186. Einvertedbreve: 0x0206,
  26187. Eiotifiedcyrillic: 0x0464,
  26188. Elcyrillic: 0x041B,
  26189. Elevenroman: 0x216A,
  26190. Emacron: 0x0112,
  26191. Emacronacute: 0x1E16,
  26192. Emacrongrave: 0x1E14,
  26193. Emcyrillic: 0x041C,
  26194. Emonospace: 0xFF25,
  26195. Encyrillic: 0x041D,
  26196. Endescendercyrillic: 0x04A2,
  26197. Eng: 0x014A,
  26198. Enghecyrillic: 0x04A4,
  26199. Enhookcyrillic: 0x04C7,
  26200. Eogonek: 0x0118,
  26201. Eopen: 0x0190,
  26202. Epsilon: 0x0395,
  26203. Epsilontonos: 0x0388,
  26204. Ercyrillic: 0x0420,
  26205. Ereversed: 0x018E,
  26206. Ereversedcyrillic: 0x042D,
  26207. Escyrillic: 0x0421,
  26208. Esdescendercyrillic: 0x04AA,
  26209. Esh: 0x01A9,
  26210. Esmall: 0xF765,
  26211. Eta: 0x0397,
  26212. Etarmenian: 0x0538,
  26213. Etatonos: 0x0389,
  26214. Eth: 0x00D0,
  26215. Ethsmall: 0xF7F0,
  26216. Etilde: 0x1EBC,
  26217. Etildebelow: 0x1E1A,
  26218. Euro: 0x20AC,
  26219. Ezh: 0x01B7,
  26220. Ezhcaron: 0x01EE,
  26221. Ezhreversed: 0x01B8,
  26222. F: 0x0046,
  26223. Fcircle: 0x24BB,
  26224. Fdotaccent: 0x1E1E,
  26225. Feharmenian: 0x0556,
  26226. Feicoptic: 0x03E4,
  26227. Fhook: 0x0191,
  26228. Fitacyrillic: 0x0472,
  26229. Fiveroman: 0x2164,
  26230. Fmonospace: 0xFF26,
  26231. Fourroman: 0x2163,
  26232. Fsmall: 0xF766,
  26233. G: 0x0047,
  26234. GBsquare: 0x3387,
  26235. Gacute: 0x01F4,
  26236. Gamma: 0x0393,
  26237. Gammaafrican: 0x0194,
  26238. Gangiacoptic: 0x03EA,
  26239. Gbreve: 0x011E,
  26240. Gcaron: 0x01E6,
  26241. Gcedilla: 0x0122,
  26242. Gcircle: 0x24BC,
  26243. Gcircumflex: 0x011C,
  26244. Gcommaaccent: 0x0122,
  26245. Gdot: 0x0120,
  26246. Gdotaccent: 0x0120,
  26247. Gecyrillic: 0x0413,
  26248. Ghadarmenian: 0x0542,
  26249. Ghemiddlehookcyrillic: 0x0494,
  26250. Ghestrokecyrillic: 0x0492,
  26251. Gheupturncyrillic: 0x0490,
  26252. Ghook: 0x0193,
  26253. Gimarmenian: 0x0533,
  26254. Gjecyrillic: 0x0403,
  26255. Gmacron: 0x1E20,
  26256. Gmonospace: 0xFF27,
  26257. Grave: 0xF6CE,
  26258. Gravesmall: 0xF760,
  26259. Gsmall: 0xF767,
  26260. Gsmallhook: 0x029B,
  26261. Gstroke: 0x01E4,
  26262. H: 0x0048,
  26263. H18533: 0x25CF,
  26264. H18543: 0x25AA,
  26265. H18551: 0x25AB,
  26266. H22073: 0x25A1,
  26267. HPsquare: 0x33CB,
  26268. Haabkhasiancyrillic: 0x04A8,
  26269. Hadescendercyrillic: 0x04B2,
  26270. Hardsigncyrillic: 0x042A,
  26271. Hbar: 0x0126,
  26272. Hbrevebelow: 0x1E2A,
  26273. Hcedilla: 0x1E28,
  26274. Hcircle: 0x24BD,
  26275. Hcircumflex: 0x0124,
  26276. Hdieresis: 0x1E26,
  26277. Hdotaccent: 0x1E22,
  26278. Hdotbelow: 0x1E24,
  26279. Hmonospace: 0xFF28,
  26280. Hoarmenian: 0x0540,
  26281. Horicoptic: 0x03E8,
  26282. Hsmall: 0xF768,
  26283. Hungarumlaut: 0xF6CF,
  26284. Hungarumlautsmall: 0xF6F8,
  26285. Hzsquare: 0x3390,
  26286. I: 0x0049,
  26287. IAcyrillic: 0x042F,
  26288. IJ: 0x0132,
  26289. IUcyrillic: 0x042E,
  26290. Iacute: 0x00CD,
  26291. Iacutesmall: 0xF7ED,
  26292. Ibreve: 0x012C,
  26293. Icaron: 0x01CF,
  26294. Icircle: 0x24BE,
  26295. Icircumflex: 0x00CE,
  26296. Icircumflexsmall: 0xF7EE,
  26297. Icyrillic: 0x0406,
  26298. Idblgrave: 0x0208,
  26299. Idieresis: 0x00CF,
  26300. Idieresisacute: 0x1E2E,
  26301. Idieresiscyrillic: 0x04E4,
  26302. Idieresissmall: 0xF7EF,
  26303. Idot: 0x0130,
  26304. Idotaccent: 0x0130,
  26305. Idotbelow: 0x1ECA,
  26306. Iebrevecyrillic: 0x04D6,
  26307. Iecyrillic: 0x0415,
  26308. Ifraktur: 0x2111,
  26309. Igrave: 0x00CC,
  26310. Igravesmall: 0xF7EC,
  26311. Ihookabove: 0x1EC8,
  26312. Iicyrillic: 0x0418,
  26313. Iinvertedbreve: 0x020A,
  26314. Iishortcyrillic: 0x0419,
  26315. Imacron: 0x012A,
  26316. Imacroncyrillic: 0x04E2,
  26317. Imonospace: 0xFF29,
  26318. Iniarmenian: 0x053B,
  26319. Iocyrillic: 0x0401,
  26320. Iogonek: 0x012E,
  26321. Iota: 0x0399,
  26322. Iotaafrican: 0x0196,
  26323. Iotadieresis: 0x03AA,
  26324. Iotatonos: 0x038A,
  26325. Ismall: 0xF769,
  26326. Istroke: 0x0197,
  26327. Itilde: 0x0128,
  26328. Itildebelow: 0x1E2C,
  26329. Izhitsacyrillic: 0x0474,
  26330. Izhitsadblgravecyrillic: 0x0476,
  26331. J: 0x004A,
  26332. Jaarmenian: 0x0541,
  26333. Jcircle: 0x24BF,
  26334. Jcircumflex: 0x0134,
  26335. Jecyrillic: 0x0408,
  26336. Jheharmenian: 0x054B,
  26337. Jmonospace: 0xFF2A,
  26338. Jsmall: 0xF76A,
  26339. K: 0x004B,
  26340. KBsquare: 0x3385,
  26341. KKsquare: 0x33CD,
  26342. Kabashkircyrillic: 0x04A0,
  26343. Kacute: 0x1E30,
  26344. Kacyrillic: 0x041A,
  26345. Kadescendercyrillic: 0x049A,
  26346. Kahookcyrillic: 0x04C3,
  26347. Kappa: 0x039A,
  26348. Kastrokecyrillic: 0x049E,
  26349. Kaverticalstrokecyrillic: 0x049C,
  26350. Kcaron: 0x01E8,
  26351. Kcedilla: 0x0136,
  26352. Kcircle: 0x24C0,
  26353. Kcommaaccent: 0x0136,
  26354. Kdotbelow: 0x1E32,
  26355. Keharmenian: 0x0554,
  26356. Kenarmenian: 0x053F,
  26357. Khacyrillic: 0x0425,
  26358. Kheicoptic: 0x03E6,
  26359. Khook: 0x0198,
  26360. Kjecyrillic: 0x040C,
  26361. Klinebelow: 0x1E34,
  26362. Kmonospace: 0xFF2B,
  26363. Koppacyrillic: 0x0480,
  26364. Koppagreek: 0x03DE,
  26365. Ksicyrillic: 0x046E,
  26366. Ksmall: 0xF76B,
  26367. L: 0x004C,
  26368. LJ: 0x01C7,
  26369. LL: 0xF6BF,
  26370. Lacute: 0x0139,
  26371. Lambda: 0x039B,
  26372. Lcaron: 0x013D,
  26373. Lcedilla: 0x013B,
  26374. Lcircle: 0x24C1,
  26375. Lcircumflexbelow: 0x1E3C,
  26376. Lcommaaccent: 0x013B,
  26377. Ldot: 0x013F,
  26378. Ldotaccent: 0x013F,
  26379. Ldotbelow: 0x1E36,
  26380. Ldotbelowmacron: 0x1E38,
  26381. Liwnarmenian: 0x053C,
  26382. Lj: 0x01C8,
  26383. Ljecyrillic: 0x0409,
  26384. Llinebelow: 0x1E3A,
  26385. Lmonospace: 0xFF2C,
  26386. Lslash: 0x0141,
  26387. Lslashsmall: 0xF6F9,
  26388. Lsmall: 0xF76C,
  26389. M: 0x004D,
  26390. MBsquare: 0x3386,
  26391. Macron: 0xF6D0,
  26392. Macronsmall: 0xF7AF,
  26393. Macute: 0x1E3E,
  26394. Mcircle: 0x24C2,
  26395. Mdotaccent: 0x1E40,
  26396. Mdotbelow: 0x1E42,
  26397. Menarmenian: 0x0544,
  26398. Mmonospace: 0xFF2D,
  26399. Msmall: 0xF76D,
  26400. Mturned: 0x019C,
  26401. Mu: 0x039C,
  26402. N: 0x004E,
  26403. NJ: 0x01CA,
  26404. Nacute: 0x0143,
  26405. Ncaron: 0x0147,
  26406. Ncedilla: 0x0145,
  26407. Ncircle: 0x24C3,
  26408. Ncircumflexbelow: 0x1E4A,
  26409. Ncommaaccent: 0x0145,
  26410. Ndotaccent: 0x1E44,
  26411. Ndotbelow: 0x1E46,
  26412. Nhookleft: 0x019D,
  26413. Nineroman: 0x2168,
  26414. Nj: 0x01CB,
  26415. Njecyrillic: 0x040A,
  26416. Nlinebelow: 0x1E48,
  26417. Nmonospace: 0xFF2E,
  26418. Nowarmenian: 0x0546,
  26419. Nsmall: 0xF76E,
  26420. Ntilde: 0x00D1,
  26421. Ntildesmall: 0xF7F1,
  26422. Nu: 0x039D,
  26423. O: 0x004F,
  26424. OE: 0x0152,
  26425. OEsmall: 0xF6FA,
  26426. Oacute: 0x00D3,
  26427. Oacutesmall: 0xF7F3,
  26428. Obarredcyrillic: 0x04E8,
  26429. Obarreddieresiscyrillic: 0x04EA,
  26430. Obreve: 0x014E,
  26431. Ocaron: 0x01D1,
  26432. Ocenteredtilde: 0x019F,
  26433. Ocircle: 0x24C4,
  26434. Ocircumflex: 0x00D4,
  26435. Ocircumflexacute: 0x1ED0,
  26436. Ocircumflexdotbelow: 0x1ED8,
  26437. Ocircumflexgrave: 0x1ED2,
  26438. Ocircumflexhookabove: 0x1ED4,
  26439. Ocircumflexsmall: 0xF7F4,
  26440. Ocircumflextilde: 0x1ED6,
  26441. Ocyrillic: 0x041E,
  26442. Odblacute: 0x0150,
  26443. Odblgrave: 0x020C,
  26444. Odieresis: 0x00D6,
  26445. Odieresiscyrillic: 0x04E6,
  26446. Odieresissmall: 0xF7F6,
  26447. Odotbelow: 0x1ECC,
  26448. Ogoneksmall: 0xF6FB,
  26449. Ograve: 0x00D2,
  26450. Ogravesmall: 0xF7F2,
  26451. Oharmenian: 0x0555,
  26452. Ohm: 0x2126,
  26453. Ohookabove: 0x1ECE,
  26454. Ohorn: 0x01A0,
  26455. Ohornacute: 0x1EDA,
  26456. Ohorndotbelow: 0x1EE2,
  26457. Ohorngrave: 0x1EDC,
  26458. Ohornhookabove: 0x1EDE,
  26459. Ohorntilde: 0x1EE0,
  26460. Ohungarumlaut: 0x0150,
  26461. Oi: 0x01A2,
  26462. Oinvertedbreve: 0x020E,
  26463. Omacron: 0x014C,
  26464. Omacronacute: 0x1E52,
  26465. Omacrongrave: 0x1E50,
  26466. Omega: 0x2126,
  26467. Omegacyrillic: 0x0460,
  26468. Omegagreek: 0x03A9,
  26469. Omegaroundcyrillic: 0x047A,
  26470. Omegatitlocyrillic: 0x047C,
  26471. Omegatonos: 0x038F,
  26472. Omicron: 0x039F,
  26473. Omicrontonos: 0x038C,
  26474. Omonospace: 0xFF2F,
  26475. Oneroman: 0x2160,
  26476. Oogonek: 0x01EA,
  26477. Oogonekmacron: 0x01EC,
  26478. Oopen: 0x0186,
  26479. Oslash: 0x00D8,
  26480. Oslashacute: 0x01FE,
  26481. Oslashsmall: 0xF7F8,
  26482. Osmall: 0xF76F,
  26483. Ostrokeacute: 0x01FE,
  26484. Otcyrillic: 0x047E,
  26485. Otilde: 0x00D5,
  26486. Otildeacute: 0x1E4C,
  26487. Otildedieresis: 0x1E4E,
  26488. Otildesmall: 0xF7F5,
  26489. P: 0x0050,
  26490. Pacute: 0x1E54,
  26491. Pcircle: 0x24C5,
  26492. Pdotaccent: 0x1E56,
  26493. Pecyrillic: 0x041F,
  26494. Peharmenian: 0x054A,
  26495. Pemiddlehookcyrillic: 0x04A6,
  26496. Phi: 0x03A6,
  26497. Phook: 0x01A4,
  26498. Pi: 0x03A0,
  26499. Piwrarmenian: 0x0553,
  26500. Pmonospace: 0xFF30,
  26501. Psi: 0x03A8,
  26502. Psicyrillic: 0x0470,
  26503. Psmall: 0xF770,
  26504. Q: 0x0051,
  26505. Qcircle: 0x24C6,
  26506. Qmonospace: 0xFF31,
  26507. Qsmall: 0xF771,
  26508. R: 0x0052,
  26509. Raarmenian: 0x054C,
  26510. Racute: 0x0154,
  26511. Rcaron: 0x0158,
  26512. Rcedilla: 0x0156,
  26513. Rcircle: 0x24C7,
  26514. Rcommaaccent: 0x0156,
  26515. Rdblgrave: 0x0210,
  26516. Rdotaccent: 0x1E58,
  26517. Rdotbelow: 0x1E5A,
  26518. Rdotbelowmacron: 0x1E5C,
  26519. Reharmenian: 0x0550,
  26520. Rfraktur: 0x211C,
  26521. Rho: 0x03A1,
  26522. Ringsmall: 0xF6FC,
  26523. Rinvertedbreve: 0x0212,
  26524. Rlinebelow: 0x1E5E,
  26525. Rmonospace: 0xFF32,
  26526. Rsmall: 0xF772,
  26527. Rsmallinverted: 0x0281,
  26528. Rsmallinvertedsuperior: 0x02B6,
  26529. S: 0x0053,
  26530. SF010000: 0x250C,
  26531. SF020000: 0x2514,
  26532. SF030000: 0x2510,
  26533. SF040000: 0x2518,
  26534. SF050000: 0x253C,
  26535. SF060000: 0x252C,
  26536. SF070000: 0x2534,
  26537. SF080000: 0x251C,
  26538. SF090000: 0x2524,
  26539. SF100000: 0x2500,
  26540. SF110000: 0x2502,
  26541. SF190000: 0x2561,
  26542. SF200000: 0x2562,
  26543. SF210000: 0x2556,
  26544. SF220000: 0x2555,
  26545. SF230000: 0x2563,
  26546. SF240000: 0x2551,
  26547. SF250000: 0x2557,
  26548. SF260000: 0x255D,
  26549. SF270000: 0x255C,
  26550. SF280000: 0x255B,
  26551. SF360000: 0x255E,
  26552. SF370000: 0x255F,
  26553. SF380000: 0x255A,
  26554. SF390000: 0x2554,
  26555. SF400000: 0x2569,
  26556. SF410000: 0x2566,
  26557. SF420000: 0x2560,
  26558. SF430000: 0x2550,
  26559. SF440000: 0x256C,
  26560. SF450000: 0x2567,
  26561. SF460000: 0x2568,
  26562. SF470000: 0x2564,
  26563. SF480000: 0x2565,
  26564. SF490000: 0x2559,
  26565. SF500000: 0x2558,
  26566. SF510000: 0x2552,
  26567. SF520000: 0x2553,
  26568. SF530000: 0x256B,
  26569. SF540000: 0x256A,
  26570. Sacute: 0x015A,
  26571. Sacutedotaccent: 0x1E64,
  26572. Sampigreek: 0x03E0,
  26573. Scaron: 0x0160,
  26574. Scarondotaccent: 0x1E66,
  26575. Scaronsmall: 0xF6FD,
  26576. Scedilla: 0x015E,
  26577. Schwa: 0x018F,
  26578. Schwacyrillic: 0x04D8,
  26579. Schwadieresiscyrillic: 0x04DA,
  26580. Scircle: 0x24C8,
  26581. Scircumflex: 0x015C,
  26582. Scommaaccent: 0x0218,
  26583. Sdotaccent: 0x1E60,
  26584. Sdotbelow: 0x1E62,
  26585. Sdotbelowdotaccent: 0x1E68,
  26586. Seharmenian: 0x054D,
  26587. Sevenroman: 0x2166,
  26588. Shaarmenian: 0x0547,
  26589. Shacyrillic: 0x0428,
  26590. Shchacyrillic: 0x0429,
  26591. Sheicoptic: 0x03E2,
  26592. Shhacyrillic: 0x04BA,
  26593. Shimacoptic: 0x03EC,
  26594. Sigma: 0x03A3,
  26595. Sixroman: 0x2165,
  26596. Smonospace: 0xFF33,
  26597. Softsigncyrillic: 0x042C,
  26598. Ssmall: 0xF773,
  26599. Stigmagreek: 0x03DA,
  26600. T: 0x0054,
  26601. Tau: 0x03A4,
  26602. Tbar: 0x0166,
  26603. Tcaron: 0x0164,
  26604. Tcedilla: 0x0162,
  26605. Tcircle: 0x24C9,
  26606. Tcircumflexbelow: 0x1E70,
  26607. Tcommaaccent: 0x0162,
  26608. Tdotaccent: 0x1E6A,
  26609. Tdotbelow: 0x1E6C,
  26610. Tecyrillic: 0x0422,
  26611. Tedescendercyrillic: 0x04AC,
  26612. Tenroman: 0x2169,
  26613. Tetsecyrillic: 0x04B4,
  26614. Theta: 0x0398,
  26615. Thook: 0x01AC,
  26616. Thorn: 0x00DE,
  26617. Thornsmall: 0xF7FE,
  26618. Threeroman: 0x2162,
  26619. Tildesmall: 0xF6FE,
  26620. Tiwnarmenian: 0x054F,
  26621. Tlinebelow: 0x1E6E,
  26622. Tmonospace: 0xFF34,
  26623. Toarmenian: 0x0539,
  26624. Tonefive: 0x01BC,
  26625. Tonesix: 0x0184,
  26626. Tonetwo: 0x01A7,
  26627. Tretroflexhook: 0x01AE,
  26628. Tsecyrillic: 0x0426,
  26629. Tshecyrillic: 0x040B,
  26630. Tsmall: 0xF774,
  26631. Twelveroman: 0x216B,
  26632. Tworoman: 0x2161,
  26633. U: 0x0055,
  26634. Uacute: 0x00DA,
  26635. Uacutesmall: 0xF7FA,
  26636. Ubreve: 0x016C,
  26637. Ucaron: 0x01D3,
  26638. Ucircle: 0x24CA,
  26639. Ucircumflex: 0x00DB,
  26640. Ucircumflexbelow: 0x1E76,
  26641. Ucircumflexsmall: 0xF7FB,
  26642. Ucyrillic: 0x0423,
  26643. Udblacute: 0x0170,
  26644. Udblgrave: 0x0214,
  26645. Udieresis: 0x00DC,
  26646. Udieresisacute: 0x01D7,
  26647. Udieresisbelow: 0x1E72,
  26648. Udieresiscaron: 0x01D9,
  26649. Udieresiscyrillic: 0x04F0,
  26650. Udieresisgrave: 0x01DB,
  26651. Udieresismacron: 0x01D5,
  26652. Udieresissmall: 0xF7FC,
  26653. Udotbelow: 0x1EE4,
  26654. Ugrave: 0x00D9,
  26655. Ugravesmall: 0xF7F9,
  26656. Uhookabove: 0x1EE6,
  26657. Uhorn: 0x01AF,
  26658. Uhornacute: 0x1EE8,
  26659. Uhorndotbelow: 0x1EF0,
  26660. Uhorngrave: 0x1EEA,
  26661. Uhornhookabove: 0x1EEC,
  26662. Uhorntilde: 0x1EEE,
  26663. Uhungarumlaut: 0x0170,
  26664. Uhungarumlautcyrillic: 0x04F2,
  26665. Uinvertedbreve: 0x0216,
  26666. Ukcyrillic: 0x0478,
  26667. Umacron: 0x016A,
  26668. Umacroncyrillic: 0x04EE,
  26669. Umacrondieresis: 0x1E7A,
  26670. Umonospace: 0xFF35,
  26671. Uogonek: 0x0172,
  26672. Upsilon: 0x03A5,
  26673. Upsilon1: 0x03D2,
  26674. Upsilonacutehooksymbolgreek: 0x03D3,
  26675. Upsilonafrican: 0x01B1,
  26676. Upsilondieresis: 0x03AB,
  26677. Upsilondieresishooksymbolgreek: 0x03D4,
  26678. Upsilonhooksymbol: 0x03D2,
  26679. Upsilontonos: 0x038E,
  26680. Uring: 0x016E,
  26681. Ushortcyrillic: 0x040E,
  26682. Usmall: 0xF775,
  26683. Ustraightcyrillic: 0x04AE,
  26684. Ustraightstrokecyrillic: 0x04B0,
  26685. Utilde: 0x0168,
  26686. Utildeacute: 0x1E78,
  26687. Utildebelow: 0x1E74,
  26688. V: 0x0056,
  26689. Vcircle: 0x24CB,
  26690. Vdotbelow: 0x1E7E,
  26691. Vecyrillic: 0x0412,
  26692. Vewarmenian: 0x054E,
  26693. Vhook: 0x01B2,
  26694. Vmonospace: 0xFF36,
  26695. Voarmenian: 0x0548,
  26696. Vsmall: 0xF776,
  26697. Vtilde: 0x1E7C,
  26698. W: 0x0057,
  26699. Wacute: 0x1E82,
  26700. Wcircle: 0x24CC,
  26701. Wcircumflex: 0x0174,
  26702. Wdieresis: 0x1E84,
  26703. Wdotaccent: 0x1E86,
  26704. Wdotbelow: 0x1E88,
  26705. Wgrave: 0x1E80,
  26706. Wmonospace: 0xFF37,
  26707. Wsmall: 0xF777,
  26708. X: 0x0058,
  26709. Xcircle: 0x24CD,
  26710. Xdieresis: 0x1E8C,
  26711. Xdotaccent: 0x1E8A,
  26712. Xeharmenian: 0x053D,
  26713. Xi: 0x039E,
  26714. Xmonospace: 0xFF38,
  26715. Xsmall: 0xF778,
  26716. Y: 0x0059,
  26717. Yacute: 0x00DD,
  26718. Yacutesmall: 0xF7FD,
  26719. Yatcyrillic: 0x0462,
  26720. Ycircle: 0x24CE,
  26721. Ycircumflex: 0x0176,
  26722. Ydieresis: 0x0178,
  26723. Ydieresissmall: 0xF7FF,
  26724. Ydotaccent: 0x1E8E,
  26725. Ydotbelow: 0x1EF4,
  26726. Yericyrillic: 0x042B,
  26727. Yerudieresiscyrillic: 0x04F8,
  26728. Ygrave: 0x1EF2,
  26729. Yhook: 0x01B3,
  26730. Yhookabove: 0x1EF6,
  26731. Yiarmenian: 0x0545,
  26732. Yicyrillic: 0x0407,
  26733. Yiwnarmenian: 0x0552,
  26734. Ymonospace: 0xFF39,
  26735. Ysmall: 0xF779,
  26736. Ytilde: 0x1EF8,
  26737. Yusbigcyrillic: 0x046A,
  26738. Yusbigiotifiedcyrillic: 0x046C,
  26739. Yuslittlecyrillic: 0x0466,
  26740. Yuslittleiotifiedcyrillic: 0x0468,
  26741. Z: 0x005A,
  26742. Zaarmenian: 0x0536,
  26743. Zacute: 0x0179,
  26744. Zcaron: 0x017D,
  26745. Zcaronsmall: 0xF6FF,
  26746. Zcircle: 0x24CF,
  26747. Zcircumflex: 0x1E90,
  26748. Zdot: 0x017B,
  26749. Zdotaccent: 0x017B,
  26750. Zdotbelow: 0x1E92,
  26751. Zecyrillic: 0x0417,
  26752. Zedescendercyrillic: 0x0498,
  26753. Zedieresiscyrillic: 0x04DE,
  26754. Zeta: 0x0396,
  26755. Zhearmenian: 0x053A,
  26756. Zhebrevecyrillic: 0x04C1,
  26757. Zhecyrillic: 0x0416,
  26758. Zhedescendercyrillic: 0x0496,
  26759. Zhedieresiscyrillic: 0x04DC,
  26760. Zlinebelow: 0x1E94,
  26761. Zmonospace: 0xFF3A,
  26762. Zsmall: 0xF77A,
  26763. Zstroke: 0x01B5,
  26764. a: 0x0061,
  26765. aabengali: 0x0986,
  26766. aacute: 0x00E1,
  26767. aadeva: 0x0906,
  26768. aagujarati: 0x0A86,
  26769. aagurmukhi: 0x0A06,
  26770. aamatragurmukhi: 0x0A3E,
  26771. aarusquare: 0x3303,
  26772. aavowelsignbengali: 0x09BE,
  26773. aavowelsigndeva: 0x093E,
  26774. aavowelsigngujarati: 0x0ABE,
  26775. abbreviationmarkarmenian: 0x055F,
  26776. abbreviationsigndeva: 0x0970,
  26777. abengali: 0x0985,
  26778. abopomofo: 0x311A,
  26779. abreve: 0x0103,
  26780. abreveacute: 0x1EAF,
  26781. abrevecyrillic: 0x04D1,
  26782. abrevedotbelow: 0x1EB7,
  26783. abrevegrave: 0x1EB1,
  26784. abrevehookabove: 0x1EB3,
  26785. abrevetilde: 0x1EB5,
  26786. acaron: 0x01CE,
  26787. acircle: 0x24D0,
  26788. acircumflex: 0x00E2,
  26789. acircumflexacute: 0x1EA5,
  26790. acircumflexdotbelow: 0x1EAD,
  26791. acircumflexgrave: 0x1EA7,
  26792. acircumflexhookabove: 0x1EA9,
  26793. acircumflextilde: 0x1EAB,
  26794. acute: 0x00B4,
  26795. acutebelowcmb: 0x0317,
  26796. acutecmb: 0x0301,
  26797. acutecomb: 0x0301,
  26798. acutedeva: 0x0954,
  26799. acutelowmod: 0x02CF,
  26800. acutetonecmb: 0x0341,
  26801. acyrillic: 0x0430,
  26802. adblgrave: 0x0201,
  26803. addakgurmukhi: 0x0A71,
  26804. adeva: 0x0905,
  26805. adieresis: 0x00E4,
  26806. adieresiscyrillic: 0x04D3,
  26807. adieresismacron: 0x01DF,
  26808. adotbelow: 0x1EA1,
  26809. adotmacron: 0x01E1,
  26810. ae: 0x00E6,
  26811. aeacute: 0x01FD,
  26812. aekorean: 0x3150,
  26813. aemacron: 0x01E3,
  26814. afii00208: 0x2015,
  26815. afii08941: 0x20A4,
  26816. afii10017: 0x0410,
  26817. afii10018: 0x0411,
  26818. afii10019: 0x0412,
  26819. afii10020: 0x0413,
  26820. afii10021: 0x0414,
  26821. afii10022: 0x0415,
  26822. afii10023: 0x0401,
  26823. afii10024: 0x0416,
  26824. afii10025: 0x0417,
  26825. afii10026: 0x0418,
  26826. afii10027: 0x0419,
  26827. afii10028: 0x041A,
  26828. afii10029: 0x041B,
  26829. afii10030: 0x041C,
  26830. afii10031: 0x041D,
  26831. afii10032: 0x041E,
  26832. afii10033: 0x041F,
  26833. afii10034: 0x0420,
  26834. afii10035: 0x0421,
  26835. afii10036: 0x0422,
  26836. afii10037: 0x0423,
  26837. afii10038: 0x0424,
  26838. afii10039: 0x0425,
  26839. afii10040: 0x0426,
  26840. afii10041: 0x0427,
  26841. afii10042: 0x0428,
  26842. afii10043: 0x0429,
  26843. afii10044: 0x042A,
  26844. afii10045: 0x042B,
  26845. afii10046: 0x042C,
  26846. afii10047: 0x042D,
  26847. afii10048: 0x042E,
  26848. afii10049: 0x042F,
  26849. afii10050: 0x0490,
  26850. afii10051: 0x0402,
  26851. afii10052: 0x0403,
  26852. afii10053: 0x0404,
  26853. afii10054: 0x0405,
  26854. afii10055: 0x0406,
  26855. afii10056: 0x0407,
  26856. afii10057: 0x0408,
  26857. afii10058: 0x0409,
  26858. afii10059: 0x040A,
  26859. afii10060: 0x040B,
  26860. afii10061: 0x040C,
  26861. afii10062: 0x040E,
  26862. afii10063: 0xF6C4,
  26863. afii10064: 0xF6C5,
  26864. afii10065: 0x0430,
  26865. afii10066: 0x0431,
  26866. afii10067: 0x0432,
  26867. afii10068: 0x0433,
  26868. afii10069: 0x0434,
  26869. afii10070: 0x0435,
  26870. afii10071: 0x0451,
  26871. afii10072: 0x0436,
  26872. afii10073: 0x0437,
  26873. afii10074: 0x0438,
  26874. afii10075: 0x0439,
  26875. afii10076: 0x043A,
  26876. afii10077: 0x043B,
  26877. afii10078: 0x043C,
  26878. afii10079: 0x043D,
  26879. afii10080: 0x043E,
  26880. afii10081: 0x043F,
  26881. afii10082: 0x0440,
  26882. afii10083: 0x0441,
  26883. afii10084: 0x0442,
  26884. afii10085: 0x0443,
  26885. afii10086: 0x0444,
  26886. afii10087: 0x0445,
  26887. afii10088: 0x0446,
  26888. afii10089: 0x0447,
  26889. afii10090: 0x0448,
  26890. afii10091: 0x0449,
  26891. afii10092: 0x044A,
  26892. afii10093: 0x044B,
  26893. afii10094: 0x044C,
  26894. afii10095: 0x044D,
  26895. afii10096: 0x044E,
  26896. afii10097: 0x044F,
  26897. afii10098: 0x0491,
  26898. afii10099: 0x0452,
  26899. afii10100: 0x0453,
  26900. afii10101: 0x0454,
  26901. afii10102: 0x0455,
  26902. afii10103: 0x0456,
  26903. afii10104: 0x0457,
  26904. afii10105: 0x0458,
  26905. afii10106: 0x0459,
  26906. afii10107: 0x045A,
  26907. afii10108: 0x045B,
  26908. afii10109: 0x045C,
  26909. afii10110: 0x045E,
  26910. afii10145: 0x040F,
  26911. afii10146: 0x0462,
  26912. afii10147: 0x0472,
  26913. afii10148: 0x0474,
  26914. afii10192: 0xF6C6,
  26915. afii10193: 0x045F,
  26916. afii10194: 0x0463,
  26917. afii10195: 0x0473,
  26918. afii10196: 0x0475,
  26919. afii10831: 0xF6C7,
  26920. afii10832: 0xF6C8,
  26921. afii10846: 0x04D9,
  26922. afii299: 0x200E,
  26923. afii300: 0x200F,
  26924. afii301: 0x200D,
  26925. afii57381: 0x066A,
  26926. afii57388: 0x060C,
  26927. afii57392: 0x0660,
  26928. afii57393: 0x0661,
  26929. afii57394: 0x0662,
  26930. afii57395: 0x0663,
  26931. afii57396: 0x0664,
  26932. afii57397: 0x0665,
  26933. afii57398: 0x0666,
  26934. afii57399: 0x0667,
  26935. afii57400: 0x0668,
  26936. afii57401: 0x0669,
  26937. afii57403: 0x061B,
  26938. afii57407: 0x061F,
  26939. afii57409: 0x0621,
  26940. afii57410: 0x0622,
  26941. afii57411: 0x0623,
  26942. afii57412: 0x0624,
  26943. afii57413: 0x0625,
  26944. afii57414: 0x0626,
  26945. afii57415: 0x0627,
  26946. afii57416: 0x0628,
  26947. afii57417: 0x0629,
  26948. afii57418: 0x062A,
  26949. afii57419: 0x062B,
  26950. afii57420: 0x062C,
  26951. afii57421: 0x062D,
  26952. afii57422: 0x062E,
  26953. afii57423: 0x062F,
  26954. afii57424: 0x0630,
  26955. afii57425: 0x0631,
  26956. afii57426: 0x0632,
  26957. afii57427: 0x0633,
  26958. afii57428: 0x0634,
  26959. afii57429: 0x0635,
  26960. afii57430: 0x0636,
  26961. afii57431: 0x0637,
  26962. afii57432: 0x0638,
  26963. afii57433: 0x0639,
  26964. afii57434: 0x063A,
  26965. afii57440: 0x0640,
  26966. afii57441: 0x0641,
  26967. afii57442: 0x0642,
  26968. afii57443: 0x0643,
  26969. afii57444: 0x0644,
  26970. afii57445: 0x0645,
  26971. afii57446: 0x0646,
  26972. afii57448: 0x0648,
  26973. afii57449: 0x0649,
  26974. afii57450: 0x064A,
  26975. afii57451: 0x064B,
  26976. afii57452: 0x064C,
  26977. afii57453: 0x064D,
  26978. afii57454: 0x064E,
  26979. afii57455: 0x064F,
  26980. afii57456: 0x0650,
  26981. afii57457: 0x0651,
  26982. afii57458: 0x0652,
  26983. afii57470: 0x0647,
  26984. afii57505: 0x06A4,
  26985. afii57506: 0x067E,
  26986. afii57507: 0x0686,
  26987. afii57508: 0x0698,
  26988. afii57509: 0x06AF,
  26989. afii57511: 0x0679,
  26990. afii57512: 0x0688,
  26991. afii57513: 0x0691,
  26992. afii57514: 0x06BA,
  26993. afii57519: 0x06D2,
  26994. afii57534: 0x06D5,
  26995. afii57636: 0x20AA,
  26996. afii57645: 0x05BE,
  26997. afii57658: 0x05C3,
  26998. afii57664: 0x05D0,
  26999. afii57665: 0x05D1,
  27000. afii57666: 0x05D2,
  27001. afii57667: 0x05D3,
  27002. afii57668: 0x05D4,
  27003. afii57669: 0x05D5,
  27004. afii57670: 0x05D6,
  27005. afii57671: 0x05D7,
  27006. afii57672: 0x05D8,
  27007. afii57673: 0x05D9,
  27008. afii57674: 0x05DA,
  27009. afii57675: 0x05DB,
  27010. afii57676: 0x05DC,
  27011. afii57677: 0x05DD,
  27012. afii57678: 0x05DE,
  27013. afii57679: 0x05DF,
  27014. afii57680: 0x05E0,
  27015. afii57681: 0x05E1,
  27016. afii57682: 0x05E2,
  27017. afii57683: 0x05E3,
  27018. afii57684: 0x05E4,
  27019. afii57685: 0x05E5,
  27020. afii57686: 0x05E6,
  27021. afii57687: 0x05E7,
  27022. afii57688: 0x05E8,
  27023. afii57689: 0x05E9,
  27024. afii57690: 0x05EA,
  27025. afii57694: 0xFB2A,
  27026. afii57695: 0xFB2B,
  27027. afii57700: 0xFB4B,
  27028. afii57705: 0xFB1F,
  27029. afii57716: 0x05F0,
  27030. afii57717: 0x05F1,
  27031. afii57718: 0x05F2,
  27032. afii57723: 0xFB35,
  27033. afii57793: 0x05B4,
  27034. afii57794: 0x05B5,
  27035. afii57795: 0x05B6,
  27036. afii57796: 0x05BB,
  27037. afii57797: 0x05B8,
  27038. afii57798: 0x05B7,
  27039. afii57799: 0x05B0,
  27040. afii57800: 0x05B2,
  27041. afii57801: 0x05B1,
  27042. afii57802: 0x05B3,
  27043. afii57803: 0x05C2,
  27044. afii57804: 0x05C1,
  27045. afii57806: 0x05B9,
  27046. afii57807: 0x05BC,
  27047. afii57839: 0x05BD,
  27048. afii57841: 0x05BF,
  27049. afii57842: 0x05C0,
  27050. afii57929: 0x02BC,
  27051. afii61248: 0x2105,
  27052. afii61289: 0x2113,
  27053. afii61352: 0x2116,
  27054. afii61573: 0x202C,
  27055. afii61574: 0x202D,
  27056. afii61575: 0x202E,
  27057. afii61664: 0x200C,
  27058. afii63167: 0x066D,
  27059. afii64937: 0x02BD,
  27060. agrave: 0x00E0,
  27061. agujarati: 0x0A85,
  27062. agurmukhi: 0x0A05,
  27063. ahiragana: 0x3042,
  27064. ahookabove: 0x1EA3,
  27065. aibengali: 0x0990,
  27066. aibopomofo: 0x311E,
  27067. aideva: 0x0910,
  27068. aiecyrillic: 0x04D5,
  27069. aigujarati: 0x0A90,
  27070. aigurmukhi: 0x0A10,
  27071. aimatragurmukhi: 0x0A48,
  27072. ainarabic: 0x0639,
  27073. ainfinalarabic: 0xFECA,
  27074. aininitialarabic: 0xFECB,
  27075. ainmedialarabic: 0xFECC,
  27076. ainvertedbreve: 0x0203,
  27077. aivowelsignbengali: 0x09C8,
  27078. aivowelsigndeva: 0x0948,
  27079. aivowelsigngujarati: 0x0AC8,
  27080. akatakana: 0x30A2,
  27081. akatakanahalfwidth: 0xFF71,
  27082. akorean: 0x314F,
  27083. alef: 0x05D0,
  27084. alefarabic: 0x0627,
  27085. alefdageshhebrew: 0xFB30,
  27086. aleffinalarabic: 0xFE8E,
  27087. alefhamzaabovearabic: 0x0623,
  27088. alefhamzaabovefinalarabic: 0xFE84,
  27089. alefhamzabelowarabic: 0x0625,
  27090. alefhamzabelowfinalarabic: 0xFE88,
  27091. alefhebrew: 0x05D0,
  27092. aleflamedhebrew: 0xFB4F,
  27093. alefmaddaabovearabic: 0x0622,
  27094. alefmaddaabovefinalarabic: 0xFE82,
  27095. alefmaksuraarabic: 0x0649,
  27096. alefmaksurafinalarabic: 0xFEF0,
  27097. alefmaksurainitialarabic: 0xFEF3,
  27098. alefmaksuramedialarabic: 0xFEF4,
  27099. alefpatahhebrew: 0xFB2E,
  27100. alefqamatshebrew: 0xFB2F,
  27101. aleph: 0x2135,
  27102. allequal: 0x224C,
  27103. alpha: 0x03B1,
  27104. alphatonos: 0x03AC,
  27105. amacron: 0x0101,
  27106. amonospace: 0xFF41,
  27107. ampersand: 0x0026,
  27108. ampersandmonospace: 0xFF06,
  27109. ampersandsmall: 0xF726,
  27110. amsquare: 0x33C2,
  27111. anbopomofo: 0x3122,
  27112. angbopomofo: 0x3124,
  27113. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  27114. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  27115. angkhankhuthai: 0x0E5A,
  27116. angle: 0x2220,
  27117. anglebracketleft: 0x3008,
  27118. anglebracketleftvertical: 0xFE3F,
  27119. anglebracketright: 0x3009,
  27120. anglebracketrightvertical: 0xFE40,
  27121. angleleft: 0x2329,
  27122. angleright: 0x232A,
  27123. angstrom: 0x212B,
  27124. anoteleia: 0x0387,
  27125. anudattadeva: 0x0952,
  27126. anusvarabengali: 0x0982,
  27127. anusvaradeva: 0x0902,
  27128. anusvaragujarati: 0x0A82,
  27129. aogonek: 0x0105,
  27130. apaatosquare: 0x3300,
  27131. aparen: 0x249C,
  27132. apostrophearmenian: 0x055A,
  27133. apostrophemod: 0x02BC,
  27134. apple: 0xF8FF,
  27135. approaches: 0x2250,
  27136. approxequal: 0x2248,
  27137. approxequalorimage: 0x2252,
  27138. approximatelyequal: 0x2245,
  27139. araeaekorean: 0x318E,
  27140. araeakorean: 0x318D,
  27141. arc: 0x2312,
  27142. arighthalfring: 0x1E9A,
  27143. aring: 0x00E5,
  27144. aringacute: 0x01FB,
  27145. aringbelow: 0x1E01,
  27146. arrowboth: 0x2194,
  27147. arrowdashdown: 0x21E3,
  27148. arrowdashleft: 0x21E0,
  27149. arrowdashright: 0x21E2,
  27150. arrowdashup: 0x21E1,
  27151. arrowdblboth: 0x21D4,
  27152. arrowdbldown: 0x21D3,
  27153. arrowdblleft: 0x21D0,
  27154. arrowdblright: 0x21D2,
  27155. arrowdblup: 0x21D1,
  27156. arrowdown: 0x2193,
  27157. arrowdownleft: 0x2199,
  27158. arrowdownright: 0x2198,
  27159. arrowdownwhite: 0x21E9,
  27160. arrowheaddownmod: 0x02C5,
  27161. arrowheadleftmod: 0x02C2,
  27162. arrowheadrightmod: 0x02C3,
  27163. arrowheadupmod: 0x02C4,
  27164. arrowhorizex: 0xF8E7,
  27165. arrowleft: 0x2190,
  27166. arrowleftdbl: 0x21D0,
  27167. arrowleftdblstroke: 0x21CD,
  27168. arrowleftoverright: 0x21C6,
  27169. arrowleftwhite: 0x21E6,
  27170. arrowright: 0x2192,
  27171. arrowrightdblstroke: 0x21CF,
  27172. arrowrightheavy: 0x279E,
  27173. arrowrightoverleft: 0x21C4,
  27174. arrowrightwhite: 0x21E8,
  27175. arrowtableft: 0x21E4,
  27176. arrowtabright: 0x21E5,
  27177. arrowup: 0x2191,
  27178. arrowupdn: 0x2195,
  27179. arrowupdnbse: 0x21A8,
  27180. arrowupdownbase: 0x21A8,
  27181. arrowupleft: 0x2196,
  27182. arrowupleftofdown: 0x21C5,
  27183. arrowupright: 0x2197,
  27184. arrowupwhite: 0x21E7,
  27185. arrowvertex: 0xF8E6,
  27186. asciicircum: 0x005E,
  27187. asciicircummonospace: 0xFF3E,
  27188. asciitilde: 0x007E,
  27189. asciitildemonospace: 0xFF5E,
  27190. ascript: 0x0251,
  27191. ascriptturned: 0x0252,
  27192. asmallhiragana: 0x3041,
  27193. asmallkatakana: 0x30A1,
  27194. asmallkatakanahalfwidth: 0xFF67,
  27195. asterisk: 0x002A,
  27196. asteriskaltonearabic: 0x066D,
  27197. asteriskarabic: 0x066D,
  27198. asteriskmath: 0x2217,
  27199. asteriskmonospace: 0xFF0A,
  27200. asterisksmall: 0xFE61,
  27201. asterism: 0x2042,
  27202. asuperior: 0xF6E9,
  27203. asymptoticallyequal: 0x2243,
  27204. at: 0x0040,
  27205. atilde: 0x00E3,
  27206. atmonospace: 0xFF20,
  27207. atsmall: 0xFE6B,
  27208. aturned: 0x0250,
  27209. aubengali: 0x0994,
  27210. aubopomofo: 0x3120,
  27211. audeva: 0x0914,
  27212. augujarati: 0x0A94,
  27213. augurmukhi: 0x0A14,
  27214. aulengthmarkbengali: 0x09D7,
  27215. aumatragurmukhi: 0x0A4C,
  27216. auvowelsignbengali: 0x09CC,
  27217. auvowelsigndeva: 0x094C,
  27218. auvowelsigngujarati: 0x0ACC,
  27219. avagrahadeva: 0x093D,
  27220. aybarmenian: 0x0561,
  27221. ayin: 0x05E2,
  27222. ayinaltonehebrew: 0xFB20,
  27223. ayinhebrew: 0x05E2,
  27224. b: 0x0062,
  27225. babengali: 0x09AC,
  27226. backslash: 0x005C,
  27227. backslashmonospace: 0xFF3C,
  27228. badeva: 0x092C,
  27229. bagujarati: 0x0AAC,
  27230. bagurmukhi: 0x0A2C,
  27231. bahiragana: 0x3070,
  27232. bahtthai: 0x0E3F,
  27233. bakatakana: 0x30D0,
  27234. bar: 0x007C,
  27235. barmonospace: 0xFF5C,
  27236. bbopomofo: 0x3105,
  27237. bcircle: 0x24D1,
  27238. bdotaccent: 0x1E03,
  27239. bdotbelow: 0x1E05,
  27240. beamedsixteenthnotes: 0x266C,
  27241. because: 0x2235,
  27242. becyrillic: 0x0431,
  27243. beharabic: 0x0628,
  27244. behfinalarabic: 0xFE90,
  27245. behinitialarabic: 0xFE91,
  27246. behiragana: 0x3079,
  27247. behmedialarabic: 0xFE92,
  27248. behmeeminitialarabic: 0xFC9F,
  27249. behmeemisolatedarabic: 0xFC08,
  27250. behnoonfinalarabic: 0xFC6D,
  27251. bekatakana: 0x30D9,
  27252. benarmenian: 0x0562,
  27253. bet: 0x05D1,
  27254. beta: 0x03B2,
  27255. betasymbolgreek: 0x03D0,
  27256. betdagesh: 0xFB31,
  27257. betdageshhebrew: 0xFB31,
  27258. bethebrew: 0x05D1,
  27259. betrafehebrew: 0xFB4C,
  27260. bhabengali: 0x09AD,
  27261. bhadeva: 0x092D,
  27262. bhagujarati: 0x0AAD,
  27263. bhagurmukhi: 0x0A2D,
  27264. bhook: 0x0253,
  27265. bihiragana: 0x3073,
  27266. bikatakana: 0x30D3,
  27267. bilabialclick: 0x0298,
  27268. bindigurmukhi: 0x0A02,
  27269. birusquare: 0x3331,
  27270. blackcircle: 0x25CF,
  27271. blackdiamond: 0x25C6,
  27272. blackdownpointingtriangle: 0x25BC,
  27273. blackleftpointingpointer: 0x25C4,
  27274. blackleftpointingtriangle: 0x25C0,
  27275. blacklenticularbracketleft: 0x3010,
  27276. blacklenticularbracketleftvertical: 0xFE3B,
  27277. blacklenticularbracketright: 0x3011,
  27278. blacklenticularbracketrightvertical: 0xFE3C,
  27279. blacklowerlefttriangle: 0x25E3,
  27280. blacklowerrighttriangle: 0x25E2,
  27281. blackrectangle: 0x25AC,
  27282. blackrightpointingpointer: 0x25BA,
  27283. blackrightpointingtriangle: 0x25B6,
  27284. blacksmallsquare: 0x25AA,
  27285. blacksmilingface: 0x263B,
  27286. blacksquare: 0x25A0,
  27287. blackstar: 0x2605,
  27288. blackupperlefttriangle: 0x25E4,
  27289. blackupperrighttriangle: 0x25E5,
  27290. blackuppointingsmalltriangle: 0x25B4,
  27291. blackuppointingtriangle: 0x25B2,
  27292. blank: 0x2423,
  27293. blinebelow: 0x1E07,
  27294. block: 0x2588,
  27295. bmonospace: 0xFF42,
  27296. bobaimaithai: 0x0E1A,
  27297. bohiragana: 0x307C,
  27298. bokatakana: 0x30DC,
  27299. bparen: 0x249D,
  27300. bqsquare: 0x33C3,
  27301. braceex: 0xF8F4,
  27302. braceleft: 0x007B,
  27303. braceleftbt: 0xF8F3,
  27304. braceleftmid: 0xF8F2,
  27305. braceleftmonospace: 0xFF5B,
  27306. braceleftsmall: 0xFE5B,
  27307. bracelefttp: 0xF8F1,
  27308. braceleftvertical: 0xFE37,
  27309. braceright: 0x007D,
  27310. bracerightbt: 0xF8FE,
  27311. bracerightmid: 0xF8FD,
  27312. bracerightmonospace: 0xFF5D,
  27313. bracerightsmall: 0xFE5C,
  27314. bracerighttp: 0xF8FC,
  27315. bracerightvertical: 0xFE38,
  27316. bracketleft: 0x005B,
  27317. bracketleftbt: 0xF8F0,
  27318. bracketleftex: 0xF8EF,
  27319. bracketleftmonospace: 0xFF3B,
  27320. bracketlefttp: 0xF8EE,
  27321. bracketright: 0x005D,
  27322. bracketrightbt: 0xF8FB,
  27323. bracketrightex: 0xF8FA,
  27324. bracketrightmonospace: 0xFF3D,
  27325. bracketrighttp: 0xF8F9,
  27326. breve: 0x02D8,
  27327. brevebelowcmb: 0x032E,
  27328. brevecmb: 0x0306,
  27329. breveinvertedbelowcmb: 0x032F,
  27330. breveinvertedcmb: 0x0311,
  27331. breveinverteddoublecmb: 0x0361,
  27332. bridgebelowcmb: 0x032A,
  27333. bridgeinvertedbelowcmb: 0x033A,
  27334. brokenbar: 0x00A6,
  27335. bstroke: 0x0180,
  27336. bsuperior: 0xF6EA,
  27337. btopbar: 0x0183,
  27338. buhiragana: 0x3076,
  27339. bukatakana: 0x30D6,
  27340. bullet: 0x2022,
  27341. bulletinverse: 0x25D8,
  27342. bulletoperator: 0x2219,
  27343. bullseye: 0x25CE,
  27344. c: 0x0063,
  27345. caarmenian: 0x056E,
  27346. cabengali: 0x099A,
  27347. cacute: 0x0107,
  27348. cadeva: 0x091A,
  27349. cagujarati: 0x0A9A,
  27350. cagurmukhi: 0x0A1A,
  27351. calsquare: 0x3388,
  27352. candrabindubengali: 0x0981,
  27353. candrabinducmb: 0x0310,
  27354. candrabindudeva: 0x0901,
  27355. candrabindugujarati: 0x0A81,
  27356. capslock: 0x21EA,
  27357. careof: 0x2105,
  27358. caron: 0x02C7,
  27359. caronbelowcmb: 0x032C,
  27360. caroncmb: 0x030C,
  27361. carriagereturn: 0x21B5,
  27362. cbopomofo: 0x3118,
  27363. ccaron: 0x010D,
  27364. ccedilla: 0x00E7,
  27365. ccedillaacute: 0x1E09,
  27366. ccircle: 0x24D2,
  27367. ccircumflex: 0x0109,
  27368. ccurl: 0x0255,
  27369. cdot: 0x010B,
  27370. cdotaccent: 0x010B,
  27371. cdsquare: 0x33C5,
  27372. cedilla: 0x00B8,
  27373. cedillacmb: 0x0327,
  27374. cent: 0x00A2,
  27375. centigrade: 0x2103,
  27376. centinferior: 0xF6DF,
  27377. centmonospace: 0xFFE0,
  27378. centoldstyle: 0xF7A2,
  27379. centsuperior: 0xF6E0,
  27380. chaarmenian: 0x0579,
  27381. chabengali: 0x099B,
  27382. chadeva: 0x091B,
  27383. chagujarati: 0x0A9B,
  27384. chagurmukhi: 0x0A1B,
  27385. chbopomofo: 0x3114,
  27386. cheabkhasiancyrillic: 0x04BD,
  27387. checkmark: 0x2713,
  27388. checyrillic: 0x0447,
  27389. chedescenderabkhasiancyrillic: 0x04BF,
  27390. chedescendercyrillic: 0x04B7,
  27391. chedieresiscyrillic: 0x04F5,
  27392. cheharmenian: 0x0573,
  27393. chekhakassiancyrillic: 0x04CC,
  27394. cheverticalstrokecyrillic: 0x04B9,
  27395. chi: 0x03C7,
  27396. chieuchacirclekorean: 0x3277,
  27397. chieuchaparenkorean: 0x3217,
  27398. chieuchcirclekorean: 0x3269,
  27399. chieuchkorean: 0x314A,
  27400. chieuchparenkorean: 0x3209,
  27401. chochangthai: 0x0E0A,
  27402. chochanthai: 0x0E08,
  27403. chochingthai: 0x0E09,
  27404. chochoethai: 0x0E0C,
  27405. chook: 0x0188,
  27406. cieucacirclekorean: 0x3276,
  27407. cieucaparenkorean: 0x3216,
  27408. cieuccirclekorean: 0x3268,
  27409. cieuckorean: 0x3148,
  27410. cieucparenkorean: 0x3208,
  27411. cieucuparenkorean: 0x321C,
  27412. circle: 0x25CB,
  27413. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27414. circlemultiply: 0x2297,
  27415. circleot: 0x2299,
  27416. circleplus: 0x2295,
  27417. circlepostalmark: 0x3036,
  27418. circlewithlefthalfblack: 0x25D0,
  27419. circlewithrighthalfblack: 0x25D1,
  27420. circumflex: 0x02C6,
  27421. circumflexbelowcmb: 0x032D,
  27422. circumflexcmb: 0x0302,
  27423. clear: 0x2327,
  27424. clickalveolar: 0x01C2,
  27425. clickdental: 0x01C0,
  27426. clicklateral: 0x01C1,
  27427. clickretroflex: 0x01C3,
  27428. club: 0x2663,
  27429. clubsuitblack: 0x2663,
  27430. clubsuitwhite: 0x2667,
  27431. cmcubedsquare: 0x33A4,
  27432. cmonospace: 0xFF43,
  27433. cmsquaredsquare: 0x33A0,
  27434. coarmenian: 0x0581,
  27435. colon: 0x003A,
  27436. colonmonetary: 0x20A1,
  27437. colonmonospace: 0xFF1A,
  27438. colonsign: 0x20A1,
  27439. colonsmall: 0xFE55,
  27440. colontriangularhalfmod: 0x02D1,
  27441. colontriangularmod: 0x02D0,
  27442. comma: 0x002C,
  27443. commaabovecmb: 0x0313,
  27444. commaaboverightcmb: 0x0315,
  27445. commaaccent: 0xF6C3,
  27446. commaarabic: 0x060C,
  27447. commaarmenian: 0x055D,
  27448. commainferior: 0xF6E1,
  27449. commamonospace: 0xFF0C,
  27450. commareversedabovecmb: 0x0314,
  27451. commareversedmod: 0x02BD,
  27452. commasmall: 0xFE50,
  27453. commasuperior: 0xF6E2,
  27454. commaturnedabovecmb: 0x0312,
  27455. commaturnedmod: 0x02BB,
  27456. compass: 0x263C,
  27457. congruent: 0x2245,
  27458. contourintegral: 0x222E,
  27459. control: 0x2303,
  27460. controlACK: 0x0006,
  27461. controlBEL: 0x0007,
  27462. controlBS: 0x0008,
  27463. controlCAN: 0x0018,
  27464. controlCR: 0x000D,
  27465. controlDC1: 0x0011,
  27466. controlDC2: 0x0012,
  27467. controlDC3: 0x0013,
  27468. controlDC4: 0x0014,
  27469. controlDEL: 0x007F,
  27470. controlDLE: 0x0010,
  27471. controlEM: 0x0019,
  27472. controlENQ: 0x0005,
  27473. controlEOT: 0x0004,
  27474. controlESC: 0x001B,
  27475. controlETB: 0x0017,
  27476. controlETX: 0x0003,
  27477. controlFF: 0x000C,
  27478. controlFS: 0x001C,
  27479. controlGS: 0x001D,
  27480. controlHT: 0x0009,
  27481. controlLF: 0x000A,
  27482. controlNAK: 0x0015,
  27483. controlRS: 0x001E,
  27484. controlSI: 0x000F,
  27485. controlSO: 0x000E,
  27486. controlSOT: 0x0002,
  27487. controlSTX: 0x0001,
  27488. controlSUB: 0x001A,
  27489. controlSYN: 0x0016,
  27490. controlUS: 0x001F,
  27491. controlVT: 0x000B,
  27492. copyright: 0x00A9,
  27493. copyrightsans: 0xF8E9,
  27494. copyrightserif: 0xF6D9,
  27495. cornerbracketleft: 0x300C,
  27496. cornerbracketlefthalfwidth: 0xFF62,
  27497. cornerbracketleftvertical: 0xFE41,
  27498. cornerbracketright: 0x300D,
  27499. cornerbracketrighthalfwidth: 0xFF63,
  27500. cornerbracketrightvertical: 0xFE42,
  27501. corporationsquare: 0x337F,
  27502. cosquare: 0x33C7,
  27503. coverkgsquare: 0x33C6,
  27504. cparen: 0x249E,
  27505. cruzeiro: 0x20A2,
  27506. cstretched: 0x0297,
  27507. curlyand: 0x22CF,
  27508. curlyor: 0x22CE,
  27509. currency: 0x00A4,
  27510. cyrBreve: 0xF6D1,
  27511. cyrFlex: 0xF6D2,
  27512. cyrbreve: 0xF6D4,
  27513. cyrflex: 0xF6D5,
  27514. d: 0x0064,
  27515. daarmenian: 0x0564,
  27516. dabengali: 0x09A6,
  27517. dadarabic: 0x0636,
  27518. dadeva: 0x0926,
  27519. dadfinalarabic: 0xFEBE,
  27520. dadinitialarabic: 0xFEBF,
  27521. dadmedialarabic: 0xFEC0,
  27522. dagesh: 0x05BC,
  27523. dageshhebrew: 0x05BC,
  27524. dagger: 0x2020,
  27525. daggerdbl: 0x2021,
  27526. dagujarati: 0x0AA6,
  27527. dagurmukhi: 0x0A26,
  27528. dahiragana: 0x3060,
  27529. dakatakana: 0x30C0,
  27530. dalarabic: 0x062F,
  27531. dalet: 0x05D3,
  27532. daletdagesh: 0xFB33,
  27533. daletdageshhebrew: 0xFB33,
  27534. dalethebrew: 0x05D3,
  27535. dalfinalarabic: 0xFEAA,
  27536. dammaarabic: 0x064F,
  27537. dammalowarabic: 0x064F,
  27538. dammatanaltonearabic: 0x064C,
  27539. dammatanarabic: 0x064C,
  27540. danda: 0x0964,
  27541. dargahebrew: 0x05A7,
  27542. dargalefthebrew: 0x05A7,
  27543. dasiapneumatacyrilliccmb: 0x0485,
  27544. dblGrave: 0xF6D3,
  27545. dblanglebracketleft: 0x300A,
  27546. dblanglebracketleftvertical: 0xFE3D,
  27547. dblanglebracketright: 0x300B,
  27548. dblanglebracketrightvertical: 0xFE3E,
  27549. dblarchinvertedbelowcmb: 0x032B,
  27550. dblarrowleft: 0x21D4,
  27551. dblarrowright: 0x21D2,
  27552. dbldanda: 0x0965,
  27553. dblgrave: 0xF6D6,
  27554. dblgravecmb: 0x030F,
  27555. dblintegral: 0x222C,
  27556. dbllowline: 0x2017,
  27557. dbllowlinecmb: 0x0333,
  27558. dbloverlinecmb: 0x033F,
  27559. dblprimemod: 0x02BA,
  27560. dblverticalbar: 0x2016,
  27561. dblverticallineabovecmb: 0x030E,
  27562. dbopomofo: 0x3109,
  27563. dbsquare: 0x33C8,
  27564. dcaron: 0x010F,
  27565. dcedilla: 0x1E11,
  27566. dcircle: 0x24D3,
  27567. dcircumflexbelow: 0x1E13,
  27568. dcroat: 0x0111,
  27569. ddabengali: 0x09A1,
  27570. ddadeva: 0x0921,
  27571. ddagujarati: 0x0AA1,
  27572. ddagurmukhi: 0x0A21,
  27573. ddalarabic: 0x0688,
  27574. ddalfinalarabic: 0xFB89,
  27575. dddhadeva: 0x095C,
  27576. ddhabengali: 0x09A2,
  27577. ddhadeva: 0x0922,
  27578. ddhagujarati: 0x0AA2,
  27579. ddhagurmukhi: 0x0A22,
  27580. ddotaccent: 0x1E0B,
  27581. ddotbelow: 0x1E0D,
  27582. decimalseparatorarabic: 0x066B,
  27583. decimalseparatorpersian: 0x066B,
  27584. decyrillic: 0x0434,
  27585. degree: 0x00B0,
  27586. dehihebrew: 0x05AD,
  27587. dehiragana: 0x3067,
  27588. deicoptic: 0x03EF,
  27589. dekatakana: 0x30C7,
  27590. deleteleft: 0x232B,
  27591. deleteright: 0x2326,
  27592. delta: 0x03B4,
  27593. deltaturned: 0x018D,
  27594. denominatorminusonenumeratorbengali: 0x09F8,
  27595. dezh: 0x02A4,
  27596. dhabengali: 0x09A7,
  27597. dhadeva: 0x0927,
  27598. dhagujarati: 0x0AA7,
  27599. dhagurmukhi: 0x0A27,
  27600. dhook: 0x0257,
  27601. dialytikatonos: 0x0385,
  27602. dialytikatonoscmb: 0x0344,
  27603. diamond: 0x2666,
  27604. diamondsuitwhite: 0x2662,
  27605. dieresis: 0x00A8,
  27606. dieresisacute: 0xF6D7,
  27607. dieresisbelowcmb: 0x0324,
  27608. dieresiscmb: 0x0308,
  27609. dieresisgrave: 0xF6D8,
  27610. dieresistonos: 0x0385,
  27611. dihiragana: 0x3062,
  27612. dikatakana: 0x30C2,
  27613. dittomark: 0x3003,
  27614. divide: 0x00F7,
  27615. divides: 0x2223,
  27616. divisionslash: 0x2215,
  27617. djecyrillic: 0x0452,
  27618. dkshade: 0x2593,
  27619. dlinebelow: 0x1E0F,
  27620. dlsquare: 0x3397,
  27621. dmacron: 0x0111,
  27622. dmonospace: 0xFF44,
  27623. dnblock: 0x2584,
  27624. dochadathai: 0x0E0E,
  27625. dodekthai: 0x0E14,
  27626. dohiragana: 0x3069,
  27627. dokatakana: 0x30C9,
  27628. dollar: 0x0024,
  27629. dollarinferior: 0xF6E3,
  27630. dollarmonospace: 0xFF04,
  27631. dollaroldstyle: 0xF724,
  27632. dollarsmall: 0xFE69,
  27633. dollarsuperior: 0xF6E4,
  27634. dong: 0x20AB,
  27635. dorusquare: 0x3326,
  27636. dotaccent: 0x02D9,
  27637. dotaccentcmb: 0x0307,
  27638. dotbelowcmb: 0x0323,
  27639. dotbelowcomb: 0x0323,
  27640. dotkatakana: 0x30FB,
  27641. dotlessi: 0x0131,
  27642. dotlessj: 0xF6BE,
  27643. dotlessjstrokehook: 0x0284,
  27644. dotmath: 0x22C5,
  27645. dottedcircle: 0x25CC,
  27646. doubleyodpatah: 0xFB1F,
  27647. doubleyodpatahhebrew: 0xFB1F,
  27648. downtackbelowcmb: 0x031E,
  27649. downtackmod: 0x02D5,
  27650. dparen: 0x249F,
  27651. dsuperior: 0xF6EB,
  27652. dtail: 0x0256,
  27653. dtopbar: 0x018C,
  27654. duhiragana: 0x3065,
  27655. dukatakana: 0x30C5,
  27656. dz: 0x01F3,
  27657. dzaltone: 0x02A3,
  27658. dzcaron: 0x01C6,
  27659. dzcurl: 0x02A5,
  27660. dzeabkhasiancyrillic: 0x04E1,
  27661. dzecyrillic: 0x0455,
  27662. dzhecyrillic: 0x045F,
  27663. e: 0x0065,
  27664. eacute: 0x00E9,
  27665. earth: 0x2641,
  27666. ebengali: 0x098F,
  27667. ebopomofo: 0x311C,
  27668. ebreve: 0x0115,
  27669. ecandradeva: 0x090D,
  27670. ecandragujarati: 0x0A8D,
  27671. ecandravowelsigndeva: 0x0945,
  27672. ecandravowelsigngujarati: 0x0AC5,
  27673. ecaron: 0x011B,
  27674. ecedillabreve: 0x1E1D,
  27675. echarmenian: 0x0565,
  27676. echyiwnarmenian: 0x0587,
  27677. ecircle: 0x24D4,
  27678. ecircumflex: 0x00EA,
  27679. ecircumflexacute: 0x1EBF,
  27680. ecircumflexbelow: 0x1E19,
  27681. ecircumflexdotbelow: 0x1EC7,
  27682. ecircumflexgrave: 0x1EC1,
  27683. ecircumflexhookabove: 0x1EC3,
  27684. ecircumflextilde: 0x1EC5,
  27685. ecyrillic: 0x0454,
  27686. edblgrave: 0x0205,
  27687. edeva: 0x090F,
  27688. edieresis: 0x00EB,
  27689. edot: 0x0117,
  27690. edotaccent: 0x0117,
  27691. edotbelow: 0x1EB9,
  27692. eegurmukhi: 0x0A0F,
  27693. eematragurmukhi: 0x0A47,
  27694. efcyrillic: 0x0444,
  27695. egrave: 0x00E8,
  27696. egujarati: 0x0A8F,
  27697. eharmenian: 0x0567,
  27698. ehbopomofo: 0x311D,
  27699. ehiragana: 0x3048,
  27700. ehookabove: 0x1EBB,
  27701. eibopomofo: 0x311F,
  27702. eight: 0x0038,
  27703. eightarabic: 0x0668,
  27704. eightbengali: 0x09EE,
  27705. eightcircle: 0x2467,
  27706. eightcircleinversesansserif: 0x2791,
  27707. eightdeva: 0x096E,
  27708. eighteencircle: 0x2471,
  27709. eighteenparen: 0x2485,
  27710. eighteenperiod: 0x2499,
  27711. eightgujarati: 0x0AEE,
  27712. eightgurmukhi: 0x0A6E,
  27713. eighthackarabic: 0x0668,
  27714. eighthangzhou: 0x3028,
  27715. eighthnotebeamed: 0x266B,
  27716. eightideographicparen: 0x3227,
  27717. eightinferior: 0x2088,
  27718. eightmonospace: 0xFF18,
  27719. eightoldstyle: 0xF738,
  27720. eightparen: 0x247B,
  27721. eightperiod: 0x248F,
  27722. eightpersian: 0x06F8,
  27723. eightroman: 0x2177,
  27724. eightsuperior: 0x2078,
  27725. eightthai: 0x0E58,
  27726. einvertedbreve: 0x0207,
  27727. eiotifiedcyrillic: 0x0465,
  27728. ekatakana: 0x30A8,
  27729. ekatakanahalfwidth: 0xFF74,
  27730. ekonkargurmukhi: 0x0A74,
  27731. ekorean: 0x3154,
  27732. elcyrillic: 0x043B,
  27733. element: 0x2208,
  27734. elevencircle: 0x246A,
  27735. elevenparen: 0x247E,
  27736. elevenperiod: 0x2492,
  27737. elevenroman: 0x217A,
  27738. ellipsis: 0x2026,
  27739. ellipsisvertical: 0x22EE,
  27740. emacron: 0x0113,
  27741. emacronacute: 0x1E17,
  27742. emacrongrave: 0x1E15,
  27743. emcyrillic: 0x043C,
  27744. emdash: 0x2014,
  27745. emdashvertical: 0xFE31,
  27746. emonospace: 0xFF45,
  27747. emphasismarkarmenian: 0x055B,
  27748. emptyset: 0x2205,
  27749. enbopomofo: 0x3123,
  27750. encyrillic: 0x043D,
  27751. endash: 0x2013,
  27752. endashvertical: 0xFE32,
  27753. endescendercyrillic: 0x04A3,
  27754. eng: 0x014B,
  27755. engbopomofo: 0x3125,
  27756. enghecyrillic: 0x04A5,
  27757. enhookcyrillic: 0x04C8,
  27758. enspace: 0x2002,
  27759. eogonek: 0x0119,
  27760. eokorean: 0x3153,
  27761. eopen: 0x025B,
  27762. eopenclosed: 0x029A,
  27763. eopenreversed: 0x025C,
  27764. eopenreversedclosed: 0x025E,
  27765. eopenreversedhook: 0x025D,
  27766. eparen: 0x24A0,
  27767. epsilon: 0x03B5,
  27768. epsilontonos: 0x03AD,
  27769. equal: 0x003D,
  27770. equalmonospace: 0xFF1D,
  27771. equalsmall: 0xFE66,
  27772. equalsuperior: 0x207C,
  27773. equivalence: 0x2261,
  27774. erbopomofo: 0x3126,
  27775. ercyrillic: 0x0440,
  27776. ereversed: 0x0258,
  27777. ereversedcyrillic: 0x044D,
  27778. escyrillic: 0x0441,
  27779. esdescendercyrillic: 0x04AB,
  27780. esh: 0x0283,
  27781. eshcurl: 0x0286,
  27782. eshortdeva: 0x090E,
  27783. eshortvowelsigndeva: 0x0946,
  27784. eshreversedloop: 0x01AA,
  27785. eshsquatreversed: 0x0285,
  27786. esmallhiragana: 0x3047,
  27787. esmallkatakana: 0x30A7,
  27788. esmallkatakanahalfwidth: 0xFF6A,
  27789. estimated: 0x212E,
  27790. esuperior: 0xF6EC,
  27791. eta: 0x03B7,
  27792. etarmenian: 0x0568,
  27793. etatonos: 0x03AE,
  27794. eth: 0x00F0,
  27795. etilde: 0x1EBD,
  27796. etildebelow: 0x1E1B,
  27797. etnahtafoukhhebrew: 0x0591,
  27798. etnahtafoukhlefthebrew: 0x0591,
  27799. etnahtahebrew: 0x0591,
  27800. etnahtalefthebrew: 0x0591,
  27801. eturned: 0x01DD,
  27802. eukorean: 0x3161,
  27803. euro: 0x20AC,
  27804. evowelsignbengali: 0x09C7,
  27805. evowelsigndeva: 0x0947,
  27806. evowelsigngujarati: 0x0AC7,
  27807. exclam: 0x0021,
  27808. exclamarmenian: 0x055C,
  27809. exclamdbl: 0x203C,
  27810. exclamdown: 0x00A1,
  27811. exclamdownsmall: 0xF7A1,
  27812. exclammonospace: 0xFF01,
  27813. exclamsmall: 0xF721,
  27814. existential: 0x2203,
  27815. ezh: 0x0292,
  27816. ezhcaron: 0x01EF,
  27817. ezhcurl: 0x0293,
  27818. ezhreversed: 0x01B9,
  27819. ezhtail: 0x01BA,
  27820. f: 0x0066,
  27821. fadeva: 0x095E,
  27822. fagurmukhi: 0x0A5E,
  27823. fahrenheit: 0x2109,
  27824. fathaarabic: 0x064E,
  27825. fathalowarabic: 0x064E,
  27826. fathatanarabic: 0x064B,
  27827. fbopomofo: 0x3108,
  27828. fcircle: 0x24D5,
  27829. fdotaccent: 0x1E1F,
  27830. feharabic: 0x0641,
  27831. feharmenian: 0x0586,
  27832. fehfinalarabic: 0xFED2,
  27833. fehinitialarabic: 0xFED3,
  27834. fehmedialarabic: 0xFED4,
  27835. feicoptic: 0x03E5,
  27836. female: 0x2640,
  27837. ff: 0xFB00,
  27838. ffi: 0xFB03,
  27839. ffl: 0xFB04,
  27840. fi: 0xFB01,
  27841. fifteencircle: 0x246E,
  27842. fifteenparen: 0x2482,
  27843. fifteenperiod: 0x2496,
  27844. figuredash: 0x2012,
  27845. filledbox: 0x25A0,
  27846. filledrect: 0x25AC,
  27847. finalkaf: 0x05DA,
  27848. finalkafdagesh: 0xFB3A,
  27849. finalkafdageshhebrew: 0xFB3A,
  27850. finalkafhebrew: 0x05DA,
  27851. finalmem: 0x05DD,
  27852. finalmemhebrew: 0x05DD,
  27853. finalnun: 0x05DF,
  27854. finalnunhebrew: 0x05DF,
  27855. finalpe: 0x05E3,
  27856. finalpehebrew: 0x05E3,
  27857. finaltsadi: 0x05E5,
  27858. finaltsadihebrew: 0x05E5,
  27859. firsttonechinese: 0x02C9,
  27860. fisheye: 0x25C9,
  27861. fitacyrillic: 0x0473,
  27862. five: 0x0035,
  27863. fivearabic: 0x0665,
  27864. fivebengali: 0x09EB,
  27865. fivecircle: 0x2464,
  27866. fivecircleinversesansserif: 0x278E,
  27867. fivedeva: 0x096B,
  27868. fiveeighths: 0x215D,
  27869. fivegujarati: 0x0AEB,
  27870. fivegurmukhi: 0x0A6B,
  27871. fivehackarabic: 0x0665,
  27872. fivehangzhou: 0x3025,
  27873. fiveideographicparen: 0x3224,
  27874. fiveinferior: 0x2085,
  27875. fivemonospace: 0xFF15,
  27876. fiveoldstyle: 0xF735,
  27877. fiveparen: 0x2478,
  27878. fiveperiod: 0x248C,
  27879. fivepersian: 0x06F5,
  27880. fiveroman: 0x2174,
  27881. fivesuperior: 0x2075,
  27882. fivethai: 0x0E55,
  27883. fl: 0xFB02,
  27884. florin: 0x0192,
  27885. fmonospace: 0xFF46,
  27886. fmsquare: 0x3399,
  27887. fofanthai: 0x0E1F,
  27888. fofathai: 0x0E1D,
  27889. fongmanthai: 0x0E4F,
  27890. forall: 0x2200,
  27891. four: 0x0034,
  27892. fourarabic: 0x0664,
  27893. fourbengali: 0x09EA,
  27894. fourcircle: 0x2463,
  27895. fourcircleinversesansserif: 0x278D,
  27896. fourdeva: 0x096A,
  27897. fourgujarati: 0x0AEA,
  27898. fourgurmukhi: 0x0A6A,
  27899. fourhackarabic: 0x0664,
  27900. fourhangzhou: 0x3024,
  27901. fourideographicparen: 0x3223,
  27902. fourinferior: 0x2084,
  27903. fourmonospace: 0xFF14,
  27904. fournumeratorbengali: 0x09F7,
  27905. fouroldstyle: 0xF734,
  27906. fourparen: 0x2477,
  27907. fourperiod: 0x248B,
  27908. fourpersian: 0x06F4,
  27909. fourroman: 0x2173,
  27910. foursuperior: 0x2074,
  27911. fourteencircle: 0x246D,
  27912. fourteenparen: 0x2481,
  27913. fourteenperiod: 0x2495,
  27914. fourthai: 0x0E54,
  27915. fourthtonechinese: 0x02CB,
  27916. fparen: 0x24A1,
  27917. fraction: 0x2044,
  27918. franc: 0x20A3,
  27919. g: 0x0067,
  27920. gabengali: 0x0997,
  27921. gacute: 0x01F5,
  27922. gadeva: 0x0917,
  27923. gafarabic: 0x06AF,
  27924. gaffinalarabic: 0xFB93,
  27925. gafinitialarabic: 0xFB94,
  27926. gafmedialarabic: 0xFB95,
  27927. gagujarati: 0x0A97,
  27928. gagurmukhi: 0x0A17,
  27929. gahiragana: 0x304C,
  27930. gakatakana: 0x30AC,
  27931. gamma: 0x03B3,
  27932. gammalatinsmall: 0x0263,
  27933. gammasuperior: 0x02E0,
  27934. gangiacoptic: 0x03EB,
  27935. gbopomofo: 0x310D,
  27936. gbreve: 0x011F,
  27937. gcaron: 0x01E7,
  27938. gcedilla: 0x0123,
  27939. gcircle: 0x24D6,
  27940. gcircumflex: 0x011D,
  27941. gcommaaccent: 0x0123,
  27942. gdot: 0x0121,
  27943. gdotaccent: 0x0121,
  27944. gecyrillic: 0x0433,
  27945. gehiragana: 0x3052,
  27946. gekatakana: 0x30B2,
  27947. geometricallyequal: 0x2251,
  27948. gereshaccenthebrew: 0x059C,
  27949. gereshhebrew: 0x05F3,
  27950. gereshmuqdamhebrew: 0x059D,
  27951. germandbls: 0x00DF,
  27952. gershayimaccenthebrew: 0x059E,
  27953. gershayimhebrew: 0x05F4,
  27954. getamark: 0x3013,
  27955. ghabengali: 0x0998,
  27956. ghadarmenian: 0x0572,
  27957. ghadeva: 0x0918,
  27958. ghagujarati: 0x0A98,
  27959. ghagurmukhi: 0x0A18,
  27960. ghainarabic: 0x063A,
  27961. ghainfinalarabic: 0xFECE,
  27962. ghaininitialarabic: 0xFECF,
  27963. ghainmedialarabic: 0xFED0,
  27964. ghemiddlehookcyrillic: 0x0495,
  27965. ghestrokecyrillic: 0x0493,
  27966. gheupturncyrillic: 0x0491,
  27967. ghhadeva: 0x095A,
  27968. ghhagurmukhi: 0x0A5A,
  27969. ghook: 0x0260,
  27970. ghzsquare: 0x3393,
  27971. gihiragana: 0x304E,
  27972. gikatakana: 0x30AE,
  27973. gimarmenian: 0x0563,
  27974. gimel: 0x05D2,
  27975. gimeldagesh: 0xFB32,
  27976. gimeldageshhebrew: 0xFB32,
  27977. gimelhebrew: 0x05D2,
  27978. gjecyrillic: 0x0453,
  27979. glottalinvertedstroke: 0x01BE,
  27980. glottalstop: 0x0294,
  27981. glottalstopinverted: 0x0296,
  27982. glottalstopmod: 0x02C0,
  27983. glottalstopreversed: 0x0295,
  27984. glottalstopreversedmod: 0x02C1,
  27985. glottalstopreversedsuperior: 0x02E4,
  27986. glottalstopstroke: 0x02A1,
  27987. glottalstopstrokereversed: 0x02A2,
  27988. gmacron: 0x1E21,
  27989. gmonospace: 0xFF47,
  27990. gohiragana: 0x3054,
  27991. gokatakana: 0x30B4,
  27992. gparen: 0x24A2,
  27993. gpasquare: 0x33AC,
  27994. gradient: 0x2207,
  27995. grave: 0x0060,
  27996. gravebelowcmb: 0x0316,
  27997. gravecmb: 0x0300,
  27998. gravecomb: 0x0300,
  27999. gravedeva: 0x0953,
  28000. gravelowmod: 0x02CE,
  28001. gravemonospace: 0xFF40,
  28002. gravetonecmb: 0x0340,
  28003. greater: 0x003E,
  28004. greaterequal: 0x2265,
  28005. greaterequalorless: 0x22DB,
  28006. greatermonospace: 0xFF1E,
  28007. greaterorequivalent: 0x2273,
  28008. greaterorless: 0x2277,
  28009. greateroverequal: 0x2267,
  28010. greatersmall: 0xFE65,
  28011. gscript: 0x0261,
  28012. gstroke: 0x01E5,
  28013. guhiragana: 0x3050,
  28014. guillemotleft: 0x00AB,
  28015. guillemotright: 0x00BB,
  28016. guilsinglleft: 0x2039,
  28017. guilsinglright: 0x203A,
  28018. gukatakana: 0x30B0,
  28019. guramusquare: 0x3318,
  28020. gysquare: 0x33C9,
  28021. h: 0x0068,
  28022. haabkhasiancyrillic: 0x04A9,
  28023. haaltonearabic: 0x06C1,
  28024. habengali: 0x09B9,
  28025. hadescendercyrillic: 0x04B3,
  28026. hadeva: 0x0939,
  28027. hagujarati: 0x0AB9,
  28028. hagurmukhi: 0x0A39,
  28029. haharabic: 0x062D,
  28030. hahfinalarabic: 0xFEA2,
  28031. hahinitialarabic: 0xFEA3,
  28032. hahiragana: 0x306F,
  28033. hahmedialarabic: 0xFEA4,
  28034. haitusquare: 0x332A,
  28035. hakatakana: 0x30CF,
  28036. hakatakanahalfwidth: 0xFF8A,
  28037. halantgurmukhi: 0x0A4D,
  28038. hamzaarabic: 0x0621,
  28039. hamzalowarabic: 0x0621,
  28040. hangulfiller: 0x3164,
  28041. hardsigncyrillic: 0x044A,
  28042. harpoonleftbarbup: 0x21BC,
  28043. harpoonrightbarbup: 0x21C0,
  28044. hasquare: 0x33CA,
  28045. hatafpatah: 0x05B2,
  28046. hatafpatah16: 0x05B2,
  28047. hatafpatah23: 0x05B2,
  28048. hatafpatah2f: 0x05B2,
  28049. hatafpatahhebrew: 0x05B2,
  28050. hatafpatahnarrowhebrew: 0x05B2,
  28051. hatafpatahquarterhebrew: 0x05B2,
  28052. hatafpatahwidehebrew: 0x05B2,
  28053. hatafqamats: 0x05B3,
  28054. hatafqamats1b: 0x05B3,
  28055. hatafqamats28: 0x05B3,
  28056. hatafqamats34: 0x05B3,
  28057. hatafqamatshebrew: 0x05B3,
  28058. hatafqamatsnarrowhebrew: 0x05B3,
  28059. hatafqamatsquarterhebrew: 0x05B3,
  28060. hatafqamatswidehebrew: 0x05B3,
  28061. hatafsegol: 0x05B1,
  28062. hatafsegol17: 0x05B1,
  28063. hatafsegol24: 0x05B1,
  28064. hatafsegol30: 0x05B1,
  28065. hatafsegolhebrew: 0x05B1,
  28066. hatafsegolnarrowhebrew: 0x05B1,
  28067. hatafsegolquarterhebrew: 0x05B1,
  28068. hatafsegolwidehebrew: 0x05B1,
  28069. hbar: 0x0127,
  28070. hbopomofo: 0x310F,
  28071. hbrevebelow: 0x1E2B,
  28072. hcedilla: 0x1E29,
  28073. hcircle: 0x24D7,
  28074. hcircumflex: 0x0125,
  28075. hdieresis: 0x1E27,
  28076. hdotaccent: 0x1E23,
  28077. hdotbelow: 0x1E25,
  28078. he: 0x05D4,
  28079. heart: 0x2665,
  28080. heartsuitblack: 0x2665,
  28081. heartsuitwhite: 0x2661,
  28082. hedagesh: 0xFB34,
  28083. hedageshhebrew: 0xFB34,
  28084. hehaltonearabic: 0x06C1,
  28085. heharabic: 0x0647,
  28086. hehebrew: 0x05D4,
  28087. hehfinalaltonearabic: 0xFBA7,
  28088. hehfinalalttwoarabic: 0xFEEA,
  28089. hehfinalarabic: 0xFEEA,
  28090. hehhamzaabovefinalarabic: 0xFBA5,
  28091. hehhamzaaboveisolatedarabic: 0xFBA4,
  28092. hehinitialaltonearabic: 0xFBA8,
  28093. hehinitialarabic: 0xFEEB,
  28094. hehiragana: 0x3078,
  28095. hehmedialaltonearabic: 0xFBA9,
  28096. hehmedialarabic: 0xFEEC,
  28097. heiseierasquare: 0x337B,
  28098. hekatakana: 0x30D8,
  28099. hekatakanahalfwidth: 0xFF8D,
  28100. hekutaarusquare: 0x3336,
  28101. henghook: 0x0267,
  28102. herutusquare: 0x3339,
  28103. het: 0x05D7,
  28104. hethebrew: 0x05D7,
  28105. hhook: 0x0266,
  28106. hhooksuperior: 0x02B1,
  28107. hieuhacirclekorean: 0x327B,
  28108. hieuhaparenkorean: 0x321B,
  28109. hieuhcirclekorean: 0x326D,
  28110. hieuhkorean: 0x314E,
  28111. hieuhparenkorean: 0x320D,
  28112. hihiragana: 0x3072,
  28113. hikatakana: 0x30D2,
  28114. hikatakanahalfwidth: 0xFF8B,
  28115. hiriq: 0x05B4,
  28116. hiriq14: 0x05B4,
  28117. hiriq21: 0x05B4,
  28118. hiriq2d: 0x05B4,
  28119. hiriqhebrew: 0x05B4,
  28120. hiriqnarrowhebrew: 0x05B4,
  28121. hiriqquarterhebrew: 0x05B4,
  28122. hiriqwidehebrew: 0x05B4,
  28123. hlinebelow: 0x1E96,
  28124. hmonospace: 0xFF48,
  28125. hoarmenian: 0x0570,
  28126. hohipthai: 0x0E2B,
  28127. hohiragana: 0x307B,
  28128. hokatakana: 0x30DB,
  28129. hokatakanahalfwidth: 0xFF8E,
  28130. holam: 0x05B9,
  28131. holam19: 0x05B9,
  28132. holam26: 0x05B9,
  28133. holam32: 0x05B9,
  28134. holamhebrew: 0x05B9,
  28135. holamnarrowhebrew: 0x05B9,
  28136. holamquarterhebrew: 0x05B9,
  28137. holamwidehebrew: 0x05B9,
  28138. honokhukthai: 0x0E2E,
  28139. hookabovecomb: 0x0309,
  28140. hookcmb: 0x0309,
  28141. hookpalatalizedbelowcmb: 0x0321,
  28142. hookretroflexbelowcmb: 0x0322,
  28143. hoonsquare: 0x3342,
  28144. horicoptic: 0x03E9,
  28145. horizontalbar: 0x2015,
  28146. horncmb: 0x031B,
  28147. hotsprings: 0x2668,
  28148. house: 0x2302,
  28149. hparen: 0x24A3,
  28150. hsuperior: 0x02B0,
  28151. hturned: 0x0265,
  28152. huhiragana: 0x3075,
  28153. huiitosquare: 0x3333,
  28154. hukatakana: 0x30D5,
  28155. hukatakanahalfwidth: 0xFF8C,
  28156. hungarumlaut: 0x02DD,
  28157. hungarumlautcmb: 0x030B,
  28158. hv: 0x0195,
  28159. hyphen: 0x002D,
  28160. hypheninferior: 0xF6E5,
  28161. hyphenmonospace: 0xFF0D,
  28162. hyphensmall: 0xFE63,
  28163. hyphensuperior: 0xF6E6,
  28164. hyphentwo: 0x2010,
  28165. i: 0x0069,
  28166. iacute: 0x00ED,
  28167. iacyrillic: 0x044F,
  28168. ibengali: 0x0987,
  28169. ibopomofo: 0x3127,
  28170. ibreve: 0x012D,
  28171. icaron: 0x01D0,
  28172. icircle: 0x24D8,
  28173. icircumflex: 0x00EE,
  28174. icyrillic: 0x0456,
  28175. idblgrave: 0x0209,
  28176. ideographearthcircle: 0x328F,
  28177. ideographfirecircle: 0x328B,
  28178. ideographicallianceparen: 0x323F,
  28179. ideographiccallparen: 0x323A,
  28180. ideographiccentrecircle: 0x32A5,
  28181. ideographicclose: 0x3006,
  28182. ideographiccomma: 0x3001,
  28183. ideographiccommaleft: 0xFF64,
  28184. ideographiccongratulationparen: 0x3237,
  28185. ideographiccorrectcircle: 0x32A3,
  28186. ideographicearthparen: 0x322F,
  28187. ideographicenterpriseparen: 0x323D,
  28188. ideographicexcellentcircle: 0x329D,
  28189. ideographicfestivalparen: 0x3240,
  28190. ideographicfinancialcircle: 0x3296,
  28191. ideographicfinancialparen: 0x3236,
  28192. ideographicfireparen: 0x322B,
  28193. ideographichaveparen: 0x3232,
  28194. ideographichighcircle: 0x32A4,
  28195. ideographiciterationmark: 0x3005,
  28196. ideographiclaborcircle: 0x3298,
  28197. ideographiclaborparen: 0x3238,
  28198. ideographicleftcircle: 0x32A7,
  28199. ideographiclowcircle: 0x32A6,
  28200. ideographicmedicinecircle: 0x32A9,
  28201. ideographicmetalparen: 0x322E,
  28202. ideographicmoonparen: 0x322A,
  28203. ideographicnameparen: 0x3234,
  28204. ideographicperiod: 0x3002,
  28205. ideographicprintcircle: 0x329E,
  28206. ideographicreachparen: 0x3243,
  28207. ideographicrepresentparen: 0x3239,
  28208. ideographicresourceparen: 0x323E,
  28209. ideographicrightcircle: 0x32A8,
  28210. ideographicsecretcircle: 0x3299,
  28211. ideographicselfparen: 0x3242,
  28212. ideographicsocietyparen: 0x3233,
  28213. ideographicspace: 0x3000,
  28214. ideographicspecialparen: 0x3235,
  28215. ideographicstockparen: 0x3231,
  28216. ideographicstudyparen: 0x323B,
  28217. ideographicsunparen: 0x3230,
  28218. ideographicsuperviseparen: 0x323C,
  28219. ideographicwaterparen: 0x322C,
  28220. ideographicwoodparen: 0x322D,
  28221. ideographiczero: 0x3007,
  28222. ideographmetalcircle: 0x328E,
  28223. ideographmooncircle: 0x328A,
  28224. ideographnamecircle: 0x3294,
  28225. ideographsuncircle: 0x3290,
  28226. ideographwatercircle: 0x328C,
  28227. ideographwoodcircle: 0x328D,
  28228. ideva: 0x0907,
  28229. idieresis: 0x00EF,
  28230. idieresisacute: 0x1E2F,
  28231. idieresiscyrillic: 0x04E5,
  28232. idotbelow: 0x1ECB,
  28233. iebrevecyrillic: 0x04D7,
  28234. iecyrillic: 0x0435,
  28235. ieungacirclekorean: 0x3275,
  28236. ieungaparenkorean: 0x3215,
  28237. ieungcirclekorean: 0x3267,
  28238. ieungkorean: 0x3147,
  28239. ieungparenkorean: 0x3207,
  28240. igrave: 0x00EC,
  28241. igujarati: 0x0A87,
  28242. igurmukhi: 0x0A07,
  28243. ihiragana: 0x3044,
  28244. ihookabove: 0x1EC9,
  28245. iibengali: 0x0988,
  28246. iicyrillic: 0x0438,
  28247. iideva: 0x0908,
  28248. iigujarati: 0x0A88,
  28249. iigurmukhi: 0x0A08,
  28250. iimatragurmukhi: 0x0A40,
  28251. iinvertedbreve: 0x020B,
  28252. iishortcyrillic: 0x0439,
  28253. iivowelsignbengali: 0x09C0,
  28254. iivowelsigndeva: 0x0940,
  28255. iivowelsigngujarati: 0x0AC0,
  28256. ij: 0x0133,
  28257. ikatakana: 0x30A4,
  28258. ikatakanahalfwidth: 0xFF72,
  28259. ikorean: 0x3163,
  28260. ilde: 0x02DC,
  28261. iluyhebrew: 0x05AC,
  28262. imacron: 0x012B,
  28263. imacroncyrillic: 0x04E3,
  28264. imageorapproximatelyequal: 0x2253,
  28265. imatragurmukhi: 0x0A3F,
  28266. imonospace: 0xFF49,
  28267. increment: 0x2206,
  28268. infinity: 0x221E,
  28269. iniarmenian: 0x056B,
  28270. integral: 0x222B,
  28271. integralbottom: 0x2321,
  28272. integralbt: 0x2321,
  28273. integralex: 0xF8F5,
  28274. integraltop: 0x2320,
  28275. integraltp: 0x2320,
  28276. intersection: 0x2229,
  28277. intisquare: 0x3305,
  28278. invbullet: 0x25D8,
  28279. invcircle: 0x25D9,
  28280. invsmileface: 0x263B,
  28281. iocyrillic: 0x0451,
  28282. iogonek: 0x012F,
  28283. iota: 0x03B9,
  28284. iotadieresis: 0x03CA,
  28285. iotadieresistonos: 0x0390,
  28286. iotalatin: 0x0269,
  28287. iotatonos: 0x03AF,
  28288. iparen: 0x24A4,
  28289. irigurmukhi: 0x0A72,
  28290. ismallhiragana: 0x3043,
  28291. ismallkatakana: 0x30A3,
  28292. ismallkatakanahalfwidth: 0xFF68,
  28293. issharbengali: 0x09FA,
  28294. istroke: 0x0268,
  28295. isuperior: 0xF6ED,
  28296. iterationhiragana: 0x309D,
  28297. iterationkatakana: 0x30FD,
  28298. itilde: 0x0129,
  28299. itildebelow: 0x1E2D,
  28300. iubopomofo: 0x3129,
  28301. iucyrillic: 0x044E,
  28302. ivowelsignbengali: 0x09BF,
  28303. ivowelsigndeva: 0x093F,
  28304. ivowelsigngujarati: 0x0ABF,
  28305. izhitsacyrillic: 0x0475,
  28306. izhitsadblgravecyrillic: 0x0477,
  28307. j: 0x006A,
  28308. jaarmenian: 0x0571,
  28309. jabengali: 0x099C,
  28310. jadeva: 0x091C,
  28311. jagujarati: 0x0A9C,
  28312. jagurmukhi: 0x0A1C,
  28313. jbopomofo: 0x3110,
  28314. jcaron: 0x01F0,
  28315. jcircle: 0x24D9,
  28316. jcircumflex: 0x0135,
  28317. jcrossedtail: 0x029D,
  28318. jdotlessstroke: 0x025F,
  28319. jecyrillic: 0x0458,
  28320. jeemarabic: 0x062C,
  28321. jeemfinalarabic: 0xFE9E,
  28322. jeeminitialarabic: 0xFE9F,
  28323. jeemmedialarabic: 0xFEA0,
  28324. jeharabic: 0x0698,
  28325. jehfinalarabic: 0xFB8B,
  28326. jhabengali: 0x099D,
  28327. jhadeva: 0x091D,
  28328. jhagujarati: 0x0A9D,
  28329. jhagurmukhi: 0x0A1D,
  28330. jheharmenian: 0x057B,
  28331. jis: 0x3004,
  28332. jmonospace: 0xFF4A,
  28333. jparen: 0x24A5,
  28334. jsuperior: 0x02B2,
  28335. k: 0x006B,
  28336. kabashkircyrillic: 0x04A1,
  28337. kabengali: 0x0995,
  28338. kacute: 0x1E31,
  28339. kacyrillic: 0x043A,
  28340. kadescendercyrillic: 0x049B,
  28341. kadeva: 0x0915,
  28342. kaf: 0x05DB,
  28343. kafarabic: 0x0643,
  28344. kafdagesh: 0xFB3B,
  28345. kafdageshhebrew: 0xFB3B,
  28346. kaffinalarabic: 0xFEDA,
  28347. kafhebrew: 0x05DB,
  28348. kafinitialarabic: 0xFEDB,
  28349. kafmedialarabic: 0xFEDC,
  28350. kafrafehebrew: 0xFB4D,
  28351. kagujarati: 0x0A95,
  28352. kagurmukhi: 0x0A15,
  28353. kahiragana: 0x304B,
  28354. kahookcyrillic: 0x04C4,
  28355. kakatakana: 0x30AB,
  28356. kakatakanahalfwidth: 0xFF76,
  28357. kappa: 0x03BA,
  28358. kappasymbolgreek: 0x03F0,
  28359. kapyeounmieumkorean: 0x3171,
  28360. kapyeounphieuphkorean: 0x3184,
  28361. kapyeounpieupkorean: 0x3178,
  28362. kapyeounssangpieupkorean: 0x3179,
  28363. karoriisquare: 0x330D,
  28364. kashidaautoarabic: 0x0640,
  28365. kashidaautonosidebearingarabic: 0x0640,
  28366. kasmallkatakana: 0x30F5,
  28367. kasquare: 0x3384,
  28368. kasraarabic: 0x0650,
  28369. kasratanarabic: 0x064D,
  28370. kastrokecyrillic: 0x049F,
  28371. katahiraprolongmarkhalfwidth: 0xFF70,
  28372. kaverticalstrokecyrillic: 0x049D,
  28373. kbopomofo: 0x310E,
  28374. kcalsquare: 0x3389,
  28375. kcaron: 0x01E9,
  28376. kcedilla: 0x0137,
  28377. kcircle: 0x24DA,
  28378. kcommaaccent: 0x0137,
  28379. kdotbelow: 0x1E33,
  28380. keharmenian: 0x0584,
  28381. kehiragana: 0x3051,
  28382. kekatakana: 0x30B1,
  28383. kekatakanahalfwidth: 0xFF79,
  28384. kenarmenian: 0x056F,
  28385. kesmallkatakana: 0x30F6,
  28386. kgreenlandic: 0x0138,
  28387. khabengali: 0x0996,
  28388. khacyrillic: 0x0445,
  28389. khadeva: 0x0916,
  28390. khagujarati: 0x0A96,
  28391. khagurmukhi: 0x0A16,
  28392. khaharabic: 0x062E,
  28393. khahfinalarabic: 0xFEA6,
  28394. khahinitialarabic: 0xFEA7,
  28395. khahmedialarabic: 0xFEA8,
  28396. kheicoptic: 0x03E7,
  28397. khhadeva: 0x0959,
  28398. khhagurmukhi: 0x0A59,
  28399. khieukhacirclekorean: 0x3278,
  28400. khieukhaparenkorean: 0x3218,
  28401. khieukhcirclekorean: 0x326A,
  28402. khieukhkorean: 0x314B,
  28403. khieukhparenkorean: 0x320A,
  28404. khokhaithai: 0x0E02,
  28405. khokhonthai: 0x0E05,
  28406. khokhuatthai: 0x0E03,
  28407. khokhwaithai: 0x0E04,
  28408. khomutthai: 0x0E5B,
  28409. khook: 0x0199,
  28410. khorakhangthai: 0x0E06,
  28411. khzsquare: 0x3391,
  28412. kihiragana: 0x304D,
  28413. kikatakana: 0x30AD,
  28414. kikatakanahalfwidth: 0xFF77,
  28415. kiroguramusquare: 0x3315,
  28416. kiromeetorusquare: 0x3316,
  28417. kirosquare: 0x3314,
  28418. kiyeokacirclekorean: 0x326E,
  28419. kiyeokaparenkorean: 0x320E,
  28420. kiyeokcirclekorean: 0x3260,
  28421. kiyeokkorean: 0x3131,
  28422. kiyeokparenkorean: 0x3200,
  28423. kiyeoksioskorean: 0x3133,
  28424. kjecyrillic: 0x045C,
  28425. klinebelow: 0x1E35,
  28426. klsquare: 0x3398,
  28427. kmcubedsquare: 0x33A6,
  28428. kmonospace: 0xFF4B,
  28429. kmsquaredsquare: 0x33A2,
  28430. kohiragana: 0x3053,
  28431. kohmsquare: 0x33C0,
  28432. kokaithai: 0x0E01,
  28433. kokatakana: 0x30B3,
  28434. kokatakanahalfwidth: 0xFF7A,
  28435. kooposquare: 0x331E,
  28436. koppacyrillic: 0x0481,
  28437. koreanstandardsymbol: 0x327F,
  28438. koroniscmb: 0x0343,
  28439. kparen: 0x24A6,
  28440. kpasquare: 0x33AA,
  28441. ksicyrillic: 0x046F,
  28442. ktsquare: 0x33CF,
  28443. kturned: 0x029E,
  28444. kuhiragana: 0x304F,
  28445. kukatakana: 0x30AF,
  28446. kukatakanahalfwidth: 0xFF78,
  28447. kvsquare: 0x33B8,
  28448. kwsquare: 0x33BE,
  28449. l: 0x006C,
  28450. labengali: 0x09B2,
  28451. lacute: 0x013A,
  28452. ladeva: 0x0932,
  28453. lagujarati: 0x0AB2,
  28454. lagurmukhi: 0x0A32,
  28455. lakkhangyaothai: 0x0E45,
  28456. lamaleffinalarabic: 0xFEFC,
  28457. lamalefhamzaabovefinalarabic: 0xFEF8,
  28458. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28459. lamalefhamzabelowfinalarabic: 0xFEFA,
  28460. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28461. lamalefisolatedarabic: 0xFEFB,
  28462. lamalefmaddaabovefinalarabic: 0xFEF6,
  28463. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28464. lamarabic: 0x0644,
  28465. lambda: 0x03BB,
  28466. lambdastroke: 0x019B,
  28467. lamed: 0x05DC,
  28468. lameddagesh: 0xFB3C,
  28469. lameddageshhebrew: 0xFB3C,
  28470. lamedhebrew: 0x05DC,
  28471. lamfinalarabic: 0xFEDE,
  28472. lamhahinitialarabic: 0xFCCA,
  28473. laminitialarabic: 0xFEDF,
  28474. lamjeeminitialarabic: 0xFCC9,
  28475. lamkhahinitialarabic: 0xFCCB,
  28476. lamlamhehisolatedarabic: 0xFDF2,
  28477. lammedialarabic: 0xFEE0,
  28478. lammeemhahinitialarabic: 0xFD88,
  28479. lammeeminitialarabic: 0xFCCC,
  28480. largecircle: 0x25EF,
  28481. lbar: 0x019A,
  28482. lbelt: 0x026C,
  28483. lbopomofo: 0x310C,
  28484. lcaron: 0x013E,
  28485. lcedilla: 0x013C,
  28486. lcircle: 0x24DB,
  28487. lcircumflexbelow: 0x1E3D,
  28488. lcommaaccent: 0x013C,
  28489. ldot: 0x0140,
  28490. ldotaccent: 0x0140,
  28491. ldotbelow: 0x1E37,
  28492. ldotbelowmacron: 0x1E39,
  28493. leftangleabovecmb: 0x031A,
  28494. lefttackbelowcmb: 0x0318,
  28495. less: 0x003C,
  28496. lessequal: 0x2264,
  28497. lessequalorgreater: 0x22DA,
  28498. lessmonospace: 0xFF1C,
  28499. lessorequivalent: 0x2272,
  28500. lessorgreater: 0x2276,
  28501. lessoverequal: 0x2266,
  28502. lesssmall: 0xFE64,
  28503. lezh: 0x026E,
  28504. lfblock: 0x258C,
  28505. lhookretroflex: 0x026D,
  28506. lira: 0x20A4,
  28507. liwnarmenian: 0x056C,
  28508. lj: 0x01C9,
  28509. ljecyrillic: 0x0459,
  28510. ll: 0xF6C0,
  28511. lladeva: 0x0933,
  28512. llagujarati: 0x0AB3,
  28513. llinebelow: 0x1E3B,
  28514. llladeva: 0x0934,
  28515. llvocalicbengali: 0x09E1,
  28516. llvocalicdeva: 0x0961,
  28517. llvocalicvowelsignbengali: 0x09E3,
  28518. llvocalicvowelsigndeva: 0x0963,
  28519. lmiddletilde: 0x026B,
  28520. lmonospace: 0xFF4C,
  28521. lmsquare: 0x33D0,
  28522. lochulathai: 0x0E2C,
  28523. logicaland: 0x2227,
  28524. logicalnot: 0x00AC,
  28525. logicalnotreversed: 0x2310,
  28526. logicalor: 0x2228,
  28527. lolingthai: 0x0E25,
  28528. longs: 0x017F,
  28529. lowlinecenterline: 0xFE4E,
  28530. lowlinecmb: 0x0332,
  28531. lowlinedashed: 0xFE4D,
  28532. lozenge: 0x25CA,
  28533. lparen: 0x24A7,
  28534. lslash: 0x0142,
  28535. lsquare: 0x2113,
  28536. lsuperior: 0xF6EE,
  28537. ltshade: 0x2591,
  28538. luthai: 0x0E26,
  28539. lvocalicbengali: 0x098C,
  28540. lvocalicdeva: 0x090C,
  28541. lvocalicvowelsignbengali: 0x09E2,
  28542. lvocalicvowelsigndeva: 0x0962,
  28543. lxsquare: 0x33D3,
  28544. m: 0x006D,
  28545. mabengali: 0x09AE,
  28546. macron: 0x00AF,
  28547. macronbelowcmb: 0x0331,
  28548. macroncmb: 0x0304,
  28549. macronlowmod: 0x02CD,
  28550. macronmonospace: 0xFFE3,
  28551. macute: 0x1E3F,
  28552. madeva: 0x092E,
  28553. magujarati: 0x0AAE,
  28554. magurmukhi: 0x0A2E,
  28555. mahapakhhebrew: 0x05A4,
  28556. mahapakhlefthebrew: 0x05A4,
  28557. mahiragana: 0x307E,
  28558. maichattawalowleftthai: 0xF895,
  28559. maichattawalowrightthai: 0xF894,
  28560. maichattawathai: 0x0E4B,
  28561. maichattawaupperleftthai: 0xF893,
  28562. maieklowleftthai: 0xF88C,
  28563. maieklowrightthai: 0xF88B,
  28564. maiekthai: 0x0E48,
  28565. maiekupperleftthai: 0xF88A,
  28566. maihanakatleftthai: 0xF884,
  28567. maihanakatthai: 0x0E31,
  28568. maitaikhuleftthai: 0xF889,
  28569. maitaikhuthai: 0x0E47,
  28570. maitholowleftthai: 0xF88F,
  28571. maitholowrightthai: 0xF88E,
  28572. maithothai: 0x0E49,
  28573. maithoupperleftthai: 0xF88D,
  28574. maitrilowleftthai: 0xF892,
  28575. maitrilowrightthai: 0xF891,
  28576. maitrithai: 0x0E4A,
  28577. maitriupperleftthai: 0xF890,
  28578. maiyamokthai: 0x0E46,
  28579. makatakana: 0x30DE,
  28580. makatakanahalfwidth: 0xFF8F,
  28581. male: 0x2642,
  28582. mansyonsquare: 0x3347,
  28583. maqafhebrew: 0x05BE,
  28584. mars: 0x2642,
  28585. masoracirclehebrew: 0x05AF,
  28586. masquare: 0x3383,
  28587. mbopomofo: 0x3107,
  28588. mbsquare: 0x33D4,
  28589. mcircle: 0x24DC,
  28590. mcubedsquare: 0x33A5,
  28591. mdotaccent: 0x1E41,
  28592. mdotbelow: 0x1E43,
  28593. meemarabic: 0x0645,
  28594. meemfinalarabic: 0xFEE2,
  28595. meeminitialarabic: 0xFEE3,
  28596. meemmedialarabic: 0xFEE4,
  28597. meemmeeminitialarabic: 0xFCD1,
  28598. meemmeemisolatedarabic: 0xFC48,
  28599. meetorusquare: 0x334D,
  28600. mehiragana: 0x3081,
  28601. meizierasquare: 0x337E,
  28602. mekatakana: 0x30E1,
  28603. mekatakanahalfwidth: 0xFF92,
  28604. mem: 0x05DE,
  28605. memdagesh: 0xFB3E,
  28606. memdageshhebrew: 0xFB3E,
  28607. memhebrew: 0x05DE,
  28608. menarmenian: 0x0574,
  28609. merkhahebrew: 0x05A5,
  28610. merkhakefulahebrew: 0x05A6,
  28611. merkhakefulalefthebrew: 0x05A6,
  28612. merkhalefthebrew: 0x05A5,
  28613. mhook: 0x0271,
  28614. mhzsquare: 0x3392,
  28615. middledotkatakanahalfwidth: 0xFF65,
  28616. middot: 0x00B7,
  28617. mieumacirclekorean: 0x3272,
  28618. mieumaparenkorean: 0x3212,
  28619. mieumcirclekorean: 0x3264,
  28620. mieumkorean: 0x3141,
  28621. mieumpansioskorean: 0x3170,
  28622. mieumparenkorean: 0x3204,
  28623. mieumpieupkorean: 0x316E,
  28624. mieumsioskorean: 0x316F,
  28625. mihiragana: 0x307F,
  28626. mikatakana: 0x30DF,
  28627. mikatakanahalfwidth: 0xFF90,
  28628. minus: 0x2212,
  28629. minusbelowcmb: 0x0320,
  28630. minuscircle: 0x2296,
  28631. minusmod: 0x02D7,
  28632. minusplus: 0x2213,
  28633. minute: 0x2032,
  28634. miribaarusquare: 0x334A,
  28635. mirisquare: 0x3349,
  28636. mlonglegturned: 0x0270,
  28637. mlsquare: 0x3396,
  28638. mmcubedsquare: 0x33A3,
  28639. mmonospace: 0xFF4D,
  28640. mmsquaredsquare: 0x339F,
  28641. mohiragana: 0x3082,
  28642. mohmsquare: 0x33C1,
  28643. mokatakana: 0x30E2,
  28644. mokatakanahalfwidth: 0xFF93,
  28645. molsquare: 0x33D6,
  28646. momathai: 0x0E21,
  28647. moverssquare: 0x33A7,
  28648. moverssquaredsquare: 0x33A8,
  28649. mparen: 0x24A8,
  28650. mpasquare: 0x33AB,
  28651. mssquare: 0x33B3,
  28652. msuperior: 0xF6EF,
  28653. mturned: 0x026F,
  28654. mu: 0x00B5,
  28655. mu1: 0x00B5,
  28656. muasquare: 0x3382,
  28657. muchgreater: 0x226B,
  28658. muchless: 0x226A,
  28659. mufsquare: 0x338C,
  28660. mugreek: 0x03BC,
  28661. mugsquare: 0x338D,
  28662. muhiragana: 0x3080,
  28663. mukatakana: 0x30E0,
  28664. mukatakanahalfwidth: 0xFF91,
  28665. mulsquare: 0x3395,
  28666. multiply: 0x00D7,
  28667. mumsquare: 0x339B,
  28668. munahhebrew: 0x05A3,
  28669. munahlefthebrew: 0x05A3,
  28670. musicalnote: 0x266A,
  28671. musicalnotedbl: 0x266B,
  28672. musicflatsign: 0x266D,
  28673. musicsharpsign: 0x266F,
  28674. mussquare: 0x33B2,
  28675. muvsquare: 0x33B6,
  28676. muwsquare: 0x33BC,
  28677. mvmegasquare: 0x33B9,
  28678. mvsquare: 0x33B7,
  28679. mwmegasquare: 0x33BF,
  28680. mwsquare: 0x33BD,
  28681. n: 0x006E,
  28682. nabengali: 0x09A8,
  28683. nabla: 0x2207,
  28684. nacute: 0x0144,
  28685. nadeva: 0x0928,
  28686. nagujarati: 0x0AA8,
  28687. nagurmukhi: 0x0A28,
  28688. nahiragana: 0x306A,
  28689. nakatakana: 0x30CA,
  28690. nakatakanahalfwidth: 0xFF85,
  28691. napostrophe: 0x0149,
  28692. nasquare: 0x3381,
  28693. nbopomofo: 0x310B,
  28694. nbspace: 0x00A0,
  28695. ncaron: 0x0148,
  28696. ncedilla: 0x0146,
  28697. ncircle: 0x24DD,
  28698. ncircumflexbelow: 0x1E4B,
  28699. ncommaaccent: 0x0146,
  28700. ndotaccent: 0x1E45,
  28701. ndotbelow: 0x1E47,
  28702. nehiragana: 0x306D,
  28703. nekatakana: 0x30CD,
  28704. nekatakanahalfwidth: 0xFF88,
  28705. newsheqelsign: 0x20AA,
  28706. nfsquare: 0x338B,
  28707. ngabengali: 0x0999,
  28708. ngadeva: 0x0919,
  28709. ngagujarati: 0x0A99,
  28710. ngagurmukhi: 0x0A19,
  28711. ngonguthai: 0x0E07,
  28712. nhiragana: 0x3093,
  28713. nhookleft: 0x0272,
  28714. nhookretroflex: 0x0273,
  28715. nieunacirclekorean: 0x326F,
  28716. nieunaparenkorean: 0x320F,
  28717. nieuncieuckorean: 0x3135,
  28718. nieuncirclekorean: 0x3261,
  28719. nieunhieuhkorean: 0x3136,
  28720. nieunkorean: 0x3134,
  28721. nieunpansioskorean: 0x3168,
  28722. nieunparenkorean: 0x3201,
  28723. nieunsioskorean: 0x3167,
  28724. nieuntikeutkorean: 0x3166,
  28725. nihiragana: 0x306B,
  28726. nikatakana: 0x30CB,
  28727. nikatakanahalfwidth: 0xFF86,
  28728. nikhahitleftthai: 0xF899,
  28729. nikhahitthai: 0x0E4D,
  28730. nine: 0x0039,
  28731. ninearabic: 0x0669,
  28732. ninebengali: 0x09EF,
  28733. ninecircle: 0x2468,
  28734. ninecircleinversesansserif: 0x2792,
  28735. ninedeva: 0x096F,
  28736. ninegujarati: 0x0AEF,
  28737. ninegurmukhi: 0x0A6F,
  28738. ninehackarabic: 0x0669,
  28739. ninehangzhou: 0x3029,
  28740. nineideographicparen: 0x3228,
  28741. nineinferior: 0x2089,
  28742. ninemonospace: 0xFF19,
  28743. nineoldstyle: 0xF739,
  28744. nineparen: 0x247C,
  28745. nineperiod: 0x2490,
  28746. ninepersian: 0x06F9,
  28747. nineroman: 0x2178,
  28748. ninesuperior: 0x2079,
  28749. nineteencircle: 0x2472,
  28750. nineteenparen: 0x2486,
  28751. nineteenperiod: 0x249A,
  28752. ninethai: 0x0E59,
  28753. nj: 0x01CC,
  28754. njecyrillic: 0x045A,
  28755. nkatakana: 0x30F3,
  28756. nkatakanahalfwidth: 0xFF9D,
  28757. nlegrightlong: 0x019E,
  28758. nlinebelow: 0x1E49,
  28759. nmonospace: 0xFF4E,
  28760. nmsquare: 0x339A,
  28761. nnabengali: 0x09A3,
  28762. nnadeva: 0x0923,
  28763. nnagujarati: 0x0AA3,
  28764. nnagurmukhi: 0x0A23,
  28765. nnnadeva: 0x0929,
  28766. nohiragana: 0x306E,
  28767. nokatakana: 0x30CE,
  28768. nokatakanahalfwidth: 0xFF89,
  28769. nonbreakingspace: 0x00A0,
  28770. nonenthai: 0x0E13,
  28771. nonuthai: 0x0E19,
  28772. noonarabic: 0x0646,
  28773. noonfinalarabic: 0xFEE6,
  28774. noonghunnaarabic: 0x06BA,
  28775. noonghunnafinalarabic: 0xFB9F,
  28776. nooninitialarabic: 0xFEE7,
  28777. noonjeeminitialarabic: 0xFCD2,
  28778. noonjeemisolatedarabic: 0xFC4B,
  28779. noonmedialarabic: 0xFEE8,
  28780. noonmeeminitialarabic: 0xFCD5,
  28781. noonmeemisolatedarabic: 0xFC4E,
  28782. noonnoonfinalarabic: 0xFC8D,
  28783. notcontains: 0x220C,
  28784. notelement: 0x2209,
  28785. notelementof: 0x2209,
  28786. notequal: 0x2260,
  28787. notgreater: 0x226F,
  28788. notgreaternorequal: 0x2271,
  28789. notgreaternorless: 0x2279,
  28790. notidentical: 0x2262,
  28791. notless: 0x226E,
  28792. notlessnorequal: 0x2270,
  28793. notparallel: 0x2226,
  28794. notprecedes: 0x2280,
  28795. notsubset: 0x2284,
  28796. notsucceeds: 0x2281,
  28797. notsuperset: 0x2285,
  28798. nowarmenian: 0x0576,
  28799. nparen: 0x24A9,
  28800. nssquare: 0x33B1,
  28801. nsuperior: 0x207F,
  28802. ntilde: 0x00F1,
  28803. nu: 0x03BD,
  28804. nuhiragana: 0x306C,
  28805. nukatakana: 0x30CC,
  28806. nukatakanahalfwidth: 0xFF87,
  28807. nuktabengali: 0x09BC,
  28808. nuktadeva: 0x093C,
  28809. nuktagujarati: 0x0ABC,
  28810. nuktagurmukhi: 0x0A3C,
  28811. numbersign: 0x0023,
  28812. numbersignmonospace: 0xFF03,
  28813. numbersignsmall: 0xFE5F,
  28814. numeralsigngreek: 0x0374,
  28815. numeralsignlowergreek: 0x0375,
  28816. numero: 0x2116,
  28817. nun: 0x05E0,
  28818. nundagesh: 0xFB40,
  28819. nundageshhebrew: 0xFB40,
  28820. nunhebrew: 0x05E0,
  28821. nvsquare: 0x33B5,
  28822. nwsquare: 0x33BB,
  28823. nyabengali: 0x099E,
  28824. nyadeva: 0x091E,
  28825. nyagujarati: 0x0A9E,
  28826. nyagurmukhi: 0x0A1E,
  28827. o: 0x006F,
  28828. oacute: 0x00F3,
  28829. oangthai: 0x0E2D,
  28830. obarred: 0x0275,
  28831. obarredcyrillic: 0x04E9,
  28832. obarreddieresiscyrillic: 0x04EB,
  28833. obengali: 0x0993,
  28834. obopomofo: 0x311B,
  28835. obreve: 0x014F,
  28836. ocandradeva: 0x0911,
  28837. ocandragujarati: 0x0A91,
  28838. ocandravowelsigndeva: 0x0949,
  28839. ocandravowelsigngujarati: 0x0AC9,
  28840. ocaron: 0x01D2,
  28841. ocircle: 0x24DE,
  28842. ocircumflex: 0x00F4,
  28843. ocircumflexacute: 0x1ED1,
  28844. ocircumflexdotbelow: 0x1ED9,
  28845. ocircumflexgrave: 0x1ED3,
  28846. ocircumflexhookabove: 0x1ED5,
  28847. ocircumflextilde: 0x1ED7,
  28848. ocyrillic: 0x043E,
  28849. odblacute: 0x0151,
  28850. odblgrave: 0x020D,
  28851. odeva: 0x0913,
  28852. odieresis: 0x00F6,
  28853. odieresiscyrillic: 0x04E7,
  28854. odotbelow: 0x1ECD,
  28855. oe: 0x0153,
  28856. oekorean: 0x315A,
  28857. ogonek: 0x02DB,
  28858. ogonekcmb: 0x0328,
  28859. ograve: 0x00F2,
  28860. ogujarati: 0x0A93,
  28861. oharmenian: 0x0585,
  28862. ohiragana: 0x304A,
  28863. ohookabove: 0x1ECF,
  28864. ohorn: 0x01A1,
  28865. ohornacute: 0x1EDB,
  28866. ohorndotbelow: 0x1EE3,
  28867. ohorngrave: 0x1EDD,
  28868. ohornhookabove: 0x1EDF,
  28869. ohorntilde: 0x1EE1,
  28870. ohungarumlaut: 0x0151,
  28871. oi: 0x01A3,
  28872. oinvertedbreve: 0x020F,
  28873. okatakana: 0x30AA,
  28874. okatakanahalfwidth: 0xFF75,
  28875. okorean: 0x3157,
  28876. olehebrew: 0x05AB,
  28877. omacron: 0x014D,
  28878. omacronacute: 0x1E53,
  28879. omacrongrave: 0x1E51,
  28880. omdeva: 0x0950,
  28881. omega: 0x03C9,
  28882. omega1: 0x03D6,
  28883. omegacyrillic: 0x0461,
  28884. omegalatinclosed: 0x0277,
  28885. omegaroundcyrillic: 0x047B,
  28886. omegatitlocyrillic: 0x047D,
  28887. omegatonos: 0x03CE,
  28888. omgujarati: 0x0AD0,
  28889. omicron: 0x03BF,
  28890. omicrontonos: 0x03CC,
  28891. omonospace: 0xFF4F,
  28892. one: 0x0031,
  28893. onearabic: 0x0661,
  28894. onebengali: 0x09E7,
  28895. onecircle: 0x2460,
  28896. onecircleinversesansserif: 0x278A,
  28897. onedeva: 0x0967,
  28898. onedotenleader: 0x2024,
  28899. oneeighth: 0x215B,
  28900. onefitted: 0xF6DC,
  28901. onegujarati: 0x0AE7,
  28902. onegurmukhi: 0x0A67,
  28903. onehackarabic: 0x0661,
  28904. onehalf: 0x00BD,
  28905. onehangzhou: 0x3021,
  28906. oneideographicparen: 0x3220,
  28907. oneinferior: 0x2081,
  28908. onemonospace: 0xFF11,
  28909. onenumeratorbengali: 0x09F4,
  28910. oneoldstyle: 0xF731,
  28911. oneparen: 0x2474,
  28912. oneperiod: 0x2488,
  28913. onepersian: 0x06F1,
  28914. onequarter: 0x00BC,
  28915. oneroman: 0x2170,
  28916. onesuperior: 0x00B9,
  28917. onethai: 0x0E51,
  28918. onethird: 0x2153,
  28919. oogonek: 0x01EB,
  28920. oogonekmacron: 0x01ED,
  28921. oogurmukhi: 0x0A13,
  28922. oomatragurmukhi: 0x0A4B,
  28923. oopen: 0x0254,
  28924. oparen: 0x24AA,
  28925. openbullet: 0x25E6,
  28926. option: 0x2325,
  28927. ordfeminine: 0x00AA,
  28928. ordmasculine: 0x00BA,
  28929. orthogonal: 0x221F,
  28930. oshortdeva: 0x0912,
  28931. oshortvowelsigndeva: 0x094A,
  28932. oslash: 0x00F8,
  28933. oslashacute: 0x01FF,
  28934. osmallhiragana: 0x3049,
  28935. osmallkatakana: 0x30A9,
  28936. osmallkatakanahalfwidth: 0xFF6B,
  28937. ostrokeacute: 0x01FF,
  28938. osuperior: 0xF6F0,
  28939. otcyrillic: 0x047F,
  28940. otilde: 0x00F5,
  28941. otildeacute: 0x1E4D,
  28942. otildedieresis: 0x1E4F,
  28943. oubopomofo: 0x3121,
  28944. overline: 0x203E,
  28945. overlinecenterline: 0xFE4A,
  28946. overlinecmb: 0x0305,
  28947. overlinedashed: 0xFE49,
  28948. overlinedblwavy: 0xFE4C,
  28949. overlinewavy: 0xFE4B,
  28950. overscore: 0x00AF,
  28951. ovowelsignbengali: 0x09CB,
  28952. ovowelsigndeva: 0x094B,
  28953. ovowelsigngujarati: 0x0ACB,
  28954. p: 0x0070,
  28955. paampssquare: 0x3380,
  28956. paasentosquare: 0x332B,
  28957. pabengali: 0x09AA,
  28958. pacute: 0x1E55,
  28959. padeva: 0x092A,
  28960. pagedown: 0x21DF,
  28961. pageup: 0x21DE,
  28962. pagujarati: 0x0AAA,
  28963. pagurmukhi: 0x0A2A,
  28964. pahiragana: 0x3071,
  28965. paiyannoithai: 0x0E2F,
  28966. pakatakana: 0x30D1,
  28967. palatalizationcyrilliccmb: 0x0484,
  28968. palochkacyrillic: 0x04C0,
  28969. pansioskorean: 0x317F,
  28970. paragraph: 0x00B6,
  28971. parallel: 0x2225,
  28972. parenleft: 0x0028,
  28973. parenleftaltonearabic: 0xFD3E,
  28974. parenleftbt: 0xF8ED,
  28975. parenleftex: 0xF8EC,
  28976. parenleftinferior: 0x208D,
  28977. parenleftmonospace: 0xFF08,
  28978. parenleftsmall: 0xFE59,
  28979. parenleftsuperior: 0x207D,
  28980. parenlefttp: 0xF8EB,
  28981. parenleftvertical: 0xFE35,
  28982. parenright: 0x0029,
  28983. parenrightaltonearabic: 0xFD3F,
  28984. parenrightbt: 0xF8F8,
  28985. parenrightex: 0xF8F7,
  28986. parenrightinferior: 0x208E,
  28987. parenrightmonospace: 0xFF09,
  28988. parenrightsmall: 0xFE5A,
  28989. parenrightsuperior: 0x207E,
  28990. parenrighttp: 0xF8F6,
  28991. parenrightvertical: 0xFE36,
  28992. partialdiff: 0x2202,
  28993. paseqhebrew: 0x05C0,
  28994. pashtahebrew: 0x0599,
  28995. pasquare: 0x33A9,
  28996. patah: 0x05B7,
  28997. patah11: 0x05B7,
  28998. patah1d: 0x05B7,
  28999. patah2a: 0x05B7,
  29000. patahhebrew: 0x05B7,
  29001. patahnarrowhebrew: 0x05B7,
  29002. patahquarterhebrew: 0x05B7,
  29003. patahwidehebrew: 0x05B7,
  29004. pazerhebrew: 0x05A1,
  29005. pbopomofo: 0x3106,
  29006. pcircle: 0x24DF,
  29007. pdotaccent: 0x1E57,
  29008. pe: 0x05E4,
  29009. pecyrillic: 0x043F,
  29010. pedagesh: 0xFB44,
  29011. pedageshhebrew: 0xFB44,
  29012. peezisquare: 0x333B,
  29013. pefinaldageshhebrew: 0xFB43,
  29014. peharabic: 0x067E,
  29015. peharmenian: 0x057A,
  29016. pehebrew: 0x05E4,
  29017. pehfinalarabic: 0xFB57,
  29018. pehinitialarabic: 0xFB58,
  29019. pehiragana: 0x307A,
  29020. pehmedialarabic: 0xFB59,
  29021. pekatakana: 0x30DA,
  29022. pemiddlehookcyrillic: 0x04A7,
  29023. perafehebrew: 0xFB4E,
  29024. percent: 0x0025,
  29025. percentarabic: 0x066A,
  29026. percentmonospace: 0xFF05,
  29027. percentsmall: 0xFE6A,
  29028. period: 0x002E,
  29029. periodarmenian: 0x0589,
  29030. periodcentered: 0x00B7,
  29031. periodhalfwidth: 0xFF61,
  29032. periodinferior: 0xF6E7,
  29033. periodmonospace: 0xFF0E,
  29034. periodsmall: 0xFE52,
  29035. periodsuperior: 0xF6E8,
  29036. perispomenigreekcmb: 0x0342,
  29037. perpendicular: 0x22A5,
  29038. perthousand: 0x2030,
  29039. peseta: 0x20A7,
  29040. pfsquare: 0x338A,
  29041. phabengali: 0x09AB,
  29042. phadeva: 0x092B,
  29043. phagujarati: 0x0AAB,
  29044. phagurmukhi: 0x0A2B,
  29045. phi: 0x03C6,
  29046. phi1: 0x03D5,
  29047. phieuphacirclekorean: 0x327A,
  29048. phieuphaparenkorean: 0x321A,
  29049. phieuphcirclekorean: 0x326C,
  29050. phieuphkorean: 0x314D,
  29051. phieuphparenkorean: 0x320C,
  29052. philatin: 0x0278,
  29053. phinthuthai: 0x0E3A,
  29054. phisymbolgreek: 0x03D5,
  29055. phook: 0x01A5,
  29056. phophanthai: 0x0E1E,
  29057. phophungthai: 0x0E1C,
  29058. phosamphaothai: 0x0E20,
  29059. pi: 0x03C0,
  29060. pieupacirclekorean: 0x3273,
  29061. pieupaparenkorean: 0x3213,
  29062. pieupcieuckorean: 0x3176,
  29063. pieupcirclekorean: 0x3265,
  29064. pieupkiyeokkorean: 0x3172,
  29065. pieupkorean: 0x3142,
  29066. pieupparenkorean: 0x3205,
  29067. pieupsioskiyeokkorean: 0x3174,
  29068. pieupsioskorean: 0x3144,
  29069. pieupsiostikeutkorean: 0x3175,
  29070. pieupthieuthkorean: 0x3177,
  29071. pieuptikeutkorean: 0x3173,
  29072. pihiragana: 0x3074,
  29073. pikatakana: 0x30D4,
  29074. pisymbolgreek: 0x03D6,
  29075. piwrarmenian: 0x0583,
  29076. plus: 0x002B,
  29077. plusbelowcmb: 0x031F,
  29078. pluscircle: 0x2295,
  29079. plusminus: 0x00B1,
  29080. plusmod: 0x02D6,
  29081. plusmonospace: 0xFF0B,
  29082. plussmall: 0xFE62,
  29083. plussuperior: 0x207A,
  29084. pmonospace: 0xFF50,
  29085. pmsquare: 0x33D8,
  29086. pohiragana: 0x307D,
  29087. pointingindexdownwhite: 0x261F,
  29088. pointingindexleftwhite: 0x261C,
  29089. pointingindexrightwhite: 0x261E,
  29090. pointingindexupwhite: 0x261D,
  29091. pokatakana: 0x30DD,
  29092. poplathai: 0x0E1B,
  29093. postalmark: 0x3012,
  29094. postalmarkface: 0x3020,
  29095. pparen: 0x24AB,
  29096. precedes: 0x227A,
  29097. prescription: 0x211E,
  29098. primemod: 0x02B9,
  29099. primereversed: 0x2035,
  29100. product: 0x220F,
  29101. projective: 0x2305,
  29102. prolongedkana: 0x30FC,
  29103. propellor: 0x2318,
  29104. propersubset: 0x2282,
  29105. propersuperset: 0x2283,
  29106. proportion: 0x2237,
  29107. proportional: 0x221D,
  29108. psi: 0x03C8,
  29109. psicyrillic: 0x0471,
  29110. psilipneumatacyrilliccmb: 0x0486,
  29111. pssquare: 0x33B0,
  29112. puhiragana: 0x3077,
  29113. pukatakana: 0x30D7,
  29114. pvsquare: 0x33B4,
  29115. pwsquare: 0x33BA,
  29116. q: 0x0071,
  29117. qadeva: 0x0958,
  29118. qadmahebrew: 0x05A8,
  29119. qafarabic: 0x0642,
  29120. qaffinalarabic: 0xFED6,
  29121. qafinitialarabic: 0xFED7,
  29122. qafmedialarabic: 0xFED8,
  29123. qamats: 0x05B8,
  29124. qamats10: 0x05B8,
  29125. qamats1a: 0x05B8,
  29126. qamats1c: 0x05B8,
  29127. qamats27: 0x05B8,
  29128. qamats29: 0x05B8,
  29129. qamats33: 0x05B8,
  29130. qamatsde: 0x05B8,
  29131. qamatshebrew: 0x05B8,
  29132. qamatsnarrowhebrew: 0x05B8,
  29133. qamatsqatanhebrew: 0x05B8,
  29134. qamatsqatannarrowhebrew: 0x05B8,
  29135. qamatsqatanquarterhebrew: 0x05B8,
  29136. qamatsqatanwidehebrew: 0x05B8,
  29137. qamatsquarterhebrew: 0x05B8,
  29138. qamatswidehebrew: 0x05B8,
  29139. qarneyparahebrew: 0x059F,
  29140. qbopomofo: 0x3111,
  29141. qcircle: 0x24E0,
  29142. qhook: 0x02A0,
  29143. qmonospace: 0xFF51,
  29144. qof: 0x05E7,
  29145. qofdagesh: 0xFB47,
  29146. qofdageshhebrew: 0xFB47,
  29147. qofhebrew: 0x05E7,
  29148. qparen: 0x24AC,
  29149. quarternote: 0x2669,
  29150. qubuts: 0x05BB,
  29151. qubuts18: 0x05BB,
  29152. qubuts25: 0x05BB,
  29153. qubuts31: 0x05BB,
  29154. qubutshebrew: 0x05BB,
  29155. qubutsnarrowhebrew: 0x05BB,
  29156. qubutsquarterhebrew: 0x05BB,
  29157. qubutswidehebrew: 0x05BB,
  29158. question: 0x003F,
  29159. questionarabic: 0x061F,
  29160. questionarmenian: 0x055E,
  29161. questiondown: 0x00BF,
  29162. questiondownsmall: 0xF7BF,
  29163. questiongreek: 0x037E,
  29164. questionmonospace: 0xFF1F,
  29165. questionsmall: 0xF73F,
  29166. quotedbl: 0x0022,
  29167. quotedblbase: 0x201E,
  29168. quotedblleft: 0x201C,
  29169. quotedblmonospace: 0xFF02,
  29170. quotedblprime: 0x301E,
  29171. quotedblprimereversed: 0x301D,
  29172. quotedblright: 0x201D,
  29173. quoteleft: 0x2018,
  29174. quoteleftreversed: 0x201B,
  29175. quotereversed: 0x201B,
  29176. quoteright: 0x2019,
  29177. quoterightn: 0x0149,
  29178. quotesinglbase: 0x201A,
  29179. quotesingle: 0x0027,
  29180. quotesinglemonospace: 0xFF07,
  29181. r: 0x0072,
  29182. raarmenian: 0x057C,
  29183. rabengali: 0x09B0,
  29184. racute: 0x0155,
  29185. radeva: 0x0930,
  29186. radical: 0x221A,
  29187. radicalex: 0xF8E5,
  29188. radoverssquare: 0x33AE,
  29189. radoverssquaredsquare: 0x33AF,
  29190. radsquare: 0x33AD,
  29191. rafe: 0x05BF,
  29192. rafehebrew: 0x05BF,
  29193. ragujarati: 0x0AB0,
  29194. ragurmukhi: 0x0A30,
  29195. rahiragana: 0x3089,
  29196. rakatakana: 0x30E9,
  29197. rakatakanahalfwidth: 0xFF97,
  29198. ralowerdiagonalbengali: 0x09F1,
  29199. ramiddlediagonalbengali: 0x09F0,
  29200. ramshorn: 0x0264,
  29201. ratio: 0x2236,
  29202. rbopomofo: 0x3116,
  29203. rcaron: 0x0159,
  29204. rcedilla: 0x0157,
  29205. rcircle: 0x24E1,
  29206. rcommaaccent: 0x0157,
  29207. rdblgrave: 0x0211,
  29208. rdotaccent: 0x1E59,
  29209. rdotbelow: 0x1E5B,
  29210. rdotbelowmacron: 0x1E5D,
  29211. referencemark: 0x203B,
  29212. reflexsubset: 0x2286,
  29213. reflexsuperset: 0x2287,
  29214. registered: 0x00AE,
  29215. registersans: 0xF8E8,
  29216. registerserif: 0xF6DA,
  29217. reharabic: 0x0631,
  29218. reharmenian: 0x0580,
  29219. rehfinalarabic: 0xFEAE,
  29220. rehiragana: 0x308C,
  29221. rekatakana: 0x30EC,
  29222. rekatakanahalfwidth: 0xFF9A,
  29223. resh: 0x05E8,
  29224. reshdageshhebrew: 0xFB48,
  29225. reshhebrew: 0x05E8,
  29226. reversedtilde: 0x223D,
  29227. reviahebrew: 0x0597,
  29228. reviamugrashhebrew: 0x0597,
  29229. revlogicalnot: 0x2310,
  29230. rfishhook: 0x027E,
  29231. rfishhookreversed: 0x027F,
  29232. rhabengali: 0x09DD,
  29233. rhadeva: 0x095D,
  29234. rho: 0x03C1,
  29235. rhook: 0x027D,
  29236. rhookturned: 0x027B,
  29237. rhookturnedsuperior: 0x02B5,
  29238. rhosymbolgreek: 0x03F1,
  29239. rhotichookmod: 0x02DE,
  29240. rieulacirclekorean: 0x3271,
  29241. rieulaparenkorean: 0x3211,
  29242. rieulcirclekorean: 0x3263,
  29243. rieulhieuhkorean: 0x3140,
  29244. rieulkiyeokkorean: 0x313A,
  29245. rieulkiyeoksioskorean: 0x3169,
  29246. rieulkorean: 0x3139,
  29247. rieulmieumkorean: 0x313B,
  29248. rieulpansioskorean: 0x316C,
  29249. rieulparenkorean: 0x3203,
  29250. rieulphieuphkorean: 0x313F,
  29251. rieulpieupkorean: 0x313C,
  29252. rieulpieupsioskorean: 0x316B,
  29253. rieulsioskorean: 0x313D,
  29254. rieulthieuthkorean: 0x313E,
  29255. rieultikeutkorean: 0x316A,
  29256. rieulyeorinhieuhkorean: 0x316D,
  29257. rightangle: 0x221F,
  29258. righttackbelowcmb: 0x0319,
  29259. righttriangle: 0x22BF,
  29260. rihiragana: 0x308A,
  29261. rikatakana: 0x30EA,
  29262. rikatakanahalfwidth: 0xFF98,
  29263. ring: 0x02DA,
  29264. ringbelowcmb: 0x0325,
  29265. ringcmb: 0x030A,
  29266. ringhalfleft: 0x02BF,
  29267. ringhalfleftarmenian: 0x0559,
  29268. ringhalfleftbelowcmb: 0x031C,
  29269. ringhalfleftcentered: 0x02D3,
  29270. ringhalfright: 0x02BE,
  29271. ringhalfrightbelowcmb: 0x0339,
  29272. ringhalfrightcentered: 0x02D2,
  29273. rinvertedbreve: 0x0213,
  29274. rittorusquare: 0x3351,
  29275. rlinebelow: 0x1E5F,
  29276. rlongleg: 0x027C,
  29277. rlonglegturned: 0x027A,
  29278. rmonospace: 0xFF52,
  29279. rohiragana: 0x308D,
  29280. rokatakana: 0x30ED,
  29281. rokatakanahalfwidth: 0xFF9B,
  29282. roruathai: 0x0E23,
  29283. rparen: 0x24AD,
  29284. rrabengali: 0x09DC,
  29285. rradeva: 0x0931,
  29286. rragurmukhi: 0x0A5C,
  29287. rreharabic: 0x0691,
  29288. rrehfinalarabic: 0xFB8D,
  29289. rrvocalicbengali: 0x09E0,
  29290. rrvocalicdeva: 0x0960,
  29291. rrvocalicgujarati: 0x0AE0,
  29292. rrvocalicvowelsignbengali: 0x09C4,
  29293. rrvocalicvowelsigndeva: 0x0944,
  29294. rrvocalicvowelsigngujarati: 0x0AC4,
  29295. rsuperior: 0xF6F1,
  29296. rtblock: 0x2590,
  29297. rturned: 0x0279,
  29298. rturnedsuperior: 0x02B4,
  29299. ruhiragana: 0x308B,
  29300. rukatakana: 0x30EB,
  29301. rukatakanahalfwidth: 0xFF99,
  29302. rupeemarkbengali: 0x09F2,
  29303. rupeesignbengali: 0x09F3,
  29304. rupiah: 0xF6DD,
  29305. ruthai: 0x0E24,
  29306. rvocalicbengali: 0x098B,
  29307. rvocalicdeva: 0x090B,
  29308. rvocalicgujarati: 0x0A8B,
  29309. rvocalicvowelsignbengali: 0x09C3,
  29310. rvocalicvowelsigndeva: 0x0943,
  29311. rvocalicvowelsigngujarati: 0x0AC3,
  29312. s: 0x0073,
  29313. sabengali: 0x09B8,
  29314. sacute: 0x015B,
  29315. sacutedotaccent: 0x1E65,
  29316. sadarabic: 0x0635,
  29317. sadeva: 0x0938,
  29318. sadfinalarabic: 0xFEBA,
  29319. sadinitialarabic: 0xFEBB,
  29320. sadmedialarabic: 0xFEBC,
  29321. sagujarati: 0x0AB8,
  29322. sagurmukhi: 0x0A38,
  29323. sahiragana: 0x3055,
  29324. sakatakana: 0x30B5,
  29325. sakatakanahalfwidth: 0xFF7B,
  29326. sallallahoualayhewasallamarabic: 0xFDFA,
  29327. samekh: 0x05E1,
  29328. samekhdagesh: 0xFB41,
  29329. samekhdageshhebrew: 0xFB41,
  29330. samekhhebrew: 0x05E1,
  29331. saraaathai: 0x0E32,
  29332. saraaethai: 0x0E41,
  29333. saraaimaimalaithai: 0x0E44,
  29334. saraaimaimuanthai: 0x0E43,
  29335. saraamthai: 0x0E33,
  29336. saraathai: 0x0E30,
  29337. saraethai: 0x0E40,
  29338. saraiileftthai: 0xF886,
  29339. saraiithai: 0x0E35,
  29340. saraileftthai: 0xF885,
  29341. saraithai: 0x0E34,
  29342. saraothai: 0x0E42,
  29343. saraueeleftthai: 0xF888,
  29344. saraueethai: 0x0E37,
  29345. saraueleftthai: 0xF887,
  29346. sarauethai: 0x0E36,
  29347. sarauthai: 0x0E38,
  29348. sarauuthai: 0x0E39,
  29349. sbopomofo: 0x3119,
  29350. scaron: 0x0161,
  29351. scarondotaccent: 0x1E67,
  29352. scedilla: 0x015F,
  29353. schwa: 0x0259,
  29354. schwacyrillic: 0x04D9,
  29355. schwadieresiscyrillic: 0x04DB,
  29356. schwahook: 0x025A,
  29357. scircle: 0x24E2,
  29358. scircumflex: 0x015D,
  29359. scommaaccent: 0x0219,
  29360. sdotaccent: 0x1E61,
  29361. sdotbelow: 0x1E63,
  29362. sdotbelowdotaccent: 0x1E69,
  29363. seagullbelowcmb: 0x033C,
  29364. second: 0x2033,
  29365. secondtonechinese: 0x02CA,
  29366. section: 0x00A7,
  29367. seenarabic: 0x0633,
  29368. seenfinalarabic: 0xFEB2,
  29369. seeninitialarabic: 0xFEB3,
  29370. seenmedialarabic: 0xFEB4,
  29371. segol: 0x05B6,
  29372. segol13: 0x05B6,
  29373. segol1f: 0x05B6,
  29374. segol2c: 0x05B6,
  29375. segolhebrew: 0x05B6,
  29376. segolnarrowhebrew: 0x05B6,
  29377. segolquarterhebrew: 0x05B6,
  29378. segoltahebrew: 0x0592,
  29379. segolwidehebrew: 0x05B6,
  29380. seharmenian: 0x057D,
  29381. sehiragana: 0x305B,
  29382. sekatakana: 0x30BB,
  29383. sekatakanahalfwidth: 0xFF7E,
  29384. semicolon: 0x003B,
  29385. semicolonarabic: 0x061B,
  29386. semicolonmonospace: 0xFF1B,
  29387. semicolonsmall: 0xFE54,
  29388. semivoicedmarkkana: 0x309C,
  29389. semivoicedmarkkanahalfwidth: 0xFF9F,
  29390. sentisquare: 0x3322,
  29391. sentosquare: 0x3323,
  29392. seven: 0x0037,
  29393. sevenarabic: 0x0667,
  29394. sevenbengali: 0x09ED,
  29395. sevencircle: 0x2466,
  29396. sevencircleinversesansserif: 0x2790,
  29397. sevendeva: 0x096D,
  29398. seveneighths: 0x215E,
  29399. sevengujarati: 0x0AED,
  29400. sevengurmukhi: 0x0A6D,
  29401. sevenhackarabic: 0x0667,
  29402. sevenhangzhou: 0x3027,
  29403. sevenideographicparen: 0x3226,
  29404. seveninferior: 0x2087,
  29405. sevenmonospace: 0xFF17,
  29406. sevenoldstyle: 0xF737,
  29407. sevenparen: 0x247A,
  29408. sevenperiod: 0x248E,
  29409. sevenpersian: 0x06F7,
  29410. sevenroman: 0x2176,
  29411. sevensuperior: 0x2077,
  29412. seventeencircle: 0x2470,
  29413. seventeenparen: 0x2484,
  29414. seventeenperiod: 0x2498,
  29415. seventhai: 0x0E57,
  29416. sfthyphen: 0x00AD,
  29417. shaarmenian: 0x0577,
  29418. shabengali: 0x09B6,
  29419. shacyrillic: 0x0448,
  29420. shaddaarabic: 0x0651,
  29421. shaddadammaarabic: 0xFC61,
  29422. shaddadammatanarabic: 0xFC5E,
  29423. shaddafathaarabic: 0xFC60,
  29424. shaddakasraarabic: 0xFC62,
  29425. shaddakasratanarabic: 0xFC5F,
  29426. shade: 0x2592,
  29427. shadedark: 0x2593,
  29428. shadelight: 0x2591,
  29429. shademedium: 0x2592,
  29430. shadeva: 0x0936,
  29431. shagujarati: 0x0AB6,
  29432. shagurmukhi: 0x0A36,
  29433. shalshelethebrew: 0x0593,
  29434. shbopomofo: 0x3115,
  29435. shchacyrillic: 0x0449,
  29436. sheenarabic: 0x0634,
  29437. sheenfinalarabic: 0xFEB6,
  29438. sheeninitialarabic: 0xFEB7,
  29439. sheenmedialarabic: 0xFEB8,
  29440. sheicoptic: 0x03E3,
  29441. sheqel: 0x20AA,
  29442. sheqelhebrew: 0x20AA,
  29443. sheva: 0x05B0,
  29444. sheva115: 0x05B0,
  29445. sheva15: 0x05B0,
  29446. sheva22: 0x05B0,
  29447. sheva2e: 0x05B0,
  29448. shevahebrew: 0x05B0,
  29449. shevanarrowhebrew: 0x05B0,
  29450. shevaquarterhebrew: 0x05B0,
  29451. shevawidehebrew: 0x05B0,
  29452. shhacyrillic: 0x04BB,
  29453. shimacoptic: 0x03ED,
  29454. shin: 0x05E9,
  29455. shindagesh: 0xFB49,
  29456. shindageshhebrew: 0xFB49,
  29457. shindageshshindot: 0xFB2C,
  29458. shindageshshindothebrew: 0xFB2C,
  29459. shindageshsindot: 0xFB2D,
  29460. shindageshsindothebrew: 0xFB2D,
  29461. shindothebrew: 0x05C1,
  29462. shinhebrew: 0x05E9,
  29463. shinshindot: 0xFB2A,
  29464. shinshindothebrew: 0xFB2A,
  29465. shinsindot: 0xFB2B,
  29466. shinsindothebrew: 0xFB2B,
  29467. shook: 0x0282,
  29468. sigma: 0x03C3,
  29469. sigma1: 0x03C2,
  29470. sigmafinal: 0x03C2,
  29471. sigmalunatesymbolgreek: 0x03F2,
  29472. sihiragana: 0x3057,
  29473. sikatakana: 0x30B7,
  29474. sikatakanahalfwidth: 0xFF7C,
  29475. siluqhebrew: 0x05BD,
  29476. siluqlefthebrew: 0x05BD,
  29477. similar: 0x223C,
  29478. sindothebrew: 0x05C2,
  29479. siosacirclekorean: 0x3274,
  29480. siosaparenkorean: 0x3214,
  29481. sioscieuckorean: 0x317E,
  29482. sioscirclekorean: 0x3266,
  29483. sioskiyeokkorean: 0x317A,
  29484. sioskorean: 0x3145,
  29485. siosnieunkorean: 0x317B,
  29486. siosparenkorean: 0x3206,
  29487. siospieupkorean: 0x317D,
  29488. siostikeutkorean: 0x317C,
  29489. six: 0x0036,
  29490. sixarabic: 0x0666,
  29491. sixbengali: 0x09EC,
  29492. sixcircle: 0x2465,
  29493. sixcircleinversesansserif: 0x278F,
  29494. sixdeva: 0x096C,
  29495. sixgujarati: 0x0AEC,
  29496. sixgurmukhi: 0x0A6C,
  29497. sixhackarabic: 0x0666,
  29498. sixhangzhou: 0x3026,
  29499. sixideographicparen: 0x3225,
  29500. sixinferior: 0x2086,
  29501. sixmonospace: 0xFF16,
  29502. sixoldstyle: 0xF736,
  29503. sixparen: 0x2479,
  29504. sixperiod: 0x248D,
  29505. sixpersian: 0x06F6,
  29506. sixroman: 0x2175,
  29507. sixsuperior: 0x2076,
  29508. sixteencircle: 0x246F,
  29509. sixteencurrencydenominatorbengali: 0x09F9,
  29510. sixteenparen: 0x2483,
  29511. sixteenperiod: 0x2497,
  29512. sixthai: 0x0E56,
  29513. slash: 0x002F,
  29514. slashmonospace: 0xFF0F,
  29515. slong: 0x017F,
  29516. slongdotaccent: 0x1E9B,
  29517. smileface: 0x263A,
  29518. smonospace: 0xFF53,
  29519. sofpasuqhebrew: 0x05C3,
  29520. softhyphen: 0x00AD,
  29521. softsigncyrillic: 0x044C,
  29522. sohiragana: 0x305D,
  29523. sokatakana: 0x30BD,
  29524. sokatakanahalfwidth: 0xFF7F,
  29525. soliduslongoverlaycmb: 0x0338,
  29526. solidusshortoverlaycmb: 0x0337,
  29527. sorusithai: 0x0E29,
  29528. sosalathai: 0x0E28,
  29529. sosothai: 0x0E0B,
  29530. sosuathai: 0x0E2A,
  29531. space: 0x0020,
  29532. spacehackarabic: 0x0020,
  29533. spade: 0x2660,
  29534. spadesuitblack: 0x2660,
  29535. spadesuitwhite: 0x2664,
  29536. sparen: 0x24AE,
  29537. squarebelowcmb: 0x033B,
  29538. squarecc: 0x33C4,
  29539. squarecm: 0x339D,
  29540. squarediagonalcrosshatchfill: 0x25A9,
  29541. squarehorizontalfill: 0x25A4,
  29542. squarekg: 0x338F,
  29543. squarekm: 0x339E,
  29544. squarekmcapital: 0x33CE,
  29545. squareln: 0x33D1,
  29546. squarelog: 0x33D2,
  29547. squaremg: 0x338E,
  29548. squaremil: 0x33D5,
  29549. squaremm: 0x339C,
  29550. squaremsquared: 0x33A1,
  29551. squareorthogonalcrosshatchfill: 0x25A6,
  29552. squareupperlefttolowerrightfill: 0x25A7,
  29553. squareupperrighttolowerleftfill: 0x25A8,
  29554. squareverticalfill: 0x25A5,
  29555. squarewhitewithsmallblack: 0x25A3,
  29556. srsquare: 0x33DB,
  29557. ssabengali: 0x09B7,
  29558. ssadeva: 0x0937,
  29559. ssagujarati: 0x0AB7,
  29560. ssangcieuckorean: 0x3149,
  29561. ssanghieuhkorean: 0x3185,
  29562. ssangieungkorean: 0x3180,
  29563. ssangkiyeokkorean: 0x3132,
  29564. ssangnieunkorean: 0x3165,
  29565. ssangpieupkorean: 0x3143,
  29566. ssangsioskorean: 0x3146,
  29567. ssangtikeutkorean: 0x3138,
  29568. ssuperior: 0xF6F2,
  29569. sterling: 0x00A3,
  29570. sterlingmonospace: 0xFFE1,
  29571. strokelongoverlaycmb: 0x0336,
  29572. strokeshortoverlaycmb: 0x0335,
  29573. subset: 0x2282,
  29574. subsetnotequal: 0x228A,
  29575. subsetorequal: 0x2286,
  29576. succeeds: 0x227B,
  29577. suchthat: 0x220B,
  29578. suhiragana: 0x3059,
  29579. sukatakana: 0x30B9,
  29580. sukatakanahalfwidth: 0xFF7D,
  29581. sukunarabic: 0x0652,
  29582. summation: 0x2211,
  29583. sun: 0x263C,
  29584. superset: 0x2283,
  29585. supersetnotequal: 0x228B,
  29586. supersetorequal: 0x2287,
  29587. svsquare: 0x33DC,
  29588. syouwaerasquare: 0x337C,
  29589. t: 0x0074,
  29590. tabengali: 0x09A4,
  29591. tackdown: 0x22A4,
  29592. tackleft: 0x22A3,
  29593. tadeva: 0x0924,
  29594. tagujarati: 0x0AA4,
  29595. tagurmukhi: 0x0A24,
  29596. taharabic: 0x0637,
  29597. tahfinalarabic: 0xFEC2,
  29598. tahinitialarabic: 0xFEC3,
  29599. tahiragana: 0x305F,
  29600. tahmedialarabic: 0xFEC4,
  29601. taisyouerasquare: 0x337D,
  29602. takatakana: 0x30BF,
  29603. takatakanahalfwidth: 0xFF80,
  29604. tatweelarabic: 0x0640,
  29605. tau: 0x03C4,
  29606. tav: 0x05EA,
  29607. tavdages: 0xFB4A,
  29608. tavdagesh: 0xFB4A,
  29609. tavdageshhebrew: 0xFB4A,
  29610. tavhebrew: 0x05EA,
  29611. tbar: 0x0167,
  29612. tbopomofo: 0x310A,
  29613. tcaron: 0x0165,
  29614. tccurl: 0x02A8,
  29615. tcedilla: 0x0163,
  29616. tcheharabic: 0x0686,
  29617. tchehfinalarabic: 0xFB7B,
  29618. tchehinitialarabic: 0xFB7C,
  29619. tchehmedialarabic: 0xFB7D,
  29620. tcircle: 0x24E3,
  29621. tcircumflexbelow: 0x1E71,
  29622. tcommaaccent: 0x0163,
  29623. tdieresis: 0x1E97,
  29624. tdotaccent: 0x1E6B,
  29625. tdotbelow: 0x1E6D,
  29626. tecyrillic: 0x0442,
  29627. tedescendercyrillic: 0x04AD,
  29628. teharabic: 0x062A,
  29629. tehfinalarabic: 0xFE96,
  29630. tehhahinitialarabic: 0xFCA2,
  29631. tehhahisolatedarabic: 0xFC0C,
  29632. tehinitialarabic: 0xFE97,
  29633. tehiragana: 0x3066,
  29634. tehjeeminitialarabic: 0xFCA1,
  29635. tehjeemisolatedarabic: 0xFC0B,
  29636. tehmarbutaarabic: 0x0629,
  29637. tehmarbutafinalarabic: 0xFE94,
  29638. tehmedialarabic: 0xFE98,
  29639. tehmeeminitialarabic: 0xFCA4,
  29640. tehmeemisolatedarabic: 0xFC0E,
  29641. tehnoonfinalarabic: 0xFC73,
  29642. tekatakana: 0x30C6,
  29643. tekatakanahalfwidth: 0xFF83,
  29644. telephone: 0x2121,
  29645. telephoneblack: 0x260E,
  29646. telishagedolahebrew: 0x05A0,
  29647. telishaqetanahebrew: 0x05A9,
  29648. tencircle: 0x2469,
  29649. tenideographicparen: 0x3229,
  29650. tenparen: 0x247D,
  29651. tenperiod: 0x2491,
  29652. tenroman: 0x2179,
  29653. tesh: 0x02A7,
  29654. tet: 0x05D8,
  29655. tetdagesh: 0xFB38,
  29656. tetdageshhebrew: 0xFB38,
  29657. tethebrew: 0x05D8,
  29658. tetsecyrillic: 0x04B5,
  29659. tevirhebrew: 0x059B,
  29660. tevirlefthebrew: 0x059B,
  29661. thabengali: 0x09A5,
  29662. thadeva: 0x0925,
  29663. thagujarati: 0x0AA5,
  29664. thagurmukhi: 0x0A25,
  29665. thalarabic: 0x0630,
  29666. thalfinalarabic: 0xFEAC,
  29667. thanthakhatlowleftthai: 0xF898,
  29668. thanthakhatlowrightthai: 0xF897,
  29669. thanthakhatthai: 0x0E4C,
  29670. thanthakhatupperleftthai: 0xF896,
  29671. theharabic: 0x062B,
  29672. thehfinalarabic: 0xFE9A,
  29673. thehinitialarabic: 0xFE9B,
  29674. thehmedialarabic: 0xFE9C,
  29675. thereexists: 0x2203,
  29676. therefore: 0x2234,
  29677. theta: 0x03B8,
  29678. theta1: 0x03D1,
  29679. thetasymbolgreek: 0x03D1,
  29680. thieuthacirclekorean: 0x3279,
  29681. thieuthaparenkorean: 0x3219,
  29682. thieuthcirclekorean: 0x326B,
  29683. thieuthkorean: 0x314C,
  29684. thieuthparenkorean: 0x320B,
  29685. thirteencircle: 0x246C,
  29686. thirteenparen: 0x2480,
  29687. thirteenperiod: 0x2494,
  29688. thonangmonthothai: 0x0E11,
  29689. thook: 0x01AD,
  29690. thophuthaothai: 0x0E12,
  29691. thorn: 0x00FE,
  29692. thothahanthai: 0x0E17,
  29693. thothanthai: 0x0E10,
  29694. thothongthai: 0x0E18,
  29695. thothungthai: 0x0E16,
  29696. thousandcyrillic: 0x0482,
  29697. thousandsseparatorarabic: 0x066C,
  29698. thousandsseparatorpersian: 0x066C,
  29699. three: 0x0033,
  29700. threearabic: 0x0663,
  29701. threebengali: 0x09E9,
  29702. threecircle: 0x2462,
  29703. threecircleinversesansserif: 0x278C,
  29704. threedeva: 0x0969,
  29705. threeeighths: 0x215C,
  29706. threegujarati: 0x0AE9,
  29707. threegurmukhi: 0x0A69,
  29708. threehackarabic: 0x0663,
  29709. threehangzhou: 0x3023,
  29710. threeideographicparen: 0x3222,
  29711. threeinferior: 0x2083,
  29712. threemonospace: 0xFF13,
  29713. threenumeratorbengali: 0x09F6,
  29714. threeoldstyle: 0xF733,
  29715. threeparen: 0x2476,
  29716. threeperiod: 0x248A,
  29717. threepersian: 0x06F3,
  29718. threequarters: 0x00BE,
  29719. threequartersemdash: 0xF6DE,
  29720. threeroman: 0x2172,
  29721. threesuperior: 0x00B3,
  29722. threethai: 0x0E53,
  29723. thzsquare: 0x3394,
  29724. tihiragana: 0x3061,
  29725. tikatakana: 0x30C1,
  29726. tikatakanahalfwidth: 0xFF81,
  29727. tikeutacirclekorean: 0x3270,
  29728. tikeutaparenkorean: 0x3210,
  29729. tikeutcirclekorean: 0x3262,
  29730. tikeutkorean: 0x3137,
  29731. tikeutparenkorean: 0x3202,
  29732. tilde: 0x02DC,
  29733. tildebelowcmb: 0x0330,
  29734. tildecmb: 0x0303,
  29735. tildecomb: 0x0303,
  29736. tildedoublecmb: 0x0360,
  29737. tildeoperator: 0x223C,
  29738. tildeoverlaycmb: 0x0334,
  29739. tildeverticalcmb: 0x033E,
  29740. timescircle: 0x2297,
  29741. tipehahebrew: 0x0596,
  29742. tipehalefthebrew: 0x0596,
  29743. tippigurmukhi: 0x0A70,
  29744. titlocyrilliccmb: 0x0483,
  29745. tiwnarmenian: 0x057F,
  29746. tlinebelow: 0x1E6F,
  29747. tmonospace: 0xFF54,
  29748. toarmenian: 0x0569,
  29749. tohiragana: 0x3068,
  29750. tokatakana: 0x30C8,
  29751. tokatakanahalfwidth: 0xFF84,
  29752. tonebarextrahighmod: 0x02E5,
  29753. tonebarextralowmod: 0x02E9,
  29754. tonebarhighmod: 0x02E6,
  29755. tonebarlowmod: 0x02E8,
  29756. tonebarmidmod: 0x02E7,
  29757. tonefive: 0x01BD,
  29758. tonesix: 0x0185,
  29759. tonetwo: 0x01A8,
  29760. tonos: 0x0384,
  29761. tonsquare: 0x3327,
  29762. topatakthai: 0x0E0F,
  29763. tortoiseshellbracketleft: 0x3014,
  29764. tortoiseshellbracketleftsmall: 0xFE5D,
  29765. tortoiseshellbracketleftvertical: 0xFE39,
  29766. tortoiseshellbracketright: 0x3015,
  29767. tortoiseshellbracketrightsmall: 0xFE5E,
  29768. tortoiseshellbracketrightvertical: 0xFE3A,
  29769. totaothai: 0x0E15,
  29770. tpalatalhook: 0x01AB,
  29771. tparen: 0x24AF,
  29772. trademark: 0x2122,
  29773. trademarksans: 0xF8EA,
  29774. trademarkserif: 0xF6DB,
  29775. tretroflexhook: 0x0288,
  29776. triagdn: 0x25BC,
  29777. triaglf: 0x25C4,
  29778. triagrt: 0x25BA,
  29779. triagup: 0x25B2,
  29780. ts: 0x02A6,
  29781. tsadi: 0x05E6,
  29782. tsadidagesh: 0xFB46,
  29783. tsadidageshhebrew: 0xFB46,
  29784. tsadihebrew: 0x05E6,
  29785. tsecyrillic: 0x0446,
  29786. tsere: 0x05B5,
  29787. tsere12: 0x05B5,
  29788. tsere1e: 0x05B5,
  29789. tsere2b: 0x05B5,
  29790. tserehebrew: 0x05B5,
  29791. tserenarrowhebrew: 0x05B5,
  29792. tserequarterhebrew: 0x05B5,
  29793. tserewidehebrew: 0x05B5,
  29794. tshecyrillic: 0x045B,
  29795. tsuperior: 0xF6F3,
  29796. ttabengali: 0x099F,
  29797. ttadeva: 0x091F,
  29798. ttagujarati: 0x0A9F,
  29799. ttagurmukhi: 0x0A1F,
  29800. tteharabic: 0x0679,
  29801. ttehfinalarabic: 0xFB67,
  29802. ttehinitialarabic: 0xFB68,
  29803. ttehmedialarabic: 0xFB69,
  29804. tthabengali: 0x09A0,
  29805. tthadeva: 0x0920,
  29806. tthagujarati: 0x0AA0,
  29807. tthagurmukhi: 0x0A20,
  29808. tturned: 0x0287,
  29809. tuhiragana: 0x3064,
  29810. tukatakana: 0x30C4,
  29811. tukatakanahalfwidth: 0xFF82,
  29812. tusmallhiragana: 0x3063,
  29813. tusmallkatakana: 0x30C3,
  29814. tusmallkatakanahalfwidth: 0xFF6F,
  29815. twelvecircle: 0x246B,
  29816. twelveparen: 0x247F,
  29817. twelveperiod: 0x2493,
  29818. twelveroman: 0x217B,
  29819. twentycircle: 0x2473,
  29820. twentyhangzhou: 0x5344,
  29821. twentyparen: 0x2487,
  29822. twentyperiod: 0x249B,
  29823. two: 0x0032,
  29824. twoarabic: 0x0662,
  29825. twobengali: 0x09E8,
  29826. twocircle: 0x2461,
  29827. twocircleinversesansserif: 0x278B,
  29828. twodeva: 0x0968,
  29829. twodotenleader: 0x2025,
  29830. twodotleader: 0x2025,
  29831. twodotleadervertical: 0xFE30,
  29832. twogujarati: 0x0AE8,
  29833. twogurmukhi: 0x0A68,
  29834. twohackarabic: 0x0662,
  29835. twohangzhou: 0x3022,
  29836. twoideographicparen: 0x3221,
  29837. twoinferior: 0x2082,
  29838. twomonospace: 0xFF12,
  29839. twonumeratorbengali: 0x09F5,
  29840. twooldstyle: 0xF732,
  29841. twoparen: 0x2475,
  29842. twoperiod: 0x2489,
  29843. twopersian: 0x06F2,
  29844. tworoman: 0x2171,
  29845. twostroke: 0x01BB,
  29846. twosuperior: 0x00B2,
  29847. twothai: 0x0E52,
  29848. twothirds: 0x2154,
  29849. u: 0x0075,
  29850. uacute: 0x00FA,
  29851. ubar: 0x0289,
  29852. ubengali: 0x0989,
  29853. ubopomofo: 0x3128,
  29854. ubreve: 0x016D,
  29855. ucaron: 0x01D4,
  29856. ucircle: 0x24E4,
  29857. ucircumflex: 0x00FB,
  29858. ucircumflexbelow: 0x1E77,
  29859. ucyrillic: 0x0443,
  29860. udattadeva: 0x0951,
  29861. udblacute: 0x0171,
  29862. udblgrave: 0x0215,
  29863. udeva: 0x0909,
  29864. udieresis: 0x00FC,
  29865. udieresisacute: 0x01D8,
  29866. udieresisbelow: 0x1E73,
  29867. udieresiscaron: 0x01DA,
  29868. udieresiscyrillic: 0x04F1,
  29869. udieresisgrave: 0x01DC,
  29870. udieresismacron: 0x01D6,
  29871. udotbelow: 0x1EE5,
  29872. ugrave: 0x00F9,
  29873. ugujarati: 0x0A89,
  29874. ugurmukhi: 0x0A09,
  29875. uhiragana: 0x3046,
  29876. uhookabove: 0x1EE7,
  29877. uhorn: 0x01B0,
  29878. uhornacute: 0x1EE9,
  29879. uhorndotbelow: 0x1EF1,
  29880. uhorngrave: 0x1EEB,
  29881. uhornhookabove: 0x1EED,
  29882. uhorntilde: 0x1EEF,
  29883. uhungarumlaut: 0x0171,
  29884. uhungarumlautcyrillic: 0x04F3,
  29885. uinvertedbreve: 0x0217,
  29886. ukatakana: 0x30A6,
  29887. ukatakanahalfwidth: 0xFF73,
  29888. ukcyrillic: 0x0479,
  29889. ukorean: 0x315C,
  29890. umacron: 0x016B,
  29891. umacroncyrillic: 0x04EF,
  29892. umacrondieresis: 0x1E7B,
  29893. umatragurmukhi: 0x0A41,
  29894. umonospace: 0xFF55,
  29895. underscore: 0x005F,
  29896. underscoredbl: 0x2017,
  29897. underscoremonospace: 0xFF3F,
  29898. underscorevertical: 0xFE33,
  29899. underscorewavy: 0xFE4F,
  29900. union: 0x222A,
  29901. universal: 0x2200,
  29902. uogonek: 0x0173,
  29903. uparen: 0x24B0,
  29904. upblock: 0x2580,
  29905. upperdothebrew: 0x05C4,
  29906. upsilon: 0x03C5,
  29907. upsilondieresis: 0x03CB,
  29908. upsilondieresistonos: 0x03B0,
  29909. upsilonlatin: 0x028A,
  29910. upsilontonos: 0x03CD,
  29911. uptackbelowcmb: 0x031D,
  29912. uptackmod: 0x02D4,
  29913. uragurmukhi: 0x0A73,
  29914. uring: 0x016F,
  29915. ushortcyrillic: 0x045E,
  29916. usmallhiragana: 0x3045,
  29917. usmallkatakana: 0x30A5,
  29918. usmallkatakanahalfwidth: 0xFF69,
  29919. ustraightcyrillic: 0x04AF,
  29920. ustraightstrokecyrillic: 0x04B1,
  29921. utilde: 0x0169,
  29922. utildeacute: 0x1E79,
  29923. utildebelow: 0x1E75,
  29924. uubengali: 0x098A,
  29925. uudeva: 0x090A,
  29926. uugujarati: 0x0A8A,
  29927. uugurmukhi: 0x0A0A,
  29928. uumatragurmukhi: 0x0A42,
  29929. uuvowelsignbengali: 0x09C2,
  29930. uuvowelsigndeva: 0x0942,
  29931. uuvowelsigngujarati: 0x0AC2,
  29932. uvowelsignbengali: 0x09C1,
  29933. uvowelsigndeva: 0x0941,
  29934. uvowelsigngujarati: 0x0AC1,
  29935. v: 0x0076,
  29936. vadeva: 0x0935,
  29937. vagujarati: 0x0AB5,
  29938. vagurmukhi: 0x0A35,
  29939. vakatakana: 0x30F7,
  29940. vav: 0x05D5,
  29941. vavdagesh: 0xFB35,
  29942. vavdagesh65: 0xFB35,
  29943. vavdageshhebrew: 0xFB35,
  29944. vavhebrew: 0x05D5,
  29945. vavholam: 0xFB4B,
  29946. vavholamhebrew: 0xFB4B,
  29947. vavvavhebrew: 0x05F0,
  29948. vavyodhebrew: 0x05F1,
  29949. vcircle: 0x24E5,
  29950. vdotbelow: 0x1E7F,
  29951. vecyrillic: 0x0432,
  29952. veharabic: 0x06A4,
  29953. vehfinalarabic: 0xFB6B,
  29954. vehinitialarabic: 0xFB6C,
  29955. vehmedialarabic: 0xFB6D,
  29956. vekatakana: 0x30F9,
  29957. venus: 0x2640,
  29958. verticalbar: 0x007C,
  29959. verticallineabovecmb: 0x030D,
  29960. verticallinebelowcmb: 0x0329,
  29961. verticallinelowmod: 0x02CC,
  29962. verticallinemod: 0x02C8,
  29963. vewarmenian: 0x057E,
  29964. vhook: 0x028B,
  29965. vikatakana: 0x30F8,
  29966. viramabengali: 0x09CD,
  29967. viramadeva: 0x094D,
  29968. viramagujarati: 0x0ACD,
  29969. visargabengali: 0x0983,
  29970. visargadeva: 0x0903,
  29971. visargagujarati: 0x0A83,
  29972. vmonospace: 0xFF56,
  29973. voarmenian: 0x0578,
  29974. voicediterationhiragana: 0x309E,
  29975. voicediterationkatakana: 0x30FE,
  29976. voicedmarkkana: 0x309B,
  29977. voicedmarkkanahalfwidth: 0xFF9E,
  29978. vokatakana: 0x30FA,
  29979. vparen: 0x24B1,
  29980. vtilde: 0x1E7D,
  29981. vturned: 0x028C,
  29982. vuhiragana: 0x3094,
  29983. vukatakana: 0x30F4,
  29984. w: 0x0077,
  29985. wacute: 0x1E83,
  29986. waekorean: 0x3159,
  29987. wahiragana: 0x308F,
  29988. wakatakana: 0x30EF,
  29989. wakatakanahalfwidth: 0xFF9C,
  29990. wakorean: 0x3158,
  29991. wasmallhiragana: 0x308E,
  29992. wasmallkatakana: 0x30EE,
  29993. wattosquare: 0x3357,
  29994. wavedash: 0x301C,
  29995. wavyunderscorevertical: 0xFE34,
  29996. wawarabic: 0x0648,
  29997. wawfinalarabic: 0xFEEE,
  29998. wawhamzaabovearabic: 0x0624,
  29999. wawhamzaabovefinalarabic: 0xFE86,
  30000. wbsquare: 0x33DD,
  30001. wcircle: 0x24E6,
  30002. wcircumflex: 0x0175,
  30003. wdieresis: 0x1E85,
  30004. wdotaccent: 0x1E87,
  30005. wdotbelow: 0x1E89,
  30006. wehiragana: 0x3091,
  30007. weierstrass: 0x2118,
  30008. wekatakana: 0x30F1,
  30009. wekorean: 0x315E,
  30010. weokorean: 0x315D,
  30011. wgrave: 0x1E81,
  30012. whitebullet: 0x25E6,
  30013. whitecircle: 0x25CB,
  30014. whitecircleinverse: 0x25D9,
  30015. whitecornerbracketleft: 0x300E,
  30016. whitecornerbracketleftvertical: 0xFE43,
  30017. whitecornerbracketright: 0x300F,
  30018. whitecornerbracketrightvertical: 0xFE44,
  30019. whitediamond: 0x25C7,
  30020. whitediamondcontainingblacksmalldiamond: 0x25C8,
  30021. whitedownpointingsmalltriangle: 0x25BF,
  30022. whitedownpointingtriangle: 0x25BD,
  30023. whiteleftpointingsmalltriangle: 0x25C3,
  30024. whiteleftpointingtriangle: 0x25C1,
  30025. whitelenticularbracketleft: 0x3016,
  30026. whitelenticularbracketright: 0x3017,
  30027. whiterightpointingsmalltriangle: 0x25B9,
  30028. whiterightpointingtriangle: 0x25B7,
  30029. whitesmallsquare: 0x25AB,
  30030. whitesmilingface: 0x263A,
  30031. whitesquare: 0x25A1,
  30032. whitestar: 0x2606,
  30033. whitetelephone: 0x260F,
  30034. whitetortoiseshellbracketleft: 0x3018,
  30035. whitetortoiseshellbracketright: 0x3019,
  30036. whiteuppointingsmalltriangle: 0x25B5,
  30037. whiteuppointingtriangle: 0x25B3,
  30038. wihiragana: 0x3090,
  30039. wikatakana: 0x30F0,
  30040. wikorean: 0x315F,
  30041. wmonospace: 0xFF57,
  30042. wohiragana: 0x3092,
  30043. wokatakana: 0x30F2,
  30044. wokatakanahalfwidth: 0xFF66,
  30045. won: 0x20A9,
  30046. wonmonospace: 0xFFE6,
  30047. wowaenthai: 0x0E27,
  30048. wparen: 0x24B2,
  30049. wring: 0x1E98,
  30050. wsuperior: 0x02B7,
  30051. wturned: 0x028D,
  30052. wynn: 0x01BF,
  30053. x: 0x0078,
  30054. xabovecmb: 0x033D,
  30055. xbopomofo: 0x3112,
  30056. xcircle: 0x24E7,
  30057. xdieresis: 0x1E8D,
  30058. xdotaccent: 0x1E8B,
  30059. xeharmenian: 0x056D,
  30060. xi: 0x03BE,
  30061. xmonospace: 0xFF58,
  30062. xparen: 0x24B3,
  30063. xsuperior: 0x02E3,
  30064. y: 0x0079,
  30065. yaadosquare: 0x334E,
  30066. yabengali: 0x09AF,
  30067. yacute: 0x00FD,
  30068. yadeva: 0x092F,
  30069. yaekorean: 0x3152,
  30070. yagujarati: 0x0AAF,
  30071. yagurmukhi: 0x0A2F,
  30072. yahiragana: 0x3084,
  30073. yakatakana: 0x30E4,
  30074. yakatakanahalfwidth: 0xFF94,
  30075. yakorean: 0x3151,
  30076. yamakkanthai: 0x0E4E,
  30077. yasmallhiragana: 0x3083,
  30078. yasmallkatakana: 0x30E3,
  30079. yasmallkatakanahalfwidth: 0xFF6C,
  30080. yatcyrillic: 0x0463,
  30081. ycircle: 0x24E8,
  30082. ycircumflex: 0x0177,
  30083. ydieresis: 0x00FF,
  30084. ydotaccent: 0x1E8F,
  30085. ydotbelow: 0x1EF5,
  30086. yeharabic: 0x064A,
  30087. yehbarreearabic: 0x06D2,
  30088. yehbarreefinalarabic: 0xFBAF,
  30089. yehfinalarabic: 0xFEF2,
  30090. yehhamzaabovearabic: 0x0626,
  30091. yehhamzaabovefinalarabic: 0xFE8A,
  30092. yehhamzaaboveinitialarabic: 0xFE8B,
  30093. yehhamzaabovemedialarabic: 0xFE8C,
  30094. yehinitialarabic: 0xFEF3,
  30095. yehmedialarabic: 0xFEF4,
  30096. yehmeeminitialarabic: 0xFCDD,
  30097. yehmeemisolatedarabic: 0xFC58,
  30098. yehnoonfinalarabic: 0xFC94,
  30099. yehthreedotsbelowarabic: 0x06D1,
  30100. yekorean: 0x3156,
  30101. yen: 0x00A5,
  30102. yenmonospace: 0xFFE5,
  30103. yeokorean: 0x3155,
  30104. yeorinhieuhkorean: 0x3186,
  30105. yerahbenyomohebrew: 0x05AA,
  30106. yerahbenyomolefthebrew: 0x05AA,
  30107. yericyrillic: 0x044B,
  30108. yerudieresiscyrillic: 0x04F9,
  30109. yesieungkorean: 0x3181,
  30110. yesieungpansioskorean: 0x3183,
  30111. yesieungsioskorean: 0x3182,
  30112. yetivhebrew: 0x059A,
  30113. ygrave: 0x1EF3,
  30114. yhook: 0x01B4,
  30115. yhookabove: 0x1EF7,
  30116. yiarmenian: 0x0575,
  30117. yicyrillic: 0x0457,
  30118. yikorean: 0x3162,
  30119. yinyang: 0x262F,
  30120. yiwnarmenian: 0x0582,
  30121. ymonospace: 0xFF59,
  30122. yod: 0x05D9,
  30123. yoddagesh: 0xFB39,
  30124. yoddageshhebrew: 0xFB39,
  30125. yodhebrew: 0x05D9,
  30126. yodyodhebrew: 0x05F2,
  30127. yodyodpatahhebrew: 0xFB1F,
  30128. yohiragana: 0x3088,
  30129. yoikorean: 0x3189,
  30130. yokatakana: 0x30E8,
  30131. yokatakanahalfwidth: 0xFF96,
  30132. yokorean: 0x315B,
  30133. yosmallhiragana: 0x3087,
  30134. yosmallkatakana: 0x30E7,
  30135. yosmallkatakanahalfwidth: 0xFF6E,
  30136. yotgreek: 0x03F3,
  30137. yoyaekorean: 0x3188,
  30138. yoyakorean: 0x3187,
  30139. yoyakthai: 0x0E22,
  30140. yoyingthai: 0x0E0D,
  30141. yparen: 0x24B4,
  30142. ypogegrammeni: 0x037A,
  30143. ypogegrammenigreekcmb: 0x0345,
  30144. yr: 0x01A6,
  30145. yring: 0x1E99,
  30146. ysuperior: 0x02B8,
  30147. ytilde: 0x1EF9,
  30148. yturned: 0x028E,
  30149. yuhiragana: 0x3086,
  30150. yuikorean: 0x318C,
  30151. yukatakana: 0x30E6,
  30152. yukatakanahalfwidth: 0xFF95,
  30153. yukorean: 0x3160,
  30154. yusbigcyrillic: 0x046B,
  30155. yusbigiotifiedcyrillic: 0x046D,
  30156. yuslittlecyrillic: 0x0467,
  30157. yuslittleiotifiedcyrillic: 0x0469,
  30158. yusmallhiragana: 0x3085,
  30159. yusmallkatakana: 0x30E5,
  30160. yusmallkatakanahalfwidth: 0xFF6D,
  30161. yuyekorean: 0x318B,
  30162. yuyeokorean: 0x318A,
  30163. yyabengali: 0x09DF,
  30164. yyadeva: 0x095F,
  30165. z: 0x007A,
  30166. zaarmenian: 0x0566,
  30167. zacute: 0x017A,
  30168. zadeva: 0x095B,
  30169. zagurmukhi: 0x0A5B,
  30170. zaharabic: 0x0638,
  30171. zahfinalarabic: 0xFEC6,
  30172. zahinitialarabic: 0xFEC7,
  30173. zahiragana: 0x3056,
  30174. zahmedialarabic: 0xFEC8,
  30175. zainarabic: 0x0632,
  30176. zainfinalarabic: 0xFEB0,
  30177. zakatakana: 0x30B6,
  30178. zaqefgadolhebrew: 0x0595,
  30179. zaqefqatanhebrew: 0x0594,
  30180. zarqahebrew: 0x0598,
  30181. zayin: 0x05D6,
  30182. zayindagesh: 0xFB36,
  30183. zayindageshhebrew: 0xFB36,
  30184. zayinhebrew: 0x05D6,
  30185. zbopomofo: 0x3117,
  30186. zcaron: 0x017E,
  30187. zcircle: 0x24E9,
  30188. zcircumflex: 0x1E91,
  30189. zcurl: 0x0291,
  30190. zdot: 0x017C,
  30191. zdotaccent: 0x017C,
  30192. zdotbelow: 0x1E93,
  30193. zecyrillic: 0x0437,
  30194. zedescendercyrillic: 0x0499,
  30195. zedieresiscyrillic: 0x04DF,
  30196. zehiragana: 0x305C,
  30197. zekatakana: 0x30BC,
  30198. zero: 0x0030,
  30199. zeroarabic: 0x0660,
  30200. zerobengali: 0x09E6,
  30201. zerodeva: 0x0966,
  30202. zerogujarati: 0x0AE6,
  30203. zerogurmukhi: 0x0A66,
  30204. zerohackarabic: 0x0660,
  30205. zeroinferior: 0x2080,
  30206. zeromonospace: 0xFF10,
  30207. zerooldstyle: 0xF730,
  30208. zeropersian: 0x06F0,
  30209. zerosuperior: 0x2070,
  30210. zerothai: 0x0E50,
  30211. zerowidthjoiner: 0xFEFF,
  30212. zerowidthnonjoiner: 0x200C,
  30213. zerowidthspace: 0x200B,
  30214. zeta: 0x03B6,
  30215. zhbopomofo: 0x3113,
  30216. zhearmenian: 0x056A,
  30217. zhebrevecyrillic: 0x04C2,
  30218. zhecyrillic: 0x0436,
  30219. zhedescendercyrillic: 0x0497,
  30220. zhedieresiscyrillic: 0x04DD,
  30221. zihiragana: 0x3058,
  30222. zikatakana: 0x30B8,
  30223. zinorhebrew: 0x05AE,
  30224. zlinebelow: 0x1E95,
  30225. zmonospace: 0xFF5A,
  30226. zohiragana: 0x305E,
  30227. zokatakana: 0x30BE,
  30228. zparen: 0x24B5,
  30229. zretroflexhook: 0x0290,
  30230. zstroke: 0x01B6,
  30231. zuhiragana: 0x305A,
  30232. zukatakana: 0x30BA,
  30233. '.notdef': 0x0000
  30234. };
  30235. var DingbatsGlyphsUnicode = {
  30236. space: 0x0020,
  30237. a1: 0x2701,
  30238. a2: 0x2702,
  30239. a202: 0x2703,
  30240. a3: 0x2704,
  30241. a4: 0x260E,
  30242. a5: 0x2706,
  30243. a119: 0x2707,
  30244. a118: 0x2708,
  30245. a117: 0x2709,
  30246. a11: 0x261B,
  30247. a12: 0x261E,
  30248. a13: 0x270C,
  30249. a14: 0x270D,
  30250. a15: 0x270E,
  30251. a16: 0x270F,
  30252. a105: 0x2710,
  30253. a17: 0x2711,
  30254. a18: 0x2712,
  30255. a19: 0x2713,
  30256. a20: 0x2714,
  30257. a21: 0x2715,
  30258. a22: 0x2716,
  30259. a23: 0x2717,
  30260. a24: 0x2718,
  30261. a25: 0x2719,
  30262. a26: 0x271A,
  30263. a27: 0x271B,
  30264. a28: 0x271C,
  30265. a6: 0x271D,
  30266. a7: 0x271E,
  30267. a8: 0x271F,
  30268. a9: 0x2720,
  30269. a10: 0x2721,
  30270. a29: 0x2722,
  30271. a30: 0x2723,
  30272. a31: 0x2724,
  30273. a32: 0x2725,
  30274. a33: 0x2726,
  30275. a34: 0x2727,
  30276. a35: 0x2605,
  30277. a36: 0x2729,
  30278. a37: 0x272A,
  30279. a38: 0x272B,
  30280. a39: 0x272C,
  30281. a40: 0x272D,
  30282. a41: 0x272E,
  30283. a42: 0x272F,
  30284. a43: 0x2730,
  30285. a44: 0x2731,
  30286. a45: 0x2732,
  30287. a46: 0x2733,
  30288. a47: 0x2734,
  30289. a48: 0x2735,
  30290. a49: 0x2736,
  30291. a50: 0x2737,
  30292. a51: 0x2738,
  30293. a52: 0x2739,
  30294. a53: 0x273A,
  30295. a54: 0x273B,
  30296. a55: 0x273C,
  30297. a56: 0x273D,
  30298. a57: 0x273E,
  30299. a58: 0x273F,
  30300. a59: 0x2740,
  30301. a60: 0x2741,
  30302. a61: 0x2742,
  30303. a62: 0x2743,
  30304. a63: 0x2744,
  30305. a64: 0x2745,
  30306. a65: 0x2746,
  30307. a66: 0x2747,
  30308. a67: 0x2748,
  30309. a68: 0x2749,
  30310. a69: 0x274A,
  30311. a70: 0x274B,
  30312. a71: 0x25CF,
  30313. a72: 0x274D,
  30314. a73: 0x25A0,
  30315. a74: 0x274F,
  30316. a203: 0x2750,
  30317. a75: 0x2751,
  30318. a204: 0x2752,
  30319. a76: 0x25B2,
  30320. a77: 0x25BC,
  30321. a78: 0x25C6,
  30322. a79: 0x2756,
  30323. a81: 0x25D7,
  30324. a82: 0x2758,
  30325. a83: 0x2759,
  30326. a84: 0x275A,
  30327. a97: 0x275B,
  30328. a98: 0x275C,
  30329. a99: 0x275D,
  30330. a100: 0x275E,
  30331. a101: 0x2761,
  30332. a102: 0x2762,
  30333. a103: 0x2763,
  30334. a104: 0x2764,
  30335. a106: 0x2765,
  30336. a107: 0x2766,
  30337. a108: 0x2767,
  30338. a112: 0x2663,
  30339. a111: 0x2666,
  30340. a110: 0x2665,
  30341. a109: 0x2660,
  30342. a120: 0x2460,
  30343. a121: 0x2461,
  30344. a122: 0x2462,
  30345. a123: 0x2463,
  30346. a124: 0x2464,
  30347. a125: 0x2465,
  30348. a126: 0x2466,
  30349. a127: 0x2467,
  30350. a128: 0x2468,
  30351. a129: 0x2469,
  30352. a130: 0x2776,
  30353. a131: 0x2777,
  30354. a132: 0x2778,
  30355. a133: 0x2779,
  30356. a134: 0x277A,
  30357. a135: 0x277B,
  30358. a136: 0x277C,
  30359. a137: 0x277D,
  30360. a138: 0x277E,
  30361. a139: 0x277F,
  30362. a140: 0x2780,
  30363. a141: 0x2781,
  30364. a142: 0x2782,
  30365. a143: 0x2783,
  30366. a144: 0x2784,
  30367. a145: 0x2785,
  30368. a146: 0x2786,
  30369. a147: 0x2787,
  30370. a148: 0x2788,
  30371. a149: 0x2789,
  30372. a150: 0x278A,
  30373. a151: 0x278B,
  30374. a152: 0x278C,
  30375. a153: 0x278D,
  30376. a154: 0x278E,
  30377. a155: 0x278F,
  30378. a156: 0x2790,
  30379. a157: 0x2791,
  30380. a158: 0x2792,
  30381. a159: 0x2793,
  30382. a160: 0x2794,
  30383. a161: 0x2192,
  30384. a163: 0x2194,
  30385. a164: 0x2195,
  30386. a196: 0x2798,
  30387. a165: 0x2799,
  30388. a192: 0x279A,
  30389. a166: 0x279B,
  30390. a167: 0x279C,
  30391. a168: 0x279D,
  30392. a169: 0x279E,
  30393. a170: 0x279F,
  30394. a171: 0x27A0,
  30395. a172: 0x27A1,
  30396. a173: 0x27A2,
  30397. a162: 0x27A3,
  30398. a174: 0x27A4,
  30399. a175: 0x27A5,
  30400. a176: 0x27A6,
  30401. a177: 0x27A7,
  30402. a178: 0x27A8,
  30403. a179: 0x27A9,
  30404. a193: 0x27AA,
  30405. a180: 0x27AB,
  30406. a199: 0x27AC,
  30407. a181: 0x27AD,
  30408. a200: 0x27AE,
  30409. a182: 0x27AF,
  30410. a201: 0x27B1,
  30411. a183: 0x27B2,
  30412. a184: 0x27B3,
  30413. a197: 0x27B4,
  30414. a185: 0x27B5,
  30415. a194: 0x27B6,
  30416. a198: 0x27B7,
  30417. a186: 0x27B8,
  30418. a195: 0x27B9,
  30419. a187: 0x27BA,
  30420. a188: 0x27BB,
  30421. a189: 0x27BC,
  30422. a190: 0x27BD,
  30423. a191: 0x27BE,
  30424. a89: 0x2768, // 0xF8D7
  30425. a90: 0x2769, // 0xF8D8
  30426. a93: 0x276A, // 0xF8D9
  30427. a94: 0x276B, // 0xF8DA
  30428. a91: 0x276C, // 0xF8DB
  30429. a92: 0x276D, // 0xF8DC
  30430. a205: 0x276E, // 0xF8DD
  30431. a85: 0x276F, // 0xF8DE
  30432. a206: 0x2770, // 0xF8DF
  30433. a86: 0x2771, // 0xF8E0
  30434. a87: 0x2772, // 0xF8E1
  30435. a88: 0x2773, // 0xF8E2
  30436. a95: 0x2774, // 0xF8E3
  30437. a96: 0x2775, // 0xF8E4
  30438. '.notdef': 0x0000
  30439. };
  30440. var PDFImage = (function PDFImageClosure() {
  30441. /**
  30442. * Decode the image in the main thread if it supported. Resovles the promise
  30443. * when the image data is ready.
  30444. */
  30445. function handleImageData(handler, xref, res, image) {
  30446. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30447. // For natively supported jpegs send them to the main thread for decoding.
  30448. var dict = image.dict;
  30449. var colorSpace = dict.get('ColorSpace', 'CS');
  30450. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30451. var numComps = colorSpace.numComps;
  30452. var decodePromise = handler.sendWithPromise('JpegDecode',
  30453. [image.getIR(), numComps]);
  30454. return decodePromise.then(function (message) {
  30455. var data = message.data;
  30456. return new Stream(data, 0, data.length, image.dict);
  30457. });
  30458. } else {
  30459. return Promise.resolve(image);
  30460. }
  30461. }
  30462. /**
  30463. * Decode and clamp a value. The formula is different from the spec because we
  30464. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30465. */
  30466. function decodeAndClamp(value, addend, coefficient, max) {
  30467. value = addend + value * coefficient;
  30468. // Clamp the value to the range
  30469. return (value < 0 ? 0 : (value > max ? max : value));
  30470. }
  30471. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30472. this.image = image;
  30473. var dict = image.dict;
  30474. if (dict.has('Filter')) {
  30475. var filter = dict.get('Filter').name;
  30476. if (filter === 'JPXDecode') {
  30477. var jpxImage = new JpxImage();
  30478. jpxImage.parseImageProperties(image.stream);
  30479. image.stream.reset();
  30480. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30481. image.numComps = jpxImage.componentsCount;
  30482. } else if (filter === 'JBIG2Decode') {
  30483. image.bitsPerComponent = 1;
  30484. image.numComps = 1;
  30485. }
  30486. }
  30487. // TODO cache rendered images?
  30488. this.width = dict.get('Width', 'W');
  30489. this.height = dict.get('Height', 'H');
  30490. if (this.width < 1 || this.height < 1) {
  30491. error('Invalid image width: ' + this.width + ' or height: ' +
  30492. this.height);
  30493. }
  30494. this.interpolate = dict.get('Interpolate', 'I') || false;
  30495. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30496. this.matte = dict.get('Matte') || false;
  30497. var bitsPerComponent = image.bitsPerComponent;
  30498. if (!bitsPerComponent) {
  30499. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30500. if (!bitsPerComponent) {
  30501. if (this.imageMask) {
  30502. bitsPerComponent = 1;
  30503. } else {
  30504. error('Bits per component missing in image: ' + this.imageMask);
  30505. }
  30506. }
  30507. }
  30508. this.bpc = bitsPerComponent;
  30509. if (!this.imageMask) {
  30510. var colorSpace = dict.get('ColorSpace', 'CS');
  30511. if (!colorSpace) {
  30512. info('JPX images (which do not require color spaces)');
  30513. switch (image.numComps) {
  30514. case 1:
  30515. colorSpace = Name.get('DeviceGray');
  30516. break;
  30517. case 3:
  30518. colorSpace = Name.get('DeviceRGB');
  30519. break;
  30520. case 4:
  30521. colorSpace = Name.get('DeviceCMYK');
  30522. break;
  30523. default:
  30524. error('JPX images with ' + this.numComps +
  30525. ' color components not supported.');
  30526. }
  30527. }
  30528. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30529. this.numComps = this.colorSpace.numComps;
  30530. }
  30531. this.decode = dict.get('Decode', 'D');
  30532. this.needsDecode = false;
  30533. if (this.decode &&
  30534. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30535. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30536. this.needsDecode = true;
  30537. // Do some preprocessing to avoid more math.
  30538. var max = (1 << bitsPerComponent) - 1;
  30539. this.decodeCoefficients = [];
  30540. this.decodeAddends = [];
  30541. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30542. var dmin = this.decode[i];
  30543. var dmax = this.decode[i + 1];
  30544. this.decodeCoefficients[j] = dmax - dmin;
  30545. this.decodeAddends[j] = max * dmin;
  30546. }
  30547. }
  30548. if (smask) {
  30549. this.smask = new PDFImage(xref, res, smask, false);
  30550. } else if (mask) {
  30551. if (isStream(mask)) {
  30552. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30553. } else {
  30554. // Color key mask (just an array).
  30555. this.mask = mask;
  30556. }
  30557. }
  30558. }
  30559. /**
  30560. * Handles processing of image data and returns the Promise that is resolved
  30561. * with a PDFImage when the image is ready to be used.
  30562. */
  30563. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30564. res, image, inline) {
  30565. var imagePromise = handleImageData(handler, xref, res, image);
  30566. var smaskPromise;
  30567. var maskPromise;
  30568. var smask = image.dict.get('SMask');
  30569. var mask = image.dict.get('Mask');
  30570. if (smask) {
  30571. smaskPromise = handleImageData(handler, xref, res, smask);
  30572. maskPromise = Promise.resolve(null);
  30573. } else {
  30574. smaskPromise = Promise.resolve(null);
  30575. if (mask) {
  30576. if (isStream(mask)) {
  30577. maskPromise = handleImageData(handler, xref, res, mask);
  30578. } else if (isArray(mask)) {
  30579. maskPromise = Promise.resolve(mask);
  30580. } else {
  30581. warn('Unsupported mask format.');
  30582. maskPromise = Promise.resolve(null);
  30583. }
  30584. } else {
  30585. maskPromise = Promise.resolve(null);
  30586. }
  30587. }
  30588. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30589. function(results) {
  30590. var imageData = results[0];
  30591. var smaskData = results[1];
  30592. var maskData = results[2];
  30593. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30594. });
  30595. };
  30596. /**
  30597. * Resize an image using the nearest neighbor algorithm. Currently only
  30598. * supports one and three component images.
  30599. * @param {TypedArray} pixels The original image with one component.
  30600. * @param {Number} bpc Number of bits per component.
  30601. * @param {Number} components Number of color components, 1 or 3 is supported.
  30602. * @param {Number} w1 Original width.
  30603. * @param {Number} h1 Original height.
  30604. * @param {Number} w2 New width.
  30605. * @param {Number} h2 New height.
  30606. * @param {TypedArray} dest (Optional) The destination buffer.
  30607. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30608. * @return {TypedArray} Resized image data.
  30609. */
  30610. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30611. w1, h1, w2, h2, dest, alpha01) {
  30612. if (components !== 1 && components !== 3) {
  30613. error('Unsupported component count for resizing.');
  30614. }
  30615. var length = w2 * h2 * components;
  30616. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30617. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30618. var xRatio = w1 / w2;
  30619. var yRatio = h1 / h2;
  30620. var i, j, py, newIndex = 0, oldIndex;
  30621. var xScaled = new Uint16Array(w2);
  30622. var w1Scanline = w1 * components;
  30623. if (alpha01 !== 1) {
  30624. alpha01 = 0;
  30625. }
  30626. for (j = 0; j < w2; j++) {
  30627. xScaled[j] = Math.floor(j * xRatio) * components;
  30628. }
  30629. if (components === 1) {
  30630. for (i = 0; i < h2; i++) {
  30631. py = Math.floor(i * yRatio) * w1Scanline;
  30632. for (j = 0; j < w2; j++) {
  30633. oldIndex = py + xScaled[j];
  30634. temp[newIndex++] = pixels[oldIndex];
  30635. }
  30636. }
  30637. } else if (components === 3) {
  30638. for (i = 0; i < h2; i++) {
  30639. py = Math.floor(i * yRatio) * w1Scanline;
  30640. for (j = 0; j < w2; j++) {
  30641. oldIndex = py + xScaled[j];
  30642. temp[newIndex++] = pixels[oldIndex++];
  30643. temp[newIndex++] = pixels[oldIndex++];
  30644. temp[newIndex++] = pixels[oldIndex++];
  30645. newIndex += alpha01;
  30646. }
  30647. }
  30648. }
  30649. return temp;
  30650. };
  30651. PDFImage.createMask =
  30652. function PDFImage_createMask(imgArray, width, height,
  30653. imageIsFromDecodeStream, inverseDecode) {
  30654. // |imgArray| might not contain full data for every pixel of the mask, so
  30655. // we need to distinguish between |computedLength| and |actualLength|.
  30656. // In particular, if inverseDecode is true, then the array we return must
  30657. // have a length of |computedLength|.
  30658. var computedLength = ((width + 7) >> 3) * height;
  30659. var actualLength = imgArray.byteLength;
  30660. var haveFullData = computedLength === actualLength;
  30661. var data, i;
  30662. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30663. // imgArray came from a DecodeStream and its data is in an appropriate
  30664. // form, so we can just transfer it.
  30665. data = imgArray;
  30666. } else if (!inverseDecode) {
  30667. data = new Uint8Array(actualLength);
  30668. data.set(imgArray);
  30669. } else {
  30670. data = new Uint8Array(computedLength);
  30671. data.set(imgArray);
  30672. for (i = actualLength; i < computedLength; i++) {
  30673. data[i] = 0xff;
  30674. }
  30675. }
  30676. // If necessary, invert the original mask data (but not any extra we might
  30677. // have added above). It's safe to modify the array -- whether it's the
  30678. // original or a copy, we're about to transfer it anyway, so nothing else
  30679. // in this thread can be relying on its contents.
  30680. if (inverseDecode) {
  30681. for (i = 0; i < actualLength; i++) {
  30682. data[i] = ~data[i];
  30683. }
  30684. }
  30685. return {data: data, width: width, height: height};
  30686. };
  30687. PDFImage.prototype = {
  30688. get drawWidth() {
  30689. return Math.max(this.width,
  30690. this.smask && this.smask.width || 0,
  30691. this.mask && this.mask.width || 0);
  30692. },
  30693. get drawHeight() {
  30694. return Math.max(this.height,
  30695. this.smask && this.smask.height || 0,
  30696. this.mask && this.mask.height || 0);
  30697. },
  30698. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30699. var bpc = this.bpc;
  30700. var numComps = this.numComps;
  30701. var decodeAddends = this.decodeAddends;
  30702. var decodeCoefficients = this.decodeCoefficients;
  30703. var max = (1 << bpc) - 1;
  30704. var i, ii;
  30705. if (bpc === 1) {
  30706. // If the buffer needed decode that means it just needs to be inverted.
  30707. for (i = 0, ii = buffer.length; i < ii; i++) {
  30708. buffer[i] = +!(buffer[i]);
  30709. }
  30710. return;
  30711. }
  30712. var index = 0;
  30713. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30714. for (var j = 0; j < numComps; j++) {
  30715. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30716. decodeCoefficients[j], max);
  30717. index++;
  30718. }
  30719. }
  30720. },
  30721. getComponents: function PDFImage_getComponents(buffer) {
  30722. var bpc = this.bpc;
  30723. // This image doesn't require any extra work.
  30724. if (bpc === 8) {
  30725. return buffer;
  30726. }
  30727. var width = this.width;
  30728. var height = this.height;
  30729. var numComps = this.numComps;
  30730. var length = width * height * numComps;
  30731. var bufferPos = 0;
  30732. var output = (bpc <= 8 ? new Uint8Array(length) :
  30733. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30734. var rowComps = width * numComps;
  30735. var max = (1 << bpc) - 1;
  30736. var i = 0, ii, buf;
  30737. if (bpc === 1) {
  30738. // Optimization for reading 1 bpc images.
  30739. var mask, loop1End, loop2End;
  30740. for (var j = 0; j < height; j++) {
  30741. loop1End = i + (rowComps & ~7);
  30742. loop2End = i + rowComps;
  30743. // unroll loop for all full bytes
  30744. while (i < loop1End) {
  30745. buf = buffer[bufferPos++];
  30746. output[i] = (buf >> 7) & 1;
  30747. output[i + 1] = (buf >> 6) & 1;
  30748. output[i + 2] = (buf >> 5) & 1;
  30749. output[i + 3] = (buf >> 4) & 1;
  30750. output[i + 4] = (buf >> 3) & 1;
  30751. output[i + 5] = (buf >> 2) & 1;
  30752. output[i + 6] = (buf >> 1) & 1;
  30753. output[i + 7] = buf & 1;
  30754. i += 8;
  30755. }
  30756. // handle remaing bits
  30757. if (i < loop2End) {
  30758. buf = buffer[bufferPos++];
  30759. mask = 128;
  30760. while (i < loop2End) {
  30761. output[i++] = +!!(buf & mask);
  30762. mask >>= 1;
  30763. }
  30764. }
  30765. }
  30766. } else {
  30767. // The general case that handles all other bpc values.
  30768. var bits = 0;
  30769. buf = 0;
  30770. for (i = 0, ii = length; i < ii; ++i) {
  30771. if (i % rowComps === 0) {
  30772. buf = 0;
  30773. bits = 0;
  30774. }
  30775. while (bits < bpc) {
  30776. buf = (buf << 8) | buffer[bufferPos++];
  30777. bits += 8;
  30778. }
  30779. var remainingBits = bits - bpc;
  30780. var value = buf >> remainingBits;
  30781. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30782. buf = buf & ((1 << remainingBits) - 1);
  30783. bits = remainingBits;
  30784. }
  30785. }
  30786. return output;
  30787. },
  30788. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30789. actualHeight, image) {
  30790. var smask = this.smask;
  30791. var mask = this.mask;
  30792. var alphaBuf, sw, sh, i, ii, j;
  30793. if (smask) {
  30794. sw = smask.width;
  30795. sh = smask.height;
  30796. alphaBuf = new Uint8Array(sw * sh);
  30797. smask.fillGrayBuffer(alphaBuf);
  30798. if (sw !== width || sh !== height) {
  30799. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30800. height);
  30801. }
  30802. } else if (mask) {
  30803. if (mask instanceof PDFImage) {
  30804. sw = mask.width;
  30805. sh = mask.height;
  30806. alphaBuf = new Uint8Array(sw * sh);
  30807. mask.numComps = 1;
  30808. mask.fillGrayBuffer(alphaBuf);
  30809. // Need to invert values in rgbaBuf
  30810. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30811. alphaBuf[i] = 255 - alphaBuf[i];
  30812. }
  30813. if (sw !== width || sh !== height) {
  30814. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30815. height);
  30816. }
  30817. } else if (isArray(mask)) {
  30818. // Color key mask: if any of the compontents are outside the range
  30819. // then they should be painted.
  30820. alphaBuf = new Uint8Array(width * height);
  30821. var numComps = this.numComps;
  30822. for (i = 0, ii = width * height; i < ii; ++i) {
  30823. var opacity = 0;
  30824. var imageOffset = i * numComps;
  30825. for (j = 0; j < numComps; ++j) {
  30826. var color = image[imageOffset + j];
  30827. var maskOffset = j * 2;
  30828. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30829. opacity = 255;
  30830. break;
  30831. }
  30832. }
  30833. alphaBuf[i] = opacity;
  30834. }
  30835. } else {
  30836. error('Unknown mask format.');
  30837. }
  30838. }
  30839. if (alphaBuf) {
  30840. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30841. rgbaBuf[j] = alphaBuf[i];
  30842. }
  30843. } else {
  30844. // No mask.
  30845. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30846. rgbaBuf[j] = 255;
  30847. }
  30848. }
  30849. },
  30850. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30851. var matte = this.smask && this.smask.matte;
  30852. if (!matte) {
  30853. return;
  30854. }
  30855. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30856. var matteR = matteRgb[0];
  30857. var matteG = matteRgb[1];
  30858. var matteB = matteRgb[2];
  30859. var length = width * height * 4;
  30860. var r, g, b;
  30861. for (var i = 0; i < length; i += 4) {
  30862. var alpha = buffer[i + 3];
  30863. if (alpha === 0) {
  30864. // according formula we have to get Infinity in all components
  30865. // making it white (typical paper color) should be okay
  30866. buffer[i] = 255;
  30867. buffer[i + 1] = 255;
  30868. buffer[i + 2] = 255;
  30869. continue;
  30870. }
  30871. var k = 255 / alpha;
  30872. r = (buffer[i] - matteR) * k + matteR;
  30873. g = (buffer[i + 1] - matteG) * k + matteG;
  30874. b = (buffer[i + 2] - matteB) * k + matteB;
  30875. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30876. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30877. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30878. }
  30879. },
  30880. createImageData: function PDFImage_createImageData(forceRGBA) {
  30881. var drawWidth = this.drawWidth;
  30882. var drawHeight = this.drawHeight;
  30883. var imgData = { // other fields are filled in below
  30884. width: drawWidth,
  30885. height: drawHeight
  30886. };
  30887. var numComps = this.numComps;
  30888. var originalWidth = this.width;
  30889. var originalHeight = this.height;
  30890. var bpc = this.bpc;
  30891. // Rows start at byte boundary.
  30892. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30893. var imgArray;
  30894. if (!forceRGBA) {
  30895. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30896. // without any complications, we pass a same-sized copy to the main
  30897. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30898. // of memory for many scanned documents. It's also much faster.
  30899. //
  30900. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30901. // complications, we avoid expanding by 1.333x to RGBA form.
  30902. var kind;
  30903. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30904. kind = ImageKind.GRAYSCALE_1BPP;
  30905. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30906. !this.needsDecode) {
  30907. kind = ImageKind.RGB_24BPP;
  30908. }
  30909. if (kind && !this.smask && !this.mask &&
  30910. drawWidth === originalWidth && drawHeight === originalHeight) {
  30911. imgData.kind = kind;
  30912. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30913. // If imgArray came from a DecodeStream, we're safe to transfer it
  30914. // (and thus neuter it) because it will constitute the entire
  30915. // DecodeStream's data. But if it came from a Stream, we need to
  30916. // copy it because it'll only be a portion of the Stream's data, and
  30917. // the rest will be read later on.
  30918. if (this.image instanceof DecodeStream) {
  30919. imgData.data = imgArray;
  30920. } else {
  30921. var newArray = new Uint8Array(imgArray.length);
  30922. newArray.set(imgArray);
  30923. imgData.data = newArray;
  30924. }
  30925. if (this.needsDecode) {
  30926. // Invert the buffer (which must be grayscale if we reached here).
  30927. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30928. var buffer = imgData.data;
  30929. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30930. buffer[i] ^= 0xff;
  30931. }
  30932. }
  30933. return imgData;
  30934. }
  30935. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30936. imgData.kind = ImageKind.RGB_24BPP;
  30937. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30938. drawWidth, drawHeight, true);
  30939. return imgData;
  30940. }
  30941. }
  30942. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30943. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  30944. var actualHeight = 0 | (imgArray.length / rowBytes *
  30945. drawHeight / originalHeight);
  30946. var comps = this.getComponents(imgArray);
  30947. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  30948. // more compact RGB_24BPP form if allowable.
  30949. var alpha01, maybeUndoPreblend;
  30950. if (!forceRGBA && !this.smask && !this.mask) {
  30951. imgData.kind = ImageKind.RGB_24BPP;
  30952. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  30953. alpha01 = 0;
  30954. maybeUndoPreblend = false;
  30955. } else {
  30956. imgData.kind = ImageKind.RGBA_32BPP;
  30957. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  30958. alpha01 = 1;
  30959. maybeUndoPreblend = true;
  30960. // Color key masking (opacity) must be performed before decoding.
  30961. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  30962. comps);
  30963. }
  30964. if (this.needsDecode) {
  30965. this.decodeBuffer(comps);
  30966. }
  30967. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  30968. drawWidth, drawHeight, actualHeight, bpc, comps,
  30969. alpha01);
  30970. if (maybeUndoPreblend) {
  30971. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  30972. }
  30973. return imgData;
  30974. },
  30975. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  30976. var numComps = this.numComps;
  30977. if (numComps !== 1) {
  30978. error('Reading gray scale from a color image: ' + numComps);
  30979. }
  30980. var width = this.width;
  30981. var height = this.height;
  30982. var bpc = this.bpc;
  30983. // rows start at byte boundary
  30984. var rowBytes = (width * numComps * bpc + 7) >> 3;
  30985. var imgArray = this.getImageBytes(height * rowBytes);
  30986. var comps = this.getComponents(imgArray);
  30987. var i, length;
  30988. if (bpc === 1) {
  30989. // inline decoding (= inversion) for 1 bpc images
  30990. length = width * height;
  30991. if (this.needsDecode) {
  30992. // invert and scale to {0, 255}
  30993. for (i = 0; i < length; ++i) {
  30994. buffer[i] = (comps[i] - 1) & 255;
  30995. }
  30996. } else {
  30997. // scale to {0, 255}
  30998. for (i = 0; i < length; ++i) {
  30999. buffer[i] = (-comps[i]) & 255;
  31000. }
  31001. }
  31002. return;
  31003. }
  31004. if (this.needsDecode) {
  31005. this.decodeBuffer(comps);
  31006. }
  31007. length = width * height;
  31008. // we aren't using a colorspace so we need to scale the value
  31009. var scale = 255 / ((1 << bpc) - 1);
  31010. for (i = 0; i < length; ++i) {
  31011. buffer[i] = (scale * comps[i]) | 0;
  31012. }
  31013. },
  31014. getImageBytes: function PDFImage_getImageBytes(length,
  31015. drawWidth, drawHeight,
  31016. forceRGB) {
  31017. this.image.reset();
  31018. this.image.drawWidth = drawWidth || this.width;
  31019. this.image.drawHeight = drawHeight || this.height;
  31020. this.image.forceRGB = !!forceRGB;
  31021. return this.image.getBytes(length);
  31022. }
  31023. };
  31024. return PDFImage;
  31025. })();
  31026. // The Metrics object contains glyph widths (in glyph space units).
  31027. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  31028. // space unit corresponds to 1/1000th of text space unit.
  31029. var Metrics = {
  31030. 'Courier': 600,
  31031. 'Courier-Bold': 600,
  31032. 'Courier-BoldOblique': 600,
  31033. 'Courier-Oblique': 600,
  31034. 'Helvetica' : {
  31035. 'space': 278,
  31036. 'exclam': 278,
  31037. 'quotedbl': 355,
  31038. 'numbersign': 556,
  31039. 'dollar': 556,
  31040. 'percent': 889,
  31041. 'ampersand': 667,
  31042. 'quoteright': 222,
  31043. 'parenleft': 333,
  31044. 'parenright': 333,
  31045. 'asterisk': 389,
  31046. 'plus': 584,
  31047. 'comma': 278,
  31048. 'hyphen': 333,
  31049. 'period': 278,
  31050. 'slash': 278,
  31051. 'zero': 556,
  31052. 'one': 556,
  31053. 'two': 556,
  31054. 'three': 556,
  31055. 'four': 556,
  31056. 'five': 556,
  31057. 'six': 556,
  31058. 'seven': 556,
  31059. 'eight': 556,
  31060. 'nine': 556,
  31061. 'colon': 278,
  31062. 'semicolon': 278,
  31063. 'less': 584,
  31064. 'equal': 584,
  31065. 'greater': 584,
  31066. 'question': 556,
  31067. 'at': 1015,
  31068. 'A': 667,
  31069. 'B': 667,
  31070. 'C': 722,
  31071. 'D': 722,
  31072. 'E': 667,
  31073. 'F': 611,
  31074. 'G': 778,
  31075. 'H': 722,
  31076. 'I': 278,
  31077. 'J': 500,
  31078. 'K': 667,
  31079. 'L': 556,
  31080. 'M': 833,
  31081. 'N': 722,
  31082. 'O': 778,
  31083. 'P': 667,
  31084. 'Q': 778,
  31085. 'R': 722,
  31086. 'S': 667,
  31087. 'T': 611,
  31088. 'U': 722,
  31089. 'V': 667,
  31090. 'W': 944,
  31091. 'X': 667,
  31092. 'Y': 667,
  31093. 'Z': 611,
  31094. 'bracketleft': 278,
  31095. 'backslash': 278,
  31096. 'bracketright': 278,
  31097. 'asciicircum': 469,
  31098. 'underscore': 556,
  31099. 'quoteleft': 222,
  31100. 'a': 556,
  31101. 'b': 556,
  31102. 'c': 500,
  31103. 'd': 556,
  31104. 'e': 556,
  31105. 'f': 278,
  31106. 'g': 556,
  31107. 'h': 556,
  31108. 'i': 222,
  31109. 'j': 222,
  31110. 'k': 500,
  31111. 'l': 222,
  31112. 'm': 833,
  31113. 'n': 556,
  31114. 'o': 556,
  31115. 'p': 556,
  31116. 'q': 556,
  31117. 'r': 333,
  31118. 's': 500,
  31119. 't': 278,
  31120. 'u': 556,
  31121. 'v': 500,
  31122. 'w': 722,
  31123. 'x': 500,
  31124. 'y': 500,
  31125. 'z': 500,
  31126. 'braceleft': 334,
  31127. 'bar': 260,
  31128. 'braceright': 334,
  31129. 'asciitilde': 584,
  31130. 'exclamdown': 333,
  31131. 'cent': 556,
  31132. 'sterling': 556,
  31133. 'fraction': 167,
  31134. 'yen': 556,
  31135. 'florin': 556,
  31136. 'section': 556,
  31137. 'currency': 556,
  31138. 'quotesingle': 191,
  31139. 'quotedblleft': 333,
  31140. 'guillemotleft': 556,
  31141. 'guilsinglleft': 333,
  31142. 'guilsinglright': 333,
  31143. 'fi': 500,
  31144. 'fl': 500,
  31145. 'endash': 556,
  31146. 'dagger': 556,
  31147. 'daggerdbl': 556,
  31148. 'periodcentered': 278,
  31149. 'paragraph': 537,
  31150. 'bullet': 350,
  31151. 'quotesinglbase': 222,
  31152. 'quotedblbase': 333,
  31153. 'quotedblright': 333,
  31154. 'guillemotright': 556,
  31155. 'ellipsis': 1000,
  31156. 'perthousand': 1000,
  31157. 'questiondown': 611,
  31158. 'grave': 333,
  31159. 'acute': 333,
  31160. 'circumflex': 333,
  31161. 'tilde': 333,
  31162. 'macron': 333,
  31163. 'breve': 333,
  31164. 'dotaccent': 333,
  31165. 'dieresis': 333,
  31166. 'ring': 333,
  31167. 'cedilla': 333,
  31168. 'hungarumlaut': 333,
  31169. 'ogonek': 333,
  31170. 'caron': 333,
  31171. 'emdash': 1000,
  31172. 'AE': 1000,
  31173. 'ordfeminine': 370,
  31174. 'Lslash': 556,
  31175. 'Oslash': 778,
  31176. 'OE': 1000,
  31177. 'ordmasculine': 365,
  31178. 'ae': 889,
  31179. 'dotlessi': 278,
  31180. 'lslash': 222,
  31181. 'oslash': 611,
  31182. 'oe': 944,
  31183. 'germandbls': 611,
  31184. 'Idieresis': 278,
  31185. 'eacute': 556,
  31186. 'abreve': 556,
  31187. 'uhungarumlaut': 556,
  31188. 'ecaron': 556,
  31189. 'Ydieresis': 667,
  31190. 'divide': 584,
  31191. 'Yacute': 667,
  31192. 'Acircumflex': 667,
  31193. 'aacute': 556,
  31194. 'Ucircumflex': 722,
  31195. 'yacute': 500,
  31196. 'scommaaccent': 500,
  31197. 'ecircumflex': 556,
  31198. 'Uring': 722,
  31199. 'Udieresis': 722,
  31200. 'aogonek': 556,
  31201. 'Uacute': 722,
  31202. 'uogonek': 556,
  31203. 'Edieresis': 667,
  31204. 'Dcroat': 722,
  31205. 'commaaccent': 250,
  31206. 'copyright': 737,
  31207. 'Emacron': 667,
  31208. 'ccaron': 500,
  31209. 'aring': 556,
  31210. 'Ncommaaccent': 722,
  31211. 'lacute': 222,
  31212. 'agrave': 556,
  31213. 'Tcommaaccent': 611,
  31214. 'Cacute': 722,
  31215. 'atilde': 556,
  31216. 'Edotaccent': 667,
  31217. 'scaron': 500,
  31218. 'scedilla': 500,
  31219. 'iacute': 278,
  31220. 'lozenge': 471,
  31221. 'Rcaron': 722,
  31222. 'Gcommaaccent': 778,
  31223. 'ucircumflex': 556,
  31224. 'acircumflex': 556,
  31225. 'Amacron': 667,
  31226. 'rcaron': 333,
  31227. 'ccedilla': 500,
  31228. 'Zdotaccent': 611,
  31229. 'Thorn': 667,
  31230. 'Omacron': 778,
  31231. 'Racute': 722,
  31232. 'Sacute': 667,
  31233. 'dcaron': 643,
  31234. 'Umacron': 722,
  31235. 'uring': 556,
  31236. 'threesuperior': 333,
  31237. 'Ograve': 778,
  31238. 'Agrave': 667,
  31239. 'Abreve': 667,
  31240. 'multiply': 584,
  31241. 'uacute': 556,
  31242. 'Tcaron': 611,
  31243. 'partialdiff': 476,
  31244. 'ydieresis': 500,
  31245. 'Nacute': 722,
  31246. 'icircumflex': 278,
  31247. 'Ecircumflex': 667,
  31248. 'adieresis': 556,
  31249. 'edieresis': 556,
  31250. 'cacute': 500,
  31251. 'nacute': 556,
  31252. 'umacron': 556,
  31253. 'Ncaron': 722,
  31254. 'Iacute': 278,
  31255. 'plusminus': 584,
  31256. 'brokenbar': 260,
  31257. 'registered': 737,
  31258. 'Gbreve': 778,
  31259. 'Idotaccent': 278,
  31260. 'summation': 600,
  31261. 'Egrave': 667,
  31262. 'racute': 333,
  31263. 'omacron': 556,
  31264. 'Zacute': 611,
  31265. 'Zcaron': 611,
  31266. 'greaterequal': 549,
  31267. 'Eth': 722,
  31268. 'Ccedilla': 722,
  31269. 'lcommaaccent': 222,
  31270. 'tcaron': 317,
  31271. 'eogonek': 556,
  31272. 'Uogonek': 722,
  31273. 'Aacute': 667,
  31274. 'Adieresis': 667,
  31275. 'egrave': 556,
  31276. 'zacute': 500,
  31277. 'iogonek': 222,
  31278. 'Oacute': 778,
  31279. 'oacute': 556,
  31280. 'amacron': 556,
  31281. 'sacute': 500,
  31282. 'idieresis': 278,
  31283. 'Ocircumflex': 778,
  31284. 'Ugrave': 722,
  31285. 'Delta': 612,
  31286. 'thorn': 556,
  31287. 'twosuperior': 333,
  31288. 'Odieresis': 778,
  31289. 'mu': 556,
  31290. 'igrave': 278,
  31291. 'ohungarumlaut': 556,
  31292. 'Eogonek': 667,
  31293. 'dcroat': 556,
  31294. 'threequarters': 834,
  31295. 'Scedilla': 667,
  31296. 'lcaron': 299,
  31297. 'Kcommaaccent': 667,
  31298. 'Lacute': 556,
  31299. 'trademark': 1000,
  31300. 'edotaccent': 556,
  31301. 'Igrave': 278,
  31302. 'Imacron': 278,
  31303. 'Lcaron': 556,
  31304. 'onehalf': 834,
  31305. 'lessequal': 549,
  31306. 'ocircumflex': 556,
  31307. 'ntilde': 556,
  31308. 'Uhungarumlaut': 722,
  31309. 'Eacute': 667,
  31310. 'emacron': 556,
  31311. 'gbreve': 556,
  31312. 'onequarter': 834,
  31313. 'Scaron': 667,
  31314. 'Scommaaccent': 667,
  31315. 'Ohungarumlaut': 778,
  31316. 'degree': 400,
  31317. 'ograve': 556,
  31318. 'Ccaron': 722,
  31319. 'ugrave': 556,
  31320. 'radical': 453,
  31321. 'Dcaron': 722,
  31322. 'rcommaaccent': 333,
  31323. 'Ntilde': 722,
  31324. 'otilde': 556,
  31325. 'Rcommaaccent': 722,
  31326. 'Lcommaaccent': 556,
  31327. 'Atilde': 667,
  31328. 'Aogonek': 667,
  31329. 'Aring': 667,
  31330. 'Otilde': 778,
  31331. 'zdotaccent': 500,
  31332. 'Ecaron': 667,
  31333. 'Iogonek': 278,
  31334. 'kcommaaccent': 500,
  31335. 'minus': 584,
  31336. 'Icircumflex': 278,
  31337. 'ncaron': 556,
  31338. 'tcommaaccent': 278,
  31339. 'logicalnot': 584,
  31340. 'odieresis': 556,
  31341. 'udieresis': 556,
  31342. 'notequal': 549,
  31343. 'gcommaaccent': 556,
  31344. 'eth': 556,
  31345. 'zcaron': 500,
  31346. 'ncommaaccent': 556,
  31347. 'onesuperior': 333,
  31348. 'imacron': 278,
  31349. 'Euro': 556
  31350. },
  31351. 'Helvetica-Bold': {
  31352. 'space': 278,
  31353. 'exclam': 333,
  31354. 'quotedbl': 474,
  31355. 'numbersign': 556,
  31356. 'dollar': 556,
  31357. 'percent': 889,
  31358. 'ampersand': 722,
  31359. 'quoteright': 278,
  31360. 'parenleft': 333,
  31361. 'parenright': 333,
  31362. 'asterisk': 389,
  31363. 'plus': 584,
  31364. 'comma': 278,
  31365. 'hyphen': 333,
  31366. 'period': 278,
  31367. 'slash': 278,
  31368. 'zero': 556,
  31369. 'one': 556,
  31370. 'two': 556,
  31371. 'three': 556,
  31372. 'four': 556,
  31373. 'five': 556,
  31374. 'six': 556,
  31375. 'seven': 556,
  31376. 'eight': 556,
  31377. 'nine': 556,
  31378. 'colon': 333,
  31379. 'semicolon': 333,
  31380. 'less': 584,
  31381. 'equal': 584,
  31382. 'greater': 584,
  31383. 'question': 611,
  31384. 'at': 975,
  31385. 'A': 722,
  31386. 'B': 722,
  31387. 'C': 722,
  31388. 'D': 722,
  31389. 'E': 667,
  31390. 'F': 611,
  31391. 'G': 778,
  31392. 'H': 722,
  31393. 'I': 278,
  31394. 'J': 556,
  31395. 'K': 722,
  31396. 'L': 611,
  31397. 'M': 833,
  31398. 'N': 722,
  31399. 'O': 778,
  31400. 'P': 667,
  31401. 'Q': 778,
  31402. 'R': 722,
  31403. 'S': 667,
  31404. 'T': 611,
  31405. 'U': 722,
  31406. 'V': 667,
  31407. 'W': 944,
  31408. 'X': 667,
  31409. 'Y': 667,
  31410. 'Z': 611,
  31411. 'bracketleft': 333,
  31412. 'backslash': 278,
  31413. 'bracketright': 333,
  31414. 'asciicircum': 584,
  31415. 'underscore': 556,
  31416. 'quoteleft': 278,
  31417. 'a': 556,
  31418. 'b': 611,
  31419. 'c': 556,
  31420. 'd': 611,
  31421. 'e': 556,
  31422. 'f': 333,
  31423. 'g': 611,
  31424. 'h': 611,
  31425. 'i': 278,
  31426. 'j': 278,
  31427. 'k': 556,
  31428. 'l': 278,
  31429. 'm': 889,
  31430. 'n': 611,
  31431. 'o': 611,
  31432. 'p': 611,
  31433. 'q': 611,
  31434. 'r': 389,
  31435. 's': 556,
  31436. 't': 333,
  31437. 'u': 611,
  31438. 'v': 556,
  31439. 'w': 778,
  31440. 'x': 556,
  31441. 'y': 556,
  31442. 'z': 500,
  31443. 'braceleft': 389,
  31444. 'bar': 280,
  31445. 'braceright': 389,
  31446. 'asciitilde': 584,
  31447. 'exclamdown': 333,
  31448. 'cent': 556,
  31449. 'sterling': 556,
  31450. 'fraction': 167,
  31451. 'yen': 556,
  31452. 'florin': 556,
  31453. 'section': 556,
  31454. 'currency': 556,
  31455. 'quotesingle': 238,
  31456. 'quotedblleft': 500,
  31457. 'guillemotleft': 556,
  31458. 'guilsinglleft': 333,
  31459. 'guilsinglright': 333,
  31460. 'fi': 611,
  31461. 'fl': 611,
  31462. 'endash': 556,
  31463. 'dagger': 556,
  31464. 'daggerdbl': 556,
  31465. 'periodcentered': 278,
  31466. 'paragraph': 556,
  31467. 'bullet': 350,
  31468. 'quotesinglbase': 278,
  31469. 'quotedblbase': 500,
  31470. 'quotedblright': 500,
  31471. 'guillemotright': 556,
  31472. 'ellipsis': 1000,
  31473. 'perthousand': 1000,
  31474. 'questiondown': 611,
  31475. 'grave': 333,
  31476. 'acute': 333,
  31477. 'circumflex': 333,
  31478. 'tilde': 333,
  31479. 'macron': 333,
  31480. 'breve': 333,
  31481. 'dotaccent': 333,
  31482. 'dieresis': 333,
  31483. 'ring': 333,
  31484. 'cedilla': 333,
  31485. 'hungarumlaut': 333,
  31486. 'ogonek': 333,
  31487. 'caron': 333,
  31488. 'emdash': 1000,
  31489. 'AE': 1000,
  31490. 'ordfeminine': 370,
  31491. 'Lslash': 611,
  31492. 'Oslash': 778,
  31493. 'OE': 1000,
  31494. 'ordmasculine': 365,
  31495. 'ae': 889,
  31496. 'dotlessi': 278,
  31497. 'lslash': 278,
  31498. 'oslash': 611,
  31499. 'oe': 944,
  31500. 'germandbls': 611,
  31501. 'Idieresis': 278,
  31502. 'eacute': 556,
  31503. 'abreve': 556,
  31504. 'uhungarumlaut': 611,
  31505. 'ecaron': 556,
  31506. 'Ydieresis': 667,
  31507. 'divide': 584,
  31508. 'Yacute': 667,
  31509. 'Acircumflex': 722,
  31510. 'aacute': 556,
  31511. 'Ucircumflex': 722,
  31512. 'yacute': 556,
  31513. 'scommaaccent': 556,
  31514. 'ecircumflex': 556,
  31515. 'Uring': 722,
  31516. 'Udieresis': 722,
  31517. 'aogonek': 556,
  31518. 'Uacute': 722,
  31519. 'uogonek': 611,
  31520. 'Edieresis': 667,
  31521. 'Dcroat': 722,
  31522. 'commaaccent': 250,
  31523. 'copyright': 737,
  31524. 'Emacron': 667,
  31525. 'ccaron': 556,
  31526. 'aring': 556,
  31527. 'Ncommaaccent': 722,
  31528. 'lacute': 278,
  31529. 'agrave': 556,
  31530. 'Tcommaaccent': 611,
  31531. 'Cacute': 722,
  31532. 'atilde': 556,
  31533. 'Edotaccent': 667,
  31534. 'scaron': 556,
  31535. 'scedilla': 556,
  31536. 'iacute': 278,
  31537. 'lozenge': 494,
  31538. 'Rcaron': 722,
  31539. 'Gcommaaccent': 778,
  31540. 'ucircumflex': 611,
  31541. 'acircumflex': 556,
  31542. 'Amacron': 722,
  31543. 'rcaron': 389,
  31544. 'ccedilla': 556,
  31545. 'Zdotaccent': 611,
  31546. 'Thorn': 667,
  31547. 'Omacron': 778,
  31548. 'Racute': 722,
  31549. 'Sacute': 667,
  31550. 'dcaron': 743,
  31551. 'Umacron': 722,
  31552. 'uring': 611,
  31553. 'threesuperior': 333,
  31554. 'Ograve': 778,
  31555. 'Agrave': 722,
  31556. 'Abreve': 722,
  31557. 'multiply': 584,
  31558. 'uacute': 611,
  31559. 'Tcaron': 611,
  31560. 'partialdiff': 494,
  31561. 'ydieresis': 556,
  31562. 'Nacute': 722,
  31563. 'icircumflex': 278,
  31564. 'Ecircumflex': 667,
  31565. 'adieresis': 556,
  31566. 'edieresis': 556,
  31567. 'cacute': 556,
  31568. 'nacute': 611,
  31569. 'umacron': 611,
  31570. 'Ncaron': 722,
  31571. 'Iacute': 278,
  31572. 'plusminus': 584,
  31573. 'brokenbar': 280,
  31574. 'registered': 737,
  31575. 'Gbreve': 778,
  31576. 'Idotaccent': 278,
  31577. 'summation': 600,
  31578. 'Egrave': 667,
  31579. 'racute': 389,
  31580. 'omacron': 611,
  31581. 'Zacute': 611,
  31582. 'Zcaron': 611,
  31583. 'greaterequal': 549,
  31584. 'Eth': 722,
  31585. 'Ccedilla': 722,
  31586. 'lcommaaccent': 278,
  31587. 'tcaron': 389,
  31588. 'eogonek': 556,
  31589. 'Uogonek': 722,
  31590. 'Aacute': 722,
  31591. 'Adieresis': 722,
  31592. 'egrave': 556,
  31593. 'zacute': 500,
  31594. 'iogonek': 278,
  31595. 'Oacute': 778,
  31596. 'oacute': 611,
  31597. 'amacron': 556,
  31598. 'sacute': 556,
  31599. 'idieresis': 278,
  31600. 'Ocircumflex': 778,
  31601. 'Ugrave': 722,
  31602. 'Delta': 612,
  31603. 'thorn': 611,
  31604. 'twosuperior': 333,
  31605. 'Odieresis': 778,
  31606. 'mu': 611,
  31607. 'igrave': 278,
  31608. 'ohungarumlaut': 611,
  31609. 'Eogonek': 667,
  31610. 'dcroat': 611,
  31611. 'threequarters': 834,
  31612. 'Scedilla': 667,
  31613. 'lcaron': 400,
  31614. 'Kcommaaccent': 722,
  31615. 'Lacute': 611,
  31616. 'trademark': 1000,
  31617. 'edotaccent': 556,
  31618. 'Igrave': 278,
  31619. 'Imacron': 278,
  31620. 'Lcaron': 611,
  31621. 'onehalf': 834,
  31622. 'lessequal': 549,
  31623. 'ocircumflex': 611,
  31624. 'ntilde': 611,
  31625. 'Uhungarumlaut': 722,
  31626. 'Eacute': 667,
  31627. 'emacron': 556,
  31628. 'gbreve': 611,
  31629. 'onequarter': 834,
  31630. 'Scaron': 667,
  31631. 'Scommaaccent': 667,
  31632. 'Ohungarumlaut': 778,
  31633. 'degree': 400,
  31634. 'ograve': 611,
  31635. 'Ccaron': 722,
  31636. 'ugrave': 611,
  31637. 'radical': 549,
  31638. 'Dcaron': 722,
  31639. 'rcommaaccent': 389,
  31640. 'Ntilde': 722,
  31641. 'otilde': 611,
  31642. 'Rcommaaccent': 722,
  31643. 'Lcommaaccent': 611,
  31644. 'Atilde': 722,
  31645. 'Aogonek': 722,
  31646. 'Aring': 722,
  31647. 'Otilde': 778,
  31648. 'zdotaccent': 500,
  31649. 'Ecaron': 667,
  31650. 'Iogonek': 278,
  31651. 'kcommaaccent': 556,
  31652. 'minus': 584,
  31653. 'Icircumflex': 278,
  31654. 'ncaron': 611,
  31655. 'tcommaaccent': 333,
  31656. 'logicalnot': 584,
  31657. 'odieresis': 611,
  31658. 'udieresis': 611,
  31659. 'notequal': 549,
  31660. 'gcommaaccent': 611,
  31661. 'eth': 611,
  31662. 'zcaron': 500,
  31663. 'ncommaaccent': 611,
  31664. 'onesuperior': 333,
  31665. 'imacron': 278,
  31666. 'Euro': 556
  31667. },
  31668. 'Helvetica-BoldOblique': {
  31669. 'space': 278,
  31670. 'exclam': 333,
  31671. 'quotedbl': 474,
  31672. 'numbersign': 556,
  31673. 'dollar': 556,
  31674. 'percent': 889,
  31675. 'ampersand': 722,
  31676. 'quoteright': 278,
  31677. 'parenleft': 333,
  31678. 'parenright': 333,
  31679. 'asterisk': 389,
  31680. 'plus': 584,
  31681. 'comma': 278,
  31682. 'hyphen': 333,
  31683. 'period': 278,
  31684. 'slash': 278,
  31685. 'zero': 556,
  31686. 'one': 556,
  31687. 'two': 556,
  31688. 'three': 556,
  31689. 'four': 556,
  31690. 'five': 556,
  31691. 'six': 556,
  31692. 'seven': 556,
  31693. 'eight': 556,
  31694. 'nine': 556,
  31695. 'colon': 333,
  31696. 'semicolon': 333,
  31697. 'less': 584,
  31698. 'equal': 584,
  31699. 'greater': 584,
  31700. 'question': 611,
  31701. 'at': 975,
  31702. 'A': 722,
  31703. 'B': 722,
  31704. 'C': 722,
  31705. 'D': 722,
  31706. 'E': 667,
  31707. 'F': 611,
  31708. 'G': 778,
  31709. 'H': 722,
  31710. 'I': 278,
  31711. 'J': 556,
  31712. 'K': 722,
  31713. 'L': 611,
  31714. 'M': 833,
  31715. 'N': 722,
  31716. 'O': 778,
  31717. 'P': 667,
  31718. 'Q': 778,
  31719. 'R': 722,
  31720. 'S': 667,
  31721. 'T': 611,
  31722. 'U': 722,
  31723. 'V': 667,
  31724. 'W': 944,
  31725. 'X': 667,
  31726. 'Y': 667,
  31727. 'Z': 611,
  31728. 'bracketleft': 333,
  31729. 'backslash': 278,
  31730. 'bracketright': 333,
  31731. 'asciicircum': 584,
  31732. 'underscore': 556,
  31733. 'quoteleft': 278,
  31734. 'a': 556,
  31735. 'b': 611,
  31736. 'c': 556,
  31737. 'd': 611,
  31738. 'e': 556,
  31739. 'f': 333,
  31740. 'g': 611,
  31741. 'h': 611,
  31742. 'i': 278,
  31743. 'j': 278,
  31744. 'k': 556,
  31745. 'l': 278,
  31746. 'm': 889,
  31747. 'n': 611,
  31748. 'o': 611,
  31749. 'p': 611,
  31750. 'q': 611,
  31751. 'r': 389,
  31752. 's': 556,
  31753. 't': 333,
  31754. 'u': 611,
  31755. 'v': 556,
  31756. 'w': 778,
  31757. 'x': 556,
  31758. 'y': 556,
  31759. 'z': 500,
  31760. 'braceleft': 389,
  31761. 'bar': 280,
  31762. 'braceright': 389,
  31763. 'asciitilde': 584,
  31764. 'exclamdown': 333,
  31765. 'cent': 556,
  31766. 'sterling': 556,
  31767. 'fraction': 167,
  31768. 'yen': 556,
  31769. 'florin': 556,
  31770. 'section': 556,
  31771. 'currency': 556,
  31772. 'quotesingle': 238,
  31773. 'quotedblleft': 500,
  31774. 'guillemotleft': 556,
  31775. 'guilsinglleft': 333,
  31776. 'guilsinglright': 333,
  31777. 'fi': 611,
  31778. 'fl': 611,
  31779. 'endash': 556,
  31780. 'dagger': 556,
  31781. 'daggerdbl': 556,
  31782. 'periodcentered': 278,
  31783. 'paragraph': 556,
  31784. 'bullet': 350,
  31785. 'quotesinglbase': 278,
  31786. 'quotedblbase': 500,
  31787. 'quotedblright': 500,
  31788. 'guillemotright': 556,
  31789. 'ellipsis': 1000,
  31790. 'perthousand': 1000,
  31791. 'questiondown': 611,
  31792. 'grave': 333,
  31793. 'acute': 333,
  31794. 'circumflex': 333,
  31795. 'tilde': 333,
  31796. 'macron': 333,
  31797. 'breve': 333,
  31798. 'dotaccent': 333,
  31799. 'dieresis': 333,
  31800. 'ring': 333,
  31801. 'cedilla': 333,
  31802. 'hungarumlaut': 333,
  31803. 'ogonek': 333,
  31804. 'caron': 333,
  31805. 'emdash': 1000,
  31806. 'AE': 1000,
  31807. 'ordfeminine': 370,
  31808. 'Lslash': 611,
  31809. 'Oslash': 778,
  31810. 'OE': 1000,
  31811. 'ordmasculine': 365,
  31812. 'ae': 889,
  31813. 'dotlessi': 278,
  31814. 'lslash': 278,
  31815. 'oslash': 611,
  31816. 'oe': 944,
  31817. 'germandbls': 611,
  31818. 'Idieresis': 278,
  31819. 'eacute': 556,
  31820. 'abreve': 556,
  31821. 'uhungarumlaut': 611,
  31822. 'ecaron': 556,
  31823. 'Ydieresis': 667,
  31824. 'divide': 584,
  31825. 'Yacute': 667,
  31826. 'Acircumflex': 722,
  31827. 'aacute': 556,
  31828. 'Ucircumflex': 722,
  31829. 'yacute': 556,
  31830. 'scommaaccent': 556,
  31831. 'ecircumflex': 556,
  31832. 'Uring': 722,
  31833. 'Udieresis': 722,
  31834. 'aogonek': 556,
  31835. 'Uacute': 722,
  31836. 'uogonek': 611,
  31837. 'Edieresis': 667,
  31838. 'Dcroat': 722,
  31839. 'commaaccent': 250,
  31840. 'copyright': 737,
  31841. 'Emacron': 667,
  31842. 'ccaron': 556,
  31843. 'aring': 556,
  31844. 'Ncommaaccent': 722,
  31845. 'lacute': 278,
  31846. 'agrave': 556,
  31847. 'Tcommaaccent': 611,
  31848. 'Cacute': 722,
  31849. 'atilde': 556,
  31850. 'Edotaccent': 667,
  31851. 'scaron': 556,
  31852. 'scedilla': 556,
  31853. 'iacute': 278,
  31854. 'lozenge': 494,
  31855. 'Rcaron': 722,
  31856. 'Gcommaaccent': 778,
  31857. 'ucircumflex': 611,
  31858. 'acircumflex': 556,
  31859. 'Amacron': 722,
  31860. 'rcaron': 389,
  31861. 'ccedilla': 556,
  31862. 'Zdotaccent': 611,
  31863. 'Thorn': 667,
  31864. 'Omacron': 778,
  31865. 'Racute': 722,
  31866. 'Sacute': 667,
  31867. 'dcaron': 743,
  31868. 'Umacron': 722,
  31869. 'uring': 611,
  31870. 'threesuperior': 333,
  31871. 'Ograve': 778,
  31872. 'Agrave': 722,
  31873. 'Abreve': 722,
  31874. 'multiply': 584,
  31875. 'uacute': 611,
  31876. 'Tcaron': 611,
  31877. 'partialdiff': 494,
  31878. 'ydieresis': 556,
  31879. 'Nacute': 722,
  31880. 'icircumflex': 278,
  31881. 'Ecircumflex': 667,
  31882. 'adieresis': 556,
  31883. 'edieresis': 556,
  31884. 'cacute': 556,
  31885. 'nacute': 611,
  31886. 'umacron': 611,
  31887. 'Ncaron': 722,
  31888. 'Iacute': 278,
  31889. 'plusminus': 584,
  31890. 'brokenbar': 280,
  31891. 'registered': 737,
  31892. 'Gbreve': 778,
  31893. 'Idotaccent': 278,
  31894. 'summation': 600,
  31895. 'Egrave': 667,
  31896. 'racute': 389,
  31897. 'omacron': 611,
  31898. 'Zacute': 611,
  31899. 'Zcaron': 611,
  31900. 'greaterequal': 549,
  31901. 'Eth': 722,
  31902. 'Ccedilla': 722,
  31903. 'lcommaaccent': 278,
  31904. 'tcaron': 389,
  31905. 'eogonek': 556,
  31906. 'Uogonek': 722,
  31907. 'Aacute': 722,
  31908. 'Adieresis': 722,
  31909. 'egrave': 556,
  31910. 'zacute': 500,
  31911. 'iogonek': 278,
  31912. 'Oacute': 778,
  31913. 'oacute': 611,
  31914. 'amacron': 556,
  31915. 'sacute': 556,
  31916. 'idieresis': 278,
  31917. 'Ocircumflex': 778,
  31918. 'Ugrave': 722,
  31919. 'Delta': 612,
  31920. 'thorn': 611,
  31921. 'twosuperior': 333,
  31922. 'Odieresis': 778,
  31923. 'mu': 611,
  31924. 'igrave': 278,
  31925. 'ohungarumlaut': 611,
  31926. 'Eogonek': 667,
  31927. 'dcroat': 611,
  31928. 'threequarters': 834,
  31929. 'Scedilla': 667,
  31930. 'lcaron': 400,
  31931. 'Kcommaaccent': 722,
  31932. 'Lacute': 611,
  31933. 'trademark': 1000,
  31934. 'edotaccent': 556,
  31935. 'Igrave': 278,
  31936. 'Imacron': 278,
  31937. 'Lcaron': 611,
  31938. 'onehalf': 834,
  31939. 'lessequal': 549,
  31940. 'ocircumflex': 611,
  31941. 'ntilde': 611,
  31942. 'Uhungarumlaut': 722,
  31943. 'Eacute': 667,
  31944. 'emacron': 556,
  31945. 'gbreve': 611,
  31946. 'onequarter': 834,
  31947. 'Scaron': 667,
  31948. 'Scommaaccent': 667,
  31949. 'Ohungarumlaut': 778,
  31950. 'degree': 400,
  31951. 'ograve': 611,
  31952. 'Ccaron': 722,
  31953. 'ugrave': 611,
  31954. 'radical': 549,
  31955. 'Dcaron': 722,
  31956. 'rcommaaccent': 389,
  31957. 'Ntilde': 722,
  31958. 'otilde': 611,
  31959. 'Rcommaaccent': 722,
  31960. 'Lcommaaccent': 611,
  31961. 'Atilde': 722,
  31962. 'Aogonek': 722,
  31963. 'Aring': 722,
  31964. 'Otilde': 778,
  31965. 'zdotaccent': 500,
  31966. 'Ecaron': 667,
  31967. 'Iogonek': 278,
  31968. 'kcommaaccent': 556,
  31969. 'minus': 584,
  31970. 'Icircumflex': 278,
  31971. 'ncaron': 611,
  31972. 'tcommaaccent': 333,
  31973. 'logicalnot': 584,
  31974. 'odieresis': 611,
  31975. 'udieresis': 611,
  31976. 'notequal': 549,
  31977. 'gcommaaccent': 611,
  31978. 'eth': 611,
  31979. 'zcaron': 500,
  31980. 'ncommaaccent': 611,
  31981. 'onesuperior': 333,
  31982. 'imacron': 278,
  31983. 'Euro': 556
  31984. },
  31985. 'Helvetica-Oblique' : {
  31986. 'space': 278,
  31987. 'exclam': 278,
  31988. 'quotedbl': 355,
  31989. 'numbersign': 556,
  31990. 'dollar': 556,
  31991. 'percent': 889,
  31992. 'ampersand': 667,
  31993. 'quoteright': 222,
  31994. 'parenleft': 333,
  31995. 'parenright': 333,
  31996. 'asterisk': 389,
  31997. 'plus': 584,
  31998. 'comma': 278,
  31999. 'hyphen': 333,
  32000. 'period': 278,
  32001. 'slash': 278,
  32002. 'zero': 556,
  32003. 'one': 556,
  32004. 'two': 556,
  32005. 'three': 556,
  32006. 'four': 556,
  32007. 'five': 556,
  32008. 'six': 556,
  32009. 'seven': 556,
  32010. 'eight': 556,
  32011. 'nine': 556,
  32012. 'colon': 278,
  32013. 'semicolon': 278,
  32014. 'less': 584,
  32015. 'equal': 584,
  32016. 'greater': 584,
  32017. 'question': 556,
  32018. 'at': 1015,
  32019. 'A': 667,
  32020. 'B': 667,
  32021. 'C': 722,
  32022. 'D': 722,
  32023. 'E': 667,
  32024. 'F': 611,
  32025. 'G': 778,
  32026. 'H': 722,
  32027. 'I': 278,
  32028. 'J': 500,
  32029. 'K': 667,
  32030. 'L': 556,
  32031. 'M': 833,
  32032. 'N': 722,
  32033. 'O': 778,
  32034. 'P': 667,
  32035. 'Q': 778,
  32036. 'R': 722,
  32037. 'S': 667,
  32038. 'T': 611,
  32039. 'U': 722,
  32040. 'V': 667,
  32041. 'W': 944,
  32042. 'X': 667,
  32043. 'Y': 667,
  32044. 'Z': 611,
  32045. 'bracketleft': 278,
  32046. 'backslash': 278,
  32047. 'bracketright': 278,
  32048. 'asciicircum': 469,
  32049. 'underscore': 556,
  32050. 'quoteleft': 222,
  32051. 'a': 556,
  32052. 'b': 556,
  32053. 'c': 500,
  32054. 'd': 556,
  32055. 'e': 556,
  32056. 'f': 278,
  32057. 'g': 556,
  32058. 'h': 556,
  32059. 'i': 222,
  32060. 'j': 222,
  32061. 'k': 500,
  32062. 'l': 222,
  32063. 'm': 833,
  32064. 'n': 556,
  32065. 'o': 556,
  32066. 'p': 556,
  32067. 'q': 556,
  32068. 'r': 333,
  32069. 's': 500,
  32070. 't': 278,
  32071. 'u': 556,
  32072. 'v': 500,
  32073. 'w': 722,
  32074. 'x': 500,
  32075. 'y': 500,
  32076. 'z': 500,
  32077. 'braceleft': 334,
  32078. 'bar': 260,
  32079. 'braceright': 334,
  32080. 'asciitilde': 584,
  32081. 'exclamdown': 333,
  32082. 'cent': 556,
  32083. 'sterling': 556,
  32084. 'fraction': 167,
  32085. 'yen': 556,
  32086. 'florin': 556,
  32087. 'section': 556,
  32088. 'currency': 556,
  32089. 'quotesingle': 191,
  32090. 'quotedblleft': 333,
  32091. 'guillemotleft': 556,
  32092. 'guilsinglleft': 333,
  32093. 'guilsinglright': 333,
  32094. 'fi': 500,
  32095. 'fl': 500,
  32096. 'endash': 556,
  32097. 'dagger': 556,
  32098. 'daggerdbl': 556,
  32099. 'periodcentered': 278,
  32100. 'paragraph': 537,
  32101. 'bullet': 350,
  32102. 'quotesinglbase': 222,
  32103. 'quotedblbase': 333,
  32104. 'quotedblright': 333,
  32105. 'guillemotright': 556,
  32106. 'ellipsis': 1000,
  32107. 'perthousand': 1000,
  32108. 'questiondown': 611,
  32109. 'grave': 333,
  32110. 'acute': 333,
  32111. 'circumflex': 333,
  32112. 'tilde': 333,
  32113. 'macron': 333,
  32114. 'breve': 333,
  32115. 'dotaccent': 333,
  32116. 'dieresis': 333,
  32117. 'ring': 333,
  32118. 'cedilla': 333,
  32119. 'hungarumlaut': 333,
  32120. 'ogonek': 333,
  32121. 'caron': 333,
  32122. 'emdash': 1000,
  32123. 'AE': 1000,
  32124. 'ordfeminine': 370,
  32125. 'Lslash': 556,
  32126. 'Oslash': 778,
  32127. 'OE': 1000,
  32128. 'ordmasculine': 365,
  32129. 'ae': 889,
  32130. 'dotlessi': 278,
  32131. 'lslash': 222,
  32132. 'oslash': 611,
  32133. 'oe': 944,
  32134. 'germandbls': 611,
  32135. 'Idieresis': 278,
  32136. 'eacute': 556,
  32137. 'abreve': 556,
  32138. 'uhungarumlaut': 556,
  32139. 'ecaron': 556,
  32140. 'Ydieresis': 667,
  32141. 'divide': 584,
  32142. 'Yacute': 667,
  32143. 'Acircumflex': 667,
  32144. 'aacute': 556,
  32145. 'Ucircumflex': 722,
  32146. 'yacute': 500,
  32147. 'scommaaccent': 500,
  32148. 'ecircumflex': 556,
  32149. 'Uring': 722,
  32150. 'Udieresis': 722,
  32151. 'aogonek': 556,
  32152. 'Uacute': 722,
  32153. 'uogonek': 556,
  32154. 'Edieresis': 667,
  32155. 'Dcroat': 722,
  32156. 'commaaccent': 250,
  32157. 'copyright': 737,
  32158. 'Emacron': 667,
  32159. 'ccaron': 500,
  32160. 'aring': 556,
  32161. 'Ncommaaccent': 722,
  32162. 'lacute': 222,
  32163. 'agrave': 556,
  32164. 'Tcommaaccent': 611,
  32165. 'Cacute': 722,
  32166. 'atilde': 556,
  32167. 'Edotaccent': 667,
  32168. 'scaron': 500,
  32169. 'scedilla': 500,
  32170. 'iacute': 278,
  32171. 'lozenge': 471,
  32172. 'Rcaron': 722,
  32173. 'Gcommaaccent': 778,
  32174. 'ucircumflex': 556,
  32175. 'acircumflex': 556,
  32176. 'Amacron': 667,
  32177. 'rcaron': 333,
  32178. 'ccedilla': 500,
  32179. 'Zdotaccent': 611,
  32180. 'Thorn': 667,
  32181. 'Omacron': 778,
  32182. 'Racute': 722,
  32183. 'Sacute': 667,
  32184. 'dcaron': 643,
  32185. 'Umacron': 722,
  32186. 'uring': 556,
  32187. 'threesuperior': 333,
  32188. 'Ograve': 778,
  32189. 'Agrave': 667,
  32190. 'Abreve': 667,
  32191. 'multiply': 584,
  32192. 'uacute': 556,
  32193. 'Tcaron': 611,
  32194. 'partialdiff': 476,
  32195. 'ydieresis': 500,
  32196. 'Nacute': 722,
  32197. 'icircumflex': 278,
  32198. 'Ecircumflex': 667,
  32199. 'adieresis': 556,
  32200. 'edieresis': 556,
  32201. 'cacute': 500,
  32202. 'nacute': 556,
  32203. 'umacron': 556,
  32204. 'Ncaron': 722,
  32205. 'Iacute': 278,
  32206. 'plusminus': 584,
  32207. 'brokenbar': 260,
  32208. 'registered': 737,
  32209. 'Gbreve': 778,
  32210. 'Idotaccent': 278,
  32211. 'summation': 600,
  32212. 'Egrave': 667,
  32213. 'racute': 333,
  32214. 'omacron': 556,
  32215. 'Zacute': 611,
  32216. 'Zcaron': 611,
  32217. 'greaterequal': 549,
  32218. 'Eth': 722,
  32219. 'Ccedilla': 722,
  32220. 'lcommaaccent': 222,
  32221. 'tcaron': 317,
  32222. 'eogonek': 556,
  32223. 'Uogonek': 722,
  32224. 'Aacute': 667,
  32225. 'Adieresis': 667,
  32226. 'egrave': 556,
  32227. 'zacute': 500,
  32228. 'iogonek': 222,
  32229. 'Oacute': 778,
  32230. 'oacute': 556,
  32231. 'amacron': 556,
  32232. 'sacute': 500,
  32233. 'idieresis': 278,
  32234. 'Ocircumflex': 778,
  32235. 'Ugrave': 722,
  32236. 'Delta': 612,
  32237. 'thorn': 556,
  32238. 'twosuperior': 333,
  32239. 'Odieresis': 778,
  32240. 'mu': 556,
  32241. 'igrave': 278,
  32242. 'ohungarumlaut': 556,
  32243. 'Eogonek': 667,
  32244. 'dcroat': 556,
  32245. 'threequarters': 834,
  32246. 'Scedilla': 667,
  32247. 'lcaron': 299,
  32248. 'Kcommaaccent': 667,
  32249. 'Lacute': 556,
  32250. 'trademark': 1000,
  32251. 'edotaccent': 556,
  32252. 'Igrave': 278,
  32253. 'Imacron': 278,
  32254. 'Lcaron': 556,
  32255. 'onehalf': 834,
  32256. 'lessequal': 549,
  32257. 'ocircumflex': 556,
  32258. 'ntilde': 556,
  32259. 'Uhungarumlaut': 722,
  32260. 'Eacute': 667,
  32261. 'emacron': 556,
  32262. 'gbreve': 556,
  32263. 'onequarter': 834,
  32264. 'Scaron': 667,
  32265. 'Scommaaccent': 667,
  32266. 'Ohungarumlaut': 778,
  32267. 'degree': 400,
  32268. 'ograve': 556,
  32269. 'Ccaron': 722,
  32270. 'ugrave': 556,
  32271. 'radical': 453,
  32272. 'Dcaron': 722,
  32273. 'rcommaaccent': 333,
  32274. 'Ntilde': 722,
  32275. 'otilde': 556,
  32276. 'Rcommaaccent': 722,
  32277. 'Lcommaaccent': 556,
  32278. 'Atilde': 667,
  32279. 'Aogonek': 667,
  32280. 'Aring': 667,
  32281. 'Otilde': 778,
  32282. 'zdotaccent': 500,
  32283. 'Ecaron': 667,
  32284. 'Iogonek': 278,
  32285. 'kcommaaccent': 500,
  32286. 'minus': 584,
  32287. 'Icircumflex': 278,
  32288. 'ncaron': 556,
  32289. 'tcommaaccent': 278,
  32290. 'logicalnot': 584,
  32291. 'odieresis': 556,
  32292. 'udieresis': 556,
  32293. 'notequal': 549,
  32294. 'gcommaaccent': 556,
  32295. 'eth': 556,
  32296. 'zcaron': 500,
  32297. 'ncommaaccent': 556,
  32298. 'onesuperior': 333,
  32299. 'imacron': 278,
  32300. 'Euro': 556
  32301. },
  32302. 'Symbol': {
  32303. 'space': 250,
  32304. 'exclam': 333,
  32305. 'universal': 713,
  32306. 'numbersign': 500,
  32307. 'existential': 549,
  32308. 'percent': 833,
  32309. 'ampersand': 778,
  32310. 'suchthat': 439,
  32311. 'parenleft': 333,
  32312. 'parenright': 333,
  32313. 'asteriskmath': 500,
  32314. 'plus': 549,
  32315. 'comma': 250,
  32316. 'minus': 549,
  32317. 'period': 250,
  32318. 'slash': 278,
  32319. 'zero': 500,
  32320. 'one': 500,
  32321. 'two': 500,
  32322. 'three': 500,
  32323. 'four': 500,
  32324. 'five': 500,
  32325. 'six': 500,
  32326. 'seven': 500,
  32327. 'eight': 500,
  32328. 'nine': 500,
  32329. 'colon': 278,
  32330. 'semicolon': 278,
  32331. 'less': 549,
  32332. 'equal': 549,
  32333. 'greater': 549,
  32334. 'question': 444,
  32335. 'congruent': 549,
  32336. 'Alpha': 722,
  32337. 'Beta': 667,
  32338. 'Chi': 722,
  32339. 'Delta': 612,
  32340. 'Epsilon': 611,
  32341. 'Phi': 763,
  32342. 'Gamma': 603,
  32343. 'Eta': 722,
  32344. 'Iota': 333,
  32345. 'theta1': 631,
  32346. 'Kappa': 722,
  32347. 'Lambda': 686,
  32348. 'Mu': 889,
  32349. 'Nu': 722,
  32350. 'Omicron': 722,
  32351. 'Pi': 768,
  32352. 'Theta': 741,
  32353. 'Rho': 556,
  32354. 'Sigma': 592,
  32355. 'Tau': 611,
  32356. 'Upsilon': 690,
  32357. 'sigma1': 439,
  32358. 'Omega': 768,
  32359. 'Xi': 645,
  32360. 'Psi': 795,
  32361. 'Zeta': 611,
  32362. 'bracketleft': 333,
  32363. 'therefore': 863,
  32364. 'bracketright': 333,
  32365. 'perpendicular': 658,
  32366. 'underscore': 500,
  32367. 'radicalex': 500,
  32368. 'alpha': 631,
  32369. 'beta': 549,
  32370. 'chi': 549,
  32371. 'delta': 494,
  32372. 'epsilon': 439,
  32373. 'phi': 521,
  32374. 'gamma': 411,
  32375. 'eta': 603,
  32376. 'iota': 329,
  32377. 'phi1': 603,
  32378. 'kappa': 549,
  32379. 'lambda': 549,
  32380. 'mu': 576,
  32381. 'nu': 521,
  32382. 'omicron': 549,
  32383. 'pi': 549,
  32384. 'theta': 521,
  32385. 'rho': 549,
  32386. 'sigma': 603,
  32387. 'tau': 439,
  32388. 'upsilon': 576,
  32389. 'omega1': 713,
  32390. 'omega': 686,
  32391. 'xi': 493,
  32392. 'psi': 686,
  32393. 'zeta': 494,
  32394. 'braceleft': 480,
  32395. 'bar': 200,
  32396. 'braceright': 480,
  32397. 'similar': 549,
  32398. 'Euro': 750,
  32399. 'Upsilon1': 620,
  32400. 'minute': 247,
  32401. 'lessequal': 549,
  32402. 'fraction': 167,
  32403. 'infinity': 713,
  32404. 'florin': 500,
  32405. 'club': 753,
  32406. 'diamond': 753,
  32407. 'heart': 753,
  32408. 'spade': 753,
  32409. 'arrowboth': 1042,
  32410. 'arrowleft': 987,
  32411. 'arrowup': 603,
  32412. 'arrowright': 987,
  32413. 'arrowdown': 603,
  32414. 'degree': 400,
  32415. 'plusminus': 549,
  32416. 'second': 411,
  32417. 'greaterequal': 549,
  32418. 'multiply': 549,
  32419. 'proportional': 713,
  32420. 'partialdiff': 494,
  32421. 'bullet': 460,
  32422. 'divide': 549,
  32423. 'notequal': 549,
  32424. 'equivalence': 549,
  32425. 'approxequal': 549,
  32426. 'ellipsis': 1000,
  32427. 'arrowvertex': 603,
  32428. 'arrowhorizex': 1000,
  32429. 'carriagereturn': 658,
  32430. 'aleph': 823,
  32431. 'Ifraktur': 686,
  32432. 'Rfraktur': 795,
  32433. 'weierstrass': 987,
  32434. 'circlemultiply': 768,
  32435. 'circleplus': 768,
  32436. 'emptyset': 823,
  32437. 'intersection': 768,
  32438. 'union': 768,
  32439. 'propersuperset': 713,
  32440. 'reflexsuperset': 713,
  32441. 'notsubset': 713,
  32442. 'propersubset': 713,
  32443. 'reflexsubset': 713,
  32444. 'element': 713,
  32445. 'notelement': 713,
  32446. 'angle': 768,
  32447. 'gradient': 713,
  32448. 'registerserif': 790,
  32449. 'copyrightserif': 790,
  32450. 'trademarkserif': 890,
  32451. 'product': 823,
  32452. 'radical': 549,
  32453. 'dotmath': 250,
  32454. 'logicalnot': 713,
  32455. 'logicaland': 603,
  32456. 'logicalor': 603,
  32457. 'arrowdblboth': 1042,
  32458. 'arrowdblleft': 987,
  32459. 'arrowdblup': 603,
  32460. 'arrowdblright': 987,
  32461. 'arrowdbldown': 603,
  32462. 'lozenge': 494,
  32463. 'angleleft': 329,
  32464. 'registersans': 790,
  32465. 'copyrightsans': 790,
  32466. 'trademarksans': 786,
  32467. 'summation': 713,
  32468. 'parenlefttp': 384,
  32469. 'parenleftex': 384,
  32470. 'parenleftbt': 384,
  32471. 'bracketlefttp': 384,
  32472. 'bracketleftex': 384,
  32473. 'bracketleftbt': 384,
  32474. 'bracelefttp': 494,
  32475. 'braceleftmid': 494,
  32476. 'braceleftbt': 494,
  32477. 'braceex': 494,
  32478. 'angleright': 329,
  32479. 'integral': 274,
  32480. 'integraltp': 686,
  32481. 'integralex': 686,
  32482. 'integralbt': 686,
  32483. 'parenrighttp': 384,
  32484. 'parenrightex': 384,
  32485. 'parenrightbt': 384,
  32486. 'bracketrighttp': 384,
  32487. 'bracketrightex': 384,
  32488. 'bracketrightbt': 384,
  32489. 'bracerighttp': 494,
  32490. 'bracerightmid': 494,
  32491. 'bracerightbt': 494,
  32492. 'apple': 790
  32493. },
  32494. 'Times-Roman': {
  32495. 'space': 250,
  32496. 'exclam': 333,
  32497. 'quotedbl': 408,
  32498. 'numbersign': 500,
  32499. 'dollar': 500,
  32500. 'percent': 833,
  32501. 'ampersand': 778,
  32502. 'quoteright': 333,
  32503. 'parenleft': 333,
  32504. 'parenright': 333,
  32505. 'asterisk': 500,
  32506. 'plus': 564,
  32507. 'comma': 250,
  32508. 'hyphen': 333,
  32509. 'period': 250,
  32510. 'slash': 278,
  32511. 'zero': 500,
  32512. 'one': 500,
  32513. 'two': 500,
  32514. 'three': 500,
  32515. 'four': 500,
  32516. 'five': 500,
  32517. 'six': 500,
  32518. 'seven': 500,
  32519. 'eight': 500,
  32520. 'nine': 500,
  32521. 'colon': 278,
  32522. 'semicolon': 278,
  32523. 'less': 564,
  32524. 'equal': 564,
  32525. 'greater': 564,
  32526. 'question': 444,
  32527. 'at': 921,
  32528. 'A': 722,
  32529. 'B': 667,
  32530. 'C': 667,
  32531. 'D': 722,
  32532. 'E': 611,
  32533. 'F': 556,
  32534. 'G': 722,
  32535. 'H': 722,
  32536. 'I': 333,
  32537. 'J': 389,
  32538. 'K': 722,
  32539. 'L': 611,
  32540. 'M': 889,
  32541. 'N': 722,
  32542. 'O': 722,
  32543. 'P': 556,
  32544. 'Q': 722,
  32545. 'R': 667,
  32546. 'S': 556,
  32547. 'T': 611,
  32548. 'U': 722,
  32549. 'V': 722,
  32550. 'W': 944,
  32551. 'X': 722,
  32552. 'Y': 722,
  32553. 'Z': 611,
  32554. 'bracketleft': 333,
  32555. 'backslash': 278,
  32556. 'bracketright': 333,
  32557. 'asciicircum': 469,
  32558. 'underscore': 500,
  32559. 'quoteleft': 333,
  32560. 'a': 444,
  32561. 'b': 500,
  32562. 'c': 444,
  32563. 'd': 500,
  32564. 'e': 444,
  32565. 'f': 333,
  32566. 'g': 500,
  32567. 'h': 500,
  32568. 'i': 278,
  32569. 'j': 278,
  32570. 'k': 500,
  32571. 'l': 278,
  32572. 'm': 778,
  32573. 'n': 500,
  32574. 'o': 500,
  32575. 'p': 500,
  32576. 'q': 500,
  32577. 'r': 333,
  32578. 's': 389,
  32579. 't': 278,
  32580. 'u': 500,
  32581. 'v': 500,
  32582. 'w': 722,
  32583. 'x': 500,
  32584. 'y': 500,
  32585. 'z': 444,
  32586. 'braceleft': 480,
  32587. 'bar': 200,
  32588. 'braceright': 480,
  32589. 'asciitilde': 541,
  32590. 'exclamdown': 333,
  32591. 'cent': 500,
  32592. 'sterling': 500,
  32593. 'fraction': 167,
  32594. 'yen': 500,
  32595. 'florin': 500,
  32596. 'section': 500,
  32597. 'currency': 500,
  32598. 'quotesingle': 180,
  32599. 'quotedblleft': 444,
  32600. 'guillemotleft': 500,
  32601. 'guilsinglleft': 333,
  32602. 'guilsinglright': 333,
  32603. 'fi': 556,
  32604. 'fl': 556,
  32605. 'endash': 500,
  32606. 'dagger': 500,
  32607. 'daggerdbl': 500,
  32608. 'periodcentered': 250,
  32609. 'paragraph': 453,
  32610. 'bullet': 350,
  32611. 'quotesinglbase': 333,
  32612. 'quotedblbase': 444,
  32613. 'quotedblright': 444,
  32614. 'guillemotright': 500,
  32615. 'ellipsis': 1000,
  32616. 'perthousand': 1000,
  32617. 'questiondown': 444,
  32618. 'grave': 333,
  32619. 'acute': 333,
  32620. 'circumflex': 333,
  32621. 'tilde': 333,
  32622. 'macron': 333,
  32623. 'breve': 333,
  32624. 'dotaccent': 333,
  32625. 'dieresis': 333,
  32626. 'ring': 333,
  32627. 'cedilla': 333,
  32628. 'hungarumlaut': 333,
  32629. 'ogonek': 333,
  32630. 'caron': 333,
  32631. 'emdash': 1000,
  32632. 'AE': 889,
  32633. 'ordfeminine': 276,
  32634. 'Lslash': 611,
  32635. 'Oslash': 722,
  32636. 'OE': 889,
  32637. 'ordmasculine': 310,
  32638. 'ae': 667,
  32639. 'dotlessi': 278,
  32640. 'lslash': 278,
  32641. 'oslash': 500,
  32642. 'oe': 722,
  32643. 'germandbls': 500,
  32644. 'Idieresis': 333,
  32645. 'eacute': 444,
  32646. 'abreve': 444,
  32647. 'uhungarumlaut': 500,
  32648. 'ecaron': 444,
  32649. 'Ydieresis': 722,
  32650. 'divide': 564,
  32651. 'Yacute': 722,
  32652. 'Acircumflex': 722,
  32653. 'aacute': 444,
  32654. 'Ucircumflex': 722,
  32655. 'yacute': 500,
  32656. 'scommaaccent': 389,
  32657. 'ecircumflex': 444,
  32658. 'Uring': 722,
  32659. 'Udieresis': 722,
  32660. 'aogonek': 444,
  32661. 'Uacute': 722,
  32662. 'uogonek': 500,
  32663. 'Edieresis': 611,
  32664. 'Dcroat': 722,
  32665. 'commaaccent': 250,
  32666. 'copyright': 760,
  32667. 'Emacron': 611,
  32668. 'ccaron': 444,
  32669. 'aring': 444,
  32670. 'Ncommaaccent': 722,
  32671. 'lacute': 278,
  32672. 'agrave': 444,
  32673. 'Tcommaaccent': 611,
  32674. 'Cacute': 667,
  32675. 'atilde': 444,
  32676. 'Edotaccent': 611,
  32677. 'scaron': 389,
  32678. 'scedilla': 389,
  32679. 'iacute': 278,
  32680. 'lozenge': 471,
  32681. 'Rcaron': 667,
  32682. 'Gcommaaccent': 722,
  32683. 'ucircumflex': 500,
  32684. 'acircumflex': 444,
  32685. 'Amacron': 722,
  32686. 'rcaron': 333,
  32687. 'ccedilla': 444,
  32688. 'Zdotaccent': 611,
  32689. 'Thorn': 556,
  32690. 'Omacron': 722,
  32691. 'Racute': 667,
  32692. 'Sacute': 556,
  32693. 'dcaron': 588,
  32694. 'Umacron': 722,
  32695. 'uring': 500,
  32696. 'threesuperior': 300,
  32697. 'Ograve': 722,
  32698. 'Agrave': 722,
  32699. 'Abreve': 722,
  32700. 'multiply': 564,
  32701. 'uacute': 500,
  32702. 'Tcaron': 611,
  32703. 'partialdiff': 476,
  32704. 'ydieresis': 500,
  32705. 'Nacute': 722,
  32706. 'icircumflex': 278,
  32707. 'Ecircumflex': 611,
  32708. 'adieresis': 444,
  32709. 'edieresis': 444,
  32710. 'cacute': 444,
  32711. 'nacute': 500,
  32712. 'umacron': 500,
  32713. 'Ncaron': 722,
  32714. 'Iacute': 333,
  32715. 'plusminus': 564,
  32716. 'brokenbar': 200,
  32717. 'registered': 760,
  32718. 'Gbreve': 722,
  32719. 'Idotaccent': 333,
  32720. 'summation': 600,
  32721. 'Egrave': 611,
  32722. 'racute': 333,
  32723. 'omacron': 500,
  32724. 'Zacute': 611,
  32725. 'Zcaron': 611,
  32726. 'greaterequal': 549,
  32727. 'Eth': 722,
  32728. 'Ccedilla': 667,
  32729. 'lcommaaccent': 278,
  32730. 'tcaron': 326,
  32731. 'eogonek': 444,
  32732. 'Uogonek': 722,
  32733. 'Aacute': 722,
  32734. 'Adieresis': 722,
  32735. 'egrave': 444,
  32736. 'zacute': 444,
  32737. 'iogonek': 278,
  32738. 'Oacute': 722,
  32739. 'oacute': 500,
  32740. 'amacron': 444,
  32741. 'sacute': 389,
  32742. 'idieresis': 278,
  32743. 'Ocircumflex': 722,
  32744. 'Ugrave': 722,
  32745. 'Delta': 612,
  32746. 'thorn': 500,
  32747. 'twosuperior': 300,
  32748. 'Odieresis': 722,
  32749. 'mu': 500,
  32750. 'igrave': 278,
  32751. 'ohungarumlaut': 500,
  32752. 'Eogonek': 611,
  32753. 'dcroat': 500,
  32754. 'threequarters': 750,
  32755. 'Scedilla': 556,
  32756. 'lcaron': 344,
  32757. 'Kcommaaccent': 722,
  32758. 'Lacute': 611,
  32759. 'trademark': 980,
  32760. 'edotaccent': 444,
  32761. 'Igrave': 333,
  32762. 'Imacron': 333,
  32763. 'Lcaron': 611,
  32764. 'onehalf': 750,
  32765. 'lessequal': 549,
  32766. 'ocircumflex': 500,
  32767. 'ntilde': 500,
  32768. 'Uhungarumlaut': 722,
  32769. 'Eacute': 611,
  32770. 'emacron': 444,
  32771. 'gbreve': 500,
  32772. 'onequarter': 750,
  32773. 'Scaron': 556,
  32774. 'Scommaaccent': 556,
  32775. 'Ohungarumlaut': 722,
  32776. 'degree': 400,
  32777. 'ograve': 500,
  32778. 'Ccaron': 667,
  32779. 'ugrave': 500,
  32780. 'radical': 453,
  32781. 'Dcaron': 722,
  32782. 'rcommaaccent': 333,
  32783. 'Ntilde': 722,
  32784. 'otilde': 500,
  32785. 'Rcommaaccent': 667,
  32786. 'Lcommaaccent': 611,
  32787. 'Atilde': 722,
  32788. 'Aogonek': 722,
  32789. 'Aring': 722,
  32790. 'Otilde': 722,
  32791. 'zdotaccent': 444,
  32792. 'Ecaron': 611,
  32793. 'Iogonek': 333,
  32794. 'kcommaaccent': 500,
  32795. 'minus': 564,
  32796. 'Icircumflex': 333,
  32797. 'ncaron': 500,
  32798. 'tcommaaccent': 278,
  32799. 'logicalnot': 564,
  32800. 'odieresis': 500,
  32801. 'udieresis': 500,
  32802. 'notequal': 549,
  32803. 'gcommaaccent': 500,
  32804. 'eth': 500,
  32805. 'zcaron': 444,
  32806. 'ncommaaccent': 500,
  32807. 'onesuperior': 300,
  32808. 'imacron': 278,
  32809. 'Euro': 500
  32810. },
  32811. 'Times-Bold': {
  32812. 'space': 250,
  32813. 'exclam': 333,
  32814. 'quotedbl': 555,
  32815. 'numbersign': 500,
  32816. 'dollar': 500,
  32817. 'percent': 1000,
  32818. 'ampersand': 833,
  32819. 'quoteright': 333,
  32820. 'parenleft': 333,
  32821. 'parenright': 333,
  32822. 'asterisk': 500,
  32823. 'plus': 570,
  32824. 'comma': 250,
  32825. 'hyphen': 333,
  32826. 'period': 250,
  32827. 'slash': 278,
  32828. 'zero': 500,
  32829. 'one': 500,
  32830. 'two': 500,
  32831. 'three': 500,
  32832. 'four': 500,
  32833. 'five': 500,
  32834. 'six': 500,
  32835. 'seven': 500,
  32836. 'eight': 500,
  32837. 'nine': 500,
  32838. 'colon': 333,
  32839. 'semicolon': 333,
  32840. 'less': 570,
  32841. 'equal': 570,
  32842. 'greater': 570,
  32843. 'question': 500,
  32844. 'at': 930,
  32845. 'A': 722,
  32846. 'B': 667,
  32847. 'C': 722,
  32848. 'D': 722,
  32849. 'E': 667,
  32850. 'F': 611,
  32851. 'G': 778,
  32852. 'H': 778,
  32853. 'I': 389,
  32854. 'J': 500,
  32855. 'K': 778,
  32856. 'L': 667,
  32857. 'M': 944,
  32858. 'N': 722,
  32859. 'O': 778,
  32860. 'P': 611,
  32861. 'Q': 778,
  32862. 'R': 722,
  32863. 'S': 556,
  32864. 'T': 667,
  32865. 'U': 722,
  32866. 'V': 722,
  32867. 'W': 1000,
  32868. 'X': 722,
  32869. 'Y': 722,
  32870. 'Z': 667,
  32871. 'bracketleft': 333,
  32872. 'backslash': 278,
  32873. 'bracketright': 333,
  32874. 'asciicircum': 581,
  32875. 'underscore': 500,
  32876. 'quoteleft': 333,
  32877. 'a': 500,
  32878. 'b': 556,
  32879. 'c': 444,
  32880. 'd': 556,
  32881. 'e': 444,
  32882. 'f': 333,
  32883. 'g': 500,
  32884. 'h': 556,
  32885. 'i': 278,
  32886. 'j': 333,
  32887. 'k': 556,
  32888. 'l': 278,
  32889. 'm': 833,
  32890. 'n': 556,
  32891. 'o': 500,
  32892. 'p': 556,
  32893. 'q': 556,
  32894. 'r': 444,
  32895. 's': 389,
  32896. 't': 333,
  32897. 'u': 556,
  32898. 'v': 500,
  32899. 'w': 722,
  32900. 'x': 500,
  32901. 'y': 500,
  32902. 'z': 444,
  32903. 'braceleft': 394,
  32904. 'bar': 220,
  32905. 'braceright': 394,
  32906. 'asciitilde': 520,
  32907. 'exclamdown': 333,
  32908. 'cent': 500,
  32909. 'sterling': 500,
  32910. 'fraction': 167,
  32911. 'yen': 500,
  32912. 'florin': 500,
  32913. 'section': 500,
  32914. 'currency': 500,
  32915. 'quotesingle': 278,
  32916. 'quotedblleft': 500,
  32917. 'guillemotleft': 500,
  32918. 'guilsinglleft': 333,
  32919. 'guilsinglright': 333,
  32920. 'fi': 556,
  32921. 'fl': 556,
  32922. 'endash': 500,
  32923. 'dagger': 500,
  32924. 'daggerdbl': 500,
  32925. 'periodcentered': 250,
  32926. 'paragraph': 540,
  32927. 'bullet': 350,
  32928. 'quotesinglbase': 333,
  32929. 'quotedblbase': 500,
  32930. 'quotedblright': 500,
  32931. 'guillemotright': 500,
  32932. 'ellipsis': 1000,
  32933. 'perthousand': 1000,
  32934. 'questiondown': 500,
  32935. 'grave': 333,
  32936. 'acute': 333,
  32937. 'circumflex': 333,
  32938. 'tilde': 333,
  32939. 'macron': 333,
  32940. 'breve': 333,
  32941. 'dotaccent': 333,
  32942. 'dieresis': 333,
  32943. 'ring': 333,
  32944. 'cedilla': 333,
  32945. 'hungarumlaut': 333,
  32946. 'ogonek': 333,
  32947. 'caron': 333,
  32948. 'emdash': 1000,
  32949. 'AE': 1000,
  32950. 'ordfeminine': 300,
  32951. 'Lslash': 667,
  32952. 'Oslash': 778,
  32953. 'OE': 1000,
  32954. 'ordmasculine': 330,
  32955. 'ae': 722,
  32956. 'dotlessi': 278,
  32957. 'lslash': 278,
  32958. 'oslash': 500,
  32959. 'oe': 722,
  32960. 'germandbls': 556,
  32961. 'Idieresis': 389,
  32962. 'eacute': 444,
  32963. 'abreve': 500,
  32964. 'uhungarumlaut': 556,
  32965. 'ecaron': 444,
  32966. 'Ydieresis': 722,
  32967. 'divide': 570,
  32968. 'Yacute': 722,
  32969. 'Acircumflex': 722,
  32970. 'aacute': 500,
  32971. 'Ucircumflex': 722,
  32972. 'yacute': 500,
  32973. 'scommaaccent': 389,
  32974. 'ecircumflex': 444,
  32975. 'Uring': 722,
  32976. 'Udieresis': 722,
  32977. 'aogonek': 500,
  32978. 'Uacute': 722,
  32979. 'uogonek': 556,
  32980. 'Edieresis': 667,
  32981. 'Dcroat': 722,
  32982. 'commaaccent': 250,
  32983. 'copyright': 747,
  32984. 'Emacron': 667,
  32985. 'ccaron': 444,
  32986. 'aring': 500,
  32987. 'Ncommaaccent': 722,
  32988. 'lacute': 278,
  32989. 'agrave': 500,
  32990. 'Tcommaaccent': 667,
  32991. 'Cacute': 722,
  32992. 'atilde': 500,
  32993. 'Edotaccent': 667,
  32994. 'scaron': 389,
  32995. 'scedilla': 389,
  32996. 'iacute': 278,
  32997. 'lozenge': 494,
  32998. 'Rcaron': 722,
  32999. 'Gcommaaccent': 778,
  33000. 'ucircumflex': 556,
  33001. 'acircumflex': 500,
  33002. 'Amacron': 722,
  33003. 'rcaron': 444,
  33004. 'ccedilla': 444,
  33005. 'Zdotaccent': 667,
  33006. 'Thorn': 611,
  33007. 'Omacron': 778,
  33008. 'Racute': 722,
  33009. 'Sacute': 556,
  33010. 'dcaron': 672,
  33011. 'Umacron': 722,
  33012. 'uring': 556,
  33013. 'threesuperior': 300,
  33014. 'Ograve': 778,
  33015. 'Agrave': 722,
  33016. 'Abreve': 722,
  33017. 'multiply': 570,
  33018. 'uacute': 556,
  33019. 'Tcaron': 667,
  33020. 'partialdiff': 494,
  33021. 'ydieresis': 500,
  33022. 'Nacute': 722,
  33023. 'icircumflex': 278,
  33024. 'Ecircumflex': 667,
  33025. 'adieresis': 500,
  33026. 'edieresis': 444,
  33027. 'cacute': 444,
  33028. 'nacute': 556,
  33029. 'umacron': 556,
  33030. 'Ncaron': 722,
  33031. 'Iacute': 389,
  33032. 'plusminus': 570,
  33033. 'brokenbar': 220,
  33034. 'registered': 747,
  33035. 'Gbreve': 778,
  33036. 'Idotaccent': 389,
  33037. 'summation': 600,
  33038. 'Egrave': 667,
  33039. 'racute': 444,
  33040. 'omacron': 500,
  33041. 'Zacute': 667,
  33042. 'Zcaron': 667,
  33043. 'greaterequal': 549,
  33044. 'Eth': 722,
  33045. 'Ccedilla': 722,
  33046. 'lcommaaccent': 278,
  33047. 'tcaron': 416,
  33048. 'eogonek': 444,
  33049. 'Uogonek': 722,
  33050. 'Aacute': 722,
  33051. 'Adieresis': 722,
  33052. 'egrave': 444,
  33053. 'zacute': 444,
  33054. 'iogonek': 278,
  33055. 'Oacute': 778,
  33056. 'oacute': 500,
  33057. 'amacron': 500,
  33058. 'sacute': 389,
  33059. 'idieresis': 278,
  33060. 'Ocircumflex': 778,
  33061. 'Ugrave': 722,
  33062. 'Delta': 612,
  33063. 'thorn': 556,
  33064. 'twosuperior': 300,
  33065. 'Odieresis': 778,
  33066. 'mu': 556,
  33067. 'igrave': 278,
  33068. 'ohungarumlaut': 500,
  33069. 'Eogonek': 667,
  33070. 'dcroat': 556,
  33071. 'threequarters': 750,
  33072. 'Scedilla': 556,
  33073. 'lcaron': 394,
  33074. 'Kcommaaccent': 778,
  33075. 'Lacute': 667,
  33076. 'trademark': 1000,
  33077. 'edotaccent': 444,
  33078. 'Igrave': 389,
  33079. 'Imacron': 389,
  33080. 'Lcaron': 667,
  33081. 'onehalf': 750,
  33082. 'lessequal': 549,
  33083. 'ocircumflex': 500,
  33084. 'ntilde': 556,
  33085. 'Uhungarumlaut': 722,
  33086. 'Eacute': 667,
  33087. 'emacron': 444,
  33088. 'gbreve': 500,
  33089. 'onequarter': 750,
  33090. 'Scaron': 556,
  33091. 'Scommaaccent': 556,
  33092. 'Ohungarumlaut': 778,
  33093. 'degree': 400,
  33094. 'ograve': 500,
  33095. 'Ccaron': 722,
  33096. 'ugrave': 556,
  33097. 'radical': 549,
  33098. 'Dcaron': 722,
  33099. 'rcommaaccent': 444,
  33100. 'Ntilde': 722,
  33101. 'otilde': 500,
  33102. 'Rcommaaccent': 722,
  33103. 'Lcommaaccent': 667,
  33104. 'Atilde': 722,
  33105. 'Aogonek': 722,
  33106. 'Aring': 722,
  33107. 'Otilde': 778,
  33108. 'zdotaccent': 444,
  33109. 'Ecaron': 667,
  33110. 'Iogonek': 389,
  33111. 'kcommaaccent': 556,
  33112. 'minus': 570,
  33113. 'Icircumflex': 389,
  33114. 'ncaron': 556,
  33115. 'tcommaaccent': 333,
  33116. 'logicalnot': 570,
  33117. 'odieresis': 500,
  33118. 'udieresis': 556,
  33119. 'notequal': 549,
  33120. 'gcommaaccent': 500,
  33121. 'eth': 500,
  33122. 'zcaron': 444,
  33123. 'ncommaaccent': 556,
  33124. 'onesuperior': 300,
  33125. 'imacron': 278,
  33126. 'Euro': 500
  33127. },
  33128. 'Times-BoldItalic': {
  33129. 'space': 250,
  33130. 'exclam': 389,
  33131. 'quotedbl': 555,
  33132. 'numbersign': 500,
  33133. 'dollar': 500,
  33134. 'percent': 833,
  33135. 'ampersand': 778,
  33136. 'quoteright': 333,
  33137. 'parenleft': 333,
  33138. 'parenright': 333,
  33139. 'asterisk': 500,
  33140. 'plus': 570,
  33141. 'comma': 250,
  33142. 'hyphen': 333,
  33143. 'period': 250,
  33144. 'slash': 278,
  33145. 'zero': 500,
  33146. 'one': 500,
  33147. 'two': 500,
  33148. 'three': 500,
  33149. 'four': 500,
  33150. 'five': 500,
  33151. 'six': 500,
  33152. 'seven': 500,
  33153. 'eight': 500,
  33154. 'nine': 500,
  33155. 'colon': 333,
  33156. 'semicolon': 333,
  33157. 'less': 570,
  33158. 'equal': 570,
  33159. 'greater': 570,
  33160. 'question': 500,
  33161. 'at': 832,
  33162. 'A': 667,
  33163. 'B': 667,
  33164. 'C': 667,
  33165. 'D': 722,
  33166. 'E': 667,
  33167. 'F': 667,
  33168. 'G': 722,
  33169. 'H': 778,
  33170. 'I': 389,
  33171. 'J': 500,
  33172. 'K': 667,
  33173. 'L': 611,
  33174. 'M': 889,
  33175. 'N': 722,
  33176. 'O': 722,
  33177. 'P': 611,
  33178. 'Q': 722,
  33179. 'R': 667,
  33180. 'S': 556,
  33181. 'T': 611,
  33182. 'U': 722,
  33183. 'V': 667,
  33184. 'W': 889,
  33185. 'X': 667,
  33186. 'Y': 611,
  33187. 'Z': 611,
  33188. 'bracketleft': 333,
  33189. 'backslash': 278,
  33190. 'bracketright': 333,
  33191. 'asciicircum': 570,
  33192. 'underscore': 500,
  33193. 'quoteleft': 333,
  33194. 'a': 500,
  33195. 'b': 500,
  33196. 'c': 444,
  33197. 'd': 500,
  33198. 'e': 444,
  33199. 'f': 333,
  33200. 'g': 500,
  33201. 'h': 556,
  33202. 'i': 278,
  33203. 'j': 278,
  33204. 'k': 500,
  33205. 'l': 278,
  33206. 'm': 778,
  33207. 'n': 556,
  33208. 'o': 500,
  33209. 'p': 500,
  33210. 'q': 500,
  33211. 'r': 389,
  33212. 's': 389,
  33213. 't': 278,
  33214. 'u': 556,
  33215. 'v': 444,
  33216. 'w': 667,
  33217. 'x': 500,
  33218. 'y': 444,
  33219. 'z': 389,
  33220. 'braceleft': 348,
  33221. 'bar': 220,
  33222. 'braceright': 348,
  33223. 'asciitilde': 570,
  33224. 'exclamdown': 389,
  33225. 'cent': 500,
  33226. 'sterling': 500,
  33227. 'fraction': 167,
  33228. 'yen': 500,
  33229. 'florin': 500,
  33230. 'section': 500,
  33231. 'currency': 500,
  33232. 'quotesingle': 278,
  33233. 'quotedblleft': 500,
  33234. 'guillemotleft': 500,
  33235. 'guilsinglleft': 333,
  33236. 'guilsinglright': 333,
  33237. 'fi': 556,
  33238. 'fl': 556,
  33239. 'endash': 500,
  33240. 'dagger': 500,
  33241. 'daggerdbl': 500,
  33242. 'periodcentered': 250,
  33243. 'paragraph': 500,
  33244. 'bullet': 350,
  33245. 'quotesinglbase': 333,
  33246. 'quotedblbase': 500,
  33247. 'quotedblright': 500,
  33248. 'guillemotright': 500,
  33249. 'ellipsis': 1000,
  33250. 'perthousand': 1000,
  33251. 'questiondown': 500,
  33252. 'grave': 333,
  33253. 'acute': 333,
  33254. 'circumflex': 333,
  33255. 'tilde': 333,
  33256. 'macron': 333,
  33257. 'breve': 333,
  33258. 'dotaccent': 333,
  33259. 'dieresis': 333,
  33260. 'ring': 333,
  33261. 'cedilla': 333,
  33262. 'hungarumlaut': 333,
  33263. 'ogonek': 333,
  33264. 'caron': 333,
  33265. 'emdash': 1000,
  33266. 'AE': 944,
  33267. 'ordfeminine': 266,
  33268. 'Lslash': 611,
  33269. 'Oslash': 722,
  33270. 'OE': 944,
  33271. 'ordmasculine': 300,
  33272. 'ae': 722,
  33273. 'dotlessi': 278,
  33274. 'lslash': 278,
  33275. 'oslash': 500,
  33276. 'oe': 722,
  33277. 'germandbls': 500,
  33278. 'Idieresis': 389,
  33279. 'eacute': 444,
  33280. 'abreve': 500,
  33281. 'uhungarumlaut': 556,
  33282. 'ecaron': 444,
  33283. 'Ydieresis': 611,
  33284. 'divide': 570,
  33285. 'Yacute': 611,
  33286. 'Acircumflex': 667,
  33287. 'aacute': 500,
  33288. 'Ucircumflex': 722,
  33289. 'yacute': 444,
  33290. 'scommaaccent': 389,
  33291. 'ecircumflex': 444,
  33292. 'Uring': 722,
  33293. 'Udieresis': 722,
  33294. 'aogonek': 500,
  33295. 'Uacute': 722,
  33296. 'uogonek': 556,
  33297. 'Edieresis': 667,
  33298. 'Dcroat': 722,
  33299. 'commaaccent': 250,
  33300. 'copyright': 747,
  33301. 'Emacron': 667,
  33302. 'ccaron': 444,
  33303. 'aring': 500,
  33304. 'Ncommaaccent': 722,
  33305. 'lacute': 278,
  33306. 'agrave': 500,
  33307. 'Tcommaaccent': 611,
  33308. 'Cacute': 667,
  33309. 'atilde': 500,
  33310. 'Edotaccent': 667,
  33311. 'scaron': 389,
  33312. 'scedilla': 389,
  33313. 'iacute': 278,
  33314. 'lozenge': 494,
  33315. 'Rcaron': 667,
  33316. 'Gcommaaccent': 722,
  33317. 'ucircumflex': 556,
  33318. 'acircumflex': 500,
  33319. 'Amacron': 667,
  33320. 'rcaron': 389,
  33321. 'ccedilla': 444,
  33322. 'Zdotaccent': 611,
  33323. 'Thorn': 611,
  33324. 'Omacron': 722,
  33325. 'Racute': 667,
  33326. 'Sacute': 556,
  33327. 'dcaron': 608,
  33328. 'Umacron': 722,
  33329. 'uring': 556,
  33330. 'threesuperior': 300,
  33331. 'Ograve': 722,
  33332. 'Agrave': 667,
  33333. 'Abreve': 667,
  33334. 'multiply': 570,
  33335. 'uacute': 556,
  33336. 'Tcaron': 611,
  33337. 'partialdiff': 494,
  33338. 'ydieresis': 444,
  33339. 'Nacute': 722,
  33340. 'icircumflex': 278,
  33341. 'Ecircumflex': 667,
  33342. 'adieresis': 500,
  33343. 'edieresis': 444,
  33344. 'cacute': 444,
  33345. 'nacute': 556,
  33346. 'umacron': 556,
  33347. 'Ncaron': 722,
  33348. 'Iacute': 389,
  33349. 'plusminus': 570,
  33350. 'brokenbar': 220,
  33351. 'registered': 747,
  33352. 'Gbreve': 722,
  33353. 'Idotaccent': 389,
  33354. 'summation': 600,
  33355. 'Egrave': 667,
  33356. 'racute': 389,
  33357. 'omacron': 500,
  33358. 'Zacute': 611,
  33359. 'Zcaron': 611,
  33360. 'greaterequal': 549,
  33361. 'Eth': 722,
  33362. 'Ccedilla': 667,
  33363. 'lcommaaccent': 278,
  33364. 'tcaron': 366,
  33365. 'eogonek': 444,
  33366. 'Uogonek': 722,
  33367. 'Aacute': 667,
  33368. 'Adieresis': 667,
  33369. 'egrave': 444,
  33370. 'zacute': 389,
  33371. 'iogonek': 278,
  33372. 'Oacute': 722,
  33373. 'oacute': 500,
  33374. 'amacron': 500,
  33375. 'sacute': 389,
  33376. 'idieresis': 278,
  33377. 'Ocircumflex': 722,
  33378. 'Ugrave': 722,
  33379. 'Delta': 612,
  33380. 'thorn': 500,
  33381. 'twosuperior': 300,
  33382. 'Odieresis': 722,
  33383. 'mu': 576,
  33384. 'igrave': 278,
  33385. 'ohungarumlaut': 500,
  33386. 'Eogonek': 667,
  33387. 'dcroat': 500,
  33388. 'threequarters': 750,
  33389. 'Scedilla': 556,
  33390. 'lcaron': 382,
  33391. 'Kcommaaccent': 667,
  33392. 'Lacute': 611,
  33393. 'trademark': 1000,
  33394. 'edotaccent': 444,
  33395. 'Igrave': 389,
  33396. 'Imacron': 389,
  33397. 'Lcaron': 611,
  33398. 'onehalf': 750,
  33399. 'lessequal': 549,
  33400. 'ocircumflex': 500,
  33401. 'ntilde': 556,
  33402. 'Uhungarumlaut': 722,
  33403. 'Eacute': 667,
  33404. 'emacron': 444,
  33405. 'gbreve': 500,
  33406. 'onequarter': 750,
  33407. 'Scaron': 556,
  33408. 'Scommaaccent': 556,
  33409. 'Ohungarumlaut': 722,
  33410. 'degree': 400,
  33411. 'ograve': 500,
  33412. 'Ccaron': 667,
  33413. 'ugrave': 556,
  33414. 'radical': 549,
  33415. 'Dcaron': 722,
  33416. 'rcommaaccent': 389,
  33417. 'Ntilde': 722,
  33418. 'otilde': 500,
  33419. 'Rcommaaccent': 667,
  33420. 'Lcommaaccent': 611,
  33421. 'Atilde': 667,
  33422. 'Aogonek': 667,
  33423. 'Aring': 667,
  33424. 'Otilde': 722,
  33425. 'zdotaccent': 389,
  33426. 'Ecaron': 667,
  33427. 'Iogonek': 389,
  33428. 'kcommaaccent': 500,
  33429. 'minus': 606,
  33430. 'Icircumflex': 389,
  33431. 'ncaron': 556,
  33432. 'tcommaaccent': 278,
  33433. 'logicalnot': 606,
  33434. 'odieresis': 500,
  33435. 'udieresis': 556,
  33436. 'notequal': 549,
  33437. 'gcommaaccent': 500,
  33438. 'eth': 500,
  33439. 'zcaron': 389,
  33440. 'ncommaaccent': 556,
  33441. 'onesuperior': 300,
  33442. 'imacron': 278,
  33443. 'Euro': 500
  33444. },
  33445. 'Times-Italic': {
  33446. 'space': 250,
  33447. 'exclam': 333,
  33448. 'quotedbl': 420,
  33449. 'numbersign': 500,
  33450. 'dollar': 500,
  33451. 'percent': 833,
  33452. 'ampersand': 778,
  33453. 'quoteright': 333,
  33454. 'parenleft': 333,
  33455. 'parenright': 333,
  33456. 'asterisk': 500,
  33457. 'plus': 675,
  33458. 'comma': 250,
  33459. 'hyphen': 333,
  33460. 'period': 250,
  33461. 'slash': 278,
  33462. 'zero': 500,
  33463. 'one': 500,
  33464. 'two': 500,
  33465. 'three': 500,
  33466. 'four': 500,
  33467. 'five': 500,
  33468. 'six': 500,
  33469. 'seven': 500,
  33470. 'eight': 500,
  33471. 'nine': 500,
  33472. 'colon': 333,
  33473. 'semicolon': 333,
  33474. 'less': 675,
  33475. 'equal': 675,
  33476. 'greater': 675,
  33477. 'question': 500,
  33478. 'at': 920,
  33479. 'A': 611,
  33480. 'B': 611,
  33481. 'C': 667,
  33482. 'D': 722,
  33483. 'E': 611,
  33484. 'F': 611,
  33485. 'G': 722,
  33486. 'H': 722,
  33487. 'I': 333,
  33488. 'J': 444,
  33489. 'K': 667,
  33490. 'L': 556,
  33491. 'M': 833,
  33492. 'N': 667,
  33493. 'O': 722,
  33494. 'P': 611,
  33495. 'Q': 722,
  33496. 'R': 611,
  33497. 'S': 500,
  33498. 'T': 556,
  33499. 'U': 722,
  33500. 'V': 611,
  33501. 'W': 833,
  33502. 'X': 611,
  33503. 'Y': 556,
  33504. 'Z': 556,
  33505. 'bracketleft': 389,
  33506. 'backslash': 278,
  33507. 'bracketright': 389,
  33508. 'asciicircum': 422,
  33509. 'underscore': 500,
  33510. 'quoteleft': 333,
  33511. 'a': 500,
  33512. 'b': 500,
  33513. 'c': 444,
  33514. 'd': 500,
  33515. 'e': 444,
  33516. 'f': 278,
  33517. 'g': 500,
  33518. 'h': 500,
  33519. 'i': 278,
  33520. 'j': 278,
  33521. 'k': 444,
  33522. 'l': 278,
  33523. 'm': 722,
  33524. 'n': 500,
  33525. 'o': 500,
  33526. 'p': 500,
  33527. 'q': 500,
  33528. 'r': 389,
  33529. 's': 389,
  33530. 't': 278,
  33531. 'u': 500,
  33532. 'v': 444,
  33533. 'w': 667,
  33534. 'x': 444,
  33535. 'y': 444,
  33536. 'z': 389,
  33537. 'braceleft': 400,
  33538. 'bar': 275,
  33539. 'braceright': 400,
  33540. 'asciitilde': 541,
  33541. 'exclamdown': 389,
  33542. 'cent': 500,
  33543. 'sterling': 500,
  33544. 'fraction': 167,
  33545. 'yen': 500,
  33546. 'florin': 500,
  33547. 'section': 500,
  33548. 'currency': 500,
  33549. 'quotesingle': 214,
  33550. 'quotedblleft': 556,
  33551. 'guillemotleft': 500,
  33552. 'guilsinglleft': 333,
  33553. 'guilsinglright': 333,
  33554. 'fi': 500,
  33555. 'fl': 500,
  33556. 'endash': 500,
  33557. 'dagger': 500,
  33558. 'daggerdbl': 500,
  33559. 'periodcentered': 250,
  33560. 'paragraph': 523,
  33561. 'bullet': 350,
  33562. 'quotesinglbase': 333,
  33563. 'quotedblbase': 556,
  33564. 'quotedblright': 556,
  33565. 'guillemotright': 500,
  33566. 'ellipsis': 889,
  33567. 'perthousand': 1000,
  33568. 'questiondown': 500,
  33569. 'grave': 333,
  33570. 'acute': 333,
  33571. 'circumflex': 333,
  33572. 'tilde': 333,
  33573. 'macron': 333,
  33574. 'breve': 333,
  33575. 'dotaccent': 333,
  33576. 'dieresis': 333,
  33577. 'ring': 333,
  33578. 'cedilla': 333,
  33579. 'hungarumlaut': 333,
  33580. 'ogonek': 333,
  33581. 'caron': 333,
  33582. 'emdash': 889,
  33583. 'AE': 889,
  33584. 'ordfeminine': 276,
  33585. 'Lslash': 556,
  33586. 'Oslash': 722,
  33587. 'OE': 944,
  33588. 'ordmasculine': 310,
  33589. 'ae': 667,
  33590. 'dotlessi': 278,
  33591. 'lslash': 278,
  33592. 'oslash': 500,
  33593. 'oe': 667,
  33594. 'germandbls': 500,
  33595. 'Idieresis': 333,
  33596. 'eacute': 444,
  33597. 'abreve': 500,
  33598. 'uhungarumlaut': 500,
  33599. 'ecaron': 444,
  33600. 'Ydieresis': 556,
  33601. 'divide': 675,
  33602. 'Yacute': 556,
  33603. 'Acircumflex': 611,
  33604. 'aacute': 500,
  33605. 'Ucircumflex': 722,
  33606. 'yacute': 444,
  33607. 'scommaaccent': 389,
  33608. 'ecircumflex': 444,
  33609. 'Uring': 722,
  33610. 'Udieresis': 722,
  33611. 'aogonek': 500,
  33612. 'Uacute': 722,
  33613. 'uogonek': 500,
  33614. 'Edieresis': 611,
  33615. 'Dcroat': 722,
  33616. 'commaaccent': 250,
  33617. 'copyright': 760,
  33618. 'Emacron': 611,
  33619. 'ccaron': 444,
  33620. 'aring': 500,
  33621. 'Ncommaaccent': 667,
  33622. 'lacute': 278,
  33623. 'agrave': 500,
  33624. 'Tcommaaccent': 556,
  33625. 'Cacute': 667,
  33626. 'atilde': 500,
  33627. 'Edotaccent': 611,
  33628. 'scaron': 389,
  33629. 'scedilla': 389,
  33630. 'iacute': 278,
  33631. 'lozenge': 471,
  33632. 'Rcaron': 611,
  33633. 'Gcommaaccent': 722,
  33634. 'ucircumflex': 500,
  33635. 'acircumflex': 500,
  33636. 'Amacron': 611,
  33637. 'rcaron': 389,
  33638. 'ccedilla': 444,
  33639. 'Zdotaccent': 556,
  33640. 'Thorn': 611,
  33641. 'Omacron': 722,
  33642. 'Racute': 611,
  33643. 'Sacute': 500,
  33644. 'dcaron': 544,
  33645. 'Umacron': 722,
  33646. 'uring': 500,
  33647. 'threesuperior': 300,
  33648. 'Ograve': 722,
  33649. 'Agrave': 611,
  33650. 'Abreve': 611,
  33651. 'multiply': 675,
  33652. 'uacute': 500,
  33653. 'Tcaron': 556,
  33654. 'partialdiff': 476,
  33655. 'ydieresis': 444,
  33656. 'Nacute': 667,
  33657. 'icircumflex': 278,
  33658. 'Ecircumflex': 611,
  33659. 'adieresis': 500,
  33660. 'edieresis': 444,
  33661. 'cacute': 444,
  33662. 'nacute': 500,
  33663. 'umacron': 500,
  33664. 'Ncaron': 667,
  33665. 'Iacute': 333,
  33666. 'plusminus': 675,
  33667. 'brokenbar': 275,
  33668. 'registered': 760,
  33669. 'Gbreve': 722,
  33670. 'Idotaccent': 333,
  33671. 'summation': 600,
  33672. 'Egrave': 611,
  33673. 'racute': 389,
  33674. 'omacron': 500,
  33675. 'Zacute': 556,
  33676. 'Zcaron': 556,
  33677. 'greaterequal': 549,
  33678. 'Eth': 722,
  33679. 'Ccedilla': 667,
  33680. 'lcommaaccent': 278,
  33681. 'tcaron': 300,
  33682. 'eogonek': 444,
  33683. 'Uogonek': 722,
  33684. 'Aacute': 611,
  33685. 'Adieresis': 611,
  33686. 'egrave': 444,
  33687. 'zacute': 389,
  33688. 'iogonek': 278,
  33689. 'Oacute': 722,
  33690. 'oacute': 500,
  33691. 'amacron': 500,
  33692. 'sacute': 389,
  33693. 'idieresis': 278,
  33694. 'Ocircumflex': 722,
  33695. 'Ugrave': 722,
  33696. 'Delta': 612,
  33697. 'thorn': 500,
  33698. 'twosuperior': 300,
  33699. 'Odieresis': 722,
  33700. 'mu': 500,
  33701. 'igrave': 278,
  33702. 'ohungarumlaut': 500,
  33703. 'Eogonek': 611,
  33704. 'dcroat': 500,
  33705. 'threequarters': 750,
  33706. 'Scedilla': 500,
  33707. 'lcaron': 300,
  33708. 'Kcommaaccent': 667,
  33709. 'Lacute': 556,
  33710. 'trademark': 980,
  33711. 'edotaccent': 444,
  33712. 'Igrave': 333,
  33713. 'Imacron': 333,
  33714. 'Lcaron': 611,
  33715. 'onehalf': 750,
  33716. 'lessequal': 549,
  33717. 'ocircumflex': 500,
  33718. 'ntilde': 500,
  33719. 'Uhungarumlaut': 722,
  33720. 'Eacute': 611,
  33721. 'emacron': 444,
  33722. 'gbreve': 500,
  33723. 'onequarter': 750,
  33724. 'Scaron': 500,
  33725. 'Scommaaccent': 500,
  33726. 'Ohungarumlaut': 722,
  33727. 'degree': 400,
  33728. 'ograve': 500,
  33729. 'Ccaron': 667,
  33730. 'ugrave': 500,
  33731. 'radical': 453,
  33732. 'Dcaron': 722,
  33733. 'rcommaaccent': 389,
  33734. 'Ntilde': 667,
  33735. 'otilde': 500,
  33736. 'Rcommaaccent': 611,
  33737. 'Lcommaaccent': 556,
  33738. 'Atilde': 611,
  33739. 'Aogonek': 611,
  33740. 'Aring': 611,
  33741. 'Otilde': 722,
  33742. 'zdotaccent': 389,
  33743. 'Ecaron': 611,
  33744. 'Iogonek': 333,
  33745. 'kcommaaccent': 444,
  33746. 'minus': 675,
  33747. 'Icircumflex': 333,
  33748. 'ncaron': 500,
  33749. 'tcommaaccent': 278,
  33750. 'logicalnot': 675,
  33751. 'odieresis': 500,
  33752. 'udieresis': 500,
  33753. 'notequal': 549,
  33754. 'gcommaaccent': 500,
  33755. 'eth': 500,
  33756. 'zcaron': 389,
  33757. 'ncommaaccent': 500,
  33758. 'onesuperior': 300,
  33759. 'imacron': 278,
  33760. 'Euro': 500
  33761. },
  33762. 'ZapfDingbats': {
  33763. 'space': 278,
  33764. 'a1': 974,
  33765. 'a2': 961,
  33766. 'a202': 974,
  33767. 'a3': 980,
  33768. 'a4': 719,
  33769. 'a5': 789,
  33770. 'a119': 790,
  33771. 'a118': 791,
  33772. 'a117': 690,
  33773. 'a11': 960,
  33774. 'a12': 939,
  33775. 'a13': 549,
  33776. 'a14': 855,
  33777. 'a15': 911,
  33778. 'a16': 933,
  33779. 'a105': 911,
  33780. 'a17': 945,
  33781. 'a18': 974,
  33782. 'a19': 755,
  33783. 'a20': 846,
  33784. 'a21': 762,
  33785. 'a22': 761,
  33786. 'a23': 571,
  33787. 'a24': 677,
  33788. 'a25': 763,
  33789. 'a26': 760,
  33790. 'a27': 759,
  33791. 'a28': 754,
  33792. 'a6': 494,
  33793. 'a7': 552,
  33794. 'a8': 537,
  33795. 'a9': 577,
  33796. 'a10': 692,
  33797. 'a29': 786,
  33798. 'a30': 788,
  33799. 'a31': 788,
  33800. 'a32': 790,
  33801. 'a33': 793,
  33802. 'a34': 794,
  33803. 'a35': 816,
  33804. 'a36': 823,
  33805. 'a37': 789,
  33806. 'a38': 841,
  33807. 'a39': 823,
  33808. 'a40': 833,
  33809. 'a41': 816,
  33810. 'a42': 831,
  33811. 'a43': 923,
  33812. 'a44': 744,
  33813. 'a45': 723,
  33814. 'a46': 749,
  33815. 'a47': 790,
  33816. 'a48': 792,
  33817. 'a49': 695,
  33818. 'a50': 776,
  33819. 'a51': 768,
  33820. 'a52': 792,
  33821. 'a53': 759,
  33822. 'a54': 707,
  33823. 'a55': 708,
  33824. 'a56': 682,
  33825. 'a57': 701,
  33826. 'a58': 826,
  33827. 'a59': 815,
  33828. 'a60': 789,
  33829. 'a61': 789,
  33830. 'a62': 707,
  33831. 'a63': 687,
  33832. 'a64': 696,
  33833. 'a65': 689,
  33834. 'a66': 786,
  33835. 'a67': 787,
  33836. 'a68': 713,
  33837. 'a69': 791,
  33838. 'a70': 785,
  33839. 'a71': 791,
  33840. 'a72': 873,
  33841. 'a73': 761,
  33842. 'a74': 762,
  33843. 'a203': 762,
  33844. 'a75': 759,
  33845. 'a204': 759,
  33846. 'a76': 892,
  33847. 'a77': 892,
  33848. 'a78': 788,
  33849. 'a79': 784,
  33850. 'a81': 438,
  33851. 'a82': 138,
  33852. 'a83': 277,
  33853. 'a84': 415,
  33854. 'a97': 392,
  33855. 'a98': 392,
  33856. 'a99': 668,
  33857. 'a100': 668,
  33858. 'a89': 390,
  33859. 'a90': 390,
  33860. 'a93': 317,
  33861. 'a94': 317,
  33862. 'a91': 276,
  33863. 'a92': 276,
  33864. 'a205': 509,
  33865. 'a85': 509,
  33866. 'a206': 410,
  33867. 'a86': 410,
  33868. 'a87': 234,
  33869. 'a88': 234,
  33870. 'a95': 334,
  33871. 'a96': 334,
  33872. 'a101': 732,
  33873. 'a102': 544,
  33874. 'a103': 544,
  33875. 'a104': 910,
  33876. 'a106': 667,
  33877. 'a107': 760,
  33878. 'a108': 760,
  33879. 'a112': 776,
  33880. 'a111': 595,
  33881. 'a110': 694,
  33882. 'a109': 626,
  33883. 'a120': 788,
  33884. 'a121': 788,
  33885. 'a122': 788,
  33886. 'a123': 788,
  33887. 'a124': 788,
  33888. 'a125': 788,
  33889. 'a126': 788,
  33890. 'a127': 788,
  33891. 'a128': 788,
  33892. 'a129': 788,
  33893. 'a130': 788,
  33894. 'a131': 788,
  33895. 'a132': 788,
  33896. 'a133': 788,
  33897. 'a134': 788,
  33898. 'a135': 788,
  33899. 'a136': 788,
  33900. 'a137': 788,
  33901. 'a138': 788,
  33902. 'a139': 788,
  33903. 'a140': 788,
  33904. 'a141': 788,
  33905. 'a142': 788,
  33906. 'a143': 788,
  33907. 'a144': 788,
  33908. 'a145': 788,
  33909. 'a146': 788,
  33910. 'a147': 788,
  33911. 'a148': 788,
  33912. 'a149': 788,
  33913. 'a150': 788,
  33914. 'a151': 788,
  33915. 'a152': 788,
  33916. 'a153': 788,
  33917. 'a154': 788,
  33918. 'a155': 788,
  33919. 'a156': 788,
  33920. 'a157': 788,
  33921. 'a158': 788,
  33922. 'a159': 788,
  33923. 'a160': 894,
  33924. 'a161': 838,
  33925. 'a163': 1016,
  33926. 'a164': 458,
  33927. 'a196': 748,
  33928. 'a165': 924,
  33929. 'a192': 748,
  33930. 'a166': 918,
  33931. 'a167': 927,
  33932. 'a168': 928,
  33933. 'a169': 928,
  33934. 'a170': 834,
  33935. 'a171': 873,
  33936. 'a172': 828,
  33937. 'a173': 924,
  33938. 'a162': 924,
  33939. 'a174': 917,
  33940. 'a175': 930,
  33941. 'a176': 931,
  33942. 'a177': 463,
  33943. 'a178': 883,
  33944. 'a179': 836,
  33945. 'a193': 836,
  33946. 'a180': 867,
  33947. 'a199': 867,
  33948. 'a181': 696,
  33949. 'a200': 696,
  33950. 'a182': 874,
  33951. 'a201': 874,
  33952. 'a183': 760,
  33953. 'a184': 946,
  33954. 'a197': 771,
  33955. 'a185': 865,
  33956. 'a194': 771,
  33957. 'a198': 888,
  33958. 'a186': 967,
  33959. 'a195': 888,
  33960. 'a187': 831,
  33961. 'a188': 873,
  33962. 'a189': 927,
  33963. 'a190': 970,
  33964. 'a191': 918
  33965. }
  33966. };
  33967. var EOF = {};
  33968. function isEOF(v) {
  33969. return (v === EOF);
  33970. }
  33971. var MAX_LENGTH_TO_CACHE = 1000;
  33972. var Parser = (function ParserClosure() {
  33973. function Parser(lexer, allowStreams, xref) {
  33974. this.lexer = lexer;
  33975. this.allowStreams = allowStreams;
  33976. this.xref = xref;
  33977. this.imageCache = {};
  33978. this.refill();
  33979. }
  33980. Parser.prototype = {
  33981. refill: function Parser_refill() {
  33982. this.buf1 = this.lexer.getObj();
  33983. this.buf2 = this.lexer.getObj();
  33984. },
  33985. shift: function Parser_shift() {
  33986. if (isCmd(this.buf2, 'ID')) {
  33987. this.buf1 = this.buf2;
  33988. this.buf2 = null;
  33989. } else {
  33990. this.buf1 = this.buf2;
  33991. this.buf2 = this.lexer.getObj();
  33992. }
  33993. },
  33994. getObj: function Parser_getObj(cipherTransform) {
  33995. var buf1 = this.buf1;
  33996. this.shift();
  33997. if (buf1 instanceof Cmd) {
  33998. switch (buf1.cmd) {
  33999. case 'BI': // inline image
  34000. return this.makeInlineImage(cipherTransform);
  34001. case '[': // array
  34002. var array = [];
  34003. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  34004. array.push(this.getObj(cipherTransform));
  34005. }
  34006. if (isEOF(this.buf1)) {
  34007. error('End of file inside array');
  34008. }
  34009. this.shift();
  34010. return array;
  34011. case '<<': // dictionary or stream
  34012. var dict = new Dict(this.xref);
  34013. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  34014. if (!isName(this.buf1)) {
  34015. info('Malformed dictionary: key must be a name object');
  34016. this.shift();
  34017. continue;
  34018. }
  34019. var key = this.buf1.name;
  34020. this.shift();
  34021. if (isEOF(this.buf1)) {
  34022. break;
  34023. }
  34024. dict.set(key, this.getObj(cipherTransform));
  34025. }
  34026. if (isEOF(this.buf1)) {
  34027. error('End of file inside dictionary');
  34028. }
  34029. // Stream objects are not allowed inside content streams or
  34030. // object streams.
  34031. if (isCmd(this.buf2, 'stream')) {
  34032. return (this.allowStreams ?
  34033. this.makeStream(dict, cipherTransform) : dict);
  34034. }
  34035. this.shift();
  34036. return dict;
  34037. default: // simple object
  34038. return buf1;
  34039. }
  34040. }
  34041. if (isInt(buf1)) { // indirect reference or integer
  34042. var num = buf1;
  34043. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  34044. var ref = new Ref(num, this.buf1);
  34045. this.shift();
  34046. this.shift();
  34047. return ref;
  34048. }
  34049. return num;
  34050. }
  34051. if (isString(buf1)) { // string
  34052. var str = buf1;
  34053. if (cipherTransform) {
  34054. str = cipherTransform.decryptString(str);
  34055. }
  34056. return str;
  34057. }
  34058. // simple object
  34059. return buf1;
  34060. },
  34061. /**
  34062. * Find the end of the stream by searching for the /EI\s/.
  34063. * @returns {number} The inline stream length.
  34064. */
  34065. findDefaultInlineStreamEnd:
  34066. function Parser_findDefaultInlineStreamEnd(stream) {
  34067. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  34068. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  34069. while ((ch = stream.getByte()) !== -1) {
  34070. if (state === 0) {
  34071. state = (ch === E) ? 1 : 0;
  34072. } else if (state === 1) {
  34073. state = (ch === I) ? 2 : 0;
  34074. } else {
  34075. assert(state === 2);
  34076. if (ch === SPACE || ch === LF || ch === CR) {
  34077. // Let's check the next five bytes are ASCII... just be sure.
  34078. n = 5;
  34079. followingBytes = stream.peekBytes(n);
  34080. for (i = 0; i < n; i++) {
  34081. ch = followingBytes[i];
  34082. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  34083. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  34084. // it's binary stuff. Resetting the state.
  34085. state = 0;
  34086. break;
  34087. }
  34088. }
  34089. if (state === 2) {
  34090. break; // Finished!
  34091. }
  34092. } else {
  34093. state = 0;
  34094. }
  34095. }
  34096. }
  34097. return ((stream.pos - 4) - startPos);
  34098. },
  34099. /**
  34100. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  34101. * @returns {number} The inline stream length.
  34102. */
  34103. findDCTDecodeInlineStreamEnd:
  34104. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  34105. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  34106. while ((b = stream.getByte()) !== -1) {
  34107. if (b !== 0xFF) { // Not a valid marker.
  34108. continue;
  34109. }
  34110. switch (stream.getByte()) {
  34111. case 0x00: // Byte stuffing.
  34112. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  34113. break;
  34114. case 0xFF: // Fill byte.
  34115. // Avoid skipping a valid marker, resetting the stream position.
  34116. stream.skip(-1);
  34117. break;
  34118. case 0xD9: // EOI
  34119. foundEOI = true;
  34120. break;
  34121. case 0xC0: // SOF0
  34122. case 0xC1: // SOF1
  34123. case 0xC2: // SOF2
  34124. case 0xC3: // SOF3
  34125. case 0xC5: // SOF5
  34126. case 0xC6: // SOF6
  34127. case 0xC7: // SOF7
  34128. case 0xC9: // SOF9
  34129. case 0xCA: // SOF10
  34130. case 0xCB: // SOF11
  34131. case 0xCD: // SOF13
  34132. case 0xCE: // SOF14
  34133. case 0xCF: // SOF15
  34134. case 0xC4: // DHT
  34135. case 0xCC: // DAC
  34136. case 0xDA: // SOS
  34137. case 0xDB: // DQT
  34138. case 0xDC: // DNL
  34139. case 0xDD: // DRI
  34140. case 0xDE: // DHP
  34141. case 0xDF: // EXP
  34142. case 0xE0: // APP0
  34143. case 0xE1: // APP1
  34144. case 0xE2: // APP2
  34145. case 0xE3: // APP3
  34146. case 0xE4: // APP4
  34147. case 0xE5: // APP5
  34148. case 0xE6: // APP6
  34149. case 0xE7: // APP7
  34150. case 0xE8: // APP8
  34151. case 0xE9: // APP9
  34152. case 0xEA: // APP10
  34153. case 0xEB: // APP11
  34154. case 0xEC: // APP12
  34155. case 0xED: // APP13
  34156. case 0xEE: // APP14
  34157. case 0xEF: // APP15
  34158. case 0xFE: // COM
  34159. // The marker should be followed by the length of the segment.
  34160. markerLength = stream.getUint16();
  34161. if (markerLength > 2) {
  34162. // |markerLength| contains the byte length of the marker segment,
  34163. // including its own length (2 bytes) and excluding the marker.
  34164. stream.skip(markerLength - 2); // Jump to the next marker.
  34165. } else {
  34166. // The marker length is invalid, resetting the stream position.
  34167. stream.skip(-2);
  34168. }
  34169. break;
  34170. }
  34171. if (foundEOI) {
  34172. break;
  34173. }
  34174. }
  34175. length = stream.pos - startPos;
  34176. if (b === -1) {
  34177. warn('Inline DCTDecode image stream: ' +
  34178. 'EOI marker not found, searching for /EI/ instead.');
  34179. stream.skip(-length); // Reset the stream position.
  34180. return this.findDefaultInlineStreamEnd(stream);
  34181. }
  34182. this.inlineStreamSkipEI(stream);
  34183. return length;
  34184. },
  34185. /**
  34186. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  34187. * @returns {number} The inline stream length.
  34188. */
  34189. findASCII85DecodeInlineStreamEnd:
  34190. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  34191. var TILDE = 0x7E, GT = 0x3E;
  34192. var startPos = stream.pos, ch, length;
  34193. while ((ch = stream.getByte()) !== -1) {
  34194. if (ch === TILDE && stream.peekByte() === GT) {
  34195. stream.skip();
  34196. break;
  34197. }
  34198. }
  34199. length = stream.pos - startPos;
  34200. if (ch === -1) {
  34201. warn('Inline ASCII85Decode image stream: ' +
  34202. 'EOD marker not found, searching for /EI/ instead.');
  34203. stream.skip(-length); // Reset the stream position.
  34204. return this.findDefaultInlineStreamEnd(stream);
  34205. }
  34206. this.inlineStreamSkipEI(stream);
  34207. return length;
  34208. },
  34209. /**
  34210. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  34211. * @returns {number} The inline stream length.
  34212. */
  34213. findASCIIHexDecodeInlineStreamEnd:
  34214. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  34215. var GT = 0x3E;
  34216. var startPos = stream.pos, ch, length;
  34217. while ((ch = stream.getByte()) !== -1) {
  34218. if (ch === GT) {
  34219. break;
  34220. }
  34221. }
  34222. length = stream.pos - startPos;
  34223. if (ch === -1) {
  34224. warn('Inline ASCIIHexDecode image stream: ' +
  34225. 'EOD marker not found, searching for /EI/ instead.');
  34226. stream.skip(-length); // Reset the stream position.
  34227. return this.findDefaultInlineStreamEnd(stream);
  34228. }
  34229. this.inlineStreamSkipEI(stream);
  34230. return length;
  34231. },
  34232. /**
  34233. * Skip over the /EI/ for streams where we search for an EOD marker.
  34234. */
  34235. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  34236. var E = 0x45, I = 0x49;
  34237. var state = 0, ch;
  34238. while ((ch = stream.getByte()) !== -1) {
  34239. if (state === 0) {
  34240. state = (ch === E) ? 1 : 0;
  34241. } else if (state === 1) {
  34242. state = (ch === I) ? 2 : 0;
  34243. } else if (state === 2) {
  34244. break;
  34245. }
  34246. }
  34247. },
  34248. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  34249. var lexer = this.lexer;
  34250. var stream = lexer.stream;
  34251. // Parse dictionary.
  34252. var dict = new Dict(null);
  34253. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  34254. if (!isName(this.buf1)) {
  34255. error('Dictionary key must be a name object');
  34256. }
  34257. var key = this.buf1.name;
  34258. this.shift();
  34259. if (isEOF(this.buf1)) {
  34260. break;
  34261. }
  34262. dict.set(key, this.getObj(cipherTransform));
  34263. }
  34264. // Extract the name of the first (i.e. the current) image filter.
  34265. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  34266. if (isName(filter)) {
  34267. filterName = filter.name;
  34268. } else if (isArray(filter) && isName(filter[0])) {
  34269. filterName = filter[0].name;
  34270. }
  34271. // Parse image stream.
  34272. var startPos = stream.pos, length, i, ii;
  34273. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  34274. length = this.findDCTDecodeInlineStreamEnd(stream);
  34275. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  34276. length = this.findASCII85DecodeInlineStreamEnd(stream);
  34277. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  34278. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  34279. } else {
  34280. length = this.findDefaultInlineStreamEnd(stream);
  34281. }
  34282. var imageStream = stream.makeSubStream(startPos, length, dict);
  34283. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  34284. // adler32 checksum.
  34285. var adler32;
  34286. if (length < MAX_LENGTH_TO_CACHE) {
  34287. var imageBytes = imageStream.getBytes();
  34288. imageStream.reset();
  34289. var a = 1;
  34290. var b = 0;
  34291. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  34292. // No modulo required in the loop if imageBytes.length < 5552.
  34293. a += imageBytes[i] & 0xff;
  34294. b += a;
  34295. }
  34296. adler32 = ((b % 65521) << 16) | (a % 65521);
  34297. if (this.imageCache.adler32 === adler32) {
  34298. this.buf2 = Cmd.get('EI');
  34299. this.shift();
  34300. this.imageCache[adler32].reset();
  34301. return this.imageCache[adler32];
  34302. }
  34303. }
  34304. if (cipherTransform) {
  34305. imageStream = cipherTransform.createStream(imageStream, length);
  34306. }
  34307. imageStream = this.filter(imageStream, dict, length);
  34308. imageStream.dict = dict;
  34309. if (adler32 !== undefined) {
  34310. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  34311. this.imageCache[adler32] = imageStream;
  34312. }
  34313. this.buf2 = Cmd.get('EI');
  34314. this.shift();
  34315. return imageStream;
  34316. },
  34317. fetchIfRef: function Parser_fetchIfRef(obj) {
  34318. // not relying on the xref.fetchIfRef -- xref might not be set
  34319. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  34320. },
  34321. makeStream: function Parser_makeStream(dict, cipherTransform) {
  34322. var lexer = this.lexer;
  34323. var stream = lexer.stream;
  34324. // get stream start position
  34325. lexer.skipToNextLine();
  34326. var pos = stream.pos - 1;
  34327. // get length
  34328. var length = this.fetchIfRef(dict.get('Length'));
  34329. if (!isInt(length)) {
  34330. info('Bad ' + length + ' attribute in stream');
  34331. length = 0;
  34332. }
  34333. // skip over the stream data
  34334. stream.pos = pos + length;
  34335. lexer.nextChar();
  34336. this.shift(); // '>>'
  34337. this.shift(); // 'stream'
  34338. if (!isCmd(this.buf1, 'endstream')) {
  34339. // bad stream length, scanning for endstream
  34340. stream.pos = pos;
  34341. var SCAN_BLOCK_SIZE = 2048;
  34342. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  34343. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  34344. 0x61, 0x6D];
  34345. var skipped = 0, found = false, i, j;
  34346. while (stream.pos < stream.end) {
  34347. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  34348. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  34349. if (scanLength <= 0) {
  34350. break;
  34351. }
  34352. found = false;
  34353. for (i = 0, j = 0; i < scanLength; i++) {
  34354. var b = scanBytes[i];
  34355. if (b !== ENDSTREAM_SIGNATURE[j]) {
  34356. i -= j;
  34357. j = 0;
  34358. } else {
  34359. j++;
  34360. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  34361. i++;
  34362. found = true;
  34363. break;
  34364. }
  34365. }
  34366. }
  34367. if (found) {
  34368. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  34369. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  34370. break;
  34371. }
  34372. skipped += scanLength;
  34373. stream.pos += scanLength;
  34374. }
  34375. if (!found) {
  34376. error('Missing endstream');
  34377. }
  34378. length = skipped;
  34379. lexer.nextChar();
  34380. this.shift();
  34381. this.shift();
  34382. }
  34383. this.shift(); // 'endstream'
  34384. stream = stream.makeSubStream(pos, length, dict);
  34385. if (cipherTransform) {
  34386. stream = cipherTransform.createStream(stream, length);
  34387. }
  34388. stream = this.filter(stream, dict, length);
  34389. stream.dict = dict;
  34390. return stream;
  34391. },
  34392. filter: function Parser_filter(stream, dict, length) {
  34393. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  34394. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  34395. if (isName(filter)) {
  34396. return this.makeFilter(stream, filter.name, length, params);
  34397. }
  34398. var maybeLength = length;
  34399. if (isArray(filter)) {
  34400. var filterArray = filter;
  34401. var paramsArray = params;
  34402. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  34403. filter = filterArray[i];
  34404. if (!isName(filter)) {
  34405. error('Bad filter name: ' + filter);
  34406. }
  34407. params = null;
  34408. if (isArray(paramsArray) && (i in paramsArray)) {
  34409. params = paramsArray[i];
  34410. }
  34411. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  34412. // after the first stream the length variable is invalid
  34413. maybeLength = null;
  34414. }
  34415. }
  34416. return stream;
  34417. },
  34418. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  34419. if (stream.dict.get('Length') === 0) {
  34420. return new NullStream(stream);
  34421. }
  34422. try {
  34423. if (params) {
  34424. params = this.fetchIfRef(params);
  34425. }
  34426. var xrefStreamStats = this.xref.stats.streamTypes;
  34427. if (name === 'FlateDecode' || name === 'Fl') {
  34428. xrefStreamStats[StreamType.FLATE] = true;
  34429. if (params) {
  34430. return new PredictorStream(new FlateStream(stream, maybeLength),
  34431. maybeLength, params);
  34432. }
  34433. return new FlateStream(stream, maybeLength);
  34434. }
  34435. if (name === 'LZWDecode' || name === 'LZW') {
  34436. xrefStreamStats[StreamType.LZW] = true;
  34437. var earlyChange = 1;
  34438. if (params) {
  34439. if (params.has('EarlyChange')) {
  34440. earlyChange = params.get('EarlyChange');
  34441. }
  34442. return new PredictorStream(
  34443. new LZWStream(stream, maybeLength, earlyChange),
  34444. maybeLength, params);
  34445. }
  34446. return new LZWStream(stream, maybeLength, earlyChange);
  34447. }
  34448. if (name === 'DCTDecode' || name === 'DCT') {
  34449. xrefStreamStats[StreamType.DCT] = true;
  34450. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  34451. }
  34452. if (name === 'JPXDecode' || name === 'JPX') {
  34453. xrefStreamStats[StreamType.JPX] = true;
  34454. return new JpxStream(stream, maybeLength, stream.dict);
  34455. }
  34456. if (name === 'ASCII85Decode' || name === 'A85') {
  34457. xrefStreamStats[StreamType.A85] = true;
  34458. return new Ascii85Stream(stream, maybeLength);
  34459. }
  34460. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  34461. xrefStreamStats[StreamType.AHX] = true;
  34462. return new AsciiHexStream(stream, maybeLength);
  34463. }
  34464. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  34465. xrefStreamStats[StreamType.CCF] = true;
  34466. return new CCITTFaxStream(stream, maybeLength, params);
  34467. }
  34468. if (name === 'RunLengthDecode' || name === 'RL') {
  34469. xrefStreamStats[StreamType.RL] = true;
  34470. return new RunLengthStream(stream, maybeLength);
  34471. }
  34472. if (name === 'JBIG2Decode') {
  34473. xrefStreamStats[StreamType.JBIG] = true;
  34474. return new Jbig2Stream(stream, maybeLength, stream.dict);
  34475. }
  34476. warn('filter "' + name + '" not supported yet');
  34477. return stream;
  34478. } catch (ex) {
  34479. if (ex instanceof MissingDataException) {
  34480. throw ex;
  34481. }
  34482. warn('Invalid stream: \"' + ex + '\"');
  34483. return new NullStream(stream);
  34484. }
  34485. }
  34486. };
  34487. return Parser;
  34488. })();
  34489. var Lexer = (function LexerClosure() {
  34490. function Lexer(stream, knownCommands) {
  34491. this.stream = stream;
  34492. this.nextChar();
  34493. // While lexing, we build up many strings one char at a time. Using += for
  34494. // this can result in lots of garbage strings. It's better to build an
  34495. // array of single-char strings and then join() them together at the end.
  34496. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  34497. // purpose uses less memory than using a new array for each string.
  34498. this.strBuf = [];
  34499. // The PDFs might have "glued" commands with other commands, operands or
  34500. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  34501. // commands and their prefixes. The prefixes are built the following way:
  34502. // if there a command that is a prefix of the other valid command or
  34503. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  34504. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  34505. // other commands or literals as a prefix. The knowCommands is optional.
  34506. this.knownCommands = knownCommands;
  34507. }
  34508. Lexer.isSpace = function Lexer_isSpace(ch) {
  34509. // Space is one of the following characters: SPACE, TAB, CR or LF.
  34510. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  34511. };
  34512. // A '1' in this array means the character is white space. A '1' or
  34513. // '2' means the character ends a name or command.
  34514. var specialChars = [
  34515. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34517. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34531. ];
  34532. function toHexDigit(ch) {
  34533. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34534. return ch & 0x0F;
  34535. }
  34536. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34537. // 'A'-'F', 'a'-'f'
  34538. return (ch & 0x0F) + 9;
  34539. }
  34540. return -1;
  34541. }
  34542. Lexer.prototype = {
  34543. nextChar: function Lexer_nextChar() {
  34544. return (this.currentChar = this.stream.getByte());
  34545. },
  34546. peekChar: function Lexer_peekChar() {
  34547. return this.stream.peekByte();
  34548. },
  34549. getNumber: function Lexer_getNumber() {
  34550. var ch = this.currentChar;
  34551. var eNotation = false;
  34552. var divideBy = 0; // different from 0 if it's a floating point value
  34553. var sign = 1;
  34554. if (ch === 0x2D) { // '-'
  34555. sign = -1;
  34556. ch = this.nextChar();
  34557. } else if (ch === 0x2B) { // '+'
  34558. ch = this.nextChar();
  34559. }
  34560. if (ch === 0x2E) { // '.'
  34561. divideBy = 10;
  34562. ch = this.nextChar();
  34563. }
  34564. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34565. error('Invalid number: ' + String.fromCharCode(ch));
  34566. return 0;
  34567. }
  34568. var baseValue = ch - 0x30; // '0'
  34569. var powerValue = 0;
  34570. var powerValueSign = 1;
  34571. while ((ch = this.nextChar()) >= 0) {
  34572. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  34573. var currentDigit = ch - 0x30; // '0'
  34574. if (eNotation) { // We are after an 'e' or 'E'
  34575. powerValue = powerValue * 10 + currentDigit;
  34576. } else {
  34577. if (divideBy !== 0) { // We are after a point
  34578. divideBy *= 10;
  34579. }
  34580. baseValue = baseValue * 10 + currentDigit;
  34581. }
  34582. } else if (ch === 0x2E) { // '.'
  34583. if (divideBy === 0) {
  34584. divideBy = 1;
  34585. } else {
  34586. // A number can have only one '.'
  34587. break;
  34588. }
  34589. } else if (ch === 0x2D) { // '-'
  34590. // ignore minus signs in the middle of numbers to match
  34591. // Adobe's behavior
  34592. warn('Badly formated number');
  34593. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  34594. // 'E' can be either a scientific notation or the beginning of a new
  34595. // operator
  34596. ch = this.peekChar();
  34597. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  34598. powerValueSign = (ch === 0x2D) ? -1 : 1;
  34599. this.nextChar(); // Consume the sign character
  34600. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34601. // The 'E' must be the beginning of a new operator
  34602. break;
  34603. }
  34604. eNotation = true;
  34605. } else {
  34606. // the last character doesn't belong to us
  34607. break;
  34608. }
  34609. }
  34610. if (divideBy !== 0) {
  34611. baseValue /= divideBy;
  34612. }
  34613. if (eNotation) {
  34614. baseValue *= Math.pow(10, powerValueSign * powerValue);
  34615. }
  34616. return sign * baseValue;
  34617. },
  34618. getString: function Lexer_getString() {
  34619. var numParen = 1;
  34620. var done = false;
  34621. var strBuf = this.strBuf;
  34622. strBuf.length = 0;
  34623. var ch = this.nextChar();
  34624. while (true) {
  34625. var charBuffered = false;
  34626. switch (ch | 0) {
  34627. case -1:
  34628. warn('Unterminated string');
  34629. done = true;
  34630. break;
  34631. case 0x28: // '('
  34632. ++numParen;
  34633. strBuf.push('(');
  34634. break;
  34635. case 0x29: // ')'
  34636. if (--numParen === 0) {
  34637. this.nextChar(); // consume strings ')'
  34638. done = true;
  34639. } else {
  34640. strBuf.push(')');
  34641. }
  34642. break;
  34643. case 0x5C: // '\\'
  34644. ch = this.nextChar();
  34645. switch (ch) {
  34646. case -1:
  34647. warn('Unterminated string');
  34648. done = true;
  34649. break;
  34650. case 0x6E: // 'n'
  34651. strBuf.push('\n');
  34652. break;
  34653. case 0x72: // 'r'
  34654. strBuf.push('\r');
  34655. break;
  34656. case 0x74: // 't'
  34657. strBuf.push('\t');
  34658. break;
  34659. case 0x62: // 'b'
  34660. strBuf.push('\b');
  34661. break;
  34662. case 0x66: // 'f'
  34663. strBuf.push('\f');
  34664. break;
  34665. case 0x5C: // '\'
  34666. case 0x28: // '('
  34667. case 0x29: // ')'
  34668. strBuf.push(String.fromCharCode(ch));
  34669. break;
  34670. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34671. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34672. var x = ch & 0x0F;
  34673. ch = this.nextChar();
  34674. charBuffered = true;
  34675. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34676. x = (x << 3) + (ch & 0x0F);
  34677. ch = this.nextChar();
  34678. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34679. charBuffered = false;
  34680. x = (x << 3) + (ch & 0x0F);
  34681. }
  34682. }
  34683. strBuf.push(String.fromCharCode(x));
  34684. break;
  34685. case 0x0D: // CR
  34686. if (this.peekChar() === 0x0A) { // LF
  34687. this.nextChar();
  34688. }
  34689. break;
  34690. case 0x0A: // LF
  34691. break;
  34692. default:
  34693. strBuf.push(String.fromCharCode(ch));
  34694. break;
  34695. }
  34696. break;
  34697. default:
  34698. strBuf.push(String.fromCharCode(ch));
  34699. break;
  34700. }
  34701. if (done) {
  34702. break;
  34703. }
  34704. if (!charBuffered) {
  34705. ch = this.nextChar();
  34706. }
  34707. }
  34708. return strBuf.join('');
  34709. },
  34710. getName: function Lexer_getName() {
  34711. var ch;
  34712. var strBuf = this.strBuf;
  34713. strBuf.length = 0;
  34714. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34715. if (ch === 0x23) { // '#'
  34716. ch = this.nextChar();
  34717. var x = toHexDigit(ch);
  34718. if (x !== -1) {
  34719. var x2 = toHexDigit(this.nextChar());
  34720. if (x2 === -1) {
  34721. error('Illegal digit in hex char in name: ' + x2);
  34722. }
  34723. strBuf.push(String.fromCharCode((x << 4) | x2));
  34724. } else {
  34725. strBuf.push('#', String.fromCharCode(ch));
  34726. }
  34727. } else {
  34728. strBuf.push(String.fromCharCode(ch));
  34729. }
  34730. }
  34731. if (strBuf.length > 128) {
  34732. error('Warning: name token is longer than allowed by the spec: ' +
  34733. strBuf.length);
  34734. }
  34735. return Name.get(strBuf.join(''));
  34736. },
  34737. getHexString: function Lexer_getHexString() {
  34738. var strBuf = this.strBuf;
  34739. strBuf.length = 0;
  34740. var ch = this.currentChar;
  34741. var isFirstHex = true;
  34742. var firstDigit;
  34743. var secondDigit;
  34744. while (true) {
  34745. if (ch < 0) {
  34746. warn('Unterminated hex string');
  34747. break;
  34748. } else if (ch === 0x3E) { // '>'
  34749. this.nextChar();
  34750. break;
  34751. } else if (specialChars[ch] === 1) {
  34752. ch = this.nextChar();
  34753. continue;
  34754. } else {
  34755. if (isFirstHex) {
  34756. firstDigit = toHexDigit(ch);
  34757. if (firstDigit === -1) {
  34758. warn('Ignoring invalid character "' + ch + '" in hex string');
  34759. ch = this.nextChar();
  34760. continue;
  34761. }
  34762. } else {
  34763. secondDigit = toHexDigit(ch);
  34764. if (secondDigit === -1) {
  34765. warn('Ignoring invalid character "' + ch + '" in hex string');
  34766. ch = this.nextChar();
  34767. continue;
  34768. }
  34769. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34770. }
  34771. isFirstHex = !isFirstHex;
  34772. ch = this.nextChar();
  34773. }
  34774. }
  34775. return strBuf.join('');
  34776. },
  34777. getObj: function Lexer_getObj() {
  34778. // skip whitespace and comments
  34779. var comment = false;
  34780. var ch = this.currentChar;
  34781. while (true) {
  34782. if (ch < 0) {
  34783. return EOF;
  34784. }
  34785. if (comment) {
  34786. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34787. comment = false;
  34788. }
  34789. } else if (ch === 0x25) { // '%'
  34790. comment = true;
  34791. } else if (specialChars[ch] !== 1) {
  34792. break;
  34793. }
  34794. ch = this.nextChar();
  34795. }
  34796. // start reading token
  34797. switch (ch | 0) {
  34798. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34799. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34800. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34801. return this.getNumber();
  34802. case 0x28: // '('
  34803. return this.getString();
  34804. case 0x2F: // '/'
  34805. return this.getName();
  34806. // array punctuation
  34807. case 0x5B: // '['
  34808. this.nextChar();
  34809. return Cmd.get('[');
  34810. case 0x5D: // ']'
  34811. this.nextChar();
  34812. return Cmd.get(']');
  34813. // hex string or dict punctuation
  34814. case 0x3C: // '<'
  34815. ch = this.nextChar();
  34816. if (ch === 0x3C) {
  34817. // dict punctuation
  34818. this.nextChar();
  34819. return Cmd.get('<<');
  34820. }
  34821. return this.getHexString();
  34822. // dict punctuation
  34823. case 0x3E: // '>'
  34824. ch = this.nextChar();
  34825. if (ch === 0x3E) {
  34826. this.nextChar();
  34827. return Cmd.get('>>');
  34828. }
  34829. return Cmd.get('>');
  34830. case 0x7B: // '{'
  34831. this.nextChar();
  34832. return Cmd.get('{');
  34833. case 0x7D: // '}'
  34834. this.nextChar();
  34835. return Cmd.get('}');
  34836. case 0x29: // ')'
  34837. error('Illegal character: ' + ch);
  34838. break;
  34839. }
  34840. // command
  34841. var str = String.fromCharCode(ch);
  34842. var knownCommands = this.knownCommands;
  34843. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34844. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34845. // stop if known command is found and next character does not make
  34846. // the str a command
  34847. var possibleCommand = str + String.fromCharCode(ch);
  34848. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34849. break;
  34850. }
  34851. if (str.length === 128) {
  34852. error('Command token too long: ' + str.length);
  34853. }
  34854. str = possibleCommand;
  34855. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34856. }
  34857. if (str === 'true') {
  34858. return true;
  34859. }
  34860. if (str === 'false') {
  34861. return false;
  34862. }
  34863. if (str === 'null') {
  34864. return null;
  34865. }
  34866. return Cmd.get(str);
  34867. },
  34868. skipToNextLine: function Lexer_skipToNextLine() {
  34869. var ch = this.currentChar;
  34870. while (ch >= 0) {
  34871. if (ch === 0x0D) { // CR
  34872. ch = this.nextChar();
  34873. if (ch === 0x0A) { // LF
  34874. this.nextChar();
  34875. }
  34876. break;
  34877. } else if (ch === 0x0A) { // LF
  34878. this.nextChar();
  34879. break;
  34880. }
  34881. ch = this.nextChar();
  34882. }
  34883. }
  34884. };
  34885. return Lexer;
  34886. })();
  34887. var Linearization = {
  34888. create: function LinearizationCreate(stream) {
  34889. function getInt(name, allowZeroValue) {
  34890. var obj = linDict.get(name);
  34891. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34892. return obj;
  34893. }
  34894. throw new Error('The "' + name + '" parameter in the linearization ' +
  34895. 'dictionary is invalid.');
  34896. }
  34897. function getHints() {
  34898. var hints = linDict.get('H'), hintsLength, item;
  34899. if (isArray(hints) &&
  34900. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34901. for (var index = 0; index < hintsLength; index++) {
  34902. if (!(isInt(item = hints[index]) && item > 0)) {
  34903. throw new Error('Hint (' + index +
  34904. ') in the linearization dictionary is invalid.');
  34905. }
  34906. }
  34907. return hints;
  34908. }
  34909. throw new Error('Hint array in the linearization dictionary is invalid.');
  34910. }
  34911. var parser = new Parser(new Lexer(stream), false, null);
  34912. var obj1 = parser.getObj();
  34913. var obj2 = parser.getObj();
  34914. var obj3 = parser.getObj();
  34915. var linDict = parser.getObj();
  34916. var obj, length;
  34917. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34918. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34919. return null; // No valid linearization dictionary found.
  34920. } else if ((length = getInt('L')) !== stream.length) {
  34921. throw new Error('The "L" parameter in the linearization dictionary ' +
  34922. 'does not equal the stream length.');
  34923. }
  34924. return {
  34925. length: length,
  34926. hints: getHints(),
  34927. objectNumberFirst: getInt('O'),
  34928. endFirst: getInt('E'),
  34929. numPages: getInt('N'),
  34930. mainXRefEntriesOffset: getInt('T'),
  34931. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34932. };
  34933. }
  34934. };
  34935. var PostScriptParser = (function PostScriptParserClosure() {
  34936. function PostScriptParser(lexer) {
  34937. this.lexer = lexer;
  34938. this.operators = [];
  34939. this.token = null;
  34940. this.prev = null;
  34941. }
  34942. PostScriptParser.prototype = {
  34943. nextToken: function PostScriptParser_nextToken() {
  34944. this.prev = this.token;
  34945. this.token = this.lexer.getToken();
  34946. },
  34947. accept: function PostScriptParser_accept(type) {
  34948. if (this.token.type === type) {
  34949. this.nextToken();
  34950. return true;
  34951. }
  34952. return false;
  34953. },
  34954. expect: function PostScriptParser_expect(type) {
  34955. if (this.accept(type)) {
  34956. return true;
  34957. }
  34958. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  34959. type + '.');
  34960. },
  34961. parse: function PostScriptParser_parse() {
  34962. this.nextToken();
  34963. this.expect(PostScriptTokenTypes.LBRACE);
  34964. this.parseBlock();
  34965. this.expect(PostScriptTokenTypes.RBRACE);
  34966. return this.operators;
  34967. },
  34968. parseBlock: function PostScriptParser_parseBlock() {
  34969. while (true) {
  34970. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  34971. this.operators.push(this.prev.value);
  34972. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  34973. this.operators.push(this.prev.value);
  34974. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34975. this.parseCondition();
  34976. } else {
  34977. return;
  34978. }
  34979. }
  34980. },
  34981. parseCondition: function PostScriptParser_parseCondition() {
  34982. // Add two place holders that will be updated later
  34983. var conditionLocation = this.operators.length;
  34984. this.operators.push(null, null);
  34985. this.parseBlock();
  34986. this.expect(PostScriptTokenTypes.RBRACE);
  34987. if (this.accept(PostScriptTokenTypes.IF)) {
  34988. // The true block is right after the 'if' so it just falls through on
  34989. // true else it jumps and skips the true block.
  34990. this.operators[conditionLocation] = this.operators.length;
  34991. this.operators[conditionLocation + 1] = 'jz';
  34992. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34993. var jumpLocation = this.operators.length;
  34994. this.operators.push(null, null);
  34995. var endOfTrue = this.operators.length;
  34996. this.parseBlock();
  34997. this.expect(PostScriptTokenTypes.RBRACE);
  34998. this.expect(PostScriptTokenTypes.IFELSE);
  34999. // The jump is added at the end of the true block to skip the false
  35000. // block.
  35001. this.operators[jumpLocation] = this.operators.length;
  35002. this.operators[jumpLocation + 1] = 'j';
  35003. this.operators[conditionLocation] = endOfTrue;
  35004. this.operators[conditionLocation + 1] = 'jz';
  35005. } else {
  35006. error('PS Function: error parsing conditional.');
  35007. }
  35008. }
  35009. };
  35010. return PostScriptParser;
  35011. })();
  35012. var PostScriptTokenTypes = {
  35013. LBRACE: 0,
  35014. RBRACE: 1,
  35015. NUMBER: 2,
  35016. OPERATOR: 3,
  35017. IF: 4,
  35018. IFELSE: 5
  35019. };
  35020. var PostScriptToken = (function PostScriptTokenClosure() {
  35021. function PostScriptToken(type, value) {
  35022. this.type = type;
  35023. this.value = value;
  35024. }
  35025. var opCache = {};
  35026. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  35027. var opValue = opCache[op];
  35028. if (opValue) {
  35029. return opValue;
  35030. }
  35031. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  35032. };
  35033. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  35034. '{');
  35035. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  35036. '}');
  35037. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  35038. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  35039. 'IFELSE');
  35040. return PostScriptToken;
  35041. })();
  35042. var PostScriptLexer = (function PostScriptLexerClosure() {
  35043. function PostScriptLexer(stream) {
  35044. this.stream = stream;
  35045. this.nextChar();
  35046. this.strBuf = [];
  35047. }
  35048. PostScriptLexer.prototype = {
  35049. nextChar: function PostScriptLexer_nextChar() {
  35050. return (this.currentChar = this.stream.getByte());
  35051. },
  35052. getToken: function PostScriptLexer_getToken() {
  35053. var comment = false;
  35054. var ch = this.currentChar;
  35055. // skip comments
  35056. while (true) {
  35057. if (ch < 0) {
  35058. return EOF;
  35059. }
  35060. if (comment) {
  35061. if (ch === 0x0A || ch === 0x0D) {
  35062. comment = false;
  35063. }
  35064. } else if (ch === 0x25) { // '%'
  35065. comment = true;
  35066. } else if (!Lexer.isSpace(ch)) {
  35067. break;
  35068. }
  35069. ch = this.nextChar();
  35070. }
  35071. switch (ch | 0) {
  35072. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  35073. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  35074. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  35075. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  35076. this.getNumber());
  35077. case 0x7B: // '{'
  35078. this.nextChar();
  35079. return PostScriptToken.LBRACE;
  35080. case 0x7D: // '}'
  35081. this.nextChar();
  35082. return PostScriptToken.RBRACE;
  35083. }
  35084. // operator
  35085. var strBuf = this.strBuf;
  35086. strBuf.length = 0;
  35087. strBuf[0] = String.fromCharCode(ch);
  35088. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  35089. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  35090. strBuf.push(String.fromCharCode(ch));
  35091. }
  35092. var str = strBuf.join('');
  35093. switch (str.toLowerCase()) {
  35094. case 'if':
  35095. return PostScriptToken.IF;
  35096. case 'ifelse':
  35097. return PostScriptToken.IFELSE;
  35098. default:
  35099. return PostScriptToken.getOperator(str);
  35100. }
  35101. },
  35102. getNumber: function PostScriptLexer_getNumber() {
  35103. var ch = this.currentChar;
  35104. var strBuf = this.strBuf;
  35105. strBuf.length = 0;
  35106. strBuf[0] = String.fromCharCode(ch);
  35107. while ((ch = this.nextChar()) >= 0) {
  35108. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  35109. ch === 0x2D || ch === 0x2E) { // '-', '.'
  35110. strBuf.push(String.fromCharCode(ch));
  35111. } else {
  35112. break;
  35113. }
  35114. }
  35115. var value = parseFloat(strBuf.join(''));
  35116. if (isNaN(value)) {
  35117. error('Invalid floating point number: ' + value);
  35118. }
  35119. return value;
  35120. }
  35121. };
  35122. return PostScriptLexer;
  35123. })();
  35124. var Stream = (function StreamClosure() {
  35125. function Stream(arrayBuffer, start, length, dict) {
  35126. this.bytes = (arrayBuffer instanceof Uint8Array ?
  35127. arrayBuffer : new Uint8Array(arrayBuffer));
  35128. this.start = start || 0;
  35129. this.pos = this.start;
  35130. this.end = (start + length) || this.bytes.length;
  35131. this.dict = dict;
  35132. }
  35133. // required methods for a stream. if a particular stream does not
  35134. // implement these, an error should be thrown
  35135. Stream.prototype = {
  35136. get length() {
  35137. return this.end - this.start;
  35138. },
  35139. get isEmpty() {
  35140. return this.length === 0;
  35141. },
  35142. getByte: function Stream_getByte() {
  35143. if (this.pos >= this.end) {
  35144. return -1;
  35145. }
  35146. return this.bytes[this.pos++];
  35147. },
  35148. getUint16: function Stream_getUint16() {
  35149. var b0 = this.getByte();
  35150. var b1 = this.getByte();
  35151. if (b0 === -1 || b1 === -1) {
  35152. return -1;
  35153. }
  35154. return (b0 << 8) + b1;
  35155. },
  35156. getInt32: function Stream_getInt32() {
  35157. var b0 = this.getByte();
  35158. var b1 = this.getByte();
  35159. var b2 = this.getByte();
  35160. var b3 = this.getByte();
  35161. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35162. },
  35163. // returns subarray of original buffer
  35164. // should only be read
  35165. getBytes: function Stream_getBytes(length) {
  35166. var bytes = this.bytes;
  35167. var pos = this.pos;
  35168. var strEnd = this.end;
  35169. if (!length) {
  35170. return bytes.subarray(pos, strEnd);
  35171. }
  35172. var end = pos + length;
  35173. if (end > strEnd) {
  35174. end = strEnd;
  35175. }
  35176. this.pos = end;
  35177. return bytes.subarray(pos, end);
  35178. },
  35179. peekByte: function Stream_peekByte() {
  35180. var peekedByte = this.getByte();
  35181. this.pos--;
  35182. return peekedByte;
  35183. },
  35184. peekBytes: function Stream_peekBytes(length) {
  35185. var bytes = this.getBytes(length);
  35186. this.pos -= bytes.length;
  35187. return bytes;
  35188. },
  35189. skip: function Stream_skip(n) {
  35190. if (!n) {
  35191. n = 1;
  35192. }
  35193. this.pos += n;
  35194. },
  35195. reset: function Stream_reset() {
  35196. this.pos = this.start;
  35197. },
  35198. moveStart: function Stream_moveStart() {
  35199. this.start = this.pos;
  35200. },
  35201. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  35202. return new Stream(this.bytes.buffer, start, length, dict);
  35203. },
  35204. isStream: true
  35205. };
  35206. return Stream;
  35207. })();
  35208. var StringStream = (function StringStreamClosure() {
  35209. function StringStream(str) {
  35210. var length = str.length;
  35211. var bytes = new Uint8Array(length);
  35212. for (var n = 0; n < length; ++n) {
  35213. bytes[n] = str.charCodeAt(n);
  35214. }
  35215. Stream.call(this, bytes);
  35216. }
  35217. StringStream.prototype = Stream.prototype;
  35218. return StringStream;
  35219. })();
  35220. // super class for the decoding streams
  35221. var DecodeStream = (function DecodeStreamClosure() {
  35222. // Lots of DecodeStreams are created whose buffers are never used. For these
  35223. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  35224. // having special cases that would be required if we used |null| for an empty
  35225. // buffer.
  35226. var emptyBuffer = new Uint8Array(0);
  35227. function DecodeStream(maybeMinBufferLength) {
  35228. this.pos = 0;
  35229. this.bufferLength = 0;
  35230. this.eof = false;
  35231. this.buffer = emptyBuffer;
  35232. this.minBufferLength = 512;
  35233. if (maybeMinBufferLength) {
  35234. // Compute the first power of two that is as big as maybeMinBufferLength.
  35235. while (this.minBufferLength < maybeMinBufferLength) {
  35236. this.minBufferLength *= 2;
  35237. }
  35238. }
  35239. }
  35240. DecodeStream.prototype = {
  35241. get isEmpty() {
  35242. while (!this.eof && this.bufferLength === 0) {
  35243. this.readBlock();
  35244. }
  35245. return this.bufferLength === 0;
  35246. },
  35247. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  35248. var buffer = this.buffer;
  35249. if (requested <= buffer.byteLength) {
  35250. return buffer;
  35251. }
  35252. var size = this.minBufferLength;
  35253. while (size < requested) {
  35254. size *= 2;
  35255. }
  35256. var buffer2 = new Uint8Array(size);
  35257. buffer2.set(buffer);
  35258. return (this.buffer = buffer2);
  35259. },
  35260. getByte: function DecodeStream_getByte() {
  35261. var pos = this.pos;
  35262. while (this.bufferLength <= pos) {
  35263. if (this.eof) {
  35264. return -1;
  35265. }
  35266. this.readBlock();
  35267. }
  35268. return this.buffer[this.pos++];
  35269. },
  35270. getUint16: function DecodeStream_getUint16() {
  35271. var b0 = this.getByte();
  35272. var b1 = this.getByte();
  35273. if (b0 === -1 || b1 === -1) {
  35274. return -1;
  35275. }
  35276. return (b0 << 8) + b1;
  35277. },
  35278. getInt32: function DecodeStream_getInt32() {
  35279. var b0 = this.getByte();
  35280. var b1 = this.getByte();
  35281. var b2 = this.getByte();
  35282. var b3 = this.getByte();
  35283. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35284. },
  35285. getBytes: function DecodeStream_getBytes(length) {
  35286. var end, pos = this.pos;
  35287. if (length) {
  35288. this.ensureBuffer(pos + length);
  35289. end = pos + length;
  35290. while (!this.eof && this.bufferLength < end) {
  35291. this.readBlock();
  35292. }
  35293. var bufEnd = this.bufferLength;
  35294. if (end > bufEnd) {
  35295. end = bufEnd;
  35296. }
  35297. } else {
  35298. while (!this.eof) {
  35299. this.readBlock();
  35300. }
  35301. end = this.bufferLength;
  35302. }
  35303. this.pos = end;
  35304. return this.buffer.subarray(pos, end);
  35305. },
  35306. peekByte: function DecodeStream_peekByte() {
  35307. var peekedByte = this.getByte();
  35308. this.pos--;
  35309. return peekedByte;
  35310. },
  35311. peekBytes: function DecodeStream_peekBytes(length) {
  35312. var bytes = this.getBytes(length);
  35313. this.pos -= bytes.length;
  35314. return bytes;
  35315. },
  35316. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  35317. var end = start + length;
  35318. while (this.bufferLength <= end && !this.eof) {
  35319. this.readBlock();
  35320. }
  35321. return new Stream(this.buffer, start, length, dict);
  35322. },
  35323. skip: function DecodeStream_skip(n) {
  35324. if (!n) {
  35325. n = 1;
  35326. }
  35327. this.pos += n;
  35328. },
  35329. reset: function DecodeStream_reset() {
  35330. this.pos = 0;
  35331. },
  35332. getBaseStreams: function DecodeStream_getBaseStreams() {
  35333. if (this.str && this.str.getBaseStreams) {
  35334. return this.str.getBaseStreams();
  35335. }
  35336. return [];
  35337. }
  35338. };
  35339. return DecodeStream;
  35340. })();
  35341. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  35342. function StreamsSequenceStream(streams) {
  35343. this.streams = streams;
  35344. DecodeStream.call(this, /* maybeLength = */ null);
  35345. }
  35346. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  35347. StreamsSequenceStream.prototype.readBlock =
  35348. function streamSequenceStreamReadBlock() {
  35349. var streams = this.streams;
  35350. if (streams.length === 0) {
  35351. this.eof = true;
  35352. return;
  35353. }
  35354. var stream = streams.shift();
  35355. var chunk = stream.getBytes();
  35356. var bufferLength = this.bufferLength;
  35357. var newLength = bufferLength + chunk.length;
  35358. var buffer = this.ensureBuffer(newLength);
  35359. buffer.set(chunk, bufferLength);
  35360. this.bufferLength = newLength;
  35361. };
  35362. StreamsSequenceStream.prototype.getBaseStreams =
  35363. function StreamsSequenceStream_getBaseStreams() {
  35364. var baseStreams = [];
  35365. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  35366. var stream = this.streams[i];
  35367. if (stream.getBaseStreams) {
  35368. Util.appendToArray(baseStreams, stream.getBaseStreams());
  35369. }
  35370. }
  35371. return baseStreams;
  35372. };
  35373. return StreamsSequenceStream;
  35374. })();
  35375. var FlateStream = (function FlateStreamClosure() {
  35376. var codeLenCodeMap = new Int32Array([
  35377. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  35378. ]);
  35379. var lengthDecode = new Int32Array([
  35380. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  35381. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  35382. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  35383. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  35384. ]);
  35385. var distDecode = new Int32Array([
  35386. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  35387. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  35388. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  35389. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  35390. ]);
  35391. var fixedLitCodeTab = [new Int32Array([
  35392. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  35393. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  35394. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  35395. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  35396. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  35397. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  35398. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  35399. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  35400. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  35401. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  35402. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  35403. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  35404. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  35405. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  35406. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  35407. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  35408. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  35409. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  35410. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  35411. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  35412. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  35413. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  35414. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  35415. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  35416. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  35417. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  35418. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  35419. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  35420. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  35421. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  35422. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  35423. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  35424. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  35425. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  35426. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  35427. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  35428. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  35429. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  35430. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  35431. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  35432. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  35433. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  35434. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  35435. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  35436. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  35437. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  35438. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  35439. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  35440. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  35441. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  35442. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  35443. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  35444. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  35445. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  35446. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  35447. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  35448. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  35449. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  35450. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  35451. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  35452. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  35453. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  35454. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  35455. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  35456. ]), 9];
  35457. var fixedDistCodeTab = [new Int32Array([
  35458. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  35459. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  35460. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  35461. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  35462. ]), 5];
  35463. function FlateStream(str, maybeLength) {
  35464. this.str = str;
  35465. this.dict = str.dict;
  35466. var cmf = str.getByte();
  35467. var flg = str.getByte();
  35468. if (cmf === -1 || flg === -1) {
  35469. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  35470. }
  35471. if ((cmf & 0x0f) !== 0x08) {
  35472. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  35473. }
  35474. if ((((cmf << 8) + flg) % 31) !== 0) {
  35475. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  35476. }
  35477. if (flg & 0x20) {
  35478. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  35479. }
  35480. this.codeSize = 0;
  35481. this.codeBuf = 0;
  35482. DecodeStream.call(this, maybeLength);
  35483. }
  35484. FlateStream.prototype = Object.create(DecodeStream.prototype);
  35485. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  35486. var str = this.str;
  35487. var codeSize = this.codeSize;
  35488. var codeBuf = this.codeBuf;
  35489. var b;
  35490. while (codeSize < bits) {
  35491. if ((b = str.getByte()) === -1) {
  35492. error('Bad encoding in flate stream');
  35493. }
  35494. codeBuf |= b << codeSize;
  35495. codeSize += 8;
  35496. }
  35497. b = codeBuf & ((1 << bits) - 1);
  35498. this.codeBuf = codeBuf >> bits;
  35499. this.codeSize = codeSize -= bits;
  35500. return b;
  35501. };
  35502. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  35503. var str = this.str;
  35504. var codes = table[0];
  35505. var maxLen = table[1];
  35506. var codeSize = this.codeSize;
  35507. var codeBuf = this.codeBuf;
  35508. var b;
  35509. while (codeSize < maxLen) {
  35510. if ((b = str.getByte()) === -1) {
  35511. // premature end of stream. code might however still be valid.
  35512. // codeSize < codeLen check below guards against incomplete codeVal.
  35513. break;
  35514. }
  35515. codeBuf |= (b << codeSize);
  35516. codeSize += 8;
  35517. }
  35518. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35519. var codeLen = code >> 16;
  35520. var codeVal = code & 0xffff;
  35521. if (codeLen < 1 || codeSize < codeLen) {
  35522. error('Bad encoding in flate stream');
  35523. }
  35524. this.codeBuf = (codeBuf >> codeLen);
  35525. this.codeSize = (codeSize - codeLen);
  35526. return codeVal;
  35527. };
  35528. FlateStream.prototype.generateHuffmanTable =
  35529. function flateStreamGenerateHuffmanTable(lengths) {
  35530. var n = lengths.length;
  35531. // find max code length
  35532. var maxLen = 0;
  35533. var i;
  35534. for (i = 0; i < n; ++i) {
  35535. if (lengths[i] > maxLen) {
  35536. maxLen = lengths[i];
  35537. }
  35538. }
  35539. // build the table
  35540. var size = 1 << maxLen;
  35541. var codes = new Int32Array(size);
  35542. for (var len = 1, code = 0, skip = 2;
  35543. len <= maxLen;
  35544. ++len, code <<= 1, skip <<= 1) {
  35545. for (var val = 0; val < n; ++val) {
  35546. if (lengths[val] === len) {
  35547. // bit-reverse the code
  35548. var code2 = 0;
  35549. var t = code;
  35550. for (i = 0; i < len; ++i) {
  35551. code2 = (code2 << 1) | (t & 1);
  35552. t >>= 1;
  35553. }
  35554. // fill the table entries
  35555. for (i = code2; i < size; i += skip) {
  35556. codes[i] = (len << 16) | val;
  35557. }
  35558. ++code;
  35559. }
  35560. }
  35561. }
  35562. return [codes, maxLen];
  35563. };
  35564. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  35565. var buffer, len;
  35566. var str = this.str;
  35567. // read block header
  35568. var hdr = this.getBits(3);
  35569. if (hdr & 1) {
  35570. this.eof = true;
  35571. }
  35572. hdr >>= 1;
  35573. if (hdr === 0) { // uncompressed block
  35574. var b;
  35575. if ((b = str.getByte()) === -1) {
  35576. error('Bad block header in flate stream');
  35577. }
  35578. var blockLen = b;
  35579. if ((b = str.getByte()) === -1) {
  35580. error('Bad block header in flate stream');
  35581. }
  35582. blockLen |= (b << 8);
  35583. if ((b = str.getByte()) === -1) {
  35584. error('Bad block header in flate stream');
  35585. }
  35586. var check = b;
  35587. if ((b = str.getByte()) === -1) {
  35588. error('Bad block header in flate stream');
  35589. }
  35590. check |= (b << 8);
  35591. if (check !== (~blockLen & 0xffff) &&
  35592. (blockLen !== 0 || check !== 0)) {
  35593. // Ignoring error for bad "empty" block (see issue 1277)
  35594. error('Bad uncompressed block length in flate stream');
  35595. }
  35596. this.codeBuf = 0;
  35597. this.codeSize = 0;
  35598. var bufferLength = this.bufferLength;
  35599. buffer = this.ensureBuffer(bufferLength + blockLen);
  35600. var end = bufferLength + blockLen;
  35601. this.bufferLength = end;
  35602. if (blockLen === 0) {
  35603. if (str.peekByte() === -1) {
  35604. this.eof = true;
  35605. }
  35606. } else {
  35607. for (var n = bufferLength; n < end; ++n) {
  35608. if ((b = str.getByte()) === -1) {
  35609. this.eof = true;
  35610. break;
  35611. }
  35612. buffer[n] = b;
  35613. }
  35614. }
  35615. return;
  35616. }
  35617. var litCodeTable;
  35618. var distCodeTable;
  35619. if (hdr === 1) { // compressed block, fixed codes
  35620. litCodeTable = fixedLitCodeTab;
  35621. distCodeTable = fixedDistCodeTab;
  35622. } else if (hdr === 2) { // compressed block, dynamic codes
  35623. var numLitCodes = this.getBits(5) + 257;
  35624. var numDistCodes = this.getBits(5) + 1;
  35625. var numCodeLenCodes = this.getBits(4) + 4;
  35626. // build the code lengths code table
  35627. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  35628. var i;
  35629. for (i = 0; i < numCodeLenCodes; ++i) {
  35630. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  35631. }
  35632. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  35633. // build the literal and distance code tables
  35634. len = 0;
  35635. i = 0;
  35636. var codes = numLitCodes + numDistCodes;
  35637. var codeLengths = new Uint8Array(codes);
  35638. var bitsLength, bitsOffset, what;
  35639. while (i < codes) {
  35640. var code = this.getCode(codeLenCodeTab);
  35641. if (code === 16) {
  35642. bitsLength = 2; bitsOffset = 3; what = len;
  35643. } else if (code === 17) {
  35644. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35645. } else if (code === 18) {
  35646. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35647. } else {
  35648. codeLengths[i++] = len = code;
  35649. continue;
  35650. }
  35651. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35652. while (repeatLength-- > 0) {
  35653. codeLengths[i++] = what;
  35654. }
  35655. }
  35656. litCodeTable =
  35657. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35658. distCodeTable =
  35659. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35660. } else {
  35661. error('Unknown block type in flate stream');
  35662. }
  35663. buffer = this.buffer;
  35664. var limit = buffer ? buffer.length : 0;
  35665. var pos = this.bufferLength;
  35666. while (true) {
  35667. var code1 = this.getCode(litCodeTable);
  35668. if (code1 < 256) {
  35669. if (pos + 1 >= limit) {
  35670. buffer = this.ensureBuffer(pos + 1);
  35671. limit = buffer.length;
  35672. }
  35673. buffer[pos++] = code1;
  35674. continue;
  35675. }
  35676. if (code1 === 256) {
  35677. this.bufferLength = pos;
  35678. return;
  35679. }
  35680. code1 -= 257;
  35681. code1 = lengthDecode[code1];
  35682. var code2 = code1 >> 16;
  35683. if (code2 > 0) {
  35684. code2 = this.getBits(code2);
  35685. }
  35686. len = (code1 & 0xffff) + code2;
  35687. code1 = this.getCode(distCodeTable);
  35688. code1 = distDecode[code1];
  35689. code2 = code1 >> 16;
  35690. if (code2 > 0) {
  35691. code2 = this.getBits(code2);
  35692. }
  35693. var dist = (code1 & 0xffff) + code2;
  35694. if (pos + len >= limit) {
  35695. buffer = this.ensureBuffer(pos + len);
  35696. limit = buffer.length;
  35697. }
  35698. for (var k = 0; k < len; ++k, ++pos) {
  35699. buffer[pos] = buffer[pos - dist];
  35700. }
  35701. }
  35702. };
  35703. return FlateStream;
  35704. })();
  35705. var PredictorStream = (function PredictorStreamClosure() {
  35706. function PredictorStream(str, maybeLength, params) {
  35707. var predictor = this.predictor = params.get('Predictor') || 1;
  35708. if (predictor <= 1) {
  35709. return str; // no prediction
  35710. }
  35711. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35712. error('Unsupported predictor: ' + predictor);
  35713. }
  35714. if (predictor === 2) {
  35715. this.readBlock = this.readBlockTiff;
  35716. } else {
  35717. this.readBlock = this.readBlockPng;
  35718. }
  35719. this.str = str;
  35720. this.dict = str.dict;
  35721. var colors = this.colors = params.get('Colors') || 1;
  35722. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35723. var columns = this.columns = params.get('Columns') || 1;
  35724. this.pixBytes = (colors * bits + 7) >> 3;
  35725. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35726. DecodeStream.call(this, maybeLength);
  35727. return this;
  35728. }
  35729. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35730. PredictorStream.prototype.readBlockTiff =
  35731. function predictorStreamReadBlockTiff() {
  35732. var rowBytes = this.rowBytes;
  35733. var bufferLength = this.bufferLength;
  35734. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35735. var bits = this.bits;
  35736. var colors = this.colors;
  35737. var rawBytes = this.str.getBytes(rowBytes);
  35738. this.eof = !rawBytes.length;
  35739. if (this.eof) {
  35740. return;
  35741. }
  35742. var inbuf = 0, outbuf = 0;
  35743. var inbits = 0, outbits = 0;
  35744. var pos = bufferLength;
  35745. var i;
  35746. if (bits === 1) {
  35747. for (i = 0; i < rowBytes; ++i) {
  35748. var c = rawBytes[i];
  35749. inbuf = (inbuf << 8) | c;
  35750. // bitwise addition is exclusive or
  35751. // first shift inbuf and then add
  35752. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35753. // truncate inbuf (assumes colors < 16)
  35754. inbuf &= 0xFFFF;
  35755. }
  35756. } else if (bits === 8) {
  35757. for (i = 0; i < colors; ++i) {
  35758. buffer[pos++] = rawBytes[i];
  35759. }
  35760. for (; i < rowBytes; ++i) {
  35761. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35762. pos++;
  35763. }
  35764. } else {
  35765. var compArray = new Uint8Array(colors + 1);
  35766. var bitMask = (1 << bits) - 1;
  35767. var j = 0, k = bufferLength;
  35768. var columns = this.columns;
  35769. for (i = 0; i < columns; ++i) {
  35770. for (var kk = 0; kk < colors; ++kk) {
  35771. if (inbits < bits) {
  35772. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35773. inbits += 8;
  35774. }
  35775. compArray[kk] = (compArray[kk] +
  35776. (inbuf >> (inbits - bits))) & bitMask;
  35777. inbits -= bits;
  35778. outbuf = (outbuf << bits) | compArray[kk];
  35779. outbits += bits;
  35780. if (outbits >= 8) {
  35781. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35782. outbits -= 8;
  35783. }
  35784. }
  35785. }
  35786. if (outbits > 0) {
  35787. buffer[k++] = (outbuf << (8 - outbits)) +
  35788. (inbuf & ((1 << (8 - outbits)) - 1));
  35789. }
  35790. }
  35791. this.bufferLength += rowBytes;
  35792. };
  35793. PredictorStream.prototype.readBlockPng =
  35794. function predictorStreamReadBlockPng() {
  35795. var rowBytes = this.rowBytes;
  35796. var pixBytes = this.pixBytes;
  35797. var predictor = this.str.getByte();
  35798. var rawBytes = this.str.getBytes(rowBytes);
  35799. this.eof = !rawBytes.length;
  35800. if (this.eof) {
  35801. return;
  35802. }
  35803. var bufferLength = this.bufferLength;
  35804. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35805. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35806. if (prevRow.length === 0) {
  35807. prevRow = new Uint8Array(rowBytes);
  35808. }
  35809. var i, j = bufferLength, up, c;
  35810. switch (predictor) {
  35811. case 0:
  35812. for (i = 0; i < rowBytes; ++i) {
  35813. buffer[j++] = rawBytes[i];
  35814. }
  35815. break;
  35816. case 1:
  35817. for (i = 0; i < pixBytes; ++i) {
  35818. buffer[j++] = rawBytes[i];
  35819. }
  35820. for (; i < rowBytes; ++i) {
  35821. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35822. j++;
  35823. }
  35824. break;
  35825. case 2:
  35826. for (i = 0; i < rowBytes; ++i) {
  35827. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35828. }
  35829. break;
  35830. case 3:
  35831. for (i = 0; i < pixBytes; ++i) {
  35832. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35833. }
  35834. for (; i < rowBytes; ++i) {
  35835. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35836. rawBytes[i]) & 0xFF;
  35837. j++;
  35838. }
  35839. break;
  35840. case 4:
  35841. // we need to save the up left pixels values. the simplest way
  35842. // is to create a new buffer
  35843. for (i = 0; i < pixBytes; ++i) {
  35844. up = prevRow[i];
  35845. c = rawBytes[i];
  35846. buffer[j++] = up + c;
  35847. }
  35848. for (; i < rowBytes; ++i) {
  35849. up = prevRow[i];
  35850. var upLeft = prevRow[i - pixBytes];
  35851. var left = buffer[j - pixBytes];
  35852. var p = left + up - upLeft;
  35853. var pa = p - left;
  35854. if (pa < 0) {
  35855. pa = -pa;
  35856. }
  35857. var pb = p - up;
  35858. if (pb < 0) {
  35859. pb = -pb;
  35860. }
  35861. var pc = p - upLeft;
  35862. if (pc < 0) {
  35863. pc = -pc;
  35864. }
  35865. c = rawBytes[i];
  35866. if (pa <= pb && pa <= pc) {
  35867. buffer[j++] = left + c;
  35868. } else if (pb <= pc) {
  35869. buffer[j++] = up + c;
  35870. } else {
  35871. buffer[j++] = upLeft + c;
  35872. }
  35873. }
  35874. break;
  35875. default:
  35876. error('Unsupported predictor: ' + predictor);
  35877. }
  35878. this.bufferLength += rowBytes;
  35879. };
  35880. return PredictorStream;
  35881. })();
  35882. /**
  35883. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35884. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35885. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35886. * a library to decode these images and the stream behaves like all the other
  35887. * DecodeStreams.
  35888. */
  35889. var JpegStream = (function JpegStreamClosure() {
  35890. function JpegStream(stream, maybeLength, dict, xref) {
  35891. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  35892. // Note: this seems to mainly affect inline images.
  35893. var ch;
  35894. while ((ch = stream.getByte()) !== -1) {
  35895. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  35896. stream.skip(-1); // Reset the stream position to the SOI.
  35897. break;
  35898. }
  35899. }
  35900. this.stream = stream;
  35901. this.maybeLength = maybeLength;
  35902. this.dict = dict;
  35903. DecodeStream.call(this, maybeLength);
  35904. }
  35905. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35906. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35907. get: function JpegStream_bytes() {
  35908. // If this.maybeLength is null, we'll get the entire stream.
  35909. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35910. },
  35911. configurable: true
  35912. });
  35913. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35914. if (this.bufferLength) {
  35915. return;
  35916. }
  35917. try {
  35918. var jpegImage = new JpegImage();
  35919. // checking if values needs to be transformed before conversion
  35920. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  35921. var decodeArr = this.dict.get('Decode');
  35922. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35923. var decodeArrLength = decodeArr.length;
  35924. var transform = new Int32Array(decodeArrLength);
  35925. var transformNeeded = false;
  35926. var maxValue = (1 << bitsPerComponent) - 1;
  35927. for (var i = 0; i < decodeArrLength; i += 2) {
  35928. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35929. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35930. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35931. transformNeeded = true;
  35932. }
  35933. }
  35934. if (transformNeeded) {
  35935. jpegImage.decodeTransform = transform;
  35936. }
  35937. }
  35938. jpegImage.parse(this.bytes);
  35939. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  35940. this.forceRGB);
  35941. this.buffer = data;
  35942. this.bufferLength = data.length;
  35943. this.eof = true;
  35944. } catch (e) {
  35945. error('JPEG error: ' + e);
  35946. }
  35947. };
  35948. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  35949. this.ensureBuffer();
  35950. return this.buffer;
  35951. };
  35952. JpegStream.prototype.getIR = function JpegStream_getIR() {
  35953. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  35954. };
  35955. /**
  35956. * Checks if the image can be decoded and displayed by the browser without any
  35957. * further processing such as color space conversions.
  35958. */
  35959. JpegStream.prototype.isNativelySupported =
  35960. function JpegStream_isNativelySupported(xref, res) {
  35961. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35962. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  35963. };
  35964. /**
  35965. * Checks if the image can be decoded by the browser.
  35966. */
  35967. JpegStream.prototype.isNativelyDecodable =
  35968. function JpegStream_isNativelyDecodable(xref, res) {
  35969. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35970. var numComps = cs.numComps;
  35971. return numComps === 1 || numComps === 3;
  35972. };
  35973. return JpegStream;
  35974. })();
  35975. /**
  35976. * For JPEG 2000's we use a library to decode these images and
  35977. * the stream behaves like all the other DecodeStreams.
  35978. */
  35979. var JpxStream = (function JpxStreamClosure() {
  35980. function JpxStream(stream, maybeLength, dict) {
  35981. this.stream = stream;
  35982. this.maybeLength = maybeLength;
  35983. this.dict = dict;
  35984. DecodeStream.call(this, maybeLength);
  35985. }
  35986. JpxStream.prototype = Object.create(DecodeStream.prototype);
  35987. Object.defineProperty(JpxStream.prototype, 'bytes', {
  35988. get: function JpxStream_bytes() {
  35989. // If this.maybeLength is null, we'll get the entire stream.
  35990. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35991. },
  35992. configurable: true
  35993. });
  35994. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  35995. if (this.bufferLength) {
  35996. return;
  35997. }
  35998. var jpxImage = new JpxImage();
  35999. jpxImage.parse(this.bytes);
  36000. var width = jpxImage.width;
  36001. var height = jpxImage.height;
  36002. var componentsCount = jpxImage.componentsCount;
  36003. var tileCount = jpxImage.tiles.length;
  36004. if (tileCount === 1) {
  36005. this.buffer = jpxImage.tiles[0].items;
  36006. } else {
  36007. var data = new Uint8Array(width * height * componentsCount);
  36008. for (var k = 0; k < tileCount; k++) {
  36009. var tileComponents = jpxImage.tiles[k];
  36010. var tileWidth = tileComponents.width;
  36011. var tileHeight = tileComponents.height;
  36012. var tileLeft = tileComponents.left;
  36013. var tileTop = tileComponents.top;
  36014. var src = tileComponents.items;
  36015. var srcPosition = 0;
  36016. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  36017. var imgRowSize = width * componentsCount;
  36018. var tileRowSize = tileWidth * componentsCount;
  36019. for (var j = 0; j < tileHeight; j++) {
  36020. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  36021. data.set(rowBytes, dataPosition);
  36022. srcPosition += tileRowSize;
  36023. dataPosition += imgRowSize;
  36024. }
  36025. }
  36026. this.buffer = data;
  36027. }
  36028. this.bufferLength = this.buffer.length;
  36029. this.eof = true;
  36030. };
  36031. return JpxStream;
  36032. })();
  36033. /**
  36034. * For JBIG2's we use a library to decode these images and
  36035. * the stream behaves like all the other DecodeStreams.
  36036. */
  36037. var Jbig2Stream = (function Jbig2StreamClosure() {
  36038. function Jbig2Stream(stream, maybeLength, dict) {
  36039. this.stream = stream;
  36040. this.maybeLength = maybeLength;
  36041. this.dict = dict;
  36042. DecodeStream.call(this, maybeLength);
  36043. }
  36044. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  36045. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  36046. get: function Jbig2Stream_bytes() {
  36047. // If this.maybeLength is null, we'll get the entire stream.
  36048. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  36049. },
  36050. configurable: true
  36051. });
  36052. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  36053. if (this.bufferLength) {
  36054. return;
  36055. }
  36056. var jbig2Image = new Jbig2Image();
  36057. var chunks = [], xref = this.dict.xref;
  36058. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  36059. // According to the PDF specification, DecodeParms can be either
  36060. // a dictionary, or an array whose elements are dictionaries.
  36061. if (isArray(decodeParams)) {
  36062. if (decodeParams.length > 1) {
  36063. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  36064. 'not supported.');
  36065. }
  36066. decodeParams = xref.fetchIfRef(decodeParams[0]);
  36067. }
  36068. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  36069. var globalsStream = decodeParams.get('JBIG2Globals');
  36070. var globals = globalsStream.getBytes();
  36071. chunks.push({data: globals, start: 0, end: globals.length});
  36072. }
  36073. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  36074. var data = jbig2Image.parseChunks(chunks);
  36075. var dataLength = data.length;
  36076. // JBIG2 had black as 1 and white as 0, inverting the colors
  36077. for (var i = 0; i < dataLength; i++) {
  36078. data[i] ^= 0xFF;
  36079. }
  36080. this.buffer = data;
  36081. this.bufferLength = dataLength;
  36082. this.eof = true;
  36083. };
  36084. return Jbig2Stream;
  36085. })();
  36086. var DecryptStream = (function DecryptStreamClosure() {
  36087. function DecryptStream(str, maybeLength, decrypt) {
  36088. this.str = str;
  36089. this.dict = str.dict;
  36090. this.decrypt = decrypt;
  36091. this.nextChunk = null;
  36092. this.initialized = false;
  36093. DecodeStream.call(this, maybeLength);
  36094. }
  36095. var chunkSize = 512;
  36096. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  36097. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  36098. var chunk;
  36099. if (this.initialized) {
  36100. chunk = this.nextChunk;
  36101. } else {
  36102. chunk = this.str.getBytes(chunkSize);
  36103. this.initialized = true;
  36104. }
  36105. if (!chunk || chunk.length === 0) {
  36106. this.eof = true;
  36107. return;
  36108. }
  36109. this.nextChunk = this.str.getBytes(chunkSize);
  36110. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  36111. var decrypt = this.decrypt;
  36112. chunk = decrypt(chunk, !hasMoreData);
  36113. var bufferLength = this.bufferLength;
  36114. var i, n = chunk.length;
  36115. var buffer = this.ensureBuffer(bufferLength + n);
  36116. for (i = 0; i < n; i++) {
  36117. buffer[bufferLength++] = chunk[i];
  36118. }
  36119. this.bufferLength = bufferLength;
  36120. };
  36121. return DecryptStream;
  36122. })();
  36123. var Ascii85Stream = (function Ascii85StreamClosure() {
  36124. function Ascii85Stream(str, maybeLength) {
  36125. this.str = str;
  36126. this.dict = str.dict;
  36127. this.input = new Uint8Array(5);
  36128. // Most streams increase in size when decoded, but Ascii85 streams
  36129. // typically shrink by ~20%.
  36130. if (maybeLength) {
  36131. maybeLength = 0.8 * maybeLength;
  36132. }
  36133. DecodeStream.call(this, maybeLength);
  36134. }
  36135. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  36136. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  36137. var TILDA_CHAR = 0x7E; // '~'
  36138. var Z_LOWER_CHAR = 0x7A; // 'z'
  36139. var EOF = -1;
  36140. var str = this.str;
  36141. var c = str.getByte();
  36142. while (Lexer.isSpace(c)) {
  36143. c = str.getByte();
  36144. }
  36145. if (c === EOF || c === TILDA_CHAR) {
  36146. this.eof = true;
  36147. return;
  36148. }
  36149. var bufferLength = this.bufferLength, buffer;
  36150. var i;
  36151. // special code for z
  36152. if (c === Z_LOWER_CHAR) {
  36153. buffer = this.ensureBuffer(bufferLength + 4);
  36154. for (i = 0; i < 4; ++i) {
  36155. buffer[bufferLength + i] = 0;
  36156. }
  36157. this.bufferLength += 4;
  36158. } else {
  36159. var input = this.input;
  36160. input[0] = c;
  36161. for (i = 1; i < 5; ++i) {
  36162. c = str.getByte();
  36163. while (Lexer.isSpace(c)) {
  36164. c = str.getByte();
  36165. }
  36166. input[i] = c;
  36167. if (c === EOF || c === TILDA_CHAR) {
  36168. break;
  36169. }
  36170. }
  36171. buffer = this.ensureBuffer(bufferLength + i - 1);
  36172. this.bufferLength += i - 1;
  36173. // partial ending;
  36174. if (i < 5) {
  36175. for (; i < 5; ++i) {
  36176. input[i] = 0x21 + 84;
  36177. }
  36178. this.eof = true;
  36179. }
  36180. var t = 0;
  36181. for (i = 0; i < 5; ++i) {
  36182. t = t * 85 + (input[i] - 0x21);
  36183. }
  36184. for (i = 3; i >= 0; --i) {
  36185. buffer[bufferLength + i] = t & 0xFF;
  36186. t >>= 8;
  36187. }
  36188. }
  36189. };
  36190. return Ascii85Stream;
  36191. })();
  36192. var AsciiHexStream = (function AsciiHexStreamClosure() {
  36193. function AsciiHexStream(str, maybeLength) {
  36194. this.str = str;
  36195. this.dict = str.dict;
  36196. this.firstDigit = -1;
  36197. // Most streams increase in size when decoded, but AsciiHex streams shrink
  36198. // by 50%.
  36199. if (maybeLength) {
  36200. maybeLength = 0.5 * maybeLength;
  36201. }
  36202. DecodeStream.call(this, maybeLength);
  36203. }
  36204. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  36205. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  36206. var UPSTREAM_BLOCK_SIZE = 8000;
  36207. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  36208. if (!bytes.length) {
  36209. this.eof = true;
  36210. return;
  36211. }
  36212. var maxDecodeLength = (bytes.length + 1) >> 1;
  36213. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  36214. var bufferLength = this.bufferLength;
  36215. var firstDigit = this.firstDigit;
  36216. for (var i = 0, ii = bytes.length; i < ii; i++) {
  36217. var ch = bytes[i], digit;
  36218. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  36219. digit = ch & 0x0F;
  36220. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  36221. // 'A'-'Z', 'a'-'z'
  36222. digit = (ch & 0x0F) + 9;
  36223. } else if (ch === 0x3E) { // '>'
  36224. this.eof = true;
  36225. break;
  36226. } else { // probably whitespace
  36227. continue; // ignoring
  36228. }
  36229. if (firstDigit < 0) {
  36230. firstDigit = digit;
  36231. } else {
  36232. buffer[bufferLength++] = (firstDigit << 4) | digit;
  36233. firstDigit = -1;
  36234. }
  36235. }
  36236. if (firstDigit >= 0 && this.eof) {
  36237. // incomplete byte
  36238. buffer[bufferLength++] = (firstDigit << 4);
  36239. firstDigit = -1;
  36240. }
  36241. this.firstDigit = firstDigit;
  36242. this.bufferLength = bufferLength;
  36243. };
  36244. return AsciiHexStream;
  36245. })();
  36246. var RunLengthStream = (function RunLengthStreamClosure() {
  36247. function RunLengthStream(str, maybeLength) {
  36248. this.str = str;
  36249. this.dict = str.dict;
  36250. DecodeStream.call(this, maybeLength);
  36251. }
  36252. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  36253. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  36254. // The repeatHeader has following format. The first byte defines type of run
  36255. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  36256. // (in addition to the second byte from the header), n = 129 through 255 -
  36257. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  36258. var repeatHeader = this.str.getBytes(2);
  36259. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  36260. this.eof = true;
  36261. return;
  36262. }
  36263. var buffer;
  36264. var bufferLength = this.bufferLength;
  36265. var n = repeatHeader[0];
  36266. if (n < 128) {
  36267. // copy n bytes
  36268. buffer = this.ensureBuffer(bufferLength + n + 1);
  36269. buffer[bufferLength++] = repeatHeader[1];
  36270. if (n > 0) {
  36271. var source = this.str.getBytes(n);
  36272. buffer.set(source, bufferLength);
  36273. bufferLength += n;
  36274. }
  36275. } else {
  36276. n = 257 - n;
  36277. var b = repeatHeader[1];
  36278. buffer = this.ensureBuffer(bufferLength + n + 1);
  36279. for (var i = 0; i < n; i++) {
  36280. buffer[bufferLength++] = b;
  36281. }
  36282. }
  36283. this.bufferLength = bufferLength;
  36284. };
  36285. return RunLengthStream;
  36286. })();
  36287. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  36288. var ccittEOL = -2;
  36289. var twoDimPass = 0;
  36290. var twoDimHoriz = 1;
  36291. var twoDimVert0 = 2;
  36292. var twoDimVertR1 = 3;
  36293. var twoDimVertL1 = 4;
  36294. var twoDimVertR2 = 5;
  36295. var twoDimVertL2 = 6;
  36296. var twoDimVertR3 = 7;
  36297. var twoDimVertL3 = 8;
  36298. var twoDimTable = [
  36299. [-1, -1], [-1, -1], // 000000x
  36300. [7, twoDimVertL3], // 0000010
  36301. [7, twoDimVertR3], // 0000011
  36302. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  36303. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  36304. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  36305. [4, twoDimPass], [4, twoDimPass],
  36306. [4, twoDimPass], [4, twoDimPass],
  36307. [4, twoDimPass], [4, twoDimPass],
  36308. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  36309. [3, twoDimHoriz], [3, twoDimHoriz],
  36310. [3, twoDimHoriz], [3, twoDimHoriz],
  36311. [3, twoDimHoriz], [3, twoDimHoriz],
  36312. [3, twoDimHoriz], [3, twoDimHoriz],
  36313. [3, twoDimHoriz], [3, twoDimHoriz],
  36314. [3, twoDimHoriz], [3, twoDimHoriz],
  36315. [3, twoDimHoriz], [3, twoDimHoriz],
  36316. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  36317. [3, twoDimVertL1], [3, twoDimVertL1],
  36318. [3, twoDimVertL1], [3, twoDimVertL1],
  36319. [3, twoDimVertL1], [3, twoDimVertL1],
  36320. [3, twoDimVertL1], [3, twoDimVertL1],
  36321. [3, twoDimVertL1], [3, twoDimVertL1],
  36322. [3, twoDimVertL1], [3, twoDimVertL1],
  36323. [3, twoDimVertL1], [3, twoDimVertL1],
  36324. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  36325. [3, twoDimVertR1], [3, twoDimVertR1],
  36326. [3, twoDimVertR1], [3, twoDimVertR1],
  36327. [3, twoDimVertR1], [3, twoDimVertR1],
  36328. [3, twoDimVertR1], [3, twoDimVertR1],
  36329. [3, twoDimVertR1], [3, twoDimVertR1],
  36330. [3, twoDimVertR1], [3, twoDimVertR1],
  36331. [3, twoDimVertR1], [3, twoDimVertR1],
  36332. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  36333. [1, twoDimVert0], [1, twoDimVert0],
  36334. [1, twoDimVert0], [1, twoDimVert0],
  36335. [1, twoDimVert0], [1, twoDimVert0],
  36336. [1, twoDimVert0], [1, twoDimVert0],
  36337. [1, twoDimVert0], [1, twoDimVert0],
  36338. [1, twoDimVert0], [1, twoDimVert0],
  36339. [1, twoDimVert0], [1, twoDimVert0],
  36340. [1, twoDimVert0], [1, twoDimVert0],
  36341. [1, twoDimVert0], [1, twoDimVert0],
  36342. [1, twoDimVert0], [1, twoDimVert0],
  36343. [1, twoDimVert0], [1, twoDimVert0],
  36344. [1, twoDimVert0], [1, twoDimVert0],
  36345. [1, twoDimVert0], [1, twoDimVert0],
  36346. [1, twoDimVert0], [1, twoDimVert0],
  36347. [1, twoDimVert0], [1, twoDimVert0],
  36348. [1, twoDimVert0], [1, twoDimVert0],
  36349. [1, twoDimVert0], [1, twoDimVert0],
  36350. [1, twoDimVert0], [1, twoDimVert0],
  36351. [1, twoDimVert0], [1, twoDimVert0],
  36352. [1, twoDimVert0], [1, twoDimVert0],
  36353. [1, twoDimVert0], [1, twoDimVert0],
  36354. [1, twoDimVert0], [1, twoDimVert0],
  36355. [1, twoDimVert0], [1, twoDimVert0],
  36356. [1, twoDimVert0], [1, twoDimVert0],
  36357. [1, twoDimVert0], [1, twoDimVert0],
  36358. [1, twoDimVert0], [1, twoDimVert0],
  36359. [1, twoDimVert0], [1, twoDimVert0],
  36360. [1, twoDimVert0], [1, twoDimVert0],
  36361. [1, twoDimVert0], [1, twoDimVert0],
  36362. [1, twoDimVert0], [1, twoDimVert0],
  36363. [1, twoDimVert0], [1, twoDimVert0]
  36364. ];
  36365. var whiteTable1 = [
  36366. [-1, -1], // 00000
  36367. [12, ccittEOL], // 00001
  36368. [-1, -1], [-1, -1], // 0001x
  36369. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  36370. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  36371. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  36372. [11, 1792], [11, 1792], // 1000x
  36373. [12, 1984], // 10010
  36374. [12, 2048], // 10011
  36375. [12, 2112], // 10100
  36376. [12, 2176], // 10101
  36377. [12, 2240], // 10110
  36378. [12, 2304], // 10111
  36379. [11, 1856], [11, 1856], // 1100x
  36380. [11, 1920], [11, 1920], // 1101x
  36381. [12, 2368], // 11100
  36382. [12, 2432], // 11101
  36383. [12, 2496], // 11110
  36384. [12, 2560] // 11111
  36385. ];
  36386. var whiteTable2 = [
  36387. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  36388. [8, 29], [8, 29], // 00000010x
  36389. [8, 30], [8, 30], // 00000011x
  36390. [8, 45], [8, 45], // 00000100x
  36391. [8, 46], [8, 46], // 00000101x
  36392. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  36393. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  36394. [8, 47], [8, 47], // 00001010x
  36395. [8, 48], [8, 48], // 00001011x
  36396. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  36397. [6, 13], [6, 13], [6, 13], [6, 13],
  36398. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  36399. [8, 33], [8, 33], // 00010010x
  36400. [8, 34], [8, 34], // 00010011x
  36401. [8, 35], [8, 35], // 00010100x
  36402. [8, 36], [8, 36], // 00010101x
  36403. [8, 37], [8, 37], // 00010110x
  36404. [8, 38], [8, 38], // 00010111x
  36405. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  36406. [8, 31], [8, 31], // 00011010x
  36407. [8, 32], [8, 32], // 00011011x
  36408. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  36409. [6, 1], [6, 1], [6, 1], [6, 1],
  36410. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  36411. [6, 12], [6, 12], [6, 12], [6, 12],
  36412. [8, 53], [8, 53], // 00100100x
  36413. [8, 54], [8, 54], // 00100101x
  36414. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  36415. [8, 39], [8, 39], // 00101000x
  36416. [8, 40], [8, 40], // 00101001x
  36417. [8, 41], [8, 41], // 00101010x
  36418. [8, 42], [8, 42], // 00101011x
  36419. [8, 43], [8, 43], // 00101100x
  36420. [8, 44], [8, 44], // 00101101x
  36421. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  36422. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  36423. [8, 61], [8, 61], // 00110010x
  36424. [8, 62], [8, 62], // 00110011x
  36425. [8, 63], [8, 63], // 00110100x
  36426. [8, 0], [8, 0], // 00110101x
  36427. [8, 320], [8, 320], // 00110110x
  36428. [8, 384], [8, 384], // 00110111x
  36429. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  36430. [5, 10], [5, 10], [5, 10], [5, 10],
  36431. [5, 10], [5, 10], [5, 10], [5, 10],
  36432. [5, 10], [5, 10], [5, 10], [5, 10],
  36433. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  36434. [5, 11], [5, 11], [5, 11], [5, 11],
  36435. [5, 11], [5, 11], [5, 11], [5, 11],
  36436. [5, 11], [5, 11], [5, 11], [5, 11],
  36437. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  36438. [8, 59], [8, 59], // 01001010x
  36439. [8, 60], [8, 60], // 01001011x
  36440. [9, 1472], // 010011000
  36441. [9, 1536], // 010011001
  36442. [9, 1600], // 010011010
  36443. [9, 1728], // 010011011
  36444. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  36445. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  36446. [8, 49], [8, 49], // 01010010x
  36447. [8, 50], [8, 50], // 01010011x
  36448. [8, 51], [8, 51], // 01010100x
  36449. [8, 52], [8, 52], // 01010101x
  36450. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  36451. [8, 55], [8, 55], // 01011000x
  36452. [8, 56], [8, 56], // 01011001x
  36453. [8, 57], [8, 57], // 01011010x
  36454. [8, 58], [8, 58], // 01011011x
  36455. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  36456. [6, 192], [6, 192], [6, 192], [6, 192],
  36457. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  36458. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  36459. [8, 448], [8, 448], // 01100100x
  36460. [8, 512], [8, 512], // 01100101x
  36461. [9, 704], // 011001100
  36462. [9, 768], // 011001101
  36463. [8, 640], [8, 640], // 01100111x
  36464. [8, 576], [8, 576], // 01101000x
  36465. [9, 832], // 011010010
  36466. [9, 896], // 011010011
  36467. [9, 960], // 011010100
  36468. [9, 1024], // 011010101
  36469. [9, 1088], // 011010110
  36470. [9, 1152], // 011010111
  36471. [9, 1216], // 011011000
  36472. [9, 1280], // 011011001
  36473. [9, 1344], // 011011010
  36474. [9, 1408], // 011011011
  36475. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  36476. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  36477. [4, 2], [4, 2], [4, 2], [4, 2],
  36478. [4, 2], [4, 2], [4, 2], [4, 2],
  36479. [4, 2], [4, 2], [4, 2], [4, 2],
  36480. [4, 2], [4, 2], [4, 2], [4, 2],
  36481. [4, 2], [4, 2], [4, 2], [4, 2],
  36482. [4, 2], [4, 2], [4, 2], [4, 2],
  36483. [4, 2], [4, 2], [4, 2], [4, 2],
  36484. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  36485. [4, 3], [4, 3], [4, 3], [4, 3],
  36486. [4, 3], [4, 3], [4, 3], [4, 3],
  36487. [4, 3], [4, 3], [4, 3], [4, 3],
  36488. [4, 3], [4, 3], [4, 3], [4, 3],
  36489. [4, 3], [4, 3], [4, 3], [4, 3],
  36490. [4, 3], [4, 3], [4, 3], [4, 3],
  36491. [4, 3], [4, 3], [4, 3], [4, 3],
  36492. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  36493. [5, 128], [5, 128], [5, 128], [5, 128],
  36494. [5, 128], [5, 128], [5, 128], [5, 128],
  36495. [5, 128], [5, 128], [5, 128], [5, 128],
  36496. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  36497. [5, 8], [5, 8], [5, 8], [5, 8],
  36498. [5, 8], [5, 8], [5, 8], [5, 8],
  36499. [5, 8], [5, 8], [5, 8], [5, 8],
  36500. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  36501. [5, 9], [5, 9], [5, 9], [5, 9],
  36502. [5, 9], [5, 9], [5, 9], [5, 9],
  36503. [5, 9], [5, 9], [5, 9], [5, 9],
  36504. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  36505. [6, 16], [6, 16], [6, 16], [6, 16],
  36506. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  36507. [6, 17], [6, 17], [6, 17], [6, 17],
  36508. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  36509. [4, 4], [4, 4], [4, 4], [4, 4],
  36510. [4, 4], [4, 4], [4, 4], [4, 4],
  36511. [4, 4], [4, 4], [4, 4], [4, 4],
  36512. [4, 4], [4, 4], [4, 4], [4, 4],
  36513. [4, 4], [4, 4], [4, 4], [4, 4],
  36514. [4, 4], [4, 4], [4, 4], [4, 4],
  36515. [4, 4], [4, 4], [4, 4], [4, 4],
  36516. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  36517. [4, 5], [4, 5], [4, 5], [4, 5],
  36518. [4, 5], [4, 5], [4, 5], [4, 5],
  36519. [4, 5], [4, 5], [4, 5], [4, 5],
  36520. [4, 5], [4, 5], [4, 5], [4, 5],
  36521. [4, 5], [4, 5], [4, 5], [4, 5],
  36522. [4, 5], [4, 5], [4, 5], [4, 5],
  36523. [4, 5], [4, 5], [4, 5], [4, 5],
  36524. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  36525. [6, 14], [6, 14], [6, 14], [6, 14],
  36526. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36527. [6, 15], [6, 15], [6, 15], [6, 15],
  36528. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  36529. [5, 64], [5, 64], [5, 64], [5, 64],
  36530. [5, 64], [5, 64], [5, 64], [5, 64],
  36531. [5, 64], [5, 64], [5, 64], [5, 64],
  36532. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  36533. [4, 6], [4, 6], [4, 6], [4, 6],
  36534. [4, 6], [4, 6], [4, 6], [4, 6],
  36535. [4, 6], [4, 6], [4, 6], [4, 6],
  36536. [4, 6], [4, 6], [4, 6], [4, 6],
  36537. [4, 6], [4, 6], [4, 6], [4, 6],
  36538. [4, 6], [4, 6], [4, 6], [4, 6],
  36539. [4, 6], [4, 6], [4, 6], [4, 6],
  36540. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  36541. [4, 7], [4, 7], [4, 7], [4, 7],
  36542. [4, 7], [4, 7], [4, 7], [4, 7],
  36543. [4, 7], [4, 7], [4, 7], [4, 7],
  36544. [4, 7], [4, 7], [4, 7], [4, 7],
  36545. [4, 7], [4, 7], [4, 7], [4, 7],
  36546. [4, 7], [4, 7], [4, 7], [4, 7],
  36547. [4, 7], [4, 7], [4, 7], [4, 7]
  36548. ];
  36549. var blackTable1 = [
  36550. [-1, -1], [-1, -1], // 000000000000x
  36551. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  36552. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  36553. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  36554. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  36555. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  36556. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  36557. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  36558. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  36559. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  36560. [12, 1984], [12, 1984], // 000000010010x
  36561. [12, 2048], [12, 2048], // 000000010011x
  36562. [12, 2112], [12, 2112], // 000000010100x
  36563. [12, 2176], [12, 2176], // 000000010101x
  36564. [12, 2240], [12, 2240], // 000000010110x
  36565. [12, 2304], [12, 2304], // 000000010111x
  36566. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  36567. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  36568. [12, 2368], [12, 2368], // 000000011100x
  36569. [12, 2432], [12, 2432], // 000000011101x
  36570. [12, 2496], [12, 2496], // 000000011110x
  36571. [12, 2560], [12, 2560], // 000000011111x
  36572. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  36573. [10, 18], [10, 18], [10, 18], [10, 18],
  36574. [12, 52], [12, 52], // 000000100100x
  36575. [13, 640], // 0000001001010
  36576. [13, 704], // 0000001001011
  36577. [13, 768], // 0000001001100
  36578. [13, 832], // 0000001001101
  36579. [12, 55], [12, 55], // 000000100111x
  36580. [12, 56], [12, 56], // 000000101000x
  36581. [13, 1280], // 0000001010010
  36582. [13, 1344], // 0000001010011
  36583. [13, 1408], // 0000001010100
  36584. [13, 1472], // 0000001010101
  36585. [12, 59], [12, 59], // 000000101011x
  36586. [12, 60], [12, 60], // 000000101100x
  36587. [13, 1536], // 0000001011010
  36588. [13, 1600], // 0000001011011
  36589. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  36590. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  36591. [13, 1664], // 0000001100100
  36592. [13, 1728], // 0000001100101
  36593. [12, 320], [12, 320], // 000000110011x
  36594. [12, 384], [12, 384], // 000000110100x
  36595. [12, 448], [12, 448], // 000000110101x
  36596. [13, 512], // 0000001101100
  36597. [13, 576], // 0000001101101
  36598. [12, 53], [12, 53], // 000000110111x
  36599. [12, 54], [12, 54], // 000000111000x
  36600. [13, 896], // 0000001110010
  36601. [13, 960], // 0000001110011
  36602. [13, 1024], // 0000001110100
  36603. [13, 1088], // 0000001110101
  36604. [13, 1152], // 0000001110110
  36605. [13, 1216], // 0000001110111
  36606. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  36607. [10, 64], [10, 64], [10, 64], [10, 64]
  36608. ];
  36609. var blackTable2 = [
  36610. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  36611. [8, 13], [8, 13], [8, 13], [8, 13],
  36612. [8, 13], [8, 13], [8, 13], [8, 13],
  36613. [8, 13], [8, 13], [8, 13], [8, 13],
  36614. [11, 23], [11, 23], // 00000101000x
  36615. [12, 50], // 000001010010
  36616. [12, 51], // 000001010011
  36617. [12, 44], // 000001010100
  36618. [12, 45], // 000001010101
  36619. [12, 46], // 000001010110
  36620. [12, 47], // 000001010111
  36621. [12, 57], // 000001011000
  36622. [12, 58], // 000001011001
  36623. [12, 61], // 000001011010
  36624. [12, 256], // 000001011011
  36625. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  36626. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  36627. [12, 48], // 000001100100
  36628. [12, 49], // 000001100101
  36629. [12, 62], // 000001100110
  36630. [12, 63], // 000001100111
  36631. [12, 30], // 000001101000
  36632. [12, 31], // 000001101001
  36633. [12, 32], // 000001101010
  36634. [12, 33], // 000001101011
  36635. [12, 40], // 000001101100
  36636. [12, 41], // 000001101101
  36637. [11, 22], [11, 22], // 00000110111x
  36638. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  36639. [8, 14], [8, 14], [8, 14], [8, 14],
  36640. [8, 14], [8, 14], [8, 14], [8, 14],
  36641. [8, 14], [8, 14], [8, 14], [8, 14],
  36642. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36643. [7, 10], [7, 10], [7, 10], [7, 10],
  36644. [7, 10], [7, 10], [7, 10], [7, 10],
  36645. [7, 10], [7, 10], [7, 10], [7, 10],
  36646. [7, 10], [7, 10], [7, 10], [7, 10],
  36647. [7, 10], [7, 10], [7, 10], [7, 10],
  36648. [7, 10], [7, 10], [7, 10], [7, 10],
  36649. [7, 10], [7, 10], [7, 10], [7, 10],
  36650. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36651. [7, 11], [7, 11], [7, 11], [7, 11],
  36652. [7, 11], [7, 11], [7, 11], [7, 11],
  36653. [7, 11], [7, 11], [7, 11], [7, 11],
  36654. [7, 11], [7, 11], [7, 11], [7, 11],
  36655. [7, 11], [7, 11], [7, 11], [7, 11],
  36656. [7, 11], [7, 11], [7, 11], [7, 11],
  36657. [7, 11], [7, 11], [7, 11], [7, 11],
  36658. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36659. [9, 15], [9, 15], [9, 15], [9, 15],
  36660. [12, 128], // 000011001000
  36661. [12, 192], // 000011001001
  36662. [12, 26], // 000011001010
  36663. [12, 27], // 000011001011
  36664. [12, 28], // 000011001100
  36665. [12, 29], // 000011001101
  36666. [11, 19], [11, 19], // 00001100111x
  36667. [11, 20], [11, 20], // 00001101000x
  36668. [12, 34], // 000011010010
  36669. [12, 35], // 000011010011
  36670. [12, 36], // 000011010100
  36671. [12, 37], // 000011010101
  36672. [12, 38], // 000011010110
  36673. [12, 39], // 000011010111
  36674. [11, 21], [11, 21], // 00001101100x
  36675. [12, 42], // 000011011010
  36676. [12, 43], // 000011011011
  36677. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36678. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36679. [7, 12], [7, 12], [7, 12], [7, 12],
  36680. [7, 12], [7, 12], [7, 12], [7, 12],
  36681. [7, 12], [7, 12], [7, 12], [7, 12],
  36682. [7, 12], [7, 12], [7, 12], [7, 12],
  36683. [7, 12], [7, 12], [7, 12], [7, 12],
  36684. [7, 12], [7, 12], [7, 12], [7, 12],
  36685. [7, 12], [7, 12], [7, 12], [7, 12]
  36686. ];
  36687. var blackTable3 = [
  36688. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36689. [6, 9], // 000100
  36690. [6, 8], // 000101
  36691. [5, 7], [5, 7], // 00011x
  36692. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36693. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36694. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36695. [3, 1], [3, 1], [3, 1], [3, 1],
  36696. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36697. [3, 4], [3, 4], [3, 4], [3, 4],
  36698. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36699. [2, 3], [2, 3], [2, 3], [2, 3],
  36700. [2, 3], [2, 3], [2, 3], [2, 3],
  36701. [2, 3], [2, 3], [2, 3], [2, 3],
  36702. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36703. [2, 2], [2, 2], [2, 2], [2, 2],
  36704. [2, 2], [2, 2], [2, 2], [2, 2],
  36705. [2, 2], [2, 2], [2, 2], [2, 2]
  36706. ];
  36707. function CCITTFaxStream(str, maybeLength, params) {
  36708. this.str = str;
  36709. this.dict = str.dict;
  36710. params = params || Dict.empty;
  36711. this.encoding = params.get('K') || 0;
  36712. this.eoline = params.get('EndOfLine') || false;
  36713. this.byteAlign = params.get('EncodedByteAlign') || false;
  36714. this.columns = params.get('Columns') || 1728;
  36715. this.rows = params.get('Rows') || 0;
  36716. var eoblock = params.get('EndOfBlock');
  36717. if (eoblock === null || eoblock === undefined) {
  36718. eoblock = true;
  36719. }
  36720. this.eoblock = eoblock;
  36721. this.black = params.get('BlackIs1') || false;
  36722. this.codingLine = new Uint32Array(this.columns + 1);
  36723. this.refLine = new Uint32Array(this.columns + 2);
  36724. this.codingLine[0] = this.columns;
  36725. this.codingPos = 0;
  36726. this.row = 0;
  36727. this.nextLine2D = this.encoding < 0;
  36728. this.inputBits = 0;
  36729. this.inputBuf = 0;
  36730. this.outputBits = 0;
  36731. var code1;
  36732. while ((code1 = this.lookBits(12)) === 0) {
  36733. this.eatBits(1);
  36734. }
  36735. if (code1 === 1) {
  36736. this.eatBits(12);
  36737. }
  36738. if (this.encoding > 0) {
  36739. this.nextLine2D = !this.lookBits(1);
  36740. this.eatBits(1);
  36741. }
  36742. DecodeStream.call(this, maybeLength);
  36743. }
  36744. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36745. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36746. while (!this.eof) {
  36747. var c = this.lookChar();
  36748. this.ensureBuffer(this.bufferLength + 1);
  36749. this.buffer[this.bufferLength++] = c;
  36750. }
  36751. };
  36752. CCITTFaxStream.prototype.addPixels =
  36753. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36754. var codingLine = this.codingLine;
  36755. var codingPos = this.codingPos;
  36756. if (a1 > codingLine[codingPos]) {
  36757. if (a1 > this.columns) {
  36758. info('row is wrong length');
  36759. this.err = true;
  36760. a1 = this.columns;
  36761. }
  36762. if ((codingPos & 1) ^ blackPixels) {
  36763. ++codingPos;
  36764. }
  36765. codingLine[codingPos] = a1;
  36766. }
  36767. this.codingPos = codingPos;
  36768. };
  36769. CCITTFaxStream.prototype.addPixelsNeg =
  36770. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36771. var codingLine = this.codingLine;
  36772. var codingPos = this.codingPos;
  36773. if (a1 > codingLine[codingPos]) {
  36774. if (a1 > this.columns) {
  36775. info('row is wrong length');
  36776. this.err = true;
  36777. a1 = this.columns;
  36778. }
  36779. if ((codingPos & 1) ^ blackPixels) {
  36780. ++codingPos;
  36781. }
  36782. codingLine[codingPos] = a1;
  36783. } else if (a1 < codingLine[codingPos]) {
  36784. if (a1 < 0) {
  36785. info('invalid code');
  36786. this.err = true;
  36787. a1 = 0;
  36788. }
  36789. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36790. --codingPos;
  36791. }
  36792. codingLine[codingPos] = a1;
  36793. }
  36794. this.codingPos = codingPos;
  36795. };
  36796. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36797. var refLine = this.refLine;
  36798. var codingLine = this.codingLine;
  36799. var columns = this.columns;
  36800. var refPos, blackPixels, bits, i;
  36801. if (this.outputBits === 0) {
  36802. if (this.eof) {
  36803. return null;
  36804. }
  36805. this.err = false;
  36806. var code1, code2, code3;
  36807. if (this.nextLine2D) {
  36808. for (i = 0; codingLine[i] < columns; ++i) {
  36809. refLine[i] = codingLine[i];
  36810. }
  36811. refLine[i++] = columns;
  36812. refLine[i] = columns;
  36813. codingLine[0] = 0;
  36814. this.codingPos = 0;
  36815. refPos = 0;
  36816. blackPixels = 0;
  36817. while (codingLine[this.codingPos] < columns) {
  36818. code1 = this.getTwoDimCode();
  36819. switch (code1) {
  36820. case twoDimPass:
  36821. this.addPixels(refLine[refPos + 1], blackPixels);
  36822. if (refLine[refPos + 1] < columns) {
  36823. refPos += 2;
  36824. }
  36825. break;
  36826. case twoDimHoriz:
  36827. code1 = code2 = 0;
  36828. if (blackPixels) {
  36829. do {
  36830. code1 += (code3 = this.getBlackCode());
  36831. } while (code3 >= 64);
  36832. do {
  36833. code2 += (code3 = this.getWhiteCode());
  36834. } while (code3 >= 64);
  36835. } else {
  36836. do {
  36837. code1 += (code3 = this.getWhiteCode());
  36838. } while (code3 >= 64);
  36839. do {
  36840. code2 += (code3 = this.getBlackCode());
  36841. } while (code3 >= 64);
  36842. }
  36843. this.addPixels(codingLine[this.codingPos] +
  36844. code1, blackPixels);
  36845. if (codingLine[this.codingPos] < columns) {
  36846. this.addPixels(codingLine[this.codingPos] + code2,
  36847. blackPixels ^ 1);
  36848. }
  36849. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36850. refLine[refPos] < columns) {
  36851. refPos += 2;
  36852. }
  36853. break;
  36854. case twoDimVertR3:
  36855. this.addPixels(refLine[refPos] + 3, blackPixels);
  36856. blackPixels ^= 1;
  36857. if (codingLine[this.codingPos] < columns) {
  36858. ++refPos;
  36859. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36860. refLine[refPos] < columns) {
  36861. refPos += 2;
  36862. }
  36863. }
  36864. break;
  36865. case twoDimVertR2:
  36866. this.addPixels(refLine[refPos] + 2, blackPixels);
  36867. blackPixels ^= 1;
  36868. if (codingLine[this.codingPos] < columns) {
  36869. ++refPos;
  36870. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36871. refLine[refPos] < columns) {
  36872. refPos += 2;
  36873. }
  36874. }
  36875. break;
  36876. case twoDimVertR1:
  36877. this.addPixels(refLine[refPos] + 1, blackPixels);
  36878. blackPixels ^= 1;
  36879. if (codingLine[this.codingPos] < columns) {
  36880. ++refPos;
  36881. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36882. refLine[refPos] < columns) {
  36883. refPos += 2;
  36884. }
  36885. }
  36886. break;
  36887. case twoDimVert0:
  36888. this.addPixels(refLine[refPos], blackPixels);
  36889. blackPixels ^= 1;
  36890. if (codingLine[this.codingPos] < columns) {
  36891. ++refPos;
  36892. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36893. refLine[refPos] < columns) {
  36894. refPos += 2;
  36895. }
  36896. }
  36897. break;
  36898. case twoDimVertL3:
  36899. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36900. blackPixels ^= 1;
  36901. if (codingLine[this.codingPos] < columns) {
  36902. if (refPos > 0) {
  36903. --refPos;
  36904. } else {
  36905. ++refPos;
  36906. }
  36907. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36908. refLine[refPos] < columns) {
  36909. refPos += 2;
  36910. }
  36911. }
  36912. break;
  36913. case twoDimVertL2:
  36914. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36915. blackPixels ^= 1;
  36916. if (codingLine[this.codingPos] < columns) {
  36917. if (refPos > 0) {
  36918. --refPos;
  36919. } else {
  36920. ++refPos;
  36921. }
  36922. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36923. refLine[refPos] < columns) {
  36924. refPos += 2;
  36925. }
  36926. }
  36927. break;
  36928. case twoDimVertL1:
  36929. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36930. blackPixels ^= 1;
  36931. if (codingLine[this.codingPos] < columns) {
  36932. if (refPos > 0) {
  36933. --refPos;
  36934. } else {
  36935. ++refPos;
  36936. }
  36937. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36938. refLine[refPos] < columns) {
  36939. refPos += 2;
  36940. }
  36941. }
  36942. break;
  36943. case EOF:
  36944. this.addPixels(columns, 0);
  36945. this.eof = true;
  36946. break;
  36947. default:
  36948. info('bad 2d code');
  36949. this.addPixels(columns, 0);
  36950. this.err = true;
  36951. }
  36952. }
  36953. } else {
  36954. codingLine[0] = 0;
  36955. this.codingPos = 0;
  36956. blackPixels = 0;
  36957. while (codingLine[this.codingPos] < columns) {
  36958. code1 = 0;
  36959. if (blackPixels) {
  36960. do {
  36961. code1 += (code3 = this.getBlackCode());
  36962. } while (code3 >= 64);
  36963. } else {
  36964. do {
  36965. code1 += (code3 = this.getWhiteCode());
  36966. } while (code3 >= 64);
  36967. }
  36968. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  36969. blackPixels ^= 1;
  36970. }
  36971. }
  36972. var gotEOL = false;
  36973. if (this.byteAlign) {
  36974. this.inputBits &= ~7;
  36975. }
  36976. if (!this.eoblock && this.row === this.rows - 1) {
  36977. this.eof = true;
  36978. } else {
  36979. code1 = this.lookBits(12);
  36980. if (this.eoline) {
  36981. while (code1 !== EOF && code1 !== 1) {
  36982. this.eatBits(1);
  36983. code1 = this.lookBits(12);
  36984. }
  36985. } else {
  36986. while (code1 === 0) {
  36987. this.eatBits(1);
  36988. code1 = this.lookBits(12);
  36989. }
  36990. }
  36991. if (code1 === 1) {
  36992. this.eatBits(12);
  36993. gotEOL = true;
  36994. } else if (code1 === EOF) {
  36995. this.eof = true;
  36996. }
  36997. }
  36998. if (!this.eof && this.encoding > 0) {
  36999. this.nextLine2D = !this.lookBits(1);
  37000. this.eatBits(1);
  37001. }
  37002. if (this.eoblock && gotEOL && this.byteAlign) {
  37003. code1 = this.lookBits(12);
  37004. if (code1 === 1) {
  37005. this.eatBits(12);
  37006. if (this.encoding > 0) {
  37007. this.lookBits(1);
  37008. this.eatBits(1);
  37009. }
  37010. if (this.encoding >= 0) {
  37011. for (i = 0; i < 4; ++i) {
  37012. code1 = this.lookBits(12);
  37013. if (code1 !== 1) {
  37014. info('bad rtc code: ' + code1);
  37015. }
  37016. this.eatBits(12);
  37017. if (this.encoding > 0) {
  37018. this.lookBits(1);
  37019. this.eatBits(1);
  37020. }
  37021. }
  37022. }
  37023. this.eof = true;
  37024. }
  37025. } else if (this.err && this.eoline) {
  37026. while (true) {
  37027. code1 = this.lookBits(13);
  37028. if (code1 === EOF) {
  37029. this.eof = true;
  37030. return null;
  37031. }
  37032. if ((code1 >> 1) === 1) {
  37033. break;
  37034. }
  37035. this.eatBits(1);
  37036. }
  37037. this.eatBits(12);
  37038. if (this.encoding > 0) {
  37039. this.eatBits(1);
  37040. this.nextLine2D = !(code1 & 1);
  37041. }
  37042. }
  37043. if (codingLine[0] > 0) {
  37044. this.outputBits = codingLine[this.codingPos = 0];
  37045. } else {
  37046. this.outputBits = codingLine[this.codingPos = 1];
  37047. }
  37048. this.row++;
  37049. }
  37050. var c;
  37051. if (this.outputBits >= 8) {
  37052. c = (this.codingPos & 1) ? 0 : 0xFF;
  37053. this.outputBits -= 8;
  37054. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  37055. this.codingPos++;
  37056. this.outputBits = (codingLine[this.codingPos] -
  37057. codingLine[this.codingPos - 1]);
  37058. }
  37059. } else {
  37060. bits = 8;
  37061. c = 0;
  37062. do {
  37063. if (this.outputBits > bits) {
  37064. c <<= bits;
  37065. if (!(this.codingPos & 1)) {
  37066. c |= 0xFF >> (8 - bits);
  37067. }
  37068. this.outputBits -= bits;
  37069. bits = 0;
  37070. } else {
  37071. c <<= this.outputBits;
  37072. if (!(this.codingPos & 1)) {
  37073. c |= 0xFF >> (8 - this.outputBits);
  37074. }
  37075. bits -= this.outputBits;
  37076. this.outputBits = 0;
  37077. if (codingLine[this.codingPos] < columns) {
  37078. this.codingPos++;
  37079. this.outputBits = (codingLine[this.codingPos] -
  37080. codingLine[this.codingPos - 1]);
  37081. } else if (bits > 0) {
  37082. c <<= bits;
  37083. bits = 0;
  37084. }
  37085. }
  37086. } while (bits);
  37087. }
  37088. if (this.black) {
  37089. c ^= 0xFF;
  37090. }
  37091. return c;
  37092. };
  37093. // This functions returns the code found from the table.
  37094. // The start and end parameters set the boundaries for searching the table.
  37095. // The limit parameter is optional. Function returns an array with three
  37096. // values. The first array element indicates whether a valid code is being
  37097. // returned. The second array element is the actual code. The third array
  37098. // element indicates whether EOF was reached.
  37099. CCITTFaxStream.prototype.findTableCode =
  37100. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  37101. var limitValue = limit || 0;
  37102. for (var i = start; i <= end; ++i) {
  37103. var code = this.lookBits(i);
  37104. if (code === EOF) {
  37105. return [true, 1, false];
  37106. }
  37107. if (i < end) {
  37108. code <<= end - i;
  37109. }
  37110. if (!limitValue || code >= limitValue) {
  37111. var p = table[code - limitValue];
  37112. if (p[0] === i) {
  37113. this.eatBits(i);
  37114. return [true, p[1], true];
  37115. }
  37116. }
  37117. }
  37118. return [false, 0, false];
  37119. };
  37120. CCITTFaxStream.prototype.getTwoDimCode =
  37121. function ccittFaxStreamGetTwoDimCode() {
  37122. var code = 0;
  37123. var p;
  37124. if (this.eoblock) {
  37125. code = this.lookBits(7);
  37126. p = twoDimTable[code];
  37127. if (p && p[0] > 0) {
  37128. this.eatBits(p[0]);
  37129. return p[1];
  37130. }
  37131. } else {
  37132. var result = this.findTableCode(1, 7, twoDimTable);
  37133. if (result[0] && result[2]) {
  37134. return result[1];
  37135. }
  37136. }
  37137. info('Bad two dim code');
  37138. return EOF;
  37139. };
  37140. CCITTFaxStream.prototype.getWhiteCode =
  37141. function ccittFaxStreamGetWhiteCode() {
  37142. var code = 0;
  37143. var p;
  37144. if (this.eoblock) {
  37145. code = this.lookBits(12);
  37146. if (code === EOF) {
  37147. return 1;
  37148. }
  37149. if ((code >> 5) === 0) {
  37150. p = whiteTable1[code];
  37151. } else {
  37152. p = whiteTable2[code >> 3];
  37153. }
  37154. if (p[0] > 0) {
  37155. this.eatBits(p[0]);
  37156. return p[1];
  37157. }
  37158. } else {
  37159. var result = this.findTableCode(1, 9, whiteTable2);
  37160. if (result[0]) {
  37161. return result[1];
  37162. }
  37163. result = this.findTableCode(11, 12, whiteTable1);
  37164. if (result[0]) {
  37165. return result[1];
  37166. }
  37167. }
  37168. info('bad white code');
  37169. this.eatBits(1);
  37170. return 1;
  37171. };
  37172. CCITTFaxStream.prototype.getBlackCode =
  37173. function ccittFaxStreamGetBlackCode() {
  37174. var code, p;
  37175. if (this.eoblock) {
  37176. code = this.lookBits(13);
  37177. if (code === EOF) {
  37178. return 1;
  37179. }
  37180. if ((code >> 7) === 0) {
  37181. p = blackTable1[code];
  37182. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  37183. p = blackTable2[(code >> 1) - 64];
  37184. } else {
  37185. p = blackTable3[code >> 7];
  37186. }
  37187. if (p[0] > 0) {
  37188. this.eatBits(p[0]);
  37189. return p[1];
  37190. }
  37191. } else {
  37192. var result = this.findTableCode(2, 6, blackTable3);
  37193. if (result[0]) {
  37194. return result[1];
  37195. }
  37196. result = this.findTableCode(7, 12, blackTable2, 64);
  37197. if (result[0]) {
  37198. return result[1];
  37199. }
  37200. result = this.findTableCode(10, 13, blackTable1);
  37201. if (result[0]) {
  37202. return result[1];
  37203. }
  37204. }
  37205. info('bad black code');
  37206. this.eatBits(1);
  37207. return 1;
  37208. };
  37209. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  37210. var c;
  37211. while (this.inputBits < n) {
  37212. if ((c = this.str.getByte()) === -1) {
  37213. if (this.inputBits === 0) {
  37214. return EOF;
  37215. }
  37216. return ((this.inputBuf << (n - this.inputBits)) &
  37217. (0xFFFF >> (16 - n)));
  37218. }
  37219. this.inputBuf = (this.inputBuf << 8) + c;
  37220. this.inputBits += 8;
  37221. }
  37222. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  37223. };
  37224. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  37225. if ((this.inputBits -= n) < 0) {
  37226. this.inputBits = 0;
  37227. }
  37228. };
  37229. return CCITTFaxStream;
  37230. })();
  37231. var LZWStream = (function LZWStreamClosure() {
  37232. function LZWStream(str, maybeLength, earlyChange) {
  37233. this.str = str;
  37234. this.dict = str.dict;
  37235. this.cachedData = 0;
  37236. this.bitsCached = 0;
  37237. var maxLzwDictionarySize = 4096;
  37238. var lzwState = {
  37239. earlyChange: earlyChange,
  37240. codeLength: 9,
  37241. nextCode: 258,
  37242. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  37243. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  37244. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  37245. currentSequence: new Uint8Array(maxLzwDictionarySize),
  37246. currentSequenceLength: 0
  37247. };
  37248. for (var i = 0; i < 256; ++i) {
  37249. lzwState.dictionaryValues[i] = i;
  37250. lzwState.dictionaryLengths[i] = 1;
  37251. }
  37252. this.lzwState = lzwState;
  37253. DecodeStream.call(this, maybeLength);
  37254. }
  37255. LZWStream.prototype = Object.create(DecodeStream.prototype);
  37256. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  37257. var bitsCached = this.bitsCached;
  37258. var cachedData = this.cachedData;
  37259. while (bitsCached < n) {
  37260. var c = this.str.getByte();
  37261. if (c === -1) {
  37262. this.eof = true;
  37263. return null;
  37264. }
  37265. cachedData = (cachedData << 8) | c;
  37266. bitsCached += 8;
  37267. }
  37268. this.bitsCached = (bitsCached -= n);
  37269. this.cachedData = cachedData;
  37270. this.lastCode = null;
  37271. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  37272. };
  37273. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  37274. var blockSize = 512;
  37275. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  37276. var i, j, q;
  37277. var lzwState = this.lzwState;
  37278. if (!lzwState) {
  37279. return; // eof was found
  37280. }
  37281. var earlyChange = lzwState.earlyChange;
  37282. var nextCode = lzwState.nextCode;
  37283. var dictionaryValues = lzwState.dictionaryValues;
  37284. var dictionaryLengths = lzwState.dictionaryLengths;
  37285. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  37286. var codeLength = lzwState.codeLength;
  37287. var prevCode = lzwState.prevCode;
  37288. var currentSequence = lzwState.currentSequence;
  37289. var currentSequenceLength = lzwState.currentSequenceLength;
  37290. var decodedLength = 0;
  37291. var currentBufferLength = this.bufferLength;
  37292. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37293. for (i = 0; i < blockSize; i++) {
  37294. var code = this.readBits(codeLength);
  37295. var hasPrev = currentSequenceLength > 0;
  37296. if (code < 256) {
  37297. currentSequence[0] = code;
  37298. currentSequenceLength = 1;
  37299. } else if (code >= 258) {
  37300. if (code < nextCode) {
  37301. currentSequenceLength = dictionaryLengths[code];
  37302. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  37303. currentSequence[j] = dictionaryValues[q];
  37304. q = dictionaryPrevCodes[q];
  37305. }
  37306. } else {
  37307. currentSequence[currentSequenceLength++] = currentSequence[0];
  37308. }
  37309. } else if (code === 256) {
  37310. codeLength = 9;
  37311. nextCode = 258;
  37312. currentSequenceLength = 0;
  37313. continue;
  37314. } else {
  37315. this.eof = true;
  37316. delete this.lzwState;
  37317. break;
  37318. }
  37319. if (hasPrev) {
  37320. dictionaryPrevCodes[nextCode] = prevCode;
  37321. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  37322. dictionaryValues[nextCode] = currentSequence[0];
  37323. nextCode++;
  37324. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  37325. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  37326. 0.6931471805599453 + 1, 12) | 0;
  37327. }
  37328. prevCode = code;
  37329. decodedLength += currentSequenceLength;
  37330. if (estimatedDecodedSize < decodedLength) {
  37331. do {
  37332. estimatedDecodedSize += decodedSizeDelta;
  37333. } while (estimatedDecodedSize < decodedLength);
  37334. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37335. }
  37336. for (j = 0; j < currentSequenceLength; j++) {
  37337. buffer[currentBufferLength++] = currentSequence[j];
  37338. }
  37339. }
  37340. lzwState.nextCode = nextCode;
  37341. lzwState.codeLength = codeLength;
  37342. lzwState.prevCode = prevCode;
  37343. lzwState.currentSequenceLength = currentSequenceLength;
  37344. this.bufferLength = currentBufferLength;
  37345. };
  37346. return LZWStream;
  37347. })();
  37348. var NullStream = (function NullStreamClosure() {
  37349. function NullStream() {
  37350. Stream.call(this, new Uint8Array(0));
  37351. }
  37352. NullStream.prototype = Stream.prototype;
  37353. return NullStream;
  37354. })();
  37355. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37356. setup: function wphSetup(handler) {
  37357. var pdfManager;
  37358. function loadDocument(recoveryMode) {
  37359. var loadDocumentCapability = createPromiseCapability();
  37360. var parseSuccess = function parseSuccess() {
  37361. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37362. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37363. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37364. Promise.all([numPagesPromise, fingerprintPromise,
  37365. encryptedPromise]).then(function onDocReady(results) {
  37366. var doc = {
  37367. numPages: results[0],
  37368. fingerprint: results[1],
  37369. encrypted: !!results[2],
  37370. };
  37371. loadDocumentCapability.resolve(doc);
  37372. },
  37373. parseFailure);
  37374. };
  37375. var parseFailure = function parseFailure(e) {
  37376. loadDocumentCapability.reject(e);
  37377. };
  37378. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37379. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37380. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37381. parseSuccess, parseFailure);
  37382. }, parseFailure);
  37383. }, parseFailure);
  37384. return loadDocumentCapability.promise;
  37385. }
  37386. function getPdfManager(data) {
  37387. var pdfManagerCapability = createPromiseCapability();
  37388. var source = data.source;
  37389. var disableRange = data.disableRange;
  37390. if (source.data) {
  37391. try {
  37392. pdfManager = new LocalPdfManager(source.data, source.password);
  37393. pdfManagerCapability.resolve();
  37394. } catch (ex) {
  37395. pdfManagerCapability.reject(ex);
  37396. }
  37397. return pdfManagerCapability.promise;
  37398. } else if (source.chunkedViewerLoading) {
  37399. try {
  37400. pdfManager = new NetworkPdfManager(source, handler);
  37401. pdfManagerCapability.resolve();
  37402. } catch (ex) {
  37403. pdfManagerCapability.reject(ex);
  37404. }
  37405. return pdfManagerCapability.promise;
  37406. }
  37407. var networkManager = new NetworkManager(source.url, {
  37408. httpHeaders: source.httpHeaders,
  37409. withCredentials: source.withCredentials
  37410. });
  37411. var cachedChunks = [];
  37412. var fullRequestXhrId = networkManager.requestFull({
  37413. onHeadersReceived: function onHeadersReceived() {
  37414. if (disableRange) {
  37415. return;
  37416. }
  37417. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37418. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37419. return;
  37420. }
  37421. var contentEncoding =
  37422. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37423. if (contentEncoding !== 'identity') {
  37424. return;
  37425. }
  37426. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37427. length = parseInt(length, 10);
  37428. if (!isInt(length)) {
  37429. return;
  37430. }
  37431. source.length = length;
  37432. if (length <= 2 * RANGE_CHUNK_SIZE) {
  37433. // The file size is smaller than the size of two chunks, so it does
  37434. // not make any sense to abort the request and retry with a range
  37435. // request.
  37436. return;
  37437. }
  37438. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37439. // We can continue fetching when progressive loading is enabled,
  37440. // and we don't need the autoFetch feature.
  37441. source.disableAutoFetch = true;
  37442. } else {
  37443. // NOTE: by cancelling the full request, and then issuing range
  37444. // requests, there will be an issue for sites where you can only
  37445. // request the pdf once. However, if this is the case, then the
  37446. // server should not be returning that it can support range
  37447. // requests.
  37448. networkManager.abortRequest(fullRequestXhrId);
  37449. }
  37450. try {
  37451. pdfManager = new NetworkPdfManager(source, handler);
  37452. pdfManagerCapability.resolve(pdfManager);
  37453. } catch (ex) {
  37454. pdfManagerCapability.reject(ex);
  37455. }
  37456. },
  37457. onProgressiveData: source.disableStream ? null :
  37458. function onProgressiveData(chunk) {
  37459. if (!pdfManager) {
  37460. cachedChunks.push(chunk);
  37461. return;
  37462. }
  37463. pdfManager.sendProgressiveData(chunk);
  37464. },
  37465. onDone: function onDone(args) {
  37466. if (pdfManager) {
  37467. return; // already processed
  37468. }
  37469. var pdfFile;
  37470. if (args === null) {
  37471. // TODO add some streaming manager, e.g. for unknown length files.
  37472. // The data was returned in the onProgressiveData, combining...
  37473. var pdfFileLength = 0, pos = 0;
  37474. cachedChunks.forEach(function (chunk) {
  37475. pdfFileLength += chunk.byteLength;
  37476. });
  37477. if (source.length && pdfFileLength !== source.length) {
  37478. warn('reported HTTP length is different from actual');
  37479. }
  37480. var pdfFileArray = new Uint8Array(pdfFileLength);
  37481. cachedChunks.forEach(function (chunk) {
  37482. pdfFileArray.set(new Uint8Array(chunk), pos);
  37483. pos += chunk.byteLength;
  37484. });
  37485. pdfFile = pdfFileArray.buffer;
  37486. } else {
  37487. pdfFile = args.chunk;
  37488. }
  37489. // the data is array, instantiating directly from it
  37490. try {
  37491. pdfManager = new LocalPdfManager(pdfFile, source.password);
  37492. pdfManagerCapability.resolve();
  37493. } catch (ex) {
  37494. pdfManagerCapability.reject(ex);
  37495. }
  37496. },
  37497. onError: function onError(status) {
  37498. var exception;
  37499. if (status === 404) {
  37500. exception = new MissingPDFException('Missing PDF "' +
  37501. source.url + '".');
  37502. handler.send('MissingPDF', exception);
  37503. } else {
  37504. exception = new UnexpectedResponseException(
  37505. 'Unexpected server response (' + status +
  37506. ') while retrieving PDF "' + source.url + '".', status);
  37507. handler.send('UnexpectedResponse', exception);
  37508. }
  37509. },
  37510. onProgress: function onProgress(evt) {
  37511. handler.send('DocProgress', {
  37512. loaded: evt.loaded,
  37513. total: evt.lengthComputable ? evt.total : source.length
  37514. });
  37515. }
  37516. });
  37517. return pdfManagerCapability.promise;
  37518. }
  37519. handler.on('test', function wphSetupTest(data) {
  37520. // check if Uint8Array can be sent to worker
  37521. if (!(data instanceof Uint8Array)) {
  37522. handler.send('test', false);
  37523. return;
  37524. }
  37525. // making sure postMessage transfers are working
  37526. var supportTransfers = data[0] === 255;
  37527. handler.postMessageTransfers = supportTransfers;
  37528. // check if the response property is supported by xhr
  37529. var xhr = new XMLHttpRequest();
  37530. var responseExists = 'response' in xhr;
  37531. // check if the property is actually implemented
  37532. try {
  37533. var dummy = xhr.responseType;
  37534. } catch (e) {
  37535. responseExists = false;
  37536. }
  37537. if (!responseExists) {
  37538. handler.send('test', false);
  37539. return;
  37540. }
  37541. handler.send('test', {
  37542. supportTypedArray: true,
  37543. supportTransfers: supportTransfers
  37544. });
  37545. });
  37546. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37547. var onSuccess = function(doc) {
  37548. handler.send('GetDoc', { pdfInfo: doc });
  37549. };
  37550. var onFailure = function(e) {
  37551. if (e instanceof PasswordException) {
  37552. if (e.code === PasswordResponses.NEED_PASSWORD) {
  37553. handler.send('NeedPassword', e);
  37554. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  37555. handler.send('IncorrectPassword', e);
  37556. }
  37557. } else if (e instanceof InvalidPDFException) {
  37558. handler.send('InvalidPDF', e);
  37559. } else if (e instanceof MissingPDFException) {
  37560. handler.send('MissingPDF', e);
  37561. } else if (e instanceof UnexpectedResponseException) {
  37562. handler.send('UnexpectedResponse', e);
  37563. } else {
  37564. handler.send('UnknownError',
  37565. new UnknownErrorException(e.message, e.toString()));
  37566. }
  37567. };
  37568. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  37569. -1 : data.maxImageSize;
  37570. PDFJS.disableFontFace = data.disableFontFace;
  37571. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  37572. PDFJS.verbosity = data.verbosity;
  37573. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  37574. null : data.cMapUrl;
  37575. PDFJS.cMapPacked = data.cMapPacked === true;
  37576. getPdfManager(data).then(function () {
  37577. handler.send('PDFManagerReady', null);
  37578. pdfManager.onLoadedStream().then(function(stream) {
  37579. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  37580. });
  37581. }).then(function pdfManagerReady() {
  37582. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  37583. // Try again with recoveryMode == true
  37584. if (!(ex instanceof XRefParseException)) {
  37585. if (ex instanceof PasswordException) {
  37586. // after password exception prepare to receive a new password
  37587. // to repeat loading
  37588. pdfManager.passwordChanged().then(pdfManagerReady);
  37589. }
  37590. onFailure(ex);
  37591. return;
  37592. }
  37593. pdfManager.requestLoadedStream();
  37594. pdfManager.onLoadedStream().then(function() {
  37595. loadDocument(true).then(onSuccess, onFailure);
  37596. });
  37597. }, onFailure);
  37598. }, onFailure);
  37599. });
  37600. handler.on('GetPage', function wphSetupGetPage(data) {
  37601. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37602. var rotatePromise = pdfManager.ensure(page, 'rotate');
  37603. var refPromise = pdfManager.ensure(page, 'ref');
  37604. var viewPromise = pdfManager.ensure(page, 'view');
  37605. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  37606. function(results) {
  37607. return {
  37608. rotate: results[0],
  37609. ref: results[1],
  37610. view: results[2]
  37611. };
  37612. });
  37613. });
  37614. });
  37615. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  37616. var ref = new Ref(data.ref.num, data.ref.gen);
  37617. var catalog = pdfManager.pdfDocument.catalog;
  37618. return catalog.getPageIndex(ref);
  37619. });
  37620. handler.on('GetDestinations',
  37621. function wphSetupGetDestinations(data) {
  37622. return pdfManager.ensureCatalog('destinations');
  37623. }
  37624. );
  37625. handler.on('GetDestination',
  37626. function wphSetupGetDestination(data) {
  37627. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  37628. }
  37629. );
  37630. handler.on('GetAttachments',
  37631. function wphSetupGetAttachments(data) {
  37632. return pdfManager.ensureCatalog('attachments');
  37633. }
  37634. );
  37635. handler.on('GetJavaScript',
  37636. function wphSetupGetJavaScript(data) {
  37637. return pdfManager.ensureCatalog('javaScript');
  37638. }
  37639. );
  37640. handler.on('GetOutline',
  37641. function wphSetupGetOutline(data) {
  37642. return pdfManager.ensureCatalog('documentOutline');
  37643. }
  37644. );
  37645. handler.on('GetMetadata',
  37646. function wphSetupGetMetadata(data) {
  37647. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37648. pdfManager.ensureCatalog('metadata')]);
  37649. }
  37650. );
  37651. handler.on('GetData', function wphSetupGetData(data) {
  37652. pdfManager.requestLoadedStream();
  37653. return pdfManager.onLoadedStream().then(function(stream) {
  37654. return stream.bytes;
  37655. });
  37656. });
  37657. handler.on('GetStats',
  37658. function wphSetupGetStats(data) {
  37659. return pdfManager.pdfDocument.xref.stats;
  37660. }
  37661. );
  37662. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37663. pdfManager.updatePassword(data);
  37664. });
  37665. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37666. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37667. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37668. });
  37669. });
  37670. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37671. pdfManager.getPage(data.pageIndex).then(function(page) {
  37672. var pageNum = data.pageIndex + 1;
  37673. var start = Date.now();
  37674. // Pre compile the pdf page and fetch the fonts/images.
  37675. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37676. info('page=' + pageNum + ' - getOperatorList: time=' +
  37677. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37678. }, function(e) {
  37679. var minimumStackMessage =
  37680. 'worker.js: while trying to getPage() and getOperatorList()';
  37681. var wrappedException;
  37682. // Turn the error into an obj that can be serialized
  37683. if (typeof e === 'string') {
  37684. wrappedException = {
  37685. message: e,
  37686. stack: minimumStackMessage
  37687. };
  37688. } else if (typeof e === 'object') {
  37689. wrappedException = {
  37690. message: e.message || e.toString(),
  37691. stack: e.stack || minimumStackMessage
  37692. };
  37693. } else {
  37694. wrappedException = {
  37695. message: 'Unknown exception type: ' + (typeof e),
  37696. stack: minimumStackMessage
  37697. };
  37698. }
  37699. handler.send('PageError', {
  37700. pageNum: pageNum,
  37701. error: wrappedException,
  37702. intent: data.intent
  37703. });
  37704. });
  37705. });
  37706. }, this);
  37707. handler.on('GetTextContent', function wphExtractText(data) {
  37708. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37709. var pageNum = data.pageIndex + 1;
  37710. var start = Date.now();
  37711. return page.extractTextContent().then(function(textContent) {
  37712. info('text indexing: page=' + pageNum + ' - time=' +
  37713. (Date.now() - start) + 'ms');
  37714. return textContent;
  37715. });
  37716. });
  37717. });
  37718. handler.on('Cleanup', function wphCleanup(data) {
  37719. return pdfManager.cleanup();
  37720. });
  37721. handler.on('Terminate', function wphTerminate(data) {
  37722. pdfManager.terminate();
  37723. });
  37724. }
  37725. };
  37726. var consoleTimer = {};
  37727. var workerConsole = {
  37728. log: function log() {
  37729. var args = Array.prototype.slice.call(arguments);
  37730. globalScope.postMessage({
  37731. action: 'console_log',
  37732. data: args
  37733. });
  37734. },
  37735. error: function error() {
  37736. var args = Array.prototype.slice.call(arguments);
  37737. globalScope.postMessage({
  37738. action: 'console_error',
  37739. data: args
  37740. });
  37741. throw 'pdf.js execution error';
  37742. },
  37743. time: function time(name) {
  37744. consoleTimer[name] = Date.now();
  37745. },
  37746. timeEnd: function timeEnd(name) {
  37747. var time = consoleTimer[name];
  37748. if (!time) {
  37749. error('Unknown timer name ' + name);
  37750. }
  37751. this.log('Timer:', name, Date.now() - time);
  37752. }
  37753. };
  37754. // Worker thread?
  37755. if (typeof window === 'undefined') {
  37756. if (!('console' in globalScope)) {
  37757. globalScope.console = workerConsole;
  37758. }
  37759. // Listen for unsupported features so we can pass them on to the main thread.
  37760. PDFJS.UnsupportedManager.listen(function (msg) {
  37761. globalScope.postMessage({
  37762. action: '_unsupported_feature',
  37763. data: msg
  37764. });
  37765. });
  37766. var handler = new MessageHandler('worker_processor', this);
  37767. WorkerMessageHandler.setup(handler);
  37768. }
  37769. /* This class implements the QM Coder decoding as defined in
  37770. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37771. * Annex C.3 Arithmetic decoding procedure
  37772. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37773. *
  37774. * The arithmetic decoder is used in conjunction with context models to decode
  37775. * JPEG2000 and JBIG2 streams.
  37776. */
  37777. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37778. // Table C-2
  37779. var QeTable = [
  37780. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37781. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37782. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37783. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37784. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37785. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37786. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37787. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37788. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37789. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37790. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37791. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37792. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37793. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37794. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37795. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37796. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37797. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37798. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37799. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37800. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37801. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37802. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37803. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37804. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37805. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37806. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37807. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37808. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37809. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37810. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37811. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37812. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37813. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37814. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37815. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37816. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37817. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37818. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37819. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37820. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37821. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37822. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37823. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37824. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37825. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37826. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37827. ];
  37828. // C.3.5 Initialisation of the decoder (INITDEC)
  37829. function ArithmeticDecoder(data, start, end) {
  37830. this.data = data;
  37831. this.bp = start;
  37832. this.dataEnd = end;
  37833. this.chigh = data[start];
  37834. this.clow = 0;
  37835. this.byteIn();
  37836. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37837. this.clow = (this.clow << 7) & 0xFFFF;
  37838. this.ct -= 7;
  37839. this.a = 0x8000;
  37840. }
  37841. ArithmeticDecoder.prototype = {
  37842. // C.3.4 Compressed data input (BYTEIN)
  37843. byteIn: function ArithmeticDecoder_byteIn() {
  37844. var data = this.data;
  37845. var bp = this.bp;
  37846. if (data[bp] === 0xFF) {
  37847. var b1 = data[bp + 1];
  37848. if (b1 > 0x8F) {
  37849. this.clow += 0xFF00;
  37850. this.ct = 8;
  37851. } else {
  37852. bp++;
  37853. this.clow += (data[bp] << 9);
  37854. this.ct = 7;
  37855. this.bp = bp;
  37856. }
  37857. } else {
  37858. bp++;
  37859. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37860. this.ct = 8;
  37861. this.bp = bp;
  37862. }
  37863. if (this.clow > 0xFFFF) {
  37864. this.chigh += (this.clow >> 16);
  37865. this.clow &= 0xFFFF;
  37866. }
  37867. },
  37868. // C.3.2 Decoding a decision (DECODE)
  37869. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37870. // contexts are packed into 1 byte:
  37871. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37872. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37873. var qeTableIcx = QeTable[cx_index];
  37874. var qeIcx = qeTableIcx.qe;
  37875. var d;
  37876. var a = this.a - qeIcx;
  37877. if (this.chigh < qeIcx) {
  37878. // exchangeLps
  37879. if (a < qeIcx) {
  37880. a = qeIcx;
  37881. d = cx_mps;
  37882. cx_index = qeTableIcx.nmps;
  37883. } else {
  37884. a = qeIcx;
  37885. d = 1 ^ cx_mps;
  37886. if (qeTableIcx.switchFlag === 1) {
  37887. cx_mps = d;
  37888. }
  37889. cx_index = qeTableIcx.nlps;
  37890. }
  37891. } else {
  37892. this.chigh -= qeIcx;
  37893. if ((a & 0x8000) !== 0) {
  37894. this.a = a;
  37895. return cx_mps;
  37896. }
  37897. // exchangeMps
  37898. if (a < qeIcx) {
  37899. d = 1 ^ cx_mps;
  37900. if (qeTableIcx.switchFlag === 1) {
  37901. cx_mps = d;
  37902. }
  37903. cx_index = qeTableIcx.nlps;
  37904. } else {
  37905. d = cx_mps;
  37906. cx_index = qeTableIcx.nmps;
  37907. }
  37908. }
  37909. // C.3.3 renormD;
  37910. do {
  37911. if (this.ct === 0) {
  37912. this.byteIn();
  37913. }
  37914. a <<= 1;
  37915. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37916. this.clow = (this.clow << 1) & 0xFFFF;
  37917. this.ct--;
  37918. } while ((a & 0x8000) === 0);
  37919. this.a = a;
  37920. contexts[pos] = cx_index << 1 | cx_mps;
  37921. return d;
  37922. }
  37923. };
  37924. return ArithmeticDecoder;
  37925. })();
  37926. var JpegImage = (function jpegImage() {
  37927. var dctZigZag = new Uint8Array([
  37928. 0,
  37929. 1, 8,
  37930. 16, 9, 2,
  37931. 3, 10, 17, 24,
  37932. 32, 25, 18, 11, 4,
  37933. 5, 12, 19, 26, 33, 40,
  37934. 48, 41, 34, 27, 20, 13, 6,
  37935. 7, 14, 21, 28, 35, 42, 49, 56,
  37936. 57, 50, 43, 36, 29, 22, 15,
  37937. 23, 30, 37, 44, 51, 58,
  37938. 59, 52, 45, 38, 31,
  37939. 39, 46, 53, 60,
  37940. 61, 54, 47,
  37941. 55, 62,
  37942. 63
  37943. ]);
  37944. var dctCos1 = 4017; // cos(pi/16)
  37945. var dctSin1 = 799; // sin(pi/16)
  37946. var dctCos3 = 3406; // cos(3*pi/16)
  37947. var dctSin3 = 2276; // sin(3*pi/16)
  37948. var dctCos6 = 1567; // cos(6*pi/16)
  37949. var dctSin6 = 3784; // sin(6*pi/16)
  37950. var dctSqrt2 = 5793; // sqrt(2)
  37951. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  37952. function constructor() {
  37953. }
  37954. function buildHuffmanTable(codeLengths, values) {
  37955. var k = 0, code = [], i, j, length = 16;
  37956. while (length > 0 && !codeLengths[length - 1]) {
  37957. length--;
  37958. }
  37959. code.push({children: [], index: 0});
  37960. var p = code[0], q;
  37961. for (i = 0; i < length; i++) {
  37962. for (j = 0; j < codeLengths[i]; j++) {
  37963. p = code.pop();
  37964. p.children[p.index] = values[k];
  37965. while (p.index > 0) {
  37966. p = code.pop();
  37967. }
  37968. p.index++;
  37969. code.push(p);
  37970. while (code.length <= i) {
  37971. code.push(q = {children: [], index: 0});
  37972. p.children[p.index] = q.children;
  37973. p = q;
  37974. }
  37975. k++;
  37976. }
  37977. if (i + 1 < length) {
  37978. // p here points to last code
  37979. code.push(q = {children: [], index: 0});
  37980. p.children[p.index] = q.children;
  37981. p = q;
  37982. }
  37983. }
  37984. return code[0].children;
  37985. }
  37986. function getBlockBufferOffset(component, row, col) {
  37987. return 64 * ((component.blocksPerLine + 1) * row + col);
  37988. }
  37989. function decodeScan(data, offset, frame, components, resetInterval,
  37990. spectralStart, spectralEnd, successivePrev, successive) {
  37991. var precision = frame.precision;
  37992. var samplesPerLine = frame.samplesPerLine;
  37993. var scanLines = frame.scanLines;
  37994. var mcusPerLine = frame.mcusPerLine;
  37995. var progressive = frame.progressive;
  37996. var maxH = frame.maxH, maxV = frame.maxV;
  37997. var startOffset = offset, bitsData = 0, bitsCount = 0;
  37998. function readBit() {
  37999. if (bitsCount > 0) {
  38000. bitsCount--;
  38001. return (bitsData >> bitsCount) & 1;
  38002. }
  38003. bitsData = data[offset++];
  38004. if (bitsData === 0xFF) {
  38005. var nextByte = data[offset++];
  38006. if (nextByte) {
  38007. throw 'unexpected marker: ' +
  38008. ((bitsData << 8) | nextByte).toString(16);
  38009. }
  38010. // unstuff 0
  38011. }
  38012. bitsCount = 7;
  38013. return bitsData >>> 7;
  38014. }
  38015. function decodeHuffman(tree) {
  38016. var node = tree;
  38017. while (true) {
  38018. node = node[readBit()];
  38019. if (typeof node === 'number') {
  38020. return node;
  38021. }
  38022. if (typeof node !== 'object') {
  38023. throw 'invalid huffman sequence';
  38024. }
  38025. }
  38026. }
  38027. function receive(length) {
  38028. var n = 0;
  38029. while (length > 0) {
  38030. n = (n << 1) | readBit();
  38031. length--;
  38032. }
  38033. return n;
  38034. }
  38035. function receiveAndExtend(length) {
  38036. if (length === 1) {
  38037. return readBit() === 1 ? 1 : -1;
  38038. }
  38039. var n = receive(length);
  38040. if (n >= 1 << (length - 1)) {
  38041. return n;
  38042. }
  38043. return n + (-1 << length) + 1;
  38044. }
  38045. function decodeBaseline(component, offset) {
  38046. var t = decodeHuffman(component.huffmanTableDC);
  38047. var diff = t === 0 ? 0 : receiveAndExtend(t);
  38048. component.blockData[offset] = (component.pred += diff);
  38049. var k = 1;
  38050. while (k < 64) {
  38051. var rs = decodeHuffman(component.huffmanTableAC);
  38052. var s = rs & 15, r = rs >> 4;
  38053. if (s === 0) {
  38054. if (r < 15) {
  38055. break;
  38056. }
  38057. k += 16;
  38058. continue;
  38059. }
  38060. k += r;
  38061. var z = dctZigZag[k];
  38062. component.blockData[offset + z] = receiveAndExtend(s);
  38063. k++;
  38064. }
  38065. }
  38066. function decodeDCFirst(component, offset) {
  38067. var t = decodeHuffman(component.huffmanTableDC);
  38068. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  38069. component.blockData[offset] = (component.pred += diff);
  38070. }
  38071. function decodeDCSuccessive(component, offset) {
  38072. component.blockData[offset] |= readBit() << successive;
  38073. }
  38074. var eobrun = 0;
  38075. function decodeACFirst(component, offset) {
  38076. if (eobrun > 0) {
  38077. eobrun--;
  38078. return;
  38079. }
  38080. var k = spectralStart, e = spectralEnd;
  38081. while (k <= e) {
  38082. var rs = decodeHuffman(component.huffmanTableAC);
  38083. var s = rs & 15, r = rs >> 4;
  38084. if (s === 0) {
  38085. if (r < 15) {
  38086. eobrun = receive(r) + (1 << r) - 1;
  38087. break;
  38088. }
  38089. k += 16;
  38090. continue;
  38091. }
  38092. k += r;
  38093. var z = dctZigZag[k];
  38094. component.blockData[offset + z] =
  38095. receiveAndExtend(s) * (1 << successive);
  38096. k++;
  38097. }
  38098. }
  38099. var successiveACState = 0, successiveACNextValue;
  38100. function decodeACSuccessive(component, offset) {
  38101. var k = spectralStart;
  38102. var e = spectralEnd;
  38103. var r = 0;
  38104. var s;
  38105. var rs;
  38106. while (k <= e) {
  38107. var z = dctZigZag[k];
  38108. switch (successiveACState) {
  38109. case 0: // initial state
  38110. rs = decodeHuffman(component.huffmanTableAC);
  38111. s = rs & 15;
  38112. r = rs >> 4;
  38113. if (s === 0) {
  38114. if (r < 15) {
  38115. eobrun = receive(r) + (1 << r);
  38116. successiveACState = 4;
  38117. } else {
  38118. r = 16;
  38119. successiveACState = 1;
  38120. }
  38121. } else {
  38122. if (s !== 1) {
  38123. throw 'invalid ACn encoding';
  38124. }
  38125. successiveACNextValue = receiveAndExtend(s);
  38126. successiveACState = r ? 2 : 3;
  38127. }
  38128. continue;
  38129. case 1: // skipping r zero items
  38130. case 2:
  38131. if (component.blockData[offset + z]) {
  38132. component.blockData[offset + z] += (readBit() << successive);
  38133. } else {
  38134. r--;
  38135. if (r === 0) {
  38136. successiveACState = successiveACState === 2 ? 3 : 0;
  38137. }
  38138. }
  38139. break;
  38140. case 3: // set value for a zero item
  38141. if (component.blockData[offset + z]) {
  38142. component.blockData[offset + z] += (readBit() << successive);
  38143. } else {
  38144. component.blockData[offset + z] =
  38145. successiveACNextValue << successive;
  38146. successiveACState = 0;
  38147. }
  38148. break;
  38149. case 4: // eob
  38150. if (component.blockData[offset + z]) {
  38151. component.blockData[offset + z] += (readBit() << successive);
  38152. }
  38153. break;
  38154. }
  38155. k++;
  38156. }
  38157. if (successiveACState === 4) {
  38158. eobrun--;
  38159. if (eobrun === 0) {
  38160. successiveACState = 0;
  38161. }
  38162. }
  38163. }
  38164. function decodeMcu(component, decode, mcu, row, col) {
  38165. var mcuRow = (mcu / mcusPerLine) | 0;
  38166. var mcuCol = mcu % mcusPerLine;
  38167. var blockRow = mcuRow * component.v + row;
  38168. var blockCol = mcuCol * component.h + col;
  38169. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38170. decode(component, offset);
  38171. }
  38172. function decodeBlock(component, decode, mcu) {
  38173. var blockRow = (mcu / component.blocksPerLine) | 0;
  38174. var blockCol = mcu % component.blocksPerLine;
  38175. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38176. decode(component, offset);
  38177. }
  38178. var componentsLength = components.length;
  38179. var component, i, j, k, n;
  38180. var decodeFn;
  38181. if (progressive) {
  38182. if (spectralStart === 0) {
  38183. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  38184. } else {
  38185. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  38186. }
  38187. } else {
  38188. decodeFn = decodeBaseline;
  38189. }
  38190. var mcu = 0, marker;
  38191. var mcuExpected;
  38192. if (componentsLength === 1) {
  38193. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  38194. } else {
  38195. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  38196. }
  38197. if (!resetInterval) {
  38198. resetInterval = mcuExpected;
  38199. }
  38200. var h, v;
  38201. while (mcu < mcuExpected) {
  38202. // reset interval stuff
  38203. for (i = 0; i < componentsLength; i++) {
  38204. components[i].pred = 0;
  38205. }
  38206. eobrun = 0;
  38207. if (componentsLength === 1) {
  38208. component = components[0];
  38209. for (n = 0; n < resetInterval; n++) {
  38210. decodeBlock(component, decodeFn, mcu);
  38211. mcu++;
  38212. }
  38213. } else {
  38214. for (n = 0; n < resetInterval; n++) {
  38215. for (i = 0; i < componentsLength; i++) {
  38216. component = components[i];
  38217. h = component.h;
  38218. v = component.v;
  38219. for (j = 0; j < v; j++) {
  38220. for (k = 0; k < h; k++) {
  38221. decodeMcu(component, decodeFn, mcu, j, k);
  38222. }
  38223. }
  38224. }
  38225. mcu++;
  38226. }
  38227. }
  38228. // find marker
  38229. bitsCount = 0;
  38230. marker = (data[offset] << 8) | data[offset + 1];
  38231. if (marker <= 0xFF00) {
  38232. throw 'marker was not found';
  38233. }
  38234. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  38235. offset += 2;
  38236. } else {
  38237. break;
  38238. }
  38239. }
  38240. return offset - startOffset;
  38241. }
  38242. // A port of poppler's IDCT method which in turn is taken from:
  38243. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  38244. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  38245. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  38246. // 988-991.
  38247. function quantizeAndInverse(component, blockBufferOffset, p) {
  38248. var qt = component.quantizationTable, blockData = component.blockData;
  38249. var v0, v1, v2, v3, v4, v5, v6, v7;
  38250. var p0, p1, p2, p3, p4, p5, p6, p7;
  38251. var t;
  38252. // inverse DCT on rows
  38253. for (var row = 0; row < 64; row += 8) {
  38254. // gather block data
  38255. p0 = blockData[blockBufferOffset + row];
  38256. p1 = blockData[blockBufferOffset + row + 1];
  38257. p2 = blockData[blockBufferOffset + row + 2];
  38258. p3 = blockData[blockBufferOffset + row + 3];
  38259. p4 = blockData[blockBufferOffset + row + 4];
  38260. p5 = blockData[blockBufferOffset + row + 5];
  38261. p6 = blockData[blockBufferOffset + row + 6];
  38262. p7 = blockData[blockBufferOffset + row + 7];
  38263. // dequant p0
  38264. p0 *= qt[row];
  38265. // check for all-zero AC coefficients
  38266. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38267. t = (dctSqrt2 * p0 + 512) >> 10;
  38268. p[row] = t;
  38269. p[row + 1] = t;
  38270. p[row + 2] = t;
  38271. p[row + 3] = t;
  38272. p[row + 4] = t;
  38273. p[row + 5] = t;
  38274. p[row + 6] = t;
  38275. p[row + 7] = t;
  38276. continue;
  38277. }
  38278. // dequant p1 ... p7
  38279. p1 *= qt[row + 1];
  38280. p2 *= qt[row + 2];
  38281. p3 *= qt[row + 3];
  38282. p4 *= qt[row + 4];
  38283. p5 *= qt[row + 5];
  38284. p6 *= qt[row + 6];
  38285. p7 *= qt[row + 7];
  38286. // stage 4
  38287. v0 = (dctSqrt2 * p0 + 128) >> 8;
  38288. v1 = (dctSqrt2 * p4 + 128) >> 8;
  38289. v2 = p2;
  38290. v3 = p6;
  38291. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  38292. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  38293. v5 = p3 << 4;
  38294. v6 = p5 << 4;
  38295. // stage 3
  38296. v0 = (v0 + v1 + 1) >> 1;
  38297. v1 = v0 - v1;
  38298. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  38299. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  38300. v3 = t;
  38301. v4 = (v4 + v6 + 1) >> 1;
  38302. v6 = v4 - v6;
  38303. v7 = (v7 + v5 + 1) >> 1;
  38304. v5 = v7 - v5;
  38305. // stage 2
  38306. v0 = (v0 + v3 + 1) >> 1;
  38307. v3 = v0 - v3;
  38308. v1 = (v1 + v2 + 1) >> 1;
  38309. v2 = v1 - v2;
  38310. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38311. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38312. v7 = t;
  38313. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38314. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38315. v6 = t;
  38316. // stage 1
  38317. p[row] = v0 + v7;
  38318. p[row + 7] = v0 - v7;
  38319. p[row + 1] = v1 + v6;
  38320. p[row + 6] = v1 - v6;
  38321. p[row + 2] = v2 + v5;
  38322. p[row + 5] = v2 - v5;
  38323. p[row + 3] = v3 + v4;
  38324. p[row + 4] = v3 - v4;
  38325. }
  38326. // inverse DCT on columns
  38327. for (var col = 0; col < 8; ++col) {
  38328. p0 = p[col];
  38329. p1 = p[col + 8];
  38330. p2 = p[col + 16];
  38331. p3 = p[col + 24];
  38332. p4 = p[col + 32];
  38333. p5 = p[col + 40];
  38334. p6 = p[col + 48];
  38335. p7 = p[col + 56];
  38336. // check for all-zero AC coefficients
  38337. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38338. t = (dctSqrt2 * p0 + 8192) >> 14;
  38339. // convert to 8 bit
  38340. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  38341. blockData[blockBufferOffset + col] = t;
  38342. blockData[blockBufferOffset + col + 8] = t;
  38343. blockData[blockBufferOffset + col + 16] = t;
  38344. blockData[blockBufferOffset + col + 24] = t;
  38345. blockData[blockBufferOffset + col + 32] = t;
  38346. blockData[blockBufferOffset + col + 40] = t;
  38347. blockData[blockBufferOffset + col + 48] = t;
  38348. blockData[blockBufferOffset + col + 56] = t;
  38349. continue;
  38350. }
  38351. // stage 4
  38352. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  38353. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  38354. v2 = p2;
  38355. v3 = p6;
  38356. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  38357. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  38358. v5 = p3;
  38359. v6 = p5;
  38360. // stage 3
  38361. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  38362. // converting to UInt8 range later.
  38363. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  38364. v1 = v0 - v1;
  38365. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  38366. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  38367. v3 = t;
  38368. v4 = (v4 + v6 + 1) >> 1;
  38369. v6 = v4 - v6;
  38370. v7 = (v7 + v5 + 1) >> 1;
  38371. v5 = v7 - v5;
  38372. // stage 2
  38373. v0 = (v0 + v3 + 1) >> 1;
  38374. v3 = v0 - v3;
  38375. v1 = (v1 + v2 + 1) >> 1;
  38376. v2 = v1 - v2;
  38377. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38378. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38379. v7 = t;
  38380. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38381. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38382. v6 = t;
  38383. // stage 1
  38384. p0 = v0 + v7;
  38385. p7 = v0 - v7;
  38386. p1 = v1 + v6;
  38387. p6 = v1 - v6;
  38388. p2 = v2 + v5;
  38389. p5 = v2 - v5;
  38390. p3 = v3 + v4;
  38391. p4 = v3 - v4;
  38392. // convert to 8-bit integers
  38393. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  38394. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  38395. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  38396. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  38397. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  38398. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  38399. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  38400. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  38401. // store block data
  38402. blockData[blockBufferOffset + col] = p0;
  38403. blockData[blockBufferOffset + col + 8] = p1;
  38404. blockData[blockBufferOffset + col + 16] = p2;
  38405. blockData[blockBufferOffset + col + 24] = p3;
  38406. blockData[blockBufferOffset + col + 32] = p4;
  38407. blockData[blockBufferOffset + col + 40] = p5;
  38408. blockData[blockBufferOffset + col + 48] = p6;
  38409. blockData[blockBufferOffset + col + 56] = p7;
  38410. }
  38411. }
  38412. function buildComponentData(frame, component) {
  38413. var blocksPerLine = component.blocksPerLine;
  38414. var blocksPerColumn = component.blocksPerColumn;
  38415. var computationBuffer = new Int16Array(64);
  38416. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  38417. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  38418. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38419. quantizeAndInverse(component, offset, computationBuffer);
  38420. }
  38421. }
  38422. return component.blockData;
  38423. }
  38424. function clamp0to255(a) {
  38425. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  38426. }
  38427. constructor.prototype = {
  38428. parse: function parse(data) {
  38429. function readUint16() {
  38430. var value = (data[offset] << 8) | data[offset + 1];
  38431. offset += 2;
  38432. return value;
  38433. }
  38434. function readDataBlock() {
  38435. var length = readUint16();
  38436. var array = data.subarray(offset, offset + length - 2);
  38437. offset += array.length;
  38438. return array;
  38439. }
  38440. function prepareComponents(frame) {
  38441. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  38442. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  38443. for (var i = 0; i < frame.components.length; i++) {
  38444. component = frame.components[i];
  38445. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  38446. component.h / frame.maxH);
  38447. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  38448. component.v / frame.maxV);
  38449. var blocksPerLineForMcu = mcusPerLine * component.h;
  38450. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  38451. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  38452. (blocksPerLineForMcu + 1);
  38453. component.blockData = new Int16Array(blocksBufferSize);
  38454. component.blocksPerLine = blocksPerLine;
  38455. component.blocksPerColumn = blocksPerColumn;
  38456. }
  38457. frame.mcusPerLine = mcusPerLine;
  38458. frame.mcusPerColumn = mcusPerColumn;
  38459. }
  38460. var offset = 0, length = data.length;
  38461. var jfif = null;
  38462. var adobe = null;
  38463. var pixels = null;
  38464. var frame, resetInterval;
  38465. var quantizationTables = [];
  38466. var huffmanTablesAC = [], huffmanTablesDC = [];
  38467. var fileMarker = readUint16();
  38468. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  38469. throw 'SOI not found';
  38470. }
  38471. fileMarker = readUint16();
  38472. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  38473. var i, j, l;
  38474. switch(fileMarker) {
  38475. case 0xFFE0: // APP0 (Application Specific)
  38476. case 0xFFE1: // APP1
  38477. case 0xFFE2: // APP2
  38478. case 0xFFE3: // APP3
  38479. case 0xFFE4: // APP4
  38480. case 0xFFE5: // APP5
  38481. case 0xFFE6: // APP6
  38482. case 0xFFE7: // APP7
  38483. case 0xFFE8: // APP8
  38484. case 0xFFE9: // APP9
  38485. case 0xFFEA: // APP10
  38486. case 0xFFEB: // APP11
  38487. case 0xFFEC: // APP12
  38488. case 0xFFED: // APP13
  38489. case 0xFFEE: // APP14
  38490. case 0xFFEF: // APP15
  38491. case 0xFFFE: // COM (Comment)
  38492. var appData = readDataBlock();
  38493. if (fileMarker === 0xFFE0) {
  38494. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  38495. appData[2] === 0x49 && appData[3] === 0x46 &&
  38496. appData[4] === 0) { // 'JFIF\x00'
  38497. jfif = {
  38498. version: { major: appData[5], minor: appData[6] },
  38499. densityUnits: appData[7],
  38500. xDensity: (appData[8] << 8) | appData[9],
  38501. yDensity: (appData[10] << 8) | appData[11],
  38502. thumbWidth: appData[12],
  38503. thumbHeight: appData[13],
  38504. thumbData: appData.subarray(14, 14 +
  38505. 3 * appData[12] * appData[13])
  38506. };
  38507. }
  38508. }
  38509. // TODO APP1 - Exif
  38510. if (fileMarker === 0xFFEE) {
  38511. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  38512. appData[2] === 0x6F && appData[3] === 0x62 &&
  38513. appData[4] === 0x65) { // 'Adobe'
  38514. adobe = {
  38515. version: (appData[5] << 8) | appData[6],
  38516. flags0: (appData[7] << 8) | appData[8],
  38517. flags1: (appData[9] << 8) | appData[10],
  38518. transformCode: appData[11]
  38519. };
  38520. }
  38521. }
  38522. break;
  38523. case 0xFFDB: // DQT (Define Quantization Tables)
  38524. var quantizationTablesLength = readUint16();
  38525. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38526. var z;
  38527. while (offset < quantizationTablesEnd) {
  38528. var quantizationTableSpec = data[offset++];
  38529. var tableData = new Uint16Array(64);
  38530. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  38531. for (j = 0; j < 64; j++) {
  38532. z = dctZigZag[j];
  38533. tableData[z] = data[offset++];
  38534. }
  38535. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  38536. for (j = 0; j < 64; j++) {
  38537. z = dctZigZag[j];
  38538. tableData[z] = readUint16();
  38539. }
  38540. } else {
  38541. throw 'DQT: invalid table spec';
  38542. }
  38543. quantizationTables[quantizationTableSpec & 15] = tableData;
  38544. }
  38545. break;
  38546. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  38547. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  38548. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  38549. if (frame) {
  38550. throw 'Only single frame JPEGs supported';
  38551. }
  38552. readUint16(); // skip data length
  38553. frame = {};
  38554. frame.extended = (fileMarker === 0xFFC1);
  38555. frame.progressive = (fileMarker === 0xFFC2);
  38556. frame.precision = data[offset++];
  38557. frame.scanLines = readUint16();
  38558. frame.samplesPerLine = readUint16();
  38559. frame.components = [];
  38560. frame.componentIds = {};
  38561. var componentsCount = data[offset++], componentId;
  38562. var maxH = 0, maxV = 0;
  38563. for (i = 0; i < componentsCount; i++) {
  38564. componentId = data[offset];
  38565. var h = data[offset + 1] >> 4;
  38566. var v = data[offset + 1] & 15;
  38567. if (maxH < h) {
  38568. maxH = h;
  38569. }
  38570. if (maxV < v) {
  38571. maxV = v;
  38572. }
  38573. var qId = data[offset + 2];
  38574. l = frame.components.push({
  38575. h: h,
  38576. v: v,
  38577. quantizationTable: quantizationTables[qId]
  38578. });
  38579. frame.componentIds[componentId] = l - 1;
  38580. offset += 3;
  38581. }
  38582. frame.maxH = maxH;
  38583. frame.maxV = maxV;
  38584. prepareComponents(frame);
  38585. break;
  38586. case 0xFFC4: // DHT (Define Huffman Tables)
  38587. var huffmanLength = readUint16();
  38588. for (i = 2; i < huffmanLength;) {
  38589. var huffmanTableSpec = data[offset++];
  38590. var codeLengths = new Uint8Array(16);
  38591. var codeLengthSum = 0;
  38592. for (j = 0; j < 16; j++, offset++) {
  38593. codeLengthSum += (codeLengths[j] = data[offset]);
  38594. }
  38595. var huffmanValues = new Uint8Array(codeLengthSum);
  38596. for (j = 0; j < codeLengthSum; j++, offset++) {
  38597. huffmanValues[j] = data[offset];
  38598. }
  38599. i += 17 + codeLengthSum;
  38600. ((huffmanTableSpec >> 4) === 0 ?
  38601. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  38602. buildHuffmanTable(codeLengths, huffmanValues);
  38603. }
  38604. break;
  38605. case 0xFFDD: // DRI (Define Restart Interval)
  38606. readUint16(); // skip data length
  38607. resetInterval = readUint16();
  38608. break;
  38609. case 0xFFDA: // SOS (Start of Scan)
  38610. var scanLength = readUint16();
  38611. var selectorsCount = data[offset++];
  38612. var components = [], component;
  38613. for (i = 0; i < selectorsCount; i++) {
  38614. var componentIndex = frame.componentIds[data[offset++]];
  38615. component = frame.components[componentIndex];
  38616. var tableSpec = data[offset++];
  38617. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  38618. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  38619. components.push(component);
  38620. }
  38621. var spectralStart = data[offset++];
  38622. var spectralEnd = data[offset++];
  38623. var successiveApproximation = data[offset++];
  38624. var processed = decodeScan(data, offset,
  38625. frame, components, resetInterval,
  38626. spectralStart, spectralEnd,
  38627. successiveApproximation >> 4, successiveApproximation & 15);
  38628. offset += processed;
  38629. break;
  38630. case 0xFFFF: // Fill bytes
  38631. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  38632. offset--;
  38633. }
  38634. break;
  38635. default:
  38636. if (data[offset - 3] === 0xFF &&
  38637. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  38638. // could be incorrect encoding -- last 0xFF byte of the previous
  38639. // block was eaten by the encoder
  38640. offset -= 3;
  38641. break;
  38642. }
  38643. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  38644. }
  38645. fileMarker = readUint16();
  38646. }
  38647. this.width = frame.samplesPerLine;
  38648. this.height = frame.scanLines;
  38649. this.jfif = jfif;
  38650. this.adobe = adobe;
  38651. this.components = [];
  38652. for (i = 0; i < frame.components.length; i++) {
  38653. component = frame.components[i];
  38654. this.components.push({
  38655. output: buildComponentData(frame, component),
  38656. scaleX: component.h / frame.maxH,
  38657. scaleY: component.v / frame.maxV,
  38658. blocksPerLine: component.blocksPerLine,
  38659. blocksPerColumn: component.blocksPerColumn
  38660. });
  38661. }
  38662. this.numComponents = this.components.length;
  38663. },
  38664. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38665. var scaleX = this.width / width, scaleY = this.height / height;
  38666. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38667. var x, y, i, j, k;
  38668. var index;
  38669. var offset = 0;
  38670. var output;
  38671. var numComponents = this.components.length;
  38672. var dataLength = width * height * numComponents;
  38673. var data = new Uint8Array(dataLength);
  38674. var xScaleBlockOffset = new Uint32Array(width);
  38675. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38676. for (i = 0; i < numComponents; i++) {
  38677. component = this.components[i];
  38678. componentScaleX = component.scaleX * scaleX;
  38679. componentScaleY = component.scaleY * scaleY;
  38680. offset = i;
  38681. output = component.output;
  38682. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38683. // precalculate the xScaleBlockOffset
  38684. for (x = 0; x < width; x++) {
  38685. j = 0 | (x * componentScaleX);
  38686. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38687. }
  38688. // linearize the blocks of the component
  38689. for (y = 0; y < height; y++) {
  38690. j = 0 | (y * componentScaleY);
  38691. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38692. for (x = 0; x < width; x++) {
  38693. data[offset] = output[index + xScaleBlockOffset[x]];
  38694. offset += numComponents;
  38695. }
  38696. }
  38697. }
  38698. // decodeTransform contains pairs of multiplier (-256..256) and additive
  38699. var transform = this.decodeTransform;
  38700. if (transform) {
  38701. for (i = 0; i < dataLength;) {
  38702. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38703. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38704. }
  38705. }
  38706. }
  38707. return data;
  38708. },
  38709. _isColorConversionNeeded: function isColorConversionNeeded() {
  38710. if (this.adobe && this.adobe.transformCode) {
  38711. // The adobe transform marker overrides any previous setting
  38712. return true;
  38713. } else if (this.numComponents === 3) {
  38714. return true;
  38715. } else {
  38716. return false;
  38717. }
  38718. },
  38719. _convertYccToRgb: function convertYccToRgb(data) {
  38720. var Y, Cb, Cr;
  38721. for (var i = 0, length = data.length; i < length; i += 3) {
  38722. Y = data[i ];
  38723. Cb = data[i + 1];
  38724. Cr = data[i + 2];
  38725. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38726. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38727. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38728. }
  38729. return data;
  38730. },
  38731. _convertYcckToRgb: function convertYcckToRgb(data) {
  38732. var Y, Cb, Cr, k;
  38733. var offset = 0;
  38734. for (var i = 0, length = data.length; i < length; i += 4) {
  38735. Y = data[i];
  38736. Cb = data[i + 1];
  38737. Cr = data[i + 2];
  38738. k = data[i + 3];
  38739. var r = -122.67195406894 +
  38740. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  38741. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  38742. 0.154362151871126) +
  38743. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  38744. 0.00477271405408747 * k + 1.53380253221734) +
  38745. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  38746. 0.48357088451265) +
  38747. k * (-0.000336197177618394 * k + 0.484791561490776);
  38748. var g = 107.268039397724 +
  38749. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  38750. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  38751. 0.176491792462875) +
  38752. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  38753. 0.000770482631801132 * k - 0.151051492775562) +
  38754. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  38755. 0.25802910206845) +
  38756. k * (-0.000318913117588328 * k - 0.213742400323665);
  38757. var b = -20.810012546947 +
  38758. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  38759. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  38760. 0.814272968359295) +
  38761. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  38762. 0.000560833691242812 * k - 0.195152027534049) +
  38763. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  38764. 0.116935020465145) +
  38765. k * (-0.000343531996510555 * k + 0.24165260232407);
  38766. data[offset++] = clamp0to255(r);
  38767. data[offset++] = clamp0to255(g);
  38768. data[offset++] = clamp0to255(b);
  38769. }
  38770. return data;
  38771. },
  38772. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38773. var Y, Cb, Cr;
  38774. for (var i = 0, length = data.length; i < length; i += 4) {
  38775. Y = data[i];
  38776. Cb = data[i + 1];
  38777. Cr = data[i + 2];
  38778. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38779. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38780. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38781. // K in data[i + 3] is unchanged
  38782. }
  38783. return data;
  38784. },
  38785. _convertCmykToRgb: function convertCmykToRgb(data) {
  38786. var c, m, y, k;
  38787. var offset = 0;
  38788. var min = -255 * 255 * 255;
  38789. var scale = 1 / 255 / 255;
  38790. for (var i = 0, length = data.length; i < length; i += 4) {
  38791. c = data[i];
  38792. m = data[i + 1];
  38793. y = data[i + 2];
  38794. k = data[i + 3];
  38795. var r =
  38796. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38797. 18.82290502165302 * y + 212.25662451639585 * k -
  38798. 72734.4411664936) +
  38799. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38800. 17.873870861415444 * k - 1401.7366389350734) +
  38801. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38802. 4465.541406466231) -
  38803. k * (21.86122147463605 * k + 48317.86113160301);
  38804. var g =
  38805. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38806. 6.871425592049007 * y + 31.159100130055922 * k -
  38807. 20220.756542821975) +
  38808. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38809. 131.35250912493976 * k - 48691.05921601825) +
  38810. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38811. 6341.191035517494) -
  38812. k * (20.737325471181034 * k + 47890.15695978492);
  38813. var b =
  38814. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38815. 30.89978309703729 * y - 0.23883238689178934 * k -
  38816. 3616.812083916688) +
  38817. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38818. 50.606957656360734 * k - 28620.90484698408) +
  38819. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38820. 49363.43385999684) -
  38821. k * (22.33816807309886 * k + 45932.16563550634);
  38822. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38823. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38824. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38825. }
  38826. return data;
  38827. },
  38828. getData: function getData(width, height, forceRGBoutput) {
  38829. if (this.numComponents > 4) {
  38830. throw 'Unsupported color mode';
  38831. }
  38832. // type of data: Uint8Array(width * height * numComponents)
  38833. var data = this._getLinearizedBlockData(width, height);
  38834. if (this.numComponents === 3) {
  38835. return this._convertYccToRgb(data);
  38836. } else if (this.numComponents === 4) {
  38837. if (this._isColorConversionNeeded()) {
  38838. if (forceRGBoutput) {
  38839. return this._convertYcckToRgb(data);
  38840. } else {
  38841. return this._convertYcckToCmyk(data);
  38842. }
  38843. } else if (forceRGBoutput) {
  38844. return this._convertCmykToRgb(data);
  38845. }
  38846. }
  38847. return data;
  38848. }
  38849. };
  38850. return constructor;
  38851. })();
  38852. var JpxImage = (function JpxImageClosure() {
  38853. // Table E.1
  38854. var SubbandsGainLog2 = {
  38855. 'LL': 0,
  38856. 'LH': 1,
  38857. 'HL': 1,
  38858. 'HH': 2
  38859. };
  38860. function JpxImage() {
  38861. this.failOnCorruptedImage = false;
  38862. }
  38863. JpxImage.prototype = {
  38864. parse: function JpxImage_parse(data) {
  38865. var head = readUint16(data, 0);
  38866. // No box header, immediate start of codestream (SOC)
  38867. if (head === 0xFF4F) {
  38868. this.parseCodestream(data, 0, data.length);
  38869. return;
  38870. }
  38871. var position = 0, length = data.length;
  38872. while (position < length) {
  38873. var headerSize = 8;
  38874. var lbox = readUint32(data, position);
  38875. var tbox = readUint32(data, position + 4);
  38876. position += headerSize;
  38877. if (lbox === 1) {
  38878. // XLBox: read UInt64 according to spec.
  38879. // JavaScript's int precision of 53 bit should be sufficient here.
  38880. lbox = readUint32(data, position) * 4294967296 +
  38881. readUint32(data, position + 4);
  38882. position += 8;
  38883. headerSize += 8;
  38884. }
  38885. if (lbox === 0) {
  38886. lbox = length - position + headerSize;
  38887. }
  38888. if (lbox < headerSize) {
  38889. throw new Error('JPX Error: Invalid box field size');
  38890. }
  38891. var dataLength = lbox - headerSize;
  38892. var jumpDataLength = true;
  38893. switch (tbox) {
  38894. case 0x6A703268: // 'jp2h'
  38895. jumpDataLength = false; // parsing child boxes
  38896. break;
  38897. case 0x636F6C72: // 'colr'
  38898. // Colorspaces are not used, the CS from the PDF is used.
  38899. var method = data[position];
  38900. var precedence = data[position + 1];
  38901. var approximation = data[position + 2];
  38902. if (method === 1) {
  38903. // enumerated colorspace
  38904. var colorspace = readUint32(data, position + 3);
  38905. switch (colorspace) {
  38906. case 16: // this indicates a sRGB colorspace
  38907. case 17: // this indicates a grayscale colorspace
  38908. case 18: // this indicates a YUV colorspace
  38909. break;
  38910. default:
  38911. warn('Unknown colorspace ' + colorspace);
  38912. break;
  38913. }
  38914. } else if (method === 2) {
  38915. info('ICC profile not supported');
  38916. }
  38917. break;
  38918. case 0x6A703263: // 'jp2c'
  38919. this.parseCodestream(data, position, position + dataLength);
  38920. break;
  38921. case 0x6A502020: // 'jP\024\024'
  38922. if (0x0d0a870a !== readUint32(data, position)) {
  38923. warn('Invalid JP2 signature');
  38924. }
  38925. break;
  38926. // The following header types are valid but currently not used:
  38927. case 0x6A501A1A: // 'jP\032\032'
  38928. case 0x66747970: // 'ftyp'
  38929. case 0x72726571: // 'rreq'
  38930. case 0x72657320: // 'res '
  38931. case 0x69686472: // 'ihdr'
  38932. break;
  38933. default:
  38934. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  38935. (tbox >> 16) & 0xFF,
  38936. (tbox >> 8) & 0xFF,
  38937. tbox & 0xFF);
  38938. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  38939. break;
  38940. }
  38941. if (jumpDataLength) {
  38942. position += dataLength;
  38943. }
  38944. }
  38945. },
  38946. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  38947. var newByte = stream.getByte();
  38948. while (newByte >= 0) {
  38949. var oldByte = newByte;
  38950. newByte = stream.getByte();
  38951. var code = (oldByte << 8) | newByte;
  38952. // Image and tile size (SIZ)
  38953. if (code === 0xFF51) {
  38954. stream.skip(4);
  38955. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  38956. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  38957. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  38958. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  38959. stream.skip(16);
  38960. var Csiz = stream.getUint16(); // Byte 36
  38961. this.width = Xsiz - XOsiz;
  38962. this.height = Ysiz - YOsiz;
  38963. this.componentsCount = Csiz;
  38964. // Results are always returned as Uint8Arrays
  38965. this.bitsPerComponent = 8;
  38966. return;
  38967. }
  38968. }
  38969. throw new Error('JPX Error: No size marker found in JPX stream');
  38970. },
  38971. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  38972. var context = {};
  38973. try {
  38974. var doNotRecover = false;
  38975. var position = start;
  38976. while (position + 1 < end) {
  38977. var code = readUint16(data, position);
  38978. position += 2;
  38979. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  38980. switch (code) {
  38981. case 0xFF4F: // Start of codestream (SOC)
  38982. context.mainHeader = true;
  38983. break;
  38984. case 0xFFD9: // End of codestream (EOC)
  38985. break;
  38986. case 0xFF51: // Image and tile size (SIZ)
  38987. length = readUint16(data, position);
  38988. var siz = {};
  38989. siz.Xsiz = readUint32(data, position + 4);
  38990. siz.Ysiz = readUint32(data, position + 8);
  38991. siz.XOsiz = readUint32(data, position + 12);
  38992. siz.YOsiz = readUint32(data, position + 16);
  38993. siz.XTsiz = readUint32(data, position + 20);
  38994. siz.YTsiz = readUint32(data, position + 24);
  38995. siz.XTOsiz = readUint32(data, position + 28);
  38996. siz.YTOsiz = readUint32(data, position + 32);
  38997. var componentsCount = readUint16(data, position + 36);
  38998. siz.Csiz = componentsCount;
  38999. var components = [];
  39000. j = position + 38;
  39001. for (var i = 0; i < componentsCount; i++) {
  39002. var component = {
  39003. precision: (data[j] & 0x7F) + 1,
  39004. isSigned: !!(data[j] & 0x80),
  39005. XRsiz: data[j + 1],
  39006. YRsiz: data[j + 1]
  39007. };
  39008. calculateComponentDimensions(component, siz);
  39009. components.push(component);
  39010. }
  39011. context.SIZ = siz;
  39012. context.components = components;
  39013. calculateTileGrids(context, components);
  39014. context.QCC = [];
  39015. context.COC = [];
  39016. break;
  39017. case 0xFF5C: // Quantization default (QCD)
  39018. length = readUint16(data, position);
  39019. var qcd = {};
  39020. j = position + 2;
  39021. sqcd = data[j++];
  39022. switch (sqcd & 0x1F) {
  39023. case 0:
  39024. spqcdSize = 8;
  39025. scalarExpounded = true;
  39026. break;
  39027. case 1:
  39028. spqcdSize = 16;
  39029. scalarExpounded = false;
  39030. break;
  39031. case 2:
  39032. spqcdSize = 16;
  39033. scalarExpounded = true;
  39034. break;
  39035. default:
  39036. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39037. }
  39038. qcd.noQuantization = (spqcdSize === 8);
  39039. qcd.scalarExpounded = scalarExpounded;
  39040. qcd.guardBits = sqcd >> 5;
  39041. spqcds = [];
  39042. while (j < length + position) {
  39043. var spqcd = {};
  39044. if (spqcdSize === 8) {
  39045. spqcd.epsilon = data[j++] >> 3;
  39046. spqcd.mu = 0;
  39047. } else {
  39048. spqcd.epsilon = data[j] >> 3;
  39049. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39050. j += 2;
  39051. }
  39052. spqcds.push(spqcd);
  39053. }
  39054. qcd.SPqcds = spqcds;
  39055. if (context.mainHeader) {
  39056. context.QCD = qcd;
  39057. } else {
  39058. context.currentTile.QCD = qcd;
  39059. context.currentTile.QCC = [];
  39060. }
  39061. break;
  39062. case 0xFF5D: // Quantization component (QCC)
  39063. length = readUint16(data, position);
  39064. var qcc = {};
  39065. j = position + 2;
  39066. var cqcc;
  39067. if (context.SIZ.Csiz < 257) {
  39068. cqcc = data[j++];
  39069. } else {
  39070. cqcc = readUint16(data, j);
  39071. j += 2;
  39072. }
  39073. sqcd = data[j++];
  39074. switch (sqcd & 0x1F) {
  39075. case 0:
  39076. spqcdSize = 8;
  39077. scalarExpounded = true;
  39078. break;
  39079. case 1:
  39080. spqcdSize = 16;
  39081. scalarExpounded = false;
  39082. break;
  39083. case 2:
  39084. spqcdSize = 16;
  39085. scalarExpounded = true;
  39086. break;
  39087. default:
  39088. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39089. }
  39090. qcc.noQuantization = (spqcdSize === 8);
  39091. qcc.scalarExpounded = scalarExpounded;
  39092. qcc.guardBits = sqcd >> 5;
  39093. spqcds = [];
  39094. while (j < (length + position)) {
  39095. spqcd = {};
  39096. if (spqcdSize === 8) {
  39097. spqcd.epsilon = data[j++] >> 3;
  39098. spqcd.mu = 0;
  39099. } else {
  39100. spqcd.epsilon = data[j] >> 3;
  39101. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39102. j += 2;
  39103. }
  39104. spqcds.push(spqcd);
  39105. }
  39106. qcc.SPqcds = spqcds;
  39107. if (context.mainHeader) {
  39108. context.QCC[cqcc] = qcc;
  39109. } else {
  39110. context.currentTile.QCC[cqcc] = qcc;
  39111. }
  39112. break;
  39113. case 0xFF52: // Coding style default (COD)
  39114. length = readUint16(data, position);
  39115. var cod = {};
  39116. j = position + 2;
  39117. var scod = data[j++];
  39118. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  39119. cod.sopMarkerUsed = !!(scod & 2);
  39120. cod.ephMarkerUsed = !!(scod & 4);
  39121. cod.progressionOrder = data[j++];
  39122. cod.layersCount = readUint16(data, j);
  39123. j += 2;
  39124. cod.multipleComponentTransform = data[j++];
  39125. cod.decompositionLevelsCount = data[j++];
  39126. cod.xcb = (data[j++] & 0xF) + 2;
  39127. cod.ycb = (data[j++] & 0xF) + 2;
  39128. var blockStyle = data[j++];
  39129. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  39130. cod.resetContextProbabilities = !!(blockStyle & 2);
  39131. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  39132. cod.verticalyStripe = !!(blockStyle & 8);
  39133. cod.predictableTermination = !!(blockStyle & 16);
  39134. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  39135. cod.reversibleTransformation = data[j++];
  39136. if (cod.entropyCoderWithCustomPrecincts) {
  39137. var precinctsSizes = [];
  39138. while (j < length + position) {
  39139. var precinctsSize = data[j++];
  39140. precinctsSizes.push({
  39141. PPx: precinctsSize & 0xF,
  39142. PPy: precinctsSize >> 4
  39143. });
  39144. }
  39145. cod.precinctsSizes = precinctsSizes;
  39146. }
  39147. var unsupported = [];
  39148. if (cod.selectiveArithmeticCodingBypass) {
  39149. unsupported.push('selectiveArithmeticCodingBypass');
  39150. }
  39151. if (cod.resetContextProbabilities) {
  39152. unsupported.push('resetContextProbabilities');
  39153. }
  39154. if (cod.terminationOnEachCodingPass) {
  39155. unsupported.push('terminationOnEachCodingPass');
  39156. }
  39157. if (cod.verticalyStripe) {
  39158. unsupported.push('verticalyStripe');
  39159. }
  39160. if (cod.predictableTermination) {
  39161. unsupported.push('predictableTermination');
  39162. }
  39163. if (unsupported.length > 0) {
  39164. doNotRecover = true;
  39165. throw new Error('JPX Error: Unsupported COD options (' +
  39166. unsupported.join(', ') + ')');
  39167. }
  39168. if (context.mainHeader) {
  39169. context.COD = cod;
  39170. } else {
  39171. context.currentTile.COD = cod;
  39172. context.currentTile.COC = [];
  39173. }
  39174. break;
  39175. case 0xFF90: // Start of tile-part (SOT)
  39176. length = readUint16(data, position);
  39177. tile = {};
  39178. tile.index = readUint16(data, position + 2);
  39179. tile.length = readUint32(data, position + 4);
  39180. tile.dataEnd = tile.length + position - 2;
  39181. tile.partIndex = data[position + 8];
  39182. tile.partsCount = data[position + 9];
  39183. context.mainHeader = false;
  39184. if (tile.partIndex === 0) {
  39185. // reset component specific settings
  39186. tile.COD = context.COD;
  39187. tile.COC = context.COC.slice(0); // clone of the global COC
  39188. tile.QCD = context.QCD;
  39189. tile.QCC = context.QCC.slice(0); // clone of the global COC
  39190. }
  39191. context.currentTile = tile;
  39192. break;
  39193. case 0xFF93: // Start of data (SOD)
  39194. tile = context.currentTile;
  39195. if (tile.partIndex === 0) {
  39196. initializeTile(context, tile.index);
  39197. buildPackets(context);
  39198. }
  39199. // moving to the end of the data
  39200. length = tile.dataEnd - position;
  39201. parseTilePackets(context, data, position, length);
  39202. break;
  39203. case 0xFF55: // Tile-part lengths, main header (TLM)
  39204. case 0xFF57: // Packet length, main header (PLM)
  39205. case 0xFF58: // Packet length, tile-part header (PLT)
  39206. case 0xFF64: // Comment (COM)
  39207. length = readUint16(data, position);
  39208. // skipping content
  39209. break;
  39210. case 0xFF53: // Coding style component (COC)
  39211. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  39212. 'not implemented');
  39213. default:
  39214. throw new Error('JPX Error: Unknown codestream code: ' +
  39215. code.toString(16));
  39216. }
  39217. position += length;
  39218. }
  39219. } catch (e) {
  39220. if (doNotRecover || this.failOnCorruptedImage) {
  39221. throw e;
  39222. } else {
  39223. warn('Trying to recover from ' + e.message);
  39224. }
  39225. }
  39226. this.tiles = transformComponents(context);
  39227. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  39228. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  39229. this.componentsCount = context.SIZ.Csiz;
  39230. }
  39231. };
  39232. function calculateComponentDimensions(component, siz) {
  39233. // Section B.2 Component mapping
  39234. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  39235. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  39236. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  39237. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  39238. component.width = component.x1 - component.x0;
  39239. component.height = component.y1 - component.y0;
  39240. }
  39241. function calculateTileGrids(context, components) {
  39242. var siz = context.SIZ;
  39243. // Section B.3 Division into tile and tile-components
  39244. var tile, tiles = [];
  39245. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  39246. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  39247. for (var q = 0; q < numYtiles; q++) {
  39248. for (var p = 0; p < numXtiles; p++) {
  39249. tile = {};
  39250. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  39251. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  39252. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  39253. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  39254. tile.width = tile.tx1 - tile.tx0;
  39255. tile.height = tile.ty1 - tile.ty0;
  39256. tile.components = [];
  39257. tiles.push(tile);
  39258. }
  39259. }
  39260. context.tiles = tiles;
  39261. var componentsCount = siz.Csiz;
  39262. for (var i = 0, ii = componentsCount; i < ii; i++) {
  39263. var component = components[i];
  39264. for (var j = 0, jj = tiles.length; j < jj; j++) {
  39265. var tileComponent = {};
  39266. tile = tiles[j];
  39267. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  39268. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  39269. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  39270. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  39271. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  39272. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  39273. tile.components[i] = tileComponent;
  39274. }
  39275. }
  39276. }
  39277. function getBlocksDimensions(context, component, r) {
  39278. var codOrCoc = component.codingStyleParameters;
  39279. var result = {};
  39280. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  39281. result.PPx = 15;
  39282. result.PPy = 15;
  39283. } else {
  39284. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  39285. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  39286. }
  39287. // calculate codeblock size as described in section B.7
  39288. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  39289. Math.min(codOrCoc.xcb, result.PPx));
  39290. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  39291. Math.min(codOrCoc.ycb, result.PPy));
  39292. return result;
  39293. }
  39294. function buildPrecincts(context, resolution, dimensions) {
  39295. // Section B.6 Division resolution to precincts
  39296. var precinctWidth = 1 << dimensions.PPx;
  39297. var precinctHeight = 1 << dimensions.PPy;
  39298. // Jasper introduces codeblock groups for mapping each subband codeblocks
  39299. // to precincts. Precinct partition divides a resolution according to width
  39300. // and height parameters. The subband that belongs to the resolution level
  39301. // has a different size than the level, unless it is the zero resolution.
  39302. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  39303. // The precinct partitioning for a particular subband is derived from a
  39304. // partitioning of its parent LL band (i.e., the LL band at the next higher
  39305. // resolution level)... The LL band associated with each resolution level is
  39306. // divided into precincts... Each of the resulting precinct regions is then
  39307. // mapped into its child subbands (if any) at the next lower resolution
  39308. // level. This is accomplished by using the coordinate transformation
  39309. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  39310. // coordinates of a point in the LL band and child subband, respectively.
  39311. var isZeroRes = resolution.resLevel === 0;
  39312. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  39313. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  39314. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  39315. Math.ceil(resolution.trx1 / precinctWidth) -
  39316. Math.floor(resolution.trx0 / precinctWidth) : 0);
  39317. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  39318. Math.ceil(resolution.try1 / precinctHeight) -
  39319. Math.floor(resolution.try0 / precinctHeight) : 0);
  39320. var numprecincts = numprecinctswide * numprecinctshigh;
  39321. resolution.precinctParameters = {
  39322. precinctWidth: precinctWidth,
  39323. precinctHeight: precinctHeight,
  39324. numprecinctswide: numprecinctswide,
  39325. numprecinctshigh: numprecinctshigh,
  39326. numprecincts: numprecincts,
  39327. precinctWidthInSubband: precinctWidthInSubband,
  39328. precinctHeightInSubband: precinctHeightInSubband
  39329. };
  39330. }
  39331. function buildCodeblocks(context, subband, dimensions) {
  39332. // Section B.7 Division sub-band into code-blocks
  39333. var xcb_ = dimensions.xcb_;
  39334. var ycb_ = dimensions.ycb_;
  39335. var codeblockWidth = 1 << xcb_;
  39336. var codeblockHeight = 1 << ycb_;
  39337. var cbx0 = subband.tbx0 >> xcb_;
  39338. var cby0 = subband.tby0 >> ycb_;
  39339. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  39340. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  39341. var precinctParameters = subband.resolution.precinctParameters;
  39342. var codeblocks = [];
  39343. var precincts = [];
  39344. var i, j, codeblock, precinctNumber;
  39345. for (j = cby0; j < cby1; j++) {
  39346. for (i = cbx0; i < cbx1; i++) {
  39347. codeblock = {
  39348. cbx: i,
  39349. cby: j,
  39350. tbx0: codeblockWidth * i,
  39351. tby0: codeblockHeight * j,
  39352. tbx1: codeblockWidth * (i + 1),
  39353. tby1: codeblockHeight * (j + 1)
  39354. };
  39355. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  39356. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  39357. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  39358. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  39359. // Calculate precinct number for this codeblock, codeblock position
  39360. // should be relative to its subband, use actual dimension and position
  39361. // See comment about codeblock group width and height
  39362. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  39363. precinctParameters.precinctWidthInSubband);
  39364. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  39365. precinctParameters.precinctHeightInSubband);
  39366. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  39367. codeblock.precinctNumber = precinctNumber;
  39368. codeblock.subbandType = subband.type;
  39369. codeblock.Lblock = 3;
  39370. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  39371. codeblock.tby1_ <= codeblock.tby0_) {
  39372. continue;
  39373. }
  39374. codeblocks.push(codeblock);
  39375. // building precinct for the sub-band
  39376. var precinct = precincts[precinctNumber];
  39377. if (precinct !== undefined) {
  39378. if (i < precinct.cbxMin) {
  39379. precinct.cbxMin = i;
  39380. } else if (i > precinct.cbxMax) {
  39381. precinct.cbxMax = i;
  39382. }
  39383. if (j < precinct.cbyMin) {
  39384. precinct.cbxMin = j;
  39385. } else if (j > precinct.cbyMax) {
  39386. precinct.cbyMax = j;
  39387. }
  39388. } else {
  39389. precincts[precinctNumber] = precinct = {
  39390. cbxMin: i,
  39391. cbyMin: j,
  39392. cbxMax: i,
  39393. cbyMax: j
  39394. };
  39395. }
  39396. codeblock.precinct = precinct;
  39397. }
  39398. }
  39399. subband.codeblockParameters = {
  39400. codeblockWidth: xcb_,
  39401. codeblockHeight: ycb_,
  39402. numcodeblockwide: cbx1 - cbx0 + 1,
  39403. numcodeblockhigh: cby1 - cby0 + 1
  39404. };
  39405. subband.codeblocks = codeblocks;
  39406. subband.precincts = precincts;
  39407. }
  39408. function createPacket(resolution, precinctNumber, layerNumber) {
  39409. var precinctCodeblocks = [];
  39410. // Section B.10.8 Order of info in packet
  39411. var subbands = resolution.subbands;
  39412. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  39413. for (var i = 0, ii = subbands.length; i < ii; i++) {
  39414. var subband = subbands[i];
  39415. var codeblocks = subband.codeblocks;
  39416. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  39417. var codeblock = codeblocks[j];
  39418. if (codeblock.precinctNumber !== precinctNumber) {
  39419. continue;
  39420. }
  39421. precinctCodeblocks.push(codeblock);
  39422. }
  39423. }
  39424. return {
  39425. layerNumber: layerNumber,
  39426. codeblocks: precinctCodeblocks
  39427. };
  39428. }
  39429. function LayerResolutionComponentPositionIterator(context) {
  39430. var siz = context.SIZ;
  39431. var tileIndex = context.currentTile.index;
  39432. var tile = context.tiles[tileIndex];
  39433. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39434. var componentsCount = siz.Csiz;
  39435. var maxDecompositionLevelsCount = 0;
  39436. for (var q = 0; q < componentsCount; q++) {
  39437. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39438. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39439. }
  39440. var l = 0, r = 0, i = 0, k = 0;
  39441. this.nextPacket = function JpxImage_nextPacket() {
  39442. // Section B.12.1.1 Layer-resolution-component-position
  39443. for (; l < layersCount; l++) {
  39444. for (; r <= maxDecompositionLevelsCount; r++) {
  39445. for (; i < componentsCount; i++) {
  39446. var component = tile.components[i];
  39447. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39448. continue;
  39449. }
  39450. var resolution = component.resolutions[r];
  39451. var numprecincts = resolution.precinctParameters.numprecincts;
  39452. for (; k < numprecincts;) {
  39453. var packet = createPacket(resolution, k, l);
  39454. k++;
  39455. return packet;
  39456. }
  39457. k = 0;
  39458. }
  39459. i = 0;
  39460. }
  39461. r = 0;
  39462. }
  39463. throw new Error('JPX Error: Out of packets');
  39464. };
  39465. }
  39466. function ResolutionLayerComponentPositionIterator(context) {
  39467. var siz = context.SIZ;
  39468. var tileIndex = context.currentTile.index;
  39469. var tile = context.tiles[tileIndex];
  39470. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39471. var componentsCount = siz.Csiz;
  39472. var maxDecompositionLevelsCount = 0;
  39473. for (var q = 0; q < componentsCount; q++) {
  39474. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39475. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39476. }
  39477. var r = 0, l = 0, i = 0, k = 0;
  39478. this.nextPacket = function JpxImage_nextPacket() {
  39479. // Section B.12.1.2 Resolution-layer-component-position
  39480. for (; r <= maxDecompositionLevelsCount; r++) {
  39481. for (; l < layersCount; l++) {
  39482. for (; i < componentsCount; i++) {
  39483. var component = tile.components[i];
  39484. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39485. continue;
  39486. }
  39487. var resolution = component.resolutions[r];
  39488. var numprecincts = resolution.precinctParameters.numprecincts;
  39489. for (; k < numprecincts;) {
  39490. var packet = createPacket(resolution, k, l);
  39491. k++;
  39492. return packet;
  39493. }
  39494. k = 0;
  39495. }
  39496. i = 0;
  39497. }
  39498. l = 0;
  39499. }
  39500. throw new Error('JPX Error: Out of packets');
  39501. };
  39502. }
  39503. function ResolutionPositionComponentLayerIterator(context) {
  39504. var siz = context.SIZ;
  39505. var tileIndex = context.currentTile.index;
  39506. var tile = context.tiles[tileIndex];
  39507. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39508. var componentsCount = siz.Csiz;
  39509. var l, r, c, p;
  39510. var maxDecompositionLevelsCount = 0;
  39511. for (c = 0; c < componentsCount; c++) {
  39512. var component = tile.components[c];
  39513. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39514. component.codingStyleParameters.decompositionLevelsCount);
  39515. }
  39516. var maxNumPrecinctsInLevel = new Int32Array(
  39517. maxDecompositionLevelsCount + 1);
  39518. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  39519. var maxNumPrecincts = 0;
  39520. for (c = 0; c < componentsCount; ++c) {
  39521. var resolutions = tile.components[c].resolutions;
  39522. if (r < resolutions.length) {
  39523. maxNumPrecincts = Math.max(maxNumPrecincts,
  39524. resolutions[r].precinctParameters.numprecincts);
  39525. }
  39526. }
  39527. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  39528. }
  39529. l = 0;
  39530. r = 0;
  39531. c = 0;
  39532. p = 0;
  39533. this.nextPacket = function JpxImage_nextPacket() {
  39534. // Section B.12.1.3 Resolution-position-component-layer
  39535. for (; r <= maxDecompositionLevelsCount; r++) {
  39536. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  39537. for (; c < componentsCount; c++) {
  39538. var component = tile.components[c];
  39539. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39540. continue;
  39541. }
  39542. var resolution = component.resolutions[r];
  39543. var numprecincts = resolution.precinctParameters.numprecincts;
  39544. if (p >= numprecincts) {
  39545. continue;
  39546. }
  39547. for (; l < layersCount;) {
  39548. var packet = createPacket(resolution, p, l);
  39549. l++;
  39550. return packet;
  39551. }
  39552. l = 0;
  39553. }
  39554. c = 0;
  39555. }
  39556. p = 0;
  39557. }
  39558. throw new Error('JPX Error: Out of packets');
  39559. };
  39560. }
  39561. function PositionComponentResolutionLayerIterator(context) {
  39562. var siz = context.SIZ;
  39563. var tileIndex = context.currentTile.index;
  39564. var tile = context.tiles[tileIndex];
  39565. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39566. var componentsCount = siz.Csiz;
  39567. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39568. var precinctsIterationSizes = precinctsSizes;
  39569. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39570. this.nextPacket = function JpxImage_nextPacket() {
  39571. // Section B.12.1.4 Position-component-resolution-layer
  39572. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39573. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39574. for (; c < componentsCount; c++) {
  39575. var component = tile.components[c];
  39576. var decompositionLevelsCount =
  39577. component.codingStyleParameters.decompositionLevelsCount;
  39578. for (; r <= decompositionLevelsCount; r++) {
  39579. var resolution = component.resolutions[r];
  39580. var sizeInImageScale =
  39581. precinctsSizes.components[c].resolutions[r];
  39582. var k = getPrecinctIndexIfExist(
  39583. px,
  39584. py,
  39585. sizeInImageScale,
  39586. precinctsIterationSizes,
  39587. resolution);
  39588. if (k === null) {
  39589. continue;
  39590. }
  39591. for (; l < layersCount;) {
  39592. var packet = createPacket(resolution, k, l);
  39593. l++;
  39594. return packet;
  39595. }
  39596. l = 0;
  39597. }
  39598. r = 0;
  39599. }
  39600. c = 0;
  39601. }
  39602. px = 0;
  39603. }
  39604. throw new Error('JPX Error: Out of packets');
  39605. };
  39606. }
  39607. function ComponentPositionResolutionLayerIterator(context) {
  39608. var siz = context.SIZ;
  39609. var tileIndex = context.currentTile.index;
  39610. var tile = context.tiles[tileIndex];
  39611. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39612. var componentsCount = siz.Csiz;
  39613. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39614. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39615. this.nextPacket = function JpxImage_nextPacket() {
  39616. // Section B.12.1.5 Component-position-resolution-layer
  39617. for (; c < componentsCount; ++c) {
  39618. var component = tile.components[c];
  39619. var precinctsIterationSizes = precinctsSizes.components[c];
  39620. var decompositionLevelsCount =
  39621. component.codingStyleParameters.decompositionLevelsCount;
  39622. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39623. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39624. for (; r <= decompositionLevelsCount; r++) {
  39625. var resolution = component.resolutions[r];
  39626. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  39627. var k = getPrecinctIndexIfExist(
  39628. px,
  39629. py,
  39630. sizeInImageScale,
  39631. precinctsIterationSizes,
  39632. resolution);
  39633. if (k === null) {
  39634. continue;
  39635. }
  39636. for (; l < layersCount;) {
  39637. var packet = createPacket(resolution, k, l);
  39638. l++;
  39639. return packet;
  39640. }
  39641. l = 0;
  39642. }
  39643. r = 0;
  39644. }
  39645. px = 0;
  39646. }
  39647. py = 0;
  39648. }
  39649. throw new Error('JPX Error: Out of packets');
  39650. };
  39651. }
  39652. function getPrecinctIndexIfExist(
  39653. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  39654. var posX = pxIndex * precinctIterationSizes.minWidth;
  39655. var posY = pyIndex * precinctIterationSizes.minHeight;
  39656. if (posX % sizeInImageScale.width !== 0 ||
  39657. posY % sizeInImageScale.height !== 0) {
  39658. return null;
  39659. }
  39660. var startPrecinctRowIndex =
  39661. (posY / sizeInImageScale.width) *
  39662. resolution.precinctParameters.numprecinctswide;
  39663. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  39664. }
  39665. function getPrecinctSizesInImageScale(tile) {
  39666. var componentsCount = tile.components.length;
  39667. var minWidth = Number.MAX_VALUE;
  39668. var minHeight = Number.MAX_VALUE;
  39669. var maxNumWide = 0;
  39670. var maxNumHigh = 0;
  39671. var sizePerComponent = new Array(componentsCount);
  39672. for (var c = 0; c < componentsCount; c++) {
  39673. var component = tile.components[c];
  39674. var decompositionLevelsCount =
  39675. component.codingStyleParameters.decompositionLevelsCount;
  39676. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  39677. var minWidthCurrentComponent = Number.MAX_VALUE;
  39678. var minHeightCurrentComponent = Number.MAX_VALUE;
  39679. var maxNumWideCurrentComponent = 0;
  39680. var maxNumHighCurrentComponent = 0;
  39681. var scale = 1;
  39682. for (var r = decompositionLevelsCount; r >= 0; --r) {
  39683. var resolution = component.resolutions[r];
  39684. var widthCurrentResolution =
  39685. scale * resolution.precinctParameters.precinctWidth;
  39686. var heightCurrentResolution =
  39687. scale * resolution.precinctParameters.precinctHeight;
  39688. minWidthCurrentComponent = Math.min(
  39689. minWidthCurrentComponent,
  39690. widthCurrentResolution);
  39691. minHeightCurrentComponent = Math.min(
  39692. minHeightCurrentComponent,
  39693. heightCurrentResolution);
  39694. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  39695. resolution.precinctParameters.numprecinctswide);
  39696. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  39697. resolution.precinctParameters.numprecinctshigh);
  39698. sizePerResolution[r] = {
  39699. width: widthCurrentResolution,
  39700. height: heightCurrentResolution
  39701. };
  39702. scale <<= 1;
  39703. }
  39704. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  39705. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  39706. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  39707. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  39708. sizePerComponent[c] = {
  39709. resolutions: sizePerResolution,
  39710. minWidth: minWidthCurrentComponent,
  39711. minHeight: minHeightCurrentComponent,
  39712. maxNumWide: maxNumWideCurrentComponent,
  39713. maxNumHigh: maxNumHighCurrentComponent
  39714. };
  39715. }
  39716. return {
  39717. components: sizePerComponent,
  39718. minWidth: minWidth,
  39719. minHeight: minHeight,
  39720. maxNumWide: maxNumWide,
  39721. maxNumHigh: maxNumHigh
  39722. };
  39723. }
  39724. function buildPackets(context) {
  39725. var siz = context.SIZ;
  39726. var tileIndex = context.currentTile.index;
  39727. var tile = context.tiles[tileIndex];
  39728. var componentsCount = siz.Csiz;
  39729. // Creating resolutions and sub-bands for each component
  39730. for (var c = 0; c < componentsCount; c++) {
  39731. var component = tile.components[c];
  39732. var decompositionLevelsCount =
  39733. component.codingStyleParameters.decompositionLevelsCount;
  39734. // Section B.5 Resolution levels and sub-bands
  39735. var resolutions = [];
  39736. var subbands = [];
  39737. for (var r = 0; r <= decompositionLevelsCount; r++) {
  39738. var blocksDimensions = getBlocksDimensions(context, component, r);
  39739. var resolution = {};
  39740. var scale = 1 << (decompositionLevelsCount - r);
  39741. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  39742. resolution.try0 = Math.ceil(component.tcy0 / scale);
  39743. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  39744. resolution.try1 = Math.ceil(component.tcy1 / scale);
  39745. resolution.resLevel = r;
  39746. buildPrecincts(context, resolution, blocksDimensions);
  39747. resolutions.push(resolution);
  39748. var subband;
  39749. if (r === 0) {
  39750. // one sub-band (LL) with last decomposition
  39751. subband = {};
  39752. subband.type = 'LL';
  39753. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  39754. subband.tby0 = Math.ceil(component.tcy0 / scale);
  39755. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  39756. subband.tby1 = Math.ceil(component.tcy1 / scale);
  39757. subband.resolution = resolution;
  39758. buildCodeblocks(context, subband, blocksDimensions);
  39759. subbands.push(subband);
  39760. resolution.subbands = [subband];
  39761. } else {
  39762. var bscale = 1 << (decompositionLevelsCount - r + 1);
  39763. var resolutionSubbands = [];
  39764. // three sub-bands (HL, LH and HH) with rest of decompositions
  39765. subband = {};
  39766. subband.type = 'HL';
  39767. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39768. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  39769. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39770. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  39771. subband.resolution = resolution;
  39772. buildCodeblocks(context, subband, blocksDimensions);
  39773. subbands.push(subband);
  39774. resolutionSubbands.push(subband);
  39775. subband = {};
  39776. subband.type = 'LH';
  39777. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  39778. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39779. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  39780. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39781. subband.resolution = resolution;
  39782. buildCodeblocks(context, subband, blocksDimensions);
  39783. subbands.push(subband);
  39784. resolutionSubbands.push(subband);
  39785. subband = {};
  39786. subband.type = 'HH';
  39787. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39788. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39789. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39790. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39791. subband.resolution = resolution;
  39792. buildCodeblocks(context, subband, blocksDimensions);
  39793. subbands.push(subband);
  39794. resolutionSubbands.push(subband);
  39795. resolution.subbands = resolutionSubbands;
  39796. }
  39797. }
  39798. component.resolutions = resolutions;
  39799. component.subbands = subbands;
  39800. }
  39801. // Generate the packets sequence
  39802. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  39803. switch (progressionOrder) {
  39804. case 0:
  39805. tile.packetsIterator =
  39806. new LayerResolutionComponentPositionIterator(context);
  39807. break;
  39808. case 1:
  39809. tile.packetsIterator =
  39810. new ResolutionLayerComponentPositionIterator(context);
  39811. break;
  39812. case 2:
  39813. tile.packetsIterator =
  39814. new ResolutionPositionComponentLayerIterator(context);
  39815. break;
  39816. case 3:
  39817. tile.packetsIterator =
  39818. new PositionComponentResolutionLayerIterator(context);
  39819. break;
  39820. case 4:
  39821. tile.packetsIterator =
  39822. new ComponentPositionResolutionLayerIterator(context);
  39823. break;
  39824. default:
  39825. throw new Error('JPX Error: Unsupported progression order ' +
  39826. progressionOrder);
  39827. }
  39828. }
  39829. function parseTilePackets(context, data, offset, dataLength) {
  39830. var position = 0;
  39831. var buffer, bufferSize = 0, skipNextBit = false;
  39832. function readBits(count) {
  39833. while (bufferSize < count) {
  39834. var b = data[offset + position];
  39835. position++;
  39836. if (skipNextBit) {
  39837. buffer = (buffer << 7) | b;
  39838. bufferSize += 7;
  39839. skipNextBit = false;
  39840. } else {
  39841. buffer = (buffer << 8) | b;
  39842. bufferSize += 8;
  39843. }
  39844. if (b === 0xFF) {
  39845. skipNextBit = true;
  39846. }
  39847. }
  39848. bufferSize -= count;
  39849. return (buffer >>> bufferSize) & ((1 << count) - 1);
  39850. }
  39851. function skipMarkerIfEqual(value) {
  39852. if (data[offset + position - 1] === 0xFF &&
  39853. data[offset + position] === value) {
  39854. skipBytes(1);
  39855. return true;
  39856. } else if (data[offset + position] === 0xFF &&
  39857. data[offset + position + 1] === value) {
  39858. skipBytes(2);
  39859. return true;
  39860. }
  39861. return false;
  39862. }
  39863. function skipBytes(count) {
  39864. position += count;
  39865. }
  39866. function alignToByte() {
  39867. bufferSize = 0;
  39868. if (skipNextBit) {
  39869. position++;
  39870. skipNextBit = false;
  39871. }
  39872. }
  39873. function readCodingpasses() {
  39874. if (readBits(1) === 0) {
  39875. return 1;
  39876. }
  39877. if (readBits(1) === 0) {
  39878. return 2;
  39879. }
  39880. var value = readBits(2);
  39881. if (value < 3) {
  39882. return value + 3;
  39883. }
  39884. value = readBits(5);
  39885. if (value < 31) {
  39886. return value + 6;
  39887. }
  39888. value = readBits(7);
  39889. return value + 37;
  39890. }
  39891. var tileIndex = context.currentTile.index;
  39892. var tile = context.tiles[tileIndex];
  39893. var sopMarkerUsed = context.COD.sopMarkerUsed;
  39894. var ephMarkerUsed = context.COD.ephMarkerUsed;
  39895. var packetsIterator = tile.packetsIterator;
  39896. while (position < dataLength) {
  39897. alignToByte();
  39898. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  39899. // Skip also marker segment length and packet sequence ID
  39900. skipBytes(4);
  39901. }
  39902. var packet = packetsIterator.nextPacket();
  39903. if (!readBits(1)) {
  39904. continue;
  39905. }
  39906. var layerNumber = packet.layerNumber;
  39907. var queue = [], codeblock;
  39908. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  39909. codeblock = packet.codeblocks[i];
  39910. var precinct = codeblock.precinct;
  39911. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  39912. var codeblockRow = codeblock.cby - precinct.cbyMin;
  39913. var codeblockIncluded = false;
  39914. var firstTimeInclusion = false;
  39915. var valueReady;
  39916. if (codeblock['included'] !== undefined) {
  39917. codeblockIncluded = !!readBits(1);
  39918. } else {
  39919. // reading inclusion tree
  39920. precinct = codeblock.precinct;
  39921. var inclusionTree, zeroBitPlanesTree;
  39922. if (precinct['inclusionTree'] !== undefined) {
  39923. inclusionTree = precinct.inclusionTree;
  39924. } else {
  39925. // building inclusion and zero bit-planes trees
  39926. var width = precinct.cbxMax - precinct.cbxMin + 1;
  39927. var height = precinct.cbyMax - precinct.cbyMin + 1;
  39928. inclusionTree = new InclusionTree(width, height, layerNumber);
  39929. zeroBitPlanesTree = new TagTree(width, height);
  39930. precinct.inclusionTree = inclusionTree;
  39931. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  39932. }
  39933. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39934. while (true) {
  39935. if (readBits(1)) {
  39936. valueReady = !inclusionTree.nextLevel();
  39937. if (valueReady) {
  39938. codeblock.included = true;
  39939. codeblockIncluded = firstTimeInclusion = true;
  39940. break;
  39941. }
  39942. } else {
  39943. inclusionTree.incrementValue(layerNumber);
  39944. break;
  39945. }
  39946. }
  39947. }
  39948. }
  39949. if (!codeblockIncluded) {
  39950. continue;
  39951. }
  39952. if (firstTimeInclusion) {
  39953. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  39954. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  39955. while (true) {
  39956. if (readBits(1)) {
  39957. valueReady = !zeroBitPlanesTree.nextLevel();
  39958. if (valueReady) {
  39959. break;
  39960. }
  39961. } else {
  39962. zeroBitPlanesTree.incrementValue();
  39963. }
  39964. }
  39965. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  39966. }
  39967. var codingpasses = readCodingpasses();
  39968. while (readBits(1)) {
  39969. codeblock.Lblock++;
  39970. }
  39971. var codingpassesLog2 = log2(codingpasses);
  39972. // rounding down log2
  39973. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  39974. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  39975. var codedDataLength = readBits(bits);
  39976. queue.push({
  39977. codeblock: codeblock,
  39978. codingpasses: codingpasses,
  39979. dataLength: codedDataLength
  39980. });
  39981. }
  39982. alignToByte();
  39983. if (ephMarkerUsed) {
  39984. skipMarkerIfEqual(0x92);
  39985. }
  39986. while (queue.length > 0) {
  39987. var packetItem = queue.shift();
  39988. codeblock = packetItem.codeblock;
  39989. if (codeblock['data'] === undefined) {
  39990. codeblock.data = [];
  39991. }
  39992. codeblock.data.push({
  39993. data: data,
  39994. start: offset + position,
  39995. end: offset + position + packetItem.dataLength,
  39996. codingpasses: packetItem.codingpasses
  39997. });
  39998. position += packetItem.dataLength;
  39999. }
  40000. }
  40001. return position;
  40002. }
  40003. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  40004. delta, mb, reversible, segmentationSymbolUsed) {
  40005. var x0 = subband.tbx0;
  40006. var y0 = subband.tby0;
  40007. var width = subband.tbx1 - subband.tbx0;
  40008. var codeblocks = subband.codeblocks;
  40009. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  40010. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  40011. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  40012. var codeblock = codeblocks[i];
  40013. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  40014. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  40015. if (blockWidth === 0 || blockHeight === 0) {
  40016. continue;
  40017. }
  40018. if (codeblock['data'] === undefined) {
  40019. continue;
  40020. }
  40021. var bitModel, currentCodingpassType;
  40022. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  40023. codeblock.zeroBitPlanes, mb);
  40024. currentCodingpassType = 2; // first bit plane starts from cleanup
  40025. // collect data
  40026. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  40027. var j, jj, dataItem;
  40028. for (j = 0, jj = data.length; j < jj; j++) {
  40029. dataItem = data[j];
  40030. totalLength += dataItem.end - dataItem.start;
  40031. codingpasses += dataItem.codingpasses;
  40032. }
  40033. var encodedData = new Uint8Array(totalLength);
  40034. var position = 0;
  40035. for (j = 0, jj = data.length; j < jj; j++) {
  40036. dataItem = data[j];
  40037. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  40038. encodedData.set(chunk, position);
  40039. position += chunk.length;
  40040. }
  40041. // decoding the item
  40042. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  40043. bitModel.setDecoder(decoder);
  40044. for (j = 0; j < codingpasses; j++) {
  40045. switch (currentCodingpassType) {
  40046. case 0:
  40047. bitModel.runSignificancePropogationPass();
  40048. break;
  40049. case 1:
  40050. bitModel.runMagnitudeRefinementPass();
  40051. break;
  40052. case 2:
  40053. bitModel.runCleanupPass();
  40054. if (segmentationSymbolUsed) {
  40055. bitModel.checkSegmentationSymbol();
  40056. }
  40057. break;
  40058. }
  40059. currentCodingpassType = (currentCodingpassType + 1) % 3;
  40060. }
  40061. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  40062. var sign = bitModel.coefficentsSign;
  40063. var magnitude = bitModel.coefficentsMagnitude;
  40064. var bitsDecoded = bitModel.bitsDecoded;
  40065. var magnitudeCorrection = reversible ? 0 : 0.5;
  40066. var k, n, nb;
  40067. position = 0;
  40068. // Do the interleaving of Section F.3.3 here, so we do not need
  40069. // to copy later. LL level is not interleaved, just copied.
  40070. var interleave = (subband.type !== 'LL');
  40071. for (j = 0; j < blockHeight; j++) {
  40072. var row = (offset / width) | 0; // row in the non-interleaved subband
  40073. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  40074. for (k = 0; k < blockWidth; k++) {
  40075. n = magnitude[position];
  40076. if (n !== 0) {
  40077. n = (n + magnitudeCorrection) * delta;
  40078. if (sign[position] !== 0) {
  40079. n = -n;
  40080. }
  40081. nb = bitsDecoded[position];
  40082. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  40083. if (reversible && (nb >= mb)) {
  40084. coefficients[pos] = n;
  40085. } else {
  40086. coefficients[pos] = n * (1 << (mb - nb));
  40087. }
  40088. }
  40089. offset++;
  40090. position++;
  40091. }
  40092. offset += width - blockWidth;
  40093. }
  40094. }
  40095. }
  40096. function transformTile(context, tile, c) {
  40097. var component = tile.components[c];
  40098. var codingStyleParameters = component.codingStyleParameters;
  40099. var quantizationParameters = component.quantizationParameters;
  40100. var decompositionLevelsCount =
  40101. codingStyleParameters.decompositionLevelsCount;
  40102. var spqcds = quantizationParameters.SPqcds;
  40103. var scalarExpounded = quantizationParameters.scalarExpounded;
  40104. var guardBits = quantizationParameters.guardBits;
  40105. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  40106. var precision = context.components[c].precision;
  40107. var reversible = codingStyleParameters.reversibleTransformation;
  40108. var transform = (reversible ? new ReversibleTransform() :
  40109. new IrreversibleTransform());
  40110. var subbandCoefficients = [];
  40111. var b = 0;
  40112. for (var i = 0; i <= decompositionLevelsCount; i++) {
  40113. var resolution = component.resolutions[i];
  40114. var width = resolution.trx1 - resolution.trx0;
  40115. var height = resolution.try1 - resolution.try0;
  40116. // Allocate space for the whole sublevel.
  40117. var coefficients = new Float32Array(width * height);
  40118. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  40119. var mu, epsilon;
  40120. if (!scalarExpounded) {
  40121. // formula E-5
  40122. mu = spqcds[0].mu;
  40123. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  40124. } else {
  40125. mu = spqcds[b].mu;
  40126. epsilon = spqcds[b].epsilon;
  40127. b++;
  40128. }
  40129. var subband = resolution.subbands[j];
  40130. var gainLog2 = SubbandsGainLog2[subband.type];
  40131. // calulate quantization coefficient (Section E.1.1.1)
  40132. var delta = (reversible ? 1 :
  40133. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  40134. var mb = (guardBits + epsilon - 1);
  40135. // In the first resolution level, copyCoefficients will fill the
  40136. // whole array with coefficients. In the succeding passes,
  40137. // copyCoefficients will consecutively fill in the values that belong
  40138. // to the interleaved positions of the HL, LH, and HH coefficients.
  40139. // The LL coefficients will then be interleaved in Transform.iterate().
  40140. copyCoefficients(coefficients, width, height, subband, delta, mb,
  40141. reversible, segmentationSymbolUsed);
  40142. }
  40143. subbandCoefficients.push({
  40144. width: width,
  40145. height: height,
  40146. items: coefficients
  40147. });
  40148. }
  40149. var result = transform.calculate(subbandCoefficients,
  40150. component.tcx0, component.tcy0);
  40151. return {
  40152. left: component.tcx0,
  40153. top: component.tcy0,
  40154. width: result.width,
  40155. height: result.height,
  40156. items: result.items
  40157. };
  40158. }
  40159. function transformComponents(context) {
  40160. var siz = context.SIZ;
  40161. var components = context.components;
  40162. var componentsCount = siz.Csiz;
  40163. var resultImages = [];
  40164. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  40165. var tile = context.tiles[i];
  40166. var transformedTiles = [];
  40167. var c;
  40168. for (c = 0; c < componentsCount; c++) {
  40169. transformedTiles[c] = transformTile(context, tile, c);
  40170. }
  40171. var tile0 = transformedTiles[0];
  40172. var out = new Uint8Array(tile0.items.length * componentsCount);
  40173. var result = {
  40174. left: tile0.left,
  40175. top: tile0.top,
  40176. width: tile0.width,
  40177. height: tile0.height,
  40178. items: out
  40179. };
  40180. // Section G.2.2 Inverse multi component transform
  40181. var shift, offset, max, min, maxK;
  40182. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  40183. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  40184. var fourComponents = componentsCount === 4;
  40185. var y0items = transformedTiles[0].items;
  40186. var y1items = transformedTiles[1].items;
  40187. var y2items = transformedTiles[2].items;
  40188. var y3items = fourComponents ? transformedTiles[3].items : null;
  40189. // HACK: The multiple component transform formulas below assume that
  40190. // all components have the same precision. With this in mind, we
  40191. // compute shift and offset only once.
  40192. shift = components[0].precision - 8;
  40193. offset = (128 << shift) + 0.5;
  40194. max = 255 * (1 << shift);
  40195. maxK = max * 0.5;
  40196. min = -maxK;
  40197. var component0 = tile.components[0];
  40198. var alpha01 = componentsCount - 3;
  40199. jj = y0items.length;
  40200. if (!component0.codingStyleParameters.reversibleTransformation) {
  40201. // inverse irreversible multiple component transform
  40202. for (j = 0; j < jj; j++, pos += alpha01) {
  40203. y0 = y0items[j] + offset;
  40204. y1 = y1items[j];
  40205. y2 = y2items[j];
  40206. r = y0 + 1.402 * y2;
  40207. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  40208. b = y0 + 1.772 * y1;
  40209. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40210. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40211. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40212. }
  40213. } else {
  40214. // inverse reversible multiple component transform
  40215. for (j = 0; j < jj; j++, pos += alpha01) {
  40216. y0 = y0items[j] + offset;
  40217. y1 = y1items[j];
  40218. y2 = y2items[j];
  40219. g = y0 - ((y2 + y1) >> 2);
  40220. r = g + y2;
  40221. b = g + y1;
  40222. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40223. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40224. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40225. }
  40226. }
  40227. if (fourComponents) {
  40228. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  40229. k = y3items[j];
  40230. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  40231. }
  40232. }
  40233. } else { // no multi-component transform
  40234. for (c = 0; c < componentsCount; c++) {
  40235. var items = transformedTiles[c].items;
  40236. shift = components[c].precision - 8;
  40237. offset = (128 << shift) + 0.5;
  40238. max = (127.5 * (1 << shift));
  40239. min = -max;
  40240. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  40241. val = items[j];
  40242. out[pos] = val <= min ? 0 :
  40243. val >= max ? 255 : (val + offset) >> shift;
  40244. pos += componentsCount;
  40245. }
  40246. }
  40247. }
  40248. resultImages.push(result);
  40249. }
  40250. return resultImages;
  40251. }
  40252. function initializeTile(context, tileIndex) {
  40253. var siz = context.SIZ;
  40254. var componentsCount = siz.Csiz;
  40255. var tile = context.tiles[tileIndex];
  40256. for (var c = 0; c < componentsCount; c++) {
  40257. var component = tile.components[c];
  40258. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  40259. context.currentTile.QCC[c] : context.currentTile.QCD);
  40260. component.quantizationParameters = qcdOrQcc;
  40261. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  40262. context.currentTile.COC[c] : context.currentTile.COD);
  40263. component.codingStyleParameters = codOrCoc;
  40264. }
  40265. tile.codingStyleDefaultParameters = context.currentTile.COD;
  40266. }
  40267. // Section B.10.2 Tag trees
  40268. var TagTree = (function TagTreeClosure() {
  40269. function TagTree(width, height) {
  40270. var levelsLength = log2(Math.max(width, height)) + 1;
  40271. this.levels = [];
  40272. for (var i = 0; i < levelsLength; i++) {
  40273. var level = {
  40274. width: width,
  40275. height: height,
  40276. items: []
  40277. };
  40278. this.levels.push(level);
  40279. width = Math.ceil(width / 2);
  40280. height = Math.ceil(height / 2);
  40281. }
  40282. }
  40283. TagTree.prototype = {
  40284. reset: function TagTree_reset(i, j) {
  40285. var currentLevel = 0, value = 0, level;
  40286. while (currentLevel < this.levels.length) {
  40287. level = this.levels[currentLevel];
  40288. var index = i + j * level.width;
  40289. if (level.items[index] !== undefined) {
  40290. value = level.items[index];
  40291. break;
  40292. }
  40293. level.index = index;
  40294. i >>= 1;
  40295. j >>= 1;
  40296. currentLevel++;
  40297. }
  40298. currentLevel--;
  40299. level = this.levels[currentLevel];
  40300. level.items[level.index] = value;
  40301. this.currentLevel = currentLevel;
  40302. delete this.value;
  40303. },
  40304. incrementValue: function TagTree_incrementValue() {
  40305. var level = this.levels[this.currentLevel];
  40306. level.items[level.index]++;
  40307. },
  40308. nextLevel: function TagTree_nextLevel() {
  40309. var currentLevel = this.currentLevel;
  40310. var level = this.levels[currentLevel];
  40311. var value = level.items[level.index];
  40312. currentLevel--;
  40313. if (currentLevel < 0) {
  40314. this.value = value;
  40315. return false;
  40316. }
  40317. this.currentLevel = currentLevel;
  40318. level = this.levels[currentLevel];
  40319. level.items[level.index] = value;
  40320. return true;
  40321. }
  40322. };
  40323. return TagTree;
  40324. })();
  40325. var InclusionTree = (function InclusionTreeClosure() {
  40326. function InclusionTree(width, height, defaultValue) {
  40327. var levelsLength = log2(Math.max(width, height)) + 1;
  40328. this.levels = [];
  40329. for (var i = 0; i < levelsLength; i++) {
  40330. var items = new Uint8Array(width * height);
  40331. for (var j = 0, jj = items.length; j < jj; j++) {
  40332. items[j] = defaultValue;
  40333. }
  40334. var level = {
  40335. width: width,
  40336. height: height,
  40337. items: items
  40338. };
  40339. this.levels.push(level);
  40340. width = Math.ceil(width / 2);
  40341. height = Math.ceil(height / 2);
  40342. }
  40343. }
  40344. InclusionTree.prototype = {
  40345. reset: function InclusionTree_reset(i, j, stopValue) {
  40346. var currentLevel = 0;
  40347. while (currentLevel < this.levels.length) {
  40348. var level = this.levels[currentLevel];
  40349. var index = i + j * level.width;
  40350. level.index = index;
  40351. var value = level.items[index];
  40352. if (value === 0xFF) {
  40353. break;
  40354. }
  40355. if (value > stopValue) {
  40356. this.currentLevel = currentLevel;
  40357. // already know about this one, propagating the value to top levels
  40358. this.propagateValues();
  40359. return false;
  40360. }
  40361. i >>= 1;
  40362. j >>= 1;
  40363. currentLevel++;
  40364. }
  40365. this.currentLevel = currentLevel - 1;
  40366. return true;
  40367. },
  40368. incrementValue: function InclusionTree_incrementValue(stopValue) {
  40369. var level = this.levels[this.currentLevel];
  40370. level.items[level.index] = stopValue + 1;
  40371. this.propagateValues();
  40372. },
  40373. propagateValues: function InclusionTree_propagateValues() {
  40374. var levelIndex = this.currentLevel;
  40375. var level = this.levels[levelIndex];
  40376. var currentValue = level.items[level.index];
  40377. while (--levelIndex >= 0) {
  40378. level = this.levels[levelIndex];
  40379. level.items[level.index] = currentValue;
  40380. }
  40381. },
  40382. nextLevel: function InclusionTree_nextLevel() {
  40383. var currentLevel = this.currentLevel;
  40384. var level = this.levels[currentLevel];
  40385. var value = level.items[level.index];
  40386. level.items[level.index] = 0xFF;
  40387. currentLevel--;
  40388. if (currentLevel < 0) {
  40389. return false;
  40390. }
  40391. this.currentLevel = currentLevel;
  40392. level = this.levels[currentLevel];
  40393. level.items[level.index] = value;
  40394. return true;
  40395. }
  40396. };
  40397. return InclusionTree;
  40398. })();
  40399. // Section D. Coefficient bit modeling
  40400. var BitModel = (function BitModelClosure() {
  40401. var UNIFORM_CONTEXT = 17;
  40402. var RUNLENGTH_CONTEXT = 18;
  40403. // Table D-1
  40404. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  40405. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  40406. var LLAndLHContextsLabel = new Uint8Array([
  40407. 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,
  40408. 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,
  40409. 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
  40410. ]);
  40411. var HLContextLabel = new Uint8Array([
  40412. 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,
  40413. 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,
  40414. 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
  40415. ]);
  40416. var HHContextLabel = new Uint8Array([
  40417. 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,
  40418. 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,
  40419. 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
  40420. ]);
  40421. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  40422. this.width = width;
  40423. this.height = height;
  40424. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  40425. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  40426. var coefficientCount = width * height;
  40427. // coefficients outside the encoding region treated as insignificant
  40428. // add border state cells for significanceState
  40429. this.neighborsSignificance = new Uint8Array(coefficientCount);
  40430. this.coefficentsSign = new Uint8Array(coefficientCount);
  40431. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  40432. mb > 6 ? new Uint16Array(coefficientCount) :
  40433. new Uint8Array(coefficientCount);
  40434. this.processingFlags = new Uint8Array(coefficientCount);
  40435. var bitsDecoded = new Uint8Array(coefficientCount);
  40436. if (zeroBitPlanes !== 0) {
  40437. for (var i = 0; i < coefficientCount; i++) {
  40438. bitsDecoded[i] = zeroBitPlanes;
  40439. }
  40440. }
  40441. this.bitsDecoded = bitsDecoded;
  40442. this.reset();
  40443. }
  40444. BitModel.prototype = {
  40445. setDecoder: function BitModel_setDecoder(decoder) {
  40446. this.decoder = decoder;
  40447. },
  40448. reset: function BitModel_reset() {
  40449. // We have 17 contexts that are accessed via context labels,
  40450. // plus the uniform and runlength context.
  40451. this.contexts = new Int8Array(19);
  40452. // Contexts are packed into 1 byte:
  40453. // highest 7 bits carry the index, lowest bit carries mps
  40454. this.contexts[0] = (4 << 1) | 0;
  40455. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  40456. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  40457. },
  40458. setNeighborsSignificance:
  40459. function BitModel_setNeighborsSignificance(row, column, index) {
  40460. var neighborsSignificance = this.neighborsSignificance;
  40461. var width = this.width, height = this.height;
  40462. var left = (column > 0);
  40463. var right = (column + 1 < width);
  40464. var i;
  40465. if (row > 0) {
  40466. i = index - width;
  40467. if (left) {
  40468. neighborsSignificance[i - 1] += 0x10;
  40469. }
  40470. if (right) {
  40471. neighborsSignificance[i + 1] += 0x10;
  40472. }
  40473. neighborsSignificance[i] += 0x04;
  40474. }
  40475. if (row + 1 < height) {
  40476. i = index + width;
  40477. if (left) {
  40478. neighborsSignificance[i - 1] += 0x10;
  40479. }
  40480. if (right) {
  40481. neighborsSignificance[i + 1] += 0x10;
  40482. }
  40483. neighborsSignificance[i] += 0x04;
  40484. }
  40485. if (left) {
  40486. neighborsSignificance[index - 1] += 0x01;
  40487. }
  40488. if (right) {
  40489. neighborsSignificance[index + 1] += 0x01;
  40490. }
  40491. neighborsSignificance[index] |= 0x80;
  40492. },
  40493. runSignificancePropogationPass:
  40494. function BitModel_runSignificancePropogationPass() {
  40495. var decoder = this.decoder;
  40496. var width = this.width, height = this.height;
  40497. var coefficentsMagnitude = this.coefficentsMagnitude;
  40498. var coefficentsSign = this.coefficentsSign;
  40499. var neighborsSignificance = this.neighborsSignificance;
  40500. var processingFlags = this.processingFlags;
  40501. var contexts = this.contexts;
  40502. var labels = this.contextLabelTable;
  40503. var bitsDecoded = this.bitsDecoded;
  40504. var processedInverseMask = ~1;
  40505. var processedMask = 1;
  40506. var firstMagnitudeBitMask = 2;
  40507. for (var i0 = 0; i0 < height; i0 += 4) {
  40508. for (var j = 0; j < width; j++) {
  40509. var index = i0 * width + j;
  40510. for (var i1 = 0; i1 < 4; i1++, index += width) {
  40511. var i = i0 + i1;
  40512. if (i >= height) {
  40513. break;
  40514. }
  40515. // clear processed flag first
  40516. processingFlags[index] &= processedInverseMask;
  40517. if (coefficentsMagnitude[index] ||
  40518. !neighborsSignificance[index]) {
  40519. continue;
  40520. }
  40521. var contextLabel = labels[neighborsSignificance[index]];
  40522. var decision = decoder.readBit(contexts, contextLabel);
  40523. if (decision) {
  40524. var sign = this.decodeSignBit(i, j, index);
  40525. coefficentsSign[index] = sign;
  40526. coefficentsMagnitude[index] = 1;
  40527. this.setNeighborsSignificance(i, j, index);
  40528. processingFlags[index] |= firstMagnitudeBitMask;
  40529. }
  40530. bitsDecoded[index]++;
  40531. processingFlags[index] |= processedMask;
  40532. }
  40533. }
  40534. }
  40535. },
  40536. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  40537. var width = this.width, height = this.height;
  40538. var coefficentsMagnitude = this.coefficentsMagnitude;
  40539. var coefficentsSign = this.coefficentsSign;
  40540. var contribution, sign0, sign1, significance1;
  40541. var contextLabel, decoded;
  40542. // calculate horizontal contribution
  40543. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  40544. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  40545. sign1 = coefficentsSign[index + 1];
  40546. if (significance1) {
  40547. sign0 = coefficentsSign[index - 1];
  40548. contribution = 1 - sign1 - sign0;
  40549. } else {
  40550. contribution = 1 - sign1 - sign1;
  40551. }
  40552. } else if (significance1) {
  40553. sign0 = coefficentsSign[index - 1];
  40554. contribution = 1 - sign0 - sign0;
  40555. } else {
  40556. contribution = 0;
  40557. }
  40558. var horizontalContribution = 3 * contribution;
  40559. // calculate vertical contribution and combine with the horizontal
  40560. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  40561. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  40562. sign1 = coefficentsSign[index + width];
  40563. if (significance1) {
  40564. sign0 = coefficentsSign[index - width];
  40565. contribution = 1 - sign1 - sign0 + horizontalContribution;
  40566. } else {
  40567. contribution = 1 - sign1 - sign1 + horizontalContribution;
  40568. }
  40569. } else if (significance1) {
  40570. sign0 = coefficentsSign[index - width];
  40571. contribution = 1 - sign0 - sign0 + horizontalContribution;
  40572. } else {
  40573. contribution = horizontalContribution;
  40574. }
  40575. if (contribution >= 0) {
  40576. contextLabel = 9 + contribution;
  40577. decoded = this.decoder.readBit(this.contexts, contextLabel);
  40578. } else {
  40579. contextLabel = 9 - contribution;
  40580. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  40581. }
  40582. return decoded;
  40583. },
  40584. runMagnitudeRefinementPass:
  40585. function BitModel_runMagnitudeRefinementPass() {
  40586. var decoder = this.decoder;
  40587. var width = this.width, height = this.height;
  40588. var coefficentsMagnitude = this.coefficentsMagnitude;
  40589. var neighborsSignificance = this.neighborsSignificance;
  40590. var contexts = this.contexts;
  40591. var bitsDecoded = this.bitsDecoded;
  40592. var processingFlags = this.processingFlags;
  40593. var processedMask = 1;
  40594. var firstMagnitudeBitMask = 2;
  40595. var length = width * height;
  40596. var width4 = width * 4;
  40597. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  40598. indexNext = Math.min(length, index0 + width4);
  40599. for (var j = 0; j < width; j++) {
  40600. for (var index = index0 + j; index < indexNext; index += width) {
  40601. // significant but not those that have just become
  40602. if (!coefficentsMagnitude[index] ||
  40603. (processingFlags[index] & processedMask) !== 0) {
  40604. continue;
  40605. }
  40606. var contextLabel = 16;
  40607. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  40608. processingFlags[index] ^= firstMagnitudeBitMask;
  40609. // first refinement
  40610. var significance = neighborsSignificance[index] & 127;
  40611. contextLabel = significance === 0 ? 15 : 14;
  40612. }
  40613. var bit = decoder.readBit(contexts, contextLabel);
  40614. coefficentsMagnitude[index] =
  40615. (coefficentsMagnitude[index] << 1) | bit;
  40616. bitsDecoded[index]++;
  40617. processingFlags[index] |= processedMask;
  40618. }
  40619. }
  40620. }
  40621. },
  40622. runCleanupPass: function BitModel_runCleanupPass() {
  40623. var decoder = this.decoder;
  40624. var width = this.width, height = this.height;
  40625. var neighborsSignificance = this.neighborsSignificance;
  40626. var coefficentsMagnitude = this.coefficentsMagnitude;
  40627. var coefficentsSign = this.coefficentsSign;
  40628. var contexts = this.contexts;
  40629. var labels = this.contextLabelTable;
  40630. var bitsDecoded = this.bitsDecoded;
  40631. var processingFlags = this.processingFlags;
  40632. var processedMask = 1;
  40633. var firstMagnitudeBitMask = 2;
  40634. var oneRowDown = width;
  40635. var twoRowsDown = width * 2;
  40636. var threeRowsDown = width * 3;
  40637. var iNext;
  40638. for (var i0 = 0; i0 < height; i0 = iNext) {
  40639. iNext = Math.min(i0 + 4, height);
  40640. var indexBase = i0 * width;
  40641. var checkAllEmpty = i0 + 3 < height;
  40642. for (var j = 0; j < width; j++) {
  40643. var index0 = indexBase + j;
  40644. // using the property: labels[neighborsSignificance[index]] === 0
  40645. // when neighborsSignificance[index] === 0
  40646. var allEmpty = (checkAllEmpty &&
  40647. processingFlags[index0] === 0 &&
  40648. processingFlags[index0 + oneRowDown] === 0 &&
  40649. processingFlags[index0 + twoRowsDown] === 0 &&
  40650. processingFlags[index0 + threeRowsDown] === 0 &&
  40651. neighborsSignificance[index0] === 0 &&
  40652. neighborsSignificance[index0 + oneRowDown] === 0 &&
  40653. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  40654. neighborsSignificance[index0 + threeRowsDown] === 0);
  40655. var i1 = 0, index = index0;
  40656. var i = i0, sign;
  40657. if (allEmpty) {
  40658. var hasSignificantCoefficent =
  40659. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  40660. if (!hasSignificantCoefficent) {
  40661. bitsDecoded[index0]++;
  40662. bitsDecoded[index0 + oneRowDown]++;
  40663. bitsDecoded[index0 + twoRowsDown]++;
  40664. bitsDecoded[index0 + threeRowsDown]++;
  40665. continue; // next column
  40666. }
  40667. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40668. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40669. if (i1 !== 0) {
  40670. i = i0 + i1;
  40671. index += i1 * width;
  40672. }
  40673. sign = this.decodeSignBit(i, j, index);
  40674. coefficentsSign[index] = sign;
  40675. coefficentsMagnitude[index] = 1;
  40676. this.setNeighborsSignificance(i, j, index);
  40677. processingFlags[index] |= firstMagnitudeBitMask;
  40678. index = index0;
  40679. for (var i2 = i0; i2 <= i; i2++, index += width) {
  40680. bitsDecoded[index]++;
  40681. }
  40682. i1++;
  40683. }
  40684. for (i = i0 + i1; i < iNext; i++, index += width) {
  40685. if (coefficentsMagnitude[index] ||
  40686. (processingFlags[index] & processedMask) !== 0) {
  40687. continue;
  40688. }
  40689. var contextLabel = labels[neighborsSignificance[index]];
  40690. var decision = decoder.readBit(contexts, contextLabel);
  40691. if (decision === 1) {
  40692. sign = this.decodeSignBit(i, j, index);
  40693. coefficentsSign[index] = sign;
  40694. coefficentsMagnitude[index] = 1;
  40695. this.setNeighborsSignificance(i, j, index);
  40696. processingFlags[index] |= firstMagnitudeBitMask;
  40697. }
  40698. bitsDecoded[index]++;
  40699. }
  40700. }
  40701. }
  40702. },
  40703. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  40704. var decoder = this.decoder;
  40705. var contexts = this.contexts;
  40706. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  40707. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  40708. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40709. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40710. if (symbol !== 0xA) {
  40711. throw new Error('JPX Error: Invalid segmentation symbol');
  40712. }
  40713. }
  40714. };
  40715. return BitModel;
  40716. })();
  40717. // Section F, Discrete wavelet transformation
  40718. var Transform = (function TransformClosure() {
  40719. function Transform() {}
  40720. Transform.prototype.calculate =
  40721. function transformCalculate(subbands, u0, v0) {
  40722. var ll = subbands[0];
  40723. for (var i = 1, ii = subbands.length; i < ii; i++) {
  40724. ll = this.iterate(ll, subbands[i], u0, v0);
  40725. }
  40726. return ll;
  40727. };
  40728. Transform.prototype.extend = function extend(buffer, offset, size) {
  40729. // Section F.3.7 extending... using max extension of 4
  40730. var i1 = offset - 1, j1 = offset + 1;
  40731. var i2 = offset + size - 2, j2 = offset + size;
  40732. buffer[i1--] = buffer[j1++];
  40733. buffer[j2++] = buffer[i2--];
  40734. buffer[i1--] = buffer[j1++];
  40735. buffer[j2++] = buffer[i2--];
  40736. buffer[i1--] = buffer[j1++];
  40737. buffer[j2++] = buffer[i2--];
  40738. buffer[i1] = buffer[j1];
  40739. buffer[j2] = buffer[i2];
  40740. };
  40741. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  40742. u0, v0) {
  40743. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  40744. var width = hl_lh_hh.width;
  40745. var height = hl_lh_hh.height;
  40746. var items = hl_lh_hh.items;
  40747. var i, j, k, l, u, v;
  40748. // Interleave LL according to Section F.3.3
  40749. for (k = 0, i = 0; i < llHeight; i++) {
  40750. l = i * 2 * width;
  40751. for (j = 0; j < llWidth; j++, k++, l += 2) {
  40752. items[l] = llItems[k];
  40753. }
  40754. }
  40755. // The LL band is not needed anymore.
  40756. llItems = ll.items = null;
  40757. var bufferPadding = 4;
  40758. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  40759. // Section F.3.4 HOR_SR
  40760. if (width === 1) {
  40761. // if width = 1, when u0 even keep items as is, when odd divide by 2
  40762. if ((u0 & 1) !== 0) {
  40763. for (v = 0, k = 0; v < height; v++, k += width) {
  40764. items[k] *= 0.5;
  40765. }
  40766. }
  40767. } else {
  40768. for (v = 0, k = 0; v < height; v++, k += width) {
  40769. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  40770. this.extend(rowBuffer, bufferPadding, width);
  40771. this.filter(rowBuffer, bufferPadding, width);
  40772. items.set(
  40773. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  40774. k);
  40775. }
  40776. }
  40777. // Accesses to the items array can take long, because it may not fit into
  40778. // CPU cache and has to be fetched from main memory. Since subsequent
  40779. // accesses to the items array are not local when reading columns, we
  40780. // have a cache miss every time. To reduce cache misses, get up to
  40781. // 'numBuffers' items at a time and store them into the individual
  40782. // buffers. The colBuffers should be small enough to fit into CPU cache.
  40783. var numBuffers = 16;
  40784. var colBuffers = [];
  40785. for (i = 0; i < numBuffers; i++) {
  40786. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  40787. }
  40788. var b, currentBuffer = 0;
  40789. ll = bufferPadding + height;
  40790. // Section F.3.5 VER_SR
  40791. if (height === 1) {
  40792. // if height = 1, when v0 even keep items as is, when odd divide by 2
  40793. if ((v0 & 1) !== 0) {
  40794. for (u = 0; u < width; u++) {
  40795. items[u] *= 0.5;
  40796. }
  40797. }
  40798. } else {
  40799. for (u = 0; u < width; u++) {
  40800. // if we ran out of buffers, copy several image columns at once
  40801. if (currentBuffer === 0) {
  40802. numBuffers = Math.min(width - u, numBuffers);
  40803. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  40804. for (b = 0; b < numBuffers; b++) {
  40805. colBuffers[b][l] = items[k + b];
  40806. }
  40807. }
  40808. currentBuffer = numBuffers;
  40809. }
  40810. currentBuffer--;
  40811. var buffer = colBuffers[currentBuffer];
  40812. this.extend(buffer, bufferPadding, height);
  40813. this.filter(buffer, bufferPadding, height);
  40814. // If this is last buffer in this group of buffers, flush all buffers.
  40815. if (currentBuffer === 0) {
  40816. k = u - numBuffers + 1;
  40817. for (l = bufferPadding; l < ll; k += width, l++) {
  40818. for (b = 0; b < numBuffers; b++) {
  40819. items[k + b] = colBuffers[b][l];
  40820. }
  40821. }
  40822. }
  40823. }
  40824. }
  40825. return {
  40826. width: width,
  40827. height: height,
  40828. items: items
  40829. };
  40830. };
  40831. return Transform;
  40832. })();
  40833. // Section 3.8.2 Irreversible 9-7 filter
  40834. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  40835. function IrreversibleTransform() {
  40836. Transform.call(this);
  40837. }
  40838. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  40839. IrreversibleTransform.prototype.filter =
  40840. function irreversibleTransformFilter(x, offset, length) {
  40841. var len = length >> 1;
  40842. offset = offset | 0;
  40843. var j, n, current, next;
  40844. var alpha = -1.586134342059924;
  40845. var beta = -0.052980118572961;
  40846. var gamma = 0.882911075530934;
  40847. var delta = 0.443506852043971;
  40848. var K = 1.230174104914001;
  40849. var K_ = 1 / K;
  40850. // step 1 is combined with step 3
  40851. // step 2
  40852. j = offset - 3;
  40853. for (n = len + 4; n--; j += 2) {
  40854. x[j] *= K_;
  40855. }
  40856. // step 1 & 3
  40857. j = offset - 2;
  40858. current = delta * x[j -1];
  40859. for (n = len + 3; n--; j += 2) {
  40860. next = delta * x[j + 1];
  40861. x[j] = K * x[j] - current - next;
  40862. if (n--) {
  40863. j += 2;
  40864. current = delta * x[j + 1];
  40865. x[j] = K * x[j] - current - next;
  40866. } else {
  40867. break;
  40868. }
  40869. }
  40870. // step 4
  40871. j = offset - 1;
  40872. current = gamma * x[j - 1];
  40873. for (n = len + 2; n--; j += 2) {
  40874. next = gamma * x[j + 1];
  40875. x[j] -= current + next;
  40876. if (n--) {
  40877. j += 2;
  40878. current = gamma * x[j + 1];
  40879. x[j] -= current + next;
  40880. } else {
  40881. break;
  40882. }
  40883. }
  40884. // step 5
  40885. j = offset;
  40886. current = beta * x[j - 1];
  40887. for (n = len + 1; n--; j += 2) {
  40888. next = beta * x[j + 1];
  40889. x[j] -= current + next;
  40890. if (n--) {
  40891. j += 2;
  40892. current = beta * x[j + 1];
  40893. x[j] -= current + next;
  40894. } else {
  40895. break;
  40896. }
  40897. }
  40898. // step 6
  40899. if (len !== 0) {
  40900. j = offset + 1;
  40901. current = alpha * x[j - 1];
  40902. for (n = len; n--; j += 2) {
  40903. next = alpha * x[j + 1];
  40904. x[j] -= current + next;
  40905. if (n--) {
  40906. j += 2;
  40907. current = alpha * x[j + 1];
  40908. x[j] -= current + next;
  40909. } else {
  40910. break;
  40911. }
  40912. }
  40913. }
  40914. };
  40915. return IrreversibleTransform;
  40916. })();
  40917. // Section 3.8.1 Reversible 5-3 filter
  40918. var ReversibleTransform = (function ReversibleTransformClosure() {
  40919. function ReversibleTransform() {
  40920. Transform.call(this);
  40921. }
  40922. ReversibleTransform.prototype = Object.create(Transform.prototype);
  40923. ReversibleTransform.prototype.filter =
  40924. function reversibleTransformFilter(x, offset, length) {
  40925. var len = length >> 1;
  40926. offset = offset | 0;
  40927. var j, n;
  40928. for (j = offset, n = len + 1; n--; j += 2) {
  40929. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  40930. }
  40931. for (j = offset + 1, n = len; n--; j += 2) {
  40932. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  40933. }
  40934. };
  40935. return ReversibleTransform;
  40936. })();
  40937. return JpxImage;
  40938. })();
  40939. var Jbig2Image = (function Jbig2ImageClosure() {
  40940. // Utility data structures
  40941. function ContextCache() {}
  40942. ContextCache.prototype = {
  40943. getContexts: function(id) {
  40944. if (id in this) {
  40945. return this[id];
  40946. }
  40947. return (this[id] = new Int8Array(1 << 16));
  40948. }
  40949. };
  40950. function DecodingContext(data, start, end) {
  40951. this.data = data;
  40952. this.start = start;
  40953. this.end = end;
  40954. }
  40955. DecodingContext.prototype = {
  40956. get decoder() {
  40957. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  40958. return shadow(this, 'decoder', decoder);
  40959. },
  40960. get contextCache() {
  40961. var cache = new ContextCache();
  40962. return shadow(this, 'contextCache', cache);
  40963. }
  40964. };
  40965. // Annex A. Arithmetic Integer Decoding Procedure
  40966. // A.2 Procedure for decoding values
  40967. function decodeInteger(contextCache, procedure, decoder) {
  40968. var contexts = contextCache.getContexts(procedure);
  40969. var prev = 1;
  40970. function readBits(length) {
  40971. var v = 0;
  40972. for (var i = 0; i < length; i++) {
  40973. var bit = decoder.readBit(contexts, prev);
  40974. prev = (prev < 256 ? (prev << 1) | bit :
  40975. (((prev << 1) | bit) & 511) | 256);
  40976. v = (v << 1) | bit;
  40977. }
  40978. return v >>> 0;
  40979. }
  40980. var sign = readBits(1);
  40981. var value = readBits(1) ?
  40982. (readBits(1) ?
  40983. (readBits(1) ?
  40984. (readBits(1) ?
  40985. (readBits(1) ?
  40986. (readBits(32) + 4436) :
  40987. readBits(12) + 340) :
  40988. readBits(8) + 84) :
  40989. readBits(6) + 20) :
  40990. readBits(4) + 4) :
  40991. readBits(2);
  40992. return (sign === 0 ? value : (value > 0 ? -value : null));
  40993. }
  40994. // A.3 The IAID decoding procedure
  40995. function decodeIAID(contextCache, decoder, codeLength) {
  40996. var contexts = contextCache.getContexts('IAID');
  40997. var prev = 1;
  40998. for (var i = 0; i < codeLength; i++) {
  40999. var bit = decoder.readBit(contexts, prev);
  41000. prev = (prev << 1) | bit;
  41001. }
  41002. if (codeLength < 31) {
  41003. return prev & ((1 << codeLength) - 1);
  41004. }
  41005. return prev & 0x7FFFFFFF;
  41006. }
  41007. // 7.3 Segment types
  41008. var SegmentTypes = [
  41009. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  41010. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  41011. null, null, null, null, null, 'patternDictionary', null, null, null,
  41012. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  41013. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  41014. null, null, null, null, null, 'IntermediateGenericRegion', null,
  41015. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  41016. 'IntermediateGenericRefinementRegion', null,
  41017. 'ImmediateGenericRefinementRegion',
  41018. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  41019. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  41020. 'Tables', null, null, null, null, null, null, null, null,
  41021. 'Extension'
  41022. ];
  41023. var CodingTemplates = [
  41024. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  41025. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  41026. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  41027. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  41028. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  41029. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  41030. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  41031. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  41032. {x: -1, y: 0}],
  41033. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  41034. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  41035. ];
  41036. var RefinementTemplates = [
  41037. {
  41038. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  41039. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  41040. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  41041. },
  41042. {
  41043. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  41044. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  41045. {x: 0, y: 1}, {x: 1, y: 1}]
  41046. }
  41047. ];
  41048. // See 6.2.5.7 Decoding the bitmap.
  41049. var ReusedContexts = [
  41050. 0x9B25, // 10011 0110010 0101
  41051. 0x0795, // 0011 110010 101
  41052. 0x00E5, // 001 11001 01
  41053. 0x0195 // 011001 0101
  41054. ];
  41055. var RefinementReusedContexts = [
  41056. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  41057. 0x0008 // '0000' + '001000'
  41058. ];
  41059. function decodeBitmapTemplate0(width, height, decodingContext) {
  41060. var decoder = decodingContext.decoder;
  41061. var contexts = decodingContext.contextCache.getContexts('GB');
  41062. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  41063. // ...ooooo....
  41064. // ..ooooooo... Context template for current pixel (X)
  41065. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  41066. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  41067. for (i = 0; i < height; i++) {
  41068. row = bitmap[i] = new Uint8Array(width);
  41069. row1 = (i < 1) ? row : bitmap[i - 1];
  41070. row2 = (i < 2) ? row : bitmap[i - 2];
  41071. // At the beginning of each row:
  41072. // Fill contextLabel with pixels that are above/right of (X)
  41073. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  41074. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  41075. (row1[3] << 4);
  41076. for (j = 0; j < width; j++) {
  41077. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  41078. // At each pixel: Clear contextLabel pixels that are shifted
  41079. // out of the context, then add new ones.
  41080. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  41081. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  41082. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  41083. }
  41084. }
  41085. return bitmap;
  41086. }
  41087. // 6.2 Generic Region Decoding Procedure
  41088. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  41089. decodingContext) {
  41090. if (mmr) {
  41091. error('JBIG2 error: MMR encoding is not supported');
  41092. }
  41093. // Use optimized version for the most common case
  41094. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  41095. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  41096. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  41097. return decodeBitmapTemplate0(width, height, decodingContext);
  41098. }
  41099. var useskip = !!skip;
  41100. var template = CodingTemplates[templateIndex].concat(at);
  41101. // Sorting is non-standard, and it is not required. But sorting increases
  41102. // the number of template bits that can be reused from the previous
  41103. // contextLabel in the main loop.
  41104. template.sort(function (a, b) {
  41105. return (a.y - b.y) || (a.x - b.x);
  41106. });
  41107. var templateLength = template.length;
  41108. var templateX = new Int8Array(templateLength);
  41109. var templateY = new Int8Array(templateLength);
  41110. var changingTemplateEntries = [];
  41111. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  41112. var c, k;
  41113. for (k = 0; k < templateLength; k++) {
  41114. templateX[k] = template[k].x;
  41115. templateY[k] = template[k].y;
  41116. minX = Math.min(minX, template[k].x);
  41117. maxX = Math.max(maxX, template[k].x);
  41118. minY = Math.min(minY, template[k].y);
  41119. // Check if the template pixel appears in two consecutive context labels,
  41120. // so it can be reused. Otherwise, we add it to the list of changing
  41121. // template entries.
  41122. if (k < templateLength - 1 &&
  41123. template[k].y === template[k + 1].y &&
  41124. template[k].x === template[k + 1].x - 1) {
  41125. reuseMask |= 1 << (templateLength - 1 - k);
  41126. } else {
  41127. changingTemplateEntries.push(k);
  41128. }
  41129. }
  41130. var changingEntriesLength = changingTemplateEntries.length;
  41131. var changingTemplateX = new Int8Array(changingEntriesLength);
  41132. var changingTemplateY = new Int8Array(changingEntriesLength);
  41133. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  41134. for (c = 0; c < changingEntriesLength; c++) {
  41135. k = changingTemplateEntries[c];
  41136. changingTemplateX[c] = template[k].x;
  41137. changingTemplateY[c] = template[k].y;
  41138. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  41139. }
  41140. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  41141. var sbb_left = -minX;
  41142. var sbb_top = -minY;
  41143. var sbb_right = width - maxX;
  41144. var pseudoPixelContext = ReusedContexts[templateIndex];
  41145. var row = new Uint8Array(width);
  41146. var bitmap = [];
  41147. var decoder = decodingContext.decoder;
  41148. var contexts = decodingContext.contextCache.getContexts('GB');
  41149. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  41150. for (var i = 0; i < height; i++) {
  41151. if (prediction) {
  41152. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41153. ltp ^= sltp;
  41154. if (ltp) {
  41155. bitmap.push(row); // duplicate previous row
  41156. continue;
  41157. }
  41158. }
  41159. row = new Uint8Array(row);
  41160. bitmap.push(row);
  41161. for (j = 0; j < width; j++) {
  41162. if (useskip && skip[i][j]) {
  41163. row[j] = 0;
  41164. continue;
  41165. }
  41166. // Are we in the middle of a scanline, so we can reuse contextLabel
  41167. // bits?
  41168. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  41169. // If yes, we can just shift the bits that are reusable and only
  41170. // fetch the remaining ones.
  41171. contextLabel = (contextLabel << 1) & reuseMask;
  41172. for (k = 0; k < changingEntriesLength; k++) {
  41173. i0 = i + changingTemplateY[k];
  41174. j0 = j + changingTemplateX[k];
  41175. bit = bitmap[i0][j0];
  41176. if (bit) {
  41177. bit = changingTemplateBit[k];
  41178. contextLabel |= bit;
  41179. }
  41180. }
  41181. } else {
  41182. // compute the contextLabel from scratch
  41183. contextLabel = 0;
  41184. shift = templateLength - 1;
  41185. for (k = 0; k < templateLength; k++, shift--) {
  41186. j0 = j + templateX[k];
  41187. if (j0 >= 0 && j0 < width) {
  41188. i0 = i + templateY[k];
  41189. if (i0 >= 0) {
  41190. bit = bitmap[i0][j0];
  41191. if (bit) {
  41192. contextLabel |= bit << shift;
  41193. }
  41194. }
  41195. }
  41196. }
  41197. }
  41198. var pixel = decoder.readBit(contexts, contextLabel);
  41199. row[j] = pixel;
  41200. }
  41201. }
  41202. return bitmap;
  41203. }
  41204. // 6.3.2 Generic Refinement Region Decoding Procedure
  41205. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  41206. offsetX, offsetY, prediction, at,
  41207. decodingContext) {
  41208. var codingTemplate = RefinementTemplates[templateIndex].coding;
  41209. if (templateIndex === 0) {
  41210. codingTemplate = codingTemplate.concat([at[0]]);
  41211. }
  41212. var codingTemplateLength = codingTemplate.length;
  41213. var codingTemplateX = new Int32Array(codingTemplateLength);
  41214. var codingTemplateY = new Int32Array(codingTemplateLength);
  41215. var k;
  41216. for (k = 0; k < codingTemplateLength; k++) {
  41217. codingTemplateX[k] = codingTemplate[k].x;
  41218. codingTemplateY[k] = codingTemplate[k].y;
  41219. }
  41220. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  41221. if (templateIndex === 0) {
  41222. referenceTemplate = referenceTemplate.concat([at[1]]);
  41223. }
  41224. var referenceTemplateLength = referenceTemplate.length;
  41225. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  41226. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  41227. for (k = 0; k < referenceTemplateLength; k++) {
  41228. referenceTemplateX[k] = referenceTemplate[k].x;
  41229. referenceTemplateY[k] = referenceTemplate[k].y;
  41230. }
  41231. var referenceWidth = referenceBitmap[0].length;
  41232. var referenceHeight = referenceBitmap.length;
  41233. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  41234. var bitmap = [];
  41235. var decoder = decodingContext.decoder;
  41236. var contexts = decodingContext.contextCache.getContexts('GR');
  41237. var ltp = 0;
  41238. for (var i = 0; i < height; i++) {
  41239. if (prediction) {
  41240. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41241. ltp ^= sltp;
  41242. if (ltp) {
  41243. error('JBIG2 error: prediction is not supported');
  41244. }
  41245. }
  41246. var row = new Uint8Array(width);
  41247. bitmap.push(row);
  41248. for (var j = 0; j < width; j++) {
  41249. var i0, j0;
  41250. var contextLabel = 0;
  41251. for (k = 0; k < codingTemplateLength; k++) {
  41252. i0 = i + codingTemplateY[k];
  41253. j0 = j + codingTemplateX[k];
  41254. if (i0 < 0 || j0 < 0 || j0 >= width) {
  41255. contextLabel <<= 1; // out of bound pixel
  41256. } else {
  41257. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  41258. }
  41259. }
  41260. for (k = 0; k < referenceTemplateLength; k++) {
  41261. i0 = i + referenceTemplateY[k] + offsetY;
  41262. j0 = j + referenceTemplateX[k] + offsetX;
  41263. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  41264. j0 >= referenceWidth) {
  41265. contextLabel <<= 1; // out of bound pixel
  41266. } else {
  41267. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  41268. }
  41269. }
  41270. var pixel = decoder.readBit(contexts, contextLabel);
  41271. row[j] = pixel;
  41272. }
  41273. }
  41274. return bitmap;
  41275. }
  41276. // 6.5.5 Decoding the symbol dictionary
  41277. function decodeSymbolDictionary(huffman, refinement, symbols,
  41278. numberOfNewSymbols, numberOfExportedSymbols,
  41279. huffmanTables, templateIndex, at,
  41280. refinementTemplateIndex, refinementAt,
  41281. decodingContext) {
  41282. if (huffman) {
  41283. error('JBIG2 error: huffman is not supported');
  41284. }
  41285. var newSymbols = [];
  41286. var currentHeight = 0;
  41287. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  41288. var decoder = decodingContext.decoder;
  41289. var contextCache = decodingContext.contextCache;
  41290. while (newSymbols.length < numberOfNewSymbols) {
  41291. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  41292. currentHeight += deltaHeight;
  41293. var currentWidth = 0;
  41294. var totalWidth = 0;
  41295. while (true) {
  41296. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  41297. if (deltaWidth === null) {
  41298. break; // OOB
  41299. }
  41300. currentWidth += deltaWidth;
  41301. totalWidth += currentWidth;
  41302. var bitmap;
  41303. if (refinement) {
  41304. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  41305. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  41306. if (numberOfInstances > 1) {
  41307. bitmap = decodeTextRegion(huffman, refinement,
  41308. currentWidth, currentHeight, 0,
  41309. numberOfInstances, 1, //strip size
  41310. symbols.concat(newSymbols),
  41311. symbolCodeLength,
  41312. 0, //transposed
  41313. 0, //ds offset
  41314. 1, //top left 7.4.3.1.1
  41315. 0, //OR operator
  41316. huffmanTables,
  41317. refinementTemplateIndex, refinementAt,
  41318. decodingContext);
  41319. } else {
  41320. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41321. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41322. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41323. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  41324. newSymbols[symbolId - symbols.length]);
  41325. bitmap = decodeRefinement(currentWidth, currentHeight,
  41326. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  41327. decodingContext);
  41328. }
  41329. } else {
  41330. // 6.5.8.1 Direct-coded symbol bitmap
  41331. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  41332. templateIndex, false, null, at, decodingContext);
  41333. }
  41334. newSymbols.push(bitmap);
  41335. }
  41336. }
  41337. // 6.5.10 Exported symbols
  41338. var exportedSymbols = [];
  41339. var flags = [], currentFlag = false;
  41340. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  41341. while (flags.length < totalSymbolsLength) {
  41342. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  41343. while (runLength--) {
  41344. flags.push(currentFlag);
  41345. }
  41346. currentFlag = !currentFlag;
  41347. }
  41348. for (var i = 0, ii = symbols.length; i < ii; i++) {
  41349. if (flags[i]) {
  41350. exportedSymbols.push(symbols[i]);
  41351. }
  41352. }
  41353. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  41354. if (flags[i]) {
  41355. exportedSymbols.push(newSymbols[j]);
  41356. }
  41357. }
  41358. return exportedSymbols;
  41359. }
  41360. function decodeTextRegion(huffman, refinement, width, height,
  41361. defaultPixelValue, numberOfSymbolInstances,
  41362. stripSize, inputSymbols, symbolCodeLength,
  41363. transposed, dsOffset, referenceCorner,
  41364. combinationOperator, huffmanTables,
  41365. refinementTemplateIndex, refinementAt,
  41366. decodingContext) {
  41367. if (huffman) {
  41368. error('JBIG2 error: huffman is not supported');
  41369. }
  41370. // Prepare bitmap
  41371. var bitmap = [];
  41372. var i, row;
  41373. for (i = 0; i < height; i++) {
  41374. row = new Uint8Array(width);
  41375. if (defaultPixelValue) {
  41376. for (var j = 0; j < width; j++) {
  41377. row[j] = defaultPixelValue;
  41378. }
  41379. }
  41380. bitmap.push(row);
  41381. }
  41382. var decoder = decodingContext.decoder;
  41383. var contextCache = decodingContext.contextCache;
  41384. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41385. var firstS = 0;
  41386. i = 0;
  41387. while (i < numberOfSymbolInstances) {
  41388. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41389. stripT += deltaT;
  41390. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  41391. firstS += deltaFirstS;
  41392. var currentS = firstS;
  41393. do {
  41394. var currentT = (stripSize === 1 ? 0 :
  41395. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  41396. var t = stripSize * stripT + currentT;
  41397. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41398. var applyRefinement = (refinement &&
  41399. decodeInteger(contextCache, 'IARI', decoder));
  41400. var symbolBitmap = inputSymbols[symbolId];
  41401. var symbolWidth = symbolBitmap[0].length;
  41402. var symbolHeight = symbolBitmap.length;
  41403. if (applyRefinement) {
  41404. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  41405. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  41406. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41407. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41408. symbolWidth += rdw;
  41409. symbolHeight += rdh;
  41410. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  41411. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  41412. (rdh >> 1) + rdy, false, refinementAt,
  41413. decodingContext);
  41414. }
  41415. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  41416. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  41417. var s2, t2, symbolRow;
  41418. if (transposed) {
  41419. // Place Symbol Bitmap from T1,S1
  41420. for (s2 = 0; s2 < symbolHeight; s2++) {
  41421. row = bitmap[offsetS + s2];
  41422. if (!row) {
  41423. continue;
  41424. }
  41425. symbolRow = symbolBitmap[s2];
  41426. // To ignore Parts of Symbol bitmap which goes
  41427. // outside bitmap region
  41428. var maxWidth = Math.min(width - offsetT, symbolWidth);
  41429. switch (combinationOperator) {
  41430. case 0: // OR
  41431. for (t2 = 0; t2 < maxWidth; t2++) {
  41432. row[offsetT + t2] |= symbolRow[t2];
  41433. }
  41434. break;
  41435. case 2: // XOR
  41436. for (t2 = 0; t2 < maxWidth; t2++) {
  41437. row[offsetT + t2] ^= symbolRow[t2];
  41438. }
  41439. break;
  41440. default:
  41441. error('JBIG2 error: operator ' + combinationOperator +
  41442. ' is not supported');
  41443. }
  41444. }
  41445. currentS += symbolHeight - 1;
  41446. } else {
  41447. for (t2 = 0; t2 < symbolHeight; t2++) {
  41448. row = bitmap[offsetT + t2];
  41449. if (!row) {
  41450. continue;
  41451. }
  41452. symbolRow = symbolBitmap[t2];
  41453. switch (combinationOperator) {
  41454. case 0: // OR
  41455. for (s2 = 0; s2 < symbolWidth; s2++) {
  41456. row[offsetS + s2] |= symbolRow[s2];
  41457. }
  41458. break;
  41459. case 2: // XOR
  41460. for (s2 = 0; s2 < symbolWidth; s2++) {
  41461. row[offsetS + s2] ^= symbolRow[s2];
  41462. }
  41463. break;
  41464. default:
  41465. error('JBIG2 error: operator ' + combinationOperator +
  41466. ' is not supported');
  41467. }
  41468. }
  41469. currentS += symbolWidth - 1;
  41470. }
  41471. i++;
  41472. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  41473. if (deltaS === null) {
  41474. break; // OOB
  41475. }
  41476. currentS += deltaS + dsOffset;
  41477. } while (true);
  41478. }
  41479. return bitmap;
  41480. }
  41481. function readSegmentHeader(data, start) {
  41482. var segmentHeader = {};
  41483. segmentHeader.number = readUint32(data, start);
  41484. var flags = data[start + 4];
  41485. var segmentType = flags & 0x3F;
  41486. if (!SegmentTypes[segmentType]) {
  41487. error('JBIG2 error: invalid segment type: ' + segmentType);
  41488. }
  41489. segmentHeader.type = segmentType;
  41490. segmentHeader.typeName = SegmentTypes[segmentType];
  41491. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  41492. var pageAssociationFieldSize = !!(flags & 0x40);
  41493. var referredFlags = data[start + 5];
  41494. var referredToCount = (referredFlags >> 5) & 7;
  41495. var retainBits = [referredFlags & 31];
  41496. var position = start + 6;
  41497. if (referredFlags === 7) {
  41498. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  41499. position += 3;
  41500. var bytes = (referredToCount + 7) >> 3;
  41501. retainBits[0] = data[position++];
  41502. while (--bytes > 0) {
  41503. retainBits.push(data[position++]);
  41504. }
  41505. } else if (referredFlags === 5 || referredFlags === 6) {
  41506. error('JBIG2 error: invalid referred-to flags');
  41507. }
  41508. segmentHeader.retainBits = retainBits;
  41509. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  41510. (segmentHeader.number <= 65536 ? 2 : 4));
  41511. var referredTo = [];
  41512. var i, ii;
  41513. for (i = 0; i < referredToCount; i++) {
  41514. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  41515. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  41516. readUint32(data, position)));
  41517. referredTo.push(number);
  41518. position += referredToSegmentNumberSize;
  41519. }
  41520. segmentHeader.referredTo = referredTo;
  41521. if (!pageAssociationFieldSize) {
  41522. segmentHeader.pageAssociation = data[position++];
  41523. } else {
  41524. segmentHeader.pageAssociation = readUint32(data, position);
  41525. position += 4;
  41526. }
  41527. segmentHeader.length = readUint32(data, position);
  41528. position += 4;
  41529. if (segmentHeader.length === 0xFFFFFFFF) {
  41530. // 7.2.7 Segment data length, unknown segment length
  41531. if (segmentType === 38) { // ImmediateGenericRegion
  41532. var genericRegionInfo = readRegionSegmentInformation(data, position);
  41533. var genericRegionSegmentFlags = data[position +
  41534. RegionSegmentInformationFieldLength];
  41535. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  41536. // searching for the segment end
  41537. var searchPatternLength = 6;
  41538. var searchPattern = new Uint8Array(searchPatternLength);
  41539. if (!genericRegionMmr) {
  41540. searchPattern[0] = 0xFF;
  41541. searchPattern[1] = 0xAC;
  41542. }
  41543. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  41544. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  41545. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  41546. searchPattern[5] = genericRegionInfo.height & 0xFF;
  41547. for (i = position, ii = data.length; i < ii; i++) {
  41548. var j = 0;
  41549. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  41550. j++;
  41551. }
  41552. if (j === searchPatternLength) {
  41553. segmentHeader.length = i + searchPatternLength;
  41554. break;
  41555. }
  41556. }
  41557. if (segmentHeader.length === 0xFFFFFFFF) {
  41558. error('JBIG2 error: segment end was not found');
  41559. }
  41560. } else {
  41561. error('JBIG2 error: invalid unknown segment length');
  41562. }
  41563. }
  41564. segmentHeader.headerEnd = position;
  41565. return segmentHeader;
  41566. }
  41567. function readSegments(header, data, start, end) {
  41568. var segments = [];
  41569. var position = start;
  41570. while (position < end) {
  41571. var segmentHeader = readSegmentHeader(data, position);
  41572. position = segmentHeader.headerEnd;
  41573. var segment = {
  41574. header: segmentHeader,
  41575. data: data
  41576. };
  41577. if (!header.randomAccess) {
  41578. segment.start = position;
  41579. position += segmentHeader.length;
  41580. segment.end = position;
  41581. }
  41582. segments.push(segment);
  41583. if (segmentHeader.type === 51) {
  41584. break; // end of file is found
  41585. }
  41586. }
  41587. if (header.randomAccess) {
  41588. for (var i = 0, ii = segments.length; i < ii; i++) {
  41589. segments[i].start = position;
  41590. position += segments[i].header.length;
  41591. segments[i].end = position;
  41592. }
  41593. }
  41594. return segments;
  41595. }
  41596. // 7.4.1 Region segment information field
  41597. function readRegionSegmentInformation(data, start) {
  41598. return {
  41599. width: readUint32(data, start),
  41600. height: readUint32(data, start + 4),
  41601. x: readUint32(data, start + 8),
  41602. y: readUint32(data, start + 12),
  41603. combinationOperator: data[start + 16] & 7
  41604. };
  41605. }
  41606. var RegionSegmentInformationFieldLength = 17;
  41607. function processSegment(segment, visitor) {
  41608. var header = segment.header;
  41609. var data = segment.data, position = segment.start, end = segment.end;
  41610. var args, at, i, atLength;
  41611. switch (header.type) {
  41612. case 0: // SymbolDictionary
  41613. // 7.4.2 Symbol dictionary segment syntax
  41614. var dictionary = {};
  41615. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  41616. dictionary.huffman = !!(dictionaryFlags & 1);
  41617. dictionary.refinement = !!(dictionaryFlags & 2);
  41618. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  41619. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  41620. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  41621. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  41622. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  41623. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  41624. dictionary.template = (dictionaryFlags >> 10) & 3;
  41625. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  41626. position += 2;
  41627. if (!dictionary.huffman) {
  41628. atLength = dictionary.template === 0 ? 4 : 1;
  41629. at = [];
  41630. for (i = 0; i < atLength; i++) {
  41631. at.push({
  41632. x: readInt8(data, position),
  41633. y: readInt8(data, position + 1)
  41634. });
  41635. position += 2;
  41636. }
  41637. dictionary.at = at;
  41638. }
  41639. if (dictionary.refinement && !dictionary.refinementTemplate) {
  41640. at = [];
  41641. for (i = 0; i < 2; i++) {
  41642. at.push({
  41643. x: readInt8(data, position),
  41644. y: readInt8(data, position + 1)
  41645. });
  41646. position += 2;
  41647. }
  41648. dictionary.refinementAt = at;
  41649. }
  41650. dictionary.numberOfExportedSymbols = readUint32(data, position);
  41651. position += 4;
  41652. dictionary.numberOfNewSymbols = readUint32(data, position);
  41653. position += 4;
  41654. args = [dictionary, header.number, header.referredTo,
  41655. data, position, end];
  41656. break;
  41657. case 6: // ImmediateTextRegion
  41658. case 7: // ImmediateLosslessTextRegion
  41659. var textRegion = {};
  41660. textRegion.info = readRegionSegmentInformation(data, position);
  41661. position += RegionSegmentInformationFieldLength;
  41662. var textRegionSegmentFlags = readUint16(data, position);
  41663. position += 2;
  41664. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  41665. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  41666. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  41667. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  41668. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  41669. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  41670. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  41671. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  41672. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  41673. if (textRegion.huffman) {
  41674. var textRegionHuffmanFlags = readUint16(data, position);
  41675. position += 2;
  41676. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  41677. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  41678. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  41679. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  41680. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  41681. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  41682. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  41683. textRegion.huffmanRefinementSizeSelector =
  41684. !!(textRegionHuffmanFlags & 14);
  41685. }
  41686. if (textRegion.refinement && !textRegion.refinementTemplate) {
  41687. at = [];
  41688. for (i = 0; i < 2; i++) {
  41689. at.push({
  41690. x: readInt8(data, position),
  41691. y: readInt8(data, position + 1)
  41692. });
  41693. position += 2;
  41694. }
  41695. textRegion.refinementAt = at;
  41696. }
  41697. textRegion.numberOfSymbolInstances = readUint32(data, position);
  41698. position += 4;
  41699. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  41700. if (textRegion.huffman) {
  41701. error('JBIG2 error: huffman is not supported');
  41702. }
  41703. args = [textRegion, header.referredTo, data, position, end];
  41704. break;
  41705. case 38: // ImmediateGenericRegion
  41706. case 39: // ImmediateLosslessGenericRegion
  41707. var genericRegion = {};
  41708. genericRegion.info = readRegionSegmentInformation(data, position);
  41709. position += RegionSegmentInformationFieldLength;
  41710. var genericRegionSegmentFlags = data[position++];
  41711. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  41712. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  41713. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  41714. if (!genericRegion.mmr) {
  41715. atLength = genericRegion.template === 0 ? 4 : 1;
  41716. at = [];
  41717. for (i = 0; i < atLength; i++) {
  41718. at.push({
  41719. x: readInt8(data, position),
  41720. y: readInt8(data, position + 1)
  41721. });
  41722. position += 2;
  41723. }
  41724. genericRegion.at = at;
  41725. }
  41726. args = [genericRegion, data, position, end];
  41727. break;
  41728. case 48: // PageInformation
  41729. var pageInfo = {
  41730. width: readUint32(data, position),
  41731. height: readUint32(data, position + 4),
  41732. resolutionX: readUint32(data, position + 8),
  41733. resolutionY: readUint32(data, position + 12)
  41734. };
  41735. if (pageInfo.height === 0xFFFFFFFF) {
  41736. delete pageInfo.height;
  41737. }
  41738. var pageSegmentFlags = data[position + 16];
  41739. var pageStripingInformatiom = readUint16(data, position + 17);
  41740. pageInfo.lossless = !!(pageSegmentFlags & 1);
  41741. pageInfo.refinement = !!(pageSegmentFlags & 2);
  41742. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  41743. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  41744. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  41745. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  41746. args = [pageInfo];
  41747. break;
  41748. case 49: // EndOfPage
  41749. break;
  41750. case 50: // EndOfStripe
  41751. break;
  41752. case 51: // EndOfFile
  41753. break;
  41754. case 62: // 7.4.15 defines 2 extension types which
  41755. // are comments and can be ignored.
  41756. break;
  41757. default:
  41758. error('JBIG2 error: segment type ' + header.typeName + '(' +
  41759. header.type + ') is not implemented');
  41760. }
  41761. var callbackName = 'on' + header.typeName;
  41762. if (callbackName in visitor) {
  41763. visitor[callbackName].apply(visitor, args);
  41764. }
  41765. }
  41766. function processSegments(segments, visitor) {
  41767. for (var i = 0, ii = segments.length; i < ii; i++) {
  41768. processSegment(segments[i], visitor);
  41769. }
  41770. }
  41771. function parseJbig2(data, start, end) {
  41772. var position = start;
  41773. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  41774. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  41775. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  41776. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  41777. error('JBIG2 error: invalid header');
  41778. }
  41779. var header = {};
  41780. position += 8;
  41781. var flags = data[position++];
  41782. header.randomAccess = !(flags & 1);
  41783. if (!(flags & 2)) {
  41784. header.numberOfPages = readUint32(data, position);
  41785. position += 4;
  41786. }
  41787. var segments = readSegments(header, data, position, end);
  41788. error('Not implemented');
  41789. // processSegments(segments, new SimpleSegmentVisitor());
  41790. }
  41791. function parseJbig2Chunks(chunks) {
  41792. var visitor = new SimpleSegmentVisitor();
  41793. for (var i = 0, ii = chunks.length; i < ii; i++) {
  41794. var chunk = chunks[i];
  41795. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  41796. processSegments(segments, visitor);
  41797. }
  41798. return visitor.buffer;
  41799. }
  41800. function SimpleSegmentVisitor() {}
  41801. SimpleSegmentVisitor.prototype = {
  41802. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  41803. this.currentPageInfo = info;
  41804. var rowSize = (info.width + 7) >> 3;
  41805. var buffer = new Uint8Array(rowSize * info.height);
  41806. // The contents of ArrayBuffers are initialized to 0.
  41807. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  41808. if (info.defaultPixelValue) {
  41809. for (var i = 0, ii = buffer.length; i < ii; i++) {
  41810. buffer[i] = 0xFF;
  41811. }
  41812. }
  41813. this.buffer = buffer;
  41814. },
  41815. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  41816. var pageInfo = this.currentPageInfo;
  41817. var width = regionInfo.width, height = regionInfo.height;
  41818. var rowSize = (pageInfo.width + 7) >> 3;
  41819. var combinationOperator = pageInfo.combinationOperatorOverride ?
  41820. regionInfo.combinationOperator : pageInfo.combinationOperator;
  41821. var buffer = this.buffer;
  41822. var mask0 = 128 >> (regionInfo.x & 7);
  41823. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  41824. var i, j, mask, offset;
  41825. switch (combinationOperator) {
  41826. case 0: // OR
  41827. for (i = 0; i < height; i++) {
  41828. mask = mask0;
  41829. offset = offset0;
  41830. for (j = 0; j < width; j++) {
  41831. if (bitmap[i][j]) {
  41832. buffer[offset] |= mask;
  41833. }
  41834. mask >>= 1;
  41835. if (!mask) {
  41836. mask = 128;
  41837. offset++;
  41838. }
  41839. }
  41840. offset0 += rowSize;
  41841. }
  41842. break;
  41843. case 2: // XOR
  41844. for (i = 0; i < height; i++) {
  41845. mask = mask0;
  41846. offset = offset0;
  41847. for (j = 0; j < width; j++) {
  41848. if (bitmap[i][j]) {
  41849. buffer[offset] ^= mask;
  41850. }
  41851. mask >>= 1;
  41852. if (!mask) {
  41853. mask = 128;
  41854. offset++;
  41855. }
  41856. }
  41857. offset0 += rowSize;
  41858. }
  41859. break;
  41860. default:
  41861. error('JBIG2 error: operator ' + combinationOperator +
  41862. ' is not supported');
  41863. }
  41864. },
  41865. onImmediateGenericRegion:
  41866. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  41867. start, end) {
  41868. var regionInfo = region.info;
  41869. var decodingContext = new DecodingContext(data, start, end);
  41870. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  41871. region.template, region.prediction, null,
  41872. region.at, decodingContext);
  41873. this.drawBitmap(regionInfo, bitmap);
  41874. },
  41875. onImmediateLosslessGenericRegion:
  41876. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  41877. this.onImmediateGenericRegion.apply(this, arguments);
  41878. },
  41879. onSymbolDictionary:
  41880. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  41881. currentSegment,
  41882. referredSegments,
  41883. data, start, end) {
  41884. var huffmanTables;
  41885. if (dictionary.huffman) {
  41886. error('JBIG2 error: huffman is not supported');
  41887. }
  41888. // Combines exported symbols from all referred segments
  41889. var symbols = this.symbols;
  41890. if (!symbols) {
  41891. this.symbols = symbols = {};
  41892. }
  41893. var inputSymbols = [];
  41894. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41895. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41896. }
  41897. var decodingContext = new DecodingContext(data, start, end);
  41898. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  41899. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  41900. dictionary.numberOfExportedSymbols, huffmanTables,
  41901. dictionary.template, dictionary.at,
  41902. dictionary.refinementTemplate, dictionary.refinementAt,
  41903. decodingContext);
  41904. },
  41905. onImmediateTextRegion:
  41906. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  41907. referredSegments,
  41908. data, start, end) {
  41909. var regionInfo = region.info;
  41910. var huffmanTables;
  41911. // Combines exported symbols from all referred segments
  41912. var symbols = this.symbols;
  41913. var inputSymbols = [];
  41914. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41915. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41916. }
  41917. var symbolCodeLength = log2(inputSymbols.length);
  41918. var decodingContext = new DecodingContext(data, start, end);
  41919. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  41920. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  41921. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  41922. symbolCodeLength, region.transposed, region.dsOffset,
  41923. region.referenceCorner, region.combinationOperator, huffmanTables,
  41924. region.refinementTemplate, region.refinementAt, decodingContext);
  41925. this.drawBitmap(regionInfo, bitmap);
  41926. },
  41927. onImmediateLosslessTextRegion:
  41928. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  41929. this.onImmediateTextRegion.apply(this, arguments);
  41930. }
  41931. };
  41932. function Jbig2Image() {}
  41933. Jbig2Image.prototype = {
  41934. parseChunks: function Jbig2Image_parseChunks(chunks) {
  41935. return parseJbig2Chunks(chunks);
  41936. }
  41937. };
  41938. return Jbig2Image;
  41939. })();
  41940. var bidi = PDFJS.bidi = (function bidiClosure() {
  41941. // Character types for symbols from 0000 to 00FF.
  41942. var baseTypes = [
  41943. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  41944. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41945. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  41946. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  41947. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  41948. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41949. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  41950. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41951. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41952. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  41953. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41954. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41955. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  41956. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  41957. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41958. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41959. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41960. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41961. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  41962. ];
  41963. // Character types for symbols from 0600 to 06FF
  41964. var arabicTypes = [
  41965. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41966. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  41967. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41968. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41969. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41970. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41971. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41972. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41973. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  41974. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41975. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41976. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41977. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41978. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41979. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41980. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41981. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41982. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41983. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41984. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  41985. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41986. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  41987. ];
  41988. function isOdd(i) {
  41989. return (i & 1) !== 0;
  41990. }
  41991. function isEven(i) {
  41992. return (i & 1) === 0;
  41993. }
  41994. function findUnequal(arr, start, value) {
  41995. for (var j = start, jj = arr.length; j < jj; ++j) {
  41996. if (arr[j] !== value) {
  41997. return j;
  41998. }
  41999. }
  42000. return j;
  42001. }
  42002. function setValues(arr, start, end, value) {
  42003. for (var j = start; j < end; ++j) {
  42004. arr[j] = value;
  42005. }
  42006. }
  42007. function reverseValues(arr, start, end) {
  42008. for (var i = start, j = end - 1; i < j; ++i, --j) {
  42009. var temp = arr[i];
  42010. arr[i] = arr[j];
  42011. arr[j] = temp;
  42012. }
  42013. }
  42014. function createBidiText(str, isLTR, vertical) {
  42015. return {
  42016. str: str,
  42017. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  42018. };
  42019. }
  42020. // These are used in bidi(), which is called frequently. We re-use them on
  42021. // each call to avoid unnecessary allocations.
  42022. var chars = [];
  42023. var types = [];
  42024. function bidi(str, startLevel, vertical) {
  42025. var isLTR = true;
  42026. var strLength = str.length;
  42027. if (strLength === 0 || vertical) {
  42028. return createBidiText(str, isLTR, vertical);
  42029. }
  42030. // Get types and fill arrays
  42031. chars.length = strLength;
  42032. types.length = strLength;
  42033. var numBidi = 0;
  42034. var i, ii;
  42035. for (i = 0; i < strLength; ++i) {
  42036. chars[i] = str.charAt(i);
  42037. var charCode = str.charCodeAt(i);
  42038. var charType = 'L';
  42039. if (charCode <= 0x00ff) {
  42040. charType = baseTypes[charCode];
  42041. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  42042. charType = 'R';
  42043. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  42044. charType = arabicTypes[charCode & 0xff];
  42045. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  42046. charType = 'AL';
  42047. }
  42048. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  42049. numBidi++;
  42050. }
  42051. types[i] = charType;
  42052. }
  42053. // Detect the bidi method
  42054. // - If there are no rtl characters then no bidi needed
  42055. // - If less than 30% chars are rtl then string is primarily ltr
  42056. // - If more than 30% chars are rtl then string is primarily rtl
  42057. if (numBidi === 0) {
  42058. isLTR = true;
  42059. return createBidiText(str, isLTR);
  42060. }
  42061. if (startLevel === -1) {
  42062. if ((strLength / numBidi) < 0.3) {
  42063. isLTR = true;
  42064. startLevel = 0;
  42065. } else {
  42066. isLTR = false;
  42067. startLevel = 1;
  42068. }
  42069. }
  42070. var levels = [];
  42071. for (i = 0; i < strLength; ++i) {
  42072. levels[i] = startLevel;
  42073. }
  42074. /*
  42075. X1-X10: skip most of this, since we are NOT doing the embeddings.
  42076. */
  42077. var e = (isOdd(startLevel) ? 'R' : 'L');
  42078. var sor = e;
  42079. var eor = sor;
  42080. /*
  42081. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  42082. type of the NSM to the type of the previous character. If the NSM is at the
  42083. start of the level run, it will get the type of sor.
  42084. */
  42085. var lastType = sor;
  42086. for (i = 0; i < strLength; ++i) {
  42087. if (types[i] === 'NSM') {
  42088. types[i] = lastType;
  42089. } else {
  42090. lastType = types[i];
  42091. }
  42092. }
  42093. /*
  42094. W2. Search backwards from each instance of a European number until the
  42095. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  42096. the type of the European number to Arabic number.
  42097. */
  42098. lastType = sor;
  42099. var t;
  42100. for (i = 0; i < strLength; ++i) {
  42101. t = types[i];
  42102. if (t === 'EN') {
  42103. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  42104. } else if (t === 'R' || t === 'L' || t === 'AL') {
  42105. lastType = t;
  42106. }
  42107. }
  42108. /*
  42109. W3. Change all ALs to R.
  42110. */
  42111. for (i = 0; i < strLength; ++i) {
  42112. t = types[i];
  42113. if (t === 'AL') {
  42114. types[i] = 'R';
  42115. }
  42116. }
  42117. /*
  42118. W4. A single European separator between two European numbers changes to a
  42119. European number. A single common separator between two numbers of the same
  42120. type changes to that type:
  42121. */
  42122. for (i = 1; i < strLength - 1; ++i) {
  42123. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  42124. types[i] = 'EN';
  42125. }
  42126. if (types[i] === 'CS' &&
  42127. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  42128. types[i + 1] === types[i - 1]) {
  42129. types[i] = types[i - 1];
  42130. }
  42131. }
  42132. /*
  42133. W5. A sequence of European terminators adjacent to European numbers changes
  42134. to all European numbers:
  42135. */
  42136. for (i = 0; i < strLength; ++i) {
  42137. if (types[i] === 'EN') {
  42138. // do before
  42139. var j;
  42140. for (j = i - 1; j >= 0; --j) {
  42141. if (types[j] !== 'ET') {
  42142. break;
  42143. }
  42144. types[j] = 'EN';
  42145. }
  42146. // do after
  42147. for (j = i + 1; j < strLength; --j) {
  42148. if (types[j] !== 'ET') {
  42149. break;
  42150. }
  42151. types[j] = 'EN';
  42152. }
  42153. }
  42154. }
  42155. /*
  42156. W6. Otherwise, separators and terminators change to Other Neutral:
  42157. */
  42158. for (i = 0; i < strLength; ++i) {
  42159. t = types[i];
  42160. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  42161. types[i] = 'ON';
  42162. }
  42163. }
  42164. /*
  42165. W7. Search backwards from each instance of a European number until the
  42166. first strong type (R, L, or sor) is found. If an L is found, then change
  42167. the type of the European number to L.
  42168. */
  42169. lastType = sor;
  42170. for (i = 0; i < strLength; ++i) {
  42171. t = types[i];
  42172. if (t === 'EN') {
  42173. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  42174. } else if (t === 'R' || t === 'L') {
  42175. lastType = t;
  42176. }
  42177. }
  42178. /*
  42179. N1. A sequence of neutrals takes the direction of the surrounding strong
  42180. text if the text on both sides has the same direction. European and Arabic
  42181. numbers are treated as though they were R. Start-of-level-run (sor) and
  42182. end-of-level-run (eor) are used at level run boundaries.
  42183. */
  42184. for (i = 0; i < strLength; ++i) {
  42185. if (types[i] === 'ON') {
  42186. var end = findUnequal(types, i + 1, 'ON');
  42187. var before = sor;
  42188. if (i > 0) {
  42189. before = types[i - 1];
  42190. }
  42191. var after = eor;
  42192. if (end + 1 < strLength) {
  42193. after = types[end + 1];
  42194. }
  42195. if (before !== 'L') {
  42196. before = 'R';
  42197. }
  42198. if (after !== 'L') {
  42199. after = 'R';
  42200. }
  42201. if (before === after) {
  42202. setValues(types, i, end, before);
  42203. }
  42204. i = end - 1; // reset to end (-1 so next iteration is ok)
  42205. }
  42206. }
  42207. /*
  42208. N2. Any remaining neutrals take the embedding direction.
  42209. */
  42210. for (i = 0; i < strLength; ++i) {
  42211. if (types[i] === 'ON') {
  42212. types[i] = e;
  42213. }
  42214. }
  42215. /*
  42216. I1. For all characters with an even (left-to-right) embedding direction,
  42217. those of type R go up one level and those of type AN or EN go up two
  42218. levels.
  42219. I2. For all characters with an odd (right-to-left) embedding direction,
  42220. those of type L, EN or AN go up one level.
  42221. */
  42222. for (i = 0; i < strLength; ++i) {
  42223. t = types[i];
  42224. if (isEven(levels[i])) {
  42225. if (t === 'R') {
  42226. levels[i] += 1;
  42227. } else if (t === 'AN' || t === 'EN') {
  42228. levels[i] += 2;
  42229. }
  42230. } else { // isOdd
  42231. if (t === 'L' || t === 'AN' || t === 'EN') {
  42232. levels[i] += 1;
  42233. }
  42234. }
  42235. }
  42236. /*
  42237. L1. On each line, reset the embedding level of the following characters to
  42238. the paragraph embedding level:
  42239. segment separators,
  42240. paragraph separators,
  42241. any sequence of whitespace characters preceding a segment separator or
  42242. paragraph separator, and any sequence of white space characters at the end
  42243. of the line.
  42244. */
  42245. // don't bother as text is only single line
  42246. /*
  42247. L2. From the highest level found in the text to the lowest odd level on
  42248. each line, reverse any contiguous sequence of characters that are at that
  42249. level or higher.
  42250. */
  42251. // find highest level & lowest odd level
  42252. var highestLevel = -1;
  42253. var lowestOddLevel = 99;
  42254. var level;
  42255. for (i = 0, ii = levels.length; i < ii; ++i) {
  42256. level = levels[i];
  42257. if (highestLevel < level) {
  42258. highestLevel = level;
  42259. }
  42260. if (lowestOddLevel > level && isOdd(level)) {
  42261. lowestOddLevel = level;
  42262. }
  42263. }
  42264. // now reverse between those limits
  42265. for (level = highestLevel; level >= lowestOddLevel; --level) {
  42266. // find segments to reverse
  42267. var start = -1;
  42268. for (i = 0, ii = levels.length; i < ii; ++i) {
  42269. if (levels[i] < level) {
  42270. if (start >= 0) {
  42271. reverseValues(chars, start, i);
  42272. start = -1;
  42273. }
  42274. } else if (start < 0) {
  42275. start = i;
  42276. }
  42277. }
  42278. if (start >= 0) {
  42279. reverseValues(chars, start, levels.length);
  42280. }
  42281. }
  42282. /*
  42283. L3. Combining marks applied to a right-to-left base character will at this
  42284. point precede their base character. If the rendering engine expects them to
  42285. follow the base characters in the final display process, then the ordering
  42286. of the marks and the base character must be reversed.
  42287. */
  42288. // don't bother for now
  42289. /*
  42290. L4. A character that possesses the mirrored property as specified by
  42291. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  42292. directionality of that character is R.
  42293. */
  42294. // don't mirror as characters are already mirrored in the pdf
  42295. // Finally, return string
  42296. var result = '';
  42297. for (i = 0, ii = chars.length; i < ii; ++i) {
  42298. var ch = chars[i];
  42299. if (ch !== '<' && ch !== '>') {
  42300. result += ch;
  42301. }
  42302. }
  42303. return createBidiText(result, isLTR);
  42304. }
  42305. return bidi;
  42306. })();
  42307. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  42308. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  42309. /* Copyright 2014 Opera Software ASA
  42310. *
  42311. * Licensed under the Apache License, Version 2.0 (the "License");
  42312. * you may not use this file except in compliance with the License.
  42313. * You may obtain a copy of the License at
  42314. *
  42315. * http://www.apache.org/licenses/LICENSE-2.0
  42316. *
  42317. * Unless required by applicable law or agreed to in writing, software
  42318. * distributed under the License is distributed on an "AS IS" BASIS,
  42319. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  42320. * See the License for the specific language governing permissions and
  42321. * limitations under the License.
  42322. *
  42323. *
  42324. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  42325. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  42326. */
  42327. /* globals Uint32ArrayView */
  42328. 'use strict';
  42329. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  42330. // Workaround for missing math precison in JS.
  42331. var MASK_HIGH = 0xffff0000;
  42332. var MASK_LOW = 0xffff;
  42333. function MurmurHash3_64 (seed) {
  42334. var SEED = 0xc3d2e1f0;
  42335. this.h1 = seed ? seed & 0xffffffff : SEED;
  42336. this.h2 = seed ? seed & 0xffffffff : SEED;
  42337. }
  42338. var alwaysUseUint32ArrayView = false;
  42339. // old webkits have issues with non-aligned arrays
  42340. try {
  42341. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  42342. } catch (e) {
  42343. alwaysUseUint32ArrayView = true;
  42344. }
  42345. MurmurHash3_64.prototype = {
  42346. update: function MurmurHash3_64_update(input) {
  42347. var useUint32ArrayView = alwaysUseUint32ArrayView;
  42348. var i;
  42349. if (typeof input === 'string') {
  42350. var data = new Uint8Array(input.length * 2);
  42351. var length = 0;
  42352. for (i = 0; i < input.length; i++) {
  42353. var code = input.charCodeAt(i);
  42354. if (code <= 0xff) {
  42355. data[length++] = code;
  42356. }
  42357. else {
  42358. data[length++] = code >>> 8;
  42359. data[length++] = code & 0xff;
  42360. }
  42361. }
  42362. } else if (input instanceof Uint8Array) {
  42363. data = input;
  42364. length = data.length;
  42365. } else if (typeof input === 'object' && ('length' in input)) {
  42366. // processing regular arrays as well, e.g. for IE9
  42367. data = input;
  42368. length = data.length;
  42369. useUint32ArrayView = true;
  42370. } else {
  42371. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  42372. 'Input must be a string or array.');
  42373. }
  42374. var blockCounts = length >> 2;
  42375. var tailLength = length - blockCounts * 4;
  42376. // we don't care about endianness here
  42377. var dataUint32 = useUint32ArrayView ?
  42378. new Uint32ArrayView(data, blockCounts) :
  42379. new Uint32Array(data.buffer, 0, blockCounts);
  42380. var k1 = 0;
  42381. var k2 = 0;
  42382. var h1 = this.h1;
  42383. var h2 = this.h2;
  42384. var C1 = 0xcc9e2d51;
  42385. var C2 = 0x1b873593;
  42386. var C1_LOW = C1 & MASK_LOW;
  42387. var C2_LOW = C2 & MASK_LOW;
  42388. for (i = 0; i < blockCounts; i++) {
  42389. if (i & 1) {
  42390. k1 = dataUint32[i];
  42391. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42392. k1 = k1 << 15 | k1 >>> 17;
  42393. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42394. h1 ^= k1;
  42395. h1 = h1 << 13 | h1 >>> 19;
  42396. h1 = h1 * 5 + 0xe6546b64;
  42397. } else {
  42398. k2 = dataUint32[i];
  42399. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  42400. k2 = k2 << 15 | k2 >>> 17;
  42401. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  42402. h2 ^= k2;
  42403. h2 = h2 << 13 | h2 >>> 19;
  42404. h2 = h2 * 5 + 0xe6546b64;
  42405. }
  42406. }
  42407. k1 = 0;
  42408. switch (tailLength) {
  42409. case 3:
  42410. k1 ^= data[blockCounts * 4 + 2] << 16;
  42411. /* falls through */
  42412. case 2:
  42413. k1 ^= data[blockCounts * 4 + 1] << 8;
  42414. /* falls through */
  42415. case 1:
  42416. k1 ^= data[blockCounts * 4];
  42417. /* falls through */
  42418. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42419. k1 = k1 << 15 | k1 >>> 17;
  42420. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42421. if (blockCounts & 1) {
  42422. h1 ^= k1;
  42423. } else {
  42424. h2 ^= k1;
  42425. }
  42426. }
  42427. this.h1 = h1;
  42428. this.h2 = h2;
  42429. return this;
  42430. },
  42431. hexdigest: function MurmurHash3_64_hexdigest () {
  42432. var h1 = this.h1;
  42433. var h2 = this.h2;
  42434. h1 ^= h2 >>> 1;
  42435. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  42436. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  42437. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  42438. h1 ^= h2 >>> 1;
  42439. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  42440. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  42441. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  42442. h1 ^= h2 >>> 1;
  42443. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  42444. var hex = (arr[i] >>> 0).toString(16);
  42445. while (hex.length < 8) {
  42446. hex = '0' + hex;
  42447. }
  42448. str += hex;
  42449. }
  42450. return str;
  42451. }
  42452. };
  42453. return MurmurHash3_64;
  42454. })();
  42455. }).call((typeof window === 'undefined') ? this : window);
  42456. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  42457. // workerSrc is not set -- using last script url to define default location
  42458. PDFJS.workerSrc = (function () {
  42459. 'use strict';
  42460. var scriptTagContainer = document.body ||
  42461. document.getElementsByTagName('head')[0];
  42462. var pdfjsSrc = scriptTagContainer.lastChild.src;
  42463. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  42464. })();
  42465. }