pdf.combined.js 1.5 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* jshint globalstrict: false */
  16. /* globals PDFJS, global */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window :
  20. typeof global !== 'undefined' ? global : this).PDFJS = {};
  21. }
  22. PDFJS.version = '1.3.131';
  23. PDFJS.build = 'edf8ccc';
  24. (function pdfjsWrapper() {
  25. // Use strict in our context only - users might not want it
  26. 'use strict';
  27. (function (root, factory) {
  28. {
  29. factory((root.pdfjsSharedGlobal = {}));
  30. }
  31. }(this, function (exports) {
  32. var globalScope = (typeof window !== 'undefined') ? window :
  33. (typeof global !== 'undefined') ? global :
  34. (typeof self !== 'undefined') ? self : this;
  35. var isWorker = (typeof window === 'undefined');
  36. // The global PDFJS object exposes the API
  37. // In production, it will be declared outside a global wrapper
  38. // In development, it will be declared here
  39. if (!globalScope.PDFJS) {
  40. globalScope.PDFJS = {};
  41. }
  42. globalScope.PDFJS.pdfBug = false;
  43. exports.globalScope = globalScope;
  44. exports.isWorker = isWorker;
  45. exports.PDFJS = globalScope.PDFJS;
  46. }));
  47. (function (root, factory) {
  48. {
  49. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  50. }
  51. }(this, function (exports, sharedGlobal) {
  52. var PDFJS = sharedGlobal.PDFJS;
  53. var globalScope = sharedGlobal.globalScope;
  54. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  55. var TextRenderingMode = {
  56. FILL: 0,
  57. STROKE: 1,
  58. FILL_STROKE: 2,
  59. INVISIBLE: 3,
  60. FILL_ADD_TO_PATH: 4,
  61. STROKE_ADD_TO_PATH: 5,
  62. FILL_STROKE_ADD_TO_PATH: 6,
  63. ADD_TO_PATH: 7,
  64. FILL_STROKE_MASK: 3,
  65. ADD_TO_PATH_FLAG: 4
  66. };
  67. var ImageKind = {
  68. GRAYSCALE_1BPP: 1,
  69. RGB_24BPP: 2,
  70. RGBA_32BPP: 3
  71. };
  72. var AnnotationType = {
  73. TEXT: 1,
  74. LINK: 2,
  75. FREETEXT: 3,
  76. LINE: 4,
  77. SQUARE: 5,
  78. CIRCLE: 6,
  79. POLYGON: 7,
  80. POLYLINE: 8,
  81. HIGHLIGHT: 9,
  82. UNDERLINE: 10,
  83. SQUIGGLY: 11,
  84. STRIKEOUT: 12,
  85. STAMP: 13,
  86. CARET: 14,
  87. INK: 15,
  88. POPUP: 16,
  89. FILEATTACHMENT: 17,
  90. SOUND: 18,
  91. MOVIE: 19,
  92. WIDGET: 20,
  93. SCREEN: 21,
  94. PRINTERMARK: 22,
  95. TRAPNET: 23,
  96. WATERMARK: 24,
  97. THREED: 25,
  98. REDACT: 26
  99. };
  100. var AnnotationFlag = {
  101. INVISIBLE: 0x01,
  102. HIDDEN: 0x02,
  103. PRINT: 0x04,
  104. NOZOOM: 0x08,
  105. NOROTATE: 0x10,
  106. NOVIEW: 0x20,
  107. READONLY: 0x40,
  108. LOCKED: 0x80,
  109. TOGGLENOVIEW: 0x100,
  110. LOCKEDCONTENTS: 0x200
  111. };
  112. var AnnotationBorderStyleType = {
  113. SOLID: 1,
  114. DASHED: 2,
  115. BEVELED: 3,
  116. INSET: 4,
  117. UNDERLINE: 5
  118. };
  119. var StreamType = {
  120. UNKNOWN: 0,
  121. FLATE: 1,
  122. LZW: 2,
  123. DCT: 3,
  124. JPX: 4,
  125. JBIG: 5,
  126. A85: 6,
  127. AHX: 7,
  128. CCF: 8,
  129. RL: 9
  130. };
  131. var FontType = {
  132. UNKNOWN: 0,
  133. TYPE1: 1,
  134. TYPE1C: 2,
  135. CIDFONTTYPE0: 3,
  136. CIDFONTTYPE0C: 4,
  137. TRUETYPE: 5,
  138. CIDFONTTYPE2: 6,
  139. TYPE3: 7,
  140. OPENTYPE: 8,
  141. TYPE0: 9,
  142. MMTYPE1: 10
  143. };
  144. PDFJS.VERBOSITY_LEVELS = {
  145. errors: 0,
  146. warnings: 1,
  147. infos: 5
  148. };
  149. // All the possible operations for an operator list.
  150. var OPS = PDFJS.OPS = {
  151. // Intentionally start from 1 so it is easy to spot bad operators that will be
  152. // 0's.
  153. dependency: 1,
  154. setLineWidth: 2,
  155. setLineCap: 3,
  156. setLineJoin: 4,
  157. setMiterLimit: 5,
  158. setDash: 6,
  159. setRenderingIntent: 7,
  160. setFlatness: 8,
  161. setGState: 9,
  162. save: 10,
  163. restore: 11,
  164. transform: 12,
  165. moveTo: 13,
  166. lineTo: 14,
  167. curveTo: 15,
  168. curveTo2: 16,
  169. curveTo3: 17,
  170. closePath: 18,
  171. rectangle: 19,
  172. stroke: 20,
  173. closeStroke: 21,
  174. fill: 22,
  175. eoFill: 23,
  176. fillStroke: 24,
  177. eoFillStroke: 25,
  178. closeFillStroke: 26,
  179. closeEOFillStroke: 27,
  180. endPath: 28,
  181. clip: 29,
  182. eoClip: 30,
  183. beginText: 31,
  184. endText: 32,
  185. setCharSpacing: 33,
  186. setWordSpacing: 34,
  187. setHScale: 35,
  188. setLeading: 36,
  189. setFont: 37,
  190. setTextRenderingMode: 38,
  191. setTextRise: 39,
  192. moveText: 40,
  193. setLeadingMoveText: 41,
  194. setTextMatrix: 42,
  195. nextLine: 43,
  196. showText: 44,
  197. showSpacedText: 45,
  198. nextLineShowText: 46,
  199. nextLineSetSpacingShowText: 47,
  200. setCharWidth: 48,
  201. setCharWidthAndBounds: 49,
  202. setStrokeColorSpace: 50,
  203. setFillColorSpace: 51,
  204. setStrokeColor: 52,
  205. setStrokeColorN: 53,
  206. setFillColor: 54,
  207. setFillColorN: 55,
  208. setStrokeGray: 56,
  209. setFillGray: 57,
  210. setStrokeRGBColor: 58,
  211. setFillRGBColor: 59,
  212. setStrokeCMYKColor: 60,
  213. setFillCMYKColor: 61,
  214. shadingFill: 62,
  215. beginInlineImage: 63,
  216. beginImageData: 64,
  217. endInlineImage: 65,
  218. paintXObject: 66,
  219. markPoint: 67,
  220. markPointProps: 68,
  221. beginMarkedContent: 69,
  222. beginMarkedContentProps: 70,
  223. endMarkedContent: 71,
  224. beginCompat: 72,
  225. endCompat: 73,
  226. paintFormXObjectBegin: 74,
  227. paintFormXObjectEnd: 75,
  228. beginGroup: 76,
  229. endGroup: 77,
  230. beginAnnotations: 78,
  231. endAnnotations: 79,
  232. beginAnnotation: 80,
  233. endAnnotation: 81,
  234. paintJpegXObject: 82,
  235. paintImageMaskXObject: 83,
  236. paintImageMaskXObjectGroup: 84,
  237. paintImageXObject: 85,
  238. paintInlineImageXObject: 86,
  239. paintInlineImageXObjectGroup: 87,
  240. paintImageXObjectRepeat: 88,
  241. paintImageMaskXObjectRepeat: 89,
  242. paintSolidColorImageMask: 90,
  243. constructPath: 91
  244. };
  245. // A notice for devs. These are good for things that are helpful to devs, such
  246. // as warning that Workers were disabled, which is important to devs but not
  247. // end users.
  248. function info(msg) {
  249. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  250. console.log('Info: ' + msg);
  251. }
  252. }
  253. // Non-fatal warnings.
  254. function warn(msg) {
  255. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  256. console.log('Warning: ' + msg);
  257. }
  258. }
  259. // Deprecated API function -- treated as warnings.
  260. function deprecated(details) {
  261. warn('Deprecated API usage: ' + details);
  262. }
  263. // Fatal errors that should trigger the fallback UI and halt execution by
  264. // throwing an exception.
  265. function error(msg) {
  266. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  267. console.log('Error: ' + msg);
  268. console.log(backtrace());
  269. }
  270. throw new Error(msg);
  271. }
  272. function backtrace() {
  273. try {
  274. throw new Error();
  275. } catch (e) {
  276. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  277. }
  278. }
  279. function assert(cond, msg) {
  280. if (!cond) {
  281. error(msg);
  282. }
  283. }
  284. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  285. unknown: 'unknown',
  286. forms: 'forms',
  287. javaScript: 'javaScript',
  288. smask: 'smask',
  289. shadingPattern: 'shadingPattern',
  290. font: 'font'
  291. };
  292. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  293. // absolute URL, it will be returned as is.
  294. function combineUrl(baseUrl, url) {
  295. if (!url) {
  296. return baseUrl;
  297. }
  298. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  299. return url;
  300. }
  301. var i;
  302. if (url.charAt(0) === '/') {
  303. // absolute path
  304. i = baseUrl.indexOf('://');
  305. if (url.charAt(1) === '/') {
  306. ++i;
  307. } else {
  308. i = baseUrl.indexOf('/', i + 3);
  309. }
  310. return baseUrl.substring(0, i) + url;
  311. } else {
  312. // relative path
  313. var pathLength = baseUrl.length;
  314. i = baseUrl.lastIndexOf('#');
  315. pathLength = i >= 0 ? i : pathLength;
  316. i = baseUrl.lastIndexOf('?', pathLength);
  317. pathLength = i >= 0 ? i : pathLength;
  318. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  319. return baseUrl.substring(0, prefixLength + 1) + url;
  320. }
  321. }
  322. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  323. function isValidUrl(url, allowRelative) {
  324. if (!url) {
  325. return false;
  326. }
  327. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  328. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  329. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  330. if (!protocol) {
  331. return allowRelative;
  332. }
  333. protocol = protocol[0].toLowerCase();
  334. switch (protocol) {
  335. case 'http':
  336. case 'https':
  337. case 'ftp':
  338. case 'mailto':
  339. case 'tel':
  340. return true;
  341. default:
  342. return false;
  343. }
  344. }
  345. PDFJS.isValidUrl = isValidUrl;
  346. function shadow(obj, prop, value) {
  347. Object.defineProperty(obj, prop, { value: value,
  348. enumerable: true,
  349. configurable: true,
  350. writable: false });
  351. return value;
  352. }
  353. PDFJS.shadow = shadow;
  354. var LinkTarget = PDFJS.LinkTarget = {
  355. NONE: 0, // Default value.
  356. SELF: 1,
  357. BLANK: 2,
  358. PARENT: 3,
  359. TOP: 4,
  360. };
  361. var LinkTargetStringMap = [
  362. '',
  363. '_self',
  364. '_blank',
  365. '_parent',
  366. '_top'
  367. ];
  368. function isExternalLinkTargetSet() {
  369. if (PDFJS.openExternalLinksInNewWindow) {
  370. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  371. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  372. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  373. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  374. }
  375. // Reset the deprecated parameter, to suppress further warnings.
  376. PDFJS.openExternalLinksInNewWindow = false;
  377. }
  378. switch (PDFJS.externalLinkTarget) {
  379. case LinkTarget.NONE:
  380. return false;
  381. case LinkTarget.SELF:
  382. case LinkTarget.BLANK:
  383. case LinkTarget.PARENT:
  384. case LinkTarget.TOP:
  385. return true;
  386. }
  387. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  388. // Reset the external link target, to suppress further warnings.
  389. PDFJS.externalLinkTarget = LinkTarget.NONE;
  390. return false;
  391. }
  392. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  393. var PasswordResponses = PDFJS.PasswordResponses = {
  394. NEED_PASSWORD: 1,
  395. INCORRECT_PASSWORD: 2
  396. };
  397. var PasswordException = (function PasswordExceptionClosure() {
  398. function PasswordException(msg, code) {
  399. this.name = 'PasswordException';
  400. this.message = msg;
  401. this.code = code;
  402. }
  403. PasswordException.prototype = new Error();
  404. PasswordException.constructor = PasswordException;
  405. return PasswordException;
  406. })();
  407. PDFJS.PasswordException = PasswordException;
  408. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  409. function UnknownErrorException(msg, details) {
  410. this.name = 'UnknownErrorException';
  411. this.message = msg;
  412. this.details = details;
  413. }
  414. UnknownErrorException.prototype = new Error();
  415. UnknownErrorException.constructor = UnknownErrorException;
  416. return UnknownErrorException;
  417. })();
  418. PDFJS.UnknownErrorException = UnknownErrorException;
  419. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  420. function InvalidPDFException(msg) {
  421. this.name = 'InvalidPDFException';
  422. this.message = msg;
  423. }
  424. InvalidPDFException.prototype = new Error();
  425. InvalidPDFException.constructor = InvalidPDFException;
  426. return InvalidPDFException;
  427. })();
  428. PDFJS.InvalidPDFException = InvalidPDFException;
  429. var MissingPDFException = (function MissingPDFExceptionClosure() {
  430. function MissingPDFException(msg) {
  431. this.name = 'MissingPDFException';
  432. this.message = msg;
  433. }
  434. MissingPDFException.prototype = new Error();
  435. MissingPDFException.constructor = MissingPDFException;
  436. return MissingPDFException;
  437. })();
  438. PDFJS.MissingPDFException = MissingPDFException;
  439. var UnexpectedResponseException =
  440. (function UnexpectedResponseExceptionClosure() {
  441. function UnexpectedResponseException(msg, status) {
  442. this.name = 'UnexpectedResponseException';
  443. this.message = msg;
  444. this.status = status;
  445. }
  446. UnexpectedResponseException.prototype = new Error();
  447. UnexpectedResponseException.constructor = UnexpectedResponseException;
  448. return UnexpectedResponseException;
  449. })();
  450. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  451. var NotImplementedException = (function NotImplementedExceptionClosure() {
  452. function NotImplementedException(msg) {
  453. this.message = msg;
  454. }
  455. NotImplementedException.prototype = new Error();
  456. NotImplementedException.prototype.name = 'NotImplementedException';
  457. NotImplementedException.constructor = NotImplementedException;
  458. return NotImplementedException;
  459. })();
  460. var MissingDataException = (function MissingDataExceptionClosure() {
  461. function MissingDataException(begin, end) {
  462. this.begin = begin;
  463. this.end = end;
  464. this.message = 'Missing data [' + begin + ', ' + end + ')';
  465. }
  466. MissingDataException.prototype = new Error();
  467. MissingDataException.prototype.name = 'MissingDataException';
  468. MissingDataException.constructor = MissingDataException;
  469. return MissingDataException;
  470. })();
  471. var XRefParseException = (function XRefParseExceptionClosure() {
  472. function XRefParseException(msg) {
  473. this.message = msg;
  474. }
  475. XRefParseException.prototype = new Error();
  476. XRefParseException.prototype.name = 'XRefParseException';
  477. XRefParseException.constructor = XRefParseException;
  478. return XRefParseException;
  479. })();
  480. function bytesToString(bytes) {
  481. assert(bytes !== null && typeof bytes === 'object' &&
  482. bytes.length !== undefined, 'Invalid argument for bytesToString');
  483. var length = bytes.length;
  484. var MAX_ARGUMENT_COUNT = 8192;
  485. if (length < MAX_ARGUMENT_COUNT) {
  486. return String.fromCharCode.apply(null, bytes);
  487. }
  488. var strBuf = [];
  489. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  490. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  491. var chunk = bytes.subarray(i, chunkEnd);
  492. strBuf.push(String.fromCharCode.apply(null, chunk));
  493. }
  494. return strBuf.join('');
  495. }
  496. function stringToBytes(str) {
  497. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  498. var length = str.length;
  499. var bytes = new Uint8Array(length);
  500. for (var i = 0; i < length; ++i) {
  501. bytes[i] = str.charCodeAt(i) & 0xFF;
  502. }
  503. return bytes;
  504. }
  505. function string32(value) {
  506. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  507. (value >> 8) & 0xff, value & 0xff);
  508. }
  509. function log2(x) {
  510. var n = 1, i = 0;
  511. while (x > n) {
  512. n <<= 1;
  513. i++;
  514. }
  515. return i;
  516. }
  517. function readInt8(data, start) {
  518. return (data[start] << 24) >> 24;
  519. }
  520. function readUint16(data, offset) {
  521. return (data[offset] << 8) | data[offset + 1];
  522. }
  523. function readUint32(data, offset) {
  524. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  525. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  526. }
  527. // Lazy test the endianness of the platform
  528. // NOTE: This will be 'true' for simulated TypedArrays
  529. function isLittleEndian() {
  530. var buffer8 = new Uint8Array(2);
  531. buffer8[0] = 1;
  532. var buffer16 = new Uint16Array(buffer8.buffer);
  533. return (buffer16[0] === 1);
  534. }
  535. Object.defineProperty(PDFJS, 'isLittleEndian', {
  536. configurable: true,
  537. get: function PDFJS_isLittleEndian() {
  538. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  539. }
  540. });
  541. // Lazy test if the userAgent support CanvasTypedArrays
  542. function hasCanvasTypedArrays() {
  543. var canvas = document.createElement('canvas');
  544. canvas.width = canvas.height = 1;
  545. var ctx = canvas.getContext('2d');
  546. var imageData = ctx.createImageData(1, 1);
  547. return (typeof imageData.data.buffer !== 'undefined');
  548. }
  549. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  550. configurable: true,
  551. get: function PDFJS_hasCanvasTypedArrays() {
  552. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  553. }
  554. });
  555. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  556. function Uint32ArrayView(buffer, length) {
  557. this.buffer = buffer;
  558. this.byteLength = buffer.length;
  559. this.length = length === undefined ? (this.byteLength >> 2) : length;
  560. ensureUint32ArrayViewProps(this.length);
  561. }
  562. Uint32ArrayView.prototype = Object.create(null);
  563. var uint32ArrayViewSetters = 0;
  564. function createUint32ArrayProp(index) {
  565. return {
  566. get: function () {
  567. var buffer = this.buffer, offset = index << 2;
  568. return (buffer[offset] | (buffer[offset + 1] << 8) |
  569. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  570. },
  571. set: function (value) {
  572. var buffer = this.buffer, offset = index << 2;
  573. buffer[offset] = value & 255;
  574. buffer[offset + 1] = (value >> 8) & 255;
  575. buffer[offset + 2] = (value >> 16) & 255;
  576. buffer[offset + 3] = (value >>> 24) & 255;
  577. }
  578. };
  579. }
  580. function ensureUint32ArrayViewProps(length) {
  581. while (uint32ArrayViewSetters < length) {
  582. Object.defineProperty(Uint32ArrayView.prototype,
  583. uint32ArrayViewSetters,
  584. createUint32ArrayProp(uint32ArrayViewSetters));
  585. uint32ArrayViewSetters++;
  586. }
  587. }
  588. return Uint32ArrayView;
  589. })();
  590. exports.Uint32ArrayView = Uint32ArrayView;
  591. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  592. var Util = PDFJS.Util = (function UtilClosure() {
  593. function Util() {}
  594. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  595. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  596. // creating many intermediate strings.
  597. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  598. rgbBuf[1] = r;
  599. rgbBuf[3] = g;
  600. rgbBuf[5] = b;
  601. return rgbBuf.join('');
  602. };
  603. // Concatenates two transformation matrices together and returns the result.
  604. Util.transform = function Util_transform(m1, m2) {
  605. return [
  606. m1[0] * m2[0] + m1[2] * m2[1],
  607. m1[1] * m2[0] + m1[3] * m2[1],
  608. m1[0] * m2[2] + m1[2] * m2[3],
  609. m1[1] * m2[2] + m1[3] * m2[3],
  610. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  611. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  612. ];
  613. };
  614. // For 2d affine transforms
  615. Util.applyTransform = function Util_applyTransform(p, m) {
  616. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  617. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  618. return [xt, yt];
  619. };
  620. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  621. var d = m[0] * m[3] - m[1] * m[2];
  622. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  623. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  624. return [xt, yt];
  625. };
  626. // Applies the transform to the rectangle and finds the minimum axially
  627. // aligned bounding box.
  628. Util.getAxialAlignedBoundingBox =
  629. function Util_getAxialAlignedBoundingBox(r, m) {
  630. var p1 = Util.applyTransform(r, m);
  631. var p2 = Util.applyTransform(r.slice(2, 4), m);
  632. var p3 = Util.applyTransform([r[0], r[3]], m);
  633. var p4 = Util.applyTransform([r[2], r[1]], m);
  634. return [
  635. Math.min(p1[0], p2[0], p3[0], p4[0]),
  636. Math.min(p1[1], p2[1], p3[1], p4[1]),
  637. Math.max(p1[0], p2[0], p3[0], p4[0]),
  638. Math.max(p1[1], p2[1], p3[1], p4[1])
  639. ];
  640. };
  641. Util.inverseTransform = function Util_inverseTransform(m) {
  642. var d = m[0] * m[3] - m[1] * m[2];
  643. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  644. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  645. };
  646. // Apply a generic 3d matrix M on a 3-vector v:
  647. // | a b c | | X |
  648. // | d e f | x | Y |
  649. // | g h i | | Z |
  650. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  651. // with v as [X,Y,Z]
  652. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  653. return [
  654. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  655. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  656. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  657. ];
  658. };
  659. // This calculation uses Singular Value Decomposition.
  660. // The SVD can be represented with formula A = USV. We are interested in the
  661. // matrix S here because it represents the scale values.
  662. Util.singularValueDecompose2dScale =
  663. function Util_singularValueDecompose2dScale(m) {
  664. var transpose = [m[0], m[2], m[1], m[3]];
  665. // Multiply matrix m with its transpose.
  666. var a = m[0] * transpose[0] + m[1] * transpose[2];
  667. var b = m[0] * transpose[1] + m[1] * transpose[3];
  668. var c = m[2] * transpose[0] + m[3] * transpose[2];
  669. var d = m[2] * transpose[1] + m[3] * transpose[3];
  670. // Solve the second degree polynomial to get roots.
  671. var first = (a + d) / 2;
  672. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  673. var sx = first + second || 1;
  674. var sy = first - second || 1;
  675. // Scale values are the square roots of the eigenvalues.
  676. return [Math.sqrt(sx), Math.sqrt(sy)];
  677. };
  678. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  679. // For coordinate systems whose origin lies in the bottom-left, this
  680. // means normalization to (BL,TR) ordering. For systems with origin in the
  681. // top-left, this means (TL,BR) ordering.
  682. Util.normalizeRect = function Util_normalizeRect(rect) {
  683. var r = rect.slice(0); // clone rect
  684. if (rect[0] > rect[2]) {
  685. r[0] = rect[2];
  686. r[2] = rect[0];
  687. }
  688. if (rect[1] > rect[3]) {
  689. r[1] = rect[3];
  690. r[3] = rect[1];
  691. }
  692. return r;
  693. };
  694. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  695. // intersection of rect1 and rect2. If no intersection, returns 'false'
  696. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  697. Util.intersect = function Util_intersect(rect1, rect2) {
  698. function compare(a, b) {
  699. return a - b;
  700. }
  701. // Order points along the axes
  702. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  703. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  704. result = [];
  705. rect1 = Util.normalizeRect(rect1);
  706. rect2 = Util.normalizeRect(rect2);
  707. // X: first and second points belong to different rectangles?
  708. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  709. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  710. // Intersection must be between second and third points
  711. result[0] = orderedX[1];
  712. result[2] = orderedX[2];
  713. } else {
  714. return false;
  715. }
  716. // Y: first and second points belong to different rectangles?
  717. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  718. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  719. // Intersection must be between second and third points
  720. result[1] = orderedY[1];
  721. result[3] = orderedY[2];
  722. } else {
  723. return false;
  724. }
  725. return result;
  726. };
  727. Util.sign = function Util_sign(num) {
  728. return num < 0 ? -1 : 1;
  729. };
  730. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  731. Array.prototype.push.apply(arr1, arr2);
  732. };
  733. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  734. Array.prototype.unshift.apply(arr1, arr2);
  735. };
  736. Util.extendObj = function extendObj(obj1, obj2) {
  737. for (var key in obj2) {
  738. obj1[key] = obj2[key];
  739. }
  740. };
  741. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  742. name) {
  743. while (dict && !dict.has(name)) {
  744. dict = dict.get('Parent');
  745. }
  746. if (!dict) {
  747. return null;
  748. }
  749. return dict.get(name);
  750. };
  751. Util.inherit = function Util_inherit(sub, base, prototype) {
  752. sub.prototype = Object.create(base.prototype);
  753. sub.prototype.constructor = sub;
  754. for (var prop in prototype) {
  755. sub.prototype[prop] = prototype[prop];
  756. }
  757. };
  758. Util.loadScript = function Util_loadScript(src, callback) {
  759. var script = document.createElement('script');
  760. var loaded = false;
  761. script.setAttribute('src', src);
  762. if (callback) {
  763. script.onload = function() {
  764. if (!loaded) {
  765. callback();
  766. }
  767. loaded = true;
  768. };
  769. }
  770. document.getElementsByTagName('head')[0].appendChild(script);
  771. };
  772. return Util;
  773. })();
  774. /**
  775. * PDF page viewport created based on scale, rotation and offset.
  776. * @class
  777. * @alias PDFJS.PageViewport
  778. */
  779. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  780. /**
  781. * @constructor
  782. * @private
  783. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  784. * @param scale {number} scale of the viewport.
  785. * @param rotation {number} rotations of the viewport in degrees.
  786. * @param offsetX {number} offset X
  787. * @param offsetY {number} offset Y
  788. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  789. */
  790. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  791. this.viewBox = viewBox;
  792. this.scale = scale;
  793. this.rotation = rotation;
  794. this.offsetX = offsetX;
  795. this.offsetY = offsetY;
  796. // creating transform to convert pdf coordinate system to the normal
  797. // canvas like coordinates taking in account scale and rotation
  798. var centerX = (viewBox[2] + viewBox[0]) / 2;
  799. var centerY = (viewBox[3] + viewBox[1]) / 2;
  800. var rotateA, rotateB, rotateC, rotateD;
  801. rotation = rotation % 360;
  802. rotation = rotation < 0 ? rotation + 360 : rotation;
  803. switch (rotation) {
  804. case 180:
  805. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  806. break;
  807. case 90:
  808. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  809. break;
  810. case 270:
  811. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  812. break;
  813. //case 0:
  814. default:
  815. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  816. break;
  817. }
  818. if (dontFlip) {
  819. rotateC = -rotateC; rotateD = -rotateD;
  820. }
  821. var offsetCanvasX, offsetCanvasY;
  822. var width, height;
  823. if (rotateA === 0) {
  824. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  825. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  826. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  827. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  828. } else {
  829. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  830. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  831. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  832. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  833. }
  834. // creating transform for the following operations:
  835. // translate(-centerX, -centerY), rotate and flip vertically,
  836. // scale, and translate(offsetCanvasX, offsetCanvasY)
  837. this.transform = [
  838. rotateA * scale,
  839. rotateB * scale,
  840. rotateC * scale,
  841. rotateD * scale,
  842. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  843. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  844. ];
  845. this.width = width;
  846. this.height = height;
  847. this.fontScale = scale;
  848. }
  849. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  850. /**
  851. * Clones viewport with additional properties.
  852. * @param args {Object} (optional) If specified, may contain the 'scale' or
  853. * 'rotation' properties to override the corresponding properties in
  854. * the cloned viewport.
  855. * @returns {PDFJS.PageViewport} Cloned viewport.
  856. */
  857. clone: function PageViewPort_clone(args) {
  858. args = args || {};
  859. var scale = 'scale' in args ? args.scale : this.scale;
  860. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  861. return new PageViewport(this.viewBox.slice(), scale, rotation,
  862. this.offsetX, this.offsetY, args.dontFlip);
  863. },
  864. /**
  865. * Converts PDF point to the viewport coordinates. For examples, useful for
  866. * converting PDF location into canvas pixel coordinates.
  867. * @param x {number} X coordinate.
  868. * @param y {number} Y coordinate.
  869. * @returns {Object} Object that contains 'x' and 'y' properties of the
  870. * point in the viewport coordinate space.
  871. * @see {@link convertToPdfPoint}
  872. * @see {@link convertToViewportRectangle}
  873. */
  874. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  875. return Util.applyTransform([x, y], this.transform);
  876. },
  877. /**
  878. * Converts PDF rectangle to the viewport coordinates.
  879. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  880. * @returns {Array} Contains corresponding coordinates of the rectangle
  881. * in the viewport coordinate space.
  882. * @see {@link convertToViewportPoint}
  883. */
  884. convertToViewportRectangle:
  885. function PageViewport_convertToViewportRectangle(rect) {
  886. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  887. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  888. return [tl[0], tl[1], br[0], br[1]];
  889. },
  890. /**
  891. * Converts viewport coordinates to the PDF location. For examples, useful
  892. * for converting canvas pixel location into PDF one.
  893. * @param x {number} X coordinate.
  894. * @param y {number} Y coordinate.
  895. * @returns {Object} Object that contains 'x' and 'y' properties of the
  896. * point in the PDF coordinate space.
  897. * @see {@link convertToViewportPoint}
  898. */
  899. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  900. return Util.applyInverseTransform([x, y], this.transform);
  901. }
  902. };
  903. return PageViewport;
  904. })();
  905. var PDFStringTranslateTable = [
  906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  907. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  908. 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,
  909. 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,
  910. 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,
  911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  912. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  913. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  914. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  915. ];
  916. function stringToPDFString(str) {
  917. var i, n = str.length, strBuf = [];
  918. if (str[0] === '\xFE' && str[1] === '\xFF') {
  919. // UTF16BE BOM
  920. for (i = 2; i < n; i += 2) {
  921. strBuf.push(String.fromCharCode(
  922. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  923. }
  924. } else {
  925. for (i = 0; i < n; ++i) {
  926. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  927. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  928. }
  929. }
  930. return strBuf.join('');
  931. }
  932. function stringToUTF8String(str) {
  933. return decodeURIComponent(escape(str));
  934. }
  935. function utf8StringToString(str) {
  936. return unescape(encodeURIComponent(str));
  937. }
  938. function isEmptyObj(obj) {
  939. for (var key in obj) {
  940. return false;
  941. }
  942. return true;
  943. }
  944. function isBool(v) {
  945. return typeof v === 'boolean';
  946. }
  947. function isInt(v) {
  948. return typeof v === 'number' && ((v | 0) === v);
  949. }
  950. function isNum(v) {
  951. return typeof v === 'number';
  952. }
  953. function isString(v) {
  954. return typeof v === 'string';
  955. }
  956. function isArray(v) {
  957. return v instanceof Array;
  958. }
  959. function isArrayBuffer(v) {
  960. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  961. }
  962. /**
  963. * Promise Capability object.
  964. *
  965. * @typedef {Object} PromiseCapability
  966. * @property {Promise} promise - A promise object.
  967. * @property {function} resolve - Fullfills the promise.
  968. * @property {function} reject - Rejects the promise.
  969. */
  970. /**
  971. * Creates a promise capability object.
  972. * @alias PDFJS.createPromiseCapability
  973. *
  974. * @return {PromiseCapability} A capability object contains:
  975. * - a Promise, resolve and reject methods.
  976. */
  977. function createPromiseCapability() {
  978. var capability = {};
  979. capability.promise = new Promise(function (resolve, reject) {
  980. capability.resolve = resolve;
  981. capability.reject = reject;
  982. });
  983. return capability;
  984. }
  985. PDFJS.createPromiseCapability = createPromiseCapability;
  986. /**
  987. * Polyfill for Promises:
  988. * The following promise implementation tries to generally implement the
  989. * Promise/A+ spec. Some notable differences from other promise libaries are:
  990. * - There currently isn't a seperate deferred and promise object.
  991. * - Unhandled rejections eventually show an error if they aren't handled.
  992. *
  993. * Based off of the work in:
  994. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  995. */
  996. (function PromiseClosure() {
  997. if (globalScope.Promise) {
  998. // Promises existing in the DOM/Worker, checking presence of all/resolve
  999. if (typeof globalScope.Promise.all !== 'function') {
  1000. globalScope.Promise.all = function (iterable) {
  1001. var count = 0, results = [], resolve, reject;
  1002. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1003. resolve = resolve_;
  1004. reject = reject_;
  1005. });
  1006. iterable.forEach(function (p, i) {
  1007. count++;
  1008. p.then(function (result) {
  1009. results[i] = result;
  1010. count--;
  1011. if (count === 0) {
  1012. resolve(results);
  1013. }
  1014. }, reject);
  1015. });
  1016. if (count === 0) {
  1017. resolve(results);
  1018. }
  1019. return promise;
  1020. };
  1021. }
  1022. if (typeof globalScope.Promise.resolve !== 'function') {
  1023. globalScope.Promise.resolve = function (value) {
  1024. return new globalScope.Promise(function (resolve) { resolve(value); });
  1025. };
  1026. }
  1027. if (typeof globalScope.Promise.reject !== 'function') {
  1028. globalScope.Promise.reject = function (reason) {
  1029. return new globalScope.Promise(function (resolve, reject) {
  1030. reject(reason);
  1031. });
  1032. };
  1033. }
  1034. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1035. globalScope.Promise.prototype.catch = function (onReject) {
  1036. return globalScope.Promise.prototype.then(undefined, onReject);
  1037. };
  1038. }
  1039. return;
  1040. }
  1041. var STATUS_PENDING = 0;
  1042. var STATUS_RESOLVED = 1;
  1043. var STATUS_REJECTED = 2;
  1044. // In an attempt to avoid silent exceptions, unhandled rejections are
  1045. // tracked and if they aren't handled in a certain amount of time an
  1046. // error is logged.
  1047. var REJECTION_TIMEOUT = 500;
  1048. var HandlerManager = {
  1049. handlers: [],
  1050. running: false,
  1051. unhandledRejections: [],
  1052. pendingRejectionCheck: false,
  1053. scheduleHandlers: function scheduleHandlers(promise) {
  1054. if (promise._status === STATUS_PENDING) {
  1055. return;
  1056. }
  1057. this.handlers = this.handlers.concat(promise._handlers);
  1058. promise._handlers = [];
  1059. if (this.running) {
  1060. return;
  1061. }
  1062. this.running = true;
  1063. setTimeout(this.runHandlers.bind(this), 0);
  1064. },
  1065. runHandlers: function runHandlers() {
  1066. var RUN_TIMEOUT = 1; // ms
  1067. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1068. while (this.handlers.length > 0) {
  1069. var handler = this.handlers.shift();
  1070. var nextStatus = handler.thisPromise._status;
  1071. var nextValue = handler.thisPromise._value;
  1072. try {
  1073. if (nextStatus === STATUS_RESOLVED) {
  1074. if (typeof handler.onResolve === 'function') {
  1075. nextValue = handler.onResolve(nextValue);
  1076. }
  1077. } else if (typeof handler.onReject === 'function') {
  1078. nextValue = handler.onReject(nextValue);
  1079. nextStatus = STATUS_RESOLVED;
  1080. if (handler.thisPromise._unhandledRejection) {
  1081. this.removeUnhandeledRejection(handler.thisPromise);
  1082. }
  1083. }
  1084. } catch (ex) {
  1085. nextStatus = STATUS_REJECTED;
  1086. nextValue = ex;
  1087. }
  1088. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1089. if (Date.now() >= timeoutAt) {
  1090. break;
  1091. }
  1092. }
  1093. if (this.handlers.length > 0) {
  1094. setTimeout(this.runHandlers.bind(this), 0);
  1095. return;
  1096. }
  1097. this.running = false;
  1098. },
  1099. addUnhandledRejection: function addUnhandledRejection(promise) {
  1100. this.unhandledRejections.push({
  1101. promise: promise,
  1102. time: Date.now()
  1103. });
  1104. this.scheduleRejectionCheck();
  1105. },
  1106. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1107. promise._unhandledRejection = false;
  1108. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1109. if (this.unhandledRejections[i].promise === promise) {
  1110. this.unhandledRejections.splice(i);
  1111. i--;
  1112. }
  1113. }
  1114. },
  1115. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1116. if (this.pendingRejectionCheck) {
  1117. return;
  1118. }
  1119. this.pendingRejectionCheck = true;
  1120. setTimeout(function rejectionCheck() {
  1121. this.pendingRejectionCheck = false;
  1122. var now = Date.now();
  1123. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1124. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1125. var unhandled = this.unhandledRejections[i].promise._value;
  1126. var msg = 'Unhandled rejection: ' + unhandled;
  1127. if (unhandled.stack) {
  1128. msg += '\n' + unhandled.stack;
  1129. }
  1130. warn(msg);
  1131. this.unhandledRejections.splice(i);
  1132. i--;
  1133. }
  1134. }
  1135. if (this.unhandledRejections.length) {
  1136. this.scheduleRejectionCheck();
  1137. }
  1138. }.bind(this), REJECTION_TIMEOUT);
  1139. }
  1140. };
  1141. function Promise(resolver) {
  1142. this._status = STATUS_PENDING;
  1143. this._handlers = [];
  1144. try {
  1145. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1146. } catch (e) {
  1147. this._reject(e);
  1148. }
  1149. }
  1150. /**
  1151. * Builds a promise that is resolved when all the passed in promises are
  1152. * resolved.
  1153. * @param {array} array of data and/or promises to wait for.
  1154. * @return {Promise} New dependant promise.
  1155. */
  1156. Promise.all = function Promise_all(promises) {
  1157. var resolveAll, rejectAll;
  1158. var deferred = new Promise(function (resolve, reject) {
  1159. resolveAll = resolve;
  1160. rejectAll = reject;
  1161. });
  1162. var unresolved = promises.length;
  1163. var results = [];
  1164. if (unresolved === 0) {
  1165. resolveAll(results);
  1166. return deferred;
  1167. }
  1168. function reject(reason) {
  1169. if (deferred._status === STATUS_REJECTED) {
  1170. return;
  1171. }
  1172. results = [];
  1173. rejectAll(reason);
  1174. }
  1175. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1176. var promise = promises[i];
  1177. var resolve = (function(i) {
  1178. return function(value) {
  1179. if (deferred._status === STATUS_REJECTED) {
  1180. return;
  1181. }
  1182. results[i] = value;
  1183. unresolved--;
  1184. if (unresolved === 0) {
  1185. resolveAll(results);
  1186. }
  1187. };
  1188. })(i);
  1189. if (Promise.isPromise(promise)) {
  1190. promise.then(resolve, reject);
  1191. } else {
  1192. resolve(promise);
  1193. }
  1194. }
  1195. return deferred;
  1196. };
  1197. /**
  1198. * Checks if the value is likely a promise (has a 'then' function).
  1199. * @return {boolean} true if value is thenable
  1200. */
  1201. Promise.isPromise = function Promise_isPromise(value) {
  1202. return value && typeof value.then === 'function';
  1203. };
  1204. /**
  1205. * Creates resolved promise
  1206. * @param value resolve value
  1207. * @returns {Promise}
  1208. */
  1209. Promise.resolve = function Promise_resolve(value) {
  1210. return new Promise(function (resolve) { resolve(value); });
  1211. };
  1212. /**
  1213. * Creates rejected promise
  1214. * @param reason rejection value
  1215. * @returns {Promise}
  1216. */
  1217. Promise.reject = function Promise_reject(reason) {
  1218. return new Promise(function (resolve, reject) { reject(reason); });
  1219. };
  1220. Promise.prototype = {
  1221. _status: null,
  1222. _value: null,
  1223. _handlers: null,
  1224. _unhandledRejection: null,
  1225. _updateStatus: function Promise__updateStatus(status, value) {
  1226. if (this._status === STATUS_RESOLVED ||
  1227. this._status === STATUS_REJECTED) {
  1228. return;
  1229. }
  1230. if (status === STATUS_RESOLVED &&
  1231. Promise.isPromise(value)) {
  1232. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1233. this._updateStatus.bind(this, STATUS_REJECTED));
  1234. return;
  1235. }
  1236. this._status = status;
  1237. this._value = value;
  1238. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1239. this._unhandledRejection = true;
  1240. HandlerManager.addUnhandledRejection(this);
  1241. }
  1242. HandlerManager.scheduleHandlers(this);
  1243. },
  1244. _resolve: function Promise_resolve(value) {
  1245. this._updateStatus(STATUS_RESOLVED, value);
  1246. },
  1247. _reject: function Promise_reject(reason) {
  1248. this._updateStatus(STATUS_REJECTED, reason);
  1249. },
  1250. then: function Promise_then(onResolve, onReject) {
  1251. var nextPromise = new Promise(function (resolve, reject) {
  1252. this.resolve = resolve;
  1253. this.reject = reject;
  1254. });
  1255. this._handlers.push({
  1256. thisPromise: this,
  1257. onResolve: onResolve,
  1258. onReject: onReject,
  1259. nextPromise: nextPromise
  1260. });
  1261. HandlerManager.scheduleHandlers(this);
  1262. return nextPromise;
  1263. },
  1264. catch: function Promise_catch(onReject) {
  1265. return this.then(undefined, onReject);
  1266. }
  1267. };
  1268. globalScope.Promise = Promise;
  1269. })();
  1270. var StatTimer = (function StatTimerClosure() {
  1271. function rpad(str, pad, length) {
  1272. while (str.length < length) {
  1273. str += pad;
  1274. }
  1275. return str;
  1276. }
  1277. function StatTimer() {
  1278. this.started = {};
  1279. this.times = [];
  1280. this.enabled = true;
  1281. }
  1282. StatTimer.prototype = {
  1283. time: function StatTimer_time(name) {
  1284. if (!this.enabled) {
  1285. return;
  1286. }
  1287. if (name in this.started) {
  1288. warn('Timer is already running for ' + name);
  1289. }
  1290. this.started[name] = Date.now();
  1291. },
  1292. timeEnd: function StatTimer_timeEnd(name) {
  1293. if (!this.enabled) {
  1294. return;
  1295. }
  1296. if (!(name in this.started)) {
  1297. warn('Timer has not been started for ' + name);
  1298. }
  1299. this.times.push({
  1300. 'name': name,
  1301. 'start': this.started[name],
  1302. 'end': Date.now()
  1303. });
  1304. // Remove timer from started so it can be called again.
  1305. delete this.started[name];
  1306. },
  1307. toString: function StatTimer_toString() {
  1308. var i, ii;
  1309. var times = this.times;
  1310. var out = '';
  1311. // Find the longest name for padding purposes.
  1312. var longest = 0;
  1313. for (i = 0, ii = times.length; i < ii; ++i) {
  1314. var name = times[i]['name'];
  1315. if (name.length > longest) {
  1316. longest = name.length;
  1317. }
  1318. }
  1319. for (i = 0, ii = times.length; i < ii; ++i) {
  1320. var span = times[i];
  1321. var duration = span.end - span.start;
  1322. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1323. }
  1324. return out;
  1325. }
  1326. };
  1327. return StatTimer;
  1328. })();
  1329. PDFJS.createBlob = function createBlob(data, contentType) {
  1330. if (typeof Blob !== 'undefined') {
  1331. return new Blob([data], { type: contentType });
  1332. }
  1333. // Blob builder is deprecated in FF14 and removed in FF18.
  1334. var bb = new MozBlobBuilder();
  1335. bb.append(data);
  1336. return bb.getBlob(contentType);
  1337. };
  1338. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1339. // Blob/createObjectURL is not available, falling back to data schema.
  1340. var digits =
  1341. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1342. return function createObjectURL(data, contentType) {
  1343. if (!PDFJS.disableCreateObjectURL &&
  1344. typeof URL !== 'undefined' && URL.createObjectURL) {
  1345. var blob = PDFJS.createBlob(data, contentType);
  1346. return URL.createObjectURL(blob);
  1347. }
  1348. var buffer = 'data:' + contentType + ';base64,';
  1349. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1350. var b1 = data[i] & 0xFF;
  1351. var b2 = data[i + 1] & 0xFF;
  1352. var b3 = data[i + 2] & 0xFF;
  1353. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1354. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1355. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1356. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1357. }
  1358. return buffer;
  1359. };
  1360. })();
  1361. function MessageHandler(sourceName, targetName, comObj) {
  1362. this.sourceName = sourceName;
  1363. this.targetName = targetName;
  1364. this.comObj = comObj;
  1365. this.callbackIndex = 1;
  1366. this.postMessageTransfers = true;
  1367. var callbacksCapabilities = this.callbacksCapabilities = {};
  1368. var ah = this.actionHandler = {};
  1369. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  1370. var data = event.data;
  1371. if (data.targetName !== this.sourceName) {
  1372. return;
  1373. }
  1374. if (data.isReply) {
  1375. var callbackId = data.callbackId;
  1376. if (data.callbackId in callbacksCapabilities) {
  1377. var callback = callbacksCapabilities[callbackId];
  1378. delete callbacksCapabilities[callbackId];
  1379. if ('error' in data) {
  1380. callback.reject(data.error);
  1381. } else {
  1382. callback.resolve(data.data);
  1383. }
  1384. } else {
  1385. error('Cannot resolve callback ' + callbackId);
  1386. }
  1387. } else if (data.action in ah) {
  1388. var action = ah[data.action];
  1389. if (data.callbackId) {
  1390. var sourceName = this.sourceName;
  1391. var targetName = data.sourceName;
  1392. Promise.resolve().then(function () {
  1393. return action[0].call(action[1], data.data);
  1394. }).then(function (result) {
  1395. comObj.postMessage({
  1396. sourceName: sourceName,
  1397. targetName: targetName,
  1398. isReply: true,
  1399. callbackId: data.callbackId,
  1400. data: result
  1401. });
  1402. }, function (reason) {
  1403. if (reason instanceof Error) {
  1404. // Serialize error to avoid "DataCloneError"
  1405. reason = reason + '';
  1406. }
  1407. comObj.postMessage({
  1408. sourceName: sourceName,
  1409. targetName: targetName,
  1410. isReply: true,
  1411. callbackId: data.callbackId,
  1412. error: reason
  1413. });
  1414. });
  1415. } else {
  1416. action[0].call(action[1], data.data);
  1417. }
  1418. } else {
  1419. error('Unknown action from worker: ' + data.action);
  1420. }
  1421. }.bind(this);
  1422. comObj.addEventListener('message', this._onComObjOnMessage);
  1423. }
  1424. MessageHandler.prototype = {
  1425. on: function messageHandlerOn(actionName, handler, scope) {
  1426. var ah = this.actionHandler;
  1427. if (ah[actionName]) {
  1428. error('There is already an actionName called "' + actionName + '"');
  1429. }
  1430. ah[actionName] = [handler, scope];
  1431. },
  1432. /**
  1433. * Sends a message to the comObj to invoke the action with the supplied data.
  1434. * @param {String} actionName Action to call.
  1435. * @param {JSON} data JSON data to send.
  1436. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1437. */
  1438. send: function messageHandlerSend(actionName, data, transfers) {
  1439. var message = {
  1440. sourceName: this.sourceName,
  1441. targetName: this.targetName,
  1442. action: actionName,
  1443. data: data
  1444. };
  1445. this.postMessage(message, transfers);
  1446. },
  1447. /**
  1448. * Sends a message to the comObj to invoke the action with the supplied data.
  1449. * Expects that other side will callback with the response.
  1450. * @param {String} actionName Action to call.
  1451. * @param {JSON} data JSON data to send.
  1452. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1453. * @returns {Promise} Promise to be resolved with response data.
  1454. */
  1455. sendWithPromise:
  1456. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1457. var callbackId = this.callbackIndex++;
  1458. var message = {
  1459. sourceName: this.sourceName,
  1460. targetName: this.targetName,
  1461. action: actionName,
  1462. data: data,
  1463. callbackId: callbackId
  1464. };
  1465. var capability = createPromiseCapability();
  1466. this.callbacksCapabilities[callbackId] = capability;
  1467. try {
  1468. this.postMessage(message, transfers);
  1469. } catch (e) {
  1470. capability.reject(e);
  1471. }
  1472. return capability.promise;
  1473. },
  1474. /**
  1475. * Sends raw message to the comObj.
  1476. * @private
  1477. * @param message {Object} Raw message.
  1478. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1479. */
  1480. postMessage: function (message, transfers) {
  1481. if (transfers && this.postMessageTransfers) {
  1482. this.comObj.postMessage(message, transfers);
  1483. } else {
  1484. this.comObj.postMessage(message);
  1485. }
  1486. },
  1487. destroy: function () {
  1488. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1489. }
  1490. };
  1491. function loadJpegStream(id, imageUrl, objs) {
  1492. var img = new Image();
  1493. img.onload = (function loadJpegStream_onloadClosure() {
  1494. objs.resolve(id, img);
  1495. });
  1496. img.onerror = (function loadJpegStream_onerrorClosure() {
  1497. objs.resolve(id, null);
  1498. warn('Error during JPEG image loading');
  1499. });
  1500. img.src = imageUrl;
  1501. }
  1502. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  1503. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  1504. exports.OPS = OPS;
  1505. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1506. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  1507. exports.AnnotationFlag = AnnotationFlag;
  1508. exports.AnnotationType = AnnotationType;
  1509. exports.FontType = FontType;
  1510. exports.ImageKind = ImageKind;
  1511. exports.InvalidPDFException = InvalidPDFException;
  1512. exports.LinkTarget = LinkTarget;
  1513. exports.LinkTargetStringMap = LinkTargetStringMap;
  1514. exports.MessageHandler = MessageHandler;
  1515. exports.MissingDataException = MissingDataException;
  1516. exports.MissingPDFException = MissingPDFException;
  1517. exports.NotImplementedException = NotImplementedException;
  1518. exports.PasswordException = PasswordException;
  1519. exports.PasswordResponses = PasswordResponses;
  1520. exports.StatTimer = StatTimer;
  1521. exports.StreamType = StreamType;
  1522. exports.TextRenderingMode = TextRenderingMode;
  1523. exports.UnexpectedResponseException = UnexpectedResponseException;
  1524. exports.UnknownErrorException = UnknownErrorException;
  1525. exports.Util = Util;
  1526. exports.XRefParseException = XRefParseException;
  1527. exports.assert = assert;
  1528. exports.bytesToString = bytesToString;
  1529. exports.combineUrl = combineUrl;
  1530. exports.createPromiseCapability = createPromiseCapability;
  1531. exports.deprecated = deprecated;
  1532. exports.error = error;
  1533. exports.info = info;
  1534. exports.isArray = isArray;
  1535. exports.isArrayBuffer = isArrayBuffer;
  1536. exports.isBool = isBool;
  1537. exports.isEmptyObj = isEmptyObj;
  1538. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1539. exports.isInt = isInt;
  1540. exports.isNum = isNum;
  1541. exports.isString = isString;
  1542. exports.isValidUrl = isValidUrl;
  1543. exports.loadJpegStream = loadJpegStream;
  1544. exports.log2 = log2;
  1545. exports.readInt8 = readInt8;
  1546. exports.readUint16 = readUint16;
  1547. exports.readUint32 = readUint32;
  1548. exports.shadow = shadow;
  1549. exports.string32 = string32;
  1550. exports.stringToBytes = stringToBytes;
  1551. exports.stringToPDFString = stringToPDFString;
  1552. exports.stringToUTF8String = stringToUTF8String;
  1553. exports.utf8StringToString = utf8StringToString;
  1554. exports.warn = warn;
  1555. }));
  1556. (function (root, factory) {
  1557. {
  1558. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  1559. }
  1560. }(this, function (exports, sharedGlobal) {
  1561. var PDFJS = sharedGlobal.PDFJS;
  1562. /**
  1563. * Optimised CSS custom property getter/setter.
  1564. * @class
  1565. */
  1566. var CustomStyle = (function CustomStyleClosure() {
  1567. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  1568. // animate-css-transforms-firefox-webkit.html
  1569. // in some versions of IE9 it is critical that ms appear in this list
  1570. // before Moz
  1571. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  1572. var _cache = {};
  1573. function CustomStyle() {}
  1574. CustomStyle.getProp = function get(propName, element) {
  1575. // check cache only when no element is given
  1576. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  1577. return _cache[propName];
  1578. }
  1579. element = element || document.documentElement;
  1580. var style = element.style, prefixed, uPropName;
  1581. // test standard property first
  1582. if (typeof style[propName] === 'string') {
  1583. return (_cache[propName] = propName);
  1584. }
  1585. // capitalize
  1586. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  1587. // test vendor specific properties
  1588. for (var i = 0, l = prefixes.length; i < l; i++) {
  1589. prefixed = prefixes[i] + uPropName;
  1590. if (typeof style[prefixed] === 'string') {
  1591. return (_cache[propName] = prefixed);
  1592. }
  1593. }
  1594. //if all fails then set to undefined
  1595. return (_cache[propName] = 'undefined');
  1596. };
  1597. CustomStyle.setProp = function set(propName, element, str) {
  1598. var prop = this.getProp(propName);
  1599. if (prop !== 'undefined') {
  1600. element.style[prop] = str;
  1601. }
  1602. };
  1603. return CustomStyle;
  1604. })();
  1605. PDFJS.CustomStyle = CustomStyle;
  1606. exports.CustomStyle = CustomStyle;
  1607. }));
  1608. (function (root, factory) {
  1609. {
  1610. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  1611. root.pdfjsDisplayDOMUtils);
  1612. }
  1613. }(this, function (exports, sharedUtil, displayDOMUtils) {
  1614. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  1615. var AnnotationType = sharedUtil.AnnotationType;
  1616. var Util = sharedUtil.Util;
  1617. var isExternalLinkTargetSet = sharedUtil.isExternalLinkTargetSet;
  1618. var LinkTargetStringMap = sharedUtil.LinkTargetStringMap;
  1619. var warn = sharedUtil.warn;
  1620. var CustomStyle = displayDOMUtils.CustomStyle;
  1621. /**
  1622. * @typedef {Object} AnnotationElementParameters
  1623. * @property {Object} data
  1624. * @property {HTMLDivElement} layer
  1625. * @property {PDFPage} page
  1626. * @property {PageViewport} viewport
  1627. * @property {IPDFLinkService} linkService
  1628. */
  1629. /**
  1630. * @class
  1631. * @alias AnnotationElementFactory
  1632. */
  1633. function AnnotationElementFactory() {}
  1634. AnnotationElementFactory.prototype =
  1635. /** @lends AnnotationElementFactory.prototype */ {
  1636. /**
  1637. * @param {AnnotationElementParameters} parameters
  1638. * @returns {AnnotationElement}
  1639. */
  1640. create: function AnnotationElementFactory_create(parameters) {
  1641. var subtype = parameters.data.annotationType;
  1642. switch (subtype) {
  1643. case AnnotationType.LINK:
  1644. return new LinkAnnotationElement(parameters);
  1645. case AnnotationType.TEXT:
  1646. return new TextAnnotationElement(parameters);
  1647. case AnnotationType.WIDGET:
  1648. return new WidgetAnnotationElement(parameters);
  1649. case AnnotationType.POPUP:
  1650. return new PopupAnnotationElement(parameters);
  1651. default:
  1652. throw new Error('Unimplemented annotation type "' + subtype + '"');
  1653. }
  1654. }
  1655. };
  1656. /**
  1657. * @class
  1658. * @alias AnnotationElement
  1659. */
  1660. var AnnotationElement = (function AnnotationElementClosure() {
  1661. function AnnotationElement(parameters) {
  1662. this.data = parameters.data;
  1663. this.layer = parameters.layer;
  1664. this.page = parameters.page;
  1665. this.viewport = parameters.viewport;
  1666. this.linkService = parameters.linkService;
  1667. this.container = this._createContainer();
  1668. }
  1669. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  1670. /**
  1671. * Create an empty container for the annotation's HTML element.
  1672. *
  1673. * @private
  1674. * @memberof AnnotationElement
  1675. * @returns {HTMLSectionElement}
  1676. */
  1677. _createContainer: function AnnotationElement_createContainer() {
  1678. var data = this.data, page = this.page, viewport = this.viewport;
  1679. var container = document.createElement('section');
  1680. var width = data.rect[2] - data.rect[0];
  1681. var height = data.rect[3] - data.rect[1];
  1682. container.setAttribute('data-annotation-id', data.id);
  1683. // Do *not* modify `data.rect`, since that will corrupt the annotation
  1684. // position on subsequent calls to `_createContainer` (see issue 6804).
  1685. var rect = Util.normalizeRect([
  1686. data.rect[0],
  1687. page.view[3] - data.rect[1] + page.view[1],
  1688. data.rect[2],
  1689. page.view[3] - data.rect[3] + page.view[1]
  1690. ]);
  1691. CustomStyle.setProp('transform', container,
  1692. 'matrix(' + viewport.transform.join(',') + ')');
  1693. CustomStyle.setProp('transformOrigin', container,
  1694. -rect[0] + 'px ' + -rect[1] + 'px');
  1695. if (data.borderStyle.width > 0) {
  1696. container.style.borderWidth = data.borderStyle.width + 'px';
  1697. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  1698. // Underline styles only have a bottom border, so we do not need
  1699. // to adjust for all borders. This yields a similar result as
  1700. // Adobe Acrobat/Reader.
  1701. width = width - 2 * data.borderStyle.width;
  1702. height = height - 2 * data.borderStyle.width;
  1703. }
  1704. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  1705. var verticalRadius = data.borderStyle.verticalCornerRadius;
  1706. if (horizontalRadius > 0 || verticalRadius > 0) {
  1707. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  1708. CustomStyle.setProp('borderRadius', container, radius);
  1709. }
  1710. switch (data.borderStyle.style) {
  1711. case AnnotationBorderStyleType.SOLID:
  1712. container.style.borderStyle = 'solid';
  1713. break;
  1714. case AnnotationBorderStyleType.DASHED:
  1715. container.style.borderStyle = 'dashed';
  1716. break;
  1717. case AnnotationBorderStyleType.BEVELED:
  1718. warn('Unimplemented border style: beveled');
  1719. break;
  1720. case AnnotationBorderStyleType.INSET:
  1721. warn('Unimplemented border style: inset');
  1722. break;
  1723. case AnnotationBorderStyleType.UNDERLINE:
  1724. container.style.borderBottomStyle = 'solid';
  1725. break;
  1726. default:
  1727. break;
  1728. }
  1729. if (data.color) {
  1730. container.style.borderColor =
  1731. Util.makeCssRgb(data.color[0] | 0,
  1732. data.color[1] | 0,
  1733. data.color[2] | 0);
  1734. } else {
  1735. // Transparent (invisible) border, so do not draw it at all.
  1736. container.style.borderWidth = 0;
  1737. }
  1738. }
  1739. container.style.left = rect[0] + 'px';
  1740. container.style.top = rect[1] + 'px';
  1741. container.style.width = width + 'px';
  1742. container.style.height = height + 'px';
  1743. return container;
  1744. },
  1745. /**
  1746. * Render the annotation's HTML element in the empty container.
  1747. *
  1748. * @public
  1749. * @memberof AnnotationElement
  1750. */
  1751. render: function AnnotationElement_render() {
  1752. throw new Error('Abstract method AnnotationElement.render called');
  1753. }
  1754. };
  1755. return AnnotationElement;
  1756. })();
  1757. /**
  1758. * @class
  1759. * @alias LinkAnnotationElement
  1760. */
  1761. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  1762. function LinkAnnotationElement(parameters) {
  1763. AnnotationElement.call(this, parameters);
  1764. }
  1765. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  1766. /**
  1767. * Render the link annotation's HTML element in the empty container.
  1768. *
  1769. * @public
  1770. * @memberof LinkAnnotationElement
  1771. * @returns {HTMLSectionElement}
  1772. */
  1773. render: function LinkAnnotationElement_render() {
  1774. this.container.className = 'linkAnnotation';
  1775. var link = document.createElement('a');
  1776. link.href = link.title = this.data.url || '';
  1777. if (this.data.url && isExternalLinkTargetSet()) {
  1778. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  1779. }
  1780. // Strip referrer from the URL.
  1781. if (this.data.url) {
  1782. link.rel = PDFJS.externalLinkRel;
  1783. }
  1784. if (!this.data.url) {
  1785. if (this.data.action) {
  1786. this._bindNamedAction(link, this.data.action);
  1787. } else {
  1788. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  1789. }
  1790. }
  1791. this.container.appendChild(link);
  1792. return this.container;
  1793. },
  1794. /**
  1795. * Bind internal links to the link element.
  1796. *
  1797. * @private
  1798. * @param {Object} link
  1799. * @param {Object} destination
  1800. * @memberof LinkAnnotationElement
  1801. */
  1802. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  1803. var self = this;
  1804. link.href = this.linkService.getDestinationHash(destination);
  1805. link.onclick = function() {
  1806. if (destination) {
  1807. self.linkService.navigateTo(destination);
  1808. }
  1809. return false;
  1810. };
  1811. if (destination) {
  1812. link.className = 'internalLink';
  1813. }
  1814. },
  1815. /**
  1816. * Bind named actions to the link element.
  1817. *
  1818. * @private
  1819. * @param {Object} link
  1820. * @param {Object} action
  1821. * @memberof LinkAnnotationElement
  1822. */
  1823. _bindNamedAction:
  1824. function LinkAnnotationElement_bindNamedAction(link, action) {
  1825. var self = this;
  1826. link.href = this.linkService.getAnchorUrl('');
  1827. link.onclick = function() {
  1828. self.linkService.executeNamedAction(action);
  1829. return false;
  1830. };
  1831. link.className = 'internalLink';
  1832. }
  1833. });
  1834. return LinkAnnotationElement;
  1835. })();
  1836. /**
  1837. * @class
  1838. * @alias TextAnnotationElement
  1839. */
  1840. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  1841. function TextAnnotationElement(parameters) {
  1842. AnnotationElement.call(this, parameters);
  1843. }
  1844. Util.inherit(TextAnnotationElement, AnnotationElement, {
  1845. /**
  1846. * Render the text annotation's HTML element in the empty container.
  1847. *
  1848. * @public
  1849. * @memberof TextAnnotationElement
  1850. * @returns {HTMLSectionElement}
  1851. */
  1852. render: function TextAnnotationElement_render() {
  1853. this.container.className = 'textAnnotation';
  1854. var image = document.createElement('img');
  1855. image.style.height = this.container.style.height;
  1856. image.style.width = this.container.style.width;
  1857. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  1858. this.data.name.toLowerCase() + '.svg';
  1859. image.alt = '[{{type}} Annotation]';
  1860. image.dataset.l10nId = 'text_annotation_type';
  1861. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  1862. if (!this.data.hasPopup) {
  1863. var popupElement = new PopupElement({
  1864. parentContainer: this.container,
  1865. parentTrigger: image,
  1866. color: this.data.color,
  1867. title: this.data.title,
  1868. contents: this.data.contents
  1869. });
  1870. var popup = popupElement.render();
  1871. // Position the popup next to the Text annotation's container.
  1872. popup.style.left = image.style.width;
  1873. this.container.appendChild(popup);
  1874. }
  1875. this.container.appendChild(image);
  1876. return this.container;
  1877. }
  1878. });
  1879. return TextAnnotationElement;
  1880. })();
  1881. /**
  1882. * @class
  1883. * @alias WidgetAnnotationElement
  1884. */
  1885. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  1886. function WidgetAnnotationElement(parameters) {
  1887. AnnotationElement.call(this, parameters);
  1888. }
  1889. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  1890. /**
  1891. * Render the widget annotation's HTML element in the empty container.
  1892. *
  1893. * @public
  1894. * @memberof WidgetAnnotationElement
  1895. * @returns {HTMLSectionElement}
  1896. */
  1897. render: function WidgetAnnotationElement_render() {
  1898. var content = document.createElement('div');
  1899. content.textContent = this.data.fieldValue;
  1900. var textAlignment = this.data.textAlignment;
  1901. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  1902. content.style.verticalAlign = 'middle';
  1903. content.style.display = 'table-cell';
  1904. var font = (this.data.fontRefName ?
  1905. this.page.commonObjs.getData(this.data.fontRefName) : null);
  1906. this._setTextStyle(content, font);
  1907. this.container.appendChild(content);
  1908. return this.container;
  1909. },
  1910. /**
  1911. * Apply text styles to the text in the element.
  1912. *
  1913. * @private
  1914. * @param {HTMLDivElement} element
  1915. * @param {Object} font
  1916. * @memberof WidgetAnnotationElement
  1917. */
  1918. _setTextStyle:
  1919. function WidgetAnnotationElement_setTextStyle(element, font) {
  1920. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  1921. var style = element.style;
  1922. style.fontSize = this.data.fontSize + 'px';
  1923. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  1924. if (!font) {
  1925. return;
  1926. }
  1927. style.fontWeight = (font.black ?
  1928. (font.bold ? '900' : 'bold') :
  1929. (font.bold ? 'bold' : 'normal'));
  1930. style.fontStyle = (font.italic ? 'italic' : 'normal');
  1931. // Use a reasonable default font if the font doesn't specify a fallback.
  1932. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  1933. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  1934. style.fontFamily = fontFamily + fallbackName;
  1935. }
  1936. });
  1937. return WidgetAnnotationElement;
  1938. })();
  1939. /**
  1940. * @class
  1941. * @alias PopupAnnotationElement
  1942. */
  1943. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  1944. function PopupAnnotationElement(parameters) {
  1945. AnnotationElement.call(this, parameters);
  1946. }
  1947. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  1948. /**
  1949. * Render the popup annotation's HTML element in the empty container.
  1950. *
  1951. * @public
  1952. * @memberof PopupAnnotationElement
  1953. * @returns {HTMLSectionElement}
  1954. */
  1955. render: function PopupAnnotationElement_render() {
  1956. this.container.className = 'popupAnnotation';
  1957. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  1958. var parentElement = this.layer.querySelector(selector);
  1959. if (!parentElement) {
  1960. return this.container;
  1961. }
  1962. var popup = new PopupElement({
  1963. parentContainer: parentElement,
  1964. parentTrigger: parentElement,
  1965. color: this.data.color,
  1966. title: this.data.title,
  1967. contents: this.data.contents
  1968. });
  1969. // Position the popup next to the parent annotation's container.
  1970. // PDF viewers ignore a popup annotation's rectangle.
  1971. var parentLeft = parseFloat(parentElement.style.left);
  1972. var parentWidth = parseFloat(parentElement.style.width);
  1973. CustomStyle.setProp('transformOrigin', this.container,
  1974. -(parentLeft + parentWidth) + 'px -' +
  1975. parentElement.style.top);
  1976. this.container.style.left = (parentLeft + parentWidth) + 'px';
  1977. this.container.appendChild(popup.render());
  1978. return this.container;
  1979. }
  1980. });
  1981. return PopupAnnotationElement;
  1982. })();
  1983. /**
  1984. * @class
  1985. * @alias PopupElement
  1986. */
  1987. var PopupElement = (function PopupElementClosure() {
  1988. var BACKGROUND_ENLIGHT = 0.7;
  1989. function PopupElement(parameters) {
  1990. this.parentContainer = parameters.parentContainer;
  1991. this.parentTrigger = parameters.parentTrigger;
  1992. this.color = parameters.color;
  1993. this.title = parameters.title;
  1994. this.contents = parameters.contents;
  1995. this.pinned = false;
  1996. }
  1997. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  1998. /**
  1999. * Render the popup's HTML element.
  2000. *
  2001. * @public
  2002. * @memberof PopupElement
  2003. * @returns {HTMLSectionElement}
  2004. */
  2005. render: function PopupElement_render() {
  2006. var wrapper = document.createElement('div');
  2007. wrapper.className = 'popupWrapper';
  2008. var popup = this.popup = document.createElement('div');
  2009. popup.className = 'popup';
  2010. popup.setAttribute('hidden', true);
  2011. var color = this.color;
  2012. if (color) {
  2013. // Enlighten the color.
  2014. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  2015. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  2016. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  2017. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  2018. }
  2019. var contents = this._formatContents(this.contents);
  2020. var title = document.createElement('h1');
  2021. title.textContent = this.title;
  2022. // Attach the event listeners to the trigger element.
  2023. var trigger = this.parentTrigger;
  2024. trigger.addEventListener('click', this._toggle.bind(this));
  2025. trigger.addEventListener('mouseover', this._show.bind(this, false));
  2026. trigger.addEventListener('mouseout', this._hide.bind(this, false));
  2027. popup.addEventListener('click', this._hide.bind(this, true));
  2028. popup.appendChild(title);
  2029. popup.appendChild(contents);
  2030. wrapper.appendChild(popup);
  2031. return wrapper;
  2032. },
  2033. /**
  2034. * Format the contents of the popup by adding newlines where necessary.
  2035. *
  2036. * @private
  2037. * @param {string} contents
  2038. * @memberof PopupElement
  2039. * @returns {HTMLParagraphElement}
  2040. */
  2041. _formatContents: function PopupElement_formatContents(contents) {
  2042. var p = document.createElement('p');
  2043. var lines = contents.split(/(?:\r\n?|\n)/);
  2044. for (var i = 0, ii = lines.length; i < ii; ++i) {
  2045. var line = lines[i];
  2046. p.appendChild(document.createTextNode(line));
  2047. if (i < (ii - 1)) {
  2048. p.appendChild(document.createElement('br'));
  2049. }
  2050. }
  2051. return p;
  2052. },
  2053. /**
  2054. * Toggle the visibility of the popup.
  2055. *
  2056. * @private
  2057. * @memberof PopupElement
  2058. */
  2059. _toggle: function PopupElement_toggle() {
  2060. if (this.pinned) {
  2061. this._hide(true);
  2062. } else {
  2063. this._show(true);
  2064. }
  2065. },
  2066. /**
  2067. * Show the popup.
  2068. *
  2069. * @private
  2070. * @param {boolean} pin
  2071. * @memberof PopupElement
  2072. */
  2073. _show: function PopupElement_show(pin) {
  2074. if (pin) {
  2075. this.pinned = true;
  2076. }
  2077. if (this.popup.hasAttribute('hidden')) {
  2078. this.popup.removeAttribute('hidden');
  2079. this.parentContainer.style.zIndex += 1;
  2080. }
  2081. },
  2082. /**
  2083. * Hide the popup.
  2084. *
  2085. * @private
  2086. * @param {boolean} unpin
  2087. * @memberof PopupElement
  2088. */
  2089. _hide: function PopupElement_hide(unpin) {
  2090. if (unpin) {
  2091. this.pinned = false;
  2092. }
  2093. if (!this.popup.hasAttribute('hidden') && !this.pinned) {
  2094. this.popup.setAttribute('hidden', true);
  2095. this.parentContainer.style.zIndex -= 1;
  2096. }
  2097. }
  2098. };
  2099. return PopupElement;
  2100. })();
  2101. /**
  2102. * @typedef {Object} AnnotationLayerParameters
  2103. * @property {PageViewport} viewport
  2104. * @property {HTMLDivElement} div
  2105. * @property {Array} annotations
  2106. * @property {PDFPage} page
  2107. * @property {IPDFLinkService} linkService
  2108. */
  2109. /**
  2110. * @class
  2111. * @alias AnnotationLayer
  2112. */
  2113. var AnnotationLayer = (function AnnotationLayerClosure() {
  2114. return {
  2115. /**
  2116. * Render a new annotation layer with all annotation elements.
  2117. *
  2118. * @public
  2119. * @param {AnnotationLayerParameters} parameters
  2120. * @memberof AnnotationLayer
  2121. */
  2122. render: function AnnotationLayer_render(parameters) {
  2123. var annotationElementFactory = new AnnotationElementFactory();
  2124. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  2125. var data = parameters.annotations[i];
  2126. if (!data || !data.hasHtml) {
  2127. continue;
  2128. }
  2129. var properties = {
  2130. data: data,
  2131. layer: parameters.div,
  2132. page: parameters.page,
  2133. viewport: parameters.viewport,
  2134. linkService: parameters.linkService
  2135. };
  2136. var element = annotationElementFactory.create(properties);
  2137. parameters.div.appendChild(element.render());
  2138. }
  2139. },
  2140. /**
  2141. * Update the annotation elements on existing annotation layer.
  2142. *
  2143. * @public
  2144. * @param {AnnotationLayerParameters} parameters
  2145. * @memberof AnnotationLayer
  2146. */
  2147. update: function AnnotationLayer_update(parameters) {
  2148. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  2149. var data = parameters.annotations[i];
  2150. var element = parameters.div.querySelector(
  2151. '[data-annotation-id="' + data.id + '"]');
  2152. if (element) {
  2153. CustomStyle.setProp('transform', element,
  2154. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  2155. }
  2156. }
  2157. parameters.div.removeAttribute('hidden');
  2158. }
  2159. };
  2160. })();
  2161. PDFJS.AnnotationLayer = AnnotationLayer;
  2162. exports.AnnotationLayer = AnnotationLayer;
  2163. }));
  2164. (function (root, factory) {
  2165. {
  2166. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  2167. root.pdfjsSharedGlobal);
  2168. }
  2169. }(this, function (exports, sharedUtil, sharedGlobal) {
  2170. var assert = sharedUtil.assert;
  2171. var bytesToString = sharedUtil.bytesToString;
  2172. var string32 = sharedUtil.string32;
  2173. var shadow = sharedUtil.shadow;
  2174. var warn = sharedUtil.warn;
  2175. var PDFJS = sharedGlobal.PDFJS;
  2176. var globalScope = sharedGlobal.globalScope;
  2177. var isWorker = sharedGlobal.isWorker;
  2178. function FontLoader(docId) {
  2179. this.docId = docId;
  2180. this.styleElement = null;
  2181. this.nativeFontFaces = [];
  2182. this.loadTestFontId = 0;
  2183. this.loadingContext = {
  2184. requests: [],
  2185. nextRequestId: 0
  2186. };
  2187. }
  2188. FontLoader.prototype = {
  2189. insertRule: function fontLoaderInsertRule(rule) {
  2190. var styleElement = this.styleElement;
  2191. if (!styleElement) {
  2192. styleElement = this.styleElement = document.createElement('style');
  2193. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  2194. document.documentElement.getElementsByTagName('head')[0].appendChild(
  2195. styleElement);
  2196. }
  2197. var styleSheet = styleElement.sheet;
  2198. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  2199. },
  2200. clear: function fontLoaderClear() {
  2201. var styleElement = this.styleElement;
  2202. if (styleElement) {
  2203. styleElement.parentNode.removeChild(styleElement);
  2204. styleElement = this.styleElement = null;
  2205. }
  2206. this.nativeFontFaces.forEach(function(nativeFontFace) {
  2207. document.fonts.delete(nativeFontFace);
  2208. });
  2209. this.nativeFontFaces.length = 0;
  2210. },
  2211. get loadTestFont() {
  2212. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  2213. // height.
  2214. return shadow(this, 'loadTestFont', atob(
  2215. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  2216. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  2217. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  2218. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  2219. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  2220. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  2221. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  2222. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  2223. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  2224. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  2225. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  2226. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  2227. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  2228. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  2229. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  2230. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  2231. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  2232. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  2233. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  2234. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  2235. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  2236. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  2237. ));
  2238. },
  2239. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  2240. this.nativeFontFaces.push(nativeFontFace);
  2241. document.fonts.add(nativeFontFace);
  2242. },
  2243. bind: function fontLoaderBind(fonts, callback) {
  2244. assert(!isWorker, 'bind() shall be called from main thread');
  2245. var rules = [];
  2246. var fontsToLoad = [];
  2247. var fontLoadPromises = [];
  2248. var getNativeFontPromise = function(nativeFontFace) {
  2249. // Return a promise that is always fulfilled, even when the font fails to
  2250. // load.
  2251. return nativeFontFace.loaded.catch(function(e) {
  2252. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  2253. });
  2254. };
  2255. for (var i = 0, ii = fonts.length; i < ii; i++) {
  2256. var font = fonts[i];
  2257. // Add the font to the DOM only once or skip if the font
  2258. // is already loaded.
  2259. if (font.attached || font.loading === false) {
  2260. continue;
  2261. }
  2262. font.attached = true;
  2263. if (FontLoader.isFontLoadingAPISupported) {
  2264. var nativeFontFace = font.createNativeFontFace();
  2265. if (nativeFontFace) {
  2266. this.addNativeFontFace(nativeFontFace);
  2267. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  2268. }
  2269. } else {
  2270. var rule = font.createFontFaceRule();
  2271. if (rule) {
  2272. this.insertRule(rule);
  2273. rules.push(rule);
  2274. fontsToLoad.push(font);
  2275. }
  2276. }
  2277. }
  2278. var request = this.queueLoadingCallback(callback);
  2279. if (FontLoader.isFontLoadingAPISupported) {
  2280. Promise.all(fontLoadPromises).then(function() {
  2281. request.complete();
  2282. });
  2283. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  2284. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  2285. } else {
  2286. request.complete();
  2287. }
  2288. },
  2289. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  2290. function LoadLoader_completeRequest() {
  2291. assert(!request.end, 'completeRequest() cannot be called twice');
  2292. request.end = Date.now();
  2293. // sending all completed requests in order how they were queued
  2294. while (context.requests.length > 0 && context.requests[0].end) {
  2295. var otherRequest = context.requests.shift();
  2296. setTimeout(otherRequest.callback, 0);
  2297. }
  2298. }
  2299. var context = this.loadingContext;
  2300. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  2301. var request = {
  2302. id: requestId,
  2303. complete: LoadLoader_completeRequest,
  2304. callback: callback,
  2305. started: Date.now()
  2306. };
  2307. context.requests.push(request);
  2308. return request;
  2309. },
  2310. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  2311. fonts,
  2312. request) {
  2313. /** Hack begin */
  2314. // There's currently no event when a font has finished downloading so the
  2315. // following code is a dirty hack to 'guess' when a font is
  2316. // ready. It's assumed fonts are loaded in order, so add a known test
  2317. // font after the desired fonts and then test for the loading of that
  2318. // test font.
  2319. function int32(data, offset) {
  2320. return (data.charCodeAt(offset) << 24) |
  2321. (data.charCodeAt(offset + 1) << 16) |
  2322. (data.charCodeAt(offset + 2) << 8) |
  2323. (data.charCodeAt(offset + 3) & 0xff);
  2324. }
  2325. function spliceString(s, offset, remove, insert) {
  2326. var chunk1 = s.substr(0, offset);
  2327. var chunk2 = s.substr(offset + remove);
  2328. return chunk1 + insert + chunk2;
  2329. }
  2330. var i, ii;
  2331. var canvas = document.createElement('canvas');
  2332. canvas.width = 1;
  2333. canvas.height = 1;
  2334. var ctx = canvas.getContext('2d');
  2335. var called = 0;
  2336. function isFontReady(name, callback) {
  2337. called++;
  2338. // With setTimeout clamping this gives the font ~100ms to load.
  2339. if(called > 30) {
  2340. warn('Load test font never loaded.');
  2341. callback();
  2342. return;
  2343. }
  2344. ctx.font = '30px ' + name;
  2345. ctx.fillText('.', 0, 20);
  2346. var imageData = ctx.getImageData(0, 0, 1, 1);
  2347. if (imageData.data[3] > 0) {
  2348. callback();
  2349. return;
  2350. }
  2351. setTimeout(isFontReady.bind(null, name, callback));
  2352. }
  2353. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  2354. // Chromium seems to cache fonts based on a hash of the actual font data,
  2355. // so the font must be modified for each load test else it will appear to
  2356. // be loaded already.
  2357. // TODO: This could maybe be made faster by avoiding the btoa of the full
  2358. // font by splitting it in chunks before hand and padding the font id.
  2359. var data = this.loadTestFont;
  2360. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  2361. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  2362. loadTestFontId);
  2363. // CFF checksum is important for IE, adjusting it
  2364. var CFF_CHECKSUM_OFFSET = 16;
  2365. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  2366. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  2367. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  2368. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  2369. }
  2370. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  2371. checksum = (checksum - XXXX_VALUE +
  2372. int32(loadTestFontId + 'XXX', i)) | 0;
  2373. }
  2374. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  2375. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  2376. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  2377. url + '}';
  2378. this.insertRule(rule);
  2379. var names = [];
  2380. for (i = 0, ii = fonts.length; i < ii; i++) {
  2381. names.push(fonts[i].loadedName);
  2382. }
  2383. names.push(loadTestFontId);
  2384. var div = document.createElement('div');
  2385. div.setAttribute('style',
  2386. 'visibility: hidden;' +
  2387. 'width: 10px; height: 10px;' +
  2388. 'position: absolute; top: 0px; left: 0px;');
  2389. for (i = 0, ii = names.length; i < ii; ++i) {
  2390. var span = document.createElement('span');
  2391. span.textContent = 'Hi';
  2392. span.style.fontFamily = names[i];
  2393. div.appendChild(span);
  2394. }
  2395. document.body.appendChild(div);
  2396. isFontReady(loadTestFontId, function() {
  2397. document.body.removeChild(div);
  2398. request.complete();
  2399. });
  2400. /** Hack end */
  2401. }
  2402. };
  2403. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  2404. typeof document !== 'undefined' && !!document.fonts);
  2405. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  2406. get: function () {
  2407. var supported = false;
  2408. // User agent string sniffing is bad, but there is no reliable way to tell
  2409. // if font is fully loaded and ready to be used with canvas.
  2410. var userAgent = window.navigator.userAgent;
  2411. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  2412. if (m && m[1] >= 14) {
  2413. supported = true;
  2414. }
  2415. // TODO other browsers
  2416. if (userAgent === 'node') {
  2417. supported = true;
  2418. }
  2419. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  2420. },
  2421. enumerable: true,
  2422. configurable: true
  2423. });
  2424. var FontFaceObject = (function FontFaceObjectClosure() {
  2425. function FontFaceObject(translatedData) {
  2426. this.compiledGlyphs = {};
  2427. // importing translated data
  2428. for (var i in translatedData) {
  2429. this[i] = translatedData[i];
  2430. }
  2431. }
  2432. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  2433. get: function () {
  2434. var evalSupport = false;
  2435. if (PDFJS.isEvalSupported) {
  2436. try {
  2437. /* jshint evil: true */
  2438. new Function('');
  2439. evalSupport = true;
  2440. } catch (e) {}
  2441. }
  2442. return shadow(this, 'isEvalSupported', evalSupport);
  2443. },
  2444. enumerable: true,
  2445. configurable: true
  2446. });
  2447. FontFaceObject.prototype = {
  2448. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  2449. if (!this.data) {
  2450. return null;
  2451. }
  2452. if (PDFJS.disableFontFace) {
  2453. this.disableFontFace = true;
  2454. return null;
  2455. }
  2456. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  2457. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  2458. globalScope['FontInspector'].enabled) {
  2459. globalScope['FontInspector'].fontAdded(this);
  2460. }
  2461. return nativeFontFace;
  2462. },
  2463. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  2464. if (!this.data) {
  2465. return null;
  2466. }
  2467. if (PDFJS.disableFontFace) {
  2468. this.disableFontFace = true;
  2469. return null;
  2470. }
  2471. var data = bytesToString(new Uint8Array(this.data));
  2472. var fontName = this.loadedName;
  2473. // Add the font-face rule to the document
  2474. var url = ('url(data:' + this.mimetype + ';base64,' +
  2475. window.btoa(data) + ');');
  2476. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  2477. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  2478. globalScope['FontInspector'].enabled) {
  2479. globalScope['FontInspector'].fontAdded(this, url);
  2480. }
  2481. return rule;
  2482. },
  2483. getPathGenerator:
  2484. function FontFaceObject_getPathGenerator(objs, character) {
  2485. if (!(character in this.compiledGlyphs)) {
  2486. var cmds = objs.get(this.loadedName + '_path_' + character);
  2487. var current, i, len;
  2488. // If we can, compile cmds into JS for MAXIMUM SPEED
  2489. if (FontFaceObject.isEvalSupported) {
  2490. var args, js = '';
  2491. for (i = 0, len = cmds.length; i < len; i++) {
  2492. current = cmds[i];
  2493. if (current.args !== undefined) {
  2494. args = current.args.join(',');
  2495. } else {
  2496. args = '';
  2497. }
  2498. js += 'c.' + current.cmd + '(' + args + ');\n';
  2499. }
  2500. /* jshint -W054 */
  2501. this.compiledGlyphs[character] = new Function('c', 'size', js);
  2502. } else {
  2503. // But fall back on using Function.prototype.apply() if we're
  2504. // blocked from using eval() for whatever reason (like CSP policies)
  2505. this.compiledGlyphs[character] = function(c, size) {
  2506. for (i = 0, len = cmds.length; i < len; i++) {
  2507. current = cmds[i];
  2508. if (current.cmd === 'scale') {
  2509. current.args = [size, -size];
  2510. }
  2511. c[current.cmd].apply(c, current.args);
  2512. }
  2513. };
  2514. }
  2515. }
  2516. return this.compiledGlyphs[character];
  2517. }
  2518. };
  2519. return FontFaceObject;
  2520. })();
  2521. exports.FontFaceObject = FontFaceObject;
  2522. exports.FontLoader = FontLoader;
  2523. }));
  2524. (function (root, factory) {
  2525. {
  2526. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  2527. }
  2528. }(this, function (exports, sharedUtil) {
  2529. var error = sharedUtil.error;
  2530. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2531. function fixMetadata(meta) {
  2532. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2533. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2534. function(code, d1, d2, d3) {
  2535. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2536. });
  2537. var chars = '';
  2538. for (var i = 0; i < bytes.length; i += 2) {
  2539. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2540. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2541. code !== 38 && false ? String.fromCharCode(code) :
  2542. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2543. }
  2544. return '>' + chars;
  2545. });
  2546. }
  2547. function Metadata(meta) {
  2548. if (typeof meta === 'string') {
  2549. // Ghostscript produces invalid metadata
  2550. meta = fixMetadata(meta);
  2551. var parser = new DOMParser();
  2552. meta = parser.parseFromString(meta, 'application/xml');
  2553. } else if (!(meta instanceof Document)) {
  2554. error('Metadata: Invalid metadata object');
  2555. }
  2556. this.metaDocument = meta;
  2557. this.metadata = {};
  2558. this.parse();
  2559. }
  2560. Metadata.prototype = {
  2561. parse: function Metadata_parse() {
  2562. var doc = this.metaDocument;
  2563. var rdf = doc.documentElement;
  2564. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2565. rdf = rdf.firstChild;
  2566. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2567. rdf = rdf.nextSibling;
  2568. }
  2569. }
  2570. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2571. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2572. return;
  2573. }
  2574. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2575. for (i = 0, length = children.length; i < length; i++) {
  2576. desc = children[i];
  2577. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2578. continue;
  2579. }
  2580. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2581. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2582. entry = desc.childNodes[ii];
  2583. name = entry.nodeName.toLowerCase();
  2584. this.metadata[name] = entry.textContent.trim();
  2585. }
  2586. }
  2587. }
  2588. },
  2589. get: function Metadata_get(name) {
  2590. return this.metadata[name] || null;
  2591. },
  2592. has: function Metadata_has(name) {
  2593. return typeof this.metadata[name] !== 'undefined';
  2594. }
  2595. };
  2596. return Metadata;
  2597. })();
  2598. exports.Metadata = Metadata;
  2599. }));
  2600. (function (root, factory) {
  2601. {
  2602. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil);
  2603. }
  2604. }(this, function (exports, sharedUtil) {
  2605. var createPromiseCapability = sharedUtil.createPromiseCapability;
  2606. /**
  2607. * Text layer render parameters.
  2608. *
  2609. * @typedef {Object} TextLayerRenderParameters
  2610. * @property {TextContent} textContent - Text content to render (the object is
  2611. * returned by the page's getTextContent() method).
  2612. * @property {HTMLElement} container - HTML element that will contain text runs.
  2613. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  2614. * layout the text runs.
  2615. * @property {Array} textDivs - (optional) HTML elements that are correspond
  2616. * the text items of the textContent input. This is output and shall be
  2617. * initially be set to empty array.
  2618. * @property {number} timeout - (optional) Delay in milliseconds before
  2619. * rendering of the text runs occurs.
  2620. */
  2621. var renderTextLayer = (function renderTextLayerClosure() {
  2622. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  2623. var NonWhitespaceRegexp = /\S/;
  2624. function isAllWhitespace(str) {
  2625. return !NonWhitespaceRegexp.test(str);
  2626. }
  2627. function appendText(textDivs, viewport, geom, styles) {
  2628. var style = styles[geom.fontName];
  2629. var textDiv = document.createElement('div');
  2630. textDivs.push(textDiv);
  2631. if (isAllWhitespace(geom.str)) {
  2632. textDiv.dataset.isWhitespace = true;
  2633. return;
  2634. }
  2635. var tx = PDFJS.Util.transform(viewport.transform, geom.transform);
  2636. var angle = Math.atan2(tx[1], tx[0]);
  2637. if (style.vertical) {
  2638. angle += Math.PI / 2;
  2639. }
  2640. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  2641. var fontAscent = fontHeight;
  2642. if (style.ascent) {
  2643. fontAscent = style.ascent * fontAscent;
  2644. } else if (style.descent) {
  2645. fontAscent = (1 + style.descent) * fontAscent;
  2646. }
  2647. var left;
  2648. var top;
  2649. if (angle === 0) {
  2650. left = tx[4];
  2651. top = tx[5] - fontAscent;
  2652. } else {
  2653. left = tx[4] + (fontAscent * Math.sin(angle));
  2654. top = tx[5] - (fontAscent * Math.cos(angle));
  2655. }
  2656. textDiv.style.left = left + 'px';
  2657. textDiv.style.top = top + 'px';
  2658. textDiv.style.fontSize = fontHeight + 'px';
  2659. textDiv.style.fontFamily = style.fontFamily;
  2660. textDiv.textContent = geom.str;
  2661. // |fontName| is only used by the Font Inspector. This test will succeed
  2662. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  2663. // not worth the effort to do a more accurate test.
  2664. if (PDFJS.pdfBug) {
  2665. textDiv.dataset.fontName = geom.fontName;
  2666. }
  2667. // Storing into dataset will convert number into string.
  2668. if (angle !== 0) {
  2669. textDiv.dataset.angle = angle * (180 / Math.PI);
  2670. }
  2671. // We don't bother scaling single-char text divs, because it has very
  2672. // little effect on text highlighting. This makes scrolling on docs with
  2673. // lots of such divs a lot faster.
  2674. if (geom.str.length > 1) {
  2675. if (style.vertical) {
  2676. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  2677. } else {
  2678. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  2679. }
  2680. }
  2681. }
  2682. function render(task) {
  2683. if (task._canceled) {
  2684. return;
  2685. }
  2686. var textLayerFrag = task._container;
  2687. var textDivs = task._textDivs;
  2688. var capability = task._capability;
  2689. var textDivsLength = textDivs.length;
  2690. // No point in rendering many divs as it would make the browser
  2691. // unusable even after the divs are rendered.
  2692. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  2693. capability.resolve();
  2694. return;
  2695. }
  2696. var canvas = document.createElement('canvas');
  2697. var ctx = canvas.getContext('2d', {alpha: false});
  2698. var lastFontSize;
  2699. var lastFontFamily;
  2700. for (var i = 0; i < textDivsLength; i++) {
  2701. var textDiv = textDivs[i];
  2702. if (textDiv.dataset.isWhitespace !== undefined) {
  2703. continue;
  2704. }
  2705. var fontSize = textDiv.style.fontSize;
  2706. var fontFamily = textDiv.style.fontFamily;
  2707. // Only build font string and set to context if different from last.
  2708. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  2709. ctx.font = fontSize + ' ' + fontFamily;
  2710. lastFontSize = fontSize;
  2711. lastFontFamily = fontFamily;
  2712. }
  2713. var width = ctx.measureText(textDiv.textContent).width;
  2714. if (width > 0) {
  2715. textLayerFrag.appendChild(textDiv);
  2716. var transform;
  2717. if (textDiv.dataset.canvasWidth !== undefined) {
  2718. // Dataset values come of type string.
  2719. var textScale = textDiv.dataset.canvasWidth / width;
  2720. transform = 'scaleX(' + textScale + ')';
  2721. } else {
  2722. transform = '';
  2723. }
  2724. var rotation = textDiv.dataset.angle;
  2725. if (rotation) {
  2726. transform = 'rotate(' + rotation + 'deg) ' + transform;
  2727. }
  2728. if (transform) {
  2729. PDFJS.CustomStyle.setProp('transform' , textDiv, transform);
  2730. }
  2731. }
  2732. }
  2733. capability.resolve();
  2734. }
  2735. /**
  2736. * Text layer rendering task.
  2737. *
  2738. * @param {TextContent} textContent
  2739. * @param {HTMLElement} container
  2740. * @param {PDFJS.PageViewport} viewport
  2741. * @param {Array} textDivs
  2742. * @private
  2743. */
  2744. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  2745. this._textContent = textContent;
  2746. this._container = container;
  2747. this._viewport = viewport;
  2748. textDivs = textDivs || [];
  2749. this._textDivs = textDivs;
  2750. this._canceled = false;
  2751. this._capability = createPromiseCapability();
  2752. this._renderTimer = null;
  2753. }
  2754. TextLayerRenderTask.prototype = {
  2755. get promise() {
  2756. return this._capability.promise;
  2757. },
  2758. cancel: function TextLayer_cancel() {
  2759. this._canceled = true;
  2760. if (this._renderTimer !== null) {
  2761. clearTimeout(this._renderTimer);
  2762. this._renderTimer = null;
  2763. }
  2764. this._capability.reject('canceled');
  2765. },
  2766. _render: function TextLayer_render(timeout) {
  2767. var textItems = this._textContent.items;
  2768. var styles = this._textContent.styles;
  2769. var textDivs = this._textDivs;
  2770. var viewport = this._viewport;
  2771. for (var i = 0, len = textItems.length; i < len; i++) {
  2772. appendText(textDivs, viewport, textItems[i], styles);
  2773. }
  2774. if (!timeout) { // Render right away
  2775. render(this);
  2776. } else { // Schedule
  2777. var self = this;
  2778. this._renderTimer = setTimeout(function() {
  2779. render(self);
  2780. self._renderTimer = null;
  2781. }, timeout);
  2782. }
  2783. }
  2784. };
  2785. /**
  2786. * Starts rendering of the text layer.
  2787. *
  2788. * @param {TextLayerRenderParameters} renderParameters
  2789. * @returns {TextLayerRenderTask}
  2790. */
  2791. function renderTextLayer(renderParameters) {
  2792. var task = new TextLayerRenderTask(renderParameters.textContent,
  2793. renderParameters.container,
  2794. renderParameters.viewport,
  2795. renderParameters.textDivs);
  2796. task._render(renderParameters.timeout);
  2797. return task;
  2798. }
  2799. return renderTextLayer;
  2800. })();
  2801. PDFJS.renderTextLayer = renderTextLayer;
  2802. exports.renderTextLayer = renderTextLayer;
  2803. }));
  2804. (function (root, factory) {
  2805. {
  2806. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  2807. }
  2808. }(this, function (exports, sharedUtil) {
  2809. var shadow = sharedUtil.shadow;
  2810. var WebGLUtils = (function WebGLUtilsClosure() {
  2811. function loadShader(gl, code, shaderType) {
  2812. var shader = gl.createShader(shaderType);
  2813. gl.shaderSource(shader, code);
  2814. gl.compileShader(shader);
  2815. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  2816. if (!compiled) {
  2817. var errorMsg = gl.getShaderInfoLog(shader);
  2818. throw new Error('Error during shader compilation: ' + errorMsg);
  2819. }
  2820. return shader;
  2821. }
  2822. function createVertexShader(gl, code) {
  2823. return loadShader(gl, code, gl.VERTEX_SHADER);
  2824. }
  2825. function createFragmentShader(gl, code) {
  2826. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  2827. }
  2828. function createProgram(gl, shaders) {
  2829. var program = gl.createProgram();
  2830. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  2831. gl.attachShader(program, shaders[i]);
  2832. }
  2833. gl.linkProgram(program);
  2834. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  2835. if (!linked) {
  2836. var errorMsg = gl.getProgramInfoLog(program);
  2837. throw new Error('Error during program linking: ' + errorMsg);
  2838. }
  2839. return program;
  2840. }
  2841. function createTexture(gl, image, textureId) {
  2842. gl.activeTexture(textureId);
  2843. var texture = gl.createTexture();
  2844. gl.bindTexture(gl.TEXTURE_2D, texture);
  2845. // Set the parameters so we can render any size image.
  2846. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  2847. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  2848. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  2849. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  2850. // Upload the image into the texture.
  2851. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  2852. return texture;
  2853. }
  2854. var currentGL, currentCanvas;
  2855. function generateGL() {
  2856. if (currentGL) {
  2857. return;
  2858. }
  2859. currentCanvas = document.createElement('canvas');
  2860. currentGL = currentCanvas.getContext('webgl',
  2861. { premultipliedalpha: false });
  2862. }
  2863. var smaskVertexShaderCode = '\
  2864. attribute vec2 a_position; \
  2865. attribute vec2 a_texCoord; \
  2866. \
  2867. uniform vec2 u_resolution; \
  2868. \
  2869. varying vec2 v_texCoord; \
  2870. \
  2871. void main() { \
  2872. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  2873. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  2874. \
  2875. v_texCoord = a_texCoord; \
  2876. } ';
  2877. var smaskFragmentShaderCode = '\
  2878. precision mediump float; \
  2879. \
  2880. uniform vec4 u_backdrop; \
  2881. uniform int u_subtype; \
  2882. uniform sampler2D u_image; \
  2883. uniform sampler2D u_mask; \
  2884. \
  2885. varying vec2 v_texCoord; \
  2886. \
  2887. void main() { \
  2888. vec4 imageColor = texture2D(u_image, v_texCoord); \
  2889. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  2890. if (u_backdrop.a > 0.0) { \
  2891. maskColor.rgb = maskColor.rgb * maskColor.a + \
  2892. u_backdrop.rgb * (1.0 - maskColor.a); \
  2893. } \
  2894. float lum; \
  2895. if (u_subtype == 0) { \
  2896. lum = maskColor.a; \
  2897. } else { \
  2898. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  2899. maskColor.b * 0.11; \
  2900. } \
  2901. imageColor.a *= lum; \
  2902. imageColor.rgb *= imageColor.a; \
  2903. gl_FragColor = imageColor; \
  2904. } ';
  2905. var smaskCache = null;
  2906. function initSmaskGL() {
  2907. var canvas, gl;
  2908. generateGL();
  2909. canvas = currentCanvas;
  2910. currentCanvas = null;
  2911. gl = currentGL;
  2912. currentGL = null;
  2913. // setup a GLSL program
  2914. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  2915. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  2916. var program = createProgram(gl, [vertexShader, fragmentShader]);
  2917. gl.useProgram(program);
  2918. var cache = {};
  2919. cache.gl = gl;
  2920. cache.canvas = canvas;
  2921. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  2922. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  2923. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  2924. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  2925. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  2926. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  2927. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  2928. // provide texture coordinates for the rectangle.
  2929. var texCoordBuffer = gl.createBuffer();
  2930. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  2931. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  2932. 0.0, 0.0,
  2933. 1.0, 0.0,
  2934. 0.0, 1.0,
  2935. 0.0, 1.0,
  2936. 1.0, 0.0,
  2937. 1.0, 1.0]), gl.STATIC_DRAW);
  2938. gl.enableVertexAttribArray(texCoordLocation);
  2939. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  2940. gl.uniform1i(texLayerLocation, 0);
  2941. gl.uniform1i(texMaskLocation, 1);
  2942. smaskCache = cache;
  2943. }
  2944. function composeSMask(layer, mask, properties) {
  2945. var width = layer.width, height = layer.height;
  2946. if (!smaskCache) {
  2947. initSmaskGL();
  2948. }
  2949. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  2950. canvas.width = width;
  2951. canvas.height = height;
  2952. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  2953. gl.uniform2f(cache.resolutionLocation, width, height);
  2954. if (properties.backdrop) {
  2955. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  2956. properties.backdrop[1], properties.backdrop[2], 1);
  2957. } else {
  2958. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  2959. }
  2960. gl.uniform1i(cache.subtypeLocation,
  2961. properties.subtype === 'Luminosity' ? 1 : 0);
  2962. // Create a textures
  2963. var texture = createTexture(gl, layer, gl.TEXTURE0);
  2964. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  2965. // Create a buffer and put a single clipspace rectangle in
  2966. // it (2 triangles)
  2967. var buffer = gl.createBuffer();
  2968. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  2969. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  2970. 0, 0,
  2971. width, 0,
  2972. 0, height,
  2973. 0, height,
  2974. width, 0,
  2975. width, height]), gl.STATIC_DRAW);
  2976. gl.enableVertexAttribArray(cache.positionLocation);
  2977. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  2978. // draw
  2979. gl.clearColor(0, 0, 0, 0);
  2980. gl.enable(gl.BLEND);
  2981. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  2982. gl.clear(gl.COLOR_BUFFER_BIT);
  2983. gl.drawArrays(gl.TRIANGLES, 0, 6);
  2984. gl.flush();
  2985. gl.deleteTexture(texture);
  2986. gl.deleteTexture(maskTexture);
  2987. gl.deleteBuffer(buffer);
  2988. return canvas;
  2989. }
  2990. var figuresVertexShaderCode = '\
  2991. attribute vec2 a_position; \
  2992. attribute vec3 a_color; \
  2993. \
  2994. uniform vec2 u_resolution; \
  2995. uniform vec2 u_scale; \
  2996. uniform vec2 u_offset; \
  2997. \
  2998. varying vec4 v_color; \
  2999. \
  3000. void main() { \
  3001. vec2 position = (a_position + u_offset) * u_scale; \
  3002. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  3003. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  3004. \
  3005. v_color = vec4(a_color / 255.0, 1.0); \
  3006. } ';
  3007. var figuresFragmentShaderCode = '\
  3008. precision mediump float; \
  3009. \
  3010. varying vec4 v_color; \
  3011. \
  3012. void main() { \
  3013. gl_FragColor = v_color; \
  3014. } ';
  3015. var figuresCache = null;
  3016. function initFiguresGL() {
  3017. var canvas, gl;
  3018. generateGL();
  3019. canvas = currentCanvas;
  3020. currentCanvas = null;
  3021. gl = currentGL;
  3022. currentGL = null;
  3023. // setup a GLSL program
  3024. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  3025. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  3026. var program = createProgram(gl, [vertexShader, fragmentShader]);
  3027. gl.useProgram(program);
  3028. var cache = {};
  3029. cache.gl = gl;
  3030. cache.canvas = canvas;
  3031. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  3032. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  3033. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  3034. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  3035. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  3036. figuresCache = cache;
  3037. }
  3038. function drawFigures(width, height, backgroundColor, figures, context) {
  3039. if (!figuresCache) {
  3040. initFiguresGL();
  3041. }
  3042. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  3043. canvas.width = width;
  3044. canvas.height = height;
  3045. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  3046. gl.uniform2f(cache.resolutionLocation, width, height);
  3047. // count triangle points
  3048. var count = 0;
  3049. var i, ii, rows;
  3050. for (i = 0, ii = figures.length; i < ii; i++) {
  3051. switch (figures[i].type) {
  3052. case 'lattice':
  3053. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  3054. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  3055. break;
  3056. case 'triangles':
  3057. count += figures[i].coords.length;
  3058. break;
  3059. }
  3060. }
  3061. // transfer data
  3062. var coords = new Float32Array(count * 2);
  3063. var colors = new Uint8Array(count * 3);
  3064. var coordsMap = context.coords, colorsMap = context.colors;
  3065. var pIndex = 0, cIndex = 0;
  3066. for (i = 0, ii = figures.length; i < ii; i++) {
  3067. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  3068. switch (figure.type) {
  3069. case 'lattice':
  3070. var cols = figure.verticesPerRow;
  3071. rows = (ps.length / cols) | 0;
  3072. for (var row = 1; row < rows; row++) {
  3073. var offset = row * cols + 1;
  3074. for (var col = 1; col < cols; col++, offset++) {
  3075. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  3076. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  3077. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  3078. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  3079. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  3080. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  3081. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  3082. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  3083. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  3084. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  3085. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  3086. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  3087. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  3088. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  3089. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  3090. coords[pIndex + 6] = coords[pIndex + 2];
  3091. coords[pIndex + 7] = coords[pIndex + 3];
  3092. coords[pIndex + 8] = coords[pIndex + 4];
  3093. coords[pIndex + 9] = coords[pIndex + 5];
  3094. coords[pIndex + 10] = coordsMap[ps[offset]];
  3095. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  3096. colors[cIndex + 9] = colors[cIndex + 3];
  3097. colors[cIndex + 10] = colors[cIndex + 4];
  3098. colors[cIndex + 11] = colors[cIndex + 5];
  3099. colors[cIndex + 12] = colors[cIndex + 6];
  3100. colors[cIndex + 13] = colors[cIndex + 7];
  3101. colors[cIndex + 14] = colors[cIndex + 8];
  3102. colors[cIndex + 15] = colorsMap[cs[offset]];
  3103. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  3104. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  3105. pIndex += 12;
  3106. cIndex += 18;
  3107. }
  3108. }
  3109. break;
  3110. case 'triangles':
  3111. for (var j = 0, jj = ps.length; j < jj; j++) {
  3112. coords[pIndex] = coordsMap[ps[j]];
  3113. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  3114. colors[cIndex] = colorsMap[cs[j]];
  3115. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  3116. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  3117. pIndex += 2;
  3118. cIndex += 3;
  3119. }
  3120. break;
  3121. }
  3122. }
  3123. // draw
  3124. if (backgroundColor) {
  3125. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  3126. backgroundColor[2] / 255, 1.0);
  3127. } else {
  3128. gl.clearColor(0, 0, 0, 0);
  3129. }
  3130. gl.clear(gl.COLOR_BUFFER_BIT);
  3131. var coordsBuffer = gl.createBuffer();
  3132. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  3133. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  3134. gl.enableVertexAttribArray(cache.positionLocation);
  3135. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  3136. var colorsBuffer = gl.createBuffer();
  3137. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  3138. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  3139. gl.enableVertexAttribArray(cache.colorLocation);
  3140. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  3141. 0, 0);
  3142. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  3143. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  3144. gl.drawArrays(gl.TRIANGLES, 0, count);
  3145. gl.flush();
  3146. gl.deleteBuffer(coordsBuffer);
  3147. gl.deleteBuffer(colorsBuffer);
  3148. return canvas;
  3149. }
  3150. function cleanup() {
  3151. if (smaskCache && smaskCache.canvas) {
  3152. smaskCache.canvas.width = 0;
  3153. smaskCache.canvas.height = 0;
  3154. }
  3155. if (figuresCache && figuresCache.canvas) {
  3156. figuresCache.canvas.width = 0;
  3157. figuresCache.canvas.height = 0;
  3158. }
  3159. smaskCache = null;
  3160. figuresCache = null;
  3161. }
  3162. return {
  3163. get isEnabled() {
  3164. if (PDFJS.disableWebGL) {
  3165. return false;
  3166. }
  3167. var enabled = false;
  3168. try {
  3169. generateGL();
  3170. enabled = !!currentGL;
  3171. } catch (e) { }
  3172. return shadow(this, 'isEnabled', enabled);
  3173. },
  3174. composeSMask: composeSMask,
  3175. drawFigures: drawFigures,
  3176. clear: cleanup
  3177. };
  3178. })();
  3179. exports.WebGLUtils = WebGLUtils;
  3180. }));
  3181. (function (root, factory) {
  3182. {
  3183. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  3184. root.pdfjsDisplayWebGL);
  3185. }
  3186. }(this, function (exports, sharedUtil, displayWebGL) {
  3187. var Util = sharedUtil.Util;
  3188. var info = sharedUtil.info;
  3189. var isArray = sharedUtil.isArray;
  3190. var error = sharedUtil.error;
  3191. var WebGLUtils = displayWebGL.WebGLUtils;
  3192. var ShadingIRs = {};
  3193. ShadingIRs.RadialAxial = {
  3194. fromIR: function RadialAxial_fromIR(raw) {
  3195. var type = raw[1];
  3196. var colorStops = raw[2];
  3197. var p0 = raw[3];
  3198. var p1 = raw[4];
  3199. var r0 = raw[5];
  3200. var r1 = raw[6];
  3201. return {
  3202. type: 'Pattern',
  3203. getPattern: function RadialAxial_getPattern(ctx) {
  3204. var grad;
  3205. if (type === 'axial') {
  3206. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  3207. } else if (type === 'radial') {
  3208. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  3209. }
  3210. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  3211. var c = colorStops[i];
  3212. grad.addColorStop(c[0], c[1]);
  3213. }
  3214. return grad;
  3215. }
  3216. };
  3217. }
  3218. };
  3219. var createMeshCanvas = (function createMeshCanvasClosure() {
  3220. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  3221. // Very basic Gouraud-shaded triangle rasterization algorithm.
  3222. var coords = context.coords, colors = context.colors;
  3223. var bytes = data.data, rowSize = data.width * 4;
  3224. var tmp;
  3225. if (coords[p1 + 1] > coords[p2 + 1]) {
  3226. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  3227. }
  3228. if (coords[p2 + 1] > coords[p3 + 1]) {
  3229. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  3230. }
  3231. if (coords[p1 + 1] > coords[p2 + 1]) {
  3232. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  3233. }
  3234. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  3235. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  3236. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  3237. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  3238. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  3239. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  3240. if (y1 >= y3) {
  3241. return;
  3242. }
  3243. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  3244. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  3245. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  3246. var minY = Math.round(y1), maxY = Math.round(y3);
  3247. var xa, car, cag, cab;
  3248. var xb, cbr, cbg, cbb;
  3249. var k;
  3250. for (var y = minY; y <= maxY; y++) {
  3251. if (y < y2) {
  3252. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  3253. xa = x1 - (x1 - x2) * k;
  3254. car = c1r - (c1r - c2r) * k;
  3255. cag = c1g - (c1g - c2g) * k;
  3256. cab = c1b - (c1b - c2b) * k;
  3257. } else {
  3258. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  3259. xa = x2 - (x2 - x3) * k;
  3260. car = c2r - (c2r - c3r) * k;
  3261. cag = c2g - (c2g - c3g) * k;
  3262. cab = c2b - (c2b - c3b) * k;
  3263. }
  3264. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  3265. xb = x1 - (x1 - x3) * k;
  3266. cbr = c1r - (c1r - c3r) * k;
  3267. cbg = c1g - (c1g - c3g) * k;
  3268. cbb = c1b - (c1b - c3b) * k;
  3269. var x1_ = Math.round(Math.min(xa, xb));
  3270. var x2_ = Math.round(Math.max(xa, xb));
  3271. var j = rowSize * y + x1_ * 4;
  3272. for (var x = x1_; x <= x2_; x++) {
  3273. k = (xa - x) / (xa - xb);
  3274. k = k < 0 ? 0 : k > 1 ? 1 : k;
  3275. bytes[j++] = (car - (car - cbr) * k) | 0;
  3276. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  3277. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  3278. bytes[j++] = 255;
  3279. }
  3280. }
  3281. }
  3282. function drawFigure(data, figure, context) {
  3283. var ps = figure.coords;
  3284. var cs = figure.colors;
  3285. var i, ii;
  3286. switch (figure.type) {
  3287. case 'lattice':
  3288. var verticesPerRow = figure.verticesPerRow;
  3289. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  3290. var cols = verticesPerRow - 1;
  3291. for (i = 0; i < rows; i++) {
  3292. var q = i * verticesPerRow;
  3293. for (var j = 0; j < cols; j++, q++) {
  3294. drawTriangle(data, context,
  3295. ps[q], ps[q + 1], ps[q + verticesPerRow],
  3296. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  3297. drawTriangle(data, context,
  3298. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  3299. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  3300. }
  3301. }
  3302. break;
  3303. case 'triangles':
  3304. for (i = 0, ii = ps.length; i < ii; i += 3) {
  3305. drawTriangle(data, context,
  3306. ps[i], ps[i + 1], ps[i + 2],
  3307. cs[i], cs[i + 1], cs[i + 2]);
  3308. }
  3309. break;
  3310. default:
  3311. error('illigal figure');
  3312. break;
  3313. }
  3314. }
  3315. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  3316. backgroundColor, cachedCanvases) {
  3317. // we will increase scale on some weird factor to let antialiasing take
  3318. // care of "rough" edges
  3319. var EXPECTED_SCALE = 1.1;
  3320. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  3321. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  3322. var offsetX = Math.floor(bounds[0]);
  3323. var offsetY = Math.floor(bounds[1]);
  3324. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  3325. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  3326. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  3327. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  3328. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  3329. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  3330. var scaleX = boundsWidth / width;
  3331. var scaleY = boundsHeight / height;
  3332. var context = {
  3333. coords: coords,
  3334. colors: colors,
  3335. offsetX: -offsetX,
  3336. offsetY: -offsetY,
  3337. scaleX: 1 / scaleX,
  3338. scaleY: 1 / scaleY
  3339. };
  3340. var canvas, tmpCanvas, i, ii;
  3341. if (WebGLUtils.isEnabled) {
  3342. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  3343. figures, context);
  3344. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  3345. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  3346. tmpCanvas.context.drawImage(canvas, 0, 0);
  3347. canvas = tmpCanvas.canvas;
  3348. } else {
  3349. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  3350. var tmpCtx = tmpCanvas.context;
  3351. var data = tmpCtx.createImageData(width, height);
  3352. if (backgroundColor) {
  3353. var bytes = data.data;
  3354. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  3355. bytes[i] = backgroundColor[0];
  3356. bytes[i + 1] = backgroundColor[1];
  3357. bytes[i + 2] = backgroundColor[2];
  3358. bytes[i + 3] = 255;
  3359. }
  3360. }
  3361. for (i = 0; i < figures.length; i++) {
  3362. drawFigure(data, figures[i], context);
  3363. }
  3364. tmpCtx.putImageData(data, 0, 0);
  3365. canvas = tmpCanvas.canvas;
  3366. }
  3367. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  3368. scaleX: scaleX, scaleY: scaleY};
  3369. }
  3370. return createMeshCanvas;
  3371. })();
  3372. ShadingIRs.Mesh = {
  3373. fromIR: function Mesh_fromIR(raw) {
  3374. //var type = raw[1];
  3375. var coords = raw[2];
  3376. var colors = raw[3];
  3377. var figures = raw[4];
  3378. var bounds = raw[5];
  3379. var matrix = raw[6];
  3380. //var bbox = raw[7];
  3381. var background = raw[8];
  3382. return {
  3383. type: 'Pattern',
  3384. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  3385. var scale;
  3386. if (shadingFill) {
  3387. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  3388. } else {
  3389. // Obtain scale from matrix and current transformation matrix.
  3390. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  3391. if (matrix) {
  3392. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  3393. scale = [scale[0] * matrixScale[0],
  3394. scale[1] * matrixScale[1]];
  3395. }
  3396. }
  3397. // Rasterizing on the main thread since sending/queue large canvases
  3398. // might cause OOM.
  3399. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  3400. colors, figures, shadingFill ? null : background,
  3401. owner.cachedCanvases);
  3402. if (!shadingFill) {
  3403. ctx.setTransform.apply(ctx, owner.baseTransform);
  3404. if (matrix) {
  3405. ctx.transform.apply(ctx, matrix);
  3406. }
  3407. }
  3408. ctx.translate(temporaryPatternCanvas.offsetX,
  3409. temporaryPatternCanvas.offsetY);
  3410. ctx.scale(temporaryPatternCanvas.scaleX,
  3411. temporaryPatternCanvas.scaleY);
  3412. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  3413. }
  3414. };
  3415. }
  3416. };
  3417. ShadingIRs.Dummy = {
  3418. fromIR: function Dummy_fromIR() {
  3419. return {
  3420. type: 'Pattern',
  3421. getPattern: function Dummy_fromIR_getPattern() {
  3422. return 'hotpink';
  3423. }
  3424. };
  3425. }
  3426. };
  3427. function getShadingPatternFromIR(raw) {
  3428. var shadingIR = ShadingIRs[raw[0]];
  3429. if (!shadingIR) {
  3430. error('Unknown IR type: ' + raw[0]);
  3431. }
  3432. return shadingIR.fromIR(raw);
  3433. }
  3434. var TilingPattern = (function TilingPatternClosure() {
  3435. var PaintType = {
  3436. COLORED: 1,
  3437. UNCOLORED: 2
  3438. };
  3439. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  3440. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  3441. this.operatorList = IR[2];
  3442. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  3443. this.bbox = IR[4];
  3444. this.xstep = IR[5];
  3445. this.ystep = IR[6];
  3446. this.paintType = IR[7];
  3447. this.tilingType = IR[8];
  3448. this.color = color;
  3449. this.canvasGraphicsFactory = canvasGraphicsFactory;
  3450. this.baseTransform = baseTransform;
  3451. this.type = 'Pattern';
  3452. this.ctx = ctx;
  3453. }
  3454. TilingPattern.prototype = {
  3455. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  3456. var operatorList = this.operatorList;
  3457. var bbox = this.bbox;
  3458. var xstep = this.xstep;
  3459. var ystep = this.ystep;
  3460. var paintType = this.paintType;
  3461. var tilingType = this.tilingType;
  3462. var color = this.color;
  3463. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  3464. info('TilingType: ' + tilingType);
  3465. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  3466. var topLeft = [x0, y0];
  3467. // we want the canvas to be as large as the step size
  3468. var botRight = [x0 + xstep, y0 + ystep];
  3469. var width = botRight[0] - topLeft[0];
  3470. var height = botRight[1] - topLeft[1];
  3471. // Obtain scale from matrix and current transformation matrix.
  3472. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  3473. var curMatrixScale = Util.singularValueDecompose2dScale(
  3474. this.baseTransform);
  3475. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  3476. matrixScale[1] * curMatrixScale[1]];
  3477. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  3478. // Use width and height values that are as close as possible to the end
  3479. // result when the pattern is used. Too low value makes the pattern look
  3480. // blurry. Too large value makes it look too crispy.
  3481. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  3482. MAX_PATTERN_SIZE);
  3483. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  3484. MAX_PATTERN_SIZE);
  3485. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  3486. width, height, true);
  3487. var tmpCtx = tmpCanvas.context;
  3488. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  3489. graphics.groupLevel = owner.groupLevel;
  3490. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  3491. this.setScale(width, height, xstep, ystep);
  3492. this.transformToScale(graphics);
  3493. // transform coordinates to pattern space
  3494. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  3495. graphics.transform.apply(graphics, tmpTranslate);
  3496. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  3497. graphics.executeOperatorList(operatorList);
  3498. return tmpCanvas.canvas;
  3499. },
  3500. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  3501. this.scale = [width / xstep, height / ystep];
  3502. },
  3503. transformToScale: function TilingPattern_transformToScale(graphics) {
  3504. var scale = this.scale;
  3505. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  3506. graphics.transform.apply(graphics, tmpScale);
  3507. },
  3508. scaleToContext: function TilingPattern_scaleToContext() {
  3509. var scale = this.scale;
  3510. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  3511. },
  3512. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  3513. if (bbox && isArray(bbox) && bbox.length === 4) {
  3514. var bboxWidth = x1 - x0;
  3515. var bboxHeight = y1 - y0;
  3516. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  3517. graphics.clip();
  3518. graphics.endPath();
  3519. }
  3520. },
  3521. setFillAndStrokeStyleToContext:
  3522. function setFillAndStrokeStyleToContext(context, paintType, color) {
  3523. switch (paintType) {
  3524. case PaintType.COLORED:
  3525. var ctx = this.ctx;
  3526. context.fillStyle = ctx.fillStyle;
  3527. context.strokeStyle = ctx.strokeStyle;
  3528. break;
  3529. case PaintType.UNCOLORED:
  3530. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  3531. context.fillStyle = cssColor;
  3532. context.strokeStyle = cssColor;
  3533. break;
  3534. default:
  3535. error('Unsupported paint type: ' + paintType);
  3536. }
  3537. },
  3538. getPattern: function TilingPattern_getPattern(ctx, owner) {
  3539. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  3540. ctx = this.ctx;
  3541. ctx.setTransform.apply(ctx, this.baseTransform);
  3542. ctx.transform.apply(ctx, this.matrix);
  3543. this.scaleToContext();
  3544. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  3545. }
  3546. };
  3547. return TilingPattern;
  3548. })();
  3549. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  3550. exports.TilingPattern = TilingPattern;
  3551. }));
  3552. (function (root, factory) {
  3553. {
  3554. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  3555. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  3556. }
  3557. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  3558. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  3559. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  3560. var ImageKind = sharedUtil.ImageKind;
  3561. var OPS = sharedUtil.OPS;
  3562. var TextRenderingMode = sharedUtil.TextRenderingMode;
  3563. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  3564. var Util = sharedUtil.Util;
  3565. var assert = sharedUtil.assert;
  3566. var info = sharedUtil.info;
  3567. var isNum = sharedUtil.isNum;
  3568. var isArray = sharedUtil.isArray;
  3569. var error = sharedUtil.error;
  3570. var shadow = sharedUtil.shadow;
  3571. var warn = sharedUtil.warn;
  3572. var TilingPattern = displayPatternHelper.TilingPattern;
  3573. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  3574. var WebGLUtils = displayWebGL.WebGLUtils;
  3575. // <canvas> contexts store most of the state we need natively.
  3576. // However, PDF needs a bit more state, which we store here.
  3577. // Minimal font size that would be used during canvas fillText operations.
  3578. var MIN_FONT_SIZE = 16;
  3579. // Maximum font size that would be used during canvas fillText operations.
  3580. var MAX_FONT_SIZE = 100;
  3581. var MAX_GROUP_SIZE = 4096;
  3582. // Heuristic value used when enforcing minimum line widths.
  3583. var MIN_WIDTH_FACTOR = 0.65;
  3584. var COMPILE_TYPE3_GLYPHS = true;
  3585. var MAX_SIZE_TO_COMPILE = 1000;
  3586. var FULL_CHUNK_HEIGHT = 16;
  3587. function createScratchCanvas(width, height) {
  3588. var canvas = document.createElement('canvas');
  3589. canvas.width = width;
  3590. canvas.height = height;
  3591. return canvas;
  3592. }
  3593. function addContextCurrentTransform(ctx) {
  3594. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  3595. if (!ctx.mozCurrentTransform) {
  3596. ctx._originalSave = ctx.save;
  3597. ctx._originalRestore = ctx.restore;
  3598. ctx._originalRotate = ctx.rotate;
  3599. ctx._originalScale = ctx.scale;
  3600. ctx._originalTranslate = ctx.translate;
  3601. ctx._originalTransform = ctx.transform;
  3602. ctx._originalSetTransform = ctx.setTransform;
  3603. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3604. ctx._transformStack = [];
  3605. Object.defineProperty(ctx, 'mozCurrentTransform', {
  3606. get: function getCurrentTransform() {
  3607. return this._transformMatrix;
  3608. }
  3609. });
  3610. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  3611. get: function getCurrentTransformInverse() {
  3612. // Calculation done using WolframAlpha:
  3613. // http://www.wolframalpha.com/input/?
  3614. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  3615. var m = this._transformMatrix;
  3616. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  3617. var ad_bc = a * d - b * c;
  3618. var bc_ad = b * c - a * d;
  3619. return [
  3620. d / ad_bc,
  3621. b / bc_ad,
  3622. c / bc_ad,
  3623. a / ad_bc,
  3624. (d * e - c * f) / bc_ad,
  3625. (b * e - a * f) / ad_bc
  3626. ];
  3627. }
  3628. });
  3629. ctx.save = function ctxSave() {
  3630. var old = this._transformMatrix;
  3631. this._transformStack.push(old);
  3632. this._transformMatrix = old.slice(0, 6);
  3633. this._originalSave();
  3634. };
  3635. ctx.restore = function ctxRestore() {
  3636. var prev = this._transformStack.pop();
  3637. if (prev) {
  3638. this._transformMatrix = prev;
  3639. this._originalRestore();
  3640. }
  3641. };
  3642. ctx.translate = function ctxTranslate(x, y) {
  3643. var m = this._transformMatrix;
  3644. m[4] = m[0] * x + m[2] * y + m[4];
  3645. m[5] = m[1] * x + m[3] * y + m[5];
  3646. this._originalTranslate(x, y);
  3647. };
  3648. ctx.scale = function ctxScale(x, y) {
  3649. var m = this._transformMatrix;
  3650. m[0] = m[0] * x;
  3651. m[1] = m[1] * x;
  3652. m[2] = m[2] * y;
  3653. m[3] = m[3] * y;
  3654. this._originalScale(x, y);
  3655. };
  3656. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3657. var m = this._transformMatrix;
  3658. this._transformMatrix = [
  3659. m[0] * a + m[2] * b,
  3660. m[1] * a + m[3] * b,
  3661. m[0] * c + m[2] * d,
  3662. m[1] * c + m[3] * d,
  3663. m[0] * e + m[2] * f + m[4],
  3664. m[1] * e + m[3] * f + m[5]
  3665. ];
  3666. ctx._originalTransform(a, b, c, d, e, f);
  3667. };
  3668. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3669. this._transformMatrix = [a, b, c, d, e, f];
  3670. ctx._originalSetTransform(a, b, c, d, e, f);
  3671. };
  3672. ctx.rotate = function ctxRotate(angle) {
  3673. var cosValue = Math.cos(angle);
  3674. var sinValue = Math.sin(angle);
  3675. var m = this._transformMatrix;
  3676. this._transformMatrix = [
  3677. m[0] * cosValue + m[2] * sinValue,
  3678. m[1] * cosValue + m[3] * sinValue,
  3679. m[0] * (-sinValue) + m[2] * cosValue,
  3680. m[1] * (-sinValue) + m[3] * cosValue,
  3681. m[4],
  3682. m[5]
  3683. ];
  3684. this._originalRotate(angle);
  3685. };
  3686. }
  3687. }
  3688. var CachedCanvases = (function CachedCanvasesClosure() {
  3689. function CachedCanvases() {
  3690. this.cache = Object.create(null);
  3691. }
  3692. CachedCanvases.prototype = {
  3693. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3694. trackTransform) {
  3695. var canvasEntry;
  3696. if (this.cache[id] !== undefined) {
  3697. canvasEntry = this.cache[id];
  3698. canvasEntry.canvas.width = width;
  3699. canvasEntry.canvas.height = height;
  3700. // reset canvas transform for emulated mozCurrentTransform, if needed
  3701. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3702. } else {
  3703. var canvas = createScratchCanvas(width, height);
  3704. var ctx = canvas.getContext('2d');
  3705. if (trackTransform) {
  3706. addContextCurrentTransform(ctx);
  3707. }
  3708. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3709. }
  3710. return canvasEntry;
  3711. },
  3712. clear: function () {
  3713. for (var id in this.cache) {
  3714. var canvasEntry = this.cache[id];
  3715. // Zeroing the width and height causes Firefox to release graphics
  3716. // resources immediately, which can greatly reduce memory consumption.
  3717. canvasEntry.canvas.width = 0;
  3718. canvasEntry.canvas.height = 0;
  3719. delete this.cache[id];
  3720. }
  3721. }
  3722. };
  3723. return CachedCanvases;
  3724. })();
  3725. function compileType3Glyph(imgData) {
  3726. var POINT_TO_PROCESS_LIMIT = 1000;
  3727. var width = imgData.width, height = imgData.height;
  3728. var i, j, j0, width1 = width + 1;
  3729. var points = new Uint8Array(width1 * (height + 1));
  3730. var POINT_TYPES =
  3731. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3732. // decodes bit-packed mask data
  3733. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3734. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3735. for (i = 0, ii = data0.length; i < ii; i++) {
  3736. var mask = 128, elem = data0[i];
  3737. while (mask > 0) {
  3738. data[pos++] = (elem & mask) ? 0 : 255;
  3739. mask >>= 1;
  3740. }
  3741. }
  3742. // finding iteresting points: every point is located between mask pixels,
  3743. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3744. // will have flags assigned based on neighboring mask pixels:
  3745. // 4 | 8
  3746. // --P--
  3747. // 2 | 1
  3748. // We are interested only in points with the flags:
  3749. // - outside corners: 1, 2, 4, 8;
  3750. // - inside corners: 7, 11, 13, 14;
  3751. // - and, intersections: 5, 10.
  3752. var count = 0;
  3753. pos = 0;
  3754. if (data[pos] !== 0) {
  3755. points[0] = 1;
  3756. ++count;
  3757. }
  3758. for (j = 1; j < width; j++) {
  3759. if (data[pos] !== data[pos + 1]) {
  3760. points[j] = data[pos] ? 2 : 1;
  3761. ++count;
  3762. }
  3763. pos++;
  3764. }
  3765. if (data[pos] !== 0) {
  3766. points[j] = 2;
  3767. ++count;
  3768. }
  3769. for (i = 1; i < height; i++) {
  3770. pos = i * lineSize;
  3771. j0 = i * width1;
  3772. if (data[pos - lineSize] !== data[pos]) {
  3773. points[j0] = data[pos] ? 1 : 8;
  3774. ++count;
  3775. }
  3776. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3777. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3778. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3779. for (j = 1; j < width; j++) {
  3780. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3781. (data[pos - lineSize + 1] ? 8 : 0);
  3782. if (POINT_TYPES[sum]) {
  3783. points[j0 + j] = POINT_TYPES[sum];
  3784. ++count;
  3785. }
  3786. pos++;
  3787. }
  3788. if (data[pos - lineSize] !== data[pos]) {
  3789. points[j0 + j] = data[pos] ? 2 : 4;
  3790. ++count;
  3791. }
  3792. if (count > POINT_TO_PROCESS_LIMIT) {
  3793. return null;
  3794. }
  3795. }
  3796. pos = lineSize * (height - 1);
  3797. j0 = i * width1;
  3798. if (data[pos] !== 0) {
  3799. points[j0] = 8;
  3800. ++count;
  3801. }
  3802. for (j = 1; j < width; j++) {
  3803. if (data[pos] !== data[pos + 1]) {
  3804. points[j0 + j] = data[pos] ? 4 : 8;
  3805. ++count;
  3806. }
  3807. pos++;
  3808. }
  3809. if (data[pos] !== 0) {
  3810. points[j0 + j] = 4;
  3811. ++count;
  3812. }
  3813. if (count > POINT_TO_PROCESS_LIMIT) {
  3814. return null;
  3815. }
  3816. // building outlines
  3817. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3818. var outlines = [];
  3819. for (i = 0; count && i <= height; i++) {
  3820. var p = i * width1;
  3821. var end = p + width;
  3822. while (p < end && !points[p]) {
  3823. p++;
  3824. }
  3825. if (p === end) {
  3826. continue;
  3827. }
  3828. var coords = [p % width1, i];
  3829. var type = points[p], p0 = p, pp;
  3830. do {
  3831. var step = steps[type];
  3832. do {
  3833. p += step;
  3834. } while (!points[p]);
  3835. pp = points[p];
  3836. if (pp !== 5 && pp !== 10) {
  3837. // set new direction
  3838. type = pp;
  3839. // delete mark
  3840. points[p] = 0;
  3841. } else { // type is 5 or 10, ie, a crossing
  3842. // set new direction
  3843. type = pp & ((0x33 * type) >> 4);
  3844. // set new type for "future hit"
  3845. points[p] &= (type >> 2 | type << 2);
  3846. }
  3847. coords.push(p % width1);
  3848. coords.push((p / width1) | 0);
  3849. --count;
  3850. } while (p0 !== p);
  3851. outlines.push(coords);
  3852. --i;
  3853. }
  3854. var drawOutline = function(c) {
  3855. c.save();
  3856. // the path shall be painted in [0..1]x[0..1] space
  3857. c.scale(1 / width, -1 / height);
  3858. c.translate(0, -height);
  3859. c.beginPath();
  3860. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3861. var o = outlines[i];
  3862. c.moveTo(o[0], o[1]);
  3863. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3864. c.lineTo(o[j], o[j+1]);
  3865. }
  3866. }
  3867. c.fill();
  3868. c.beginPath();
  3869. c.restore();
  3870. };
  3871. return drawOutline;
  3872. }
  3873. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3874. function CanvasExtraState(old) {
  3875. // Are soft masks and alpha values shapes or opacities?
  3876. this.alphaIsShape = false;
  3877. this.fontSize = 0;
  3878. this.fontSizeScale = 1;
  3879. this.textMatrix = IDENTITY_MATRIX;
  3880. this.textMatrixScale = 1;
  3881. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3882. this.leading = 0;
  3883. // Current point (in user coordinates)
  3884. this.x = 0;
  3885. this.y = 0;
  3886. // Start of text line (in text coordinates)
  3887. this.lineX = 0;
  3888. this.lineY = 0;
  3889. // Character and word spacing
  3890. this.charSpacing = 0;
  3891. this.wordSpacing = 0;
  3892. this.textHScale = 1;
  3893. this.textRenderingMode = TextRenderingMode.FILL;
  3894. this.textRise = 0;
  3895. // Default fore and background colors
  3896. this.fillColor = '#000000';
  3897. this.strokeColor = '#000000';
  3898. this.patternFill = false;
  3899. // Note: fill alpha applies to all non-stroking operations
  3900. this.fillAlpha = 1;
  3901. this.strokeAlpha = 1;
  3902. this.lineWidth = 1;
  3903. this.activeSMask = null; // nonclonable field (see the save method below)
  3904. this.old = old;
  3905. }
  3906. CanvasExtraState.prototype = {
  3907. clone: function CanvasExtraState_clone() {
  3908. return Object.create(this);
  3909. },
  3910. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3911. this.x = x;
  3912. this.y = y;
  3913. }
  3914. };
  3915. return CanvasExtraState;
  3916. })();
  3917. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3918. // Defines the time the executeOperatorList is going to be executing
  3919. // before it stops and shedules a continue of execution.
  3920. var EXECUTION_TIME = 15;
  3921. // Defines the number of steps before checking the execution time
  3922. var EXECUTION_STEPS = 10;
  3923. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3924. this.ctx = canvasCtx;
  3925. this.current = new CanvasExtraState();
  3926. this.stateStack = [];
  3927. this.pendingClip = null;
  3928. this.pendingEOFill = false;
  3929. this.res = null;
  3930. this.xobjs = null;
  3931. this.commonObjs = commonObjs;
  3932. this.objs = objs;
  3933. this.imageLayer = imageLayer;
  3934. this.groupStack = [];
  3935. this.processingType3 = null;
  3936. // Patterns are painted relative to the initial page/form transform, see pdf
  3937. // spec 8.7.2 NOTE 1.
  3938. this.baseTransform = null;
  3939. this.baseTransformStack = [];
  3940. this.groupLevel = 0;
  3941. this.smaskStack = [];
  3942. this.smaskCounter = 0;
  3943. this.tempSMask = null;
  3944. this.cachedCanvases = new CachedCanvases();
  3945. if (canvasCtx) {
  3946. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  3947. // the transformation must already be set in canvasCtx._transformMatrix.
  3948. addContextCurrentTransform(canvasCtx);
  3949. }
  3950. this.cachedGetSinglePixelWidth = null;
  3951. }
  3952. function putBinaryImageData(ctx, imgData) {
  3953. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3954. ctx.putImageData(imgData, 0, 0);
  3955. return;
  3956. }
  3957. // Put the image data to the canvas in chunks, rather than putting the
  3958. // whole image at once. This saves JS memory, because the ImageData object
  3959. // is smaller. It also possibly saves C++ memory within the implementation
  3960. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3961. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3962. // because too many putImageData() calls will slow things down.
  3963. //
  3964. // Note: as written, if the last chunk is partial, the putImageData() call
  3965. // will (conceptually) put pixels past the bounds of the canvas. But
  3966. // that's ok; any such pixels are ignored.
  3967. var height = imgData.height, width = imgData.width;
  3968. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3969. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3970. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3971. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3972. var srcPos = 0, destPos;
  3973. var src = imgData.data;
  3974. var dest = chunkImgData.data;
  3975. var i, j, thisChunkHeight, elemsInThisChunk;
  3976. // There are multiple forms in which the pixel data can be passed, and
  3977. // imgData.kind tells us which one this is.
  3978. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3979. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3980. var srcLength = src.byteLength;
  3981. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3982. new Uint32ArrayView(dest);
  3983. var dest32DataLength = dest32.length;
  3984. var fullSrcDiff = (width + 7) >> 3;
  3985. var white = 0xFFFFFFFF;
  3986. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3987. 0xFF000000 : 0x000000FF;
  3988. for (i = 0; i < totalChunks; i++) {
  3989. thisChunkHeight =
  3990. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3991. destPos = 0;
  3992. for (j = 0; j < thisChunkHeight; j++) {
  3993. var srcDiff = srcLength - srcPos;
  3994. var k = 0;
  3995. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3996. var kEndUnrolled = kEnd & ~7;
  3997. var mask = 0;
  3998. var srcByte = 0;
  3999. for (; k < kEndUnrolled; k += 8) {
  4000. srcByte = src[srcPos++];
  4001. dest32[destPos++] = (srcByte & 128) ? white : black;
  4002. dest32[destPos++] = (srcByte & 64) ? white : black;
  4003. dest32[destPos++] = (srcByte & 32) ? white : black;
  4004. dest32[destPos++] = (srcByte & 16) ? white : black;
  4005. dest32[destPos++] = (srcByte & 8) ? white : black;
  4006. dest32[destPos++] = (srcByte & 4) ? white : black;
  4007. dest32[destPos++] = (srcByte & 2) ? white : black;
  4008. dest32[destPos++] = (srcByte & 1) ? white : black;
  4009. }
  4010. for (; k < kEnd; k++) {
  4011. if (mask === 0) {
  4012. srcByte = src[srcPos++];
  4013. mask = 128;
  4014. }
  4015. dest32[destPos++] = (srcByte & mask) ? white : black;
  4016. mask >>= 1;
  4017. }
  4018. }
  4019. // We ran out of input. Make all remaining pixels transparent.
  4020. while (destPos < dest32DataLength) {
  4021. dest32[destPos++] = 0;
  4022. }
  4023. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4024. }
  4025. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  4026. // RGBA, 32-bits per pixel.
  4027. j = 0;
  4028. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4029. for (i = 0; i < fullChunks; i++) {
  4030. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4031. srcPos += elemsInThisChunk;
  4032. ctx.putImageData(chunkImgData, 0, j);
  4033. j += FULL_CHUNK_HEIGHT;
  4034. }
  4035. if (i < totalChunks) {
  4036. elemsInThisChunk = width * partialChunkHeight * 4;
  4037. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4038. ctx.putImageData(chunkImgData, 0, j);
  4039. }
  4040. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  4041. // RGB, 24-bits per pixel.
  4042. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4043. elemsInThisChunk = width * thisChunkHeight;
  4044. for (i = 0; i < totalChunks; i++) {
  4045. if (i >= fullChunks) {
  4046. thisChunkHeight = partialChunkHeight;
  4047. elemsInThisChunk = width * thisChunkHeight;
  4048. }
  4049. destPos = 0;
  4050. for (j = elemsInThisChunk; j--;) {
  4051. dest[destPos++] = src[srcPos++];
  4052. dest[destPos++] = src[srcPos++];
  4053. dest[destPos++] = src[srcPos++];
  4054. dest[destPos++] = 255;
  4055. }
  4056. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4057. }
  4058. } else {
  4059. error('bad image kind: ' + imgData.kind);
  4060. }
  4061. }
  4062. function putBinaryImageMask(ctx, imgData) {
  4063. var height = imgData.height, width = imgData.width;
  4064. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4065. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4066. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4067. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4068. var srcPos = 0;
  4069. var src = imgData.data;
  4070. var dest = chunkImgData.data;
  4071. for (var i = 0; i < totalChunks; i++) {
  4072. var thisChunkHeight =
  4073. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4074. // Expand the mask so it can be used by the canvas. Any required
  4075. // inversion has already been handled.
  4076. var destPos = 3; // alpha component offset
  4077. for (var j = 0; j < thisChunkHeight; j++) {
  4078. var mask = 0;
  4079. for (var k = 0; k < width; k++) {
  4080. if (!mask) {
  4081. var elem = src[srcPos++];
  4082. mask = 128;
  4083. }
  4084. dest[destPos] = (elem & mask) ? 0 : 255;
  4085. destPos += 4;
  4086. mask >>= 1;
  4087. }
  4088. }
  4089. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4090. }
  4091. }
  4092. function copyCtxState(sourceCtx, destCtx) {
  4093. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  4094. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  4095. 'globalCompositeOperation', 'font'];
  4096. for (var i = 0, ii = properties.length; i < ii; i++) {
  4097. var property = properties[i];
  4098. if (sourceCtx[property] !== undefined) {
  4099. destCtx[property] = sourceCtx[property];
  4100. }
  4101. }
  4102. if (sourceCtx.setLineDash !== undefined) {
  4103. destCtx.setLineDash(sourceCtx.getLineDash());
  4104. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4105. } else if (sourceCtx.mozDashOffset !== undefined) {
  4106. destCtx.mozDash = sourceCtx.mozDash;
  4107. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  4108. }
  4109. }
  4110. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4111. var length = bytes.length;
  4112. for (var i = 3; i < length; i += 4) {
  4113. var alpha = bytes[i];
  4114. if (alpha === 0) {
  4115. bytes[i - 3] = r0;
  4116. bytes[i - 2] = g0;
  4117. bytes[i - 1] = b0;
  4118. } else if (alpha < 255) {
  4119. var alpha_ = 255 - alpha;
  4120. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  4121. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  4122. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  4123. }
  4124. }
  4125. }
  4126. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4127. var length = maskData.length;
  4128. var scale = 1 / 255;
  4129. for (var i = 3; i < length; i += 4) {
  4130. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4131. layerData[i] = (layerData[i] * alpha * scale) | 0;
  4132. }
  4133. }
  4134. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4135. var length = maskData.length;
  4136. for (var i = 3; i < length; i += 4) {
  4137. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  4138. (maskData[i - 2] * 152) + // * 0.59 ....
  4139. (maskData[i - 1] * 28); // * 0.11 ....
  4140. layerData[i] = transferMap ?
  4141. (layerData[i] * transferMap[y >> 8]) >> 8 :
  4142. (layerData[i] * y) >> 16;
  4143. }
  4144. }
  4145. function genericComposeSMask(maskCtx, layerCtx, width, height,
  4146. subtype, backdrop, transferMap) {
  4147. var hasBackdrop = !!backdrop;
  4148. var r0 = hasBackdrop ? backdrop[0] : 0;
  4149. var g0 = hasBackdrop ? backdrop[1] : 0;
  4150. var b0 = hasBackdrop ? backdrop[2] : 0;
  4151. var composeFn;
  4152. if (subtype === 'Luminosity') {
  4153. composeFn = composeSMaskLuminosity;
  4154. } else {
  4155. composeFn = composeSMaskAlpha;
  4156. }
  4157. // processing image in chunks to save memory
  4158. var PIXELS_TO_PROCESS = 1048576;
  4159. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4160. for (var row = 0; row < height; row += chunkSize) {
  4161. var chunkHeight = Math.min(chunkSize, height - row);
  4162. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  4163. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  4164. if (hasBackdrop) {
  4165. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4166. }
  4167. composeFn(maskData.data, layerData.data, transferMap);
  4168. maskCtx.putImageData(layerData, 0, row);
  4169. }
  4170. }
  4171. function composeSMask(ctx, smask, layerCtx) {
  4172. var mask = smask.canvas;
  4173. var maskCtx = smask.context;
  4174. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  4175. smask.offsetX, smask.offsetY);
  4176. var backdrop = smask.backdrop || null;
  4177. if (!smask.transferMap && WebGLUtils.isEnabled) {
  4178. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  4179. {subtype: smask.subtype, backdrop: backdrop});
  4180. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4181. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  4182. return;
  4183. }
  4184. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  4185. smask.subtype, backdrop, smask.transferMap);
  4186. ctx.drawImage(mask, 0, 0);
  4187. }
  4188. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  4189. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  4190. var NORMAL_CLIP = {};
  4191. var EO_CLIP = {};
  4192. CanvasGraphics.prototype = {
  4193. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  4194. transparency) {
  4195. // For pdfs that use blend modes we have to clear the canvas else certain
  4196. // blend modes can look wrong since we'd be blending with a white
  4197. // backdrop. The problem with a transparent backdrop though is we then
  4198. // don't get sub pixel anti aliasing on text, creating temporary
  4199. // transparent canvas when we have blend modes.
  4200. var width = this.ctx.canvas.width;
  4201. var height = this.ctx.canvas.height;
  4202. this.ctx.save();
  4203. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  4204. this.ctx.fillRect(0, 0, width, height);
  4205. this.ctx.restore();
  4206. if (transparency) {
  4207. var transparentCanvas = this.cachedCanvases.getCanvas(
  4208. 'transparent', width, height, true);
  4209. this.compositeCtx = this.ctx;
  4210. this.transparentCanvas = transparentCanvas.canvas;
  4211. this.ctx = transparentCanvas.context;
  4212. this.ctx.save();
  4213. // The transform can be applied before rendering, transferring it to
  4214. // the new canvas.
  4215. this.ctx.transform.apply(this.ctx,
  4216. this.compositeCtx.mozCurrentTransform);
  4217. }
  4218. this.ctx.save();
  4219. if (transform) {
  4220. this.ctx.transform.apply(this.ctx, transform);
  4221. }
  4222. this.ctx.transform.apply(this.ctx, viewport.transform);
  4223. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4224. if (this.imageLayer) {
  4225. this.imageLayer.beginLayout();
  4226. }
  4227. },
  4228. executeOperatorList: function CanvasGraphics_executeOperatorList(
  4229. operatorList,
  4230. executionStartIdx, continueCallback,
  4231. stepper) {
  4232. var argsArray = operatorList.argsArray;
  4233. var fnArray = operatorList.fnArray;
  4234. var i = executionStartIdx || 0;
  4235. var argsArrayLen = argsArray.length;
  4236. // Sometimes the OperatorList to execute is empty.
  4237. if (argsArrayLen === i) {
  4238. return i;
  4239. }
  4240. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  4241. typeof continueCallback === 'function');
  4242. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4243. var steps = 0;
  4244. var commonObjs = this.commonObjs;
  4245. var objs = this.objs;
  4246. var fnId;
  4247. while (true) {
  4248. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4249. stepper.breakIt(i, continueCallback);
  4250. return i;
  4251. }
  4252. fnId = fnArray[i];
  4253. if (fnId !== OPS.dependency) {
  4254. this[fnId].apply(this, argsArray[i]);
  4255. } else {
  4256. var deps = argsArray[i];
  4257. for (var n = 0, nn = deps.length; n < nn; n++) {
  4258. var depObjId = deps[n];
  4259. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  4260. var objsPool = common ? commonObjs : objs;
  4261. // If the promise isn't resolved yet, add the continueCallback
  4262. // to the promise and bail out.
  4263. if (!objsPool.isResolved(depObjId)) {
  4264. objsPool.get(depObjId, continueCallback);
  4265. return i;
  4266. }
  4267. }
  4268. }
  4269. i++;
  4270. // If the entire operatorList was executed, stop as were done.
  4271. if (i === argsArrayLen) {
  4272. return i;
  4273. }
  4274. // If the execution took longer then a certain amount of time and
  4275. // `continueCallback` is specified, interrupt the execution.
  4276. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4277. if (Date.now() > endTime) {
  4278. continueCallback();
  4279. return i;
  4280. }
  4281. steps = 0;
  4282. }
  4283. // If the operatorList isn't executed completely yet OR the execution
  4284. // time was short enough, do another execution round.
  4285. }
  4286. },
  4287. endDrawing: function CanvasGraphics_endDrawing() {
  4288. this.ctx.restore();
  4289. if (this.transparentCanvas) {
  4290. this.ctx = this.compositeCtx;
  4291. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4292. this.transparentCanvas = null;
  4293. }
  4294. this.cachedCanvases.clear();
  4295. WebGLUtils.clear();
  4296. if (this.imageLayer) {
  4297. this.imageLayer.endLayout();
  4298. }
  4299. },
  4300. // Graphics state
  4301. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  4302. this.current.lineWidth = width;
  4303. this.ctx.lineWidth = width;
  4304. },
  4305. setLineCap: function CanvasGraphics_setLineCap(style) {
  4306. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4307. },
  4308. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  4309. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4310. },
  4311. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  4312. this.ctx.miterLimit = limit;
  4313. },
  4314. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  4315. var ctx = this.ctx;
  4316. if (ctx.setLineDash !== undefined) {
  4317. ctx.setLineDash(dashArray);
  4318. ctx.lineDashOffset = dashPhase;
  4319. } else {
  4320. ctx.mozDash = dashArray;
  4321. ctx.mozDashOffset = dashPhase;
  4322. }
  4323. },
  4324. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  4325. // Maybe if we one day fully support color spaces this will be important
  4326. // for now we can ignore.
  4327. // TODO set rendering intent?
  4328. },
  4329. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  4330. // There's no way to control this with canvas, but we can safely ignore.
  4331. // TODO set flatness?
  4332. },
  4333. setGState: function CanvasGraphics_setGState(states) {
  4334. for (var i = 0, ii = states.length; i < ii; i++) {
  4335. var state = states[i];
  4336. var key = state[0];
  4337. var value = state[1];
  4338. switch (key) {
  4339. case 'LW':
  4340. this.setLineWidth(value);
  4341. break;
  4342. case 'LC':
  4343. this.setLineCap(value);
  4344. break;
  4345. case 'LJ':
  4346. this.setLineJoin(value);
  4347. break;
  4348. case 'ML':
  4349. this.setMiterLimit(value);
  4350. break;
  4351. case 'D':
  4352. this.setDash(value[0], value[1]);
  4353. break;
  4354. case 'RI':
  4355. this.setRenderingIntent(value);
  4356. break;
  4357. case 'FL':
  4358. this.setFlatness(value);
  4359. break;
  4360. case 'Font':
  4361. this.setFont(value[0], value[1]);
  4362. break;
  4363. case 'CA':
  4364. this.current.strokeAlpha = state[1];
  4365. break;
  4366. case 'ca':
  4367. this.current.fillAlpha = state[1];
  4368. this.ctx.globalAlpha = state[1];
  4369. break;
  4370. case 'BM':
  4371. if (value && value.name && (value.name !== 'Normal')) {
  4372. var mode = value.name.replace(/([A-Z])/g,
  4373. function(c) {
  4374. return '-' + c.toLowerCase();
  4375. }
  4376. ).substring(1);
  4377. this.ctx.globalCompositeOperation = mode;
  4378. if (this.ctx.globalCompositeOperation !== mode) {
  4379. warn('globalCompositeOperation "' + mode +
  4380. '" is not supported');
  4381. }
  4382. } else {
  4383. this.ctx.globalCompositeOperation = 'source-over';
  4384. }
  4385. break;
  4386. case 'SMask':
  4387. if (this.current.activeSMask) {
  4388. this.endSMaskGroup();
  4389. }
  4390. this.current.activeSMask = value ? this.tempSMask : null;
  4391. if (this.current.activeSMask) {
  4392. this.beginSMaskGroup();
  4393. }
  4394. this.tempSMask = null;
  4395. break;
  4396. }
  4397. }
  4398. },
  4399. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  4400. var activeSMask = this.current.activeSMask;
  4401. var drawnWidth = activeSMask.canvas.width;
  4402. var drawnHeight = activeSMask.canvas.height;
  4403. var cacheId = 'smaskGroupAt' + this.groupLevel;
  4404. var scratchCanvas = this.cachedCanvases.getCanvas(
  4405. cacheId, drawnWidth, drawnHeight, true);
  4406. var currentCtx = this.ctx;
  4407. var currentTransform = currentCtx.mozCurrentTransform;
  4408. this.ctx.save();
  4409. var groupCtx = scratchCanvas.context;
  4410. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  4411. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  4412. groupCtx.transform.apply(groupCtx, currentTransform);
  4413. copyCtxState(currentCtx, groupCtx);
  4414. this.ctx = groupCtx;
  4415. this.setGState([
  4416. ['BM', 'Normal'],
  4417. ['ca', 1],
  4418. ['CA', 1]
  4419. ]);
  4420. this.groupStack.push(currentCtx);
  4421. this.groupLevel++;
  4422. },
  4423. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4424. var groupCtx = this.ctx;
  4425. this.groupLevel--;
  4426. this.ctx = this.groupStack.pop();
  4427. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  4428. this.ctx.restore();
  4429. copyCtxState(groupCtx, this.ctx);
  4430. },
  4431. save: function CanvasGraphics_save() {
  4432. this.ctx.save();
  4433. var old = this.current;
  4434. this.stateStack.push(old);
  4435. this.current = old.clone();
  4436. this.current.activeSMask = null;
  4437. },
  4438. restore: function CanvasGraphics_restore() {
  4439. if (this.stateStack.length !== 0) {
  4440. if (this.current.activeSMask !== null) {
  4441. this.endSMaskGroup();
  4442. }
  4443. this.current = this.stateStack.pop();
  4444. this.ctx.restore();
  4445. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  4446. this.pendingClip = null;
  4447. this.cachedGetSinglePixelWidth = null;
  4448. }
  4449. },
  4450. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  4451. this.ctx.transform(a, b, c, d, e, f);
  4452. this.cachedGetSinglePixelWidth = null;
  4453. },
  4454. // Path
  4455. constructPath: function CanvasGraphics_constructPath(ops, args) {
  4456. var ctx = this.ctx;
  4457. var current = this.current;
  4458. var x = current.x, y = current.y;
  4459. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4460. switch (ops[i] | 0) {
  4461. case OPS.rectangle:
  4462. x = args[j++];
  4463. y = args[j++];
  4464. var width = args[j++];
  4465. var height = args[j++];
  4466. if (width === 0) {
  4467. width = this.getSinglePixelWidth();
  4468. }
  4469. if (height === 0) {
  4470. height = this.getSinglePixelWidth();
  4471. }
  4472. var xw = x + width;
  4473. var yh = y + height;
  4474. this.ctx.moveTo(x, y);
  4475. this.ctx.lineTo(xw, y);
  4476. this.ctx.lineTo(xw, yh);
  4477. this.ctx.lineTo(x, yh);
  4478. this.ctx.lineTo(x, y);
  4479. this.ctx.closePath();
  4480. break;
  4481. case OPS.moveTo:
  4482. x = args[j++];
  4483. y = args[j++];
  4484. ctx.moveTo(x, y);
  4485. break;
  4486. case OPS.lineTo:
  4487. x = args[j++];
  4488. y = args[j++];
  4489. ctx.lineTo(x, y);
  4490. break;
  4491. case OPS.curveTo:
  4492. x = args[j + 4];
  4493. y = args[j + 5];
  4494. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  4495. x, y);
  4496. j += 6;
  4497. break;
  4498. case OPS.curveTo2:
  4499. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  4500. args[j + 2], args[j + 3]);
  4501. x = args[j + 2];
  4502. y = args[j + 3];
  4503. j += 4;
  4504. break;
  4505. case OPS.curveTo3:
  4506. x = args[j + 2];
  4507. y = args[j + 3];
  4508. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4509. j += 4;
  4510. break;
  4511. case OPS.closePath:
  4512. ctx.closePath();
  4513. break;
  4514. }
  4515. }
  4516. current.setCurrentPoint(x, y);
  4517. },
  4518. closePath: function CanvasGraphics_closePath() {
  4519. this.ctx.closePath();
  4520. },
  4521. stroke: function CanvasGraphics_stroke(consumePath) {
  4522. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4523. var ctx = this.ctx;
  4524. var strokeColor = this.current.strokeColor;
  4525. // Prevent drawing too thin lines by enforcing a minimum line width.
  4526. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  4527. this.current.lineWidth);
  4528. // For stroke we want to temporarily change the global alpha to the
  4529. // stroking alpha.
  4530. ctx.globalAlpha = this.current.strokeAlpha;
  4531. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  4532. strokeColor.type === 'Pattern') {
  4533. // for patterns, we transform to pattern space, calculate
  4534. // the pattern, call stroke, and restore to user space
  4535. ctx.save();
  4536. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4537. ctx.stroke();
  4538. ctx.restore();
  4539. } else {
  4540. ctx.stroke();
  4541. }
  4542. if (consumePath) {
  4543. this.consumePath();
  4544. }
  4545. // Restore the global alpha to the fill alpha
  4546. ctx.globalAlpha = this.current.fillAlpha;
  4547. },
  4548. closeStroke: function CanvasGraphics_closeStroke() {
  4549. this.closePath();
  4550. this.stroke();
  4551. },
  4552. fill: function CanvasGraphics_fill(consumePath) {
  4553. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4554. var ctx = this.ctx;
  4555. var fillColor = this.current.fillColor;
  4556. var isPatternFill = this.current.patternFill;
  4557. var needRestore = false;
  4558. if (isPatternFill) {
  4559. ctx.save();
  4560. if (this.baseTransform) {
  4561. ctx.setTransform.apply(ctx, this.baseTransform);
  4562. }
  4563. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4564. needRestore = true;
  4565. }
  4566. if (this.pendingEOFill) {
  4567. if (ctx.mozFillRule !== undefined) {
  4568. ctx.mozFillRule = 'evenodd';
  4569. ctx.fill();
  4570. ctx.mozFillRule = 'nonzero';
  4571. } else {
  4572. ctx.fill('evenodd');
  4573. }
  4574. this.pendingEOFill = false;
  4575. } else {
  4576. ctx.fill();
  4577. }
  4578. if (needRestore) {
  4579. ctx.restore();
  4580. }
  4581. if (consumePath) {
  4582. this.consumePath();
  4583. }
  4584. },
  4585. eoFill: function CanvasGraphics_eoFill() {
  4586. this.pendingEOFill = true;
  4587. this.fill();
  4588. },
  4589. fillStroke: function CanvasGraphics_fillStroke() {
  4590. this.fill(false);
  4591. this.stroke(false);
  4592. this.consumePath();
  4593. },
  4594. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4595. this.pendingEOFill = true;
  4596. this.fillStroke();
  4597. },
  4598. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4599. this.closePath();
  4600. this.fillStroke();
  4601. },
  4602. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4603. this.pendingEOFill = true;
  4604. this.closePath();
  4605. this.fillStroke();
  4606. },
  4607. endPath: function CanvasGraphics_endPath() {
  4608. this.consumePath();
  4609. },
  4610. // Clipping
  4611. clip: function CanvasGraphics_clip() {
  4612. this.pendingClip = NORMAL_CLIP;
  4613. },
  4614. eoClip: function CanvasGraphics_eoClip() {
  4615. this.pendingClip = EO_CLIP;
  4616. },
  4617. // Text
  4618. beginText: function CanvasGraphics_beginText() {
  4619. this.current.textMatrix = IDENTITY_MATRIX;
  4620. this.current.textMatrixScale = 1;
  4621. this.current.x = this.current.lineX = 0;
  4622. this.current.y = this.current.lineY = 0;
  4623. },
  4624. endText: function CanvasGraphics_endText() {
  4625. var paths = this.pendingTextPaths;
  4626. var ctx = this.ctx;
  4627. if (paths === undefined) {
  4628. ctx.beginPath();
  4629. return;
  4630. }
  4631. ctx.save();
  4632. ctx.beginPath();
  4633. for (var i = 0; i < paths.length; i++) {
  4634. var path = paths[i];
  4635. ctx.setTransform.apply(ctx, path.transform);
  4636. ctx.translate(path.x, path.y);
  4637. path.addToPath(ctx, path.fontSize);
  4638. }
  4639. ctx.restore();
  4640. ctx.clip();
  4641. ctx.beginPath();
  4642. delete this.pendingTextPaths;
  4643. },
  4644. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4645. this.current.charSpacing = spacing;
  4646. },
  4647. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4648. this.current.wordSpacing = spacing;
  4649. },
  4650. setHScale: function CanvasGraphics_setHScale(scale) {
  4651. this.current.textHScale = scale / 100;
  4652. },
  4653. setLeading: function CanvasGraphics_setLeading(leading) {
  4654. this.current.leading = -leading;
  4655. },
  4656. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4657. var fontObj = this.commonObjs.get(fontRefName);
  4658. var current = this.current;
  4659. if (!fontObj) {
  4660. error('Can\'t find font for ' + fontRefName);
  4661. }
  4662. current.fontMatrix = (fontObj.fontMatrix ?
  4663. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  4664. // A valid matrix needs all main diagonal elements to be non-zero
  4665. // This also ensures we bypass FF bugzilla bug #719844.
  4666. if (current.fontMatrix[0] === 0 ||
  4667. current.fontMatrix[3] === 0) {
  4668. warn('Invalid font matrix for font ' + fontRefName);
  4669. }
  4670. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  4671. // and in some docs this can be negative (inverted x-y axes).
  4672. if (size < 0) {
  4673. size = -size;
  4674. current.fontDirection = -1;
  4675. } else {
  4676. current.fontDirection = 1;
  4677. }
  4678. this.current.font = fontObj;
  4679. this.current.fontSize = size;
  4680. if (fontObj.isType3Font) {
  4681. return; // we don't need ctx.font for Type3 fonts
  4682. }
  4683. var name = fontObj.loadedName || 'sans-serif';
  4684. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  4685. (fontObj.bold ? 'bold' : 'normal');
  4686. var italic = fontObj.italic ? 'italic' : 'normal';
  4687. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4688. // Some font backends cannot handle fonts below certain size.
  4689. // Keeping the font at minimal size and using the fontSizeScale to change
  4690. // the current transformation matrix before the fillText/strokeText.
  4691. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4692. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4693. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4694. this.current.fontSizeScale = size / browserFontSize;
  4695. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4696. this.ctx.font = rule;
  4697. },
  4698. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4699. this.current.textRenderingMode = mode;
  4700. },
  4701. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4702. this.current.textRise = rise;
  4703. },
  4704. moveText: function CanvasGraphics_moveText(x, y) {
  4705. this.current.x = this.current.lineX += x;
  4706. this.current.y = this.current.lineY += y;
  4707. },
  4708. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4709. this.setLeading(-y);
  4710. this.moveText(x, y);
  4711. },
  4712. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4713. this.current.textMatrix = [a, b, c, d, e, f];
  4714. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4715. this.current.x = this.current.lineX = 0;
  4716. this.current.y = this.current.lineY = 0;
  4717. },
  4718. nextLine: function CanvasGraphics_nextLine() {
  4719. this.moveText(0, this.current.leading);
  4720. },
  4721. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4722. var ctx = this.ctx;
  4723. var current = this.current;
  4724. var font = current.font;
  4725. var textRenderingMode = current.textRenderingMode;
  4726. var fontSize = current.fontSize / current.fontSizeScale;
  4727. var fillStrokeMode = textRenderingMode &
  4728. TextRenderingMode.FILL_STROKE_MASK;
  4729. var isAddToPathSet = !!(textRenderingMode &
  4730. TextRenderingMode.ADD_TO_PATH_FLAG);
  4731. var addToPath;
  4732. if (font.disableFontFace || isAddToPathSet) {
  4733. addToPath = font.getPathGenerator(this.commonObjs, character);
  4734. }
  4735. if (font.disableFontFace) {
  4736. ctx.save();
  4737. ctx.translate(x, y);
  4738. ctx.beginPath();
  4739. addToPath(ctx, fontSize);
  4740. if (fillStrokeMode === TextRenderingMode.FILL ||
  4741. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4742. ctx.fill();
  4743. }
  4744. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4745. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4746. ctx.stroke();
  4747. }
  4748. ctx.restore();
  4749. } else {
  4750. if (fillStrokeMode === TextRenderingMode.FILL ||
  4751. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4752. ctx.fillText(character, x, y);
  4753. }
  4754. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4755. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4756. ctx.strokeText(character, x, y);
  4757. }
  4758. }
  4759. if (isAddToPathSet) {
  4760. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4761. paths.push({
  4762. transform: ctx.mozCurrentTransform,
  4763. x: x,
  4764. y: y,
  4765. fontSize: fontSize,
  4766. addToPath: addToPath
  4767. });
  4768. }
  4769. },
  4770. get isFontSubpixelAAEnabled() {
  4771. // Checks if anti-aliasing is enabled when scaled text is painted.
  4772. // On Windows GDI scaled fonts looks bad.
  4773. var ctx = document.createElement('canvas').getContext('2d');
  4774. ctx.scale(1.5, 1);
  4775. ctx.fillText('I', 0, 10);
  4776. var data = ctx.getImageData(0, 0, 10, 10).data;
  4777. var enabled = false;
  4778. for (var i = 3; i < data.length; i += 4) {
  4779. if (data[i] > 0 && data[i] < 255) {
  4780. enabled = true;
  4781. break;
  4782. }
  4783. }
  4784. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4785. },
  4786. showText: function CanvasGraphics_showText(glyphs) {
  4787. var current = this.current;
  4788. var font = current.font;
  4789. if (font.isType3Font) {
  4790. return this.showType3Text(glyphs);
  4791. }
  4792. var fontSize = current.fontSize;
  4793. if (fontSize === 0) {
  4794. return;
  4795. }
  4796. var ctx = this.ctx;
  4797. var fontSizeScale = current.fontSizeScale;
  4798. var charSpacing = current.charSpacing;
  4799. var wordSpacing = current.wordSpacing;
  4800. var fontDirection = current.fontDirection;
  4801. var textHScale = current.textHScale * fontDirection;
  4802. var glyphsLength = glyphs.length;
  4803. var vertical = font.vertical;
  4804. var spacingDir = vertical ? 1 : -1;
  4805. var defaultVMetrics = font.defaultVMetrics;
  4806. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4807. var simpleFillText =
  4808. current.textRenderingMode === TextRenderingMode.FILL &&
  4809. !font.disableFontFace;
  4810. ctx.save();
  4811. ctx.transform.apply(ctx, current.textMatrix);
  4812. ctx.translate(current.x, current.y + current.textRise);
  4813. if (fontDirection > 0) {
  4814. ctx.scale(textHScale, -1);
  4815. } else {
  4816. ctx.scale(textHScale, 1);
  4817. }
  4818. var lineWidth = current.lineWidth;
  4819. var scale = current.textMatrixScale;
  4820. if (scale === 0 || lineWidth === 0) {
  4821. var fillStrokeMode = current.textRenderingMode &
  4822. TextRenderingMode.FILL_STROKE_MASK;
  4823. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4824. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4825. this.cachedGetSinglePixelWidth = null;
  4826. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4827. }
  4828. } else {
  4829. lineWidth /= scale;
  4830. }
  4831. if (fontSizeScale !== 1.0) {
  4832. ctx.scale(fontSizeScale, fontSizeScale);
  4833. lineWidth /= fontSizeScale;
  4834. }
  4835. ctx.lineWidth = lineWidth;
  4836. var x = 0, i;
  4837. for (i = 0; i < glyphsLength; ++i) {
  4838. var glyph = glyphs[i];
  4839. if (isNum(glyph)) {
  4840. x += spacingDir * glyph * fontSize / 1000;
  4841. continue;
  4842. }
  4843. var restoreNeeded = false;
  4844. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4845. var character = glyph.fontChar;
  4846. var accent = glyph.accent;
  4847. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4848. var width = glyph.width;
  4849. if (vertical) {
  4850. var vmetric, vx, vy;
  4851. vmetric = glyph.vmetric || defaultVMetrics;
  4852. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4853. vx = -vx * widthAdvanceScale;
  4854. vy = vmetric[2] * widthAdvanceScale;
  4855. width = vmetric ? -vmetric[0] : width;
  4856. scaledX = vx / fontSizeScale;
  4857. scaledY = (x + vy) / fontSizeScale;
  4858. } else {
  4859. scaledX = x / fontSizeScale;
  4860. scaledY = 0;
  4861. }
  4862. if (font.remeasure && width > 0) {
  4863. // Some standard fonts may not have the exact width: rescale per
  4864. // character if measured width is greater than expected glyph width
  4865. // and subpixel-aa is enabled, otherwise just center the glyph.
  4866. var measuredWidth = ctx.measureText(character).width * 1000 /
  4867. fontSize * fontSizeScale;
  4868. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  4869. var characterScaleX = width / measuredWidth;
  4870. restoreNeeded = true;
  4871. ctx.save();
  4872. ctx.scale(characterScaleX, 1);
  4873. scaledX /= characterScaleX;
  4874. } else if (width !== measuredWidth) {
  4875. scaledX += (width - measuredWidth) / 2000 *
  4876. fontSize / fontSizeScale;
  4877. }
  4878. }
  4879. if (simpleFillText && !accent) {
  4880. // common case
  4881. ctx.fillText(character, scaledX, scaledY);
  4882. } else {
  4883. this.paintChar(character, scaledX, scaledY);
  4884. if (accent) {
  4885. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4886. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4887. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4888. }
  4889. }
  4890. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4891. x += charWidth;
  4892. if (restoreNeeded) {
  4893. ctx.restore();
  4894. }
  4895. }
  4896. if (vertical) {
  4897. current.y -= x * textHScale;
  4898. } else {
  4899. current.x += x * textHScale;
  4900. }
  4901. ctx.restore();
  4902. },
  4903. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4904. // Type3 fonts - each glyph is a "mini-PDF"
  4905. var ctx = this.ctx;
  4906. var current = this.current;
  4907. var font = current.font;
  4908. var fontSize = current.fontSize;
  4909. var fontDirection = current.fontDirection;
  4910. var spacingDir = font.vertical ? 1 : -1;
  4911. var charSpacing = current.charSpacing;
  4912. var wordSpacing = current.wordSpacing;
  4913. var textHScale = current.textHScale * fontDirection;
  4914. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4915. var glyphsLength = glyphs.length;
  4916. var isTextInvisible =
  4917. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4918. var i, glyph, width, spacingLength;
  4919. if (isTextInvisible || fontSize === 0) {
  4920. return;
  4921. }
  4922. this.cachedGetSinglePixelWidth = null;
  4923. ctx.save();
  4924. ctx.transform.apply(ctx, current.textMatrix);
  4925. ctx.translate(current.x, current.y);
  4926. ctx.scale(textHScale, fontDirection);
  4927. for (i = 0; i < glyphsLength; ++i) {
  4928. glyph = glyphs[i];
  4929. if (isNum(glyph)) {
  4930. spacingLength = spacingDir * glyph * fontSize / 1000;
  4931. this.ctx.translate(spacingLength, 0);
  4932. current.x += spacingLength * textHScale;
  4933. continue;
  4934. }
  4935. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4936. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4937. if (!operatorList) {
  4938. warn('Type3 character \"' + glyph.operatorListId +
  4939. '\" is not available');
  4940. continue;
  4941. }
  4942. this.processingType3 = glyph;
  4943. this.save();
  4944. ctx.scale(fontSize, fontSize);
  4945. ctx.transform.apply(ctx, fontMatrix);
  4946. this.executeOperatorList(operatorList);
  4947. this.restore();
  4948. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4949. width = transformed[0] * fontSize + spacing;
  4950. ctx.translate(width, 0);
  4951. current.x += width * textHScale;
  4952. }
  4953. ctx.restore();
  4954. this.processingType3 = null;
  4955. },
  4956. // Type3 fonts
  4957. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4958. // We can safely ignore this since the width should be the same
  4959. // as the width in the Widths array.
  4960. },
  4961. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4962. yWidth,
  4963. llx,
  4964. lly,
  4965. urx,
  4966. ury) {
  4967. // TODO According to the spec we're also suppose to ignore any operators
  4968. // that set color or include images while processing this type3 font.
  4969. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4970. this.clip();
  4971. this.endPath();
  4972. },
  4973. // Color
  4974. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4975. var pattern;
  4976. if (IR[0] === 'TilingPattern') {
  4977. var color = IR[1];
  4978. var baseTransform = this.baseTransform ||
  4979. this.ctx.mozCurrentTransform.slice();
  4980. var self = this;
  4981. var canvasGraphicsFactory = {
  4982. createCanvasGraphics: function (ctx) {
  4983. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  4984. }
  4985. };
  4986. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  4987. baseTransform);
  4988. } else {
  4989. pattern = getShadingPatternFromIR(IR);
  4990. }
  4991. return pattern;
  4992. },
  4993. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4994. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4995. },
  4996. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4997. this.current.fillColor = this.getColorN_Pattern(arguments);
  4998. this.current.patternFill = true;
  4999. },
  5000. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  5001. var color = Util.makeCssRgb(r, g, b);
  5002. this.ctx.strokeStyle = color;
  5003. this.current.strokeColor = color;
  5004. },
  5005. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  5006. var color = Util.makeCssRgb(r, g, b);
  5007. this.ctx.fillStyle = color;
  5008. this.current.fillColor = color;
  5009. this.current.patternFill = false;
  5010. },
  5011. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  5012. var ctx = this.ctx;
  5013. this.save();
  5014. var pattern = getShadingPatternFromIR(patternIR);
  5015. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  5016. var inv = ctx.mozCurrentTransformInverse;
  5017. if (inv) {
  5018. var canvas = ctx.canvas;
  5019. var width = canvas.width;
  5020. var height = canvas.height;
  5021. var bl = Util.applyTransform([0, 0], inv);
  5022. var br = Util.applyTransform([0, height], inv);
  5023. var ul = Util.applyTransform([width, 0], inv);
  5024. var ur = Util.applyTransform([width, height], inv);
  5025. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5026. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5027. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5028. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5029. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5030. } else {
  5031. // HACK to draw the gradient onto an infinite rectangle.
  5032. // PDF gradients are drawn across the entire image while
  5033. // Canvas only allows gradients to be drawn in a rectangle
  5034. // The following bug should allow us to remove this.
  5035. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  5036. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5037. }
  5038. this.restore();
  5039. },
  5040. // Images
  5041. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  5042. error('Should not call beginInlineImage');
  5043. },
  5044. beginImageData: function CanvasGraphics_beginImageData() {
  5045. error('Should not call beginImageData');
  5046. },
  5047. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  5048. bbox) {
  5049. this.save();
  5050. this.baseTransformStack.push(this.baseTransform);
  5051. if (isArray(matrix) && 6 === matrix.length) {
  5052. this.transform.apply(this, matrix);
  5053. }
  5054. this.baseTransform = this.ctx.mozCurrentTransform;
  5055. if (isArray(bbox) && 4 === bbox.length) {
  5056. var width = bbox[2] - bbox[0];
  5057. var height = bbox[3] - bbox[1];
  5058. this.ctx.rect(bbox[0], bbox[1], width, height);
  5059. this.clip();
  5060. this.endPath();
  5061. }
  5062. },
  5063. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  5064. this.restore();
  5065. this.baseTransform = this.baseTransformStack.pop();
  5066. },
  5067. beginGroup: function CanvasGraphics_beginGroup(group) {
  5068. this.save();
  5069. var currentCtx = this.ctx;
  5070. // TODO non-isolated groups - according to Rik at adobe non-isolated
  5071. // group results aren't usually that different and they even have tools
  5072. // that ignore this setting. Notes from Rik on implmenting:
  5073. // - When you encounter an transparency group, create a new canvas with
  5074. // the dimensions of the bbox
  5075. // - copy the content from the previous canvas to the new canvas
  5076. // - draw as usual
  5077. // - remove the backdrop alpha:
  5078. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  5079. // value of your transparency group and 'alphaBackdrop' the alpha of the
  5080. // backdrop
  5081. // - remove background color:
  5082. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  5083. if (!group.isolated) {
  5084. info('TODO: Support non-isolated groups.');
  5085. }
  5086. // TODO knockout - supposedly possible with the clever use of compositing
  5087. // modes.
  5088. if (group.knockout) {
  5089. warn('Knockout groups not supported.');
  5090. }
  5091. var currentTransform = currentCtx.mozCurrentTransform;
  5092. if (group.matrix) {
  5093. currentCtx.transform.apply(currentCtx, group.matrix);
  5094. }
  5095. assert(group.bbox, 'Bounding box is required.');
  5096. // Based on the current transform figure out how big the bounding box
  5097. // will actually be.
  5098. var bounds = Util.getAxialAlignedBoundingBox(
  5099. group.bbox,
  5100. currentCtx.mozCurrentTransform);
  5101. // Clip the bounding box to the current canvas.
  5102. var canvasBounds = [0,
  5103. 0,
  5104. currentCtx.canvas.width,
  5105. currentCtx.canvas.height];
  5106. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5107. // Use ceil in case we're between sizes so we don't create canvas that is
  5108. // too small and make the canvas at least 1x1 pixels.
  5109. var offsetX = Math.floor(bounds[0]);
  5110. var offsetY = Math.floor(bounds[1]);
  5111. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5112. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5113. var scaleX = 1, scaleY = 1;
  5114. if (drawnWidth > MAX_GROUP_SIZE) {
  5115. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5116. drawnWidth = MAX_GROUP_SIZE;
  5117. }
  5118. if (drawnHeight > MAX_GROUP_SIZE) {
  5119. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5120. drawnHeight = MAX_GROUP_SIZE;
  5121. }
  5122. var cacheId = 'groupAt' + this.groupLevel;
  5123. if (group.smask) {
  5124. // Using two cache entries is case if masks are used one after another.
  5125. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  5126. }
  5127. var scratchCanvas = this.cachedCanvases.getCanvas(
  5128. cacheId, drawnWidth, drawnHeight, true);
  5129. var groupCtx = scratchCanvas.context;
  5130. // Since we created a new canvas that is just the size of the bounding box
  5131. // we have to translate the group ctx.
  5132. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5133. groupCtx.translate(-offsetX, -offsetY);
  5134. groupCtx.transform.apply(groupCtx, currentTransform);
  5135. if (group.smask) {
  5136. // Saving state and cached mask to be used in setGState.
  5137. this.smaskStack.push({
  5138. canvas: scratchCanvas.canvas,
  5139. context: groupCtx,
  5140. offsetX: offsetX,
  5141. offsetY: offsetY,
  5142. scaleX: scaleX,
  5143. scaleY: scaleY,
  5144. subtype: group.smask.subtype,
  5145. backdrop: group.smask.backdrop,
  5146. transferMap: group.smask.transferMap || null
  5147. });
  5148. } else {
  5149. // Setup the current ctx so when the group is popped we draw it at the
  5150. // right location.
  5151. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5152. currentCtx.translate(offsetX, offsetY);
  5153. currentCtx.scale(scaleX, scaleY);
  5154. }
  5155. // The transparency group inherits all off the current graphics state
  5156. // except the blend mode, soft mask, and alpha constants.
  5157. copyCtxState(currentCtx, groupCtx);
  5158. this.ctx = groupCtx;
  5159. this.setGState([
  5160. ['BM', 'Normal'],
  5161. ['ca', 1],
  5162. ['CA', 1]
  5163. ]);
  5164. this.groupStack.push(currentCtx);
  5165. this.groupLevel++;
  5166. },
  5167. endGroup: function CanvasGraphics_endGroup(group) {
  5168. this.groupLevel--;
  5169. var groupCtx = this.ctx;
  5170. this.ctx = this.groupStack.pop();
  5171. // Turn off image smoothing to avoid sub pixel interpolation which can
  5172. // look kind of blurry for some pdfs.
  5173. if (this.ctx.imageSmoothingEnabled !== undefined) {
  5174. this.ctx.imageSmoothingEnabled = false;
  5175. } else {
  5176. this.ctx.mozImageSmoothingEnabled = false;
  5177. }
  5178. if (group.smask) {
  5179. this.tempSMask = this.smaskStack.pop();
  5180. } else {
  5181. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5182. }
  5183. this.restore();
  5184. },
  5185. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  5186. this.save();
  5187. this.current = new CanvasExtraState();
  5188. if (this.baseTransform) {
  5189. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5190. }
  5191. },
  5192. endAnnotations: function CanvasGraphics_endAnnotations() {
  5193. this.restore();
  5194. },
  5195. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  5196. matrix) {
  5197. this.save();
  5198. if (isArray(rect) && 4 === rect.length) {
  5199. var width = rect[2] - rect[0];
  5200. var height = rect[3] - rect[1];
  5201. this.ctx.rect(rect[0], rect[1], width, height);
  5202. this.clip();
  5203. this.endPath();
  5204. }
  5205. this.transform.apply(this, transform);
  5206. this.transform.apply(this, matrix);
  5207. },
  5208. endAnnotation: function CanvasGraphics_endAnnotation() {
  5209. this.restore();
  5210. },
  5211. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  5212. var domImage = this.objs.get(objId);
  5213. if (!domImage) {
  5214. warn('Dependent image isn\'t ready yet');
  5215. return;
  5216. }
  5217. this.save();
  5218. var ctx = this.ctx;
  5219. // scale the image to the unit square
  5220. ctx.scale(1 / w, -1 / h);
  5221. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  5222. 0, -h, w, h);
  5223. if (this.imageLayer) {
  5224. var currentTransform = ctx.mozCurrentTransformInverse;
  5225. var position = this.getCanvasPosition(0, 0);
  5226. this.imageLayer.appendImage({
  5227. objId: objId,
  5228. left: position[0],
  5229. top: position[1],
  5230. width: w / currentTransform[0],
  5231. height: h / currentTransform[3]
  5232. });
  5233. }
  5234. this.restore();
  5235. },
  5236. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  5237. var ctx = this.ctx;
  5238. var width = img.width, height = img.height;
  5239. var fillColor = this.current.fillColor;
  5240. var isPatternFill = this.current.patternFill;
  5241. var glyph = this.processingType3;
  5242. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  5243. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  5244. glyph.compiled =
  5245. compileType3Glyph({data: img.data, width: width, height: height});
  5246. } else {
  5247. glyph.compiled = null;
  5248. }
  5249. }
  5250. if (glyph && glyph.compiled) {
  5251. glyph.compiled(ctx);
  5252. return;
  5253. }
  5254. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5255. width, height);
  5256. var maskCtx = maskCanvas.context;
  5257. maskCtx.save();
  5258. putBinaryImageMask(maskCtx, img);
  5259. maskCtx.globalCompositeOperation = 'source-in';
  5260. maskCtx.fillStyle = isPatternFill ?
  5261. fillColor.getPattern(maskCtx, this) : fillColor;
  5262. maskCtx.fillRect(0, 0, width, height);
  5263. maskCtx.restore();
  5264. this.paintInlineImageXObject(maskCanvas.canvas);
  5265. },
  5266. paintImageMaskXObjectRepeat:
  5267. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  5268. scaleY, positions) {
  5269. var width = imgData.width;
  5270. var height = imgData.height;
  5271. var fillColor = this.current.fillColor;
  5272. var isPatternFill = this.current.patternFill;
  5273. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5274. width, height);
  5275. var maskCtx = maskCanvas.context;
  5276. maskCtx.save();
  5277. putBinaryImageMask(maskCtx, imgData);
  5278. maskCtx.globalCompositeOperation = 'source-in';
  5279. maskCtx.fillStyle = isPatternFill ?
  5280. fillColor.getPattern(maskCtx, this) : fillColor;
  5281. maskCtx.fillRect(0, 0, width, height);
  5282. maskCtx.restore();
  5283. var ctx = this.ctx;
  5284. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5285. ctx.save();
  5286. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  5287. ctx.scale(1, -1);
  5288. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  5289. 0, -1, 1, 1);
  5290. ctx.restore();
  5291. }
  5292. },
  5293. paintImageMaskXObjectGroup:
  5294. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  5295. var ctx = this.ctx;
  5296. var fillColor = this.current.fillColor;
  5297. var isPatternFill = this.current.patternFill;
  5298. for (var i = 0, ii = images.length; i < ii; i++) {
  5299. var image = images[i];
  5300. var width = image.width, height = image.height;
  5301. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5302. width, height);
  5303. var maskCtx = maskCanvas.context;
  5304. maskCtx.save();
  5305. putBinaryImageMask(maskCtx, image);
  5306. maskCtx.globalCompositeOperation = 'source-in';
  5307. maskCtx.fillStyle = isPatternFill ?
  5308. fillColor.getPattern(maskCtx, this) : fillColor;
  5309. maskCtx.fillRect(0, 0, width, height);
  5310. maskCtx.restore();
  5311. ctx.save();
  5312. ctx.transform.apply(ctx, image.transform);
  5313. ctx.scale(1, -1);
  5314. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  5315. 0, -1, 1, 1);
  5316. ctx.restore();
  5317. }
  5318. },
  5319. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  5320. var imgData = this.objs.get(objId);
  5321. if (!imgData) {
  5322. warn('Dependent image isn\'t ready yet');
  5323. return;
  5324. }
  5325. this.paintInlineImageXObject(imgData);
  5326. },
  5327. paintImageXObjectRepeat:
  5328. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  5329. positions) {
  5330. var imgData = this.objs.get(objId);
  5331. if (!imgData) {
  5332. warn('Dependent image isn\'t ready yet');
  5333. return;
  5334. }
  5335. var width = imgData.width;
  5336. var height = imgData.height;
  5337. var map = [];
  5338. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5339. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  5340. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  5341. }
  5342. this.paintInlineImageXObjectGroup(imgData, map);
  5343. },
  5344. paintInlineImageXObject:
  5345. function CanvasGraphics_paintInlineImageXObject(imgData) {
  5346. var width = imgData.width;
  5347. var height = imgData.height;
  5348. var ctx = this.ctx;
  5349. this.save();
  5350. // scale the image to the unit square
  5351. ctx.scale(1 / width, -1 / height);
  5352. var currentTransform = ctx.mozCurrentTransformInverse;
  5353. var a = currentTransform[0], b = currentTransform[1];
  5354. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  5355. var c = currentTransform[2], d = currentTransform[3];
  5356. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  5357. var imgToPaint, tmpCanvas;
  5358. // instanceof HTMLElement does not work in jsdom node.js module
  5359. if (imgData instanceof HTMLElement || !imgData.data) {
  5360. imgToPaint = imgData;
  5361. } else {
  5362. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  5363. width, height);
  5364. var tmpCtx = tmpCanvas.context;
  5365. putBinaryImageData(tmpCtx, imgData);
  5366. imgToPaint = tmpCanvas.canvas;
  5367. }
  5368. var paintWidth = width, paintHeight = height;
  5369. var tmpCanvasId = 'prescale1';
  5370. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  5371. // pixels during drawImage operation, painting on the temporary canvas(es)
  5372. // that are twice smaller in size
  5373. while ((widthScale > 2 && paintWidth > 1) ||
  5374. (heightScale > 2 && paintHeight > 1)) {
  5375. var newWidth = paintWidth, newHeight = paintHeight;
  5376. if (widthScale > 2 && paintWidth > 1) {
  5377. newWidth = Math.ceil(paintWidth / 2);
  5378. widthScale /= paintWidth / newWidth;
  5379. }
  5380. if (heightScale > 2 && paintHeight > 1) {
  5381. newHeight = Math.ceil(paintHeight / 2);
  5382. heightScale /= paintHeight / newHeight;
  5383. }
  5384. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  5385. newWidth, newHeight);
  5386. tmpCtx = tmpCanvas.context;
  5387. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5388. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  5389. 0, 0, newWidth, newHeight);
  5390. imgToPaint = tmpCanvas.canvas;
  5391. paintWidth = newWidth;
  5392. paintHeight = newHeight;
  5393. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  5394. }
  5395. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  5396. 0, -height, width, height);
  5397. if (this.imageLayer) {
  5398. var position = this.getCanvasPosition(0, -height);
  5399. this.imageLayer.appendImage({
  5400. imgData: imgData,
  5401. left: position[0],
  5402. top: position[1],
  5403. width: width / currentTransform[0],
  5404. height: height / currentTransform[3]
  5405. });
  5406. }
  5407. this.restore();
  5408. },
  5409. paintInlineImageXObjectGroup:
  5410. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  5411. var ctx = this.ctx;
  5412. var w = imgData.width;
  5413. var h = imgData.height;
  5414. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  5415. var tmpCtx = tmpCanvas.context;
  5416. putBinaryImageData(tmpCtx, imgData);
  5417. for (var i = 0, ii = map.length; i < ii; i++) {
  5418. var entry = map[i];
  5419. ctx.save();
  5420. ctx.transform.apply(ctx, entry.transform);
  5421. ctx.scale(1, -1);
  5422. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  5423. 0, -1, 1, 1);
  5424. if (this.imageLayer) {
  5425. var position = this.getCanvasPosition(entry.x, entry.y);
  5426. this.imageLayer.appendImage({
  5427. imgData: imgData,
  5428. left: position[0],
  5429. top: position[1],
  5430. width: w,
  5431. height: h
  5432. });
  5433. }
  5434. ctx.restore();
  5435. }
  5436. },
  5437. paintSolidColorImageMask:
  5438. function CanvasGraphics_paintSolidColorImageMask() {
  5439. this.ctx.fillRect(0, 0, 1, 1);
  5440. },
  5441. paintXObject: function CanvasGraphics_paintXObject() {
  5442. warn('Unsupported \'paintXObject\' command.');
  5443. },
  5444. // Marked content
  5445. markPoint: function CanvasGraphics_markPoint(tag) {
  5446. // TODO Marked content.
  5447. },
  5448. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  5449. // TODO Marked content.
  5450. },
  5451. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  5452. // TODO Marked content.
  5453. },
  5454. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  5455. tag, properties) {
  5456. // TODO Marked content.
  5457. },
  5458. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  5459. // TODO Marked content.
  5460. },
  5461. // Compatibility
  5462. beginCompat: function CanvasGraphics_beginCompat() {
  5463. // TODO ignore undefined operators (should we do that anyway?)
  5464. },
  5465. endCompat: function CanvasGraphics_endCompat() {
  5466. // TODO stop ignoring undefined operators
  5467. },
  5468. // Helper functions
  5469. consumePath: function CanvasGraphics_consumePath() {
  5470. var ctx = this.ctx;
  5471. if (this.pendingClip) {
  5472. if (this.pendingClip === EO_CLIP) {
  5473. if (ctx.mozFillRule !== undefined) {
  5474. ctx.mozFillRule = 'evenodd';
  5475. ctx.clip();
  5476. ctx.mozFillRule = 'nonzero';
  5477. } else {
  5478. ctx.clip('evenodd');
  5479. }
  5480. } else {
  5481. ctx.clip();
  5482. }
  5483. this.pendingClip = null;
  5484. }
  5485. ctx.beginPath();
  5486. },
  5487. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  5488. if (this.cachedGetSinglePixelWidth === null) {
  5489. var inverse = this.ctx.mozCurrentTransformInverse;
  5490. // max of the current horizontal and vertical scale
  5491. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  5492. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  5493. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  5494. }
  5495. return this.cachedGetSinglePixelWidth;
  5496. },
  5497. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  5498. var transform = this.ctx.mozCurrentTransform;
  5499. return [
  5500. transform[0] * x + transform[2] * y + transform[4],
  5501. transform[1] * x + transform[3] * y + transform[5]
  5502. ];
  5503. }
  5504. };
  5505. for (var op in OPS) {
  5506. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  5507. }
  5508. return CanvasGraphics;
  5509. })();
  5510. exports.CanvasGraphics = CanvasGraphics;
  5511. exports.createScratchCanvas = createScratchCanvas;
  5512. }));
  5513. (function (root, factory) {
  5514. {
  5515. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  5516. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  5517. root.pdfjsSharedGlobal);
  5518. }
  5519. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  5520. sharedGlobal, amdRequire) {
  5521. var InvalidPDFException = sharedUtil.InvalidPDFException;
  5522. var MessageHandler = sharedUtil.MessageHandler;
  5523. var MissingPDFException = sharedUtil.MissingPDFException;
  5524. var PasswordResponses = sharedUtil.PasswordResponses;
  5525. var PasswordException = sharedUtil.PasswordException;
  5526. var StatTimer = sharedUtil.StatTimer;
  5527. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  5528. var UnknownErrorException = sharedUtil.UnknownErrorException;
  5529. var Util = sharedUtil.Util;
  5530. var createPromiseCapability = sharedUtil.createPromiseCapability;
  5531. var combineUrl = sharedUtil.combineUrl;
  5532. var error = sharedUtil.error;
  5533. var deprecated = sharedUtil.deprecated;
  5534. var info = sharedUtil.info;
  5535. var isArrayBuffer = sharedUtil.isArrayBuffer;
  5536. var loadJpegStream = sharedUtil.loadJpegStream;
  5537. var stringToBytes = sharedUtil.stringToBytes;
  5538. var warn = sharedUtil.warn;
  5539. var FontFaceObject = displayFontLoader.FontFaceObject;
  5540. var FontLoader = displayFontLoader.FontLoader;
  5541. var CanvasGraphics = displayCanvas.CanvasGraphics;
  5542. var createScratchCanvas = displayCanvas.createScratchCanvas;
  5543. var PDFJS = sharedGlobal.PDFJS;
  5544. var globalScope = sharedGlobal.globalScope;
  5545. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  5546. /**
  5547. * The maximum allowed image size in total pixels e.g. width * height. Images
  5548. * above this value will not be drawn. Use -1 for no limit.
  5549. * @var {number}
  5550. */
  5551. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  5552. -1 : PDFJS.maxImageSize);
  5553. /**
  5554. * The url of where the predefined Adobe CMaps are located. Include trailing
  5555. * slash.
  5556. * @var {string}
  5557. */
  5558. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  5559. /**
  5560. * Specifies if CMaps are binary packed.
  5561. * @var {boolean}
  5562. */
  5563. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  5564. /**
  5565. * By default fonts are converted to OpenType fonts and loaded via font face
  5566. * rules. If disabled, the font will be rendered using a built in font renderer
  5567. * that constructs the glyphs with primitive path commands.
  5568. * @var {boolean}
  5569. */
  5570. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  5571. false : PDFJS.disableFontFace);
  5572. /**
  5573. * Path for image resources, mainly for annotation icons. Include trailing
  5574. * slash.
  5575. * @var {string}
  5576. */
  5577. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  5578. '' : PDFJS.imageResourcesPath);
  5579. /**
  5580. * Disable the web worker and run all code on the main thread. This will happen
  5581. * automatically if the browser doesn't support workers or sending typed arrays
  5582. * to workers.
  5583. * @var {boolean}
  5584. */
  5585. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  5586. false : PDFJS.disableWorker);
  5587. /**
  5588. * Path and filename of the worker file. Required when the worker is enabled in
  5589. * development mode. If unspecified in the production build, the worker will be
  5590. * loaded based on the location of the pdf.js file. It is recommended that
  5591. * the workerSrc is set in a custom application to prevent issues caused by
  5592. * third-party frameworks and libraries.
  5593. * @var {string}
  5594. */
  5595. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  5596. /**
  5597. * Disable range request loading of PDF files. When enabled and if the server
  5598. * supports partial content requests then the PDF will be fetched in chunks.
  5599. * Enabled (false) by default.
  5600. * @var {boolean}
  5601. */
  5602. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  5603. false : PDFJS.disableRange);
  5604. /**
  5605. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  5606. * in chunks. This default behavior can be disabled.
  5607. * @var {boolean}
  5608. */
  5609. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  5610. false : PDFJS.disableStream);
  5611. /**
  5612. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  5613. * will automatically keep fetching more data even if it isn't needed to display
  5614. * the current page. This default behavior can be disabled.
  5615. *
  5616. * NOTE: It is also necessary to disable streaming, see above,
  5617. * in order for disabling of pre-fetching to work correctly.
  5618. * @var {boolean}
  5619. */
  5620. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  5621. false : PDFJS.disableAutoFetch);
  5622. /**
  5623. * Enables special hooks for debugging PDF.js.
  5624. * @var {boolean}
  5625. */
  5626. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  5627. /**
  5628. * Enables transfer usage in postMessage for ArrayBuffers.
  5629. * @var {boolean}
  5630. */
  5631. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  5632. true : PDFJS.postMessageTransfers);
  5633. /**
  5634. * Disables URL.createObjectURL usage.
  5635. * @var {boolean}
  5636. */
  5637. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  5638. false : PDFJS.disableCreateObjectURL);
  5639. /**
  5640. * Disables WebGL usage.
  5641. * @var {boolean}
  5642. */
  5643. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  5644. true : PDFJS.disableWebGL);
  5645. /**
  5646. * Disables fullscreen support, and by extension Presentation Mode,
  5647. * in browsers which support the fullscreen API.
  5648. * @var {boolean}
  5649. */
  5650. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  5651. false : PDFJS.disableFullscreen);
  5652. /**
  5653. * Enables CSS only zooming.
  5654. * @var {boolean}
  5655. */
  5656. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  5657. false : PDFJS.useOnlyCssZoom);
  5658. /**
  5659. * Controls the logging level.
  5660. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  5661. * - errors
  5662. * - warnings [default]
  5663. * - infos
  5664. * @var {number}
  5665. */
  5666. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  5667. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  5668. /**
  5669. * The maximum supported canvas size in total pixels e.g. width * height.
  5670. * The default value is 4096 * 4096. Use -1 for no limit.
  5671. * @var {number}
  5672. */
  5673. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  5674. 16777216 : PDFJS.maxCanvasPixels);
  5675. /**
  5676. * (Deprecated) Opens external links in a new window if enabled.
  5677. * The default behavior opens external links in the PDF.js window.
  5678. *
  5679. * NOTE: This property has been deprecated, please use
  5680. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  5681. * @var {boolean}
  5682. */
  5683. PDFJS.openExternalLinksInNewWindow = (
  5684. PDFJS.openExternalLinksInNewWindow === undefined ?
  5685. false : PDFJS.openExternalLinksInNewWindow);
  5686. /**
  5687. * Specifies the |target| attribute for external links.
  5688. * The constants from PDFJS.LinkTarget should be used:
  5689. * - NONE [default]
  5690. * - SELF
  5691. * - BLANK
  5692. * - PARENT
  5693. * - TOP
  5694. * @var {number}
  5695. */
  5696. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  5697. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  5698. /**
  5699. * Specifies the |rel| attribute for external links. Defaults to stripping
  5700. * the referrer.
  5701. * @var {string}
  5702. */
  5703. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  5704. 'noreferrer' : PDFJS.externalLinkRel);
  5705. /**
  5706. * Determines if we can eval strings as JS. Primarily used to improve
  5707. * performance for font rendering.
  5708. * @var {boolean}
  5709. */
  5710. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  5711. true : PDFJS.isEvalSupported);
  5712. /**
  5713. * Document initialization / loading parameters object.
  5714. *
  5715. * @typedef {Object} DocumentInitParameters
  5716. * @property {string} url - The URL of the PDF.
  5717. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  5718. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  5719. * use atob() to convert it to a binary string first.
  5720. * @property {Object} httpHeaders - Basic authentication headers.
  5721. * @property {boolean} withCredentials - Indicates whether or not cross-site
  5722. * Access-Control requests should be made using credentials such as cookies
  5723. * or authorization headers. The default is false.
  5724. * @property {string} password - For decrypting password-protected PDFs.
  5725. * @property {TypedArray} initialData - A typed array with the first portion or
  5726. * all of the pdf data. Used by the extension since some data is already
  5727. * loaded before the switch to range requests.
  5728. * @property {number} length - The PDF file length. It's used for progress
  5729. * reports and range requests operations.
  5730. * @property {PDFDataRangeTransport} range
  5731. * @property {number} rangeChunkSize - Optional parameter to specify
  5732. * maximum number of bytes fetched per range request. The default value is
  5733. * 2^16 = 65536.
  5734. * @property {PDFWorker} worker - The worker that will be used for the loading
  5735. * and parsing of the PDF data.
  5736. */
  5737. /**
  5738. * @typedef {Object} PDFDocumentStats
  5739. * @property {Array} streamTypes - Used stream types in the document (an item
  5740. * is set to true if specific stream ID was used in the document).
  5741. * @property {Array} fontTypes - Used font type in the document (an item is set
  5742. * to true if specific font ID was used in the document).
  5743. */
  5744. /**
  5745. * This is the main entry point for loading a PDF and interacting with it.
  5746. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  5747. * is used, which means it must follow the same origin rules that any XHR does
  5748. * e.g. No cross domain requests without CORS.
  5749. *
  5750. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  5751. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  5752. * already populated with data or parameter object.
  5753. *
  5754. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  5755. * if you want to manually serve range requests for data in the PDF.
  5756. *
  5757. * @param {function} passwordCallback (deprecated) It is used to request a
  5758. * password if wrong or no password was provided. The callback receives two
  5759. * parameters: function that needs to be called with new password and reason
  5760. * (see {PasswordResponses}).
  5761. *
  5762. * @param {function} progressCallback (deprecated) It is used to be able to
  5763. * monitor the loading progress of the PDF file (necessary to implement e.g.
  5764. * a loading bar). The callback receives an {Object} with the properties:
  5765. * {number} loaded and {number} total.
  5766. *
  5767. * @return {PDFDocumentLoadingTask}
  5768. */
  5769. PDFJS.getDocument = function getDocument(src,
  5770. pdfDataRangeTransport,
  5771. passwordCallback,
  5772. progressCallback) {
  5773. var task = new PDFDocumentLoadingTask();
  5774. // Support of the obsolete arguments (for compatibility with API v1.0)
  5775. if (arguments.length > 1) {
  5776. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  5777. 'passwordCallback or progressCallback argument');
  5778. }
  5779. if (pdfDataRangeTransport) {
  5780. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  5781. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  5782. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  5783. pdfDataRangeTransport.length = src.length;
  5784. pdfDataRangeTransport.initialData = src.initialData;
  5785. if (!pdfDataRangeTransport.abort) {
  5786. pdfDataRangeTransport.abort = function () {};
  5787. }
  5788. }
  5789. src = Object.create(src);
  5790. src.range = pdfDataRangeTransport;
  5791. }
  5792. task.onPassword = passwordCallback || null;
  5793. task.onProgress = progressCallback || null;
  5794. var source;
  5795. if (typeof src === 'string') {
  5796. source = { url: src };
  5797. } else if (isArrayBuffer(src)) {
  5798. source = { data: src };
  5799. } else if (src instanceof PDFDataRangeTransport) {
  5800. source = { range: src };
  5801. } else {
  5802. if (typeof src !== 'object') {
  5803. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  5804. 'string or a parameter object');
  5805. }
  5806. if (!src.url && !src.data && !src.range) {
  5807. error('Invalid parameter object: need either .data, .range or .url');
  5808. }
  5809. source = src;
  5810. }
  5811. var params = {};
  5812. var rangeTransport = null;
  5813. var worker = null;
  5814. for (var key in source) {
  5815. if (key === 'url' && typeof window !== 'undefined') {
  5816. // The full path is required in the 'url' field.
  5817. params[key] = combineUrl(window.location.href, source[key]);
  5818. continue;
  5819. } else if (key === 'range') {
  5820. rangeTransport = source[key];
  5821. continue;
  5822. } else if (key === 'worker') {
  5823. worker = source[key];
  5824. continue;
  5825. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  5826. // Converting string or array-like data to Uint8Array.
  5827. var pdfBytes = source[key];
  5828. if (typeof pdfBytes === 'string') {
  5829. params[key] = stringToBytes(pdfBytes);
  5830. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  5831. !isNaN(pdfBytes.length)) {
  5832. params[key] = new Uint8Array(pdfBytes);
  5833. } else if (isArrayBuffer(pdfBytes)) {
  5834. params[key] = new Uint8Array(pdfBytes);
  5835. } else {
  5836. error('Invalid PDF binary data: either typed array, string or ' +
  5837. 'array-like object is expected in the data property.');
  5838. }
  5839. continue;
  5840. }
  5841. params[key] = source[key];
  5842. }
  5843. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  5844. if (!worker) {
  5845. // Worker was not provided -- creating and owning our own.
  5846. worker = new PDFWorker();
  5847. task._worker = worker;
  5848. }
  5849. var docId = task.docId;
  5850. worker.promise.then(function () {
  5851. if (task.destroyed) {
  5852. throw new Error('Loading aborted');
  5853. }
  5854. return _fetchDocument(worker, params, rangeTransport, docId).then(
  5855. function (workerId) {
  5856. if (task.destroyed) {
  5857. throw new Error('Loading aborted');
  5858. }
  5859. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  5860. messageHandler.send('Ready', null);
  5861. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  5862. task._transport = transport;
  5863. });
  5864. }, task._capability.reject);
  5865. return task;
  5866. };
  5867. /**
  5868. * Starts fetching of specified PDF document/data.
  5869. * @param {PDFWorker} worker
  5870. * @param {Object} source
  5871. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  5872. * @param {string} docId Unique document id, used as MessageHandler id.
  5873. * @returns {Promise} The promise, which is resolved when worker id of
  5874. * MessageHandler is known.
  5875. * @private
  5876. */
  5877. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  5878. if (worker.destroyed) {
  5879. return Promise.reject(new Error('Worker was destroyed'));
  5880. }
  5881. source.disableAutoFetch = PDFJS.disableAutoFetch;
  5882. source.disableStream = PDFJS.disableStream;
  5883. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  5884. if (pdfDataRangeTransport) {
  5885. source.length = pdfDataRangeTransport.length;
  5886. source.initialData = pdfDataRangeTransport.initialData;
  5887. }
  5888. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  5889. docId: docId,
  5890. source: source,
  5891. disableRange: PDFJS.disableRange,
  5892. maxImageSize: PDFJS.maxImageSize,
  5893. cMapUrl: PDFJS.cMapUrl,
  5894. cMapPacked: PDFJS.cMapPacked,
  5895. disableFontFace: PDFJS.disableFontFace,
  5896. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  5897. verbosity: PDFJS.verbosity
  5898. }).then(function (workerId) {
  5899. if (worker.destroyed) {
  5900. throw new Error('Worker was destroyed');
  5901. }
  5902. return workerId;
  5903. });
  5904. }
  5905. /**
  5906. * PDF document loading operation.
  5907. * @class
  5908. * @alias PDFDocumentLoadingTask
  5909. */
  5910. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  5911. var nextDocumentId = 0;
  5912. /** @constructs PDFDocumentLoadingTask */
  5913. function PDFDocumentLoadingTask() {
  5914. this._capability = createPromiseCapability();
  5915. this._transport = null;
  5916. this._worker = null;
  5917. /**
  5918. * Unique document loading task id -- used in MessageHandlers.
  5919. * @type {string}
  5920. */
  5921. this.docId = 'd' + (nextDocumentId++);
  5922. /**
  5923. * Shows if loading task is destroyed.
  5924. * @type {boolean}
  5925. */
  5926. this.destroyed = false;
  5927. /**
  5928. * Callback to request a password if wrong or no password was provided.
  5929. * The callback receives two parameters: function that needs to be called
  5930. * with new password and reason (see {PasswordResponses}).
  5931. */
  5932. this.onPassword = null;
  5933. /**
  5934. * Callback to be able to monitor the loading progress of the PDF file
  5935. * (necessary to implement e.g. a loading bar). The callback receives
  5936. * an {Object} with the properties: {number} loaded and {number} total.
  5937. */
  5938. this.onProgress = null;
  5939. /**
  5940. * Callback to when unsupported feature is used. The callback receives
  5941. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  5942. */
  5943. this.onUnsupportedFeature = null;
  5944. }
  5945. PDFDocumentLoadingTask.prototype =
  5946. /** @lends PDFDocumentLoadingTask.prototype */ {
  5947. /**
  5948. * @return {Promise}
  5949. */
  5950. get promise() {
  5951. return this._capability.promise;
  5952. },
  5953. /**
  5954. * Aborts all network requests and destroys worker.
  5955. * @return {Promise} A promise that is resolved after destruction activity
  5956. * is completed.
  5957. */
  5958. destroy: function () {
  5959. this.destroyed = true;
  5960. var transportDestroyed = !this._transport ? Promise.resolve() :
  5961. this._transport.destroy();
  5962. return transportDestroyed.then(function () {
  5963. this._transport = null;
  5964. if (this._worker) {
  5965. this._worker.destroy();
  5966. this._worker = null;
  5967. }
  5968. }.bind(this));
  5969. },
  5970. /**
  5971. * Registers callbacks to indicate the document loading completion.
  5972. *
  5973. * @param {function} onFulfilled The callback for the loading completion.
  5974. * @param {function} onRejected The callback for the loading failure.
  5975. * @return {Promise} A promise that is resolved after the onFulfilled or
  5976. * onRejected callback.
  5977. */
  5978. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  5979. return this.promise.then.apply(this.promise, arguments);
  5980. }
  5981. };
  5982. return PDFDocumentLoadingTask;
  5983. })();
  5984. /**
  5985. * Abstract class to support range requests file loading.
  5986. * @class
  5987. * @alias PDFJS.PDFDataRangeTransport
  5988. * @param {number} length
  5989. * @param {Uint8Array} initialData
  5990. */
  5991. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  5992. function PDFDataRangeTransport(length, initialData) {
  5993. this.length = length;
  5994. this.initialData = initialData;
  5995. this._rangeListeners = [];
  5996. this._progressListeners = [];
  5997. this._progressiveReadListeners = [];
  5998. this._readyCapability = createPromiseCapability();
  5999. }
  6000. PDFDataRangeTransport.prototype =
  6001. /** @lends PDFDataRangeTransport.prototype */ {
  6002. addRangeListener:
  6003. function PDFDataRangeTransport_addRangeListener(listener) {
  6004. this._rangeListeners.push(listener);
  6005. },
  6006. addProgressListener:
  6007. function PDFDataRangeTransport_addProgressListener(listener) {
  6008. this._progressListeners.push(listener);
  6009. },
  6010. addProgressiveReadListener:
  6011. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  6012. this._progressiveReadListeners.push(listener);
  6013. },
  6014. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  6015. var listeners = this._rangeListeners;
  6016. for (var i = 0, n = listeners.length; i < n; ++i) {
  6017. listeners[i](begin, chunk);
  6018. }
  6019. },
  6020. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  6021. this._readyCapability.promise.then(function () {
  6022. var listeners = this._progressListeners;
  6023. for (var i = 0, n = listeners.length; i < n; ++i) {
  6024. listeners[i](loaded);
  6025. }
  6026. }.bind(this));
  6027. },
  6028. onDataProgressiveRead:
  6029. function PDFDataRangeTransport_onDataProgress(chunk) {
  6030. this._readyCapability.promise.then(function () {
  6031. var listeners = this._progressiveReadListeners;
  6032. for (var i = 0, n = listeners.length; i < n; ++i) {
  6033. listeners[i](chunk);
  6034. }
  6035. }.bind(this));
  6036. },
  6037. transportReady: function PDFDataRangeTransport_transportReady() {
  6038. this._readyCapability.resolve();
  6039. },
  6040. requestDataRange:
  6041. function PDFDataRangeTransport_requestDataRange(begin, end) {
  6042. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  6043. },
  6044. abort: function PDFDataRangeTransport_abort() {
  6045. }
  6046. };
  6047. return PDFDataRangeTransport;
  6048. })();
  6049. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  6050. /**
  6051. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  6052. * properties that can be read synchronously.
  6053. * @class
  6054. * @alias PDFDocumentProxy
  6055. */
  6056. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  6057. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  6058. this.pdfInfo = pdfInfo;
  6059. this.transport = transport;
  6060. this.loadingTask = loadingTask;
  6061. }
  6062. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  6063. /**
  6064. * @return {number} Total number of pages the PDF contains.
  6065. */
  6066. get numPages() {
  6067. return this.pdfInfo.numPages;
  6068. },
  6069. /**
  6070. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  6071. * unique.
  6072. */
  6073. get fingerprint() {
  6074. return this.pdfInfo.fingerprint;
  6075. },
  6076. /**
  6077. * @param {number} pageNumber The page number to get. The first page is 1.
  6078. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  6079. * object.
  6080. */
  6081. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  6082. return this.transport.getPage(pageNumber);
  6083. },
  6084. /**
  6085. * @param {{num: number, gen: number}} ref The page reference. Must have
  6086. * the 'num' and 'gen' properties.
  6087. * @return {Promise} A promise that is resolved with the page index that is
  6088. * associated with the reference.
  6089. */
  6090. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  6091. return this.transport.getPageIndex(ref);
  6092. },
  6093. /**
  6094. * @return {Promise} A promise that is resolved with a lookup table for
  6095. * mapping named destinations to reference numbers.
  6096. *
  6097. * This can be slow for large documents: use getDestination instead
  6098. */
  6099. getDestinations: function PDFDocumentProxy_getDestinations() {
  6100. return this.transport.getDestinations();
  6101. },
  6102. /**
  6103. * @param {string} id The named destination to get.
  6104. * @return {Promise} A promise that is resolved with all information
  6105. * of the given named destination.
  6106. */
  6107. getDestination: function PDFDocumentProxy_getDestination(id) {
  6108. return this.transport.getDestination(id);
  6109. },
  6110. /**
  6111. * @return {Promise} A promise that is resolved with a lookup table for
  6112. * mapping named attachments to their content.
  6113. */
  6114. getAttachments: function PDFDocumentProxy_getAttachments() {
  6115. return this.transport.getAttachments();
  6116. },
  6117. /**
  6118. * @return {Promise} A promise that is resolved with an array of all the
  6119. * JavaScript strings in the name tree.
  6120. */
  6121. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  6122. return this.transport.getJavaScript();
  6123. },
  6124. /**
  6125. * @return {Promise} A promise that is resolved with an {Array} that is a
  6126. * tree outline (if it has one) of the PDF. The tree is in the format of:
  6127. * [
  6128. * {
  6129. * title: string,
  6130. * bold: boolean,
  6131. * italic: boolean,
  6132. * color: rgb array,
  6133. * dest: dest obj,
  6134. * items: array of more items like this
  6135. * },
  6136. * ...
  6137. * ].
  6138. */
  6139. getOutline: function PDFDocumentProxy_getOutline() {
  6140. return this.transport.getOutline();
  6141. },
  6142. /**
  6143. * @return {Promise} A promise that is resolved with an {Object} that has
  6144. * info and metadata properties. Info is an {Object} filled with anything
  6145. * available in the information dictionary and similarly metadata is a
  6146. * {Metadata} object with information from the metadata section of the PDF.
  6147. */
  6148. getMetadata: function PDFDocumentProxy_getMetadata() {
  6149. return this.transport.getMetadata();
  6150. },
  6151. /**
  6152. * @return {Promise} A promise that is resolved with a TypedArray that has
  6153. * the raw data from the PDF.
  6154. */
  6155. getData: function PDFDocumentProxy_getData() {
  6156. return this.transport.getData();
  6157. },
  6158. /**
  6159. * @return {Promise} A promise that is resolved when the document's data
  6160. * is loaded. It is resolved with an {Object} that contains the length
  6161. * property that indicates size of the PDF data in bytes.
  6162. */
  6163. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  6164. return this.transport.downloadInfoCapability.promise;
  6165. },
  6166. /**
  6167. * @return {Promise} A promise this is resolved with current stats about
  6168. * document structures (see {@link PDFDocumentStats}).
  6169. */
  6170. getStats: function PDFDocumentProxy_getStats() {
  6171. return this.transport.getStats();
  6172. },
  6173. /**
  6174. * Cleans up resources allocated by the document, e.g. created @font-face.
  6175. */
  6176. cleanup: function PDFDocumentProxy_cleanup() {
  6177. this.transport.startCleanup();
  6178. },
  6179. /**
  6180. * Destroys current document instance and terminates worker.
  6181. */
  6182. destroy: function PDFDocumentProxy_destroy() {
  6183. return this.loadingTask.destroy();
  6184. }
  6185. };
  6186. return PDFDocumentProxy;
  6187. })();
  6188. /**
  6189. * Page getTextContent parameters.
  6190. *
  6191. * @typedef {Object} getTextContentParameters
  6192. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  6193. * whitespace with standard spaces (0x20). The default value is `false`.
  6194. */
  6195. /**
  6196. * Page text content.
  6197. *
  6198. * @typedef {Object} TextContent
  6199. * @property {array} items - array of {@link TextItem}
  6200. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  6201. * name.
  6202. */
  6203. /**
  6204. * Page text content part.
  6205. *
  6206. * @typedef {Object} TextItem
  6207. * @property {string} str - text content.
  6208. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  6209. * @property {array} transform - transformation matrix.
  6210. * @property {number} width - width in device space.
  6211. * @property {number} height - height in device space.
  6212. * @property {string} fontName - font name used by pdf.js for converted font.
  6213. */
  6214. /**
  6215. * Text style.
  6216. *
  6217. * @typedef {Object} TextStyle
  6218. * @property {number} ascent - font ascent.
  6219. * @property {number} descent - font descent.
  6220. * @property {boolean} vertical - text is in vertical mode.
  6221. * @property {string} fontFamily - possible font family
  6222. */
  6223. /**
  6224. * Page annotation parameters.
  6225. *
  6226. * @typedef {Object} GetAnnotationsParameters
  6227. * @param {string} intent - Determines the annotations that will be fetched,
  6228. * can be either 'display' (viewable annotations) or 'print'
  6229. * (printable annotations).
  6230. * If the parameter is omitted, all annotations are fetched.
  6231. */
  6232. /**
  6233. * Page render parameters.
  6234. *
  6235. * @typedef {Object} RenderParameters
  6236. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  6237. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  6238. * calling of PDFPage.getViewport method.
  6239. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  6240. * (default value is 'display').
  6241. * @property {Array} transform - (optional) Additional transform, applied
  6242. * just before viewport transform.
  6243. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  6244. * endLayout and appendImage functions.
  6245. * @property {function} continueCallback - (deprecated) A function that will be
  6246. * called each time the rendering is paused. To continue
  6247. * rendering call the function that is the first argument
  6248. * to the callback.
  6249. */
  6250. /**
  6251. * PDF page operator list.
  6252. *
  6253. * @typedef {Object} PDFOperatorList
  6254. * @property {Array} fnArray - Array containing the operator functions.
  6255. * @property {Array} argsArray - Array containing the arguments of the
  6256. * functions.
  6257. */
  6258. /**
  6259. * Proxy to a PDFPage in the worker thread.
  6260. * @class
  6261. * @alias PDFPageProxy
  6262. */
  6263. var PDFPageProxy = (function PDFPageProxyClosure() {
  6264. function PDFPageProxy(pageIndex, pageInfo, transport) {
  6265. this.pageIndex = pageIndex;
  6266. this.pageInfo = pageInfo;
  6267. this.transport = transport;
  6268. this.stats = new StatTimer();
  6269. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  6270. this.commonObjs = transport.commonObjs;
  6271. this.objs = new PDFObjects();
  6272. this.cleanupAfterRender = false;
  6273. this.pendingCleanup = false;
  6274. this.intentStates = {};
  6275. this.destroyed = false;
  6276. }
  6277. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  6278. /**
  6279. * @return {number} Page number of the page. First page is 1.
  6280. */
  6281. get pageNumber() {
  6282. return this.pageIndex + 1;
  6283. },
  6284. /**
  6285. * @return {number} The number of degrees the page is rotated clockwise.
  6286. */
  6287. get rotate() {
  6288. return this.pageInfo.rotate;
  6289. },
  6290. /**
  6291. * @return {Object} The reference that points to this page. It has 'num' and
  6292. * 'gen' properties.
  6293. */
  6294. get ref() {
  6295. return this.pageInfo.ref;
  6296. },
  6297. /**
  6298. * @return {Array} An array of the visible portion of the PDF page in the
  6299. * user space units - [x1, y1, x2, y2].
  6300. */
  6301. get view() {
  6302. return this.pageInfo.view;
  6303. },
  6304. /**
  6305. * @param {number} scale The desired scale of the viewport.
  6306. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  6307. * defaults to the page rotation.
  6308. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  6309. * along with transforms required for rendering.
  6310. */
  6311. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  6312. if (arguments.length < 2) {
  6313. rotate = this.rotate;
  6314. }
  6315. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  6316. },
  6317. /**
  6318. * @param {GetAnnotationsParameters} params - Annotation parameters.
  6319. * @return {Promise} A promise that is resolved with an {Array} of the
  6320. * annotation objects.
  6321. */
  6322. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  6323. var intent = (params && params.intent) || null;
  6324. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  6325. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  6326. intent);
  6327. this.annotationsIntent = intent;
  6328. }
  6329. return this.annotationsPromise;
  6330. },
  6331. /**
  6332. * Begins the process of rendering a page to the desired context.
  6333. * @param {RenderParameters} params Page render parameters.
  6334. * @return {RenderTask} An object that contains the promise, which
  6335. * is resolved when the page finishes rendering.
  6336. */
  6337. render: function PDFPageProxy_render(params) {
  6338. var stats = this.stats;
  6339. stats.time('Overall');
  6340. // If there was a pending destroy cancel it so no cleanup happens during
  6341. // this call to render.
  6342. this.pendingCleanup = false;
  6343. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  6344. if (!this.intentStates[renderingIntent]) {
  6345. this.intentStates[renderingIntent] = {};
  6346. }
  6347. var intentState = this.intentStates[renderingIntent];
  6348. // If there's no displayReadyCapability yet, then the operatorList
  6349. // was never requested before. Make the request and create the promise.
  6350. if (!intentState.displayReadyCapability) {
  6351. intentState.receivingOperatorList = true;
  6352. intentState.displayReadyCapability = createPromiseCapability();
  6353. intentState.operatorList = {
  6354. fnArray: [],
  6355. argsArray: [],
  6356. lastChunk: false
  6357. };
  6358. this.stats.time('Page Request');
  6359. this.transport.messageHandler.send('RenderPageRequest', {
  6360. pageIndex: this.pageNumber - 1,
  6361. intent: renderingIntent
  6362. });
  6363. }
  6364. var internalRenderTask = new InternalRenderTask(complete, params,
  6365. this.objs,
  6366. this.commonObjs,
  6367. intentState.operatorList,
  6368. this.pageNumber);
  6369. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  6370. if (!intentState.renderTasks) {
  6371. intentState.renderTasks = [];
  6372. }
  6373. intentState.renderTasks.push(internalRenderTask);
  6374. var renderTask = internalRenderTask.task;
  6375. // Obsolete parameter support
  6376. if (params.continueCallback) {
  6377. deprecated('render is used with continueCallback parameter');
  6378. renderTask.onContinue = params.continueCallback;
  6379. }
  6380. var self = this;
  6381. intentState.displayReadyCapability.promise.then(
  6382. function pageDisplayReadyPromise(transparency) {
  6383. if (self.pendingCleanup) {
  6384. complete();
  6385. return;
  6386. }
  6387. stats.time('Rendering');
  6388. internalRenderTask.initalizeGraphics(transparency);
  6389. internalRenderTask.operatorListChanged();
  6390. },
  6391. function pageDisplayReadPromiseError(reason) {
  6392. complete(reason);
  6393. }
  6394. );
  6395. function complete(error) {
  6396. var i = intentState.renderTasks.indexOf(internalRenderTask);
  6397. if (i >= 0) {
  6398. intentState.renderTasks.splice(i, 1);
  6399. }
  6400. if (self.cleanupAfterRender) {
  6401. self.pendingCleanup = true;
  6402. }
  6403. self._tryCleanup();
  6404. if (error) {
  6405. internalRenderTask.capability.reject(error);
  6406. } else {
  6407. internalRenderTask.capability.resolve();
  6408. }
  6409. stats.timeEnd('Rendering');
  6410. stats.timeEnd('Overall');
  6411. }
  6412. return renderTask;
  6413. },
  6414. /**
  6415. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  6416. * object that represents page's operator list.
  6417. */
  6418. getOperatorList: function PDFPageProxy_getOperatorList() {
  6419. function operatorListChanged() {
  6420. if (intentState.operatorList.lastChunk) {
  6421. intentState.opListReadCapability.resolve(intentState.operatorList);
  6422. }
  6423. }
  6424. var renderingIntent = 'oplist';
  6425. if (!this.intentStates[renderingIntent]) {
  6426. this.intentStates[renderingIntent] = {};
  6427. }
  6428. var intentState = this.intentStates[renderingIntent];
  6429. if (!intentState.opListReadCapability) {
  6430. var opListTask = {};
  6431. opListTask.operatorListChanged = operatorListChanged;
  6432. intentState.receivingOperatorList = true;
  6433. intentState.opListReadCapability = createPromiseCapability();
  6434. intentState.renderTasks = [];
  6435. intentState.renderTasks.push(opListTask);
  6436. intentState.operatorList = {
  6437. fnArray: [],
  6438. argsArray: [],
  6439. lastChunk: false
  6440. };
  6441. this.transport.messageHandler.send('RenderPageRequest', {
  6442. pageIndex: this.pageIndex,
  6443. intent: renderingIntent
  6444. });
  6445. }
  6446. return intentState.opListReadCapability.promise;
  6447. },
  6448. /**
  6449. * @param {getTextContentParameters} params - getTextContent parameters.
  6450. * @return {Promise} That is resolved a {@link TextContent}
  6451. * object that represent the page text content.
  6452. */
  6453. getTextContent: function PDFPageProxy_getTextContent(params) {
  6454. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  6455. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  6456. pageIndex: this.pageNumber - 1,
  6457. normalizeWhitespace: normalizeWhitespace,
  6458. });
  6459. },
  6460. /**
  6461. * Destroys page object.
  6462. */
  6463. _destroy: function PDFPageProxy_destroy() {
  6464. this.destroyed = true;
  6465. this.transport.pageCache[this.pageIndex] = null;
  6466. var waitOn = [];
  6467. Object.keys(this.intentStates).forEach(function(intent) {
  6468. var intentState = this.intentStates[intent];
  6469. intentState.renderTasks.forEach(function(renderTask) {
  6470. var renderCompleted = renderTask.capability.promise.
  6471. catch(function () {}); // ignoring failures
  6472. waitOn.push(renderCompleted);
  6473. renderTask.cancel();
  6474. });
  6475. }, this);
  6476. this.objs.clear();
  6477. this.annotationsPromise = null;
  6478. this.pendingCleanup = false;
  6479. return Promise.all(waitOn);
  6480. },
  6481. /**
  6482. * Cleans up resources allocated by the page. (deprecated)
  6483. */
  6484. destroy: function() {
  6485. deprecated('page destroy method, use cleanup() instead');
  6486. this.cleanup();
  6487. },
  6488. /**
  6489. * Cleans up resources allocated by the page.
  6490. */
  6491. cleanup: function PDFPageProxy_cleanup() {
  6492. this.pendingCleanup = true;
  6493. this._tryCleanup();
  6494. },
  6495. /**
  6496. * For internal use only. Attempts to clean up if rendering is in a state
  6497. * where that's possible.
  6498. * @ignore
  6499. */
  6500. _tryCleanup: function PDFPageProxy_tryCleanup() {
  6501. if (!this.pendingCleanup ||
  6502. Object.keys(this.intentStates).some(function(intent) {
  6503. var intentState = this.intentStates[intent];
  6504. return (intentState.renderTasks.length !== 0 ||
  6505. intentState.receivingOperatorList);
  6506. }, this)) {
  6507. return;
  6508. }
  6509. Object.keys(this.intentStates).forEach(function(intent) {
  6510. delete this.intentStates[intent];
  6511. }, this);
  6512. this.objs.clear();
  6513. this.annotationsPromise = null;
  6514. this.pendingCleanup = false;
  6515. },
  6516. /**
  6517. * For internal use only.
  6518. * @ignore
  6519. */
  6520. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  6521. intent) {
  6522. var intentState = this.intentStates[intent];
  6523. // TODO Refactor RenderPageRequest to separate rendering
  6524. // and operator list logic
  6525. if (intentState.displayReadyCapability) {
  6526. intentState.displayReadyCapability.resolve(transparency);
  6527. }
  6528. },
  6529. /**
  6530. * For internal use only.
  6531. * @ignore
  6532. */
  6533. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  6534. intent) {
  6535. var intentState = this.intentStates[intent];
  6536. var i, ii;
  6537. // Add the new chunk to the current operator list.
  6538. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  6539. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  6540. intentState.operatorList.argsArray.push(
  6541. operatorListChunk.argsArray[i]);
  6542. }
  6543. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  6544. // Notify all the rendering tasks there are more operators to be consumed.
  6545. for (i = 0; i < intentState.renderTasks.length; i++) {
  6546. intentState.renderTasks[i].operatorListChanged();
  6547. }
  6548. if (operatorListChunk.lastChunk) {
  6549. intentState.receivingOperatorList = false;
  6550. this._tryCleanup();
  6551. }
  6552. }
  6553. };
  6554. return PDFPageProxy;
  6555. })();
  6556. /**
  6557. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  6558. * WorkerTransport for them. If creation of a web worker is not possible,
  6559. * a "fake" worker will be used instead.
  6560. * @class
  6561. */
  6562. var PDFWorker = (function PDFWorkerClosure() {
  6563. var nextFakeWorkerId = 0;
  6564. // Loads worker code into main thread.
  6565. function setupFakeWorkerGlobal() {
  6566. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  6567. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  6568. // In the developer build load worker_loader which in turn loads all the
  6569. // other files and resolves the promise. In production only the
  6570. // pdf.worker.js file is needed.
  6571. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  6572. }
  6573. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  6574. }
  6575. function PDFWorker(name) {
  6576. this.name = name;
  6577. this.destroyed = false;
  6578. this._readyCapability = createPromiseCapability();
  6579. this._port = null;
  6580. this._webWorker = null;
  6581. this._messageHandler = null;
  6582. this._initialize();
  6583. }
  6584. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  6585. get promise() {
  6586. return this._readyCapability.promise;
  6587. },
  6588. get port() {
  6589. return this._port;
  6590. },
  6591. get messageHandler() {
  6592. return this._messageHandler;
  6593. },
  6594. _initialize: function PDFWorker_initialize() {
  6595. // If worker support isn't disabled explicit and the browser has worker
  6596. // support, create a new web worker and test if it/the browser fullfills
  6597. // all requirements to run parts of pdf.js in a web worker.
  6598. // Right now, the requirement is, that an Uint8Array is still an
  6599. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  6600. // Either workers are disabled, not supported or have thrown an exception.
  6601. // Thus, we fallback to a faked worker.
  6602. this._setupFakeWorker();
  6603. },
  6604. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  6605. if (!globalScope.PDFJS.disableWorker) {
  6606. warn('Setting up fake worker.');
  6607. globalScope.PDFJS.disableWorker = true;
  6608. }
  6609. setupFakeWorkerGlobal().then(function () {
  6610. if (this.destroyed) {
  6611. this._readyCapability.reject(new Error('Worker was destroyed'));
  6612. return;
  6613. }
  6614. // If we don't use a worker, just post/sendMessage to the main thread.
  6615. var port = {
  6616. _listeners: [],
  6617. postMessage: function (obj) {
  6618. var e = {data: obj};
  6619. this._listeners.forEach(function (listener) {
  6620. listener.call(this, e);
  6621. }, this);
  6622. },
  6623. addEventListener: function (name, listener) {
  6624. this._listeners.push(listener);
  6625. },
  6626. removeEventListener: function (name, listener) {
  6627. var i = this._listeners.indexOf(listener);
  6628. this._listeners.splice(i, 1);
  6629. },
  6630. terminate: function () {}
  6631. };
  6632. this._port = port;
  6633. // All fake workers use the same port, making id unique.
  6634. var id = 'fake' + (nextFakeWorkerId++);
  6635. // If the main thread is our worker, setup the handling for the
  6636. // messages -- the main thread sends to it self.
  6637. var workerHandler = new MessageHandler(id + '_worker', id, port);
  6638. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  6639. var messageHandler = new MessageHandler(id, id + '_worker', port);
  6640. this._messageHandler = messageHandler;
  6641. this._readyCapability.resolve();
  6642. }.bind(this));
  6643. },
  6644. /**
  6645. * Destroys the worker instance.
  6646. */
  6647. destroy: function PDFWorker_destroy() {
  6648. this.destroyed = true;
  6649. if (this._webWorker) {
  6650. // We need to terminate only web worker created resource.
  6651. this._webWorker.terminate();
  6652. this._webWorker = null;
  6653. }
  6654. this._port = null;
  6655. if (this._messageHandler) {
  6656. this._messageHandler.destroy();
  6657. this._messageHandler = null;
  6658. }
  6659. }
  6660. };
  6661. return PDFWorker;
  6662. })();
  6663. PDFJS.PDFWorker = PDFWorker;
  6664. /**
  6665. * For internal use only.
  6666. * @ignore
  6667. */
  6668. var WorkerTransport = (function WorkerTransportClosure() {
  6669. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  6670. this.messageHandler = messageHandler;
  6671. this.loadingTask = loadingTask;
  6672. this.pdfDataRangeTransport = pdfDataRangeTransport;
  6673. this.commonObjs = new PDFObjects();
  6674. this.fontLoader = new FontLoader(loadingTask.docId);
  6675. this.destroyed = false;
  6676. this.destroyCapability = null;
  6677. this.pageCache = [];
  6678. this.pagePromises = [];
  6679. this.downloadInfoCapability = createPromiseCapability();
  6680. this.setupMessageHandler();
  6681. }
  6682. WorkerTransport.prototype = {
  6683. destroy: function WorkerTransport_destroy() {
  6684. if (this.destroyCapability) {
  6685. return this.destroyCapability.promise;
  6686. }
  6687. this.destroyed = true;
  6688. this.destroyCapability = createPromiseCapability();
  6689. var waitOn = [];
  6690. // We need to wait for all renderings to be completed, e.g.
  6691. // timeout/rAF can take a long time.
  6692. this.pageCache.forEach(function (page) {
  6693. if (page) {
  6694. waitOn.push(page._destroy());
  6695. }
  6696. });
  6697. this.pageCache = [];
  6698. this.pagePromises = [];
  6699. var self = this;
  6700. // We also need to wait for the worker to finish its long running tasks.
  6701. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  6702. waitOn.push(terminated);
  6703. Promise.all(waitOn).then(function () {
  6704. self.fontLoader.clear();
  6705. if (self.pdfDataRangeTransport) {
  6706. self.pdfDataRangeTransport.abort();
  6707. self.pdfDataRangeTransport = null;
  6708. }
  6709. if (self.messageHandler) {
  6710. self.messageHandler.destroy();
  6711. self.messageHandler = null;
  6712. }
  6713. self.destroyCapability.resolve();
  6714. }, this.destroyCapability.reject);
  6715. return this.destroyCapability.promise;
  6716. },
  6717. setupMessageHandler:
  6718. function WorkerTransport_setupMessageHandler() {
  6719. var messageHandler = this.messageHandler;
  6720. function updatePassword(password) {
  6721. messageHandler.send('UpdatePassword', password);
  6722. }
  6723. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  6724. if (pdfDataRangeTransport) {
  6725. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  6726. messageHandler.send('OnDataRange', {
  6727. begin: begin,
  6728. chunk: chunk
  6729. });
  6730. });
  6731. pdfDataRangeTransport.addProgressListener(function(loaded) {
  6732. messageHandler.send('OnDataProgress', {
  6733. loaded: loaded
  6734. });
  6735. });
  6736. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  6737. messageHandler.send('OnDataRange', {
  6738. chunk: chunk
  6739. });
  6740. });
  6741. messageHandler.on('RequestDataRange',
  6742. function transportDataRange(data) {
  6743. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  6744. }, this);
  6745. }
  6746. messageHandler.on('GetDoc', function transportDoc(data) {
  6747. var pdfInfo = data.pdfInfo;
  6748. this.numPages = data.pdfInfo.numPages;
  6749. var loadingTask = this.loadingTask;
  6750. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  6751. this.pdfDocument = pdfDocument;
  6752. loadingTask._capability.resolve(pdfDocument);
  6753. }, this);
  6754. messageHandler.on('NeedPassword',
  6755. function transportNeedPassword(exception) {
  6756. var loadingTask = this.loadingTask;
  6757. if (loadingTask.onPassword) {
  6758. return loadingTask.onPassword(updatePassword,
  6759. PasswordResponses.NEED_PASSWORD);
  6760. }
  6761. loadingTask._capability.reject(
  6762. new PasswordException(exception.message, exception.code));
  6763. }, this);
  6764. messageHandler.on('IncorrectPassword',
  6765. function transportIncorrectPassword(exception) {
  6766. var loadingTask = this.loadingTask;
  6767. if (loadingTask.onPassword) {
  6768. return loadingTask.onPassword(updatePassword,
  6769. PasswordResponses.INCORRECT_PASSWORD);
  6770. }
  6771. loadingTask._capability.reject(
  6772. new PasswordException(exception.message, exception.code));
  6773. }, this);
  6774. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  6775. this.loadingTask._capability.reject(
  6776. new InvalidPDFException(exception.message));
  6777. }, this);
  6778. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  6779. this.loadingTask._capability.reject(
  6780. new MissingPDFException(exception.message));
  6781. }, this);
  6782. messageHandler.on('UnexpectedResponse',
  6783. function transportUnexpectedResponse(exception) {
  6784. this.loadingTask._capability.reject(
  6785. new UnexpectedResponseException(exception.message, exception.status));
  6786. }, this);
  6787. messageHandler.on('UnknownError',
  6788. function transportUnknownError(exception) {
  6789. this.loadingTask._capability.reject(
  6790. new UnknownErrorException(exception.message, exception.details));
  6791. }, this);
  6792. messageHandler.on('DataLoaded', function transportPage(data) {
  6793. this.downloadInfoCapability.resolve(data);
  6794. }, this);
  6795. messageHandler.on('PDFManagerReady', function transportPage(data) {
  6796. if (this.pdfDataRangeTransport) {
  6797. this.pdfDataRangeTransport.transportReady();
  6798. }
  6799. }, this);
  6800. messageHandler.on('StartRenderPage', function transportRender(data) {
  6801. if (this.destroyed) {
  6802. return; // Ignore any pending requests if the worker was terminated.
  6803. }
  6804. var page = this.pageCache[data.pageIndex];
  6805. page.stats.timeEnd('Page Request');
  6806. page._startRenderPage(data.transparency, data.intent);
  6807. }, this);
  6808. messageHandler.on('RenderPageChunk', function transportRender(data) {
  6809. if (this.destroyed) {
  6810. return; // Ignore any pending requests if the worker was terminated.
  6811. }
  6812. var page = this.pageCache[data.pageIndex];
  6813. page._renderPageChunk(data.operatorList, data.intent);
  6814. }, this);
  6815. messageHandler.on('commonobj', function transportObj(data) {
  6816. if (this.destroyed) {
  6817. return; // Ignore any pending requests if the worker was terminated.
  6818. }
  6819. var id = data[0];
  6820. var type = data[1];
  6821. if (this.commonObjs.hasData(id)) {
  6822. return;
  6823. }
  6824. switch (type) {
  6825. case 'Font':
  6826. var exportedData = data[2];
  6827. var font;
  6828. if ('error' in exportedData) {
  6829. var error = exportedData.error;
  6830. warn('Error during font loading: ' + error);
  6831. this.commonObjs.resolve(id, error);
  6832. break;
  6833. } else {
  6834. font = new FontFaceObject(exportedData);
  6835. }
  6836. this.fontLoader.bind(
  6837. [font],
  6838. function fontReady(fontObjs) {
  6839. this.commonObjs.resolve(id, font);
  6840. }.bind(this)
  6841. );
  6842. break;
  6843. case 'FontPath':
  6844. this.commonObjs.resolve(id, data[2]);
  6845. break;
  6846. default:
  6847. error('Got unknown common object type ' + type);
  6848. }
  6849. }, this);
  6850. messageHandler.on('obj', function transportObj(data) {
  6851. if (this.destroyed) {
  6852. return; // Ignore any pending requests if the worker was terminated.
  6853. }
  6854. var id = data[0];
  6855. var pageIndex = data[1];
  6856. var type = data[2];
  6857. var pageProxy = this.pageCache[pageIndex];
  6858. var imageData;
  6859. if (pageProxy.objs.hasData(id)) {
  6860. return;
  6861. }
  6862. switch (type) {
  6863. case 'JpegStream':
  6864. imageData = data[3];
  6865. loadJpegStream(id, imageData, pageProxy.objs);
  6866. break;
  6867. case 'Image':
  6868. imageData = data[3];
  6869. pageProxy.objs.resolve(id, imageData);
  6870. // heuristics that will allow not to store large data
  6871. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  6872. if (imageData && 'data' in imageData &&
  6873. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  6874. pageProxy.cleanupAfterRender = true;
  6875. }
  6876. break;
  6877. default:
  6878. error('Got unknown object type ' + type);
  6879. }
  6880. }, this);
  6881. messageHandler.on('DocProgress', function transportDocProgress(data) {
  6882. if (this.destroyed) {
  6883. return; // Ignore any pending requests if the worker was terminated.
  6884. }
  6885. var loadingTask = this.loadingTask;
  6886. if (loadingTask.onProgress) {
  6887. loadingTask.onProgress({
  6888. loaded: data.loaded,
  6889. total: data.total
  6890. });
  6891. }
  6892. }, this);
  6893. messageHandler.on('PageError', function transportError(data) {
  6894. if (this.destroyed) {
  6895. return; // Ignore any pending requests if the worker was terminated.
  6896. }
  6897. var page = this.pageCache[data.pageNum - 1];
  6898. var intentState = page.intentStates[data.intent];
  6899. if (intentState.displayReadyCapability) {
  6900. intentState.displayReadyCapability.reject(data.error);
  6901. } else {
  6902. error(data.error);
  6903. }
  6904. }, this);
  6905. messageHandler.on('UnsupportedFeature',
  6906. function transportUnsupportedFeature(data) {
  6907. if (this.destroyed) {
  6908. return; // Ignore any pending requests if the worker was terminated.
  6909. }
  6910. var featureId = data.featureId;
  6911. var loadingTask = this.loadingTask;
  6912. if (loadingTask.onUnsupportedFeature) {
  6913. loadingTask.onUnsupportedFeature(featureId);
  6914. }
  6915. PDFJS.UnsupportedManager.notify(featureId);
  6916. }, this);
  6917. messageHandler.on('JpegDecode', function(data) {
  6918. if (this.destroyed) {
  6919. return Promise.reject('Worker was terminated');
  6920. }
  6921. var imageUrl = data[0];
  6922. var components = data[1];
  6923. if (components !== 3 && components !== 1) {
  6924. return Promise.reject(
  6925. new Error('Only 3 components or 1 component can be returned'));
  6926. }
  6927. return new Promise(function (resolve, reject) {
  6928. var img = new Image();
  6929. img.onload = function () {
  6930. var width = img.width;
  6931. var height = img.height;
  6932. var size = width * height;
  6933. var rgbaLength = size * 4;
  6934. var buf = new Uint8Array(size * components);
  6935. var tmpCanvas = createScratchCanvas(width, height);
  6936. var tmpCtx = tmpCanvas.getContext('2d');
  6937. tmpCtx.drawImage(img, 0, 0);
  6938. var data = tmpCtx.getImageData(0, 0, width, height).data;
  6939. var i, j;
  6940. if (components === 3) {
  6941. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  6942. buf[j] = data[i];
  6943. buf[j + 1] = data[i + 1];
  6944. buf[j + 2] = data[i + 2];
  6945. }
  6946. } else if (components === 1) {
  6947. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  6948. buf[j] = data[i];
  6949. }
  6950. }
  6951. resolve({ data: buf, width: width, height: height});
  6952. };
  6953. img.onerror = function () {
  6954. reject(new Error('JpegDecode failed to load image'));
  6955. };
  6956. img.src = imageUrl;
  6957. });
  6958. }, this);
  6959. },
  6960. getData: function WorkerTransport_getData() {
  6961. return this.messageHandler.sendWithPromise('GetData', null);
  6962. },
  6963. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  6964. if (pageNumber <= 0 || pageNumber > this.numPages ||
  6965. (pageNumber|0) !== pageNumber) {
  6966. return Promise.reject(new Error('Invalid page request'));
  6967. }
  6968. var pageIndex = pageNumber - 1;
  6969. if (pageIndex in this.pagePromises) {
  6970. return this.pagePromises[pageIndex];
  6971. }
  6972. var promise = this.messageHandler.sendWithPromise('GetPage', {
  6973. pageIndex: pageIndex
  6974. }).then(function (pageInfo) {
  6975. if (this.destroyed) {
  6976. throw new Error('Transport destroyed');
  6977. }
  6978. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  6979. this.pageCache[pageIndex] = page;
  6980. return page;
  6981. }.bind(this));
  6982. this.pagePromises[pageIndex] = promise;
  6983. return promise;
  6984. },
  6985. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  6986. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  6987. },
  6988. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  6989. return this.messageHandler.sendWithPromise('GetAnnotations', {
  6990. pageIndex: pageIndex,
  6991. intent: intent,
  6992. });
  6993. },
  6994. getDestinations: function WorkerTransport_getDestinations() {
  6995. return this.messageHandler.sendWithPromise('GetDestinations', null);
  6996. },
  6997. getDestination: function WorkerTransport_getDestination(id) {
  6998. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  6999. },
  7000. getAttachments: function WorkerTransport_getAttachments() {
  7001. return this.messageHandler.sendWithPromise('GetAttachments', null);
  7002. },
  7003. getJavaScript: function WorkerTransport_getJavaScript() {
  7004. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  7005. },
  7006. getOutline: function WorkerTransport_getOutline() {
  7007. return this.messageHandler.sendWithPromise('GetOutline', null);
  7008. },
  7009. getMetadata: function WorkerTransport_getMetadata() {
  7010. return this.messageHandler.sendWithPromise('GetMetadata', null).
  7011. then(function transportMetadata(results) {
  7012. return {
  7013. info: results[0],
  7014. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  7015. };
  7016. });
  7017. },
  7018. getStats: function WorkerTransport_getStats() {
  7019. return this.messageHandler.sendWithPromise('GetStats', null);
  7020. },
  7021. startCleanup: function WorkerTransport_startCleanup() {
  7022. this.messageHandler.sendWithPromise('Cleanup', null).
  7023. then(function endCleanup() {
  7024. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  7025. var page = this.pageCache[i];
  7026. if (page) {
  7027. page.cleanup();
  7028. }
  7029. }
  7030. this.commonObjs.clear();
  7031. this.fontLoader.clear();
  7032. }.bind(this));
  7033. }
  7034. };
  7035. return WorkerTransport;
  7036. })();
  7037. /**
  7038. * A PDF document and page is built of many objects. E.g. there are objects
  7039. * for fonts, images, rendering code and such. These objects might get processed
  7040. * inside of a worker. The `PDFObjects` implements some basic functions to
  7041. * manage these objects.
  7042. * @ignore
  7043. */
  7044. var PDFObjects = (function PDFObjectsClosure() {
  7045. function PDFObjects() {
  7046. this.objs = {};
  7047. }
  7048. PDFObjects.prototype = {
  7049. /**
  7050. * Internal function.
  7051. * Ensures there is an object defined for `objId`.
  7052. */
  7053. ensureObj: function PDFObjects_ensureObj(objId) {
  7054. if (this.objs[objId]) {
  7055. return this.objs[objId];
  7056. }
  7057. var obj = {
  7058. capability: createPromiseCapability(),
  7059. data: null,
  7060. resolved: false
  7061. };
  7062. this.objs[objId] = obj;
  7063. return obj;
  7064. },
  7065. /**
  7066. * If called *without* callback, this returns the data of `objId` but the
  7067. * object needs to be resolved. If it isn't, this function throws.
  7068. *
  7069. * If called *with* a callback, the callback is called with the data of the
  7070. * object once the object is resolved. That means, if you call this
  7071. * function and the object is already resolved, the callback gets called
  7072. * right away.
  7073. */
  7074. get: function PDFObjects_get(objId, callback) {
  7075. // If there is a callback, then the get can be async and the object is
  7076. // not required to be resolved right now
  7077. if (callback) {
  7078. this.ensureObj(objId).capability.promise.then(callback);
  7079. return null;
  7080. }
  7081. // If there isn't a callback, the user expects to get the resolved data
  7082. // directly.
  7083. var obj = this.objs[objId];
  7084. // If there isn't an object yet or the object isn't resolved, then the
  7085. // data isn't ready yet!
  7086. if (!obj || !obj.resolved) {
  7087. error('Requesting object that isn\'t resolved yet ' + objId);
  7088. }
  7089. return obj.data;
  7090. },
  7091. /**
  7092. * Resolves the object `objId` with optional `data`.
  7093. */
  7094. resolve: function PDFObjects_resolve(objId, data) {
  7095. var obj = this.ensureObj(objId);
  7096. obj.resolved = true;
  7097. obj.data = data;
  7098. obj.capability.resolve(data);
  7099. },
  7100. isResolved: function PDFObjects_isResolved(objId) {
  7101. var objs = this.objs;
  7102. if (!objs[objId]) {
  7103. return false;
  7104. } else {
  7105. return objs[objId].resolved;
  7106. }
  7107. },
  7108. hasData: function PDFObjects_hasData(objId) {
  7109. return this.isResolved(objId);
  7110. },
  7111. /**
  7112. * Returns the data of `objId` if object exists, null otherwise.
  7113. */
  7114. getData: function PDFObjects_getData(objId) {
  7115. var objs = this.objs;
  7116. if (!objs[objId] || !objs[objId].resolved) {
  7117. return null;
  7118. } else {
  7119. return objs[objId].data;
  7120. }
  7121. },
  7122. clear: function PDFObjects_clear() {
  7123. this.objs = {};
  7124. }
  7125. };
  7126. return PDFObjects;
  7127. })();
  7128. /**
  7129. * Allows controlling of the rendering tasks.
  7130. * @class
  7131. * @alias RenderTask
  7132. */
  7133. var RenderTask = (function RenderTaskClosure() {
  7134. function RenderTask(internalRenderTask) {
  7135. this._internalRenderTask = internalRenderTask;
  7136. /**
  7137. * Callback for incremental rendering -- a function that will be called
  7138. * each time the rendering is paused. To continue rendering call the
  7139. * function that is the first argument to the callback.
  7140. * @type {function}
  7141. */
  7142. this.onContinue = null;
  7143. }
  7144. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  7145. /**
  7146. * Promise for rendering task completion.
  7147. * @return {Promise}
  7148. */
  7149. get promise() {
  7150. return this._internalRenderTask.capability.promise;
  7151. },
  7152. /**
  7153. * Cancels the rendering task. If the task is currently rendering it will
  7154. * not be cancelled until graphics pauses with a timeout. The promise that
  7155. * this object extends will resolved when cancelled.
  7156. */
  7157. cancel: function RenderTask_cancel() {
  7158. this._internalRenderTask.cancel();
  7159. },
  7160. /**
  7161. * Registers callbacks to indicate the rendering task completion.
  7162. *
  7163. * @param {function} onFulfilled The callback for the rendering completion.
  7164. * @param {function} onRejected The callback for the rendering failure.
  7165. * @return {Promise} A promise that is resolved after the onFulfilled or
  7166. * onRejected callback.
  7167. */
  7168. then: function RenderTask_then(onFulfilled, onRejected) {
  7169. return this.promise.then.apply(this.promise, arguments);
  7170. }
  7171. };
  7172. return RenderTask;
  7173. })();
  7174. /**
  7175. * For internal use only.
  7176. * @ignore
  7177. */
  7178. var InternalRenderTask = (function InternalRenderTaskClosure() {
  7179. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  7180. pageNumber) {
  7181. this.callback = callback;
  7182. this.params = params;
  7183. this.objs = objs;
  7184. this.commonObjs = commonObjs;
  7185. this.operatorListIdx = null;
  7186. this.operatorList = operatorList;
  7187. this.pageNumber = pageNumber;
  7188. this.running = false;
  7189. this.graphicsReadyCallback = null;
  7190. this.graphicsReady = false;
  7191. this.useRequestAnimationFrame = false;
  7192. this.cancelled = false;
  7193. this.capability = createPromiseCapability();
  7194. this.task = new RenderTask(this);
  7195. // caching this-bound methods
  7196. this._continueBound = this._continue.bind(this);
  7197. this._scheduleNextBound = this._scheduleNext.bind(this);
  7198. this._nextBound = this._next.bind(this);
  7199. }
  7200. InternalRenderTask.prototype = {
  7201. initalizeGraphics:
  7202. function InternalRenderTask_initalizeGraphics(transparency) {
  7203. if (this.cancelled) {
  7204. return;
  7205. }
  7206. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  7207. globalScope.StepperManager.enabled) {
  7208. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  7209. this.stepper.init(this.operatorList);
  7210. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  7211. }
  7212. var params = this.params;
  7213. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  7214. this.objs, params.imageLayer);
  7215. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  7216. this.operatorListIdx = 0;
  7217. this.graphicsReady = true;
  7218. if (this.graphicsReadyCallback) {
  7219. this.graphicsReadyCallback();
  7220. }
  7221. },
  7222. cancel: function InternalRenderTask_cancel() {
  7223. this.running = false;
  7224. this.cancelled = true;
  7225. this.callback('cancelled');
  7226. },
  7227. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  7228. if (!this.graphicsReady) {
  7229. if (!this.graphicsReadyCallback) {
  7230. this.graphicsReadyCallback = this._continueBound;
  7231. }
  7232. return;
  7233. }
  7234. if (this.stepper) {
  7235. this.stepper.updateOperatorList(this.operatorList);
  7236. }
  7237. if (this.running) {
  7238. return;
  7239. }
  7240. this._continue();
  7241. },
  7242. _continue: function InternalRenderTask__continue() {
  7243. this.running = true;
  7244. if (this.cancelled) {
  7245. return;
  7246. }
  7247. if (this.task.onContinue) {
  7248. this.task.onContinue.call(this.task, this._scheduleNextBound);
  7249. } else {
  7250. this._scheduleNext();
  7251. }
  7252. },
  7253. _scheduleNext: function InternalRenderTask__scheduleNext() {
  7254. if (this.useRequestAnimationFrame) {
  7255. window.requestAnimationFrame(this._nextBound);
  7256. } else {
  7257. Promise.resolve(undefined).then(this._nextBound);
  7258. }
  7259. },
  7260. _next: function InternalRenderTask__next() {
  7261. if (this.cancelled) {
  7262. return;
  7263. }
  7264. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  7265. this.operatorListIdx,
  7266. this._continueBound,
  7267. this.stepper);
  7268. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  7269. this.running = false;
  7270. if (this.operatorList.lastChunk) {
  7271. this.gfx.endDrawing();
  7272. this.callback();
  7273. }
  7274. }
  7275. }
  7276. };
  7277. return InternalRenderTask;
  7278. })();
  7279. /**
  7280. * (Deprecated) Global observer of unsupported feature usages. Use
  7281. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  7282. */
  7283. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  7284. var listeners = [];
  7285. return {
  7286. listen: function (cb) {
  7287. deprecated('Global UnsupportedManager.listen is used: ' +
  7288. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  7289. listeners.push(cb);
  7290. },
  7291. notify: function (featureId) {
  7292. for (var i = 0, ii = listeners.length; i < ii; i++) {
  7293. listeners[i](featureId);
  7294. }
  7295. }
  7296. };
  7297. })();
  7298. exports.getDocument = PDFJS.getDocument;
  7299. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  7300. exports.PDFDocumentProxy = PDFDocumentProxy;
  7301. exports.PDFPageProxy = PDFPageProxy;
  7302. }));
  7303. (function (root, factory) {
  7304. {
  7305. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  7306. }
  7307. }(this, function (exports, sharedUtil) {
  7308. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  7309. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  7310. var ImageKind = sharedUtil.ImageKind;
  7311. var OPS = sharedUtil.OPS;
  7312. var Util = sharedUtil.Util;
  7313. var isNum = sharedUtil.isNum;
  7314. var isArray = sharedUtil.isArray;
  7315. var warn = sharedUtil.warn;
  7316. var SVG_DEFAULTS = {
  7317. fontStyle: 'normal',
  7318. fontWeight: 'normal',
  7319. fillColor: '#000000'
  7320. };
  7321. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  7322. var PNG_HEADER =
  7323. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  7324. var CHUNK_WRAPPER_SIZE = 12;
  7325. var crcTable = new Int32Array(256);
  7326. for (var i = 0; i < 256; i++) {
  7327. var c = i;
  7328. for (var h = 0; h < 8; h++) {
  7329. if (c & 1) {
  7330. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  7331. } else {
  7332. c = (c >> 1) & 0x7fffffff;
  7333. }
  7334. }
  7335. crcTable[i] = c;
  7336. }
  7337. function crc32(data, start, end) {
  7338. var crc = -1;
  7339. for (var i = start; i < end; i++) {
  7340. var a = (crc ^ data[i]) & 0xff;
  7341. var b = crcTable[a];
  7342. crc = (crc >>> 8) ^ b;
  7343. }
  7344. return crc ^ -1;
  7345. }
  7346. function writePngChunk(type, body, data, offset) {
  7347. var p = offset;
  7348. var len = body.length;
  7349. data[p] = len >> 24 & 0xff;
  7350. data[p + 1] = len >> 16 & 0xff;
  7351. data[p + 2] = len >> 8 & 0xff;
  7352. data[p + 3] = len & 0xff;
  7353. p += 4;
  7354. data[p] = type.charCodeAt(0) & 0xff;
  7355. data[p + 1] = type.charCodeAt(1) & 0xff;
  7356. data[p + 2] = type.charCodeAt(2) & 0xff;
  7357. data[p + 3] = type.charCodeAt(3) & 0xff;
  7358. p += 4;
  7359. data.set(body, p);
  7360. p += body.length;
  7361. var crc = crc32(data, offset + 4, p);
  7362. data[p] = crc >> 24 & 0xff;
  7363. data[p + 1] = crc >> 16 & 0xff;
  7364. data[p + 2] = crc >> 8 & 0xff;
  7365. data[p + 3] = crc & 0xff;
  7366. }
  7367. function adler32(data, start, end) {
  7368. var a = 1;
  7369. var b = 0;
  7370. for (var i = start; i < end; ++i) {
  7371. a = (a + (data[i] & 0xff)) % 65521;
  7372. b = (b + a) % 65521;
  7373. }
  7374. return (b << 16) | a;
  7375. }
  7376. function encode(imgData, kind) {
  7377. var width = imgData.width;
  7378. var height = imgData.height;
  7379. var bitDepth, colorType, lineSize;
  7380. var bytes = imgData.data;
  7381. switch (kind) {
  7382. case ImageKind.GRAYSCALE_1BPP:
  7383. colorType = 0;
  7384. bitDepth = 1;
  7385. lineSize = (width + 7) >> 3;
  7386. break;
  7387. case ImageKind.RGB_24BPP:
  7388. colorType = 2;
  7389. bitDepth = 8;
  7390. lineSize = width * 3;
  7391. break;
  7392. case ImageKind.RGBA_32BPP:
  7393. colorType = 6;
  7394. bitDepth = 8;
  7395. lineSize = width * 4;
  7396. break;
  7397. default:
  7398. throw new Error('invalid format');
  7399. }
  7400. // prefix every row with predictor 0
  7401. var literals = new Uint8Array((1 + lineSize) * height);
  7402. var offsetLiterals = 0, offsetBytes = 0;
  7403. var y, i;
  7404. for (y = 0; y < height; ++y) {
  7405. literals[offsetLiterals++] = 0; // no prediction
  7406. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  7407. offsetLiterals);
  7408. offsetBytes += lineSize;
  7409. offsetLiterals += lineSize;
  7410. }
  7411. if (kind === ImageKind.GRAYSCALE_1BPP) {
  7412. // inverting for B/W
  7413. offsetLiterals = 0;
  7414. for (y = 0; y < height; y++) {
  7415. offsetLiterals++; // skipping predictor
  7416. for (i = 0; i < lineSize; i++) {
  7417. literals[offsetLiterals++] ^= 0xFF;
  7418. }
  7419. }
  7420. }
  7421. var ihdr = new Uint8Array([
  7422. width >> 24 & 0xff,
  7423. width >> 16 & 0xff,
  7424. width >> 8 & 0xff,
  7425. width & 0xff,
  7426. height >> 24 & 0xff,
  7427. height >> 16 & 0xff,
  7428. height >> 8 & 0xff,
  7429. height & 0xff,
  7430. bitDepth, // bit depth
  7431. colorType, // color type
  7432. 0x00, // compression method
  7433. 0x00, // filter method
  7434. 0x00 // interlace method
  7435. ]);
  7436. var len = literals.length;
  7437. var maxBlockLength = 0xFFFF;
  7438. var deflateBlocks = Math.ceil(len / maxBlockLength);
  7439. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  7440. var pi = 0;
  7441. idat[pi++] = 0x78; // compression method and flags
  7442. idat[pi++] = 0x9c; // flags
  7443. var pos = 0;
  7444. while (len > maxBlockLength) {
  7445. // writing non-final DEFLATE blocks type 0 and length of 65535
  7446. idat[pi++] = 0x00;
  7447. idat[pi++] = 0xff;
  7448. idat[pi++] = 0xff;
  7449. idat[pi++] = 0x00;
  7450. idat[pi++] = 0x00;
  7451. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  7452. pi += maxBlockLength;
  7453. pos += maxBlockLength;
  7454. len -= maxBlockLength;
  7455. }
  7456. // writing non-final DEFLATE blocks type 0
  7457. idat[pi++] = 0x01;
  7458. idat[pi++] = len & 0xff;
  7459. idat[pi++] = len >> 8 & 0xff;
  7460. idat[pi++] = (~len & 0xffff) & 0xff;
  7461. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  7462. idat.set(literals.subarray(pos), pi);
  7463. pi += literals.length - pos;
  7464. var adler = adler32(literals, 0, literals.length); // checksum
  7465. idat[pi++] = adler >> 24 & 0xff;
  7466. idat[pi++] = adler >> 16 & 0xff;
  7467. idat[pi++] = adler >> 8 & 0xff;
  7468. idat[pi++] = adler & 0xff;
  7469. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  7470. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  7471. ihdr.length + idat.length;
  7472. var data = new Uint8Array(pngLength);
  7473. var offset = 0;
  7474. data.set(PNG_HEADER, offset);
  7475. offset += PNG_HEADER.length;
  7476. writePngChunk('IHDR', ihdr, data, offset);
  7477. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  7478. writePngChunk('IDATA', idat, data, offset);
  7479. offset += CHUNK_WRAPPER_SIZE + idat.length;
  7480. writePngChunk('IEND', new Uint8Array(0), data, offset);
  7481. return PDFJS.createObjectURL(data, 'image/png');
  7482. }
  7483. return function convertImgDataToPng(imgData) {
  7484. var kind = (imgData.kind === undefined ?
  7485. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  7486. return encode(imgData, kind);
  7487. };
  7488. })();
  7489. var SVGExtraState = (function SVGExtraStateClosure() {
  7490. function SVGExtraState() {
  7491. this.fontSizeScale = 1;
  7492. this.fontWeight = SVG_DEFAULTS.fontWeight;
  7493. this.fontSize = 0;
  7494. this.textMatrix = IDENTITY_MATRIX;
  7495. this.fontMatrix = FONT_IDENTITY_MATRIX;
  7496. this.leading = 0;
  7497. // Current point (in user coordinates)
  7498. this.x = 0;
  7499. this.y = 0;
  7500. // Start of text line (in text coordinates)
  7501. this.lineX = 0;
  7502. this.lineY = 0;
  7503. // Character and word spacing
  7504. this.charSpacing = 0;
  7505. this.wordSpacing = 0;
  7506. this.textHScale = 1;
  7507. this.textRise = 0;
  7508. // Default foreground and background colors
  7509. this.fillColor = SVG_DEFAULTS.fillColor;
  7510. this.strokeColor = '#000000';
  7511. this.fillAlpha = 1;
  7512. this.strokeAlpha = 1;
  7513. this.lineWidth = 1;
  7514. this.lineJoin = '';
  7515. this.lineCap = '';
  7516. this.miterLimit = 0;
  7517. this.dashArray = [];
  7518. this.dashPhase = 0;
  7519. this.dependencies = [];
  7520. // Clipping
  7521. this.clipId = '';
  7522. this.pendingClip = false;
  7523. this.maskId = '';
  7524. }
  7525. SVGExtraState.prototype = {
  7526. clone: function SVGExtraState_clone() {
  7527. return Object.create(this);
  7528. },
  7529. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  7530. this.x = x;
  7531. this.y = y;
  7532. }
  7533. };
  7534. return SVGExtraState;
  7535. })();
  7536. var SVGGraphics = (function SVGGraphicsClosure() {
  7537. function createScratchSVG(width, height) {
  7538. var NS = 'http://www.w3.org/2000/svg';
  7539. var svg = document.createElementNS(NS, 'svg:svg');
  7540. svg.setAttributeNS(null, 'version', '1.1');
  7541. svg.setAttributeNS(null, 'width', width + 'px');
  7542. svg.setAttributeNS(null, 'height', height + 'px');
  7543. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  7544. return svg;
  7545. }
  7546. function opListToTree(opList) {
  7547. var opTree = [];
  7548. var tmp = [];
  7549. var opListLen = opList.length;
  7550. for (var x = 0; x < opListLen; x++) {
  7551. if (opList[x].fn === 'save') {
  7552. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  7553. tmp.push(opTree);
  7554. opTree = opTree[opTree.length - 1].items;
  7555. continue;
  7556. }
  7557. if(opList[x].fn === 'restore') {
  7558. opTree = tmp.pop();
  7559. } else {
  7560. opTree.push(opList[x]);
  7561. }
  7562. }
  7563. return opTree;
  7564. }
  7565. /**
  7566. * Formats float number.
  7567. * @param value {number} number to format.
  7568. * @returns {string}
  7569. */
  7570. function pf(value) {
  7571. if (value === (value | 0)) { // integer number
  7572. return value.toString();
  7573. }
  7574. var s = value.toFixed(10);
  7575. var i = s.length - 1;
  7576. if (s[i] !== '0') {
  7577. return s;
  7578. }
  7579. // removing trailing zeros
  7580. do {
  7581. i--;
  7582. } while (s[i] === '0');
  7583. return s.substr(0, s[i] === '.' ? i : i + 1);
  7584. }
  7585. /**
  7586. * Formats transform matrix. The standard rotation, scale and translate
  7587. * matrices are replaced by their shorter forms, and for identity matrix
  7588. * returns empty string to save the memory.
  7589. * @param m {Array} matrix to format.
  7590. * @returns {string}
  7591. */
  7592. function pm(m) {
  7593. if (m[4] === 0 && m[5] === 0) {
  7594. if (m[1] === 0 && m[2] === 0) {
  7595. if (m[0] === 1 && m[3] === 1) {
  7596. return '';
  7597. }
  7598. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  7599. }
  7600. if (m[0] === m[3] && m[1] === -m[2]) {
  7601. var a = Math.acos(m[0]) * 180 / Math.PI;
  7602. return 'rotate(' + pf(a) + ')';
  7603. }
  7604. } else {
  7605. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  7606. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  7607. }
  7608. }
  7609. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  7610. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  7611. }
  7612. function SVGGraphics(commonObjs, objs) {
  7613. this.current = new SVGExtraState();
  7614. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  7615. this.transformStack = [];
  7616. this.extraStack = [];
  7617. this.commonObjs = commonObjs;
  7618. this.objs = objs;
  7619. this.pendingEOFill = false;
  7620. this.embedFonts = false;
  7621. this.embeddedFonts = {};
  7622. this.cssStyle = null;
  7623. }
  7624. var NS = 'http://www.w3.org/2000/svg';
  7625. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  7626. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  7627. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  7628. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  7629. var clipCount = 0;
  7630. var maskCount = 0;
  7631. SVGGraphics.prototype = {
  7632. save: function SVGGraphics_save() {
  7633. this.transformStack.push(this.transformMatrix);
  7634. var old = this.current;
  7635. this.extraStack.push(old);
  7636. this.current = old.clone();
  7637. },
  7638. restore: function SVGGraphics_restore() {
  7639. this.transformMatrix = this.transformStack.pop();
  7640. this.current = this.extraStack.pop();
  7641. this.tgrp = document.createElementNS(NS, 'svg:g');
  7642. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7643. this.pgrp.appendChild(this.tgrp);
  7644. },
  7645. group: function SVGGraphics_group(items) {
  7646. this.save();
  7647. this.executeOpTree(items);
  7648. this.restore();
  7649. },
  7650. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  7651. var fnArray = operatorList.fnArray;
  7652. var fnArrayLen = fnArray.length;
  7653. var argsArray = operatorList.argsArray;
  7654. var self = this;
  7655. for (var i = 0; i < fnArrayLen; i++) {
  7656. if (OPS.dependency === fnArray[i]) {
  7657. var deps = argsArray[i];
  7658. for (var n = 0, nn = deps.length; n < nn; n++) {
  7659. var obj = deps[n];
  7660. var common = obj.substring(0, 2) === 'g_';
  7661. var promise;
  7662. if (common) {
  7663. promise = new Promise(function(resolve) {
  7664. self.commonObjs.get(obj, resolve);
  7665. });
  7666. } else {
  7667. promise = new Promise(function(resolve) {
  7668. self.objs.get(obj, resolve);
  7669. });
  7670. }
  7671. this.current.dependencies.push(promise);
  7672. }
  7673. }
  7674. }
  7675. return Promise.all(this.current.dependencies);
  7676. },
  7677. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  7678. var transformMatrix = [a, b, c, d, e, f];
  7679. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  7680. transformMatrix);
  7681. this.tgrp = document.createElementNS(NS, 'svg:g');
  7682. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7683. },
  7684. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  7685. this.svg = createScratchSVG(viewport.width, viewport.height);
  7686. this.viewport = viewport;
  7687. return this.loadDependencies(operatorList).then(function () {
  7688. this.transformMatrix = IDENTITY_MATRIX;
  7689. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  7690. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  7691. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  7692. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7693. this.defs = document.createElementNS(NS, 'svg:defs');
  7694. this.pgrp.appendChild(this.defs);
  7695. this.pgrp.appendChild(this.tgrp);
  7696. this.svg.appendChild(this.pgrp);
  7697. var opTree = this.convertOpList(operatorList);
  7698. this.executeOpTree(opTree);
  7699. return this.svg;
  7700. }.bind(this));
  7701. },
  7702. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  7703. var argsArray = operatorList.argsArray;
  7704. var fnArray = operatorList.fnArray;
  7705. var fnArrayLen = fnArray.length;
  7706. var REVOPS = [];
  7707. var opList = [];
  7708. for (var op in OPS) {
  7709. REVOPS[OPS[op]] = op;
  7710. }
  7711. for (var x = 0; x < fnArrayLen; x++) {
  7712. var fnId = fnArray[x];
  7713. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  7714. }
  7715. return opListToTree(opList);
  7716. },
  7717. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  7718. var opTreeLen = opTree.length;
  7719. for(var x = 0; x < opTreeLen; x++) {
  7720. var fn = opTree[x].fn;
  7721. var fnId = opTree[x].fnId;
  7722. var args = opTree[x].args;
  7723. switch (fnId | 0) {
  7724. case OPS.beginText:
  7725. this.beginText();
  7726. break;
  7727. case OPS.setLeading:
  7728. this.setLeading(args);
  7729. break;
  7730. case OPS.setLeadingMoveText:
  7731. this.setLeadingMoveText(args[0], args[1]);
  7732. break;
  7733. case OPS.setFont:
  7734. this.setFont(args);
  7735. break;
  7736. case OPS.showText:
  7737. this.showText(args[0]);
  7738. break;
  7739. case OPS.showSpacedText:
  7740. this.showText(args[0]);
  7741. break;
  7742. case OPS.endText:
  7743. this.endText();
  7744. break;
  7745. case OPS.moveText:
  7746. this.moveText(args[0], args[1]);
  7747. break;
  7748. case OPS.setCharSpacing:
  7749. this.setCharSpacing(args[0]);
  7750. break;
  7751. case OPS.setWordSpacing:
  7752. this.setWordSpacing(args[0]);
  7753. break;
  7754. case OPS.setHScale:
  7755. this.setHScale(args[0]);
  7756. break;
  7757. case OPS.setTextMatrix:
  7758. this.setTextMatrix(args[0], args[1], args[2],
  7759. args[3], args[4], args[5]);
  7760. break;
  7761. case OPS.setLineWidth:
  7762. this.setLineWidth(args[0]);
  7763. break;
  7764. case OPS.setLineJoin:
  7765. this.setLineJoin(args[0]);
  7766. break;
  7767. case OPS.setLineCap:
  7768. this.setLineCap(args[0]);
  7769. break;
  7770. case OPS.setMiterLimit:
  7771. this.setMiterLimit(args[0]);
  7772. break;
  7773. case OPS.setFillRGBColor:
  7774. this.setFillRGBColor(args[0], args[1], args[2]);
  7775. break;
  7776. case OPS.setStrokeRGBColor:
  7777. this.setStrokeRGBColor(args[0], args[1], args[2]);
  7778. break;
  7779. case OPS.setDash:
  7780. this.setDash(args[0], args[1]);
  7781. break;
  7782. case OPS.setGState:
  7783. this.setGState(args[0]);
  7784. break;
  7785. case OPS.fill:
  7786. this.fill();
  7787. break;
  7788. case OPS.eoFill:
  7789. this.eoFill();
  7790. break;
  7791. case OPS.stroke:
  7792. this.stroke();
  7793. break;
  7794. case OPS.fillStroke:
  7795. this.fillStroke();
  7796. break;
  7797. case OPS.eoFillStroke:
  7798. this.eoFillStroke();
  7799. break;
  7800. case OPS.clip:
  7801. this.clip('nonzero');
  7802. break;
  7803. case OPS.eoClip:
  7804. this.clip('evenodd');
  7805. break;
  7806. case OPS.paintSolidColorImageMask:
  7807. this.paintSolidColorImageMask();
  7808. break;
  7809. case OPS.paintJpegXObject:
  7810. this.paintJpegXObject(args[0], args[1], args[2]);
  7811. break;
  7812. case OPS.paintImageXObject:
  7813. this.paintImageXObject(args[0]);
  7814. break;
  7815. case OPS.paintInlineImageXObject:
  7816. this.paintInlineImageXObject(args[0]);
  7817. break;
  7818. case OPS.paintImageMaskXObject:
  7819. this.paintImageMaskXObject(args[0]);
  7820. break;
  7821. case OPS.paintFormXObjectBegin:
  7822. this.paintFormXObjectBegin(args[0], args[1]);
  7823. break;
  7824. case OPS.paintFormXObjectEnd:
  7825. this.paintFormXObjectEnd();
  7826. break;
  7827. case OPS.closePath:
  7828. this.closePath();
  7829. break;
  7830. case OPS.closeStroke:
  7831. this.closeStroke();
  7832. break;
  7833. case OPS.closeFillStroke:
  7834. this.closeFillStroke();
  7835. break;
  7836. case OPS.nextLine:
  7837. this.nextLine();
  7838. break;
  7839. case OPS.transform:
  7840. this.transform(args[0], args[1], args[2], args[3],
  7841. args[4], args[5]);
  7842. break;
  7843. case OPS.constructPath:
  7844. this.constructPath(args[0], args[1]);
  7845. break;
  7846. case OPS.endPath:
  7847. this.endPath();
  7848. break;
  7849. case 92:
  7850. this.group(opTree[x].items);
  7851. break;
  7852. default:
  7853. warn('Unimplemented method '+ fn);
  7854. break;
  7855. }
  7856. }
  7857. },
  7858. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  7859. this.current.wordSpacing = wordSpacing;
  7860. },
  7861. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  7862. this.current.charSpacing = charSpacing;
  7863. },
  7864. nextLine: function SVGGraphics_nextLine() {
  7865. this.moveText(0, this.current.leading);
  7866. },
  7867. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  7868. var current = this.current;
  7869. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  7870. this.current.x = this.current.lineX = 0;
  7871. this.current.y = this.current.lineY = 0;
  7872. current.xcoords = [];
  7873. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7874. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7875. current.tspan.setAttributeNS(null, 'font-size',
  7876. pf(current.fontSize) + 'px');
  7877. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7878. current.txtElement = document.createElementNS(NS, 'svg:text');
  7879. current.txtElement.appendChild(current.tspan);
  7880. },
  7881. beginText: function SVGGraphics_beginText() {
  7882. this.current.x = this.current.lineX = 0;
  7883. this.current.y = this.current.lineY = 0;
  7884. this.current.textMatrix = IDENTITY_MATRIX;
  7885. this.current.lineMatrix = IDENTITY_MATRIX;
  7886. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  7887. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  7888. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  7889. this.current.xcoords = [];
  7890. },
  7891. moveText: function SVGGraphics_moveText(x, y) {
  7892. var current = this.current;
  7893. this.current.x = this.current.lineX += x;
  7894. this.current.y = this.current.lineY += y;
  7895. current.xcoords = [];
  7896. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7897. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7898. current.tspan.setAttributeNS(null, 'font-size',
  7899. pf(current.fontSize) + 'px');
  7900. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7901. },
  7902. showText: function SVGGraphics_showText(glyphs) {
  7903. var current = this.current;
  7904. var font = current.font;
  7905. var fontSize = current.fontSize;
  7906. if (fontSize === 0) {
  7907. return;
  7908. }
  7909. var charSpacing = current.charSpacing;
  7910. var wordSpacing = current.wordSpacing;
  7911. var fontDirection = current.fontDirection;
  7912. var textHScale = current.textHScale * fontDirection;
  7913. var glyphsLength = glyphs.length;
  7914. var vertical = font.vertical;
  7915. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  7916. var x = 0, i;
  7917. for (i = 0; i < glyphsLength; ++i) {
  7918. var glyph = glyphs[i];
  7919. if (glyph === null) {
  7920. // word break
  7921. x += fontDirection * wordSpacing;
  7922. continue;
  7923. } else if (isNum(glyph)) {
  7924. x += -glyph * fontSize * 0.001;
  7925. continue;
  7926. }
  7927. current.xcoords.push(current.x + x * textHScale);
  7928. var width = glyph.width;
  7929. var character = glyph.fontChar;
  7930. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  7931. x += charWidth;
  7932. current.tspan.textContent += character;
  7933. }
  7934. if (vertical) {
  7935. current.y -= x * textHScale;
  7936. } else {
  7937. current.x += x * textHScale;
  7938. }
  7939. current.tspan.setAttributeNS(null, 'x',
  7940. current.xcoords.map(pf).join(' '));
  7941. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7942. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7943. current.tspan.setAttributeNS(null, 'font-size',
  7944. pf(current.fontSize) + 'px');
  7945. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  7946. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  7947. }
  7948. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  7949. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  7950. }
  7951. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  7952. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  7953. }
  7954. current.txtElement.setAttributeNS(null, 'transform',
  7955. pm(current.textMatrix) +
  7956. ' scale(1, -1)' );
  7957. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  7958. current.txtElement.appendChild(current.tspan);
  7959. current.txtgrp.appendChild(current.txtElement);
  7960. this.tgrp.appendChild(current.txtElement);
  7961. },
  7962. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  7963. this.setLeading(-y);
  7964. this.moveText(x, y);
  7965. },
  7966. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  7967. if (!this.cssStyle) {
  7968. this.cssStyle = document.createElementNS(NS, 'svg:style');
  7969. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  7970. this.defs.appendChild(this.cssStyle);
  7971. }
  7972. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  7973. this.cssStyle.textContent +=
  7974. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  7975. ' src: url(' + url + '); }\n';
  7976. },
  7977. setFont: function SVGGraphics_setFont(details) {
  7978. var current = this.current;
  7979. var fontObj = this.commonObjs.get(details[0]);
  7980. var size = details[1];
  7981. this.current.font = fontObj;
  7982. if (this.embedFonts && fontObj.data &&
  7983. !this.embeddedFonts[fontObj.loadedName]) {
  7984. this.addFontStyle(fontObj);
  7985. this.embeddedFonts[fontObj.loadedName] = fontObj;
  7986. }
  7987. current.fontMatrix = (fontObj.fontMatrix ?
  7988. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  7989. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  7990. (fontObj.bold ? 'bold' : 'normal');
  7991. var italic = fontObj.italic ? 'italic' : 'normal';
  7992. if (size < 0) {
  7993. size = -size;
  7994. current.fontDirection = -1;
  7995. } else {
  7996. current.fontDirection = 1;
  7997. }
  7998. current.fontSize = size;
  7999. current.fontFamily = fontObj.loadedName;
  8000. current.fontWeight = bold;
  8001. current.fontStyle = italic;
  8002. current.tspan = document.createElementNS(NS, 'svg:tspan');
  8003. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  8004. current.xcoords = [];
  8005. },
  8006. endText: function SVGGraphics_endText() {
  8007. if (this.current.pendingClip) {
  8008. this.cgrp.appendChild(this.tgrp);
  8009. this.pgrp.appendChild(this.cgrp);
  8010. } else {
  8011. this.pgrp.appendChild(this.tgrp);
  8012. }
  8013. this.tgrp = document.createElementNS(NS, 'svg:g');
  8014. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  8015. },
  8016. // Path properties
  8017. setLineWidth: function SVGGraphics_setLineWidth(width) {
  8018. this.current.lineWidth = width;
  8019. },
  8020. setLineCap: function SVGGraphics_setLineCap(style) {
  8021. this.current.lineCap = LINE_CAP_STYLES[style];
  8022. },
  8023. setLineJoin: function SVGGraphics_setLineJoin(style) {
  8024. this.current.lineJoin = LINE_JOIN_STYLES[style];
  8025. },
  8026. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  8027. this.current.miterLimit = limit;
  8028. },
  8029. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  8030. var color = Util.makeCssRgb(r, g, b);
  8031. this.current.strokeColor = color;
  8032. },
  8033. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  8034. var color = Util.makeCssRgb(r, g, b);
  8035. this.current.fillColor = color;
  8036. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  8037. this.current.xcoords = [];
  8038. },
  8039. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  8040. this.current.dashArray = dashArray;
  8041. this.current.dashPhase = dashPhase;
  8042. },
  8043. constructPath: function SVGGraphics_constructPath(ops, args) {
  8044. var current = this.current;
  8045. var x = current.x, y = current.y;
  8046. current.path = document.createElementNS(NS, 'svg:path');
  8047. var d = [];
  8048. var opLength = ops.length;
  8049. for (var i = 0, j = 0; i < opLength; i++) {
  8050. switch (ops[i] | 0) {
  8051. case OPS.rectangle:
  8052. x = args[j++];
  8053. y = args[j++];
  8054. var width = args[j++];
  8055. var height = args[j++];
  8056. var xw = x + width;
  8057. var yh = y + height;
  8058. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  8059. 'L', pf(x), pf(yh), 'Z');
  8060. break;
  8061. case OPS.moveTo:
  8062. x = args[j++];
  8063. y = args[j++];
  8064. d.push('M', pf(x), pf(y));
  8065. break;
  8066. case OPS.lineTo:
  8067. x = args[j++];
  8068. y = args[j++];
  8069. d.push('L', pf(x) , pf(y));
  8070. break;
  8071. case OPS.curveTo:
  8072. x = args[j + 4];
  8073. y = args[j + 5];
  8074. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  8075. pf(args[j + 3]), pf(x), pf(y));
  8076. j += 6;
  8077. break;
  8078. case OPS.curveTo2:
  8079. x = args[j + 2];
  8080. y = args[j + 3];
  8081. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  8082. pf(args[j + 2]), pf(args[j + 3]));
  8083. j += 4;
  8084. break;
  8085. case OPS.curveTo3:
  8086. x = args[j + 2];
  8087. y = args[j + 3];
  8088. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  8089. pf(x), pf(y));
  8090. j += 4;
  8091. break;
  8092. case OPS.closePath:
  8093. d.push('Z');
  8094. break;
  8095. }
  8096. }
  8097. current.path.setAttributeNS(null, 'd', d.join(' '));
  8098. current.path.setAttributeNS(null, 'stroke-miterlimit',
  8099. pf(current.miterLimit));
  8100. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  8101. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  8102. current.path.setAttributeNS(null, 'stroke-width',
  8103. pf(current.lineWidth) + 'px');
  8104. current.path.setAttributeNS(null, 'stroke-dasharray',
  8105. current.dashArray.map(pf).join(' '));
  8106. current.path.setAttributeNS(null, 'stroke-dashoffset',
  8107. pf(current.dashPhase) + 'px');
  8108. current.path.setAttributeNS(null, 'fill', 'none');
  8109. this.tgrp.appendChild(current.path);
  8110. if (current.pendingClip) {
  8111. this.cgrp.appendChild(this.tgrp);
  8112. this.pgrp.appendChild(this.cgrp);
  8113. } else {
  8114. this.pgrp.appendChild(this.tgrp);
  8115. }
  8116. // Saving a reference in current.element so that it can be addressed
  8117. // in 'fill' and 'stroke'
  8118. current.element = current.path;
  8119. current.setCurrentPoint(x, y);
  8120. },
  8121. endPath: function SVGGraphics_endPath() {
  8122. var current = this.current;
  8123. if (current.pendingClip) {
  8124. this.cgrp.appendChild(this.tgrp);
  8125. this.pgrp.appendChild(this.cgrp);
  8126. } else {
  8127. this.pgrp.appendChild(this.tgrp);
  8128. }
  8129. this.tgrp = document.createElementNS(NS, 'svg:g');
  8130. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  8131. },
  8132. clip: function SVGGraphics_clip(type) {
  8133. var current = this.current;
  8134. // Add current path to clipping path
  8135. current.clipId = 'clippath' + clipCount;
  8136. clipCount++;
  8137. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  8138. this.clippath.setAttributeNS(null, 'id', current.clipId);
  8139. var clipElement = current.element.cloneNode();
  8140. if (type === 'evenodd') {
  8141. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  8142. } else {
  8143. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  8144. }
  8145. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  8146. this.clippath.appendChild(clipElement);
  8147. this.defs.appendChild(this.clippath);
  8148. // Create a new group with that attribute
  8149. current.pendingClip = true;
  8150. this.cgrp = document.createElementNS(NS, 'svg:g');
  8151. this.cgrp.setAttributeNS(null, 'clip-path',
  8152. 'url(#' + current.clipId + ')');
  8153. this.pgrp.appendChild(this.cgrp);
  8154. },
  8155. closePath: function SVGGraphics_closePath() {
  8156. var current = this.current;
  8157. var d = current.path.getAttributeNS(null, 'd');
  8158. d += 'Z';
  8159. current.path.setAttributeNS(null, 'd', d);
  8160. },
  8161. setLeading: function SVGGraphics_setLeading(leading) {
  8162. this.current.leading = -leading;
  8163. },
  8164. setTextRise: function SVGGraphics_setTextRise(textRise) {
  8165. this.current.textRise = textRise;
  8166. },
  8167. setHScale: function SVGGraphics_setHScale(scale) {
  8168. this.current.textHScale = scale / 100;
  8169. },
  8170. setGState: function SVGGraphics_setGState(states) {
  8171. for (var i = 0, ii = states.length; i < ii; i++) {
  8172. var state = states[i];
  8173. var key = state[0];
  8174. var value = state[1];
  8175. switch (key) {
  8176. case 'LW':
  8177. this.setLineWidth(value);
  8178. break;
  8179. case 'LC':
  8180. this.setLineCap(value);
  8181. break;
  8182. case 'LJ':
  8183. this.setLineJoin(value);
  8184. break;
  8185. case 'ML':
  8186. this.setMiterLimit(value);
  8187. break;
  8188. case 'D':
  8189. this.setDash(value[0], value[1]);
  8190. break;
  8191. case 'RI':
  8192. break;
  8193. case 'FL':
  8194. break;
  8195. case 'Font':
  8196. this.setFont(value);
  8197. break;
  8198. case 'CA':
  8199. break;
  8200. case 'ca':
  8201. break;
  8202. case 'BM':
  8203. break;
  8204. case 'SMask':
  8205. break;
  8206. }
  8207. }
  8208. },
  8209. fill: function SVGGraphics_fill() {
  8210. var current = this.current;
  8211. current.element.setAttributeNS(null, 'fill', current.fillColor);
  8212. },
  8213. stroke: function SVGGraphics_stroke() {
  8214. var current = this.current;
  8215. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  8216. current.element.setAttributeNS(null, 'fill', 'none');
  8217. },
  8218. eoFill: function SVGGraphics_eoFill() {
  8219. var current = this.current;
  8220. current.element.setAttributeNS(null, 'fill', current.fillColor);
  8221. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  8222. },
  8223. fillStroke: function SVGGraphics_fillStroke() {
  8224. // Order is important since stroke wants fill to be none.
  8225. // First stroke, then if fill needed, it will be overwritten.
  8226. this.stroke();
  8227. this.fill();
  8228. },
  8229. eoFillStroke: function SVGGraphics_eoFillStroke() {
  8230. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  8231. this.fillStroke();
  8232. },
  8233. closeStroke: function SVGGraphics_closeStroke() {
  8234. this.closePath();
  8235. this.stroke();
  8236. },
  8237. closeFillStroke: function SVGGraphics_closeFillStroke() {
  8238. this.closePath();
  8239. this.fillStroke();
  8240. },
  8241. paintSolidColorImageMask:
  8242. function SVGGraphics_paintSolidColorImageMask() {
  8243. var current = this.current;
  8244. var rect = document.createElementNS(NS, 'svg:rect');
  8245. rect.setAttributeNS(null, 'x', '0');
  8246. rect.setAttributeNS(null, 'y', '0');
  8247. rect.setAttributeNS(null, 'width', '1px');
  8248. rect.setAttributeNS(null, 'height', '1px');
  8249. rect.setAttributeNS(null, 'fill', current.fillColor);
  8250. this.tgrp.appendChild(rect);
  8251. },
  8252. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  8253. var current = this.current;
  8254. var imgObj = this.objs.get(objId);
  8255. var imgEl = document.createElementNS(NS, 'svg:image');
  8256. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  8257. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  8258. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  8259. imgEl.setAttributeNS(null, 'x', '0');
  8260. imgEl.setAttributeNS(null, 'y', pf(-h));
  8261. imgEl.setAttributeNS(null, 'transform',
  8262. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  8263. this.tgrp.appendChild(imgEl);
  8264. if (current.pendingClip) {
  8265. this.cgrp.appendChild(this.tgrp);
  8266. this.pgrp.appendChild(this.cgrp);
  8267. } else {
  8268. this.pgrp.appendChild(this.tgrp);
  8269. }
  8270. },
  8271. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  8272. var imgData = this.objs.get(objId);
  8273. if (!imgData) {
  8274. warn('Dependent image isn\'t ready yet');
  8275. return;
  8276. }
  8277. this.paintInlineImageXObject(imgData);
  8278. },
  8279. paintInlineImageXObject:
  8280. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  8281. var current = this.current;
  8282. var width = imgData.width;
  8283. var height = imgData.height;
  8284. var imgSrc = convertImgDataToPng(imgData);
  8285. var cliprect = document.createElementNS(NS, 'svg:rect');
  8286. cliprect.setAttributeNS(null, 'x', '0');
  8287. cliprect.setAttributeNS(null, 'y', '0');
  8288. cliprect.setAttributeNS(null, 'width', pf(width));
  8289. cliprect.setAttributeNS(null, 'height', pf(height));
  8290. current.element = cliprect;
  8291. this.clip('nonzero');
  8292. var imgEl = document.createElementNS(NS, 'svg:image');
  8293. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  8294. imgEl.setAttributeNS(null, 'x', '0');
  8295. imgEl.setAttributeNS(null, 'y', pf(-height));
  8296. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  8297. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  8298. imgEl.setAttributeNS(null, 'transform',
  8299. 'scale(' + pf(1 / width) + ' ' +
  8300. pf(-1 / height) + ')');
  8301. if (mask) {
  8302. mask.appendChild(imgEl);
  8303. } else {
  8304. this.tgrp.appendChild(imgEl);
  8305. }
  8306. if (current.pendingClip) {
  8307. this.cgrp.appendChild(this.tgrp);
  8308. this.pgrp.appendChild(this.cgrp);
  8309. } else {
  8310. this.pgrp.appendChild(this.tgrp);
  8311. }
  8312. },
  8313. paintImageMaskXObject:
  8314. function SVGGraphics_paintImageMaskXObject(imgData) {
  8315. var current = this.current;
  8316. var width = imgData.width;
  8317. var height = imgData.height;
  8318. var fillColor = current.fillColor;
  8319. current.maskId = 'mask' + maskCount++;
  8320. var mask = document.createElementNS(NS, 'svg:mask');
  8321. mask.setAttributeNS(null, 'id', current.maskId);
  8322. var rect = document.createElementNS(NS, 'svg:rect');
  8323. rect.setAttributeNS(null, 'x', '0');
  8324. rect.setAttributeNS(null, 'y', '0');
  8325. rect.setAttributeNS(null, 'width', pf(width));
  8326. rect.setAttributeNS(null, 'height', pf(height));
  8327. rect.setAttributeNS(null, 'fill', fillColor);
  8328. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  8329. this.defs.appendChild(mask);
  8330. this.tgrp.appendChild(rect);
  8331. this.paintInlineImageXObject(imgData, mask);
  8332. },
  8333. paintFormXObjectBegin:
  8334. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  8335. this.save();
  8336. if (isArray(matrix) && matrix.length === 6) {
  8337. this.transform(matrix[0], matrix[1], matrix[2],
  8338. matrix[3], matrix[4], matrix[5]);
  8339. }
  8340. if (isArray(bbox) && bbox.length === 4) {
  8341. var width = bbox[2] - bbox[0];
  8342. var height = bbox[3] - bbox[1];
  8343. var cliprect = document.createElementNS(NS, 'svg:rect');
  8344. cliprect.setAttributeNS(null, 'x', bbox[0]);
  8345. cliprect.setAttributeNS(null, 'y', bbox[1]);
  8346. cliprect.setAttributeNS(null, 'width', pf(width));
  8347. cliprect.setAttributeNS(null, 'height', pf(height));
  8348. this.current.element = cliprect;
  8349. this.clip('nonzero');
  8350. this.endPath();
  8351. }
  8352. },
  8353. paintFormXObjectEnd:
  8354. function SVGGraphics_paintFormXObjectEnd() {
  8355. this.restore();
  8356. }
  8357. };
  8358. return SVGGraphics;
  8359. })();
  8360. PDFJS.SVGGraphics = SVGGraphics;
  8361. exports.SVGGraphics = SVGGraphics;
  8362. }));
  8363. var NetworkManager = (function NetworkManagerClosure() {
  8364. var OK_RESPONSE = 200;
  8365. var PARTIAL_CONTENT_RESPONSE = 206;
  8366. function NetworkManager(url, args) {
  8367. this.url = url;
  8368. args = args || {};
  8369. this.isHttp = /^https?:/i.test(url);
  8370. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  8371. this.withCredentials = args.withCredentials || false;
  8372. this.getXhr = args.getXhr ||
  8373. function NetworkManager_getXhr() {
  8374. return new XMLHttpRequest();
  8375. };
  8376. this.currXhrId = 0;
  8377. this.pendingRequests = {};
  8378. this.loadedRequests = {};
  8379. }
  8380. function getArrayBuffer(xhr) {
  8381. var data = xhr.response;
  8382. if (typeof data !== 'string') {
  8383. return data;
  8384. }
  8385. var length = data.length;
  8386. var array = new Uint8Array(length);
  8387. for (var i = 0; i < length; i++) {
  8388. array[i] = data.charCodeAt(i) & 0xFF;
  8389. }
  8390. return array.buffer;
  8391. }
  8392. var supportsMozChunked = (function supportsMozChunkedClosure() {
  8393. try {
  8394. var x = new XMLHttpRequest();
  8395. // Firefox 37- required .open() to be called before setting responseType.
  8396. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  8397. // Even though the URL is not visited, .open() could fail if the URL is
  8398. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  8399. // When this error occurs, this feature detection method will mistakenly
  8400. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  8401. x.open('GET', 'https://example.com');
  8402. x.responseType = 'moz-chunked-arraybuffer';
  8403. return x.responseType === 'moz-chunked-arraybuffer';
  8404. } catch (e) {
  8405. return false;
  8406. }
  8407. })();
  8408. NetworkManager.prototype = {
  8409. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  8410. var args = {
  8411. begin: begin,
  8412. end: end
  8413. };
  8414. for (var prop in listeners) {
  8415. args[prop] = listeners[prop];
  8416. }
  8417. return this.request(args);
  8418. },
  8419. requestFull: function NetworkManager_requestFull(listeners) {
  8420. return this.request(listeners);
  8421. },
  8422. request: function NetworkManager_request(args) {
  8423. var xhr = this.getXhr();
  8424. var xhrId = this.currXhrId++;
  8425. var pendingRequest = this.pendingRequests[xhrId] = {
  8426. xhr: xhr
  8427. };
  8428. xhr.open('GET', this.url);
  8429. xhr.withCredentials = this.withCredentials;
  8430. for (var property in this.httpHeaders) {
  8431. var value = this.httpHeaders[property];
  8432. if (typeof value === 'undefined') {
  8433. continue;
  8434. }
  8435. xhr.setRequestHeader(property, value);
  8436. }
  8437. if (this.isHttp && 'begin' in args && 'end' in args) {
  8438. var rangeStr = args.begin + '-' + (args.end - 1);
  8439. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  8440. pendingRequest.expectedStatus = 206;
  8441. } else {
  8442. pendingRequest.expectedStatus = 200;
  8443. }
  8444. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  8445. if (useMozChunkedLoading) {
  8446. xhr.responseType = 'moz-chunked-arraybuffer';
  8447. pendingRequest.onProgressiveData = args.onProgressiveData;
  8448. pendingRequest.mozChunked = true;
  8449. } else {
  8450. xhr.responseType = 'arraybuffer';
  8451. }
  8452. if (args.onError) {
  8453. xhr.onerror = function(evt) {
  8454. args.onError(xhr.status);
  8455. };
  8456. }
  8457. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  8458. xhr.onprogress = this.onProgress.bind(this, xhrId);
  8459. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  8460. pendingRequest.onDone = args.onDone;
  8461. pendingRequest.onError = args.onError;
  8462. pendingRequest.onProgress = args.onProgress;
  8463. xhr.send(null);
  8464. return xhrId;
  8465. },
  8466. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  8467. var pendingRequest = this.pendingRequests[xhrId];
  8468. if (!pendingRequest) {
  8469. // Maybe abortRequest was called...
  8470. return;
  8471. }
  8472. if (pendingRequest.mozChunked) {
  8473. var chunk = getArrayBuffer(pendingRequest.xhr);
  8474. pendingRequest.onProgressiveData(chunk);
  8475. }
  8476. var onProgress = pendingRequest.onProgress;
  8477. if (onProgress) {
  8478. onProgress(evt);
  8479. }
  8480. },
  8481. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  8482. var pendingRequest = this.pendingRequests[xhrId];
  8483. if (!pendingRequest) {
  8484. // Maybe abortRequest was called...
  8485. return;
  8486. }
  8487. var xhr = pendingRequest.xhr;
  8488. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  8489. pendingRequest.onHeadersReceived();
  8490. delete pendingRequest.onHeadersReceived;
  8491. }
  8492. if (xhr.readyState !== 4) {
  8493. return;
  8494. }
  8495. if (!(xhrId in this.pendingRequests)) {
  8496. // The XHR request might have been aborted in onHeadersReceived()
  8497. // callback, in which case we should abort request
  8498. return;
  8499. }
  8500. delete this.pendingRequests[xhrId];
  8501. // success status == 0 can be on ftp, file and other protocols
  8502. if (xhr.status === 0 && this.isHttp) {
  8503. if (pendingRequest.onError) {
  8504. pendingRequest.onError(xhr.status);
  8505. }
  8506. return;
  8507. }
  8508. var xhrStatus = xhr.status || OK_RESPONSE;
  8509. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  8510. // "A server MAY ignore the Range header". This means it's possible to
  8511. // get a 200 rather than a 206 response from a range request.
  8512. var ok_response_on_range_request =
  8513. xhrStatus === OK_RESPONSE &&
  8514. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  8515. if (!ok_response_on_range_request &&
  8516. xhrStatus !== pendingRequest.expectedStatus) {
  8517. if (pendingRequest.onError) {
  8518. pendingRequest.onError(xhr.status);
  8519. }
  8520. return;
  8521. }
  8522. this.loadedRequests[xhrId] = true;
  8523. var chunk = getArrayBuffer(xhr);
  8524. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  8525. var rangeHeader = xhr.getResponseHeader('Content-Range');
  8526. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  8527. var begin = parseInt(matches[1], 10);
  8528. pendingRequest.onDone({
  8529. begin: begin,
  8530. chunk: chunk
  8531. });
  8532. } else if (pendingRequest.onProgressiveData) {
  8533. pendingRequest.onDone(null);
  8534. } else if (chunk) {
  8535. pendingRequest.onDone({
  8536. begin: 0,
  8537. chunk: chunk
  8538. });
  8539. } else if (pendingRequest.onError) {
  8540. pendingRequest.onError(xhr.status);
  8541. }
  8542. },
  8543. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  8544. for (var xhrId in this.pendingRequests) {
  8545. return true;
  8546. }
  8547. return false;
  8548. },
  8549. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  8550. return this.pendingRequests[xhrId].xhr;
  8551. },
  8552. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  8553. return !!(this.pendingRequests[xhrId].onProgressiveData);
  8554. },
  8555. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  8556. return xhrId in this.pendingRequests;
  8557. },
  8558. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  8559. return xhrId in this.loadedRequests;
  8560. },
  8561. abortAllRequests: function NetworkManager_abortAllRequests() {
  8562. for (var xhrId in this.pendingRequests) {
  8563. this.abortRequest(xhrId | 0);
  8564. }
  8565. },
  8566. abortRequest: function NetworkManager_abortRequest(xhrId) {
  8567. var xhr = this.pendingRequests[xhrId].xhr;
  8568. delete this.pendingRequests[xhrId];
  8569. xhr.abort();
  8570. }
  8571. };
  8572. return NetworkManager;
  8573. })();
  8574. (function (root, factory) {
  8575. {
  8576. factory((root.pdfjsCoreArithmeticDecoder = {}));
  8577. }
  8578. }(this, function (exports) {
  8579. /* This class implements the QM Coder decoding as defined in
  8580. * JPEG 2000 Part I Final Committee Draft Version 1.0
  8581. * Annex C.3 Arithmetic decoding procedure
  8582. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  8583. *
  8584. * The arithmetic decoder is used in conjunction with context models to decode
  8585. * JPEG2000 and JBIG2 streams.
  8586. */
  8587. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  8588. // Table C-2
  8589. var QeTable = [
  8590. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  8591. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  8592. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  8593. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  8594. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  8595. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  8596. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  8597. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  8598. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  8599. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  8600. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  8601. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  8602. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  8603. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  8604. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  8605. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  8606. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  8607. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  8608. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  8609. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  8610. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  8611. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  8612. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  8613. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  8614. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  8615. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  8616. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  8617. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  8618. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  8619. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  8620. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  8621. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  8622. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  8623. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  8624. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  8625. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  8626. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  8627. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  8628. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  8629. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  8630. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  8631. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  8632. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  8633. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  8634. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  8635. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  8636. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  8637. ];
  8638. // C.3.5 Initialisation of the decoder (INITDEC)
  8639. function ArithmeticDecoder(data, start, end) {
  8640. this.data = data;
  8641. this.bp = start;
  8642. this.dataEnd = end;
  8643. this.chigh = data[start];
  8644. this.clow = 0;
  8645. this.byteIn();
  8646. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  8647. this.clow = (this.clow << 7) & 0xFFFF;
  8648. this.ct -= 7;
  8649. this.a = 0x8000;
  8650. }
  8651. ArithmeticDecoder.prototype = {
  8652. // C.3.4 Compressed data input (BYTEIN)
  8653. byteIn: function ArithmeticDecoder_byteIn() {
  8654. var data = this.data;
  8655. var bp = this.bp;
  8656. if (data[bp] === 0xFF) {
  8657. var b1 = data[bp + 1];
  8658. if (b1 > 0x8F) {
  8659. this.clow += 0xFF00;
  8660. this.ct = 8;
  8661. } else {
  8662. bp++;
  8663. this.clow += (data[bp] << 9);
  8664. this.ct = 7;
  8665. this.bp = bp;
  8666. }
  8667. } else {
  8668. bp++;
  8669. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  8670. this.ct = 8;
  8671. this.bp = bp;
  8672. }
  8673. if (this.clow > 0xFFFF) {
  8674. this.chigh += (this.clow >> 16);
  8675. this.clow &= 0xFFFF;
  8676. }
  8677. },
  8678. // C.3.2 Decoding a decision (DECODE)
  8679. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  8680. // contexts are packed into 1 byte:
  8681. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  8682. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  8683. var qeTableIcx = QeTable[cx_index];
  8684. var qeIcx = qeTableIcx.qe;
  8685. var d;
  8686. var a = this.a - qeIcx;
  8687. if (this.chigh < qeIcx) {
  8688. // exchangeLps
  8689. if (a < qeIcx) {
  8690. a = qeIcx;
  8691. d = cx_mps;
  8692. cx_index = qeTableIcx.nmps;
  8693. } else {
  8694. a = qeIcx;
  8695. d = 1 ^ cx_mps;
  8696. if (qeTableIcx.switchFlag === 1) {
  8697. cx_mps = d;
  8698. }
  8699. cx_index = qeTableIcx.nlps;
  8700. }
  8701. } else {
  8702. this.chigh -= qeIcx;
  8703. if ((a & 0x8000) !== 0) {
  8704. this.a = a;
  8705. return cx_mps;
  8706. }
  8707. // exchangeMps
  8708. if (a < qeIcx) {
  8709. d = 1 ^ cx_mps;
  8710. if (qeTableIcx.switchFlag === 1) {
  8711. cx_mps = d;
  8712. }
  8713. cx_index = qeTableIcx.nlps;
  8714. } else {
  8715. d = cx_mps;
  8716. cx_index = qeTableIcx.nmps;
  8717. }
  8718. }
  8719. // C.3.3 renormD;
  8720. do {
  8721. if (this.ct === 0) {
  8722. this.byteIn();
  8723. }
  8724. a <<= 1;
  8725. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  8726. this.clow = (this.clow << 1) & 0xFFFF;
  8727. this.ct--;
  8728. } while ((a & 0x8000) === 0);
  8729. this.a = a;
  8730. contexts[pos] = cx_index << 1 | cx_mps;
  8731. return d;
  8732. }
  8733. };
  8734. return ArithmeticDecoder;
  8735. })();
  8736. exports.ArithmeticDecoder = ArithmeticDecoder;
  8737. }));
  8738. (function (root, factory) {
  8739. {
  8740. factory((root.pdfjsCoreCharsets = {}));
  8741. }
  8742. }(this, function (exports) {
  8743. var ISOAdobeCharset = [
  8744. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  8745. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  8746. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  8747. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  8748. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  8749. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  8750. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  8751. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  8752. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  8753. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  8754. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  8755. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  8756. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  8757. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  8758. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  8759. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  8760. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  8761. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  8762. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  8763. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  8764. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  8765. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  8766. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  8767. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  8768. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  8769. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  8770. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  8771. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  8772. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  8773. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  8774. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  8775. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  8776. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  8777. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  8778. ];
  8779. var ExpertCharset = [
  8780. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  8781. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  8782. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  8783. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  8784. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  8785. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  8786. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  8787. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  8788. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8789. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8790. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8791. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  8792. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  8793. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  8794. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  8795. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  8796. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  8797. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  8798. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  8799. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  8800. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  8801. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  8802. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8803. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8804. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8805. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8806. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8807. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8808. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  8809. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  8810. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  8811. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  8812. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  8813. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  8814. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  8815. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  8816. 'Ydieresissmall'
  8817. ];
  8818. var ExpertSubsetCharset = [
  8819. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  8820. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  8821. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  8822. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  8823. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  8824. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  8825. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  8826. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8827. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8828. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8829. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  8830. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  8831. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  8832. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8833. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8834. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8835. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8836. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8837. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8838. 'periodinferior', 'commainferior'
  8839. ];
  8840. exports.ISOAdobeCharset = ISOAdobeCharset;
  8841. exports.ExpertCharset = ExpertCharset;
  8842. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  8843. }));
  8844. (function (root, factory) {
  8845. {
  8846. factory((root.pdfjsCoreGlyphList = {}));
  8847. }
  8848. }(this, function (exports) {
  8849. var GlyphsUnicode = {
  8850. A: 0x0041,
  8851. AE: 0x00C6,
  8852. AEacute: 0x01FC,
  8853. AEmacron: 0x01E2,
  8854. AEsmall: 0xF7E6,
  8855. Aacute: 0x00C1,
  8856. Aacutesmall: 0xF7E1,
  8857. Abreve: 0x0102,
  8858. Abreveacute: 0x1EAE,
  8859. Abrevecyrillic: 0x04D0,
  8860. Abrevedotbelow: 0x1EB6,
  8861. Abrevegrave: 0x1EB0,
  8862. Abrevehookabove: 0x1EB2,
  8863. Abrevetilde: 0x1EB4,
  8864. Acaron: 0x01CD,
  8865. Acircle: 0x24B6,
  8866. Acircumflex: 0x00C2,
  8867. Acircumflexacute: 0x1EA4,
  8868. Acircumflexdotbelow: 0x1EAC,
  8869. Acircumflexgrave: 0x1EA6,
  8870. Acircumflexhookabove: 0x1EA8,
  8871. Acircumflexsmall: 0xF7E2,
  8872. Acircumflextilde: 0x1EAA,
  8873. Acute: 0xF6C9,
  8874. Acutesmall: 0xF7B4,
  8875. Acyrillic: 0x0410,
  8876. Adblgrave: 0x0200,
  8877. Adieresis: 0x00C4,
  8878. Adieresiscyrillic: 0x04D2,
  8879. Adieresismacron: 0x01DE,
  8880. Adieresissmall: 0xF7E4,
  8881. Adotbelow: 0x1EA0,
  8882. Adotmacron: 0x01E0,
  8883. Agrave: 0x00C0,
  8884. Agravesmall: 0xF7E0,
  8885. Ahookabove: 0x1EA2,
  8886. Aiecyrillic: 0x04D4,
  8887. Ainvertedbreve: 0x0202,
  8888. Alpha: 0x0391,
  8889. Alphatonos: 0x0386,
  8890. Amacron: 0x0100,
  8891. Amonospace: 0xFF21,
  8892. Aogonek: 0x0104,
  8893. Aring: 0x00C5,
  8894. Aringacute: 0x01FA,
  8895. Aringbelow: 0x1E00,
  8896. Aringsmall: 0xF7E5,
  8897. Asmall: 0xF761,
  8898. Atilde: 0x00C3,
  8899. Atildesmall: 0xF7E3,
  8900. Aybarmenian: 0x0531,
  8901. B: 0x0042,
  8902. Bcircle: 0x24B7,
  8903. Bdotaccent: 0x1E02,
  8904. Bdotbelow: 0x1E04,
  8905. Becyrillic: 0x0411,
  8906. Benarmenian: 0x0532,
  8907. Beta: 0x0392,
  8908. Bhook: 0x0181,
  8909. Blinebelow: 0x1E06,
  8910. Bmonospace: 0xFF22,
  8911. Brevesmall: 0xF6F4,
  8912. Bsmall: 0xF762,
  8913. Btopbar: 0x0182,
  8914. C: 0x0043,
  8915. Caarmenian: 0x053E,
  8916. Cacute: 0x0106,
  8917. Caron: 0xF6CA,
  8918. Caronsmall: 0xF6F5,
  8919. Ccaron: 0x010C,
  8920. Ccedilla: 0x00C7,
  8921. Ccedillaacute: 0x1E08,
  8922. Ccedillasmall: 0xF7E7,
  8923. Ccircle: 0x24B8,
  8924. Ccircumflex: 0x0108,
  8925. Cdot: 0x010A,
  8926. Cdotaccent: 0x010A,
  8927. Cedillasmall: 0xF7B8,
  8928. Chaarmenian: 0x0549,
  8929. Cheabkhasiancyrillic: 0x04BC,
  8930. Checyrillic: 0x0427,
  8931. Chedescenderabkhasiancyrillic: 0x04BE,
  8932. Chedescendercyrillic: 0x04B6,
  8933. Chedieresiscyrillic: 0x04F4,
  8934. Cheharmenian: 0x0543,
  8935. Chekhakassiancyrillic: 0x04CB,
  8936. Cheverticalstrokecyrillic: 0x04B8,
  8937. Chi: 0x03A7,
  8938. Chook: 0x0187,
  8939. Circumflexsmall: 0xF6F6,
  8940. Cmonospace: 0xFF23,
  8941. Coarmenian: 0x0551,
  8942. Csmall: 0xF763,
  8943. D: 0x0044,
  8944. DZ: 0x01F1,
  8945. DZcaron: 0x01C4,
  8946. Daarmenian: 0x0534,
  8947. Dafrican: 0x0189,
  8948. Dcaron: 0x010E,
  8949. Dcedilla: 0x1E10,
  8950. Dcircle: 0x24B9,
  8951. Dcircumflexbelow: 0x1E12,
  8952. Dcroat: 0x0110,
  8953. Ddotaccent: 0x1E0A,
  8954. Ddotbelow: 0x1E0C,
  8955. Decyrillic: 0x0414,
  8956. Deicoptic: 0x03EE,
  8957. Delta: 0x2206,
  8958. Deltagreek: 0x0394,
  8959. Dhook: 0x018A,
  8960. Dieresis: 0xF6CB,
  8961. DieresisAcute: 0xF6CC,
  8962. DieresisGrave: 0xF6CD,
  8963. Dieresissmall: 0xF7A8,
  8964. Digammagreek: 0x03DC,
  8965. Djecyrillic: 0x0402,
  8966. Dlinebelow: 0x1E0E,
  8967. Dmonospace: 0xFF24,
  8968. Dotaccentsmall: 0xF6F7,
  8969. Dslash: 0x0110,
  8970. Dsmall: 0xF764,
  8971. Dtopbar: 0x018B,
  8972. Dz: 0x01F2,
  8973. Dzcaron: 0x01C5,
  8974. Dzeabkhasiancyrillic: 0x04E0,
  8975. Dzecyrillic: 0x0405,
  8976. Dzhecyrillic: 0x040F,
  8977. E: 0x0045,
  8978. Eacute: 0x00C9,
  8979. Eacutesmall: 0xF7E9,
  8980. Ebreve: 0x0114,
  8981. Ecaron: 0x011A,
  8982. Ecedillabreve: 0x1E1C,
  8983. Echarmenian: 0x0535,
  8984. Ecircle: 0x24BA,
  8985. Ecircumflex: 0x00CA,
  8986. Ecircumflexacute: 0x1EBE,
  8987. Ecircumflexbelow: 0x1E18,
  8988. Ecircumflexdotbelow: 0x1EC6,
  8989. Ecircumflexgrave: 0x1EC0,
  8990. Ecircumflexhookabove: 0x1EC2,
  8991. Ecircumflexsmall: 0xF7EA,
  8992. Ecircumflextilde: 0x1EC4,
  8993. Ecyrillic: 0x0404,
  8994. Edblgrave: 0x0204,
  8995. Edieresis: 0x00CB,
  8996. Edieresissmall: 0xF7EB,
  8997. Edot: 0x0116,
  8998. Edotaccent: 0x0116,
  8999. Edotbelow: 0x1EB8,
  9000. Efcyrillic: 0x0424,
  9001. Egrave: 0x00C8,
  9002. Egravesmall: 0xF7E8,
  9003. Eharmenian: 0x0537,
  9004. Ehookabove: 0x1EBA,
  9005. Eightroman: 0x2167,
  9006. Einvertedbreve: 0x0206,
  9007. Eiotifiedcyrillic: 0x0464,
  9008. Elcyrillic: 0x041B,
  9009. Elevenroman: 0x216A,
  9010. Emacron: 0x0112,
  9011. Emacronacute: 0x1E16,
  9012. Emacrongrave: 0x1E14,
  9013. Emcyrillic: 0x041C,
  9014. Emonospace: 0xFF25,
  9015. Encyrillic: 0x041D,
  9016. Endescendercyrillic: 0x04A2,
  9017. Eng: 0x014A,
  9018. Enghecyrillic: 0x04A4,
  9019. Enhookcyrillic: 0x04C7,
  9020. Eogonek: 0x0118,
  9021. Eopen: 0x0190,
  9022. Epsilon: 0x0395,
  9023. Epsilontonos: 0x0388,
  9024. Ercyrillic: 0x0420,
  9025. Ereversed: 0x018E,
  9026. Ereversedcyrillic: 0x042D,
  9027. Escyrillic: 0x0421,
  9028. Esdescendercyrillic: 0x04AA,
  9029. Esh: 0x01A9,
  9030. Esmall: 0xF765,
  9031. Eta: 0x0397,
  9032. Etarmenian: 0x0538,
  9033. Etatonos: 0x0389,
  9034. Eth: 0x00D0,
  9035. Ethsmall: 0xF7F0,
  9036. Etilde: 0x1EBC,
  9037. Etildebelow: 0x1E1A,
  9038. Euro: 0x20AC,
  9039. Ezh: 0x01B7,
  9040. Ezhcaron: 0x01EE,
  9041. Ezhreversed: 0x01B8,
  9042. F: 0x0046,
  9043. Fcircle: 0x24BB,
  9044. Fdotaccent: 0x1E1E,
  9045. Feharmenian: 0x0556,
  9046. Feicoptic: 0x03E4,
  9047. Fhook: 0x0191,
  9048. Fitacyrillic: 0x0472,
  9049. Fiveroman: 0x2164,
  9050. Fmonospace: 0xFF26,
  9051. Fourroman: 0x2163,
  9052. Fsmall: 0xF766,
  9053. G: 0x0047,
  9054. GBsquare: 0x3387,
  9055. Gacute: 0x01F4,
  9056. Gamma: 0x0393,
  9057. Gammaafrican: 0x0194,
  9058. Gangiacoptic: 0x03EA,
  9059. Gbreve: 0x011E,
  9060. Gcaron: 0x01E6,
  9061. Gcedilla: 0x0122,
  9062. Gcircle: 0x24BC,
  9063. Gcircumflex: 0x011C,
  9064. Gcommaaccent: 0x0122,
  9065. Gdot: 0x0120,
  9066. Gdotaccent: 0x0120,
  9067. Gecyrillic: 0x0413,
  9068. Ghadarmenian: 0x0542,
  9069. Ghemiddlehookcyrillic: 0x0494,
  9070. Ghestrokecyrillic: 0x0492,
  9071. Gheupturncyrillic: 0x0490,
  9072. Ghook: 0x0193,
  9073. Gimarmenian: 0x0533,
  9074. Gjecyrillic: 0x0403,
  9075. Gmacron: 0x1E20,
  9076. Gmonospace: 0xFF27,
  9077. Grave: 0xF6CE,
  9078. Gravesmall: 0xF760,
  9079. Gsmall: 0xF767,
  9080. Gsmallhook: 0x029B,
  9081. Gstroke: 0x01E4,
  9082. H: 0x0048,
  9083. H18533: 0x25CF,
  9084. H18543: 0x25AA,
  9085. H18551: 0x25AB,
  9086. H22073: 0x25A1,
  9087. HPsquare: 0x33CB,
  9088. Haabkhasiancyrillic: 0x04A8,
  9089. Hadescendercyrillic: 0x04B2,
  9090. Hardsigncyrillic: 0x042A,
  9091. Hbar: 0x0126,
  9092. Hbrevebelow: 0x1E2A,
  9093. Hcedilla: 0x1E28,
  9094. Hcircle: 0x24BD,
  9095. Hcircumflex: 0x0124,
  9096. Hdieresis: 0x1E26,
  9097. Hdotaccent: 0x1E22,
  9098. Hdotbelow: 0x1E24,
  9099. Hmonospace: 0xFF28,
  9100. Hoarmenian: 0x0540,
  9101. Horicoptic: 0x03E8,
  9102. Hsmall: 0xF768,
  9103. Hungarumlaut: 0xF6CF,
  9104. Hungarumlautsmall: 0xF6F8,
  9105. Hzsquare: 0x3390,
  9106. I: 0x0049,
  9107. IAcyrillic: 0x042F,
  9108. IJ: 0x0132,
  9109. IUcyrillic: 0x042E,
  9110. Iacute: 0x00CD,
  9111. Iacutesmall: 0xF7ED,
  9112. Ibreve: 0x012C,
  9113. Icaron: 0x01CF,
  9114. Icircle: 0x24BE,
  9115. Icircumflex: 0x00CE,
  9116. Icircumflexsmall: 0xF7EE,
  9117. Icyrillic: 0x0406,
  9118. Idblgrave: 0x0208,
  9119. Idieresis: 0x00CF,
  9120. Idieresisacute: 0x1E2E,
  9121. Idieresiscyrillic: 0x04E4,
  9122. Idieresissmall: 0xF7EF,
  9123. Idot: 0x0130,
  9124. Idotaccent: 0x0130,
  9125. Idotbelow: 0x1ECA,
  9126. Iebrevecyrillic: 0x04D6,
  9127. Iecyrillic: 0x0415,
  9128. Ifraktur: 0x2111,
  9129. Igrave: 0x00CC,
  9130. Igravesmall: 0xF7EC,
  9131. Ihookabove: 0x1EC8,
  9132. Iicyrillic: 0x0418,
  9133. Iinvertedbreve: 0x020A,
  9134. Iishortcyrillic: 0x0419,
  9135. Imacron: 0x012A,
  9136. Imacroncyrillic: 0x04E2,
  9137. Imonospace: 0xFF29,
  9138. Iniarmenian: 0x053B,
  9139. Iocyrillic: 0x0401,
  9140. Iogonek: 0x012E,
  9141. Iota: 0x0399,
  9142. Iotaafrican: 0x0196,
  9143. Iotadieresis: 0x03AA,
  9144. Iotatonos: 0x038A,
  9145. Ismall: 0xF769,
  9146. Istroke: 0x0197,
  9147. Itilde: 0x0128,
  9148. Itildebelow: 0x1E2C,
  9149. Izhitsacyrillic: 0x0474,
  9150. Izhitsadblgravecyrillic: 0x0476,
  9151. J: 0x004A,
  9152. Jaarmenian: 0x0541,
  9153. Jcircle: 0x24BF,
  9154. Jcircumflex: 0x0134,
  9155. Jecyrillic: 0x0408,
  9156. Jheharmenian: 0x054B,
  9157. Jmonospace: 0xFF2A,
  9158. Jsmall: 0xF76A,
  9159. K: 0x004B,
  9160. KBsquare: 0x3385,
  9161. KKsquare: 0x33CD,
  9162. Kabashkircyrillic: 0x04A0,
  9163. Kacute: 0x1E30,
  9164. Kacyrillic: 0x041A,
  9165. Kadescendercyrillic: 0x049A,
  9166. Kahookcyrillic: 0x04C3,
  9167. Kappa: 0x039A,
  9168. Kastrokecyrillic: 0x049E,
  9169. Kaverticalstrokecyrillic: 0x049C,
  9170. Kcaron: 0x01E8,
  9171. Kcedilla: 0x0136,
  9172. Kcircle: 0x24C0,
  9173. Kcommaaccent: 0x0136,
  9174. Kdotbelow: 0x1E32,
  9175. Keharmenian: 0x0554,
  9176. Kenarmenian: 0x053F,
  9177. Khacyrillic: 0x0425,
  9178. Kheicoptic: 0x03E6,
  9179. Khook: 0x0198,
  9180. Kjecyrillic: 0x040C,
  9181. Klinebelow: 0x1E34,
  9182. Kmonospace: 0xFF2B,
  9183. Koppacyrillic: 0x0480,
  9184. Koppagreek: 0x03DE,
  9185. Ksicyrillic: 0x046E,
  9186. Ksmall: 0xF76B,
  9187. L: 0x004C,
  9188. LJ: 0x01C7,
  9189. LL: 0xF6BF,
  9190. Lacute: 0x0139,
  9191. Lambda: 0x039B,
  9192. Lcaron: 0x013D,
  9193. Lcedilla: 0x013B,
  9194. Lcircle: 0x24C1,
  9195. Lcircumflexbelow: 0x1E3C,
  9196. Lcommaaccent: 0x013B,
  9197. Ldot: 0x013F,
  9198. Ldotaccent: 0x013F,
  9199. Ldotbelow: 0x1E36,
  9200. Ldotbelowmacron: 0x1E38,
  9201. Liwnarmenian: 0x053C,
  9202. Lj: 0x01C8,
  9203. Ljecyrillic: 0x0409,
  9204. Llinebelow: 0x1E3A,
  9205. Lmonospace: 0xFF2C,
  9206. Lslash: 0x0141,
  9207. Lslashsmall: 0xF6F9,
  9208. Lsmall: 0xF76C,
  9209. M: 0x004D,
  9210. MBsquare: 0x3386,
  9211. Macron: 0xF6D0,
  9212. Macronsmall: 0xF7AF,
  9213. Macute: 0x1E3E,
  9214. Mcircle: 0x24C2,
  9215. Mdotaccent: 0x1E40,
  9216. Mdotbelow: 0x1E42,
  9217. Menarmenian: 0x0544,
  9218. Mmonospace: 0xFF2D,
  9219. Msmall: 0xF76D,
  9220. Mturned: 0x019C,
  9221. Mu: 0x039C,
  9222. N: 0x004E,
  9223. NJ: 0x01CA,
  9224. Nacute: 0x0143,
  9225. Ncaron: 0x0147,
  9226. Ncedilla: 0x0145,
  9227. Ncircle: 0x24C3,
  9228. Ncircumflexbelow: 0x1E4A,
  9229. Ncommaaccent: 0x0145,
  9230. Ndotaccent: 0x1E44,
  9231. Ndotbelow: 0x1E46,
  9232. Nhookleft: 0x019D,
  9233. Nineroman: 0x2168,
  9234. Nj: 0x01CB,
  9235. Njecyrillic: 0x040A,
  9236. Nlinebelow: 0x1E48,
  9237. Nmonospace: 0xFF2E,
  9238. Nowarmenian: 0x0546,
  9239. Nsmall: 0xF76E,
  9240. Ntilde: 0x00D1,
  9241. Ntildesmall: 0xF7F1,
  9242. Nu: 0x039D,
  9243. O: 0x004F,
  9244. OE: 0x0152,
  9245. OEsmall: 0xF6FA,
  9246. Oacute: 0x00D3,
  9247. Oacutesmall: 0xF7F3,
  9248. Obarredcyrillic: 0x04E8,
  9249. Obarreddieresiscyrillic: 0x04EA,
  9250. Obreve: 0x014E,
  9251. Ocaron: 0x01D1,
  9252. Ocenteredtilde: 0x019F,
  9253. Ocircle: 0x24C4,
  9254. Ocircumflex: 0x00D4,
  9255. Ocircumflexacute: 0x1ED0,
  9256. Ocircumflexdotbelow: 0x1ED8,
  9257. Ocircumflexgrave: 0x1ED2,
  9258. Ocircumflexhookabove: 0x1ED4,
  9259. Ocircumflexsmall: 0xF7F4,
  9260. Ocircumflextilde: 0x1ED6,
  9261. Ocyrillic: 0x041E,
  9262. Odblacute: 0x0150,
  9263. Odblgrave: 0x020C,
  9264. Odieresis: 0x00D6,
  9265. Odieresiscyrillic: 0x04E6,
  9266. Odieresissmall: 0xF7F6,
  9267. Odotbelow: 0x1ECC,
  9268. Ogoneksmall: 0xF6FB,
  9269. Ograve: 0x00D2,
  9270. Ogravesmall: 0xF7F2,
  9271. Oharmenian: 0x0555,
  9272. Ohm: 0x2126,
  9273. Ohookabove: 0x1ECE,
  9274. Ohorn: 0x01A0,
  9275. Ohornacute: 0x1EDA,
  9276. Ohorndotbelow: 0x1EE2,
  9277. Ohorngrave: 0x1EDC,
  9278. Ohornhookabove: 0x1EDE,
  9279. Ohorntilde: 0x1EE0,
  9280. Ohungarumlaut: 0x0150,
  9281. Oi: 0x01A2,
  9282. Oinvertedbreve: 0x020E,
  9283. Omacron: 0x014C,
  9284. Omacronacute: 0x1E52,
  9285. Omacrongrave: 0x1E50,
  9286. Omega: 0x2126,
  9287. Omegacyrillic: 0x0460,
  9288. Omegagreek: 0x03A9,
  9289. Omegaroundcyrillic: 0x047A,
  9290. Omegatitlocyrillic: 0x047C,
  9291. Omegatonos: 0x038F,
  9292. Omicron: 0x039F,
  9293. Omicrontonos: 0x038C,
  9294. Omonospace: 0xFF2F,
  9295. Oneroman: 0x2160,
  9296. Oogonek: 0x01EA,
  9297. Oogonekmacron: 0x01EC,
  9298. Oopen: 0x0186,
  9299. Oslash: 0x00D8,
  9300. Oslashacute: 0x01FE,
  9301. Oslashsmall: 0xF7F8,
  9302. Osmall: 0xF76F,
  9303. Ostrokeacute: 0x01FE,
  9304. Otcyrillic: 0x047E,
  9305. Otilde: 0x00D5,
  9306. Otildeacute: 0x1E4C,
  9307. Otildedieresis: 0x1E4E,
  9308. Otildesmall: 0xF7F5,
  9309. P: 0x0050,
  9310. Pacute: 0x1E54,
  9311. Pcircle: 0x24C5,
  9312. Pdotaccent: 0x1E56,
  9313. Pecyrillic: 0x041F,
  9314. Peharmenian: 0x054A,
  9315. Pemiddlehookcyrillic: 0x04A6,
  9316. Phi: 0x03A6,
  9317. Phook: 0x01A4,
  9318. Pi: 0x03A0,
  9319. Piwrarmenian: 0x0553,
  9320. Pmonospace: 0xFF30,
  9321. Psi: 0x03A8,
  9322. Psicyrillic: 0x0470,
  9323. Psmall: 0xF770,
  9324. Q: 0x0051,
  9325. Qcircle: 0x24C6,
  9326. Qmonospace: 0xFF31,
  9327. Qsmall: 0xF771,
  9328. R: 0x0052,
  9329. Raarmenian: 0x054C,
  9330. Racute: 0x0154,
  9331. Rcaron: 0x0158,
  9332. Rcedilla: 0x0156,
  9333. Rcircle: 0x24C7,
  9334. Rcommaaccent: 0x0156,
  9335. Rdblgrave: 0x0210,
  9336. Rdotaccent: 0x1E58,
  9337. Rdotbelow: 0x1E5A,
  9338. Rdotbelowmacron: 0x1E5C,
  9339. Reharmenian: 0x0550,
  9340. Rfraktur: 0x211C,
  9341. Rho: 0x03A1,
  9342. Ringsmall: 0xF6FC,
  9343. Rinvertedbreve: 0x0212,
  9344. Rlinebelow: 0x1E5E,
  9345. Rmonospace: 0xFF32,
  9346. Rsmall: 0xF772,
  9347. Rsmallinverted: 0x0281,
  9348. Rsmallinvertedsuperior: 0x02B6,
  9349. S: 0x0053,
  9350. SF010000: 0x250C,
  9351. SF020000: 0x2514,
  9352. SF030000: 0x2510,
  9353. SF040000: 0x2518,
  9354. SF050000: 0x253C,
  9355. SF060000: 0x252C,
  9356. SF070000: 0x2534,
  9357. SF080000: 0x251C,
  9358. SF090000: 0x2524,
  9359. SF100000: 0x2500,
  9360. SF110000: 0x2502,
  9361. SF190000: 0x2561,
  9362. SF200000: 0x2562,
  9363. SF210000: 0x2556,
  9364. SF220000: 0x2555,
  9365. SF230000: 0x2563,
  9366. SF240000: 0x2551,
  9367. SF250000: 0x2557,
  9368. SF260000: 0x255D,
  9369. SF270000: 0x255C,
  9370. SF280000: 0x255B,
  9371. SF360000: 0x255E,
  9372. SF370000: 0x255F,
  9373. SF380000: 0x255A,
  9374. SF390000: 0x2554,
  9375. SF400000: 0x2569,
  9376. SF410000: 0x2566,
  9377. SF420000: 0x2560,
  9378. SF430000: 0x2550,
  9379. SF440000: 0x256C,
  9380. SF450000: 0x2567,
  9381. SF460000: 0x2568,
  9382. SF470000: 0x2564,
  9383. SF480000: 0x2565,
  9384. SF490000: 0x2559,
  9385. SF500000: 0x2558,
  9386. SF510000: 0x2552,
  9387. SF520000: 0x2553,
  9388. SF530000: 0x256B,
  9389. SF540000: 0x256A,
  9390. Sacute: 0x015A,
  9391. Sacutedotaccent: 0x1E64,
  9392. Sampigreek: 0x03E0,
  9393. Scaron: 0x0160,
  9394. Scarondotaccent: 0x1E66,
  9395. Scaronsmall: 0xF6FD,
  9396. Scedilla: 0x015E,
  9397. Schwa: 0x018F,
  9398. Schwacyrillic: 0x04D8,
  9399. Schwadieresiscyrillic: 0x04DA,
  9400. Scircle: 0x24C8,
  9401. Scircumflex: 0x015C,
  9402. Scommaaccent: 0x0218,
  9403. Sdotaccent: 0x1E60,
  9404. Sdotbelow: 0x1E62,
  9405. Sdotbelowdotaccent: 0x1E68,
  9406. Seharmenian: 0x054D,
  9407. Sevenroman: 0x2166,
  9408. Shaarmenian: 0x0547,
  9409. Shacyrillic: 0x0428,
  9410. Shchacyrillic: 0x0429,
  9411. Sheicoptic: 0x03E2,
  9412. Shhacyrillic: 0x04BA,
  9413. Shimacoptic: 0x03EC,
  9414. Sigma: 0x03A3,
  9415. Sixroman: 0x2165,
  9416. Smonospace: 0xFF33,
  9417. Softsigncyrillic: 0x042C,
  9418. Ssmall: 0xF773,
  9419. Stigmagreek: 0x03DA,
  9420. T: 0x0054,
  9421. Tau: 0x03A4,
  9422. Tbar: 0x0166,
  9423. Tcaron: 0x0164,
  9424. Tcedilla: 0x0162,
  9425. Tcircle: 0x24C9,
  9426. Tcircumflexbelow: 0x1E70,
  9427. Tcommaaccent: 0x0162,
  9428. Tdotaccent: 0x1E6A,
  9429. Tdotbelow: 0x1E6C,
  9430. Tecyrillic: 0x0422,
  9431. Tedescendercyrillic: 0x04AC,
  9432. Tenroman: 0x2169,
  9433. Tetsecyrillic: 0x04B4,
  9434. Theta: 0x0398,
  9435. Thook: 0x01AC,
  9436. Thorn: 0x00DE,
  9437. Thornsmall: 0xF7FE,
  9438. Threeroman: 0x2162,
  9439. Tildesmall: 0xF6FE,
  9440. Tiwnarmenian: 0x054F,
  9441. Tlinebelow: 0x1E6E,
  9442. Tmonospace: 0xFF34,
  9443. Toarmenian: 0x0539,
  9444. Tonefive: 0x01BC,
  9445. Tonesix: 0x0184,
  9446. Tonetwo: 0x01A7,
  9447. Tretroflexhook: 0x01AE,
  9448. Tsecyrillic: 0x0426,
  9449. Tshecyrillic: 0x040B,
  9450. Tsmall: 0xF774,
  9451. Twelveroman: 0x216B,
  9452. Tworoman: 0x2161,
  9453. U: 0x0055,
  9454. Uacute: 0x00DA,
  9455. Uacutesmall: 0xF7FA,
  9456. Ubreve: 0x016C,
  9457. Ucaron: 0x01D3,
  9458. Ucircle: 0x24CA,
  9459. Ucircumflex: 0x00DB,
  9460. Ucircumflexbelow: 0x1E76,
  9461. Ucircumflexsmall: 0xF7FB,
  9462. Ucyrillic: 0x0423,
  9463. Udblacute: 0x0170,
  9464. Udblgrave: 0x0214,
  9465. Udieresis: 0x00DC,
  9466. Udieresisacute: 0x01D7,
  9467. Udieresisbelow: 0x1E72,
  9468. Udieresiscaron: 0x01D9,
  9469. Udieresiscyrillic: 0x04F0,
  9470. Udieresisgrave: 0x01DB,
  9471. Udieresismacron: 0x01D5,
  9472. Udieresissmall: 0xF7FC,
  9473. Udotbelow: 0x1EE4,
  9474. Ugrave: 0x00D9,
  9475. Ugravesmall: 0xF7F9,
  9476. Uhookabove: 0x1EE6,
  9477. Uhorn: 0x01AF,
  9478. Uhornacute: 0x1EE8,
  9479. Uhorndotbelow: 0x1EF0,
  9480. Uhorngrave: 0x1EEA,
  9481. Uhornhookabove: 0x1EEC,
  9482. Uhorntilde: 0x1EEE,
  9483. Uhungarumlaut: 0x0170,
  9484. Uhungarumlautcyrillic: 0x04F2,
  9485. Uinvertedbreve: 0x0216,
  9486. Ukcyrillic: 0x0478,
  9487. Umacron: 0x016A,
  9488. Umacroncyrillic: 0x04EE,
  9489. Umacrondieresis: 0x1E7A,
  9490. Umonospace: 0xFF35,
  9491. Uogonek: 0x0172,
  9492. Upsilon: 0x03A5,
  9493. Upsilon1: 0x03D2,
  9494. Upsilonacutehooksymbolgreek: 0x03D3,
  9495. Upsilonafrican: 0x01B1,
  9496. Upsilondieresis: 0x03AB,
  9497. Upsilondieresishooksymbolgreek: 0x03D4,
  9498. Upsilonhooksymbol: 0x03D2,
  9499. Upsilontonos: 0x038E,
  9500. Uring: 0x016E,
  9501. Ushortcyrillic: 0x040E,
  9502. Usmall: 0xF775,
  9503. Ustraightcyrillic: 0x04AE,
  9504. Ustraightstrokecyrillic: 0x04B0,
  9505. Utilde: 0x0168,
  9506. Utildeacute: 0x1E78,
  9507. Utildebelow: 0x1E74,
  9508. V: 0x0056,
  9509. Vcircle: 0x24CB,
  9510. Vdotbelow: 0x1E7E,
  9511. Vecyrillic: 0x0412,
  9512. Vewarmenian: 0x054E,
  9513. Vhook: 0x01B2,
  9514. Vmonospace: 0xFF36,
  9515. Voarmenian: 0x0548,
  9516. Vsmall: 0xF776,
  9517. Vtilde: 0x1E7C,
  9518. W: 0x0057,
  9519. Wacute: 0x1E82,
  9520. Wcircle: 0x24CC,
  9521. Wcircumflex: 0x0174,
  9522. Wdieresis: 0x1E84,
  9523. Wdotaccent: 0x1E86,
  9524. Wdotbelow: 0x1E88,
  9525. Wgrave: 0x1E80,
  9526. Wmonospace: 0xFF37,
  9527. Wsmall: 0xF777,
  9528. X: 0x0058,
  9529. Xcircle: 0x24CD,
  9530. Xdieresis: 0x1E8C,
  9531. Xdotaccent: 0x1E8A,
  9532. Xeharmenian: 0x053D,
  9533. Xi: 0x039E,
  9534. Xmonospace: 0xFF38,
  9535. Xsmall: 0xF778,
  9536. Y: 0x0059,
  9537. Yacute: 0x00DD,
  9538. Yacutesmall: 0xF7FD,
  9539. Yatcyrillic: 0x0462,
  9540. Ycircle: 0x24CE,
  9541. Ycircumflex: 0x0176,
  9542. Ydieresis: 0x0178,
  9543. Ydieresissmall: 0xF7FF,
  9544. Ydotaccent: 0x1E8E,
  9545. Ydotbelow: 0x1EF4,
  9546. Yericyrillic: 0x042B,
  9547. Yerudieresiscyrillic: 0x04F8,
  9548. Ygrave: 0x1EF2,
  9549. Yhook: 0x01B3,
  9550. Yhookabove: 0x1EF6,
  9551. Yiarmenian: 0x0545,
  9552. Yicyrillic: 0x0407,
  9553. Yiwnarmenian: 0x0552,
  9554. Ymonospace: 0xFF39,
  9555. Ysmall: 0xF779,
  9556. Ytilde: 0x1EF8,
  9557. Yusbigcyrillic: 0x046A,
  9558. Yusbigiotifiedcyrillic: 0x046C,
  9559. Yuslittlecyrillic: 0x0466,
  9560. Yuslittleiotifiedcyrillic: 0x0468,
  9561. Z: 0x005A,
  9562. Zaarmenian: 0x0536,
  9563. Zacute: 0x0179,
  9564. Zcaron: 0x017D,
  9565. Zcaronsmall: 0xF6FF,
  9566. Zcircle: 0x24CF,
  9567. Zcircumflex: 0x1E90,
  9568. Zdot: 0x017B,
  9569. Zdotaccent: 0x017B,
  9570. Zdotbelow: 0x1E92,
  9571. Zecyrillic: 0x0417,
  9572. Zedescendercyrillic: 0x0498,
  9573. Zedieresiscyrillic: 0x04DE,
  9574. Zeta: 0x0396,
  9575. Zhearmenian: 0x053A,
  9576. Zhebrevecyrillic: 0x04C1,
  9577. Zhecyrillic: 0x0416,
  9578. Zhedescendercyrillic: 0x0496,
  9579. Zhedieresiscyrillic: 0x04DC,
  9580. Zlinebelow: 0x1E94,
  9581. Zmonospace: 0xFF3A,
  9582. Zsmall: 0xF77A,
  9583. Zstroke: 0x01B5,
  9584. a: 0x0061,
  9585. aabengali: 0x0986,
  9586. aacute: 0x00E1,
  9587. aadeva: 0x0906,
  9588. aagujarati: 0x0A86,
  9589. aagurmukhi: 0x0A06,
  9590. aamatragurmukhi: 0x0A3E,
  9591. aarusquare: 0x3303,
  9592. aavowelsignbengali: 0x09BE,
  9593. aavowelsigndeva: 0x093E,
  9594. aavowelsigngujarati: 0x0ABE,
  9595. abbreviationmarkarmenian: 0x055F,
  9596. abbreviationsigndeva: 0x0970,
  9597. abengali: 0x0985,
  9598. abopomofo: 0x311A,
  9599. abreve: 0x0103,
  9600. abreveacute: 0x1EAF,
  9601. abrevecyrillic: 0x04D1,
  9602. abrevedotbelow: 0x1EB7,
  9603. abrevegrave: 0x1EB1,
  9604. abrevehookabove: 0x1EB3,
  9605. abrevetilde: 0x1EB5,
  9606. acaron: 0x01CE,
  9607. acircle: 0x24D0,
  9608. acircumflex: 0x00E2,
  9609. acircumflexacute: 0x1EA5,
  9610. acircumflexdotbelow: 0x1EAD,
  9611. acircumflexgrave: 0x1EA7,
  9612. acircumflexhookabove: 0x1EA9,
  9613. acircumflextilde: 0x1EAB,
  9614. acute: 0x00B4,
  9615. acutebelowcmb: 0x0317,
  9616. acutecmb: 0x0301,
  9617. acutecomb: 0x0301,
  9618. acutedeva: 0x0954,
  9619. acutelowmod: 0x02CF,
  9620. acutetonecmb: 0x0341,
  9621. acyrillic: 0x0430,
  9622. adblgrave: 0x0201,
  9623. addakgurmukhi: 0x0A71,
  9624. adeva: 0x0905,
  9625. adieresis: 0x00E4,
  9626. adieresiscyrillic: 0x04D3,
  9627. adieresismacron: 0x01DF,
  9628. adotbelow: 0x1EA1,
  9629. adotmacron: 0x01E1,
  9630. ae: 0x00E6,
  9631. aeacute: 0x01FD,
  9632. aekorean: 0x3150,
  9633. aemacron: 0x01E3,
  9634. afii00208: 0x2015,
  9635. afii08941: 0x20A4,
  9636. afii10017: 0x0410,
  9637. afii10018: 0x0411,
  9638. afii10019: 0x0412,
  9639. afii10020: 0x0413,
  9640. afii10021: 0x0414,
  9641. afii10022: 0x0415,
  9642. afii10023: 0x0401,
  9643. afii10024: 0x0416,
  9644. afii10025: 0x0417,
  9645. afii10026: 0x0418,
  9646. afii10027: 0x0419,
  9647. afii10028: 0x041A,
  9648. afii10029: 0x041B,
  9649. afii10030: 0x041C,
  9650. afii10031: 0x041D,
  9651. afii10032: 0x041E,
  9652. afii10033: 0x041F,
  9653. afii10034: 0x0420,
  9654. afii10035: 0x0421,
  9655. afii10036: 0x0422,
  9656. afii10037: 0x0423,
  9657. afii10038: 0x0424,
  9658. afii10039: 0x0425,
  9659. afii10040: 0x0426,
  9660. afii10041: 0x0427,
  9661. afii10042: 0x0428,
  9662. afii10043: 0x0429,
  9663. afii10044: 0x042A,
  9664. afii10045: 0x042B,
  9665. afii10046: 0x042C,
  9666. afii10047: 0x042D,
  9667. afii10048: 0x042E,
  9668. afii10049: 0x042F,
  9669. afii10050: 0x0490,
  9670. afii10051: 0x0402,
  9671. afii10052: 0x0403,
  9672. afii10053: 0x0404,
  9673. afii10054: 0x0405,
  9674. afii10055: 0x0406,
  9675. afii10056: 0x0407,
  9676. afii10057: 0x0408,
  9677. afii10058: 0x0409,
  9678. afii10059: 0x040A,
  9679. afii10060: 0x040B,
  9680. afii10061: 0x040C,
  9681. afii10062: 0x040E,
  9682. afii10063: 0xF6C4,
  9683. afii10064: 0xF6C5,
  9684. afii10065: 0x0430,
  9685. afii10066: 0x0431,
  9686. afii10067: 0x0432,
  9687. afii10068: 0x0433,
  9688. afii10069: 0x0434,
  9689. afii10070: 0x0435,
  9690. afii10071: 0x0451,
  9691. afii10072: 0x0436,
  9692. afii10073: 0x0437,
  9693. afii10074: 0x0438,
  9694. afii10075: 0x0439,
  9695. afii10076: 0x043A,
  9696. afii10077: 0x043B,
  9697. afii10078: 0x043C,
  9698. afii10079: 0x043D,
  9699. afii10080: 0x043E,
  9700. afii10081: 0x043F,
  9701. afii10082: 0x0440,
  9702. afii10083: 0x0441,
  9703. afii10084: 0x0442,
  9704. afii10085: 0x0443,
  9705. afii10086: 0x0444,
  9706. afii10087: 0x0445,
  9707. afii10088: 0x0446,
  9708. afii10089: 0x0447,
  9709. afii10090: 0x0448,
  9710. afii10091: 0x0449,
  9711. afii10092: 0x044A,
  9712. afii10093: 0x044B,
  9713. afii10094: 0x044C,
  9714. afii10095: 0x044D,
  9715. afii10096: 0x044E,
  9716. afii10097: 0x044F,
  9717. afii10098: 0x0491,
  9718. afii10099: 0x0452,
  9719. afii10100: 0x0453,
  9720. afii10101: 0x0454,
  9721. afii10102: 0x0455,
  9722. afii10103: 0x0456,
  9723. afii10104: 0x0457,
  9724. afii10105: 0x0458,
  9725. afii10106: 0x0459,
  9726. afii10107: 0x045A,
  9727. afii10108: 0x045B,
  9728. afii10109: 0x045C,
  9729. afii10110: 0x045E,
  9730. afii10145: 0x040F,
  9731. afii10146: 0x0462,
  9732. afii10147: 0x0472,
  9733. afii10148: 0x0474,
  9734. afii10192: 0xF6C6,
  9735. afii10193: 0x045F,
  9736. afii10194: 0x0463,
  9737. afii10195: 0x0473,
  9738. afii10196: 0x0475,
  9739. afii10831: 0xF6C7,
  9740. afii10832: 0xF6C8,
  9741. afii10846: 0x04D9,
  9742. afii299: 0x200E,
  9743. afii300: 0x200F,
  9744. afii301: 0x200D,
  9745. afii57381: 0x066A,
  9746. afii57388: 0x060C,
  9747. afii57392: 0x0660,
  9748. afii57393: 0x0661,
  9749. afii57394: 0x0662,
  9750. afii57395: 0x0663,
  9751. afii57396: 0x0664,
  9752. afii57397: 0x0665,
  9753. afii57398: 0x0666,
  9754. afii57399: 0x0667,
  9755. afii57400: 0x0668,
  9756. afii57401: 0x0669,
  9757. afii57403: 0x061B,
  9758. afii57407: 0x061F,
  9759. afii57409: 0x0621,
  9760. afii57410: 0x0622,
  9761. afii57411: 0x0623,
  9762. afii57412: 0x0624,
  9763. afii57413: 0x0625,
  9764. afii57414: 0x0626,
  9765. afii57415: 0x0627,
  9766. afii57416: 0x0628,
  9767. afii57417: 0x0629,
  9768. afii57418: 0x062A,
  9769. afii57419: 0x062B,
  9770. afii57420: 0x062C,
  9771. afii57421: 0x062D,
  9772. afii57422: 0x062E,
  9773. afii57423: 0x062F,
  9774. afii57424: 0x0630,
  9775. afii57425: 0x0631,
  9776. afii57426: 0x0632,
  9777. afii57427: 0x0633,
  9778. afii57428: 0x0634,
  9779. afii57429: 0x0635,
  9780. afii57430: 0x0636,
  9781. afii57431: 0x0637,
  9782. afii57432: 0x0638,
  9783. afii57433: 0x0639,
  9784. afii57434: 0x063A,
  9785. afii57440: 0x0640,
  9786. afii57441: 0x0641,
  9787. afii57442: 0x0642,
  9788. afii57443: 0x0643,
  9789. afii57444: 0x0644,
  9790. afii57445: 0x0645,
  9791. afii57446: 0x0646,
  9792. afii57448: 0x0648,
  9793. afii57449: 0x0649,
  9794. afii57450: 0x064A,
  9795. afii57451: 0x064B,
  9796. afii57452: 0x064C,
  9797. afii57453: 0x064D,
  9798. afii57454: 0x064E,
  9799. afii57455: 0x064F,
  9800. afii57456: 0x0650,
  9801. afii57457: 0x0651,
  9802. afii57458: 0x0652,
  9803. afii57470: 0x0647,
  9804. afii57505: 0x06A4,
  9805. afii57506: 0x067E,
  9806. afii57507: 0x0686,
  9807. afii57508: 0x0698,
  9808. afii57509: 0x06AF,
  9809. afii57511: 0x0679,
  9810. afii57512: 0x0688,
  9811. afii57513: 0x0691,
  9812. afii57514: 0x06BA,
  9813. afii57519: 0x06D2,
  9814. afii57534: 0x06D5,
  9815. afii57636: 0x20AA,
  9816. afii57645: 0x05BE,
  9817. afii57658: 0x05C3,
  9818. afii57664: 0x05D0,
  9819. afii57665: 0x05D1,
  9820. afii57666: 0x05D2,
  9821. afii57667: 0x05D3,
  9822. afii57668: 0x05D4,
  9823. afii57669: 0x05D5,
  9824. afii57670: 0x05D6,
  9825. afii57671: 0x05D7,
  9826. afii57672: 0x05D8,
  9827. afii57673: 0x05D9,
  9828. afii57674: 0x05DA,
  9829. afii57675: 0x05DB,
  9830. afii57676: 0x05DC,
  9831. afii57677: 0x05DD,
  9832. afii57678: 0x05DE,
  9833. afii57679: 0x05DF,
  9834. afii57680: 0x05E0,
  9835. afii57681: 0x05E1,
  9836. afii57682: 0x05E2,
  9837. afii57683: 0x05E3,
  9838. afii57684: 0x05E4,
  9839. afii57685: 0x05E5,
  9840. afii57686: 0x05E6,
  9841. afii57687: 0x05E7,
  9842. afii57688: 0x05E8,
  9843. afii57689: 0x05E9,
  9844. afii57690: 0x05EA,
  9845. afii57694: 0xFB2A,
  9846. afii57695: 0xFB2B,
  9847. afii57700: 0xFB4B,
  9848. afii57705: 0xFB1F,
  9849. afii57716: 0x05F0,
  9850. afii57717: 0x05F1,
  9851. afii57718: 0x05F2,
  9852. afii57723: 0xFB35,
  9853. afii57793: 0x05B4,
  9854. afii57794: 0x05B5,
  9855. afii57795: 0x05B6,
  9856. afii57796: 0x05BB,
  9857. afii57797: 0x05B8,
  9858. afii57798: 0x05B7,
  9859. afii57799: 0x05B0,
  9860. afii57800: 0x05B2,
  9861. afii57801: 0x05B1,
  9862. afii57802: 0x05B3,
  9863. afii57803: 0x05C2,
  9864. afii57804: 0x05C1,
  9865. afii57806: 0x05B9,
  9866. afii57807: 0x05BC,
  9867. afii57839: 0x05BD,
  9868. afii57841: 0x05BF,
  9869. afii57842: 0x05C0,
  9870. afii57929: 0x02BC,
  9871. afii61248: 0x2105,
  9872. afii61289: 0x2113,
  9873. afii61352: 0x2116,
  9874. afii61573: 0x202C,
  9875. afii61574: 0x202D,
  9876. afii61575: 0x202E,
  9877. afii61664: 0x200C,
  9878. afii63167: 0x066D,
  9879. afii64937: 0x02BD,
  9880. agrave: 0x00E0,
  9881. agujarati: 0x0A85,
  9882. agurmukhi: 0x0A05,
  9883. ahiragana: 0x3042,
  9884. ahookabove: 0x1EA3,
  9885. aibengali: 0x0990,
  9886. aibopomofo: 0x311E,
  9887. aideva: 0x0910,
  9888. aiecyrillic: 0x04D5,
  9889. aigujarati: 0x0A90,
  9890. aigurmukhi: 0x0A10,
  9891. aimatragurmukhi: 0x0A48,
  9892. ainarabic: 0x0639,
  9893. ainfinalarabic: 0xFECA,
  9894. aininitialarabic: 0xFECB,
  9895. ainmedialarabic: 0xFECC,
  9896. ainvertedbreve: 0x0203,
  9897. aivowelsignbengali: 0x09C8,
  9898. aivowelsigndeva: 0x0948,
  9899. aivowelsigngujarati: 0x0AC8,
  9900. akatakana: 0x30A2,
  9901. akatakanahalfwidth: 0xFF71,
  9902. akorean: 0x314F,
  9903. alef: 0x05D0,
  9904. alefarabic: 0x0627,
  9905. alefdageshhebrew: 0xFB30,
  9906. aleffinalarabic: 0xFE8E,
  9907. alefhamzaabovearabic: 0x0623,
  9908. alefhamzaabovefinalarabic: 0xFE84,
  9909. alefhamzabelowarabic: 0x0625,
  9910. alefhamzabelowfinalarabic: 0xFE88,
  9911. alefhebrew: 0x05D0,
  9912. aleflamedhebrew: 0xFB4F,
  9913. alefmaddaabovearabic: 0x0622,
  9914. alefmaddaabovefinalarabic: 0xFE82,
  9915. alefmaksuraarabic: 0x0649,
  9916. alefmaksurafinalarabic: 0xFEF0,
  9917. alefmaksurainitialarabic: 0xFEF3,
  9918. alefmaksuramedialarabic: 0xFEF4,
  9919. alefpatahhebrew: 0xFB2E,
  9920. alefqamatshebrew: 0xFB2F,
  9921. aleph: 0x2135,
  9922. allequal: 0x224C,
  9923. alpha: 0x03B1,
  9924. alphatonos: 0x03AC,
  9925. amacron: 0x0101,
  9926. amonospace: 0xFF41,
  9927. ampersand: 0x0026,
  9928. ampersandmonospace: 0xFF06,
  9929. ampersandsmall: 0xF726,
  9930. amsquare: 0x33C2,
  9931. anbopomofo: 0x3122,
  9932. angbopomofo: 0x3124,
  9933. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  9934. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  9935. angkhankhuthai: 0x0E5A,
  9936. angle: 0x2220,
  9937. anglebracketleft: 0x3008,
  9938. anglebracketleftvertical: 0xFE3F,
  9939. anglebracketright: 0x3009,
  9940. anglebracketrightvertical: 0xFE40,
  9941. angleleft: 0x2329,
  9942. angleright: 0x232A,
  9943. angstrom: 0x212B,
  9944. anoteleia: 0x0387,
  9945. anudattadeva: 0x0952,
  9946. anusvarabengali: 0x0982,
  9947. anusvaradeva: 0x0902,
  9948. anusvaragujarati: 0x0A82,
  9949. aogonek: 0x0105,
  9950. apaatosquare: 0x3300,
  9951. aparen: 0x249C,
  9952. apostrophearmenian: 0x055A,
  9953. apostrophemod: 0x02BC,
  9954. apple: 0xF8FF,
  9955. approaches: 0x2250,
  9956. approxequal: 0x2248,
  9957. approxequalorimage: 0x2252,
  9958. approximatelyequal: 0x2245,
  9959. araeaekorean: 0x318E,
  9960. araeakorean: 0x318D,
  9961. arc: 0x2312,
  9962. arighthalfring: 0x1E9A,
  9963. aring: 0x00E5,
  9964. aringacute: 0x01FB,
  9965. aringbelow: 0x1E01,
  9966. arrowboth: 0x2194,
  9967. arrowdashdown: 0x21E3,
  9968. arrowdashleft: 0x21E0,
  9969. arrowdashright: 0x21E2,
  9970. arrowdashup: 0x21E1,
  9971. arrowdblboth: 0x21D4,
  9972. arrowdbldown: 0x21D3,
  9973. arrowdblleft: 0x21D0,
  9974. arrowdblright: 0x21D2,
  9975. arrowdblup: 0x21D1,
  9976. arrowdown: 0x2193,
  9977. arrowdownleft: 0x2199,
  9978. arrowdownright: 0x2198,
  9979. arrowdownwhite: 0x21E9,
  9980. arrowheaddownmod: 0x02C5,
  9981. arrowheadleftmod: 0x02C2,
  9982. arrowheadrightmod: 0x02C3,
  9983. arrowheadupmod: 0x02C4,
  9984. arrowhorizex: 0xF8E7,
  9985. arrowleft: 0x2190,
  9986. arrowleftdbl: 0x21D0,
  9987. arrowleftdblstroke: 0x21CD,
  9988. arrowleftoverright: 0x21C6,
  9989. arrowleftwhite: 0x21E6,
  9990. arrowright: 0x2192,
  9991. arrowrightdblstroke: 0x21CF,
  9992. arrowrightheavy: 0x279E,
  9993. arrowrightoverleft: 0x21C4,
  9994. arrowrightwhite: 0x21E8,
  9995. arrowtableft: 0x21E4,
  9996. arrowtabright: 0x21E5,
  9997. arrowup: 0x2191,
  9998. arrowupdn: 0x2195,
  9999. arrowupdnbse: 0x21A8,
  10000. arrowupdownbase: 0x21A8,
  10001. arrowupleft: 0x2196,
  10002. arrowupleftofdown: 0x21C5,
  10003. arrowupright: 0x2197,
  10004. arrowupwhite: 0x21E7,
  10005. arrowvertex: 0xF8E6,
  10006. asciicircum: 0x005E,
  10007. asciicircummonospace: 0xFF3E,
  10008. asciitilde: 0x007E,
  10009. asciitildemonospace: 0xFF5E,
  10010. ascript: 0x0251,
  10011. ascriptturned: 0x0252,
  10012. asmallhiragana: 0x3041,
  10013. asmallkatakana: 0x30A1,
  10014. asmallkatakanahalfwidth: 0xFF67,
  10015. asterisk: 0x002A,
  10016. asteriskaltonearabic: 0x066D,
  10017. asteriskarabic: 0x066D,
  10018. asteriskmath: 0x2217,
  10019. asteriskmonospace: 0xFF0A,
  10020. asterisksmall: 0xFE61,
  10021. asterism: 0x2042,
  10022. asuperior: 0xF6E9,
  10023. asymptoticallyequal: 0x2243,
  10024. at: 0x0040,
  10025. atilde: 0x00E3,
  10026. atmonospace: 0xFF20,
  10027. atsmall: 0xFE6B,
  10028. aturned: 0x0250,
  10029. aubengali: 0x0994,
  10030. aubopomofo: 0x3120,
  10031. audeva: 0x0914,
  10032. augujarati: 0x0A94,
  10033. augurmukhi: 0x0A14,
  10034. aulengthmarkbengali: 0x09D7,
  10035. aumatragurmukhi: 0x0A4C,
  10036. auvowelsignbengali: 0x09CC,
  10037. auvowelsigndeva: 0x094C,
  10038. auvowelsigngujarati: 0x0ACC,
  10039. avagrahadeva: 0x093D,
  10040. aybarmenian: 0x0561,
  10041. ayin: 0x05E2,
  10042. ayinaltonehebrew: 0xFB20,
  10043. ayinhebrew: 0x05E2,
  10044. b: 0x0062,
  10045. babengali: 0x09AC,
  10046. backslash: 0x005C,
  10047. backslashmonospace: 0xFF3C,
  10048. badeva: 0x092C,
  10049. bagujarati: 0x0AAC,
  10050. bagurmukhi: 0x0A2C,
  10051. bahiragana: 0x3070,
  10052. bahtthai: 0x0E3F,
  10053. bakatakana: 0x30D0,
  10054. bar: 0x007C,
  10055. barmonospace: 0xFF5C,
  10056. bbopomofo: 0x3105,
  10057. bcircle: 0x24D1,
  10058. bdotaccent: 0x1E03,
  10059. bdotbelow: 0x1E05,
  10060. beamedsixteenthnotes: 0x266C,
  10061. because: 0x2235,
  10062. becyrillic: 0x0431,
  10063. beharabic: 0x0628,
  10064. behfinalarabic: 0xFE90,
  10065. behinitialarabic: 0xFE91,
  10066. behiragana: 0x3079,
  10067. behmedialarabic: 0xFE92,
  10068. behmeeminitialarabic: 0xFC9F,
  10069. behmeemisolatedarabic: 0xFC08,
  10070. behnoonfinalarabic: 0xFC6D,
  10071. bekatakana: 0x30D9,
  10072. benarmenian: 0x0562,
  10073. bet: 0x05D1,
  10074. beta: 0x03B2,
  10075. betasymbolgreek: 0x03D0,
  10076. betdagesh: 0xFB31,
  10077. betdageshhebrew: 0xFB31,
  10078. bethebrew: 0x05D1,
  10079. betrafehebrew: 0xFB4C,
  10080. bhabengali: 0x09AD,
  10081. bhadeva: 0x092D,
  10082. bhagujarati: 0x0AAD,
  10083. bhagurmukhi: 0x0A2D,
  10084. bhook: 0x0253,
  10085. bihiragana: 0x3073,
  10086. bikatakana: 0x30D3,
  10087. bilabialclick: 0x0298,
  10088. bindigurmukhi: 0x0A02,
  10089. birusquare: 0x3331,
  10090. blackcircle: 0x25CF,
  10091. blackdiamond: 0x25C6,
  10092. blackdownpointingtriangle: 0x25BC,
  10093. blackleftpointingpointer: 0x25C4,
  10094. blackleftpointingtriangle: 0x25C0,
  10095. blacklenticularbracketleft: 0x3010,
  10096. blacklenticularbracketleftvertical: 0xFE3B,
  10097. blacklenticularbracketright: 0x3011,
  10098. blacklenticularbracketrightvertical: 0xFE3C,
  10099. blacklowerlefttriangle: 0x25E3,
  10100. blacklowerrighttriangle: 0x25E2,
  10101. blackrectangle: 0x25AC,
  10102. blackrightpointingpointer: 0x25BA,
  10103. blackrightpointingtriangle: 0x25B6,
  10104. blacksmallsquare: 0x25AA,
  10105. blacksmilingface: 0x263B,
  10106. blacksquare: 0x25A0,
  10107. blackstar: 0x2605,
  10108. blackupperlefttriangle: 0x25E4,
  10109. blackupperrighttriangle: 0x25E5,
  10110. blackuppointingsmalltriangle: 0x25B4,
  10111. blackuppointingtriangle: 0x25B2,
  10112. blank: 0x2423,
  10113. blinebelow: 0x1E07,
  10114. block: 0x2588,
  10115. bmonospace: 0xFF42,
  10116. bobaimaithai: 0x0E1A,
  10117. bohiragana: 0x307C,
  10118. bokatakana: 0x30DC,
  10119. bparen: 0x249D,
  10120. bqsquare: 0x33C3,
  10121. braceex: 0xF8F4,
  10122. braceleft: 0x007B,
  10123. braceleftbt: 0xF8F3,
  10124. braceleftmid: 0xF8F2,
  10125. braceleftmonospace: 0xFF5B,
  10126. braceleftsmall: 0xFE5B,
  10127. bracelefttp: 0xF8F1,
  10128. braceleftvertical: 0xFE37,
  10129. braceright: 0x007D,
  10130. bracerightbt: 0xF8FE,
  10131. bracerightmid: 0xF8FD,
  10132. bracerightmonospace: 0xFF5D,
  10133. bracerightsmall: 0xFE5C,
  10134. bracerighttp: 0xF8FC,
  10135. bracerightvertical: 0xFE38,
  10136. bracketleft: 0x005B,
  10137. bracketleftbt: 0xF8F0,
  10138. bracketleftex: 0xF8EF,
  10139. bracketleftmonospace: 0xFF3B,
  10140. bracketlefttp: 0xF8EE,
  10141. bracketright: 0x005D,
  10142. bracketrightbt: 0xF8FB,
  10143. bracketrightex: 0xF8FA,
  10144. bracketrightmonospace: 0xFF3D,
  10145. bracketrighttp: 0xF8F9,
  10146. breve: 0x02D8,
  10147. brevebelowcmb: 0x032E,
  10148. brevecmb: 0x0306,
  10149. breveinvertedbelowcmb: 0x032F,
  10150. breveinvertedcmb: 0x0311,
  10151. breveinverteddoublecmb: 0x0361,
  10152. bridgebelowcmb: 0x032A,
  10153. bridgeinvertedbelowcmb: 0x033A,
  10154. brokenbar: 0x00A6,
  10155. bstroke: 0x0180,
  10156. bsuperior: 0xF6EA,
  10157. btopbar: 0x0183,
  10158. buhiragana: 0x3076,
  10159. bukatakana: 0x30D6,
  10160. bullet: 0x2022,
  10161. bulletinverse: 0x25D8,
  10162. bulletoperator: 0x2219,
  10163. bullseye: 0x25CE,
  10164. c: 0x0063,
  10165. caarmenian: 0x056E,
  10166. cabengali: 0x099A,
  10167. cacute: 0x0107,
  10168. cadeva: 0x091A,
  10169. cagujarati: 0x0A9A,
  10170. cagurmukhi: 0x0A1A,
  10171. calsquare: 0x3388,
  10172. candrabindubengali: 0x0981,
  10173. candrabinducmb: 0x0310,
  10174. candrabindudeva: 0x0901,
  10175. candrabindugujarati: 0x0A81,
  10176. capslock: 0x21EA,
  10177. careof: 0x2105,
  10178. caron: 0x02C7,
  10179. caronbelowcmb: 0x032C,
  10180. caroncmb: 0x030C,
  10181. carriagereturn: 0x21B5,
  10182. cbopomofo: 0x3118,
  10183. ccaron: 0x010D,
  10184. ccedilla: 0x00E7,
  10185. ccedillaacute: 0x1E09,
  10186. ccircle: 0x24D2,
  10187. ccircumflex: 0x0109,
  10188. ccurl: 0x0255,
  10189. cdot: 0x010B,
  10190. cdotaccent: 0x010B,
  10191. cdsquare: 0x33C5,
  10192. cedilla: 0x00B8,
  10193. cedillacmb: 0x0327,
  10194. cent: 0x00A2,
  10195. centigrade: 0x2103,
  10196. centinferior: 0xF6DF,
  10197. centmonospace: 0xFFE0,
  10198. centoldstyle: 0xF7A2,
  10199. centsuperior: 0xF6E0,
  10200. chaarmenian: 0x0579,
  10201. chabengali: 0x099B,
  10202. chadeva: 0x091B,
  10203. chagujarati: 0x0A9B,
  10204. chagurmukhi: 0x0A1B,
  10205. chbopomofo: 0x3114,
  10206. cheabkhasiancyrillic: 0x04BD,
  10207. checkmark: 0x2713,
  10208. checyrillic: 0x0447,
  10209. chedescenderabkhasiancyrillic: 0x04BF,
  10210. chedescendercyrillic: 0x04B7,
  10211. chedieresiscyrillic: 0x04F5,
  10212. cheharmenian: 0x0573,
  10213. chekhakassiancyrillic: 0x04CC,
  10214. cheverticalstrokecyrillic: 0x04B9,
  10215. chi: 0x03C7,
  10216. chieuchacirclekorean: 0x3277,
  10217. chieuchaparenkorean: 0x3217,
  10218. chieuchcirclekorean: 0x3269,
  10219. chieuchkorean: 0x314A,
  10220. chieuchparenkorean: 0x3209,
  10221. chochangthai: 0x0E0A,
  10222. chochanthai: 0x0E08,
  10223. chochingthai: 0x0E09,
  10224. chochoethai: 0x0E0C,
  10225. chook: 0x0188,
  10226. cieucacirclekorean: 0x3276,
  10227. cieucaparenkorean: 0x3216,
  10228. cieuccirclekorean: 0x3268,
  10229. cieuckorean: 0x3148,
  10230. cieucparenkorean: 0x3208,
  10231. cieucuparenkorean: 0x321C,
  10232. circle: 0x25CB,
  10233. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  10234. circlemultiply: 0x2297,
  10235. circleot: 0x2299,
  10236. circleplus: 0x2295,
  10237. circlepostalmark: 0x3036,
  10238. circlewithlefthalfblack: 0x25D0,
  10239. circlewithrighthalfblack: 0x25D1,
  10240. circumflex: 0x02C6,
  10241. circumflexbelowcmb: 0x032D,
  10242. circumflexcmb: 0x0302,
  10243. clear: 0x2327,
  10244. clickalveolar: 0x01C2,
  10245. clickdental: 0x01C0,
  10246. clicklateral: 0x01C1,
  10247. clickretroflex: 0x01C3,
  10248. club: 0x2663,
  10249. clubsuitblack: 0x2663,
  10250. clubsuitwhite: 0x2667,
  10251. cmcubedsquare: 0x33A4,
  10252. cmonospace: 0xFF43,
  10253. cmsquaredsquare: 0x33A0,
  10254. coarmenian: 0x0581,
  10255. colon: 0x003A,
  10256. colonmonetary: 0x20A1,
  10257. colonmonospace: 0xFF1A,
  10258. colonsign: 0x20A1,
  10259. colonsmall: 0xFE55,
  10260. colontriangularhalfmod: 0x02D1,
  10261. colontriangularmod: 0x02D0,
  10262. comma: 0x002C,
  10263. commaabovecmb: 0x0313,
  10264. commaaboverightcmb: 0x0315,
  10265. commaaccent: 0xF6C3,
  10266. commaarabic: 0x060C,
  10267. commaarmenian: 0x055D,
  10268. commainferior: 0xF6E1,
  10269. commamonospace: 0xFF0C,
  10270. commareversedabovecmb: 0x0314,
  10271. commareversedmod: 0x02BD,
  10272. commasmall: 0xFE50,
  10273. commasuperior: 0xF6E2,
  10274. commaturnedabovecmb: 0x0312,
  10275. commaturnedmod: 0x02BB,
  10276. compass: 0x263C,
  10277. congruent: 0x2245,
  10278. contourintegral: 0x222E,
  10279. control: 0x2303,
  10280. controlACK: 0x0006,
  10281. controlBEL: 0x0007,
  10282. controlBS: 0x0008,
  10283. controlCAN: 0x0018,
  10284. controlCR: 0x000D,
  10285. controlDC1: 0x0011,
  10286. controlDC2: 0x0012,
  10287. controlDC3: 0x0013,
  10288. controlDC4: 0x0014,
  10289. controlDEL: 0x007F,
  10290. controlDLE: 0x0010,
  10291. controlEM: 0x0019,
  10292. controlENQ: 0x0005,
  10293. controlEOT: 0x0004,
  10294. controlESC: 0x001B,
  10295. controlETB: 0x0017,
  10296. controlETX: 0x0003,
  10297. controlFF: 0x000C,
  10298. controlFS: 0x001C,
  10299. controlGS: 0x001D,
  10300. controlHT: 0x0009,
  10301. controlLF: 0x000A,
  10302. controlNAK: 0x0015,
  10303. controlRS: 0x001E,
  10304. controlSI: 0x000F,
  10305. controlSO: 0x000E,
  10306. controlSOT: 0x0002,
  10307. controlSTX: 0x0001,
  10308. controlSUB: 0x001A,
  10309. controlSYN: 0x0016,
  10310. controlUS: 0x001F,
  10311. controlVT: 0x000B,
  10312. copyright: 0x00A9,
  10313. copyrightsans: 0xF8E9,
  10314. copyrightserif: 0xF6D9,
  10315. cornerbracketleft: 0x300C,
  10316. cornerbracketlefthalfwidth: 0xFF62,
  10317. cornerbracketleftvertical: 0xFE41,
  10318. cornerbracketright: 0x300D,
  10319. cornerbracketrighthalfwidth: 0xFF63,
  10320. cornerbracketrightvertical: 0xFE42,
  10321. corporationsquare: 0x337F,
  10322. cosquare: 0x33C7,
  10323. coverkgsquare: 0x33C6,
  10324. cparen: 0x249E,
  10325. cruzeiro: 0x20A2,
  10326. cstretched: 0x0297,
  10327. curlyand: 0x22CF,
  10328. curlyor: 0x22CE,
  10329. currency: 0x00A4,
  10330. cyrBreve: 0xF6D1,
  10331. cyrFlex: 0xF6D2,
  10332. cyrbreve: 0xF6D4,
  10333. cyrflex: 0xF6D5,
  10334. d: 0x0064,
  10335. daarmenian: 0x0564,
  10336. dabengali: 0x09A6,
  10337. dadarabic: 0x0636,
  10338. dadeva: 0x0926,
  10339. dadfinalarabic: 0xFEBE,
  10340. dadinitialarabic: 0xFEBF,
  10341. dadmedialarabic: 0xFEC0,
  10342. dagesh: 0x05BC,
  10343. dageshhebrew: 0x05BC,
  10344. dagger: 0x2020,
  10345. daggerdbl: 0x2021,
  10346. dagujarati: 0x0AA6,
  10347. dagurmukhi: 0x0A26,
  10348. dahiragana: 0x3060,
  10349. dakatakana: 0x30C0,
  10350. dalarabic: 0x062F,
  10351. dalet: 0x05D3,
  10352. daletdagesh: 0xFB33,
  10353. daletdageshhebrew: 0xFB33,
  10354. dalethebrew: 0x05D3,
  10355. dalfinalarabic: 0xFEAA,
  10356. dammaarabic: 0x064F,
  10357. dammalowarabic: 0x064F,
  10358. dammatanaltonearabic: 0x064C,
  10359. dammatanarabic: 0x064C,
  10360. danda: 0x0964,
  10361. dargahebrew: 0x05A7,
  10362. dargalefthebrew: 0x05A7,
  10363. dasiapneumatacyrilliccmb: 0x0485,
  10364. dblGrave: 0xF6D3,
  10365. dblanglebracketleft: 0x300A,
  10366. dblanglebracketleftvertical: 0xFE3D,
  10367. dblanglebracketright: 0x300B,
  10368. dblanglebracketrightvertical: 0xFE3E,
  10369. dblarchinvertedbelowcmb: 0x032B,
  10370. dblarrowleft: 0x21D4,
  10371. dblarrowright: 0x21D2,
  10372. dbldanda: 0x0965,
  10373. dblgrave: 0xF6D6,
  10374. dblgravecmb: 0x030F,
  10375. dblintegral: 0x222C,
  10376. dbllowline: 0x2017,
  10377. dbllowlinecmb: 0x0333,
  10378. dbloverlinecmb: 0x033F,
  10379. dblprimemod: 0x02BA,
  10380. dblverticalbar: 0x2016,
  10381. dblverticallineabovecmb: 0x030E,
  10382. dbopomofo: 0x3109,
  10383. dbsquare: 0x33C8,
  10384. dcaron: 0x010F,
  10385. dcedilla: 0x1E11,
  10386. dcircle: 0x24D3,
  10387. dcircumflexbelow: 0x1E13,
  10388. dcroat: 0x0111,
  10389. ddabengali: 0x09A1,
  10390. ddadeva: 0x0921,
  10391. ddagujarati: 0x0AA1,
  10392. ddagurmukhi: 0x0A21,
  10393. ddalarabic: 0x0688,
  10394. ddalfinalarabic: 0xFB89,
  10395. dddhadeva: 0x095C,
  10396. ddhabengali: 0x09A2,
  10397. ddhadeva: 0x0922,
  10398. ddhagujarati: 0x0AA2,
  10399. ddhagurmukhi: 0x0A22,
  10400. ddotaccent: 0x1E0B,
  10401. ddotbelow: 0x1E0D,
  10402. decimalseparatorarabic: 0x066B,
  10403. decimalseparatorpersian: 0x066B,
  10404. decyrillic: 0x0434,
  10405. degree: 0x00B0,
  10406. dehihebrew: 0x05AD,
  10407. dehiragana: 0x3067,
  10408. deicoptic: 0x03EF,
  10409. dekatakana: 0x30C7,
  10410. deleteleft: 0x232B,
  10411. deleteright: 0x2326,
  10412. delta: 0x03B4,
  10413. deltaturned: 0x018D,
  10414. denominatorminusonenumeratorbengali: 0x09F8,
  10415. dezh: 0x02A4,
  10416. dhabengali: 0x09A7,
  10417. dhadeva: 0x0927,
  10418. dhagujarati: 0x0AA7,
  10419. dhagurmukhi: 0x0A27,
  10420. dhook: 0x0257,
  10421. dialytikatonos: 0x0385,
  10422. dialytikatonoscmb: 0x0344,
  10423. diamond: 0x2666,
  10424. diamondsuitwhite: 0x2662,
  10425. dieresis: 0x00A8,
  10426. dieresisacute: 0xF6D7,
  10427. dieresisbelowcmb: 0x0324,
  10428. dieresiscmb: 0x0308,
  10429. dieresisgrave: 0xF6D8,
  10430. dieresistonos: 0x0385,
  10431. dihiragana: 0x3062,
  10432. dikatakana: 0x30C2,
  10433. dittomark: 0x3003,
  10434. divide: 0x00F7,
  10435. divides: 0x2223,
  10436. divisionslash: 0x2215,
  10437. djecyrillic: 0x0452,
  10438. dkshade: 0x2593,
  10439. dlinebelow: 0x1E0F,
  10440. dlsquare: 0x3397,
  10441. dmacron: 0x0111,
  10442. dmonospace: 0xFF44,
  10443. dnblock: 0x2584,
  10444. dochadathai: 0x0E0E,
  10445. dodekthai: 0x0E14,
  10446. dohiragana: 0x3069,
  10447. dokatakana: 0x30C9,
  10448. dollar: 0x0024,
  10449. dollarinferior: 0xF6E3,
  10450. dollarmonospace: 0xFF04,
  10451. dollaroldstyle: 0xF724,
  10452. dollarsmall: 0xFE69,
  10453. dollarsuperior: 0xF6E4,
  10454. dong: 0x20AB,
  10455. dorusquare: 0x3326,
  10456. dotaccent: 0x02D9,
  10457. dotaccentcmb: 0x0307,
  10458. dotbelowcmb: 0x0323,
  10459. dotbelowcomb: 0x0323,
  10460. dotkatakana: 0x30FB,
  10461. dotlessi: 0x0131,
  10462. dotlessj: 0xF6BE,
  10463. dotlessjstrokehook: 0x0284,
  10464. dotmath: 0x22C5,
  10465. dottedcircle: 0x25CC,
  10466. doubleyodpatah: 0xFB1F,
  10467. doubleyodpatahhebrew: 0xFB1F,
  10468. downtackbelowcmb: 0x031E,
  10469. downtackmod: 0x02D5,
  10470. dparen: 0x249F,
  10471. dsuperior: 0xF6EB,
  10472. dtail: 0x0256,
  10473. dtopbar: 0x018C,
  10474. duhiragana: 0x3065,
  10475. dukatakana: 0x30C5,
  10476. dz: 0x01F3,
  10477. dzaltone: 0x02A3,
  10478. dzcaron: 0x01C6,
  10479. dzcurl: 0x02A5,
  10480. dzeabkhasiancyrillic: 0x04E1,
  10481. dzecyrillic: 0x0455,
  10482. dzhecyrillic: 0x045F,
  10483. e: 0x0065,
  10484. eacute: 0x00E9,
  10485. earth: 0x2641,
  10486. ebengali: 0x098F,
  10487. ebopomofo: 0x311C,
  10488. ebreve: 0x0115,
  10489. ecandradeva: 0x090D,
  10490. ecandragujarati: 0x0A8D,
  10491. ecandravowelsigndeva: 0x0945,
  10492. ecandravowelsigngujarati: 0x0AC5,
  10493. ecaron: 0x011B,
  10494. ecedillabreve: 0x1E1D,
  10495. echarmenian: 0x0565,
  10496. echyiwnarmenian: 0x0587,
  10497. ecircle: 0x24D4,
  10498. ecircumflex: 0x00EA,
  10499. ecircumflexacute: 0x1EBF,
  10500. ecircumflexbelow: 0x1E19,
  10501. ecircumflexdotbelow: 0x1EC7,
  10502. ecircumflexgrave: 0x1EC1,
  10503. ecircumflexhookabove: 0x1EC3,
  10504. ecircumflextilde: 0x1EC5,
  10505. ecyrillic: 0x0454,
  10506. edblgrave: 0x0205,
  10507. edeva: 0x090F,
  10508. edieresis: 0x00EB,
  10509. edot: 0x0117,
  10510. edotaccent: 0x0117,
  10511. edotbelow: 0x1EB9,
  10512. eegurmukhi: 0x0A0F,
  10513. eematragurmukhi: 0x0A47,
  10514. efcyrillic: 0x0444,
  10515. egrave: 0x00E8,
  10516. egujarati: 0x0A8F,
  10517. eharmenian: 0x0567,
  10518. ehbopomofo: 0x311D,
  10519. ehiragana: 0x3048,
  10520. ehookabove: 0x1EBB,
  10521. eibopomofo: 0x311F,
  10522. eight: 0x0038,
  10523. eightarabic: 0x0668,
  10524. eightbengali: 0x09EE,
  10525. eightcircle: 0x2467,
  10526. eightcircleinversesansserif: 0x2791,
  10527. eightdeva: 0x096E,
  10528. eighteencircle: 0x2471,
  10529. eighteenparen: 0x2485,
  10530. eighteenperiod: 0x2499,
  10531. eightgujarati: 0x0AEE,
  10532. eightgurmukhi: 0x0A6E,
  10533. eighthackarabic: 0x0668,
  10534. eighthangzhou: 0x3028,
  10535. eighthnotebeamed: 0x266B,
  10536. eightideographicparen: 0x3227,
  10537. eightinferior: 0x2088,
  10538. eightmonospace: 0xFF18,
  10539. eightoldstyle: 0xF738,
  10540. eightparen: 0x247B,
  10541. eightperiod: 0x248F,
  10542. eightpersian: 0x06F8,
  10543. eightroman: 0x2177,
  10544. eightsuperior: 0x2078,
  10545. eightthai: 0x0E58,
  10546. einvertedbreve: 0x0207,
  10547. eiotifiedcyrillic: 0x0465,
  10548. ekatakana: 0x30A8,
  10549. ekatakanahalfwidth: 0xFF74,
  10550. ekonkargurmukhi: 0x0A74,
  10551. ekorean: 0x3154,
  10552. elcyrillic: 0x043B,
  10553. element: 0x2208,
  10554. elevencircle: 0x246A,
  10555. elevenparen: 0x247E,
  10556. elevenperiod: 0x2492,
  10557. elevenroman: 0x217A,
  10558. ellipsis: 0x2026,
  10559. ellipsisvertical: 0x22EE,
  10560. emacron: 0x0113,
  10561. emacronacute: 0x1E17,
  10562. emacrongrave: 0x1E15,
  10563. emcyrillic: 0x043C,
  10564. emdash: 0x2014,
  10565. emdashvertical: 0xFE31,
  10566. emonospace: 0xFF45,
  10567. emphasismarkarmenian: 0x055B,
  10568. emptyset: 0x2205,
  10569. enbopomofo: 0x3123,
  10570. encyrillic: 0x043D,
  10571. endash: 0x2013,
  10572. endashvertical: 0xFE32,
  10573. endescendercyrillic: 0x04A3,
  10574. eng: 0x014B,
  10575. engbopomofo: 0x3125,
  10576. enghecyrillic: 0x04A5,
  10577. enhookcyrillic: 0x04C8,
  10578. enspace: 0x2002,
  10579. eogonek: 0x0119,
  10580. eokorean: 0x3153,
  10581. eopen: 0x025B,
  10582. eopenclosed: 0x029A,
  10583. eopenreversed: 0x025C,
  10584. eopenreversedclosed: 0x025E,
  10585. eopenreversedhook: 0x025D,
  10586. eparen: 0x24A0,
  10587. epsilon: 0x03B5,
  10588. epsilontonos: 0x03AD,
  10589. equal: 0x003D,
  10590. equalmonospace: 0xFF1D,
  10591. equalsmall: 0xFE66,
  10592. equalsuperior: 0x207C,
  10593. equivalence: 0x2261,
  10594. erbopomofo: 0x3126,
  10595. ercyrillic: 0x0440,
  10596. ereversed: 0x0258,
  10597. ereversedcyrillic: 0x044D,
  10598. escyrillic: 0x0441,
  10599. esdescendercyrillic: 0x04AB,
  10600. esh: 0x0283,
  10601. eshcurl: 0x0286,
  10602. eshortdeva: 0x090E,
  10603. eshortvowelsigndeva: 0x0946,
  10604. eshreversedloop: 0x01AA,
  10605. eshsquatreversed: 0x0285,
  10606. esmallhiragana: 0x3047,
  10607. esmallkatakana: 0x30A7,
  10608. esmallkatakanahalfwidth: 0xFF6A,
  10609. estimated: 0x212E,
  10610. esuperior: 0xF6EC,
  10611. eta: 0x03B7,
  10612. etarmenian: 0x0568,
  10613. etatonos: 0x03AE,
  10614. eth: 0x00F0,
  10615. etilde: 0x1EBD,
  10616. etildebelow: 0x1E1B,
  10617. etnahtafoukhhebrew: 0x0591,
  10618. etnahtafoukhlefthebrew: 0x0591,
  10619. etnahtahebrew: 0x0591,
  10620. etnahtalefthebrew: 0x0591,
  10621. eturned: 0x01DD,
  10622. eukorean: 0x3161,
  10623. euro: 0x20AC,
  10624. evowelsignbengali: 0x09C7,
  10625. evowelsigndeva: 0x0947,
  10626. evowelsigngujarati: 0x0AC7,
  10627. exclam: 0x0021,
  10628. exclamarmenian: 0x055C,
  10629. exclamdbl: 0x203C,
  10630. exclamdown: 0x00A1,
  10631. exclamdownsmall: 0xF7A1,
  10632. exclammonospace: 0xFF01,
  10633. exclamsmall: 0xF721,
  10634. existential: 0x2203,
  10635. ezh: 0x0292,
  10636. ezhcaron: 0x01EF,
  10637. ezhcurl: 0x0293,
  10638. ezhreversed: 0x01B9,
  10639. ezhtail: 0x01BA,
  10640. f: 0x0066,
  10641. fadeva: 0x095E,
  10642. fagurmukhi: 0x0A5E,
  10643. fahrenheit: 0x2109,
  10644. fathaarabic: 0x064E,
  10645. fathalowarabic: 0x064E,
  10646. fathatanarabic: 0x064B,
  10647. fbopomofo: 0x3108,
  10648. fcircle: 0x24D5,
  10649. fdotaccent: 0x1E1F,
  10650. feharabic: 0x0641,
  10651. feharmenian: 0x0586,
  10652. fehfinalarabic: 0xFED2,
  10653. fehinitialarabic: 0xFED3,
  10654. fehmedialarabic: 0xFED4,
  10655. feicoptic: 0x03E5,
  10656. female: 0x2640,
  10657. ff: 0xFB00,
  10658. ffi: 0xFB03,
  10659. ffl: 0xFB04,
  10660. fi: 0xFB01,
  10661. fifteencircle: 0x246E,
  10662. fifteenparen: 0x2482,
  10663. fifteenperiod: 0x2496,
  10664. figuredash: 0x2012,
  10665. filledbox: 0x25A0,
  10666. filledrect: 0x25AC,
  10667. finalkaf: 0x05DA,
  10668. finalkafdagesh: 0xFB3A,
  10669. finalkafdageshhebrew: 0xFB3A,
  10670. finalkafhebrew: 0x05DA,
  10671. finalmem: 0x05DD,
  10672. finalmemhebrew: 0x05DD,
  10673. finalnun: 0x05DF,
  10674. finalnunhebrew: 0x05DF,
  10675. finalpe: 0x05E3,
  10676. finalpehebrew: 0x05E3,
  10677. finaltsadi: 0x05E5,
  10678. finaltsadihebrew: 0x05E5,
  10679. firsttonechinese: 0x02C9,
  10680. fisheye: 0x25C9,
  10681. fitacyrillic: 0x0473,
  10682. five: 0x0035,
  10683. fivearabic: 0x0665,
  10684. fivebengali: 0x09EB,
  10685. fivecircle: 0x2464,
  10686. fivecircleinversesansserif: 0x278E,
  10687. fivedeva: 0x096B,
  10688. fiveeighths: 0x215D,
  10689. fivegujarati: 0x0AEB,
  10690. fivegurmukhi: 0x0A6B,
  10691. fivehackarabic: 0x0665,
  10692. fivehangzhou: 0x3025,
  10693. fiveideographicparen: 0x3224,
  10694. fiveinferior: 0x2085,
  10695. fivemonospace: 0xFF15,
  10696. fiveoldstyle: 0xF735,
  10697. fiveparen: 0x2478,
  10698. fiveperiod: 0x248C,
  10699. fivepersian: 0x06F5,
  10700. fiveroman: 0x2174,
  10701. fivesuperior: 0x2075,
  10702. fivethai: 0x0E55,
  10703. fl: 0xFB02,
  10704. florin: 0x0192,
  10705. fmonospace: 0xFF46,
  10706. fmsquare: 0x3399,
  10707. fofanthai: 0x0E1F,
  10708. fofathai: 0x0E1D,
  10709. fongmanthai: 0x0E4F,
  10710. forall: 0x2200,
  10711. four: 0x0034,
  10712. fourarabic: 0x0664,
  10713. fourbengali: 0x09EA,
  10714. fourcircle: 0x2463,
  10715. fourcircleinversesansserif: 0x278D,
  10716. fourdeva: 0x096A,
  10717. fourgujarati: 0x0AEA,
  10718. fourgurmukhi: 0x0A6A,
  10719. fourhackarabic: 0x0664,
  10720. fourhangzhou: 0x3024,
  10721. fourideographicparen: 0x3223,
  10722. fourinferior: 0x2084,
  10723. fourmonospace: 0xFF14,
  10724. fournumeratorbengali: 0x09F7,
  10725. fouroldstyle: 0xF734,
  10726. fourparen: 0x2477,
  10727. fourperiod: 0x248B,
  10728. fourpersian: 0x06F4,
  10729. fourroman: 0x2173,
  10730. foursuperior: 0x2074,
  10731. fourteencircle: 0x246D,
  10732. fourteenparen: 0x2481,
  10733. fourteenperiod: 0x2495,
  10734. fourthai: 0x0E54,
  10735. fourthtonechinese: 0x02CB,
  10736. fparen: 0x24A1,
  10737. fraction: 0x2044,
  10738. franc: 0x20A3,
  10739. g: 0x0067,
  10740. gabengali: 0x0997,
  10741. gacute: 0x01F5,
  10742. gadeva: 0x0917,
  10743. gafarabic: 0x06AF,
  10744. gaffinalarabic: 0xFB93,
  10745. gafinitialarabic: 0xFB94,
  10746. gafmedialarabic: 0xFB95,
  10747. gagujarati: 0x0A97,
  10748. gagurmukhi: 0x0A17,
  10749. gahiragana: 0x304C,
  10750. gakatakana: 0x30AC,
  10751. gamma: 0x03B3,
  10752. gammalatinsmall: 0x0263,
  10753. gammasuperior: 0x02E0,
  10754. gangiacoptic: 0x03EB,
  10755. gbopomofo: 0x310D,
  10756. gbreve: 0x011F,
  10757. gcaron: 0x01E7,
  10758. gcedilla: 0x0123,
  10759. gcircle: 0x24D6,
  10760. gcircumflex: 0x011D,
  10761. gcommaaccent: 0x0123,
  10762. gdot: 0x0121,
  10763. gdotaccent: 0x0121,
  10764. gecyrillic: 0x0433,
  10765. gehiragana: 0x3052,
  10766. gekatakana: 0x30B2,
  10767. geometricallyequal: 0x2251,
  10768. gereshaccenthebrew: 0x059C,
  10769. gereshhebrew: 0x05F3,
  10770. gereshmuqdamhebrew: 0x059D,
  10771. germandbls: 0x00DF,
  10772. gershayimaccenthebrew: 0x059E,
  10773. gershayimhebrew: 0x05F4,
  10774. getamark: 0x3013,
  10775. ghabengali: 0x0998,
  10776. ghadarmenian: 0x0572,
  10777. ghadeva: 0x0918,
  10778. ghagujarati: 0x0A98,
  10779. ghagurmukhi: 0x0A18,
  10780. ghainarabic: 0x063A,
  10781. ghainfinalarabic: 0xFECE,
  10782. ghaininitialarabic: 0xFECF,
  10783. ghainmedialarabic: 0xFED0,
  10784. ghemiddlehookcyrillic: 0x0495,
  10785. ghestrokecyrillic: 0x0493,
  10786. gheupturncyrillic: 0x0491,
  10787. ghhadeva: 0x095A,
  10788. ghhagurmukhi: 0x0A5A,
  10789. ghook: 0x0260,
  10790. ghzsquare: 0x3393,
  10791. gihiragana: 0x304E,
  10792. gikatakana: 0x30AE,
  10793. gimarmenian: 0x0563,
  10794. gimel: 0x05D2,
  10795. gimeldagesh: 0xFB32,
  10796. gimeldageshhebrew: 0xFB32,
  10797. gimelhebrew: 0x05D2,
  10798. gjecyrillic: 0x0453,
  10799. glottalinvertedstroke: 0x01BE,
  10800. glottalstop: 0x0294,
  10801. glottalstopinverted: 0x0296,
  10802. glottalstopmod: 0x02C0,
  10803. glottalstopreversed: 0x0295,
  10804. glottalstopreversedmod: 0x02C1,
  10805. glottalstopreversedsuperior: 0x02E4,
  10806. glottalstopstroke: 0x02A1,
  10807. glottalstopstrokereversed: 0x02A2,
  10808. gmacron: 0x1E21,
  10809. gmonospace: 0xFF47,
  10810. gohiragana: 0x3054,
  10811. gokatakana: 0x30B4,
  10812. gparen: 0x24A2,
  10813. gpasquare: 0x33AC,
  10814. gradient: 0x2207,
  10815. grave: 0x0060,
  10816. gravebelowcmb: 0x0316,
  10817. gravecmb: 0x0300,
  10818. gravecomb: 0x0300,
  10819. gravedeva: 0x0953,
  10820. gravelowmod: 0x02CE,
  10821. gravemonospace: 0xFF40,
  10822. gravetonecmb: 0x0340,
  10823. greater: 0x003E,
  10824. greaterequal: 0x2265,
  10825. greaterequalorless: 0x22DB,
  10826. greatermonospace: 0xFF1E,
  10827. greaterorequivalent: 0x2273,
  10828. greaterorless: 0x2277,
  10829. greateroverequal: 0x2267,
  10830. greatersmall: 0xFE65,
  10831. gscript: 0x0261,
  10832. gstroke: 0x01E5,
  10833. guhiragana: 0x3050,
  10834. guillemotleft: 0x00AB,
  10835. guillemotright: 0x00BB,
  10836. guilsinglleft: 0x2039,
  10837. guilsinglright: 0x203A,
  10838. gukatakana: 0x30B0,
  10839. guramusquare: 0x3318,
  10840. gysquare: 0x33C9,
  10841. h: 0x0068,
  10842. haabkhasiancyrillic: 0x04A9,
  10843. haaltonearabic: 0x06C1,
  10844. habengali: 0x09B9,
  10845. hadescendercyrillic: 0x04B3,
  10846. hadeva: 0x0939,
  10847. hagujarati: 0x0AB9,
  10848. hagurmukhi: 0x0A39,
  10849. haharabic: 0x062D,
  10850. hahfinalarabic: 0xFEA2,
  10851. hahinitialarabic: 0xFEA3,
  10852. hahiragana: 0x306F,
  10853. hahmedialarabic: 0xFEA4,
  10854. haitusquare: 0x332A,
  10855. hakatakana: 0x30CF,
  10856. hakatakanahalfwidth: 0xFF8A,
  10857. halantgurmukhi: 0x0A4D,
  10858. hamzaarabic: 0x0621,
  10859. hamzalowarabic: 0x0621,
  10860. hangulfiller: 0x3164,
  10861. hardsigncyrillic: 0x044A,
  10862. harpoonleftbarbup: 0x21BC,
  10863. harpoonrightbarbup: 0x21C0,
  10864. hasquare: 0x33CA,
  10865. hatafpatah: 0x05B2,
  10866. hatafpatah16: 0x05B2,
  10867. hatafpatah23: 0x05B2,
  10868. hatafpatah2f: 0x05B2,
  10869. hatafpatahhebrew: 0x05B2,
  10870. hatafpatahnarrowhebrew: 0x05B2,
  10871. hatafpatahquarterhebrew: 0x05B2,
  10872. hatafpatahwidehebrew: 0x05B2,
  10873. hatafqamats: 0x05B3,
  10874. hatafqamats1b: 0x05B3,
  10875. hatafqamats28: 0x05B3,
  10876. hatafqamats34: 0x05B3,
  10877. hatafqamatshebrew: 0x05B3,
  10878. hatafqamatsnarrowhebrew: 0x05B3,
  10879. hatafqamatsquarterhebrew: 0x05B3,
  10880. hatafqamatswidehebrew: 0x05B3,
  10881. hatafsegol: 0x05B1,
  10882. hatafsegol17: 0x05B1,
  10883. hatafsegol24: 0x05B1,
  10884. hatafsegol30: 0x05B1,
  10885. hatafsegolhebrew: 0x05B1,
  10886. hatafsegolnarrowhebrew: 0x05B1,
  10887. hatafsegolquarterhebrew: 0x05B1,
  10888. hatafsegolwidehebrew: 0x05B1,
  10889. hbar: 0x0127,
  10890. hbopomofo: 0x310F,
  10891. hbrevebelow: 0x1E2B,
  10892. hcedilla: 0x1E29,
  10893. hcircle: 0x24D7,
  10894. hcircumflex: 0x0125,
  10895. hdieresis: 0x1E27,
  10896. hdotaccent: 0x1E23,
  10897. hdotbelow: 0x1E25,
  10898. he: 0x05D4,
  10899. heart: 0x2665,
  10900. heartsuitblack: 0x2665,
  10901. heartsuitwhite: 0x2661,
  10902. hedagesh: 0xFB34,
  10903. hedageshhebrew: 0xFB34,
  10904. hehaltonearabic: 0x06C1,
  10905. heharabic: 0x0647,
  10906. hehebrew: 0x05D4,
  10907. hehfinalaltonearabic: 0xFBA7,
  10908. hehfinalalttwoarabic: 0xFEEA,
  10909. hehfinalarabic: 0xFEEA,
  10910. hehhamzaabovefinalarabic: 0xFBA5,
  10911. hehhamzaaboveisolatedarabic: 0xFBA4,
  10912. hehinitialaltonearabic: 0xFBA8,
  10913. hehinitialarabic: 0xFEEB,
  10914. hehiragana: 0x3078,
  10915. hehmedialaltonearabic: 0xFBA9,
  10916. hehmedialarabic: 0xFEEC,
  10917. heiseierasquare: 0x337B,
  10918. hekatakana: 0x30D8,
  10919. hekatakanahalfwidth: 0xFF8D,
  10920. hekutaarusquare: 0x3336,
  10921. henghook: 0x0267,
  10922. herutusquare: 0x3339,
  10923. het: 0x05D7,
  10924. hethebrew: 0x05D7,
  10925. hhook: 0x0266,
  10926. hhooksuperior: 0x02B1,
  10927. hieuhacirclekorean: 0x327B,
  10928. hieuhaparenkorean: 0x321B,
  10929. hieuhcirclekorean: 0x326D,
  10930. hieuhkorean: 0x314E,
  10931. hieuhparenkorean: 0x320D,
  10932. hihiragana: 0x3072,
  10933. hikatakana: 0x30D2,
  10934. hikatakanahalfwidth: 0xFF8B,
  10935. hiriq: 0x05B4,
  10936. hiriq14: 0x05B4,
  10937. hiriq21: 0x05B4,
  10938. hiriq2d: 0x05B4,
  10939. hiriqhebrew: 0x05B4,
  10940. hiriqnarrowhebrew: 0x05B4,
  10941. hiriqquarterhebrew: 0x05B4,
  10942. hiriqwidehebrew: 0x05B4,
  10943. hlinebelow: 0x1E96,
  10944. hmonospace: 0xFF48,
  10945. hoarmenian: 0x0570,
  10946. hohipthai: 0x0E2B,
  10947. hohiragana: 0x307B,
  10948. hokatakana: 0x30DB,
  10949. hokatakanahalfwidth: 0xFF8E,
  10950. holam: 0x05B9,
  10951. holam19: 0x05B9,
  10952. holam26: 0x05B9,
  10953. holam32: 0x05B9,
  10954. holamhebrew: 0x05B9,
  10955. holamnarrowhebrew: 0x05B9,
  10956. holamquarterhebrew: 0x05B9,
  10957. holamwidehebrew: 0x05B9,
  10958. honokhukthai: 0x0E2E,
  10959. hookabovecomb: 0x0309,
  10960. hookcmb: 0x0309,
  10961. hookpalatalizedbelowcmb: 0x0321,
  10962. hookretroflexbelowcmb: 0x0322,
  10963. hoonsquare: 0x3342,
  10964. horicoptic: 0x03E9,
  10965. horizontalbar: 0x2015,
  10966. horncmb: 0x031B,
  10967. hotsprings: 0x2668,
  10968. house: 0x2302,
  10969. hparen: 0x24A3,
  10970. hsuperior: 0x02B0,
  10971. hturned: 0x0265,
  10972. huhiragana: 0x3075,
  10973. huiitosquare: 0x3333,
  10974. hukatakana: 0x30D5,
  10975. hukatakanahalfwidth: 0xFF8C,
  10976. hungarumlaut: 0x02DD,
  10977. hungarumlautcmb: 0x030B,
  10978. hv: 0x0195,
  10979. hyphen: 0x002D,
  10980. hypheninferior: 0xF6E5,
  10981. hyphenmonospace: 0xFF0D,
  10982. hyphensmall: 0xFE63,
  10983. hyphensuperior: 0xF6E6,
  10984. hyphentwo: 0x2010,
  10985. i: 0x0069,
  10986. iacute: 0x00ED,
  10987. iacyrillic: 0x044F,
  10988. ibengali: 0x0987,
  10989. ibopomofo: 0x3127,
  10990. ibreve: 0x012D,
  10991. icaron: 0x01D0,
  10992. icircle: 0x24D8,
  10993. icircumflex: 0x00EE,
  10994. icyrillic: 0x0456,
  10995. idblgrave: 0x0209,
  10996. ideographearthcircle: 0x328F,
  10997. ideographfirecircle: 0x328B,
  10998. ideographicallianceparen: 0x323F,
  10999. ideographiccallparen: 0x323A,
  11000. ideographiccentrecircle: 0x32A5,
  11001. ideographicclose: 0x3006,
  11002. ideographiccomma: 0x3001,
  11003. ideographiccommaleft: 0xFF64,
  11004. ideographiccongratulationparen: 0x3237,
  11005. ideographiccorrectcircle: 0x32A3,
  11006. ideographicearthparen: 0x322F,
  11007. ideographicenterpriseparen: 0x323D,
  11008. ideographicexcellentcircle: 0x329D,
  11009. ideographicfestivalparen: 0x3240,
  11010. ideographicfinancialcircle: 0x3296,
  11011. ideographicfinancialparen: 0x3236,
  11012. ideographicfireparen: 0x322B,
  11013. ideographichaveparen: 0x3232,
  11014. ideographichighcircle: 0x32A4,
  11015. ideographiciterationmark: 0x3005,
  11016. ideographiclaborcircle: 0x3298,
  11017. ideographiclaborparen: 0x3238,
  11018. ideographicleftcircle: 0x32A7,
  11019. ideographiclowcircle: 0x32A6,
  11020. ideographicmedicinecircle: 0x32A9,
  11021. ideographicmetalparen: 0x322E,
  11022. ideographicmoonparen: 0x322A,
  11023. ideographicnameparen: 0x3234,
  11024. ideographicperiod: 0x3002,
  11025. ideographicprintcircle: 0x329E,
  11026. ideographicreachparen: 0x3243,
  11027. ideographicrepresentparen: 0x3239,
  11028. ideographicresourceparen: 0x323E,
  11029. ideographicrightcircle: 0x32A8,
  11030. ideographicsecretcircle: 0x3299,
  11031. ideographicselfparen: 0x3242,
  11032. ideographicsocietyparen: 0x3233,
  11033. ideographicspace: 0x3000,
  11034. ideographicspecialparen: 0x3235,
  11035. ideographicstockparen: 0x3231,
  11036. ideographicstudyparen: 0x323B,
  11037. ideographicsunparen: 0x3230,
  11038. ideographicsuperviseparen: 0x323C,
  11039. ideographicwaterparen: 0x322C,
  11040. ideographicwoodparen: 0x322D,
  11041. ideographiczero: 0x3007,
  11042. ideographmetalcircle: 0x328E,
  11043. ideographmooncircle: 0x328A,
  11044. ideographnamecircle: 0x3294,
  11045. ideographsuncircle: 0x3290,
  11046. ideographwatercircle: 0x328C,
  11047. ideographwoodcircle: 0x328D,
  11048. ideva: 0x0907,
  11049. idieresis: 0x00EF,
  11050. idieresisacute: 0x1E2F,
  11051. idieresiscyrillic: 0x04E5,
  11052. idotbelow: 0x1ECB,
  11053. iebrevecyrillic: 0x04D7,
  11054. iecyrillic: 0x0435,
  11055. ieungacirclekorean: 0x3275,
  11056. ieungaparenkorean: 0x3215,
  11057. ieungcirclekorean: 0x3267,
  11058. ieungkorean: 0x3147,
  11059. ieungparenkorean: 0x3207,
  11060. igrave: 0x00EC,
  11061. igujarati: 0x0A87,
  11062. igurmukhi: 0x0A07,
  11063. ihiragana: 0x3044,
  11064. ihookabove: 0x1EC9,
  11065. iibengali: 0x0988,
  11066. iicyrillic: 0x0438,
  11067. iideva: 0x0908,
  11068. iigujarati: 0x0A88,
  11069. iigurmukhi: 0x0A08,
  11070. iimatragurmukhi: 0x0A40,
  11071. iinvertedbreve: 0x020B,
  11072. iishortcyrillic: 0x0439,
  11073. iivowelsignbengali: 0x09C0,
  11074. iivowelsigndeva: 0x0940,
  11075. iivowelsigngujarati: 0x0AC0,
  11076. ij: 0x0133,
  11077. ikatakana: 0x30A4,
  11078. ikatakanahalfwidth: 0xFF72,
  11079. ikorean: 0x3163,
  11080. ilde: 0x02DC,
  11081. iluyhebrew: 0x05AC,
  11082. imacron: 0x012B,
  11083. imacroncyrillic: 0x04E3,
  11084. imageorapproximatelyequal: 0x2253,
  11085. imatragurmukhi: 0x0A3F,
  11086. imonospace: 0xFF49,
  11087. increment: 0x2206,
  11088. infinity: 0x221E,
  11089. iniarmenian: 0x056B,
  11090. integral: 0x222B,
  11091. integralbottom: 0x2321,
  11092. integralbt: 0x2321,
  11093. integralex: 0xF8F5,
  11094. integraltop: 0x2320,
  11095. integraltp: 0x2320,
  11096. intersection: 0x2229,
  11097. intisquare: 0x3305,
  11098. invbullet: 0x25D8,
  11099. invcircle: 0x25D9,
  11100. invsmileface: 0x263B,
  11101. iocyrillic: 0x0451,
  11102. iogonek: 0x012F,
  11103. iota: 0x03B9,
  11104. iotadieresis: 0x03CA,
  11105. iotadieresistonos: 0x0390,
  11106. iotalatin: 0x0269,
  11107. iotatonos: 0x03AF,
  11108. iparen: 0x24A4,
  11109. irigurmukhi: 0x0A72,
  11110. ismallhiragana: 0x3043,
  11111. ismallkatakana: 0x30A3,
  11112. ismallkatakanahalfwidth: 0xFF68,
  11113. issharbengali: 0x09FA,
  11114. istroke: 0x0268,
  11115. isuperior: 0xF6ED,
  11116. iterationhiragana: 0x309D,
  11117. iterationkatakana: 0x30FD,
  11118. itilde: 0x0129,
  11119. itildebelow: 0x1E2D,
  11120. iubopomofo: 0x3129,
  11121. iucyrillic: 0x044E,
  11122. ivowelsignbengali: 0x09BF,
  11123. ivowelsigndeva: 0x093F,
  11124. ivowelsigngujarati: 0x0ABF,
  11125. izhitsacyrillic: 0x0475,
  11126. izhitsadblgravecyrillic: 0x0477,
  11127. j: 0x006A,
  11128. jaarmenian: 0x0571,
  11129. jabengali: 0x099C,
  11130. jadeva: 0x091C,
  11131. jagujarati: 0x0A9C,
  11132. jagurmukhi: 0x0A1C,
  11133. jbopomofo: 0x3110,
  11134. jcaron: 0x01F0,
  11135. jcircle: 0x24D9,
  11136. jcircumflex: 0x0135,
  11137. jcrossedtail: 0x029D,
  11138. jdotlessstroke: 0x025F,
  11139. jecyrillic: 0x0458,
  11140. jeemarabic: 0x062C,
  11141. jeemfinalarabic: 0xFE9E,
  11142. jeeminitialarabic: 0xFE9F,
  11143. jeemmedialarabic: 0xFEA0,
  11144. jeharabic: 0x0698,
  11145. jehfinalarabic: 0xFB8B,
  11146. jhabengali: 0x099D,
  11147. jhadeva: 0x091D,
  11148. jhagujarati: 0x0A9D,
  11149. jhagurmukhi: 0x0A1D,
  11150. jheharmenian: 0x057B,
  11151. jis: 0x3004,
  11152. jmonospace: 0xFF4A,
  11153. jparen: 0x24A5,
  11154. jsuperior: 0x02B2,
  11155. k: 0x006B,
  11156. kabashkircyrillic: 0x04A1,
  11157. kabengali: 0x0995,
  11158. kacute: 0x1E31,
  11159. kacyrillic: 0x043A,
  11160. kadescendercyrillic: 0x049B,
  11161. kadeva: 0x0915,
  11162. kaf: 0x05DB,
  11163. kafarabic: 0x0643,
  11164. kafdagesh: 0xFB3B,
  11165. kafdageshhebrew: 0xFB3B,
  11166. kaffinalarabic: 0xFEDA,
  11167. kafhebrew: 0x05DB,
  11168. kafinitialarabic: 0xFEDB,
  11169. kafmedialarabic: 0xFEDC,
  11170. kafrafehebrew: 0xFB4D,
  11171. kagujarati: 0x0A95,
  11172. kagurmukhi: 0x0A15,
  11173. kahiragana: 0x304B,
  11174. kahookcyrillic: 0x04C4,
  11175. kakatakana: 0x30AB,
  11176. kakatakanahalfwidth: 0xFF76,
  11177. kappa: 0x03BA,
  11178. kappasymbolgreek: 0x03F0,
  11179. kapyeounmieumkorean: 0x3171,
  11180. kapyeounphieuphkorean: 0x3184,
  11181. kapyeounpieupkorean: 0x3178,
  11182. kapyeounssangpieupkorean: 0x3179,
  11183. karoriisquare: 0x330D,
  11184. kashidaautoarabic: 0x0640,
  11185. kashidaautonosidebearingarabic: 0x0640,
  11186. kasmallkatakana: 0x30F5,
  11187. kasquare: 0x3384,
  11188. kasraarabic: 0x0650,
  11189. kasratanarabic: 0x064D,
  11190. kastrokecyrillic: 0x049F,
  11191. katahiraprolongmarkhalfwidth: 0xFF70,
  11192. kaverticalstrokecyrillic: 0x049D,
  11193. kbopomofo: 0x310E,
  11194. kcalsquare: 0x3389,
  11195. kcaron: 0x01E9,
  11196. kcedilla: 0x0137,
  11197. kcircle: 0x24DA,
  11198. kcommaaccent: 0x0137,
  11199. kdotbelow: 0x1E33,
  11200. keharmenian: 0x0584,
  11201. kehiragana: 0x3051,
  11202. kekatakana: 0x30B1,
  11203. kekatakanahalfwidth: 0xFF79,
  11204. kenarmenian: 0x056F,
  11205. kesmallkatakana: 0x30F6,
  11206. kgreenlandic: 0x0138,
  11207. khabengali: 0x0996,
  11208. khacyrillic: 0x0445,
  11209. khadeva: 0x0916,
  11210. khagujarati: 0x0A96,
  11211. khagurmukhi: 0x0A16,
  11212. khaharabic: 0x062E,
  11213. khahfinalarabic: 0xFEA6,
  11214. khahinitialarabic: 0xFEA7,
  11215. khahmedialarabic: 0xFEA8,
  11216. kheicoptic: 0x03E7,
  11217. khhadeva: 0x0959,
  11218. khhagurmukhi: 0x0A59,
  11219. khieukhacirclekorean: 0x3278,
  11220. khieukhaparenkorean: 0x3218,
  11221. khieukhcirclekorean: 0x326A,
  11222. khieukhkorean: 0x314B,
  11223. khieukhparenkorean: 0x320A,
  11224. khokhaithai: 0x0E02,
  11225. khokhonthai: 0x0E05,
  11226. khokhuatthai: 0x0E03,
  11227. khokhwaithai: 0x0E04,
  11228. khomutthai: 0x0E5B,
  11229. khook: 0x0199,
  11230. khorakhangthai: 0x0E06,
  11231. khzsquare: 0x3391,
  11232. kihiragana: 0x304D,
  11233. kikatakana: 0x30AD,
  11234. kikatakanahalfwidth: 0xFF77,
  11235. kiroguramusquare: 0x3315,
  11236. kiromeetorusquare: 0x3316,
  11237. kirosquare: 0x3314,
  11238. kiyeokacirclekorean: 0x326E,
  11239. kiyeokaparenkorean: 0x320E,
  11240. kiyeokcirclekorean: 0x3260,
  11241. kiyeokkorean: 0x3131,
  11242. kiyeokparenkorean: 0x3200,
  11243. kiyeoksioskorean: 0x3133,
  11244. kjecyrillic: 0x045C,
  11245. klinebelow: 0x1E35,
  11246. klsquare: 0x3398,
  11247. kmcubedsquare: 0x33A6,
  11248. kmonospace: 0xFF4B,
  11249. kmsquaredsquare: 0x33A2,
  11250. kohiragana: 0x3053,
  11251. kohmsquare: 0x33C0,
  11252. kokaithai: 0x0E01,
  11253. kokatakana: 0x30B3,
  11254. kokatakanahalfwidth: 0xFF7A,
  11255. kooposquare: 0x331E,
  11256. koppacyrillic: 0x0481,
  11257. koreanstandardsymbol: 0x327F,
  11258. koroniscmb: 0x0343,
  11259. kparen: 0x24A6,
  11260. kpasquare: 0x33AA,
  11261. ksicyrillic: 0x046F,
  11262. ktsquare: 0x33CF,
  11263. kturned: 0x029E,
  11264. kuhiragana: 0x304F,
  11265. kukatakana: 0x30AF,
  11266. kukatakanahalfwidth: 0xFF78,
  11267. kvsquare: 0x33B8,
  11268. kwsquare: 0x33BE,
  11269. l: 0x006C,
  11270. labengali: 0x09B2,
  11271. lacute: 0x013A,
  11272. ladeva: 0x0932,
  11273. lagujarati: 0x0AB2,
  11274. lagurmukhi: 0x0A32,
  11275. lakkhangyaothai: 0x0E45,
  11276. lamaleffinalarabic: 0xFEFC,
  11277. lamalefhamzaabovefinalarabic: 0xFEF8,
  11278. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  11279. lamalefhamzabelowfinalarabic: 0xFEFA,
  11280. lamalefhamzabelowisolatedarabic: 0xFEF9,
  11281. lamalefisolatedarabic: 0xFEFB,
  11282. lamalefmaddaabovefinalarabic: 0xFEF6,
  11283. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  11284. lamarabic: 0x0644,
  11285. lambda: 0x03BB,
  11286. lambdastroke: 0x019B,
  11287. lamed: 0x05DC,
  11288. lameddagesh: 0xFB3C,
  11289. lameddageshhebrew: 0xFB3C,
  11290. lamedhebrew: 0x05DC,
  11291. lamfinalarabic: 0xFEDE,
  11292. lamhahinitialarabic: 0xFCCA,
  11293. laminitialarabic: 0xFEDF,
  11294. lamjeeminitialarabic: 0xFCC9,
  11295. lamkhahinitialarabic: 0xFCCB,
  11296. lamlamhehisolatedarabic: 0xFDF2,
  11297. lammedialarabic: 0xFEE0,
  11298. lammeemhahinitialarabic: 0xFD88,
  11299. lammeeminitialarabic: 0xFCCC,
  11300. largecircle: 0x25EF,
  11301. lbar: 0x019A,
  11302. lbelt: 0x026C,
  11303. lbopomofo: 0x310C,
  11304. lcaron: 0x013E,
  11305. lcedilla: 0x013C,
  11306. lcircle: 0x24DB,
  11307. lcircumflexbelow: 0x1E3D,
  11308. lcommaaccent: 0x013C,
  11309. ldot: 0x0140,
  11310. ldotaccent: 0x0140,
  11311. ldotbelow: 0x1E37,
  11312. ldotbelowmacron: 0x1E39,
  11313. leftangleabovecmb: 0x031A,
  11314. lefttackbelowcmb: 0x0318,
  11315. less: 0x003C,
  11316. lessequal: 0x2264,
  11317. lessequalorgreater: 0x22DA,
  11318. lessmonospace: 0xFF1C,
  11319. lessorequivalent: 0x2272,
  11320. lessorgreater: 0x2276,
  11321. lessoverequal: 0x2266,
  11322. lesssmall: 0xFE64,
  11323. lezh: 0x026E,
  11324. lfblock: 0x258C,
  11325. lhookretroflex: 0x026D,
  11326. lira: 0x20A4,
  11327. liwnarmenian: 0x056C,
  11328. lj: 0x01C9,
  11329. ljecyrillic: 0x0459,
  11330. ll: 0xF6C0,
  11331. lladeva: 0x0933,
  11332. llagujarati: 0x0AB3,
  11333. llinebelow: 0x1E3B,
  11334. llladeva: 0x0934,
  11335. llvocalicbengali: 0x09E1,
  11336. llvocalicdeva: 0x0961,
  11337. llvocalicvowelsignbengali: 0x09E3,
  11338. llvocalicvowelsigndeva: 0x0963,
  11339. lmiddletilde: 0x026B,
  11340. lmonospace: 0xFF4C,
  11341. lmsquare: 0x33D0,
  11342. lochulathai: 0x0E2C,
  11343. logicaland: 0x2227,
  11344. logicalnot: 0x00AC,
  11345. logicalnotreversed: 0x2310,
  11346. logicalor: 0x2228,
  11347. lolingthai: 0x0E25,
  11348. longs: 0x017F,
  11349. lowlinecenterline: 0xFE4E,
  11350. lowlinecmb: 0x0332,
  11351. lowlinedashed: 0xFE4D,
  11352. lozenge: 0x25CA,
  11353. lparen: 0x24A7,
  11354. lslash: 0x0142,
  11355. lsquare: 0x2113,
  11356. lsuperior: 0xF6EE,
  11357. ltshade: 0x2591,
  11358. luthai: 0x0E26,
  11359. lvocalicbengali: 0x098C,
  11360. lvocalicdeva: 0x090C,
  11361. lvocalicvowelsignbengali: 0x09E2,
  11362. lvocalicvowelsigndeva: 0x0962,
  11363. lxsquare: 0x33D3,
  11364. m: 0x006D,
  11365. mabengali: 0x09AE,
  11366. macron: 0x00AF,
  11367. macronbelowcmb: 0x0331,
  11368. macroncmb: 0x0304,
  11369. macronlowmod: 0x02CD,
  11370. macronmonospace: 0xFFE3,
  11371. macute: 0x1E3F,
  11372. madeva: 0x092E,
  11373. magujarati: 0x0AAE,
  11374. magurmukhi: 0x0A2E,
  11375. mahapakhhebrew: 0x05A4,
  11376. mahapakhlefthebrew: 0x05A4,
  11377. mahiragana: 0x307E,
  11378. maichattawalowleftthai: 0xF895,
  11379. maichattawalowrightthai: 0xF894,
  11380. maichattawathai: 0x0E4B,
  11381. maichattawaupperleftthai: 0xF893,
  11382. maieklowleftthai: 0xF88C,
  11383. maieklowrightthai: 0xF88B,
  11384. maiekthai: 0x0E48,
  11385. maiekupperleftthai: 0xF88A,
  11386. maihanakatleftthai: 0xF884,
  11387. maihanakatthai: 0x0E31,
  11388. maitaikhuleftthai: 0xF889,
  11389. maitaikhuthai: 0x0E47,
  11390. maitholowleftthai: 0xF88F,
  11391. maitholowrightthai: 0xF88E,
  11392. maithothai: 0x0E49,
  11393. maithoupperleftthai: 0xF88D,
  11394. maitrilowleftthai: 0xF892,
  11395. maitrilowrightthai: 0xF891,
  11396. maitrithai: 0x0E4A,
  11397. maitriupperleftthai: 0xF890,
  11398. maiyamokthai: 0x0E46,
  11399. makatakana: 0x30DE,
  11400. makatakanahalfwidth: 0xFF8F,
  11401. male: 0x2642,
  11402. mansyonsquare: 0x3347,
  11403. maqafhebrew: 0x05BE,
  11404. mars: 0x2642,
  11405. masoracirclehebrew: 0x05AF,
  11406. masquare: 0x3383,
  11407. mbopomofo: 0x3107,
  11408. mbsquare: 0x33D4,
  11409. mcircle: 0x24DC,
  11410. mcubedsquare: 0x33A5,
  11411. mdotaccent: 0x1E41,
  11412. mdotbelow: 0x1E43,
  11413. meemarabic: 0x0645,
  11414. meemfinalarabic: 0xFEE2,
  11415. meeminitialarabic: 0xFEE3,
  11416. meemmedialarabic: 0xFEE4,
  11417. meemmeeminitialarabic: 0xFCD1,
  11418. meemmeemisolatedarabic: 0xFC48,
  11419. meetorusquare: 0x334D,
  11420. mehiragana: 0x3081,
  11421. meizierasquare: 0x337E,
  11422. mekatakana: 0x30E1,
  11423. mekatakanahalfwidth: 0xFF92,
  11424. mem: 0x05DE,
  11425. memdagesh: 0xFB3E,
  11426. memdageshhebrew: 0xFB3E,
  11427. memhebrew: 0x05DE,
  11428. menarmenian: 0x0574,
  11429. merkhahebrew: 0x05A5,
  11430. merkhakefulahebrew: 0x05A6,
  11431. merkhakefulalefthebrew: 0x05A6,
  11432. merkhalefthebrew: 0x05A5,
  11433. mhook: 0x0271,
  11434. mhzsquare: 0x3392,
  11435. middledotkatakanahalfwidth: 0xFF65,
  11436. middot: 0x00B7,
  11437. mieumacirclekorean: 0x3272,
  11438. mieumaparenkorean: 0x3212,
  11439. mieumcirclekorean: 0x3264,
  11440. mieumkorean: 0x3141,
  11441. mieumpansioskorean: 0x3170,
  11442. mieumparenkorean: 0x3204,
  11443. mieumpieupkorean: 0x316E,
  11444. mieumsioskorean: 0x316F,
  11445. mihiragana: 0x307F,
  11446. mikatakana: 0x30DF,
  11447. mikatakanahalfwidth: 0xFF90,
  11448. minus: 0x2212,
  11449. minusbelowcmb: 0x0320,
  11450. minuscircle: 0x2296,
  11451. minusmod: 0x02D7,
  11452. minusplus: 0x2213,
  11453. minute: 0x2032,
  11454. miribaarusquare: 0x334A,
  11455. mirisquare: 0x3349,
  11456. mlonglegturned: 0x0270,
  11457. mlsquare: 0x3396,
  11458. mmcubedsquare: 0x33A3,
  11459. mmonospace: 0xFF4D,
  11460. mmsquaredsquare: 0x339F,
  11461. mohiragana: 0x3082,
  11462. mohmsquare: 0x33C1,
  11463. mokatakana: 0x30E2,
  11464. mokatakanahalfwidth: 0xFF93,
  11465. molsquare: 0x33D6,
  11466. momathai: 0x0E21,
  11467. moverssquare: 0x33A7,
  11468. moverssquaredsquare: 0x33A8,
  11469. mparen: 0x24A8,
  11470. mpasquare: 0x33AB,
  11471. mssquare: 0x33B3,
  11472. msuperior: 0xF6EF,
  11473. mturned: 0x026F,
  11474. mu: 0x00B5,
  11475. mu1: 0x00B5,
  11476. muasquare: 0x3382,
  11477. muchgreater: 0x226B,
  11478. muchless: 0x226A,
  11479. mufsquare: 0x338C,
  11480. mugreek: 0x03BC,
  11481. mugsquare: 0x338D,
  11482. muhiragana: 0x3080,
  11483. mukatakana: 0x30E0,
  11484. mukatakanahalfwidth: 0xFF91,
  11485. mulsquare: 0x3395,
  11486. multiply: 0x00D7,
  11487. mumsquare: 0x339B,
  11488. munahhebrew: 0x05A3,
  11489. munahlefthebrew: 0x05A3,
  11490. musicalnote: 0x266A,
  11491. musicalnotedbl: 0x266B,
  11492. musicflatsign: 0x266D,
  11493. musicsharpsign: 0x266F,
  11494. mussquare: 0x33B2,
  11495. muvsquare: 0x33B6,
  11496. muwsquare: 0x33BC,
  11497. mvmegasquare: 0x33B9,
  11498. mvsquare: 0x33B7,
  11499. mwmegasquare: 0x33BF,
  11500. mwsquare: 0x33BD,
  11501. n: 0x006E,
  11502. nabengali: 0x09A8,
  11503. nabla: 0x2207,
  11504. nacute: 0x0144,
  11505. nadeva: 0x0928,
  11506. nagujarati: 0x0AA8,
  11507. nagurmukhi: 0x0A28,
  11508. nahiragana: 0x306A,
  11509. nakatakana: 0x30CA,
  11510. nakatakanahalfwidth: 0xFF85,
  11511. napostrophe: 0x0149,
  11512. nasquare: 0x3381,
  11513. nbopomofo: 0x310B,
  11514. nbspace: 0x00A0,
  11515. ncaron: 0x0148,
  11516. ncedilla: 0x0146,
  11517. ncircle: 0x24DD,
  11518. ncircumflexbelow: 0x1E4B,
  11519. ncommaaccent: 0x0146,
  11520. ndotaccent: 0x1E45,
  11521. ndotbelow: 0x1E47,
  11522. nehiragana: 0x306D,
  11523. nekatakana: 0x30CD,
  11524. nekatakanahalfwidth: 0xFF88,
  11525. newsheqelsign: 0x20AA,
  11526. nfsquare: 0x338B,
  11527. ngabengali: 0x0999,
  11528. ngadeva: 0x0919,
  11529. ngagujarati: 0x0A99,
  11530. ngagurmukhi: 0x0A19,
  11531. ngonguthai: 0x0E07,
  11532. nhiragana: 0x3093,
  11533. nhookleft: 0x0272,
  11534. nhookretroflex: 0x0273,
  11535. nieunacirclekorean: 0x326F,
  11536. nieunaparenkorean: 0x320F,
  11537. nieuncieuckorean: 0x3135,
  11538. nieuncirclekorean: 0x3261,
  11539. nieunhieuhkorean: 0x3136,
  11540. nieunkorean: 0x3134,
  11541. nieunpansioskorean: 0x3168,
  11542. nieunparenkorean: 0x3201,
  11543. nieunsioskorean: 0x3167,
  11544. nieuntikeutkorean: 0x3166,
  11545. nihiragana: 0x306B,
  11546. nikatakana: 0x30CB,
  11547. nikatakanahalfwidth: 0xFF86,
  11548. nikhahitleftthai: 0xF899,
  11549. nikhahitthai: 0x0E4D,
  11550. nine: 0x0039,
  11551. ninearabic: 0x0669,
  11552. ninebengali: 0x09EF,
  11553. ninecircle: 0x2468,
  11554. ninecircleinversesansserif: 0x2792,
  11555. ninedeva: 0x096F,
  11556. ninegujarati: 0x0AEF,
  11557. ninegurmukhi: 0x0A6F,
  11558. ninehackarabic: 0x0669,
  11559. ninehangzhou: 0x3029,
  11560. nineideographicparen: 0x3228,
  11561. nineinferior: 0x2089,
  11562. ninemonospace: 0xFF19,
  11563. nineoldstyle: 0xF739,
  11564. nineparen: 0x247C,
  11565. nineperiod: 0x2490,
  11566. ninepersian: 0x06F9,
  11567. nineroman: 0x2178,
  11568. ninesuperior: 0x2079,
  11569. nineteencircle: 0x2472,
  11570. nineteenparen: 0x2486,
  11571. nineteenperiod: 0x249A,
  11572. ninethai: 0x0E59,
  11573. nj: 0x01CC,
  11574. njecyrillic: 0x045A,
  11575. nkatakana: 0x30F3,
  11576. nkatakanahalfwidth: 0xFF9D,
  11577. nlegrightlong: 0x019E,
  11578. nlinebelow: 0x1E49,
  11579. nmonospace: 0xFF4E,
  11580. nmsquare: 0x339A,
  11581. nnabengali: 0x09A3,
  11582. nnadeva: 0x0923,
  11583. nnagujarati: 0x0AA3,
  11584. nnagurmukhi: 0x0A23,
  11585. nnnadeva: 0x0929,
  11586. nohiragana: 0x306E,
  11587. nokatakana: 0x30CE,
  11588. nokatakanahalfwidth: 0xFF89,
  11589. nonbreakingspace: 0x00A0,
  11590. nonenthai: 0x0E13,
  11591. nonuthai: 0x0E19,
  11592. noonarabic: 0x0646,
  11593. noonfinalarabic: 0xFEE6,
  11594. noonghunnaarabic: 0x06BA,
  11595. noonghunnafinalarabic: 0xFB9F,
  11596. nooninitialarabic: 0xFEE7,
  11597. noonjeeminitialarabic: 0xFCD2,
  11598. noonjeemisolatedarabic: 0xFC4B,
  11599. noonmedialarabic: 0xFEE8,
  11600. noonmeeminitialarabic: 0xFCD5,
  11601. noonmeemisolatedarabic: 0xFC4E,
  11602. noonnoonfinalarabic: 0xFC8D,
  11603. notcontains: 0x220C,
  11604. notelement: 0x2209,
  11605. notelementof: 0x2209,
  11606. notequal: 0x2260,
  11607. notgreater: 0x226F,
  11608. notgreaternorequal: 0x2271,
  11609. notgreaternorless: 0x2279,
  11610. notidentical: 0x2262,
  11611. notless: 0x226E,
  11612. notlessnorequal: 0x2270,
  11613. notparallel: 0x2226,
  11614. notprecedes: 0x2280,
  11615. notsubset: 0x2284,
  11616. notsucceeds: 0x2281,
  11617. notsuperset: 0x2285,
  11618. nowarmenian: 0x0576,
  11619. nparen: 0x24A9,
  11620. nssquare: 0x33B1,
  11621. nsuperior: 0x207F,
  11622. ntilde: 0x00F1,
  11623. nu: 0x03BD,
  11624. nuhiragana: 0x306C,
  11625. nukatakana: 0x30CC,
  11626. nukatakanahalfwidth: 0xFF87,
  11627. nuktabengali: 0x09BC,
  11628. nuktadeva: 0x093C,
  11629. nuktagujarati: 0x0ABC,
  11630. nuktagurmukhi: 0x0A3C,
  11631. numbersign: 0x0023,
  11632. numbersignmonospace: 0xFF03,
  11633. numbersignsmall: 0xFE5F,
  11634. numeralsigngreek: 0x0374,
  11635. numeralsignlowergreek: 0x0375,
  11636. numero: 0x2116,
  11637. nun: 0x05E0,
  11638. nundagesh: 0xFB40,
  11639. nundageshhebrew: 0xFB40,
  11640. nunhebrew: 0x05E0,
  11641. nvsquare: 0x33B5,
  11642. nwsquare: 0x33BB,
  11643. nyabengali: 0x099E,
  11644. nyadeva: 0x091E,
  11645. nyagujarati: 0x0A9E,
  11646. nyagurmukhi: 0x0A1E,
  11647. o: 0x006F,
  11648. oacute: 0x00F3,
  11649. oangthai: 0x0E2D,
  11650. obarred: 0x0275,
  11651. obarredcyrillic: 0x04E9,
  11652. obarreddieresiscyrillic: 0x04EB,
  11653. obengali: 0x0993,
  11654. obopomofo: 0x311B,
  11655. obreve: 0x014F,
  11656. ocandradeva: 0x0911,
  11657. ocandragujarati: 0x0A91,
  11658. ocandravowelsigndeva: 0x0949,
  11659. ocandravowelsigngujarati: 0x0AC9,
  11660. ocaron: 0x01D2,
  11661. ocircle: 0x24DE,
  11662. ocircumflex: 0x00F4,
  11663. ocircumflexacute: 0x1ED1,
  11664. ocircumflexdotbelow: 0x1ED9,
  11665. ocircumflexgrave: 0x1ED3,
  11666. ocircumflexhookabove: 0x1ED5,
  11667. ocircumflextilde: 0x1ED7,
  11668. ocyrillic: 0x043E,
  11669. odblacute: 0x0151,
  11670. odblgrave: 0x020D,
  11671. odeva: 0x0913,
  11672. odieresis: 0x00F6,
  11673. odieresiscyrillic: 0x04E7,
  11674. odotbelow: 0x1ECD,
  11675. oe: 0x0153,
  11676. oekorean: 0x315A,
  11677. ogonek: 0x02DB,
  11678. ogonekcmb: 0x0328,
  11679. ograve: 0x00F2,
  11680. ogujarati: 0x0A93,
  11681. oharmenian: 0x0585,
  11682. ohiragana: 0x304A,
  11683. ohookabove: 0x1ECF,
  11684. ohorn: 0x01A1,
  11685. ohornacute: 0x1EDB,
  11686. ohorndotbelow: 0x1EE3,
  11687. ohorngrave: 0x1EDD,
  11688. ohornhookabove: 0x1EDF,
  11689. ohorntilde: 0x1EE1,
  11690. ohungarumlaut: 0x0151,
  11691. oi: 0x01A3,
  11692. oinvertedbreve: 0x020F,
  11693. okatakana: 0x30AA,
  11694. okatakanahalfwidth: 0xFF75,
  11695. okorean: 0x3157,
  11696. olehebrew: 0x05AB,
  11697. omacron: 0x014D,
  11698. omacronacute: 0x1E53,
  11699. omacrongrave: 0x1E51,
  11700. omdeva: 0x0950,
  11701. omega: 0x03C9,
  11702. omega1: 0x03D6,
  11703. omegacyrillic: 0x0461,
  11704. omegalatinclosed: 0x0277,
  11705. omegaroundcyrillic: 0x047B,
  11706. omegatitlocyrillic: 0x047D,
  11707. omegatonos: 0x03CE,
  11708. omgujarati: 0x0AD0,
  11709. omicron: 0x03BF,
  11710. omicrontonos: 0x03CC,
  11711. omonospace: 0xFF4F,
  11712. one: 0x0031,
  11713. onearabic: 0x0661,
  11714. onebengali: 0x09E7,
  11715. onecircle: 0x2460,
  11716. onecircleinversesansserif: 0x278A,
  11717. onedeva: 0x0967,
  11718. onedotenleader: 0x2024,
  11719. oneeighth: 0x215B,
  11720. onefitted: 0xF6DC,
  11721. onegujarati: 0x0AE7,
  11722. onegurmukhi: 0x0A67,
  11723. onehackarabic: 0x0661,
  11724. onehalf: 0x00BD,
  11725. onehangzhou: 0x3021,
  11726. oneideographicparen: 0x3220,
  11727. oneinferior: 0x2081,
  11728. onemonospace: 0xFF11,
  11729. onenumeratorbengali: 0x09F4,
  11730. oneoldstyle: 0xF731,
  11731. oneparen: 0x2474,
  11732. oneperiod: 0x2488,
  11733. onepersian: 0x06F1,
  11734. onequarter: 0x00BC,
  11735. oneroman: 0x2170,
  11736. onesuperior: 0x00B9,
  11737. onethai: 0x0E51,
  11738. onethird: 0x2153,
  11739. oogonek: 0x01EB,
  11740. oogonekmacron: 0x01ED,
  11741. oogurmukhi: 0x0A13,
  11742. oomatragurmukhi: 0x0A4B,
  11743. oopen: 0x0254,
  11744. oparen: 0x24AA,
  11745. openbullet: 0x25E6,
  11746. option: 0x2325,
  11747. ordfeminine: 0x00AA,
  11748. ordmasculine: 0x00BA,
  11749. orthogonal: 0x221F,
  11750. oshortdeva: 0x0912,
  11751. oshortvowelsigndeva: 0x094A,
  11752. oslash: 0x00F8,
  11753. oslashacute: 0x01FF,
  11754. osmallhiragana: 0x3049,
  11755. osmallkatakana: 0x30A9,
  11756. osmallkatakanahalfwidth: 0xFF6B,
  11757. ostrokeacute: 0x01FF,
  11758. osuperior: 0xF6F0,
  11759. otcyrillic: 0x047F,
  11760. otilde: 0x00F5,
  11761. otildeacute: 0x1E4D,
  11762. otildedieresis: 0x1E4F,
  11763. oubopomofo: 0x3121,
  11764. overline: 0x203E,
  11765. overlinecenterline: 0xFE4A,
  11766. overlinecmb: 0x0305,
  11767. overlinedashed: 0xFE49,
  11768. overlinedblwavy: 0xFE4C,
  11769. overlinewavy: 0xFE4B,
  11770. overscore: 0x00AF,
  11771. ovowelsignbengali: 0x09CB,
  11772. ovowelsigndeva: 0x094B,
  11773. ovowelsigngujarati: 0x0ACB,
  11774. p: 0x0070,
  11775. paampssquare: 0x3380,
  11776. paasentosquare: 0x332B,
  11777. pabengali: 0x09AA,
  11778. pacute: 0x1E55,
  11779. padeva: 0x092A,
  11780. pagedown: 0x21DF,
  11781. pageup: 0x21DE,
  11782. pagujarati: 0x0AAA,
  11783. pagurmukhi: 0x0A2A,
  11784. pahiragana: 0x3071,
  11785. paiyannoithai: 0x0E2F,
  11786. pakatakana: 0x30D1,
  11787. palatalizationcyrilliccmb: 0x0484,
  11788. palochkacyrillic: 0x04C0,
  11789. pansioskorean: 0x317F,
  11790. paragraph: 0x00B6,
  11791. parallel: 0x2225,
  11792. parenleft: 0x0028,
  11793. parenleftaltonearabic: 0xFD3E,
  11794. parenleftbt: 0xF8ED,
  11795. parenleftex: 0xF8EC,
  11796. parenleftinferior: 0x208D,
  11797. parenleftmonospace: 0xFF08,
  11798. parenleftsmall: 0xFE59,
  11799. parenleftsuperior: 0x207D,
  11800. parenlefttp: 0xF8EB,
  11801. parenleftvertical: 0xFE35,
  11802. parenright: 0x0029,
  11803. parenrightaltonearabic: 0xFD3F,
  11804. parenrightbt: 0xF8F8,
  11805. parenrightex: 0xF8F7,
  11806. parenrightinferior: 0x208E,
  11807. parenrightmonospace: 0xFF09,
  11808. parenrightsmall: 0xFE5A,
  11809. parenrightsuperior: 0x207E,
  11810. parenrighttp: 0xF8F6,
  11811. parenrightvertical: 0xFE36,
  11812. partialdiff: 0x2202,
  11813. paseqhebrew: 0x05C0,
  11814. pashtahebrew: 0x0599,
  11815. pasquare: 0x33A9,
  11816. patah: 0x05B7,
  11817. patah11: 0x05B7,
  11818. patah1d: 0x05B7,
  11819. patah2a: 0x05B7,
  11820. patahhebrew: 0x05B7,
  11821. patahnarrowhebrew: 0x05B7,
  11822. patahquarterhebrew: 0x05B7,
  11823. patahwidehebrew: 0x05B7,
  11824. pazerhebrew: 0x05A1,
  11825. pbopomofo: 0x3106,
  11826. pcircle: 0x24DF,
  11827. pdotaccent: 0x1E57,
  11828. pe: 0x05E4,
  11829. pecyrillic: 0x043F,
  11830. pedagesh: 0xFB44,
  11831. pedageshhebrew: 0xFB44,
  11832. peezisquare: 0x333B,
  11833. pefinaldageshhebrew: 0xFB43,
  11834. peharabic: 0x067E,
  11835. peharmenian: 0x057A,
  11836. pehebrew: 0x05E4,
  11837. pehfinalarabic: 0xFB57,
  11838. pehinitialarabic: 0xFB58,
  11839. pehiragana: 0x307A,
  11840. pehmedialarabic: 0xFB59,
  11841. pekatakana: 0x30DA,
  11842. pemiddlehookcyrillic: 0x04A7,
  11843. perafehebrew: 0xFB4E,
  11844. percent: 0x0025,
  11845. percentarabic: 0x066A,
  11846. percentmonospace: 0xFF05,
  11847. percentsmall: 0xFE6A,
  11848. period: 0x002E,
  11849. periodarmenian: 0x0589,
  11850. periodcentered: 0x00B7,
  11851. periodhalfwidth: 0xFF61,
  11852. periodinferior: 0xF6E7,
  11853. periodmonospace: 0xFF0E,
  11854. periodsmall: 0xFE52,
  11855. periodsuperior: 0xF6E8,
  11856. perispomenigreekcmb: 0x0342,
  11857. perpendicular: 0x22A5,
  11858. perthousand: 0x2030,
  11859. peseta: 0x20A7,
  11860. pfsquare: 0x338A,
  11861. phabengali: 0x09AB,
  11862. phadeva: 0x092B,
  11863. phagujarati: 0x0AAB,
  11864. phagurmukhi: 0x0A2B,
  11865. phi: 0x03C6,
  11866. phi1: 0x03D5,
  11867. phieuphacirclekorean: 0x327A,
  11868. phieuphaparenkorean: 0x321A,
  11869. phieuphcirclekorean: 0x326C,
  11870. phieuphkorean: 0x314D,
  11871. phieuphparenkorean: 0x320C,
  11872. philatin: 0x0278,
  11873. phinthuthai: 0x0E3A,
  11874. phisymbolgreek: 0x03D5,
  11875. phook: 0x01A5,
  11876. phophanthai: 0x0E1E,
  11877. phophungthai: 0x0E1C,
  11878. phosamphaothai: 0x0E20,
  11879. pi: 0x03C0,
  11880. pieupacirclekorean: 0x3273,
  11881. pieupaparenkorean: 0x3213,
  11882. pieupcieuckorean: 0x3176,
  11883. pieupcirclekorean: 0x3265,
  11884. pieupkiyeokkorean: 0x3172,
  11885. pieupkorean: 0x3142,
  11886. pieupparenkorean: 0x3205,
  11887. pieupsioskiyeokkorean: 0x3174,
  11888. pieupsioskorean: 0x3144,
  11889. pieupsiostikeutkorean: 0x3175,
  11890. pieupthieuthkorean: 0x3177,
  11891. pieuptikeutkorean: 0x3173,
  11892. pihiragana: 0x3074,
  11893. pikatakana: 0x30D4,
  11894. pisymbolgreek: 0x03D6,
  11895. piwrarmenian: 0x0583,
  11896. plus: 0x002B,
  11897. plusbelowcmb: 0x031F,
  11898. pluscircle: 0x2295,
  11899. plusminus: 0x00B1,
  11900. plusmod: 0x02D6,
  11901. plusmonospace: 0xFF0B,
  11902. plussmall: 0xFE62,
  11903. plussuperior: 0x207A,
  11904. pmonospace: 0xFF50,
  11905. pmsquare: 0x33D8,
  11906. pohiragana: 0x307D,
  11907. pointingindexdownwhite: 0x261F,
  11908. pointingindexleftwhite: 0x261C,
  11909. pointingindexrightwhite: 0x261E,
  11910. pointingindexupwhite: 0x261D,
  11911. pokatakana: 0x30DD,
  11912. poplathai: 0x0E1B,
  11913. postalmark: 0x3012,
  11914. postalmarkface: 0x3020,
  11915. pparen: 0x24AB,
  11916. precedes: 0x227A,
  11917. prescription: 0x211E,
  11918. primemod: 0x02B9,
  11919. primereversed: 0x2035,
  11920. product: 0x220F,
  11921. projective: 0x2305,
  11922. prolongedkana: 0x30FC,
  11923. propellor: 0x2318,
  11924. propersubset: 0x2282,
  11925. propersuperset: 0x2283,
  11926. proportion: 0x2237,
  11927. proportional: 0x221D,
  11928. psi: 0x03C8,
  11929. psicyrillic: 0x0471,
  11930. psilipneumatacyrilliccmb: 0x0486,
  11931. pssquare: 0x33B0,
  11932. puhiragana: 0x3077,
  11933. pukatakana: 0x30D7,
  11934. pvsquare: 0x33B4,
  11935. pwsquare: 0x33BA,
  11936. q: 0x0071,
  11937. qadeva: 0x0958,
  11938. qadmahebrew: 0x05A8,
  11939. qafarabic: 0x0642,
  11940. qaffinalarabic: 0xFED6,
  11941. qafinitialarabic: 0xFED7,
  11942. qafmedialarabic: 0xFED8,
  11943. qamats: 0x05B8,
  11944. qamats10: 0x05B8,
  11945. qamats1a: 0x05B8,
  11946. qamats1c: 0x05B8,
  11947. qamats27: 0x05B8,
  11948. qamats29: 0x05B8,
  11949. qamats33: 0x05B8,
  11950. qamatsde: 0x05B8,
  11951. qamatshebrew: 0x05B8,
  11952. qamatsnarrowhebrew: 0x05B8,
  11953. qamatsqatanhebrew: 0x05B8,
  11954. qamatsqatannarrowhebrew: 0x05B8,
  11955. qamatsqatanquarterhebrew: 0x05B8,
  11956. qamatsqatanwidehebrew: 0x05B8,
  11957. qamatsquarterhebrew: 0x05B8,
  11958. qamatswidehebrew: 0x05B8,
  11959. qarneyparahebrew: 0x059F,
  11960. qbopomofo: 0x3111,
  11961. qcircle: 0x24E0,
  11962. qhook: 0x02A0,
  11963. qmonospace: 0xFF51,
  11964. qof: 0x05E7,
  11965. qofdagesh: 0xFB47,
  11966. qofdageshhebrew: 0xFB47,
  11967. qofhebrew: 0x05E7,
  11968. qparen: 0x24AC,
  11969. quarternote: 0x2669,
  11970. qubuts: 0x05BB,
  11971. qubuts18: 0x05BB,
  11972. qubuts25: 0x05BB,
  11973. qubuts31: 0x05BB,
  11974. qubutshebrew: 0x05BB,
  11975. qubutsnarrowhebrew: 0x05BB,
  11976. qubutsquarterhebrew: 0x05BB,
  11977. qubutswidehebrew: 0x05BB,
  11978. question: 0x003F,
  11979. questionarabic: 0x061F,
  11980. questionarmenian: 0x055E,
  11981. questiondown: 0x00BF,
  11982. questiondownsmall: 0xF7BF,
  11983. questiongreek: 0x037E,
  11984. questionmonospace: 0xFF1F,
  11985. questionsmall: 0xF73F,
  11986. quotedbl: 0x0022,
  11987. quotedblbase: 0x201E,
  11988. quotedblleft: 0x201C,
  11989. quotedblmonospace: 0xFF02,
  11990. quotedblprime: 0x301E,
  11991. quotedblprimereversed: 0x301D,
  11992. quotedblright: 0x201D,
  11993. quoteleft: 0x2018,
  11994. quoteleftreversed: 0x201B,
  11995. quotereversed: 0x201B,
  11996. quoteright: 0x2019,
  11997. quoterightn: 0x0149,
  11998. quotesinglbase: 0x201A,
  11999. quotesingle: 0x0027,
  12000. quotesinglemonospace: 0xFF07,
  12001. r: 0x0072,
  12002. raarmenian: 0x057C,
  12003. rabengali: 0x09B0,
  12004. racute: 0x0155,
  12005. radeva: 0x0930,
  12006. radical: 0x221A,
  12007. radicalex: 0xF8E5,
  12008. radoverssquare: 0x33AE,
  12009. radoverssquaredsquare: 0x33AF,
  12010. radsquare: 0x33AD,
  12011. rafe: 0x05BF,
  12012. rafehebrew: 0x05BF,
  12013. ragujarati: 0x0AB0,
  12014. ragurmukhi: 0x0A30,
  12015. rahiragana: 0x3089,
  12016. rakatakana: 0x30E9,
  12017. rakatakanahalfwidth: 0xFF97,
  12018. ralowerdiagonalbengali: 0x09F1,
  12019. ramiddlediagonalbengali: 0x09F0,
  12020. ramshorn: 0x0264,
  12021. ratio: 0x2236,
  12022. rbopomofo: 0x3116,
  12023. rcaron: 0x0159,
  12024. rcedilla: 0x0157,
  12025. rcircle: 0x24E1,
  12026. rcommaaccent: 0x0157,
  12027. rdblgrave: 0x0211,
  12028. rdotaccent: 0x1E59,
  12029. rdotbelow: 0x1E5B,
  12030. rdotbelowmacron: 0x1E5D,
  12031. referencemark: 0x203B,
  12032. reflexsubset: 0x2286,
  12033. reflexsuperset: 0x2287,
  12034. registered: 0x00AE,
  12035. registersans: 0xF8E8,
  12036. registerserif: 0xF6DA,
  12037. reharabic: 0x0631,
  12038. reharmenian: 0x0580,
  12039. rehfinalarabic: 0xFEAE,
  12040. rehiragana: 0x308C,
  12041. rekatakana: 0x30EC,
  12042. rekatakanahalfwidth: 0xFF9A,
  12043. resh: 0x05E8,
  12044. reshdageshhebrew: 0xFB48,
  12045. reshhebrew: 0x05E8,
  12046. reversedtilde: 0x223D,
  12047. reviahebrew: 0x0597,
  12048. reviamugrashhebrew: 0x0597,
  12049. revlogicalnot: 0x2310,
  12050. rfishhook: 0x027E,
  12051. rfishhookreversed: 0x027F,
  12052. rhabengali: 0x09DD,
  12053. rhadeva: 0x095D,
  12054. rho: 0x03C1,
  12055. rhook: 0x027D,
  12056. rhookturned: 0x027B,
  12057. rhookturnedsuperior: 0x02B5,
  12058. rhosymbolgreek: 0x03F1,
  12059. rhotichookmod: 0x02DE,
  12060. rieulacirclekorean: 0x3271,
  12061. rieulaparenkorean: 0x3211,
  12062. rieulcirclekorean: 0x3263,
  12063. rieulhieuhkorean: 0x3140,
  12064. rieulkiyeokkorean: 0x313A,
  12065. rieulkiyeoksioskorean: 0x3169,
  12066. rieulkorean: 0x3139,
  12067. rieulmieumkorean: 0x313B,
  12068. rieulpansioskorean: 0x316C,
  12069. rieulparenkorean: 0x3203,
  12070. rieulphieuphkorean: 0x313F,
  12071. rieulpieupkorean: 0x313C,
  12072. rieulpieupsioskorean: 0x316B,
  12073. rieulsioskorean: 0x313D,
  12074. rieulthieuthkorean: 0x313E,
  12075. rieultikeutkorean: 0x316A,
  12076. rieulyeorinhieuhkorean: 0x316D,
  12077. rightangle: 0x221F,
  12078. righttackbelowcmb: 0x0319,
  12079. righttriangle: 0x22BF,
  12080. rihiragana: 0x308A,
  12081. rikatakana: 0x30EA,
  12082. rikatakanahalfwidth: 0xFF98,
  12083. ring: 0x02DA,
  12084. ringbelowcmb: 0x0325,
  12085. ringcmb: 0x030A,
  12086. ringhalfleft: 0x02BF,
  12087. ringhalfleftarmenian: 0x0559,
  12088. ringhalfleftbelowcmb: 0x031C,
  12089. ringhalfleftcentered: 0x02D3,
  12090. ringhalfright: 0x02BE,
  12091. ringhalfrightbelowcmb: 0x0339,
  12092. ringhalfrightcentered: 0x02D2,
  12093. rinvertedbreve: 0x0213,
  12094. rittorusquare: 0x3351,
  12095. rlinebelow: 0x1E5F,
  12096. rlongleg: 0x027C,
  12097. rlonglegturned: 0x027A,
  12098. rmonospace: 0xFF52,
  12099. rohiragana: 0x308D,
  12100. rokatakana: 0x30ED,
  12101. rokatakanahalfwidth: 0xFF9B,
  12102. roruathai: 0x0E23,
  12103. rparen: 0x24AD,
  12104. rrabengali: 0x09DC,
  12105. rradeva: 0x0931,
  12106. rragurmukhi: 0x0A5C,
  12107. rreharabic: 0x0691,
  12108. rrehfinalarabic: 0xFB8D,
  12109. rrvocalicbengali: 0x09E0,
  12110. rrvocalicdeva: 0x0960,
  12111. rrvocalicgujarati: 0x0AE0,
  12112. rrvocalicvowelsignbengali: 0x09C4,
  12113. rrvocalicvowelsigndeva: 0x0944,
  12114. rrvocalicvowelsigngujarati: 0x0AC4,
  12115. rsuperior: 0xF6F1,
  12116. rtblock: 0x2590,
  12117. rturned: 0x0279,
  12118. rturnedsuperior: 0x02B4,
  12119. ruhiragana: 0x308B,
  12120. rukatakana: 0x30EB,
  12121. rukatakanahalfwidth: 0xFF99,
  12122. rupeemarkbengali: 0x09F2,
  12123. rupeesignbengali: 0x09F3,
  12124. rupiah: 0xF6DD,
  12125. ruthai: 0x0E24,
  12126. rvocalicbengali: 0x098B,
  12127. rvocalicdeva: 0x090B,
  12128. rvocalicgujarati: 0x0A8B,
  12129. rvocalicvowelsignbengali: 0x09C3,
  12130. rvocalicvowelsigndeva: 0x0943,
  12131. rvocalicvowelsigngujarati: 0x0AC3,
  12132. s: 0x0073,
  12133. sabengali: 0x09B8,
  12134. sacute: 0x015B,
  12135. sacutedotaccent: 0x1E65,
  12136. sadarabic: 0x0635,
  12137. sadeva: 0x0938,
  12138. sadfinalarabic: 0xFEBA,
  12139. sadinitialarabic: 0xFEBB,
  12140. sadmedialarabic: 0xFEBC,
  12141. sagujarati: 0x0AB8,
  12142. sagurmukhi: 0x0A38,
  12143. sahiragana: 0x3055,
  12144. sakatakana: 0x30B5,
  12145. sakatakanahalfwidth: 0xFF7B,
  12146. sallallahoualayhewasallamarabic: 0xFDFA,
  12147. samekh: 0x05E1,
  12148. samekhdagesh: 0xFB41,
  12149. samekhdageshhebrew: 0xFB41,
  12150. samekhhebrew: 0x05E1,
  12151. saraaathai: 0x0E32,
  12152. saraaethai: 0x0E41,
  12153. saraaimaimalaithai: 0x0E44,
  12154. saraaimaimuanthai: 0x0E43,
  12155. saraamthai: 0x0E33,
  12156. saraathai: 0x0E30,
  12157. saraethai: 0x0E40,
  12158. saraiileftthai: 0xF886,
  12159. saraiithai: 0x0E35,
  12160. saraileftthai: 0xF885,
  12161. saraithai: 0x0E34,
  12162. saraothai: 0x0E42,
  12163. saraueeleftthai: 0xF888,
  12164. saraueethai: 0x0E37,
  12165. saraueleftthai: 0xF887,
  12166. sarauethai: 0x0E36,
  12167. sarauthai: 0x0E38,
  12168. sarauuthai: 0x0E39,
  12169. sbopomofo: 0x3119,
  12170. scaron: 0x0161,
  12171. scarondotaccent: 0x1E67,
  12172. scedilla: 0x015F,
  12173. schwa: 0x0259,
  12174. schwacyrillic: 0x04D9,
  12175. schwadieresiscyrillic: 0x04DB,
  12176. schwahook: 0x025A,
  12177. scircle: 0x24E2,
  12178. scircumflex: 0x015D,
  12179. scommaaccent: 0x0219,
  12180. sdotaccent: 0x1E61,
  12181. sdotbelow: 0x1E63,
  12182. sdotbelowdotaccent: 0x1E69,
  12183. seagullbelowcmb: 0x033C,
  12184. second: 0x2033,
  12185. secondtonechinese: 0x02CA,
  12186. section: 0x00A7,
  12187. seenarabic: 0x0633,
  12188. seenfinalarabic: 0xFEB2,
  12189. seeninitialarabic: 0xFEB3,
  12190. seenmedialarabic: 0xFEB4,
  12191. segol: 0x05B6,
  12192. segol13: 0x05B6,
  12193. segol1f: 0x05B6,
  12194. segol2c: 0x05B6,
  12195. segolhebrew: 0x05B6,
  12196. segolnarrowhebrew: 0x05B6,
  12197. segolquarterhebrew: 0x05B6,
  12198. segoltahebrew: 0x0592,
  12199. segolwidehebrew: 0x05B6,
  12200. seharmenian: 0x057D,
  12201. sehiragana: 0x305B,
  12202. sekatakana: 0x30BB,
  12203. sekatakanahalfwidth: 0xFF7E,
  12204. semicolon: 0x003B,
  12205. semicolonarabic: 0x061B,
  12206. semicolonmonospace: 0xFF1B,
  12207. semicolonsmall: 0xFE54,
  12208. semivoicedmarkkana: 0x309C,
  12209. semivoicedmarkkanahalfwidth: 0xFF9F,
  12210. sentisquare: 0x3322,
  12211. sentosquare: 0x3323,
  12212. seven: 0x0037,
  12213. sevenarabic: 0x0667,
  12214. sevenbengali: 0x09ED,
  12215. sevencircle: 0x2466,
  12216. sevencircleinversesansserif: 0x2790,
  12217. sevendeva: 0x096D,
  12218. seveneighths: 0x215E,
  12219. sevengujarati: 0x0AED,
  12220. sevengurmukhi: 0x0A6D,
  12221. sevenhackarabic: 0x0667,
  12222. sevenhangzhou: 0x3027,
  12223. sevenideographicparen: 0x3226,
  12224. seveninferior: 0x2087,
  12225. sevenmonospace: 0xFF17,
  12226. sevenoldstyle: 0xF737,
  12227. sevenparen: 0x247A,
  12228. sevenperiod: 0x248E,
  12229. sevenpersian: 0x06F7,
  12230. sevenroman: 0x2176,
  12231. sevensuperior: 0x2077,
  12232. seventeencircle: 0x2470,
  12233. seventeenparen: 0x2484,
  12234. seventeenperiod: 0x2498,
  12235. seventhai: 0x0E57,
  12236. sfthyphen: 0x00AD,
  12237. shaarmenian: 0x0577,
  12238. shabengali: 0x09B6,
  12239. shacyrillic: 0x0448,
  12240. shaddaarabic: 0x0651,
  12241. shaddadammaarabic: 0xFC61,
  12242. shaddadammatanarabic: 0xFC5E,
  12243. shaddafathaarabic: 0xFC60,
  12244. shaddakasraarabic: 0xFC62,
  12245. shaddakasratanarabic: 0xFC5F,
  12246. shade: 0x2592,
  12247. shadedark: 0x2593,
  12248. shadelight: 0x2591,
  12249. shademedium: 0x2592,
  12250. shadeva: 0x0936,
  12251. shagujarati: 0x0AB6,
  12252. shagurmukhi: 0x0A36,
  12253. shalshelethebrew: 0x0593,
  12254. shbopomofo: 0x3115,
  12255. shchacyrillic: 0x0449,
  12256. sheenarabic: 0x0634,
  12257. sheenfinalarabic: 0xFEB6,
  12258. sheeninitialarabic: 0xFEB7,
  12259. sheenmedialarabic: 0xFEB8,
  12260. sheicoptic: 0x03E3,
  12261. sheqel: 0x20AA,
  12262. sheqelhebrew: 0x20AA,
  12263. sheva: 0x05B0,
  12264. sheva115: 0x05B0,
  12265. sheva15: 0x05B0,
  12266. sheva22: 0x05B0,
  12267. sheva2e: 0x05B0,
  12268. shevahebrew: 0x05B0,
  12269. shevanarrowhebrew: 0x05B0,
  12270. shevaquarterhebrew: 0x05B0,
  12271. shevawidehebrew: 0x05B0,
  12272. shhacyrillic: 0x04BB,
  12273. shimacoptic: 0x03ED,
  12274. shin: 0x05E9,
  12275. shindagesh: 0xFB49,
  12276. shindageshhebrew: 0xFB49,
  12277. shindageshshindot: 0xFB2C,
  12278. shindageshshindothebrew: 0xFB2C,
  12279. shindageshsindot: 0xFB2D,
  12280. shindageshsindothebrew: 0xFB2D,
  12281. shindothebrew: 0x05C1,
  12282. shinhebrew: 0x05E9,
  12283. shinshindot: 0xFB2A,
  12284. shinshindothebrew: 0xFB2A,
  12285. shinsindot: 0xFB2B,
  12286. shinsindothebrew: 0xFB2B,
  12287. shook: 0x0282,
  12288. sigma: 0x03C3,
  12289. sigma1: 0x03C2,
  12290. sigmafinal: 0x03C2,
  12291. sigmalunatesymbolgreek: 0x03F2,
  12292. sihiragana: 0x3057,
  12293. sikatakana: 0x30B7,
  12294. sikatakanahalfwidth: 0xFF7C,
  12295. siluqhebrew: 0x05BD,
  12296. siluqlefthebrew: 0x05BD,
  12297. similar: 0x223C,
  12298. sindothebrew: 0x05C2,
  12299. siosacirclekorean: 0x3274,
  12300. siosaparenkorean: 0x3214,
  12301. sioscieuckorean: 0x317E,
  12302. sioscirclekorean: 0x3266,
  12303. sioskiyeokkorean: 0x317A,
  12304. sioskorean: 0x3145,
  12305. siosnieunkorean: 0x317B,
  12306. siosparenkorean: 0x3206,
  12307. siospieupkorean: 0x317D,
  12308. siostikeutkorean: 0x317C,
  12309. six: 0x0036,
  12310. sixarabic: 0x0666,
  12311. sixbengali: 0x09EC,
  12312. sixcircle: 0x2465,
  12313. sixcircleinversesansserif: 0x278F,
  12314. sixdeva: 0x096C,
  12315. sixgujarati: 0x0AEC,
  12316. sixgurmukhi: 0x0A6C,
  12317. sixhackarabic: 0x0666,
  12318. sixhangzhou: 0x3026,
  12319. sixideographicparen: 0x3225,
  12320. sixinferior: 0x2086,
  12321. sixmonospace: 0xFF16,
  12322. sixoldstyle: 0xF736,
  12323. sixparen: 0x2479,
  12324. sixperiod: 0x248D,
  12325. sixpersian: 0x06F6,
  12326. sixroman: 0x2175,
  12327. sixsuperior: 0x2076,
  12328. sixteencircle: 0x246F,
  12329. sixteencurrencydenominatorbengali: 0x09F9,
  12330. sixteenparen: 0x2483,
  12331. sixteenperiod: 0x2497,
  12332. sixthai: 0x0E56,
  12333. slash: 0x002F,
  12334. slashmonospace: 0xFF0F,
  12335. slong: 0x017F,
  12336. slongdotaccent: 0x1E9B,
  12337. smileface: 0x263A,
  12338. smonospace: 0xFF53,
  12339. sofpasuqhebrew: 0x05C3,
  12340. softhyphen: 0x00AD,
  12341. softsigncyrillic: 0x044C,
  12342. sohiragana: 0x305D,
  12343. sokatakana: 0x30BD,
  12344. sokatakanahalfwidth: 0xFF7F,
  12345. soliduslongoverlaycmb: 0x0338,
  12346. solidusshortoverlaycmb: 0x0337,
  12347. sorusithai: 0x0E29,
  12348. sosalathai: 0x0E28,
  12349. sosothai: 0x0E0B,
  12350. sosuathai: 0x0E2A,
  12351. space: 0x0020,
  12352. spacehackarabic: 0x0020,
  12353. spade: 0x2660,
  12354. spadesuitblack: 0x2660,
  12355. spadesuitwhite: 0x2664,
  12356. sparen: 0x24AE,
  12357. squarebelowcmb: 0x033B,
  12358. squarecc: 0x33C4,
  12359. squarecm: 0x339D,
  12360. squarediagonalcrosshatchfill: 0x25A9,
  12361. squarehorizontalfill: 0x25A4,
  12362. squarekg: 0x338F,
  12363. squarekm: 0x339E,
  12364. squarekmcapital: 0x33CE,
  12365. squareln: 0x33D1,
  12366. squarelog: 0x33D2,
  12367. squaremg: 0x338E,
  12368. squaremil: 0x33D5,
  12369. squaremm: 0x339C,
  12370. squaremsquared: 0x33A1,
  12371. squareorthogonalcrosshatchfill: 0x25A6,
  12372. squareupperlefttolowerrightfill: 0x25A7,
  12373. squareupperrighttolowerleftfill: 0x25A8,
  12374. squareverticalfill: 0x25A5,
  12375. squarewhitewithsmallblack: 0x25A3,
  12376. srsquare: 0x33DB,
  12377. ssabengali: 0x09B7,
  12378. ssadeva: 0x0937,
  12379. ssagujarati: 0x0AB7,
  12380. ssangcieuckorean: 0x3149,
  12381. ssanghieuhkorean: 0x3185,
  12382. ssangieungkorean: 0x3180,
  12383. ssangkiyeokkorean: 0x3132,
  12384. ssangnieunkorean: 0x3165,
  12385. ssangpieupkorean: 0x3143,
  12386. ssangsioskorean: 0x3146,
  12387. ssangtikeutkorean: 0x3138,
  12388. ssuperior: 0xF6F2,
  12389. sterling: 0x00A3,
  12390. sterlingmonospace: 0xFFE1,
  12391. strokelongoverlaycmb: 0x0336,
  12392. strokeshortoverlaycmb: 0x0335,
  12393. subset: 0x2282,
  12394. subsetnotequal: 0x228A,
  12395. subsetorequal: 0x2286,
  12396. succeeds: 0x227B,
  12397. suchthat: 0x220B,
  12398. suhiragana: 0x3059,
  12399. sukatakana: 0x30B9,
  12400. sukatakanahalfwidth: 0xFF7D,
  12401. sukunarabic: 0x0652,
  12402. summation: 0x2211,
  12403. sun: 0x263C,
  12404. superset: 0x2283,
  12405. supersetnotequal: 0x228B,
  12406. supersetorequal: 0x2287,
  12407. svsquare: 0x33DC,
  12408. syouwaerasquare: 0x337C,
  12409. t: 0x0074,
  12410. tabengali: 0x09A4,
  12411. tackdown: 0x22A4,
  12412. tackleft: 0x22A3,
  12413. tadeva: 0x0924,
  12414. tagujarati: 0x0AA4,
  12415. tagurmukhi: 0x0A24,
  12416. taharabic: 0x0637,
  12417. tahfinalarabic: 0xFEC2,
  12418. tahinitialarabic: 0xFEC3,
  12419. tahiragana: 0x305F,
  12420. tahmedialarabic: 0xFEC4,
  12421. taisyouerasquare: 0x337D,
  12422. takatakana: 0x30BF,
  12423. takatakanahalfwidth: 0xFF80,
  12424. tatweelarabic: 0x0640,
  12425. tau: 0x03C4,
  12426. tav: 0x05EA,
  12427. tavdages: 0xFB4A,
  12428. tavdagesh: 0xFB4A,
  12429. tavdageshhebrew: 0xFB4A,
  12430. tavhebrew: 0x05EA,
  12431. tbar: 0x0167,
  12432. tbopomofo: 0x310A,
  12433. tcaron: 0x0165,
  12434. tccurl: 0x02A8,
  12435. tcedilla: 0x0163,
  12436. tcheharabic: 0x0686,
  12437. tchehfinalarabic: 0xFB7B,
  12438. tchehinitialarabic: 0xFB7C,
  12439. tchehmedialarabic: 0xFB7D,
  12440. tcircle: 0x24E3,
  12441. tcircumflexbelow: 0x1E71,
  12442. tcommaaccent: 0x0163,
  12443. tdieresis: 0x1E97,
  12444. tdotaccent: 0x1E6B,
  12445. tdotbelow: 0x1E6D,
  12446. tecyrillic: 0x0442,
  12447. tedescendercyrillic: 0x04AD,
  12448. teharabic: 0x062A,
  12449. tehfinalarabic: 0xFE96,
  12450. tehhahinitialarabic: 0xFCA2,
  12451. tehhahisolatedarabic: 0xFC0C,
  12452. tehinitialarabic: 0xFE97,
  12453. tehiragana: 0x3066,
  12454. tehjeeminitialarabic: 0xFCA1,
  12455. tehjeemisolatedarabic: 0xFC0B,
  12456. tehmarbutaarabic: 0x0629,
  12457. tehmarbutafinalarabic: 0xFE94,
  12458. tehmedialarabic: 0xFE98,
  12459. tehmeeminitialarabic: 0xFCA4,
  12460. tehmeemisolatedarabic: 0xFC0E,
  12461. tehnoonfinalarabic: 0xFC73,
  12462. tekatakana: 0x30C6,
  12463. tekatakanahalfwidth: 0xFF83,
  12464. telephone: 0x2121,
  12465. telephoneblack: 0x260E,
  12466. telishagedolahebrew: 0x05A0,
  12467. telishaqetanahebrew: 0x05A9,
  12468. tencircle: 0x2469,
  12469. tenideographicparen: 0x3229,
  12470. tenparen: 0x247D,
  12471. tenperiod: 0x2491,
  12472. tenroman: 0x2179,
  12473. tesh: 0x02A7,
  12474. tet: 0x05D8,
  12475. tetdagesh: 0xFB38,
  12476. tetdageshhebrew: 0xFB38,
  12477. tethebrew: 0x05D8,
  12478. tetsecyrillic: 0x04B5,
  12479. tevirhebrew: 0x059B,
  12480. tevirlefthebrew: 0x059B,
  12481. thabengali: 0x09A5,
  12482. thadeva: 0x0925,
  12483. thagujarati: 0x0AA5,
  12484. thagurmukhi: 0x0A25,
  12485. thalarabic: 0x0630,
  12486. thalfinalarabic: 0xFEAC,
  12487. thanthakhatlowleftthai: 0xF898,
  12488. thanthakhatlowrightthai: 0xF897,
  12489. thanthakhatthai: 0x0E4C,
  12490. thanthakhatupperleftthai: 0xF896,
  12491. theharabic: 0x062B,
  12492. thehfinalarabic: 0xFE9A,
  12493. thehinitialarabic: 0xFE9B,
  12494. thehmedialarabic: 0xFE9C,
  12495. thereexists: 0x2203,
  12496. therefore: 0x2234,
  12497. theta: 0x03B8,
  12498. theta1: 0x03D1,
  12499. thetasymbolgreek: 0x03D1,
  12500. thieuthacirclekorean: 0x3279,
  12501. thieuthaparenkorean: 0x3219,
  12502. thieuthcirclekorean: 0x326B,
  12503. thieuthkorean: 0x314C,
  12504. thieuthparenkorean: 0x320B,
  12505. thirteencircle: 0x246C,
  12506. thirteenparen: 0x2480,
  12507. thirteenperiod: 0x2494,
  12508. thonangmonthothai: 0x0E11,
  12509. thook: 0x01AD,
  12510. thophuthaothai: 0x0E12,
  12511. thorn: 0x00FE,
  12512. thothahanthai: 0x0E17,
  12513. thothanthai: 0x0E10,
  12514. thothongthai: 0x0E18,
  12515. thothungthai: 0x0E16,
  12516. thousandcyrillic: 0x0482,
  12517. thousandsseparatorarabic: 0x066C,
  12518. thousandsseparatorpersian: 0x066C,
  12519. three: 0x0033,
  12520. threearabic: 0x0663,
  12521. threebengali: 0x09E9,
  12522. threecircle: 0x2462,
  12523. threecircleinversesansserif: 0x278C,
  12524. threedeva: 0x0969,
  12525. threeeighths: 0x215C,
  12526. threegujarati: 0x0AE9,
  12527. threegurmukhi: 0x0A69,
  12528. threehackarabic: 0x0663,
  12529. threehangzhou: 0x3023,
  12530. threeideographicparen: 0x3222,
  12531. threeinferior: 0x2083,
  12532. threemonospace: 0xFF13,
  12533. threenumeratorbengali: 0x09F6,
  12534. threeoldstyle: 0xF733,
  12535. threeparen: 0x2476,
  12536. threeperiod: 0x248A,
  12537. threepersian: 0x06F3,
  12538. threequarters: 0x00BE,
  12539. threequartersemdash: 0xF6DE,
  12540. threeroman: 0x2172,
  12541. threesuperior: 0x00B3,
  12542. threethai: 0x0E53,
  12543. thzsquare: 0x3394,
  12544. tihiragana: 0x3061,
  12545. tikatakana: 0x30C1,
  12546. tikatakanahalfwidth: 0xFF81,
  12547. tikeutacirclekorean: 0x3270,
  12548. tikeutaparenkorean: 0x3210,
  12549. tikeutcirclekorean: 0x3262,
  12550. tikeutkorean: 0x3137,
  12551. tikeutparenkorean: 0x3202,
  12552. tilde: 0x02DC,
  12553. tildebelowcmb: 0x0330,
  12554. tildecmb: 0x0303,
  12555. tildecomb: 0x0303,
  12556. tildedoublecmb: 0x0360,
  12557. tildeoperator: 0x223C,
  12558. tildeoverlaycmb: 0x0334,
  12559. tildeverticalcmb: 0x033E,
  12560. timescircle: 0x2297,
  12561. tipehahebrew: 0x0596,
  12562. tipehalefthebrew: 0x0596,
  12563. tippigurmukhi: 0x0A70,
  12564. titlocyrilliccmb: 0x0483,
  12565. tiwnarmenian: 0x057F,
  12566. tlinebelow: 0x1E6F,
  12567. tmonospace: 0xFF54,
  12568. toarmenian: 0x0569,
  12569. tohiragana: 0x3068,
  12570. tokatakana: 0x30C8,
  12571. tokatakanahalfwidth: 0xFF84,
  12572. tonebarextrahighmod: 0x02E5,
  12573. tonebarextralowmod: 0x02E9,
  12574. tonebarhighmod: 0x02E6,
  12575. tonebarlowmod: 0x02E8,
  12576. tonebarmidmod: 0x02E7,
  12577. tonefive: 0x01BD,
  12578. tonesix: 0x0185,
  12579. tonetwo: 0x01A8,
  12580. tonos: 0x0384,
  12581. tonsquare: 0x3327,
  12582. topatakthai: 0x0E0F,
  12583. tortoiseshellbracketleft: 0x3014,
  12584. tortoiseshellbracketleftsmall: 0xFE5D,
  12585. tortoiseshellbracketleftvertical: 0xFE39,
  12586. tortoiseshellbracketright: 0x3015,
  12587. tortoiseshellbracketrightsmall: 0xFE5E,
  12588. tortoiseshellbracketrightvertical: 0xFE3A,
  12589. totaothai: 0x0E15,
  12590. tpalatalhook: 0x01AB,
  12591. tparen: 0x24AF,
  12592. trademark: 0x2122,
  12593. trademarksans: 0xF8EA,
  12594. trademarkserif: 0xF6DB,
  12595. tretroflexhook: 0x0288,
  12596. triagdn: 0x25BC,
  12597. triaglf: 0x25C4,
  12598. triagrt: 0x25BA,
  12599. triagup: 0x25B2,
  12600. ts: 0x02A6,
  12601. tsadi: 0x05E6,
  12602. tsadidagesh: 0xFB46,
  12603. tsadidageshhebrew: 0xFB46,
  12604. tsadihebrew: 0x05E6,
  12605. tsecyrillic: 0x0446,
  12606. tsere: 0x05B5,
  12607. tsere12: 0x05B5,
  12608. tsere1e: 0x05B5,
  12609. tsere2b: 0x05B5,
  12610. tserehebrew: 0x05B5,
  12611. tserenarrowhebrew: 0x05B5,
  12612. tserequarterhebrew: 0x05B5,
  12613. tserewidehebrew: 0x05B5,
  12614. tshecyrillic: 0x045B,
  12615. tsuperior: 0xF6F3,
  12616. ttabengali: 0x099F,
  12617. ttadeva: 0x091F,
  12618. ttagujarati: 0x0A9F,
  12619. ttagurmukhi: 0x0A1F,
  12620. tteharabic: 0x0679,
  12621. ttehfinalarabic: 0xFB67,
  12622. ttehinitialarabic: 0xFB68,
  12623. ttehmedialarabic: 0xFB69,
  12624. tthabengali: 0x09A0,
  12625. tthadeva: 0x0920,
  12626. tthagujarati: 0x0AA0,
  12627. tthagurmukhi: 0x0A20,
  12628. tturned: 0x0287,
  12629. tuhiragana: 0x3064,
  12630. tukatakana: 0x30C4,
  12631. tukatakanahalfwidth: 0xFF82,
  12632. tusmallhiragana: 0x3063,
  12633. tusmallkatakana: 0x30C3,
  12634. tusmallkatakanahalfwidth: 0xFF6F,
  12635. twelvecircle: 0x246B,
  12636. twelveparen: 0x247F,
  12637. twelveperiod: 0x2493,
  12638. twelveroman: 0x217B,
  12639. twentycircle: 0x2473,
  12640. twentyhangzhou: 0x5344,
  12641. twentyparen: 0x2487,
  12642. twentyperiod: 0x249B,
  12643. two: 0x0032,
  12644. twoarabic: 0x0662,
  12645. twobengali: 0x09E8,
  12646. twocircle: 0x2461,
  12647. twocircleinversesansserif: 0x278B,
  12648. twodeva: 0x0968,
  12649. twodotenleader: 0x2025,
  12650. twodotleader: 0x2025,
  12651. twodotleadervertical: 0xFE30,
  12652. twogujarati: 0x0AE8,
  12653. twogurmukhi: 0x0A68,
  12654. twohackarabic: 0x0662,
  12655. twohangzhou: 0x3022,
  12656. twoideographicparen: 0x3221,
  12657. twoinferior: 0x2082,
  12658. twomonospace: 0xFF12,
  12659. twonumeratorbengali: 0x09F5,
  12660. twooldstyle: 0xF732,
  12661. twoparen: 0x2475,
  12662. twoperiod: 0x2489,
  12663. twopersian: 0x06F2,
  12664. tworoman: 0x2171,
  12665. twostroke: 0x01BB,
  12666. twosuperior: 0x00B2,
  12667. twothai: 0x0E52,
  12668. twothirds: 0x2154,
  12669. u: 0x0075,
  12670. uacute: 0x00FA,
  12671. ubar: 0x0289,
  12672. ubengali: 0x0989,
  12673. ubopomofo: 0x3128,
  12674. ubreve: 0x016D,
  12675. ucaron: 0x01D4,
  12676. ucircle: 0x24E4,
  12677. ucircumflex: 0x00FB,
  12678. ucircumflexbelow: 0x1E77,
  12679. ucyrillic: 0x0443,
  12680. udattadeva: 0x0951,
  12681. udblacute: 0x0171,
  12682. udblgrave: 0x0215,
  12683. udeva: 0x0909,
  12684. udieresis: 0x00FC,
  12685. udieresisacute: 0x01D8,
  12686. udieresisbelow: 0x1E73,
  12687. udieresiscaron: 0x01DA,
  12688. udieresiscyrillic: 0x04F1,
  12689. udieresisgrave: 0x01DC,
  12690. udieresismacron: 0x01D6,
  12691. udotbelow: 0x1EE5,
  12692. ugrave: 0x00F9,
  12693. ugujarati: 0x0A89,
  12694. ugurmukhi: 0x0A09,
  12695. uhiragana: 0x3046,
  12696. uhookabove: 0x1EE7,
  12697. uhorn: 0x01B0,
  12698. uhornacute: 0x1EE9,
  12699. uhorndotbelow: 0x1EF1,
  12700. uhorngrave: 0x1EEB,
  12701. uhornhookabove: 0x1EED,
  12702. uhorntilde: 0x1EEF,
  12703. uhungarumlaut: 0x0171,
  12704. uhungarumlautcyrillic: 0x04F3,
  12705. uinvertedbreve: 0x0217,
  12706. ukatakana: 0x30A6,
  12707. ukatakanahalfwidth: 0xFF73,
  12708. ukcyrillic: 0x0479,
  12709. ukorean: 0x315C,
  12710. umacron: 0x016B,
  12711. umacroncyrillic: 0x04EF,
  12712. umacrondieresis: 0x1E7B,
  12713. umatragurmukhi: 0x0A41,
  12714. umonospace: 0xFF55,
  12715. underscore: 0x005F,
  12716. underscoredbl: 0x2017,
  12717. underscoremonospace: 0xFF3F,
  12718. underscorevertical: 0xFE33,
  12719. underscorewavy: 0xFE4F,
  12720. union: 0x222A,
  12721. universal: 0x2200,
  12722. uogonek: 0x0173,
  12723. uparen: 0x24B0,
  12724. upblock: 0x2580,
  12725. upperdothebrew: 0x05C4,
  12726. upsilon: 0x03C5,
  12727. upsilondieresis: 0x03CB,
  12728. upsilondieresistonos: 0x03B0,
  12729. upsilonlatin: 0x028A,
  12730. upsilontonos: 0x03CD,
  12731. uptackbelowcmb: 0x031D,
  12732. uptackmod: 0x02D4,
  12733. uragurmukhi: 0x0A73,
  12734. uring: 0x016F,
  12735. ushortcyrillic: 0x045E,
  12736. usmallhiragana: 0x3045,
  12737. usmallkatakana: 0x30A5,
  12738. usmallkatakanahalfwidth: 0xFF69,
  12739. ustraightcyrillic: 0x04AF,
  12740. ustraightstrokecyrillic: 0x04B1,
  12741. utilde: 0x0169,
  12742. utildeacute: 0x1E79,
  12743. utildebelow: 0x1E75,
  12744. uubengali: 0x098A,
  12745. uudeva: 0x090A,
  12746. uugujarati: 0x0A8A,
  12747. uugurmukhi: 0x0A0A,
  12748. uumatragurmukhi: 0x0A42,
  12749. uuvowelsignbengali: 0x09C2,
  12750. uuvowelsigndeva: 0x0942,
  12751. uuvowelsigngujarati: 0x0AC2,
  12752. uvowelsignbengali: 0x09C1,
  12753. uvowelsigndeva: 0x0941,
  12754. uvowelsigngujarati: 0x0AC1,
  12755. v: 0x0076,
  12756. vadeva: 0x0935,
  12757. vagujarati: 0x0AB5,
  12758. vagurmukhi: 0x0A35,
  12759. vakatakana: 0x30F7,
  12760. vav: 0x05D5,
  12761. vavdagesh: 0xFB35,
  12762. vavdagesh65: 0xFB35,
  12763. vavdageshhebrew: 0xFB35,
  12764. vavhebrew: 0x05D5,
  12765. vavholam: 0xFB4B,
  12766. vavholamhebrew: 0xFB4B,
  12767. vavvavhebrew: 0x05F0,
  12768. vavyodhebrew: 0x05F1,
  12769. vcircle: 0x24E5,
  12770. vdotbelow: 0x1E7F,
  12771. vecyrillic: 0x0432,
  12772. veharabic: 0x06A4,
  12773. vehfinalarabic: 0xFB6B,
  12774. vehinitialarabic: 0xFB6C,
  12775. vehmedialarabic: 0xFB6D,
  12776. vekatakana: 0x30F9,
  12777. venus: 0x2640,
  12778. verticalbar: 0x007C,
  12779. verticallineabovecmb: 0x030D,
  12780. verticallinebelowcmb: 0x0329,
  12781. verticallinelowmod: 0x02CC,
  12782. verticallinemod: 0x02C8,
  12783. vewarmenian: 0x057E,
  12784. vhook: 0x028B,
  12785. vikatakana: 0x30F8,
  12786. viramabengali: 0x09CD,
  12787. viramadeva: 0x094D,
  12788. viramagujarati: 0x0ACD,
  12789. visargabengali: 0x0983,
  12790. visargadeva: 0x0903,
  12791. visargagujarati: 0x0A83,
  12792. vmonospace: 0xFF56,
  12793. voarmenian: 0x0578,
  12794. voicediterationhiragana: 0x309E,
  12795. voicediterationkatakana: 0x30FE,
  12796. voicedmarkkana: 0x309B,
  12797. voicedmarkkanahalfwidth: 0xFF9E,
  12798. vokatakana: 0x30FA,
  12799. vparen: 0x24B1,
  12800. vtilde: 0x1E7D,
  12801. vturned: 0x028C,
  12802. vuhiragana: 0x3094,
  12803. vukatakana: 0x30F4,
  12804. w: 0x0077,
  12805. wacute: 0x1E83,
  12806. waekorean: 0x3159,
  12807. wahiragana: 0x308F,
  12808. wakatakana: 0x30EF,
  12809. wakatakanahalfwidth: 0xFF9C,
  12810. wakorean: 0x3158,
  12811. wasmallhiragana: 0x308E,
  12812. wasmallkatakana: 0x30EE,
  12813. wattosquare: 0x3357,
  12814. wavedash: 0x301C,
  12815. wavyunderscorevertical: 0xFE34,
  12816. wawarabic: 0x0648,
  12817. wawfinalarabic: 0xFEEE,
  12818. wawhamzaabovearabic: 0x0624,
  12819. wawhamzaabovefinalarabic: 0xFE86,
  12820. wbsquare: 0x33DD,
  12821. wcircle: 0x24E6,
  12822. wcircumflex: 0x0175,
  12823. wdieresis: 0x1E85,
  12824. wdotaccent: 0x1E87,
  12825. wdotbelow: 0x1E89,
  12826. wehiragana: 0x3091,
  12827. weierstrass: 0x2118,
  12828. wekatakana: 0x30F1,
  12829. wekorean: 0x315E,
  12830. weokorean: 0x315D,
  12831. wgrave: 0x1E81,
  12832. whitebullet: 0x25E6,
  12833. whitecircle: 0x25CB,
  12834. whitecircleinverse: 0x25D9,
  12835. whitecornerbracketleft: 0x300E,
  12836. whitecornerbracketleftvertical: 0xFE43,
  12837. whitecornerbracketright: 0x300F,
  12838. whitecornerbracketrightvertical: 0xFE44,
  12839. whitediamond: 0x25C7,
  12840. whitediamondcontainingblacksmalldiamond: 0x25C8,
  12841. whitedownpointingsmalltriangle: 0x25BF,
  12842. whitedownpointingtriangle: 0x25BD,
  12843. whiteleftpointingsmalltriangle: 0x25C3,
  12844. whiteleftpointingtriangle: 0x25C1,
  12845. whitelenticularbracketleft: 0x3016,
  12846. whitelenticularbracketright: 0x3017,
  12847. whiterightpointingsmalltriangle: 0x25B9,
  12848. whiterightpointingtriangle: 0x25B7,
  12849. whitesmallsquare: 0x25AB,
  12850. whitesmilingface: 0x263A,
  12851. whitesquare: 0x25A1,
  12852. whitestar: 0x2606,
  12853. whitetelephone: 0x260F,
  12854. whitetortoiseshellbracketleft: 0x3018,
  12855. whitetortoiseshellbracketright: 0x3019,
  12856. whiteuppointingsmalltriangle: 0x25B5,
  12857. whiteuppointingtriangle: 0x25B3,
  12858. wihiragana: 0x3090,
  12859. wikatakana: 0x30F0,
  12860. wikorean: 0x315F,
  12861. wmonospace: 0xFF57,
  12862. wohiragana: 0x3092,
  12863. wokatakana: 0x30F2,
  12864. wokatakanahalfwidth: 0xFF66,
  12865. won: 0x20A9,
  12866. wonmonospace: 0xFFE6,
  12867. wowaenthai: 0x0E27,
  12868. wparen: 0x24B2,
  12869. wring: 0x1E98,
  12870. wsuperior: 0x02B7,
  12871. wturned: 0x028D,
  12872. wynn: 0x01BF,
  12873. x: 0x0078,
  12874. xabovecmb: 0x033D,
  12875. xbopomofo: 0x3112,
  12876. xcircle: 0x24E7,
  12877. xdieresis: 0x1E8D,
  12878. xdotaccent: 0x1E8B,
  12879. xeharmenian: 0x056D,
  12880. xi: 0x03BE,
  12881. xmonospace: 0xFF58,
  12882. xparen: 0x24B3,
  12883. xsuperior: 0x02E3,
  12884. y: 0x0079,
  12885. yaadosquare: 0x334E,
  12886. yabengali: 0x09AF,
  12887. yacute: 0x00FD,
  12888. yadeva: 0x092F,
  12889. yaekorean: 0x3152,
  12890. yagujarati: 0x0AAF,
  12891. yagurmukhi: 0x0A2F,
  12892. yahiragana: 0x3084,
  12893. yakatakana: 0x30E4,
  12894. yakatakanahalfwidth: 0xFF94,
  12895. yakorean: 0x3151,
  12896. yamakkanthai: 0x0E4E,
  12897. yasmallhiragana: 0x3083,
  12898. yasmallkatakana: 0x30E3,
  12899. yasmallkatakanahalfwidth: 0xFF6C,
  12900. yatcyrillic: 0x0463,
  12901. ycircle: 0x24E8,
  12902. ycircumflex: 0x0177,
  12903. ydieresis: 0x00FF,
  12904. ydotaccent: 0x1E8F,
  12905. ydotbelow: 0x1EF5,
  12906. yeharabic: 0x064A,
  12907. yehbarreearabic: 0x06D2,
  12908. yehbarreefinalarabic: 0xFBAF,
  12909. yehfinalarabic: 0xFEF2,
  12910. yehhamzaabovearabic: 0x0626,
  12911. yehhamzaabovefinalarabic: 0xFE8A,
  12912. yehhamzaaboveinitialarabic: 0xFE8B,
  12913. yehhamzaabovemedialarabic: 0xFE8C,
  12914. yehinitialarabic: 0xFEF3,
  12915. yehmedialarabic: 0xFEF4,
  12916. yehmeeminitialarabic: 0xFCDD,
  12917. yehmeemisolatedarabic: 0xFC58,
  12918. yehnoonfinalarabic: 0xFC94,
  12919. yehthreedotsbelowarabic: 0x06D1,
  12920. yekorean: 0x3156,
  12921. yen: 0x00A5,
  12922. yenmonospace: 0xFFE5,
  12923. yeokorean: 0x3155,
  12924. yeorinhieuhkorean: 0x3186,
  12925. yerahbenyomohebrew: 0x05AA,
  12926. yerahbenyomolefthebrew: 0x05AA,
  12927. yericyrillic: 0x044B,
  12928. yerudieresiscyrillic: 0x04F9,
  12929. yesieungkorean: 0x3181,
  12930. yesieungpansioskorean: 0x3183,
  12931. yesieungsioskorean: 0x3182,
  12932. yetivhebrew: 0x059A,
  12933. ygrave: 0x1EF3,
  12934. yhook: 0x01B4,
  12935. yhookabove: 0x1EF7,
  12936. yiarmenian: 0x0575,
  12937. yicyrillic: 0x0457,
  12938. yikorean: 0x3162,
  12939. yinyang: 0x262F,
  12940. yiwnarmenian: 0x0582,
  12941. ymonospace: 0xFF59,
  12942. yod: 0x05D9,
  12943. yoddagesh: 0xFB39,
  12944. yoddageshhebrew: 0xFB39,
  12945. yodhebrew: 0x05D9,
  12946. yodyodhebrew: 0x05F2,
  12947. yodyodpatahhebrew: 0xFB1F,
  12948. yohiragana: 0x3088,
  12949. yoikorean: 0x3189,
  12950. yokatakana: 0x30E8,
  12951. yokatakanahalfwidth: 0xFF96,
  12952. yokorean: 0x315B,
  12953. yosmallhiragana: 0x3087,
  12954. yosmallkatakana: 0x30E7,
  12955. yosmallkatakanahalfwidth: 0xFF6E,
  12956. yotgreek: 0x03F3,
  12957. yoyaekorean: 0x3188,
  12958. yoyakorean: 0x3187,
  12959. yoyakthai: 0x0E22,
  12960. yoyingthai: 0x0E0D,
  12961. yparen: 0x24B4,
  12962. ypogegrammeni: 0x037A,
  12963. ypogegrammenigreekcmb: 0x0345,
  12964. yr: 0x01A6,
  12965. yring: 0x1E99,
  12966. ysuperior: 0x02B8,
  12967. ytilde: 0x1EF9,
  12968. yturned: 0x028E,
  12969. yuhiragana: 0x3086,
  12970. yuikorean: 0x318C,
  12971. yukatakana: 0x30E6,
  12972. yukatakanahalfwidth: 0xFF95,
  12973. yukorean: 0x3160,
  12974. yusbigcyrillic: 0x046B,
  12975. yusbigiotifiedcyrillic: 0x046D,
  12976. yuslittlecyrillic: 0x0467,
  12977. yuslittleiotifiedcyrillic: 0x0469,
  12978. yusmallhiragana: 0x3085,
  12979. yusmallkatakana: 0x30E5,
  12980. yusmallkatakanahalfwidth: 0xFF6D,
  12981. yuyekorean: 0x318B,
  12982. yuyeokorean: 0x318A,
  12983. yyabengali: 0x09DF,
  12984. yyadeva: 0x095F,
  12985. z: 0x007A,
  12986. zaarmenian: 0x0566,
  12987. zacute: 0x017A,
  12988. zadeva: 0x095B,
  12989. zagurmukhi: 0x0A5B,
  12990. zaharabic: 0x0638,
  12991. zahfinalarabic: 0xFEC6,
  12992. zahinitialarabic: 0xFEC7,
  12993. zahiragana: 0x3056,
  12994. zahmedialarabic: 0xFEC8,
  12995. zainarabic: 0x0632,
  12996. zainfinalarabic: 0xFEB0,
  12997. zakatakana: 0x30B6,
  12998. zaqefgadolhebrew: 0x0595,
  12999. zaqefqatanhebrew: 0x0594,
  13000. zarqahebrew: 0x0598,
  13001. zayin: 0x05D6,
  13002. zayindagesh: 0xFB36,
  13003. zayindageshhebrew: 0xFB36,
  13004. zayinhebrew: 0x05D6,
  13005. zbopomofo: 0x3117,
  13006. zcaron: 0x017E,
  13007. zcircle: 0x24E9,
  13008. zcircumflex: 0x1E91,
  13009. zcurl: 0x0291,
  13010. zdot: 0x017C,
  13011. zdotaccent: 0x017C,
  13012. zdotbelow: 0x1E93,
  13013. zecyrillic: 0x0437,
  13014. zedescendercyrillic: 0x0499,
  13015. zedieresiscyrillic: 0x04DF,
  13016. zehiragana: 0x305C,
  13017. zekatakana: 0x30BC,
  13018. zero: 0x0030,
  13019. zeroarabic: 0x0660,
  13020. zerobengali: 0x09E6,
  13021. zerodeva: 0x0966,
  13022. zerogujarati: 0x0AE6,
  13023. zerogurmukhi: 0x0A66,
  13024. zerohackarabic: 0x0660,
  13025. zeroinferior: 0x2080,
  13026. zeromonospace: 0xFF10,
  13027. zerooldstyle: 0xF730,
  13028. zeropersian: 0x06F0,
  13029. zerosuperior: 0x2070,
  13030. zerothai: 0x0E50,
  13031. zerowidthjoiner: 0xFEFF,
  13032. zerowidthnonjoiner: 0x200C,
  13033. zerowidthspace: 0x200B,
  13034. zeta: 0x03B6,
  13035. zhbopomofo: 0x3113,
  13036. zhearmenian: 0x056A,
  13037. zhebrevecyrillic: 0x04C2,
  13038. zhecyrillic: 0x0436,
  13039. zhedescendercyrillic: 0x0497,
  13040. zhedieresiscyrillic: 0x04DD,
  13041. zihiragana: 0x3058,
  13042. zikatakana: 0x30B8,
  13043. zinorhebrew: 0x05AE,
  13044. zlinebelow: 0x1E95,
  13045. zmonospace: 0xFF5A,
  13046. zohiragana: 0x305E,
  13047. zokatakana: 0x30BE,
  13048. zparen: 0x24B5,
  13049. zretroflexhook: 0x0290,
  13050. zstroke: 0x01B6,
  13051. zuhiragana: 0x305A,
  13052. zukatakana: 0x30BA,
  13053. '.notdef': 0x0000
  13054. };
  13055. var DingbatsGlyphsUnicode = {
  13056. space: 0x0020,
  13057. a1: 0x2701,
  13058. a2: 0x2702,
  13059. a202: 0x2703,
  13060. a3: 0x2704,
  13061. a4: 0x260E,
  13062. a5: 0x2706,
  13063. a119: 0x2707,
  13064. a118: 0x2708,
  13065. a117: 0x2709,
  13066. a11: 0x261B,
  13067. a12: 0x261E,
  13068. a13: 0x270C,
  13069. a14: 0x270D,
  13070. a15: 0x270E,
  13071. a16: 0x270F,
  13072. a105: 0x2710,
  13073. a17: 0x2711,
  13074. a18: 0x2712,
  13075. a19: 0x2713,
  13076. a20: 0x2714,
  13077. a21: 0x2715,
  13078. a22: 0x2716,
  13079. a23: 0x2717,
  13080. a24: 0x2718,
  13081. a25: 0x2719,
  13082. a26: 0x271A,
  13083. a27: 0x271B,
  13084. a28: 0x271C,
  13085. a6: 0x271D,
  13086. a7: 0x271E,
  13087. a8: 0x271F,
  13088. a9: 0x2720,
  13089. a10: 0x2721,
  13090. a29: 0x2722,
  13091. a30: 0x2723,
  13092. a31: 0x2724,
  13093. a32: 0x2725,
  13094. a33: 0x2726,
  13095. a34: 0x2727,
  13096. a35: 0x2605,
  13097. a36: 0x2729,
  13098. a37: 0x272A,
  13099. a38: 0x272B,
  13100. a39: 0x272C,
  13101. a40: 0x272D,
  13102. a41: 0x272E,
  13103. a42: 0x272F,
  13104. a43: 0x2730,
  13105. a44: 0x2731,
  13106. a45: 0x2732,
  13107. a46: 0x2733,
  13108. a47: 0x2734,
  13109. a48: 0x2735,
  13110. a49: 0x2736,
  13111. a50: 0x2737,
  13112. a51: 0x2738,
  13113. a52: 0x2739,
  13114. a53: 0x273A,
  13115. a54: 0x273B,
  13116. a55: 0x273C,
  13117. a56: 0x273D,
  13118. a57: 0x273E,
  13119. a58: 0x273F,
  13120. a59: 0x2740,
  13121. a60: 0x2741,
  13122. a61: 0x2742,
  13123. a62: 0x2743,
  13124. a63: 0x2744,
  13125. a64: 0x2745,
  13126. a65: 0x2746,
  13127. a66: 0x2747,
  13128. a67: 0x2748,
  13129. a68: 0x2749,
  13130. a69: 0x274A,
  13131. a70: 0x274B,
  13132. a71: 0x25CF,
  13133. a72: 0x274D,
  13134. a73: 0x25A0,
  13135. a74: 0x274F,
  13136. a203: 0x2750,
  13137. a75: 0x2751,
  13138. a204: 0x2752,
  13139. a76: 0x25B2,
  13140. a77: 0x25BC,
  13141. a78: 0x25C6,
  13142. a79: 0x2756,
  13143. a81: 0x25D7,
  13144. a82: 0x2758,
  13145. a83: 0x2759,
  13146. a84: 0x275A,
  13147. a97: 0x275B,
  13148. a98: 0x275C,
  13149. a99: 0x275D,
  13150. a100: 0x275E,
  13151. a101: 0x2761,
  13152. a102: 0x2762,
  13153. a103: 0x2763,
  13154. a104: 0x2764,
  13155. a106: 0x2765,
  13156. a107: 0x2766,
  13157. a108: 0x2767,
  13158. a112: 0x2663,
  13159. a111: 0x2666,
  13160. a110: 0x2665,
  13161. a109: 0x2660,
  13162. a120: 0x2460,
  13163. a121: 0x2461,
  13164. a122: 0x2462,
  13165. a123: 0x2463,
  13166. a124: 0x2464,
  13167. a125: 0x2465,
  13168. a126: 0x2466,
  13169. a127: 0x2467,
  13170. a128: 0x2468,
  13171. a129: 0x2469,
  13172. a130: 0x2776,
  13173. a131: 0x2777,
  13174. a132: 0x2778,
  13175. a133: 0x2779,
  13176. a134: 0x277A,
  13177. a135: 0x277B,
  13178. a136: 0x277C,
  13179. a137: 0x277D,
  13180. a138: 0x277E,
  13181. a139: 0x277F,
  13182. a140: 0x2780,
  13183. a141: 0x2781,
  13184. a142: 0x2782,
  13185. a143: 0x2783,
  13186. a144: 0x2784,
  13187. a145: 0x2785,
  13188. a146: 0x2786,
  13189. a147: 0x2787,
  13190. a148: 0x2788,
  13191. a149: 0x2789,
  13192. a150: 0x278A,
  13193. a151: 0x278B,
  13194. a152: 0x278C,
  13195. a153: 0x278D,
  13196. a154: 0x278E,
  13197. a155: 0x278F,
  13198. a156: 0x2790,
  13199. a157: 0x2791,
  13200. a158: 0x2792,
  13201. a159: 0x2793,
  13202. a160: 0x2794,
  13203. a161: 0x2192,
  13204. a163: 0x2194,
  13205. a164: 0x2195,
  13206. a196: 0x2798,
  13207. a165: 0x2799,
  13208. a192: 0x279A,
  13209. a166: 0x279B,
  13210. a167: 0x279C,
  13211. a168: 0x279D,
  13212. a169: 0x279E,
  13213. a170: 0x279F,
  13214. a171: 0x27A0,
  13215. a172: 0x27A1,
  13216. a173: 0x27A2,
  13217. a162: 0x27A3,
  13218. a174: 0x27A4,
  13219. a175: 0x27A5,
  13220. a176: 0x27A6,
  13221. a177: 0x27A7,
  13222. a178: 0x27A8,
  13223. a179: 0x27A9,
  13224. a193: 0x27AA,
  13225. a180: 0x27AB,
  13226. a199: 0x27AC,
  13227. a181: 0x27AD,
  13228. a200: 0x27AE,
  13229. a182: 0x27AF,
  13230. a201: 0x27B1,
  13231. a183: 0x27B2,
  13232. a184: 0x27B3,
  13233. a197: 0x27B4,
  13234. a185: 0x27B5,
  13235. a194: 0x27B6,
  13236. a198: 0x27B7,
  13237. a186: 0x27B8,
  13238. a195: 0x27B9,
  13239. a187: 0x27BA,
  13240. a188: 0x27BB,
  13241. a189: 0x27BC,
  13242. a190: 0x27BD,
  13243. a191: 0x27BE,
  13244. a89: 0x2768, // 0xF8D7
  13245. a90: 0x2769, // 0xF8D8
  13246. a93: 0x276A, // 0xF8D9
  13247. a94: 0x276B, // 0xF8DA
  13248. a91: 0x276C, // 0xF8DB
  13249. a92: 0x276D, // 0xF8DC
  13250. a205: 0x276E, // 0xF8DD
  13251. a85: 0x276F, // 0xF8DE
  13252. a206: 0x2770, // 0xF8DF
  13253. a86: 0x2771, // 0xF8E0
  13254. a87: 0x2772, // 0xF8E1
  13255. a88: 0x2773, // 0xF8E2
  13256. a95: 0x2774, // 0xF8E3
  13257. a96: 0x2775, // 0xF8E4
  13258. '.notdef': 0x0000
  13259. };
  13260. exports.GlyphsUnicode = GlyphsUnicode;
  13261. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  13262. }));
  13263. (function (root, factory) {
  13264. {
  13265. factory((root.pdfjsCoreJpg = {}));
  13266. }
  13267. }(this, function (exports) {
  13268. /*
  13269. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  13270. version was created by github user notmasteryet
  13271. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  13272. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  13273. - The JFIF specification can be found in the JPEG File Interchange Format
  13274. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  13275. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  13276. in PostScript Level 2, Technical Note #5116
  13277. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  13278. */
  13279. var JpegImage = (function jpegImage() {
  13280. var dctZigZag = new Uint8Array([
  13281. 0,
  13282. 1, 8,
  13283. 16, 9, 2,
  13284. 3, 10, 17, 24,
  13285. 32, 25, 18, 11, 4,
  13286. 5, 12, 19, 26, 33, 40,
  13287. 48, 41, 34, 27, 20, 13, 6,
  13288. 7, 14, 21, 28, 35, 42, 49, 56,
  13289. 57, 50, 43, 36, 29, 22, 15,
  13290. 23, 30, 37, 44, 51, 58,
  13291. 59, 52, 45, 38, 31,
  13292. 39, 46, 53, 60,
  13293. 61, 54, 47,
  13294. 55, 62,
  13295. 63
  13296. ]);
  13297. var dctCos1 = 4017; // cos(pi/16)
  13298. var dctSin1 = 799; // sin(pi/16)
  13299. var dctCos3 = 3406; // cos(3*pi/16)
  13300. var dctSin3 = 2276; // sin(3*pi/16)
  13301. var dctCos6 = 1567; // cos(6*pi/16)
  13302. var dctSin6 = 3784; // sin(6*pi/16)
  13303. var dctSqrt2 = 5793; // sqrt(2)
  13304. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  13305. function constructor() {
  13306. }
  13307. function buildHuffmanTable(codeLengths, values) {
  13308. var k = 0, code = [], i, j, length = 16;
  13309. while (length > 0 && !codeLengths[length - 1]) {
  13310. length--;
  13311. }
  13312. code.push({children: [], index: 0});
  13313. var p = code[0], q;
  13314. for (i = 0; i < length; i++) {
  13315. for (j = 0; j < codeLengths[i]; j++) {
  13316. p = code.pop();
  13317. p.children[p.index] = values[k];
  13318. while (p.index > 0) {
  13319. p = code.pop();
  13320. }
  13321. p.index++;
  13322. code.push(p);
  13323. while (code.length <= i) {
  13324. code.push(q = {children: [], index: 0});
  13325. p.children[p.index] = q.children;
  13326. p = q;
  13327. }
  13328. k++;
  13329. }
  13330. if (i + 1 < length) {
  13331. // p here points to last code
  13332. code.push(q = {children: [], index: 0});
  13333. p.children[p.index] = q.children;
  13334. p = q;
  13335. }
  13336. }
  13337. return code[0].children;
  13338. }
  13339. function getBlockBufferOffset(component, row, col) {
  13340. return 64 * ((component.blocksPerLine + 1) * row + col);
  13341. }
  13342. function decodeScan(data, offset, frame, components, resetInterval,
  13343. spectralStart, spectralEnd, successivePrev, successive) {
  13344. var mcusPerLine = frame.mcusPerLine;
  13345. var progressive = frame.progressive;
  13346. var startOffset = offset, bitsData = 0, bitsCount = 0;
  13347. function readBit() {
  13348. if (bitsCount > 0) {
  13349. bitsCount--;
  13350. return (bitsData >> bitsCount) & 1;
  13351. }
  13352. bitsData = data[offset++];
  13353. if (bitsData === 0xFF) {
  13354. var nextByte = data[offset++];
  13355. if (nextByte) {
  13356. throw 'unexpected marker: ' +
  13357. ((bitsData << 8) | nextByte).toString(16);
  13358. }
  13359. // unstuff 0
  13360. }
  13361. bitsCount = 7;
  13362. return bitsData >>> 7;
  13363. }
  13364. function decodeHuffman(tree) {
  13365. var node = tree;
  13366. while (true) {
  13367. node = node[readBit()];
  13368. if (typeof node === 'number') {
  13369. return node;
  13370. }
  13371. if (typeof node !== 'object') {
  13372. throw 'invalid huffman sequence';
  13373. }
  13374. }
  13375. }
  13376. function receive(length) {
  13377. var n = 0;
  13378. while (length > 0) {
  13379. n = (n << 1) | readBit();
  13380. length--;
  13381. }
  13382. return n;
  13383. }
  13384. function receiveAndExtend(length) {
  13385. if (length === 1) {
  13386. return readBit() === 1 ? 1 : -1;
  13387. }
  13388. var n = receive(length);
  13389. if (n >= 1 << (length - 1)) {
  13390. return n;
  13391. }
  13392. return n + (-1 << length) + 1;
  13393. }
  13394. function decodeBaseline(component, offset) {
  13395. var t = decodeHuffman(component.huffmanTableDC);
  13396. var diff = t === 0 ? 0 : receiveAndExtend(t);
  13397. component.blockData[offset] = (component.pred += diff);
  13398. var k = 1;
  13399. while (k < 64) {
  13400. var rs = decodeHuffman(component.huffmanTableAC);
  13401. var s = rs & 15, r = rs >> 4;
  13402. if (s === 0) {
  13403. if (r < 15) {
  13404. break;
  13405. }
  13406. k += 16;
  13407. continue;
  13408. }
  13409. k += r;
  13410. var z = dctZigZag[k];
  13411. component.blockData[offset + z] = receiveAndExtend(s);
  13412. k++;
  13413. }
  13414. }
  13415. function decodeDCFirst(component, offset) {
  13416. var t = decodeHuffman(component.huffmanTableDC);
  13417. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  13418. component.blockData[offset] = (component.pred += diff);
  13419. }
  13420. function decodeDCSuccessive(component, offset) {
  13421. component.blockData[offset] |= readBit() << successive;
  13422. }
  13423. var eobrun = 0;
  13424. function decodeACFirst(component, offset) {
  13425. if (eobrun > 0) {
  13426. eobrun--;
  13427. return;
  13428. }
  13429. var k = spectralStart, e = spectralEnd;
  13430. while (k <= e) {
  13431. var rs = decodeHuffman(component.huffmanTableAC);
  13432. var s = rs & 15, r = rs >> 4;
  13433. if (s === 0) {
  13434. if (r < 15) {
  13435. eobrun = receive(r) + (1 << r) - 1;
  13436. break;
  13437. }
  13438. k += 16;
  13439. continue;
  13440. }
  13441. k += r;
  13442. var z = dctZigZag[k];
  13443. component.blockData[offset + z] =
  13444. receiveAndExtend(s) * (1 << successive);
  13445. k++;
  13446. }
  13447. }
  13448. var successiveACState = 0, successiveACNextValue;
  13449. function decodeACSuccessive(component, offset) {
  13450. var k = spectralStart;
  13451. var e = spectralEnd;
  13452. var r = 0;
  13453. var s;
  13454. var rs;
  13455. while (k <= e) {
  13456. var z = dctZigZag[k];
  13457. switch (successiveACState) {
  13458. case 0: // initial state
  13459. rs = decodeHuffman(component.huffmanTableAC);
  13460. s = rs & 15;
  13461. r = rs >> 4;
  13462. if (s === 0) {
  13463. if (r < 15) {
  13464. eobrun = receive(r) + (1 << r);
  13465. successiveACState = 4;
  13466. } else {
  13467. r = 16;
  13468. successiveACState = 1;
  13469. }
  13470. } else {
  13471. if (s !== 1) {
  13472. throw 'invalid ACn encoding';
  13473. }
  13474. successiveACNextValue = receiveAndExtend(s);
  13475. successiveACState = r ? 2 : 3;
  13476. }
  13477. continue;
  13478. case 1: // skipping r zero items
  13479. case 2:
  13480. if (component.blockData[offset + z]) {
  13481. component.blockData[offset + z] += (readBit() << successive);
  13482. } else {
  13483. r--;
  13484. if (r === 0) {
  13485. successiveACState = successiveACState === 2 ? 3 : 0;
  13486. }
  13487. }
  13488. break;
  13489. case 3: // set value for a zero item
  13490. if (component.blockData[offset + z]) {
  13491. component.blockData[offset + z] += (readBit() << successive);
  13492. } else {
  13493. component.blockData[offset + z] =
  13494. successiveACNextValue << successive;
  13495. successiveACState = 0;
  13496. }
  13497. break;
  13498. case 4: // eob
  13499. if (component.blockData[offset + z]) {
  13500. component.blockData[offset + z] += (readBit() << successive);
  13501. }
  13502. break;
  13503. }
  13504. k++;
  13505. }
  13506. if (successiveACState === 4) {
  13507. eobrun--;
  13508. if (eobrun === 0) {
  13509. successiveACState = 0;
  13510. }
  13511. }
  13512. }
  13513. function decodeMcu(component, decode, mcu, row, col) {
  13514. var mcuRow = (mcu / mcusPerLine) | 0;
  13515. var mcuCol = mcu % mcusPerLine;
  13516. var blockRow = mcuRow * component.v + row;
  13517. var blockCol = mcuCol * component.h + col;
  13518. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13519. decode(component, offset);
  13520. }
  13521. function decodeBlock(component, decode, mcu) {
  13522. var blockRow = (mcu / component.blocksPerLine) | 0;
  13523. var blockCol = mcu % component.blocksPerLine;
  13524. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13525. decode(component, offset);
  13526. }
  13527. var componentsLength = components.length;
  13528. var component, i, j, k, n;
  13529. var decodeFn;
  13530. if (progressive) {
  13531. if (spectralStart === 0) {
  13532. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  13533. } else {
  13534. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  13535. }
  13536. } else {
  13537. decodeFn = decodeBaseline;
  13538. }
  13539. var mcu = 0, marker;
  13540. var mcuExpected;
  13541. if (componentsLength === 1) {
  13542. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  13543. } else {
  13544. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  13545. }
  13546. if (!resetInterval) {
  13547. resetInterval = mcuExpected;
  13548. }
  13549. var h, v;
  13550. while (mcu < mcuExpected) {
  13551. // reset interval stuff
  13552. for (i = 0; i < componentsLength; i++) {
  13553. components[i].pred = 0;
  13554. }
  13555. eobrun = 0;
  13556. if (componentsLength === 1) {
  13557. component = components[0];
  13558. for (n = 0; n < resetInterval; n++) {
  13559. decodeBlock(component, decodeFn, mcu);
  13560. mcu++;
  13561. }
  13562. } else {
  13563. for (n = 0; n < resetInterval; n++) {
  13564. for (i = 0; i < componentsLength; i++) {
  13565. component = components[i];
  13566. h = component.h;
  13567. v = component.v;
  13568. for (j = 0; j < v; j++) {
  13569. for (k = 0; k < h; k++) {
  13570. decodeMcu(component, decodeFn, mcu, j, k);
  13571. }
  13572. }
  13573. }
  13574. mcu++;
  13575. }
  13576. }
  13577. // find marker
  13578. bitsCount = 0;
  13579. marker = (data[offset] << 8) | data[offset + 1];
  13580. if (marker <= 0xFF00) {
  13581. throw 'marker was not found';
  13582. }
  13583. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  13584. offset += 2;
  13585. } else {
  13586. break;
  13587. }
  13588. }
  13589. return offset - startOffset;
  13590. }
  13591. // A port of poppler's IDCT method which in turn is taken from:
  13592. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  13593. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  13594. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  13595. // 988-991.
  13596. function quantizeAndInverse(component, blockBufferOffset, p) {
  13597. var qt = component.quantizationTable, blockData = component.blockData;
  13598. var v0, v1, v2, v3, v4, v5, v6, v7;
  13599. var p0, p1, p2, p3, p4, p5, p6, p7;
  13600. var t;
  13601. // inverse DCT on rows
  13602. for (var row = 0; row < 64; row += 8) {
  13603. // gather block data
  13604. p0 = blockData[blockBufferOffset + row];
  13605. p1 = blockData[blockBufferOffset + row + 1];
  13606. p2 = blockData[blockBufferOffset + row + 2];
  13607. p3 = blockData[blockBufferOffset + row + 3];
  13608. p4 = blockData[blockBufferOffset + row + 4];
  13609. p5 = blockData[blockBufferOffset + row + 5];
  13610. p6 = blockData[blockBufferOffset + row + 6];
  13611. p7 = blockData[blockBufferOffset + row + 7];
  13612. // dequant p0
  13613. p0 *= qt[row];
  13614. // check for all-zero AC coefficients
  13615. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  13616. t = (dctSqrt2 * p0 + 512) >> 10;
  13617. p[row] = t;
  13618. p[row + 1] = t;
  13619. p[row + 2] = t;
  13620. p[row + 3] = t;
  13621. p[row + 4] = t;
  13622. p[row + 5] = t;
  13623. p[row + 6] = t;
  13624. p[row + 7] = t;
  13625. continue;
  13626. }
  13627. // dequant p1 ... p7
  13628. p1 *= qt[row + 1];
  13629. p2 *= qt[row + 2];
  13630. p3 *= qt[row + 3];
  13631. p4 *= qt[row + 4];
  13632. p5 *= qt[row + 5];
  13633. p6 *= qt[row + 6];
  13634. p7 *= qt[row + 7];
  13635. // stage 4
  13636. v0 = (dctSqrt2 * p0 + 128) >> 8;
  13637. v1 = (dctSqrt2 * p4 + 128) >> 8;
  13638. v2 = p2;
  13639. v3 = p6;
  13640. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  13641. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  13642. v5 = p3 << 4;
  13643. v6 = p5 << 4;
  13644. // stage 3
  13645. v0 = (v0 + v1 + 1) >> 1;
  13646. v1 = v0 - v1;
  13647. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  13648. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  13649. v3 = t;
  13650. v4 = (v4 + v6 + 1) >> 1;
  13651. v6 = v4 - v6;
  13652. v7 = (v7 + v5 + 1) >> 1;
  13653. v5 = v7 - v5;
  13654. // stage 2
  13655. v0 = (v0 + v3 + 1) >> 1;
  13656. v3 = v0 - v3;
  13657. v1 = (v1 + v2 + 1) >> 1;
  13658. v2 = v1 - v2;
  13659. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  13660. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  13661. v7 = t;
  13662. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  13663. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  13664. v6 = t;
  13665. // stage 1
  13666. p[row] = v0 + v7;
  13667. p[row + 7] = v0 - v7;
  13668. p[row + 1] = v1 + v6;
  13669. p[row + 6] = v1 - v6;
  13670. p[row + 2] = v2 + v5;
  13671. p[row + 5] = v2 - v5;
  13672. p[row + 3] = v3 + v4;
  13673. p[row + 4] = v3 - v4;
  13674. }
  13675. // inverse DCT on columns
  13676. for (var col = 0; col < 8; ++col) {
  13677. p0 = p[col];
  13678. p1 = p[col + 8];
  13679. p2 = p[col + 16];
  13680. p3 = p[col + 24];
  13681. p4 = p[col + 32];
  13682. p5 = p[col + 40];
  13683. p6 = p[col + 48];
  13684. p7 = p[col + 56];
  13685. // check for all-zero AC coefficients
  13686. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  13687. t = (dctSqrt2 * p0 + 8192) >> 14;
  13688. // convert to 8 bit
  13689. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  13690. blockData[blockBufferOffset + col] = t;
  13691. blockData[blockBufferOffset + col + 8] = t;
  13692. blockData[blockBufferOffset + col + 16] = t;
  13693. blockData[blockBufferOffset + col + 24] = t;
  13694. blockData[blockBufferOffset + col + 32] = t;
  13695. blockData[blockBufferOffset + col + 40] = t;
  13696. blockData[blockBufferOffset + col + 48] = t;
  13697. blockData[blockBufferOffset + col + 56] = t;
  13698. continue;
  13699. }
  13700. // stage 4
  13701. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  13702. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  13703. v2 = p2;
  13704. v3 = p6;
  13705. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  13706. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  13707. v5 = p3;
  13708. v6 = p5;
  13709. // stage 3
  13710. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  13711. // converting to UInt8 range later.
  13712. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  13713. v1 = v0 - v1;
  13714. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  13715. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  13716. v3 = t;
  13717. v4 = (v4 + v6 + 1) >> 1;
  13718. v6 = v4 - v6;
  13719. v7 = (v7 + v5 + 1) >> 1;
  13720. v5 = v7 - v5;
  13721. // stage 2
  13722. v0 = (v0 + v3 + 1) >> 1;
  13723. v3 = v0 - v3;
  13724. v1 = (v1 + v2 + 1) >> 1;
  13725. v2 = v1 - v2;
  13726. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  13727. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  13728. v7 = t;
  13729. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  13730. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  13731. v6 = t;
  13732. // stage 1
  13733. p0 = v0 + v7;
  13734. p7 = v0 - v7;
  13735. p1 = v1 + v6;
  13736. p6 = v1 - v6;
  13737. p2 = v2 + v5;
  13738. p5 = v2 - v5;
  13739. p3 = v3 + v4;
  13740. p4 = v3 - v4;
  13741. // convert to 8-bit integers
  13742. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  13743. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  13744. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  13745. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  13746. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  13747. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  13748. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  13749. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  13750. // store block data
  13751. blockData[blockBufferOffset + col] = p0;
  13752. blockData[blockBufferOffset + col + 8] = p1;
  13753. blockData[blockBufferOffset + col + 16] = p2;
  13754. blockData[blockBufferOffset + col + 24] = p3;
  13755. blockData[blockBufferOffset + col + 32] = p4;
  13756. blockData[blockBufferOffset + col + 40] = p5;
  13757. blockData[blockBufferOffset + col + 48] = p6;
  13758. blockData[blockBufferOffset + col + 56] = p7;
  13759. }
  13760. }
  13761. function buildComponentData(frame, component) {
  13762. var blocksPerLine = component.blocksPerLine;
  13763. var blocksPerColumn = component.blocksPerColumn;
  13764. var computationBuffer = new Int16Array(64);
  13765. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  13766. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  13767. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13768. quantizeAndInverse(component, offset, computationBuffer);
  13769. }
  13770. }
  13771. return component.blockData;
  13772. }
  13773. function clamp0to255(a) {
  13774. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  13775. }
  13776. constructor.prototype = {
  13777. parse: function parse(data) {
  13778. function readUint16() {
  13779. var value = (data[offset] << 8) | data[offset + 1];
  13780. offset += 2;
  13781. return value;
  13782. }
  13783. function readDataBlock() {
  13784. var length = readUint16();
  13785. var array = data.subarray(offset, offset + length - 2);
  13786. offset += array.length;
  13787. return array;
  13788. }
  13789. function prepareComponents(frame) {
  13790. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  13791. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  13792. for (var i = 0; i < frame.components.length; i++) {
  13793. component = frame.components[i];
  13794. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  13795. component.h / frame.maxH);
  13796. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  13797. component.v / frame.maxV);
  13798. var blocksPerLineForMcu = mcusPerLine * component.h;
  13799. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  13800. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  13801. (blocksPerLineForMcu + 1);
  13802. component.blockData = new Int16Array(blocksBufferSize);
  13803. component.blocksPerLine = blocksPerLine;
  13804. component.blocksPerColumn = blocksPerColumn;
  13805. }
  13806. frame.mcusPerLine = mcusPerLine;
  13807. frame.mcusPerColumn = mcusPerColumn;
  13808. }
  13809. var offset = 0;
  13810. var jfif = null;
  13811. var adobe = null;
  13812. var frame, resetInterval;
  13813. var quantizationTables = [];
  13814. var huffmanTablesAC = [], huffmanTablesDC = [];
  13815. var fileMarker = readUint16();
  13816. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  13817. throw 'SOI not found';
  13818. }
  13819. fileMarker = readUint16();
  13820. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  13821. var i, j, l;
  13822. switch(fileMarker) {
  13823. case 0xFFE0: // APP0 (Application Specific)
  13824. case 0xFFE1: // APP1
  13825. case 0xFFE2: // APP2
  13826. case 0xFFE3: // APP3
  13827. case 0xFFE4: // APP4
  13828. case 0xFFE5: // APP5
  13829. case 0xFFE6: // APP6
  13830. case 0xFFE7: // APP7
  13831. case 0xFFE8: // APP8
  13832. case 0xFFE9: // APP9
  13833. case 0xFFEA: // APP10
  13834. case 0xFFEB: // APP11
  13835. case 0xFFEC: // APP12
  13836. case 0xFFED: // APP13
  13837. case 0xFFEE: // APP14
  13838. case 0xFFEF: // APP15
  13839. case 0xFFFE: // COM (Comment)
  13840. var appData = readDataBlock();
  13841. if (fileMarker === 0xFFE0) {
  13842. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  13843. appData[2] === 0x49 && appData[3] === 0x46 &&
  13844. appData[4] === 0) { // 'JFIF\x00'
  13845. jfif = {
  13846. version: { major: appData[5], minor: appData[6] },
  13847. densityUnits: appData[7],
  13848. xDensity: (appData[8] << 8) | appData[9],
  13849. yDensity: (appData[10] << 8) | appData[11],
  13850. thumbWidth: appData[12],
  13851. thumbHeight: appData[13],
  13852. thumbData: appData.subarray(14, 14 +
  13853. 3 * appData[12] * appData[13])
  13854. };
  13855. }
  13856. }
  13857. // TODO APP1 - Exif
  13858. if (fileMarker === 0xFFEE) {
  13859. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  13860. appData[2] === 0x6F && appData[3] === 0x62 &&
  13861. appData[4] === 0x65) { // 'Adobe'
  13862. adobe = {
  13863. version: (appData[5] << 8) | appData[6],
  13864. flags0: (appData[7] << 8) | appData[8],
  13865. flags1: (appData[9] << 8) | appData[10],
  13866. transformCode: appData[11]
  13867. };
  13868. }
  13869. }
  13870. break;
  13871. case 0xFFDB: // DQT (Define Quantization Tables)
  13872. var quantizationTablesLength = readUint16();
  13873. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  13874. var z;
  13875. while (offset < quantizationTablesEnd) {
  13876. var quantizationTableSpec = data[offset++];
  13877. var tableData = new Uint16Array(64);
  13878. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  13879. for (j = 0; j < 64; j++) {
  13880. z = dctZigZag[j];
  13881. tableData[z] = data[offset++];
  13882. }
  13883. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  13884. for (j = 0; j < 64; j++) {
  13885. z = dctZigZag[j];
  13886. tableData[z] = readUint16();
  13887. }
  13888. } else {
  13889. throw 'DQT: invalid table spec';
  13890. }
  13891. quantizationTables[quantizationTableSpec & 15] = tableData;
  13892. }
  13893. break;
  13894. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  13895. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  13896. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  13897. if (frame) {
  13898. throw 'Only single frame JPEGs supported';
  13899. }
  13900. readUint16(); // skip data length
  13901. frame = {};
  13902. frame.extended = (fileMarker === 0xFFC1);
  13903. frame.progressive = (fileMarker === 0xFFC2);
  13904. frame.precision = data[offset++];
  13905. frame.scanLines = readUint16();
  13906. frame.samplesPerLine = readUint16();
  13907. frame.components = [];
  13908. frame.componentIds = {};
  13909. var componentsCount = data[offset++], componentId;
  13910. var maxH = 0, maxV = 0;
  13911. for (i = 0; i < componentsCount; i++) {
  13912. componentId = data[offset];
  13913. var h = data[offset + 1] >> 4;
  13914. var v = data[offset + 1] & 15;
  13915. if (maxH < h) {
  13916. maxH = h;
  13917. }
  13918. if (maxV < v) {
  13919. maxV = v;
  13920. }
  13921. var qId = data[offset + 2];
  13922. l = frame.components.push({
  13923. h: h,
  13924. v: v,
  13925. quantizationTable: quantizationTables[qId]
  13926. });
  13927. frame.componentIds[componentId] = l - 1;
  13928. offset += 3;
  13929. }
  13930. frame.maxH = maxH;
  13931. frame.maxV = maxV;
  13932. prepareComponents(frame);
  13933. break;
  13934. case 0xFFC4: // DHT (Define Huffman Tables)
  13935. var huffmanLength = readUint16();
  13936. for (i = 2; i < huffmanLength;) {
  13937. var huffmanTableSpec = data[offset++];
  13938. var codeLengths = new Uint8Array(16);
  13939. var codeLengthSum = 0;
  13940. for (j = 0; j < 16; j++, offset++) {
  13941. codeLengthSum += (codeLengths[j] = data[offset]);
  13942. }
  13943. var huffmanValues = new Uint8Array(codeLengthSum);
  13944. for (j = 0; j < codeLengthSum; j++, offset++) {
  13945. huffmanValues[j] = data[offset];
  13946. }
  13947. i += 17 + codeLengthSum;
  13948. ((huffmanTableSpec >> 4) === 0 ?
  13949. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  13950. buildHuffmanTable(codeLengths, huffmanValues);
  13951. }
  13952. break;
  13953. case 0xFFDD: // DRI (Define Restart Interval)
  13954. readUint16(); // skip data length
  13955. resetInterval = readUint16();
  13956. break;
  13957. case 0xFFDA: // SOS (Start of Scan)
  13958. var scanLength = readUint16();
  13959. var selectorsCount = data[offset++];
  13960. var components = [], component;
  13961. for (i = 0; i < selectorsCount; i++) {
  13962. var componentIndex = frame.componentIds[data[offset++]];
  13963. component = frame.components[componentIndex];
  13964. var tableSpec = data[offset++];
  13965. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  13966. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  13967. components.push(component);
  13968. }
  13969. var spectralStart = data[offset++];
  13970. var spectralEnd = data[offset++];
  13971. var successiveApproximation = data[offset++];
  13972. var processed = decodeScan(data, offset,
  13973. frame, components, resetInterval,
  13974. spectralStart, spectralEnd,
  13975. successiveApproximation >> 4, successiveApproximation & 15);
  13976. offset += processed;
  13977. break;
  13978. case 0xFFFF: // Fill bytes
  13979. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  13980. offset--;
  13981. }
  13982. break;
  13983. default:
  13984. if (data[offset - 3] === 0xFF &&
  13985. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  13986. // could be incorrect encoding -- last 0xFF byte of the previous
  13987. // block was eaten by the encoder
  13988. offset -= 3;
  13989. break;
  13990. }
  13991. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  13992. }
  13993. fileMarker = readUint16();
  13994. }
  13995. this.width = frame.samplesPerLine;
  13996. this.height = frame.scanLines;
  13997. this.jfif = jfif;
  13998. this.adobe = adobe;
  13999. this.components = [];
  14000. for (i = 0; i < frame.components.length; i++) {
  14001. component = frame.components[i];
  14002. this.components.push({
  14003. output: buildComponentData(frame, component),
  14004. scaleX: component.h / frame.maxH,
  14005. scaleY: component.v / frame.maxV,
  14006. blocksPerLine: component.blocksPerLine,
  14007. blocksPerColumn: component.blocksPerColumn
  14008. });
  14009. }
  14010. this.numComponents = this.components.length;
  14011. },
  14012. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  14013. var scaleX = this.width / width, scaleY = this.height / height;
  14014. var component, componentScaleX, componentScaleY, blocksPerScanline;
  14015. var x, y, i, j, k;
  14016. var index;
  14017. var offset = 0;
  14018. var output;
  14019. var numComponents = this.components.length;
  14020. var dataLength = width * height * numComponents;
  14021. var data = new Uint8Array(dataLength);
  14022. var xScaleBlockOffset = new Uint32Array(width);
  14023. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  14024. for (i = 0; i < numComponents; i++) {
  14025. component = this.components[i];
  14026. componentScaleX = component.scaleX * scaleX;
  14027. componentScaleY = component.scaleY * scaleY;
  14028. offset = i;
  14029. output = component.output;
  14030. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  14031. // precalculate the xScaleBlockOffset
  14032. for (x = 0; x < width; x++) {
  14033. j = 0 | (x * componentScaleX);
  14034. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  14035. }
  14036. // linearize the blocks of the component
  14037. for (y = 0; y < height; y++) {
  14038. j = 0 | (y * componentScaleY);
  14039. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  14040. for (x = 0; x < width; x++) {
  14041. data[offset] = output[index + xScaleBlockOffset[x]];
  14042. offset += numComponents;
  14043. }
  14044. }
  14045. }
  14046. // decodeTransform contains pairs of multiplier (-256..256) and additive
  14047. var transform = this.decodeTransform;
  14048. if (transform) {
  14049. for (i = 0; i < dataLength;) {
  14050. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  14051. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  14052. }
  14053. }
  14054. }
  14055. return data;
  14056. },
  14057. _isColorConversionNeeded: function isColorConversionNeeded() {
  14058. if (this.adobe && this.adobe.transformCode) {
  14059. // The adobe transform marker overrides any previous setting
  14060. return true;
  14061. } else if (this.numComponents === 3) {
  14062. return true;
  14063. } else {
  14064. return false;
  14065. }
  14066. },
  14067. _convertYccToRgb: function convertYccToRgb(data) {
  14068. var Y, Cb, Cr;
  14069. for (var i = 0, length = data.length; i < length; i += 3) {
  14070. Y = data[i ];
  14071. Cb = data[i + 1];
  14072. Cr = data[i + 2];
  14073. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  14074. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  14075. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  14076. }
  14077. return data;
  14078. },
  14079. _convertYcckToRgb: function convertYcckToRgb(data) {
  14080. var Y, Cb, Cr, k;
  14081. var offset = 0;
  14082. for (var i = 0, length = data.length; i < length; i += 4) {
  14083. Y = data[i];
  14084. Cb = data[i + 1];
  14085. Cr = data[i + 2];
  14086. k = data[i + 3];
  14087. var r = -122.67195406894 +
  14088. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  14089. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  14090. 0.154362151871126) +
  14091. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  14092. 0.00477271405408747 * k + 1.53380253221734) +
  14093. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  14094. 0.48357088451265) +
  14095. k * (-0.000336197177618394 * k + 0.484791561490776);
  14096. var g = 107.268039397724 +
  14097. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  14098. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  14099. 0.176491792462875) +
  14100. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  14101. 0.000770482631801132 * k - 0.151051492775562) +
  14102. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  14103. 0.25802910206845) +
  14104. k * (-0.000318913117588328 * k - 0.213742400323665);
  14105. var b = -20.810012546947 +
  14106. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  14107. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  14108. 0.814272968359295) +
  14109. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  14110. 0.000560833691242812 * k - 0.195152027534049) +
  14111. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  14112. 0.116935020465145) +
  14113. k * (-0.000343531996510555 * k + 0.24165260232407);
  14114. data[offset++] = clamp0to255(r);
  14115. data[offset++] = clamp0to255(g);
  14116. data[offset++] = clamp0to255(b);
  14117. }
  14118. return data;
  14119. },
  14120. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  14121. var Y, Cb, Cr;
  14122. for (var i = 0, length = data.length; i < length; i += 4) {
  14123. Y = data[i];
  14124. Cb = data[i + 1];
  14125. Cr = data[i + 2];
  14126. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  14127. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  14128. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  14129. // K in data[i + 3] is unchanged
  14130. }
  14131. return data;
  14132. },
  14133. _convertCmykToRgb: function convertCmykToRgb(data) {
  14134. var c, m, y, k;
  14135. var offset = 0;
  14136. var min = -255 * 255 * 255;
  14137. var scale = 1 / 255 / 255;
  14138. for (var i = 0, length = data.length; i < length; i += 4) {
  14139. c = data[i];
  14140. m = data[i + 1];
  14141. y = data[i + 2];
  14142. k = data[i + 3];
  14143. var r =
  14144. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  14145. 18.82290502165302 * y + 212.25662451639585 * k -
  14146. 72734.4411664936) +
  14147. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  14148. 17.873870861415444 * k - 1401.7366389350734) +
  14149. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  14150. 4465.541406466231) -
  14151. k * (21.86122147463605 * k + 48317.86113160301);
  14152. var g =
  14153. c * (8.841041422036149 * c + 60.118027045597366 * m +
  14154. 6.871425592049007 * y + 31.159100130055922 * k -
  14155. 20220.756542821975) +
  14156. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  14157. 131.35250912493976 * k - 48691.05921601825) +
  14158. y * (4.444339102852739 * y + 9.8632861493405 * k -
  14159. 6341.191035517494) -
  14160. k * (20.737325471181034 * k + 47890.15695978492);
  14161. var b =
  14162. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  14163. 30.89978309703729 * y - 0.23883238689178934 * k -
  14164. 3616.812083916688) +
  14165. m * (10.49593273432072 * m + 63.02378494754052 * y +
  14166. 50.606957656360734 * k - 28620.90484698408) +
  14167. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  14168. 49363.43385999684) -
  14169. k * (22.33816807309886 * k + 45932.16563550634);
  14170. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  14171. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  14172. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  14173. }
  14174. return data;
  14175. },
  14176. getData: function getData(width, height, forceRGBoutput) {
  14177. if (this.numComponents > 4) {
  14178. throw 'Unsupported color mode';
  14179. }
  14180. // type of data: Uint8Array(width * height * numComponents)
  14181. var data = this._getLinearizedBlockData(width, height);
  14182. if (this.numComponents === 3) {
  14183. return this._convertYccToRgb(data);
  14184. } else if (this.numComponents === 4) {
  14185. if (this._isColorConversionNeeded()) {
  14186. if (forceRGBoutput) {
  14187. return this._convertYcckToRgb(data);
  14188. } else {
  14189. return this._convertYcckToCmyk(data);
  14190. }
  14191. } else if (forceRGBoutput) {
  14192. return this._convertCmykToRgb(data);
  14193. }
  14194. }
  14195. return data;
  14196. }
  14197. };
  14198. return constructor;
  14199. })();
  14200. exports.JpegImage = JpegImage;
  14201. }));
  14202. (function (root, factory) {
  14203. {
  14204. factory((root.pdfjsCoreMetrics = {}));
  14205. }
  14206. }(this, function (exports) {
  14207. // The Metrics object contains glyph widths (in glyph space units).
  14208. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  14209. // space unit corresponds to 1/1000th of text space unit.
  14210. var Metrics = {
  14211. 'Courier': 600,
  14212. 'Courier-Bold': 600,
  14213. 'Courier-BoldOblique': 600,
  14214. 'Courier-Oblique': 600,
  14215. 'Helvetica' : {
  14216. 'space': 278,
  14217. 'exclam': 278,
  14218. 'quotedbl': 355,
  14219. 'numbersign': 556,
  14220. 'dollar': 556,
  14221. 'percent': 889,
  14222. 'ampersand': 667,
  14223. 'quoteright': 222,
  14224. 'parenleft': 333,
  14225. 'parenright': 333,
  14226. 'asterisk': 389,
  14227. 'plus': 584,
  14228. 'comma': 278,
  14229. 'hyphen': 333,
  14230. 'period': 278,
  14231. 'slash': 278,
  14232. 'zero': 556,
  14233. 'one': 556,
  14234. 'two': 556,
  14235. 'three': 556,
  14236. 'four': 556,
  14237. 'five': 556,
  14238. 'six': 556,
  14239. 'seven': 556,
  14240. 'eight': 556,
  14241. 'nine': 556,
  14242. 'colon': 278,
  14243. 'semicolon': 278,
  14244. 'less': 584,
  14245. 'equal': 584,
  14246. 'greater': 584,
  14247. 'question': 556,
  14248. 'at': 1015,
  14249. 'A': 667,
  14250. 'B': 667,
  14251. 'C': 722,
  14252. 'D': 722,
  14253. 'E': 667,
  14254. 'F': 611,
  14255. 'G': 778,
  14256. 'H': 722,
  14257. 'I': 278,
  14258. 'J': 500,
  14259. 'K': 667,
  14260. 'L': 556,
  14261. 'M': 833,
  14262. 'N': 722,
  14263. 'O': 778,
  14264. 'P': 667,
  14265. 'Q': 778,
  14266. 'R': 722,
  14267. 'S': 667,
  14268. 'T': 611,
  14269. 'U': 722,
  14270. 'V': 667,
  14271. 'W': 944,
  14272. 'X': 667,
  14273. 'Y': 667,
  14274. 'Z': 611,
  14275. 'bracketleft': 278,
  14276. 'backslash': 278,
  14277. 'bracketright': 278,
  14278. 'asciicircum': 469,
  14279. 'underscore': 556,
  14280. 'quoteleft': 222,
  14281. 'a': 556,
  14282. 'b': 556,
  14283. 'c': 500,
  14284. 'd': 556,
  14285. 'e': 556,
  14286. 'f': 278,
  14287. 'g': 556,
  14288. 'h': 556,
  14289. 'i': 222,
  14290. 'j': 222,
  14291. 'k': 500,
  14292. 'l': 222,
  14293. 'm': 833,
  14294. 'n': 556,
  14295. 'o': 556,
  14296. 'p': 556,
  14297. 'q': 556,
  14298. 'r': 333,
  14299. 's': 500,
  14300. 't': 278,
  14301. 'u': 556,
  14302. 'v': 500,
  14303. 'w': 722,
  14304. 'x': 500,
  14305. 'y': 500,
  14306. 'z': 500,
  14307. 'braceleft': 334,
  14308. 'bar': 260,
  14309. 'braceright': 334,
  14310. 'asciitilde': 584,
  14311. 'exclamdown': 333,
  14312. 'cent': 556,
  14313. 'sterling': 556,
  14314. 'fraction': 167,
  14315. 'yen': 556,
  14316. 'florin': 556,
  14317. 'section': 556,
  14318. 'currency': 556,
  14319. 'quotesingle': 191,
  14320. 'quotedblleft': 333,
  14321. 'guillemotleft': 556,
  14322. 'guilsinglleft': 333,
  14323. 'guilsinglright': 333,
  14324. 'fi': 500,
  14325. 'fl': 500,
  14326. 'endash': 556,
  14327. 'dagger': 556,
  14328. 'daggerdbl': 556,
  14329. 'periodcentered': 278,
  14330. 'paragraph': 537,
  14331. 'bullet': 350,
  14332. 'quotesinglbase': 222,
  14333. 'quotedblbase': 333,
  14334. 'quotedblright': 333,
  14335. 'guillemotright': 556,
  14336. 'ellipsis': 1000,
  14337. 'perthousand': 1000,
  14338. 'questiondown': 611,
  14339. 'grave': 333,
  14340. 'acute': 333,
  14341. 'circumflex': 333,
  14342. 'tilde': 333,
  14343. 'macron': 333,
  14344. 'breve': 333,
  14345. 'dotaccent': 333,
  14346. 'dieresis': 333,
  14347. 'ring': 333,
  14348. 'cedilla': 333,
  14349. 'hungarumlaut': 333,
  14350. 'ogonek': 333,
  14351. 'caron': 333,
  14352. 'emdash': 1000,
  14353. 'AE': 1000,
  14354. 'ordfeminine': 370,
  14355. 'Lslash': 556,
  14356. 'Oslash': 778,
  14357. 'OE': 1000,
  14358. 'ordmasculine': 365,
  14359. 'ae': 889,
  14360. 'dotlessi': 278,
  14361. 'lslash': 222,
  14362. 'oslash': 611,
  14363. 'oe': 944,
  14364. 'germandbls': 611,
  14365. 'Idieresis': 278,
  14366. 'eacute': 556,
  14367. 'abreve': 556,
  14368. 'uhungarumlaut': 556,
  14369. 'ecaron': 556,
  14370. 'Ydieresis': 667,
  14371. 'divide': 584,
  14372. 'Yacute': 667,
  14373. 'Acircumflex': 667,
  14374. 'aacute': 556,
  14375. 'Ucircumflex': 722,
  14376. 'yacute': 500,
  14377. 'scommaaccent': 500,
  14378. 'ecircumflex': 556,
  14379. 'Uring': 722,
  14380. 'Udieresis': 722,
  14381. 'aogonek': 556,
  14382. 'Uacute': 722,
  14383. 'uogonek': 556,
  14384. 'Edieresis': 667,
  14385. 'Dcroat': 722,
  14386. 'commaaccent': 250,
  14387. 'copyright': 737,
  14388. 'Emacron': 667,
  14389. 'ccaron': 500,
  14390. 'aring': 556,
  14391. 'Ncommaaccent': 722,
  14392. 'lacute': 222,
  14393. 'agrave': 556,
  14394. 'Tcommaaccent': 611,
  14395. 'Cacute': 722,
  14396. 'atilde': 556,
  14397. 'Edotaccent': 667,
  14398. 'scaron': 500,
  14399. 'scedilla': 500,
  14400. 'iacute': 278,
  14401. 'lozenge': 471,
  14402. 'Rcaron': 722,
  14403. 'Gcommaaccent': 778,
  14404. 'ucircumflex': 556,
  14405. 'acircumflex': 556,
  14406. 'Amacron': 667,
  14407. 'rcaron': 333,
  14408. 'ccedilla': 500,
  14409. 'Zdotaccent': 611,
  14410. 'Thorn': 667,
  14411. 'Omacron': 778,
  14412. 'Racute': 722,
  14413. 'Sacute': 667,
  14414. 'dcaron': 643,
  14415. 'Umacron': 722,
  14416. 'uring': 556,
  14417. 'threesuperior': 333,
  14418. 'Ograve': 778,
  14419. 'Agrave': 667,
  14420. 'Abreve': 667,
  14421. 'multiply': 584,
  14422. 'uacute': 556,
  14423. 'Tcaron': 611,
  14424. 'partialdiff': 476,
  14425. 'ydieresis': 500,
  14426. 'Nacute': 722,
  14427. 'icircumflex': 278,
  14428. 'Ecircumflex': 667,
  14429. 'adieresis': 556,
  14430. 'edieresis': 556,
  14431. 'cacute': 500,
  14432. 'nacute': 556,
  14433. 'umacron': 556,
  14434. 'Ncaron': 722,
  14435. 'Iacute': 278,
  14436. 'plusminus': 584,
  14437. 'brokenbar': 260,
  14438. 'registered': 737,
  14439. 'Gbreve': 778,
  14440. 'Idotaccent': 278,
  14441. 'summation': 600,
  14442. 'Egrave': 667,
  14443. 'racute': 333,
  14444. 'omacron': 556,
  14445. 'Zacute': 611,
  14446. 'Zcaron': 611,
  14447. 'greaterequal': 549,
  14448. 'Eth': 722,
  14449. 'Ccedilla': 722,
  14450. 'lcommaaccent': 222,
  14451. 'tcaron': 317,
  14452. 'eogonek': 556,
  14453. 'Uogonek': 722,
  14454. 'Aacute': 667,
  14455. 'Adieresis': 667,
  14456. 'egrave': 556,
  14457. 'zacute': 500,
  14458. 'iogonek': 222,
  14459. 'Oacute': 778,
  14460. 'oacute': 556,
  14461. 'amacron': 556,
  14462. 'sacute': 500,
  14463. 'idieresis': 278,
  14464. 'Ocircumflex': 778,
  14465. 'Ugrave': 722,
  14466. 'Delta': 612,
  14467. 'thorn': 556,
  14468. 'twosuperior': 333,
  14469. 'Odieresis': 778,
  14470. 'mu': 556,
  14471. 'igrave': 278,
  14472. 'ohungarumlaut': 556,
  14473. 'Eogonek': 667,
  14474. 'dcroat': 556,
  14475. 'threequarters': 834,
  14476. 'Scedilla': 667,
  14477. 'lcaron': 299,
  14478. 'Kcommaaccent': 667,
  14479. 'Lacute': 556,
  14480. 'trademark': 1000,
  14481. 'edotaccent': 556,
  14482. 'Igrave': 278,
  14483. 'Imacron': 278,
  14484. 'Lcaron': 556,
  14485. 'onehalf': 834,
  14486. 'lessequal': 549,
  14487. 'ocircumflex': 556,
  14488. 'ntilde': 556,
  14489. 'Uhungarumlaut': 722,
  14490. 'Eacute': 667,
  14491. 'emacron': 556,
  14492. 'gbreve': 556,
  14493. 'onequarter': 834,
  14494. 'Scaron': 667,
  14495. 'Scommaaccent': 667,
  14496. 'Ohungarumlaut': 778,
  14497. 'degree': 400,
  14498. 'ograve': 556,
  14499. 'Ccaron': 722,
  14500. 'ugrave': 556,
  14501. 'radical': 453,
  14502. 'Dcaron': 722,
  14503. 'rcommaaccent': 333,
  14504. 'Ntilde': 722,
  14505. 'otilde': 556,
  14506. 'Rcommaaccent': 722,
  14507. 'Lcommaaccent': 556,
  14508. 'Atilde': 667,
  14509. 'Aogonek': 667,
  14510. 'Aring': 667,
  14511. 'Otilde': 778,
  14512. 'zdotaccent': 500,
  14513. 'Ecaron': 667,
  14514. 'Iogonek': 278,
  14515. 'kcommaaccent': 500,
  14516. 'minus': 584,
  14517. 'Icircumflex': 278,
  14518. 'ncaron': 556,
  14519. 'tcommaaccent': 278,
  14520. 'logicalnot': 584,
  14521. 'odieresis': 556,
  14522. 'udieresis': 556,
  14523. 'notequal': 549,
  14524. 'gcommaaccent': 556,
  14525. 'eth': 556,
  14526. 'zcaron': 500,
  14527. 'ncommaaccent': 556,
  14528. 'onesuperior': 333,
  14529. 'imacron': 278,
  14530. 'Euro': 556
  14531. },
  14532. 'Helvetica-Bold': {
  14533. 'space': 278,
  14534. 'exclam': 333,
  14535. 'quotedbl': 474,
  14536. 'numbersign': 556,
  14537. 'dollar': 556,
  14538. 'percent': 889,
  14539. 'ampersand': 722,
  14540. 'quoteright': 278,
  14541. 'parenleft': 333,
  14542. 'parenright': 333,
  14543. 'asterisk': 389,
  14544. 'plus': 584,
  14545. 'comma': 278,
  14546. 'hyphen': 333,
  14547. 'period': 278,
  14548. 'slash': 278,
  14549. 'zero': 556,
  14550. 'one': 556,
  14551. 'two': 556,
  14552. 'three': 556,
  14553. 'four': 556,
  14554. 'five': 556,
  14555. 'six': 556,
  14556. 'seven': 556,
  14557. 'eight': 556,
  14558. 'nine': 556,
  14559. 'colon': 333,
  14560. 'semicolon': 333,
  14561. 'less': 584,
  14562. 'equal': 584,
  14563. 'greater': 584,
  14564. 'question': 611,
  14565. 'at': 975,
  14566. 'A': 722,
  14567. 'B': 722,
  14568. 'C': 722,
  14569. 'D': 722,
  14570. 'E': 667,
  14571. 'F': 611,
  14572. 'G': 778,
  14573. 'H': 722,
  14574. 'I': 278,
  14575. 'J': 556,
  14576. 'K': 722,
  14577. 'L': 611,
  14578. 'M': 833,
  14579. 'N': 722,
  14580. 'O': 778,
  14581. 'P': 667,
  14582. 'Q': 778,
  14583. 'R': 722,
  14584. 'S': 667,
  14585. 'T': 611,
  14586. 'U': 722,
  14587. 'V': 667,
  14588. 'W': 944,
  14589. 'X': 667,
  14590. 'Y': 667,
  14591. 'Z': 611,
  14592. 'bracketleft': 333,
  14593. 'backslash': 278,
  14594. 'bracketright': 333,
  14595. 'asciicircum': 584,
  14596. 'underscore': 556,
  14597. 'quoteleft': 278,
  14598. 'a': 556,
  14599. 'b': 611,
  14600. 'c': 556,
  14601. 'd': 611,
  14602. 'e': 556,
  14603. 'f': 333,
  14604. 'g': 611,
  14605. 'h': 611,
  14606. 'i': 278,
  14607. 'j': 278,
  14608. 'k': 556,
  14609. 'l': 278,
  14610. 'm': 889,
  14611. 'n': 611,
  14612. 'o': 611,
  14613. 'p': 611,
  14614. 'q': 611,
  14615. 'r': 389,
  14616. 's': 556,
  14617. 't': 333,
  14618. 'u': 611,
  14619. 'v': 556,
  14620. 'w': 778,
  14621. 'x': 556,
  14622. 'y': 556,
  14623. 'z': 500,
  14624. 'braceleft': 389,
  14625. 'bar': 280,
  14626. 'braceright': 389,
  14627. 'asciitilde': 584,
  14628. 'exclamdown': 333,
  14629. 'cent': 556,
  14630. 'sterling': 556,
  14631. 'fraction': 167,
  14632. 'yen': 556,
  14633. 'florin': 556,
  14634. 'section': 556,
  14635. 'currency': 556,
  14636. 'quotesingle': 238,
  14637. 'quotedblleft': 500,
  14638. 'guillemotleft': 556,
  14639. 'guilsinglleft': 333,
  14640. 'guilsinglright': 333,
  14641. 'fi': 611,
  14642. 'fl': 611,
  14643. 'endash': 556,
  14644. 'dagger': 556,
  14645. 'daggerdbl': 556,
  14646. 'periodcentered': 278,
  14647. 'paragraph': 556,
  14648. 'bullet': 350,
  14649. 'quotesinglbase': 278,
  14650. 'quotedblbase': 500,
  14651. 'quotedblright': 500,
  14652. 'guillemotright': 556,
  14653. 'ellipsis': 1000,
  14654. 'perthousand': 1000,
  14655. 'questiondown': 611,
  14656. 'grave': 333,
  14657. 'acute': 333,
  14658. 'circumflex': 333,
  14659. 'tilde': 333,
  14660. 'macron': 333,
  14661. 'breve': 333,
  14662. 'dotaccent': 333,
  14663. 'dieresis': 333,
  14664. 'ring': 333,
  14665. 'cedilla': 333,
  14666. 'hungarumlaut': 333,
  14667. 'ogonek': 333,
  14668. 'caron': 333,
  14669. 'emdash': 1000,
  14670. 'AE': 1000,
  14671. 'ordfeminine': 370,
  14672. 'Lslash': 611,
  14673. 'Oslash': 778,
  14674. 'OE': 1000,
  14675. 'ordmasculine': 365,
  14676. 'ae': 889,
  14677. 'dotlessi': 278,
  14678. 'lslash': 278,
  14679. 'oslash': 611,
  14680. 'oe': 944,
  14681. 'germandbls': 611,
  14682. 'Idieresis': 278,
  14683. 'eacute': 556,
  14684. 'abreve': 556,
  14685. 'uhungarumlaut': 611,
  14686. 'ecaron': 556,
  14687. 'Ydieresis': 667,
  14688. 'divide': 584,
  14689. 'Yacute': 667,
  14690. 'Acircumflex': 722,
  14691. 'aacute': 556,
  14692. 'Ucircumflex': 722,
  14693. 'yacute': 556,
  14694. 'scommaaccent': 556,
  14695. 'ecircumflex': 556,
  14696. 'Uring': 722,
  14697. 'Udieresis': 722,
  14698. 'aogonek': 556,
  14699. 'Uacute': 722,
  14700. 'uogonek': 611,
  14701. 'Edieresis': 667,
  14702. 'Dcroat': 722,
  14703. 'commaaccent': 250,
  14704. 'copyright': 737,
  14705. 'Emacron': 667,
  14706. 'ccaron': 556,
  14707. 'aring': 556,
  14708. 'Ncommaaccent': 722,
  14709. 'lacute': 278,
  14710. 'agrave': 556,
  14711. 'Tcommaaccent': 611,
  14712. 'Cacute': 722,
  14713. 'atilde': 556,
  14714. 'Edotaccent': 667,
  14715. 'scaron': 556,
  14716. 'scedilla': 556,
  14717. 'iacute': 278,
  14718. 'lozenge': 494,
  14719. 'Rcaron': 722,
  14720. 'Gcommaaccent': 778,
  14721. 'ucircumflex': 611,
  14722. 'acircumflex': 556,
  14723. 'Amacron': 722,
  14724. 'rcaron': 389,
  14725. 'ccedilla': 556,
  14726. 'Zdotaccent': 611,
  14727. 'Thorn': 667,
  14728. 'Omacron': 778,
  14729. 'Racute': 722,
  14730. 'Sacute': 667,
  14731. 'dcaron': 743,
  14732. 'Umacron': 722,
  14733. 'uring': 611,
  14734. 'threesuperior': 333,
  14735. 'Ograve': 778,
  14736. 'Agrave': 722,
  14737. 'Abreve': 722,
  14738. 'multiply': 584,
  14739. 'uacute': 611,
  14740. 'Tcaron': 611,
  14741. 'partialdiff': 494,
  14742. 'ydieresis': 556,
  14743. 'Nacute': 722,
  14744. 'icircumflex': 278,
  14745. 'Ecircumflex': 667,
  14746. 'adieresis': 556,
  14747. 'edieresis': 556,
  14748. 'cacute': 556,
  14749. 'nacute': 611,
  14750. 'umacron': 611,
  14751. 'Ncaron': 722,
  14752. 'Iacute': 278,
  14753. 'plusminus': 584,
  14754. 'brokenbar': 280,
  14755. 'registered': 737,
  14756. 'Gbreve': 778,
  14757. 'Idotaccent': 278,
  14758. 'summation': 600,
  14759. 'Egrave': 667,
  14760. 'racute': 389,
  14761. 'omacron': 611,
  14762. 'Zacute': 611,
  14763. 'Zcaron': 611,
  14764. 'greaterequal': 549,
  14765. 'Eth': 722,
  14766. 'Ccedilla': 722,
  14767. 'lcommaaccent': 278,
  14768. 'tcaron': 389,
  14769. 'eogonek': 556,
  14770. 'Uogonek': 722,
  14771. 'Aacute': 722,
  14772. 'Adieresis': 722,
  14773. 'egrave': 556,
  14774. 'zacute': 500,
  14775. 'iogonek': 278,
  14776. 'Oacute': 778,
  14777. 'oacute': 611,
  14778. 'amacron': 556,
  14779. 'sacute': 556,
  14780. 'idieresis': 278,
  14781. 'Ocircumflex': 778,
  14782. 'Ugrave': 722,
  14783. 'Delta': 612,
  14784. 'thorn': 611,
  14785. 'twosuperior': 333,
  14786. 'Odieresis': 778,
  14787. 'mu': 611,
  14788. 'igrave': 278,
  14789. 'ohungarumlaut': 611,
  14790. 'Eogonek': 667,
  14791. 'dcroat': 611,
  14792. 'threequarters': 834,
  14793. 'Scedilla': 667,
  14794. 'lcaron': 400,
  14795. 'Kcommaaccent': 722,
  14796. 'Lacute': 611,
  14797. 'trademark': 1000,
  14798. 'edotaccent': 556,
  14799. 'Igrave': 278,
  14800. 'Imacron': 278,
  14801. 'Lcaron': 611,
  14802. 'onehalf': 834,
  14803. 'lessequal': 549,
  14804. 'ocircumflex': 611,
  14805. 'ntilde': 611,
  14806. 'Uhungarumlaut': 722,
  14807. 'Eacute': 667,
  14808. 'emacron': 556,
  14809. 'gbreve': 611,
  14810. 'onequarter': 834,
  14811. 'Scaron': 667,
  14812. 'Scommaaccent': 667,
  14813. 'Ohungarumlaut': 778,
  14814. 'degree': 400,
  14815. 'ograve': 611,
  14816. 'Ccaron': 722,
  14817. 'ugrave': 611,
  14818. 'radical': 549,
  14819. 'Dcaron': 722,
  14820. 'rcommaaccent': 389,
  14821. 'Ntilde': 722,
  14822. 'otilde': 611,
  14823. 'Rcommaaccent': 722,
  14824. 'Lcommaaccent': 611,
  14825. 'Atilde': 722,
  14826. 'Aogonek': 722,
  14827. 'Aring': 722,
  14828. 'Otilde': 778,
  14829. 'zdotaccent': 500,
  14830. 'Ecaron': 667,
  14831. 'Iogonek': 278,
  14832. 'kcommaaccent': 556,
  14833. 'minus': 584,
  14834. 'Icircumflex': 278,
  14835. 'ncaron': 611,
  14836. 'tcommaaccent': 333,
  14837. 'logicalnot': 584,
  14838. 'odieresis': 611,
  14839. 'udieresis': 611,
  14840. 'notequal': 549,
  14841. 'gcommaaccent': 611,
  14842. 'eth': 611,
  14843. 'zcaron': 500,
  14844. 'ncommaaccent': 611,
  14845. 'onesuperior': 333,
  14846. 'imacron': 278,
  14847. 'Euro': 556
  14848. },
  14849. 'Helvetica-BoldOblique': {
  14850. 'space': 278,
  14851. 'exclam': 333,
  14852. 'quotedbl': 474,
  14853. 'numbersign': 556,
  14854. 'dollar': 556,
  14855. 'percent': 889,
  14856. 'ampersand': 722,
  14857. 'quoteright': 278,
  14858. 'parenleft': 333,
  14859. 'parenright': 333,
  14860. 'asterisk': 389,
  14861. 'plus': 584,
  14862. 'comma': 278,
  14863. 'hyphen': 333,
  14864. 'period': 278,
  14865. 'slash': 278,
  14866. 'zero': 556,
  14867. 'one': 556,
  14868. 'two': 556,
  14869. 'three': 556,
  14870. 'four': 556,
  14871. 'five': 556,
  14872. 'six': 556,
  14873. 'seven': 556,
  14874. 'eight': 556,
  14875. 'nine': 556,
  14876. 'colon': 333,
  14877. 'semicolon': 333,
  14878. 'less': 584,
  14879. 'equal': 584,
  14880. 'greater': 584,
  14881. 'question': 611,
  14882. 'at': 975,
  14883. 'A': 722,
  14884. 'B': 722,
  14885. 'C': 722,
  14886. 'D': 722,
  14887. 'E': 667,
  14888. 'F': 611,
  14889. 'G': 778,
  14890. 'H': 722,
  14891. 'I': 278,
  14892. 'J': 556,
  14893. 'K': 722,
  14894. 'L': 611,
  14895. 'M': 833,
  14896. 'N': 722,
  14897. 'O': 778,
  14898. 'P': 667,
  14899. 'Q': 778,
  14900. 'R': 722,
  14901. 'S': 667,
  14902. 'T': 611,
  14903. 'U': 722,
  14904. 'V': 667,
  14905. 'W': 944,
  14906. 'X': 667,
  14907. 'Y': 667,
  14908. 'Z': 611,
  14909. 'bracketleft': 333,
  14910. 'backslash': 278,
  14911. 'bracketright': 333,
  14912. 'asciicircum': 584,
  14913. 'underscore': 556,
  14914. 'quoteleft': 278,
  14915. 'a': 556,
  14916. 'b': 611,
  14917. 'c': 556,
  14918. 'd': 611,
  14919. 'e': 556,
  14920. 'f': 333,
  14921. 'g': 611,
  14922. 'h': 611,
  14923. 'i': 278,
  14924. 'j': 278,
  14925. 'k': 556,
  14926. 'l': 278,
  14927. 'm': 889,
  14928. 'n': 611,
  14929. 'o': 611,
  14930. 'p': 611,
  14931. 'q': 611,
  14932. 'r': 389,
  14933. 's': 556,
  14934. 't': 333,
  14935. 'u': 611,
  14936. 'v': 556,
  14937. 'w': 778,
  14938. 'x': 556,
  14939. 'y': 556,
  14940. 'z': 500,
  14941. 'braceleft': 389,
  14942. 'bar': 280,
  14943. 'braceright': 389,
  14944. 'asciitilde': 584,
  14945. 'exclamdown': 333,
  14946. 'cent': 556,
  14947. 'sterling': 556,
  14948. 'fraction': 167,
  14949. 'yen': 556,
  14950. 'florin': 556,
  14951. 'section': 556,
  14952. 'currency': 556,
  14953. 'quotesingle': 238,
  14954. 'quotedblleft': 500,
  14955. 'guillemotleft': 556,
  14956. 'guilsinglleft': 333,
  14957. 'guilsinglright': 333,
  14958. 'fi': 611,
  14959. 'fl': 611,
  14960. 'endash': 556,
  14961. 'dagger': 556,
  14962. 'daggerdbl': 556,
  14963. 'periodcentered': 278,
  14964. 'paragraph': 556,
  14965. 'bullet': 350,
  14966. 'quotesinglbase': 278,
  14967. 'quotedblbase': 500,
  14968. 'quotedblright': 500,
  14969. 'guillemotright': 556,
  14970. 'ellipsis': 1000,
  14971. 'perthousand': 1000,
  14972. 'questiondown': 611,
  14973. 'grave': 333,
  14974. 'acute': 333,
  14975. 'circumflex': 333,
  14976. 'tilde': 333,
  14977. 'macron': 333,
  14978. 'breve': 333,
  14979. 'dotaccent': 333,
  14980. 'dieresis': 333,
  14981. 'ring': 333,
  14982. 'cedilla': 333,
  14983. 'hungarumlaut': 333,
  14984. 'ogonek': 333,
  14985. 'caron': 333,
  14986. 'emdash': 1000,
  14987. 'AE': 1000,
  14988. 'ordfeminine': 370,
  14989. 'Lslash': 611,
  14990. 'Oslash': 778,
  14991. 'OE': 1000,
  14992. 'ordmasculine': 365,
  14993. 'ae': 889,
  14994. 'dotlessi': 278,
  14995. 'lslash': 278,
  14996. 'oslash': 611,
  14997. 'oe': 944,
  14998. 'germandbls': 611,
  14999. 'Idieresis': 278,
  15000. 'eacute': 556,
  15001. 'abreve': 556,
  15002. 'uhungarumlaut': 611,
  15003. 'ecaron': 556,
  15004. 'Ydieresis': 667,
  15005. 'divide': 584,
  15006. 'Yacute': 667,
  15007. 'Acircumflex': 722,
  15008. 'aacute': 556,
  15009. 'Ucircumflex': 722,
  15010. 'yacute': 556,
  15011. 'scommaaccent': 556,
  15012. 'ecircumflex': 556,
  15013. 'Uring': 722,
  15014. 'Udieresis': 722,
  15015. 'aogonek': 556,
  15016. 'Uacute': 722,
  15017. 'uogonek': 611,
  15018. 'Edieresis': 667,
  15019. 'Dcroat': 722,
  15020. 'commaaccent': 250,
  15021. 'copyright': 737,
  15022. 'Emacron': 667,
  15023. 'ccaron': 556,
  15024. 'aring': 556,
  15025. 'Ncommaaccent': 722,
  15026. 'lacute': 278,
  15027. 'agrave': 556,
  15028. 'Tcommaaccent': 611,
  15029. 'Cacute': 722,
  15030. 'atilde': 556,
  15031. 'Edotaccent': 667,
  15032. 'scaron': 556,
  15033. 'scedilla': 556,
  15034. 'iacute': 278,
  15035. 'lozenge': 494,
  15036. 'Rcaron': 722,
  15037. 'Gcommaaccent': 778,
  15038. 'ucircumflex': 611,
  15039. 'acircumflex': 556,
  15040. 'Amacron': 722,
  15041. 'rcaron': 389,
  15042. 'ccedilla': 556,
  15043. 'Zdotaccent': 611,
  15044. 'Thorn': 667,
  15045. 'Omacron': 778,
  15046. 'Racute': 722,
  15047. 'Sacute': 667,
  15048. 'dcaron': 743,
  15049. 'Umacron': 722,
  15050. 'uring': 611,
  15051. 'threesuperior': 333,
  15052. 'Ograve': 778,
  15053. 'Agrave': 722,
  15054. 'Abreve': 722,
  15055. 'multiply': 584,
  15056. 'uacute': 611,
  15057. 'Tcaron': 611,
  15058. 'partialdiff': 494,
  15059. 'ydieresis': 556,
  15060. 'Nacute': 722,
  15061. 'icircumflex': 278,
  15062. 'Ecircumflex': 667,
  15063. 'adieresis': 556,
  15064. 'edieresis': 556,
  15065. 'cacute': 556,
  15066. 'nacute': 611,
  15067. 'umacron': 611,
  15068. 'Ncaron': 722,
  15069. 'Iacute': 278,
  15070. 'plusminus': 584,
  15071. 'brokenbar': 280,
  15072. 'registered': 737,
  15073. 'Gbreve': 778,
  15074. 'Idotaccent': 278,
  15075. 'summation': 600,
  15076. 'Egrave': 667,
  15077. 'racute': 389,
  15078. 'omacron': 611,
  15079. 'Zacute': 611,
  15080. 'Zcaron': 611,
  15081. 'greaterequal': 549,
  15082. 'Eth': 722,
  15083. 'Ccedilla': 722,
  15084. 'lcommaaccent': 278,
  15085. 'tcaron': 389,
  15086. 'eogonek': 556,
  15087. 'Uogonek': 722,
  15088. 'Aacute': 722,
  15089. 'Adieresis': 722,
  15090. 'egrave': 556,
  15091. 'zacute': 500,
  15092. 'iogonek': 278,
  15093. 'Oacute': 778,
  15094. 'oacute': 611,
  15095. 'amacron': 556,
  15096. 'sacute': 556,
  15097. 'idieresis': 278,
  15098. 'Ocircumflex': 778,
  15099. 'Ugrave': 722,
  15100. 'Delta': 612,
  15101. 'thorn': 611,
  15102. 'twosuperior': 333,
  15103. 'Odieresis': 778,
  15104. 'mu': 611,
  15105. 'igrave': 278,
  15106. 'ohungarumlaut': 611,
  15107. 'Eogonek': 667,
  15108. 'dcroat': 611,
  15109. 'threequarters': 834,
  15110. 'Scedilla': 667,
  15111. 'lcaron': 400,
  15112. 'Kcommaaccent': 722,
  15113. 'Lacute': 611,
  15114. 'trademark': 1000,
  15115. 'edotaccent': 556,
  15116. 'Igrave': 278,
  15117. 'Imacron': 278,
  15118. 'Lcaron': 611,
  15119. 'onehalf': 834,
  15120. 'lessequal': 549,
  15121. 'ocircumflex': 611,
  15122. 'ntilde': 611,
  15123. 'Uhungarumlaut': 722,
  15124. 'Eacute': 667,
  15125. 'emacron': 556,
  15126. 'gbreve': 611,
  15127. 'onequarter': 834,
  15128. 'Scaron': 667,
  15129. 'Scommaaccent': 667,
  15130. 'Ohungarumlaut': 778,
  15131. 'degree': 400,
  15132. 'ograve': 611,
  15133. 'Ccaron': 722,
  15134. 'ugrave': 611,
  15135. 'radical': 549,
  15136. 'Dcaron': 722,
  15137. 'rcommaaccent': 389,
  15138. 'Ntilde': 722,
  15139. 'otilde': 611,
  15140. 'Rcommaaccent': 722,
  15141. 'Lcommaaccent': 611,
  15142. 'Atilde': 722,
  15143. 'Aogonek': 722,
  15144. 'Aring': 722,
  15145. 'Otilde': 778,
  15146. 'zdotaccent': 500,
  15147. 'Ecaron': 667,
  15148. 'Iogonek': 278,
  15149. 'kcommaaccent': 556,
  15150. 'minus': 584,
  15151. 'Icircumflex': 278,
  15152. 'ncaron': 611,
  15153. 'tcommaaccent': 333,
  15154. 'logicalnot': 584,
  15155. 'odieresis': 611,
  15156. 'udieresis': 611,
  15157. 'notequal': 549,
  15158. 'gcommaaccent': 611,
  15159. 'eth': 611,
  15160. 'zcaron': 500,
  15161. 'ncommaaccent': 611,
  15162. 'onesuperior': 333,
  15163. 'imacron': 278,
  15164. 'Euro': 556
  15165. },
  15166. 'Helvetica-Oblique' : {
  15167. 'space': 278,
  15168. 'exclam': 278,
  15169. 'quotedbl': 355,
  15170. 'numbersign': 556,
  15171. 'dollar': 556,
  15172. 'percent': 889,
  15173. 'ampersand': 667,
  15174. 'quoteright': 222,
  15175. 'parenleft': 333,
  15176. 'parenright': 333,
  15177. 'asterisk': 389,
  15178. 'plus': 584,
  15179. 'comma': 278,
  15180. 'hyphen': 333,
  15181. 'period': 278,
  15182. 'slash': 278,
  15183. 'zero': 556,
  15184. 'one': 556,
  15185. 'two': 556,
  15186. 'three': 556,
  15187. 'four': 556,
  15188. 'five': 556,
  15189. 'six': 556,
  15190. 'seven': 556,
  15191. 'eight': 556,
  15192. 'nine': 556,
  15193. 'colon': 278,
  15194. 'semicolon': 278,
  15195. 'less': 584,
  15196. 'equal': 584,
  15197. 'greater': 584,
  15198. 'question': 556,
  15199. 'at': 1015,
  15200. 'A': 667,
  15201. 'B': 667,
  15202. 'C': 722,
  15203. 'D': 722,
  15204. 'E': 667,
  15205. 'F': 611,
  15206. 'G': 778,
  15207. 'H': 722,
  15208. 'I': 278,
  15209. 'J': 500,
  15210. 'K': 667,
  15211. 'L': 556,
  15212. 'M': 833,
  15213. 'N': 722,
  15214. 'O': 778,
  15215. 'P': 667,
  15216. 'Q': 778,
  15217. 'R': 722,
  15218. 'S': 667,
  15219. 'T': 611,
  15220. 'U': 722,
  15221. 'V': 667,
  15222. 'W': 944,
  15223. 'X': 667,
  15224. 'Y': 667,
  15225. 'Z': 611,
  15226. 'bracketleft': 278,
  15227. 'backslash': 278,
  15228. 'bracketright': 278,
  15229. 'asciicircum': 469,
  15230. 'underscore': 556,
  15231. 'quoteleft': 222,
  15232. 'a': 556,
  15233. 'b': 556,
  15234. 'c': 500,
  15235. 'd': 556,
  15236. 'e': 556,
  15237. 'f': 278,
  15238. 'g': 556,
  15239. 'h': 556,
  15240. 'i': 222,
  15241. 'j': 222,
  15242. 'k': 500,
  15243. 'l': 222,
  15244. 'm': 833,
  15245. 'n': 556,
  15246. 'o': 556,
  15247. 'p': 556,
  15248. 'q': 556,
  15249. 'r': 333,
  15250. 's': 500,
  15251. 't': 278,
  15252. 'u': 556,
  15253. 'v': 500,
  15254. 'w': 722,
  15255. 'x': 500,
  15256. 'y': 500,
  15257. 'z': 500,
  15258. 'braceleft': 334,
  15259. 'bar': 260,
  15260. 'braceright': 334,
  15261. 'asciitilde': 584,
  15262. 'exclamdown': 333,
  15263. 'cent': 556,
  15264. 'sterling': 556,
  15265. 'fraction': 167,
  15266. 'yen': 556,
  15267. 'florin': 556,
  15268. 'section': 556,
  15269. 'currency': 556,
  15270. 'quotesingle': 191,
  15271. 'quotedblleft': 333,
  15272. 'guillemotleft': 556,
  15273. 'guilsinglleft': 333,
  15274. 'guilsinglright': 333,
  15275. 'fi': 500,
  15276. 'fl': 500,
  15277. 'endash': 556,
  15278. 'dagger': 556,
  15279. 'daggerdbl': 556,
  15280. 'periodcentered': 278,
  15281. 'paragraph': 537,
  15282. 'bullet': 350,
  15283. 'quotesinglbase': 222,
  15284. 'quotedblbase': 333,
  15285. 'quotedblright': 333,
  15286. 'guillemotright': 556,
  15287. 'ellipsis': 1000,
  15288. 'perthousand': 1000,
  15289. 'questiondown': 611,
  15290. 'grave': 333,
  15291. 'acute': 333,
  15292. 'circumflex': 333,
  15293. 'tilde': 333,
  15294. 'macron': 333,
  15295. 'breve': 333,
  15296. 'dotaccent': 333,
  15297. 'dieresis': 333,
  15298. 'ring': 333,
  15299. 'cedilla': 333,
  15300. 'hungarumlaut': 333,
  15301. 'ogonek': 333,
  15302. 'caron': 333,
  15303. 'emdash': 1000,
  15304. 'AE': 1000,
  15305. 'ordfeminine': 370,
  15306. 'Lslash': 556,
  15307. 'Oslash': 778,
  15308. 'OE': 1000,
  15309. 'ordmasculine': 365,
  15310. 'ae': 889,
  15311. 'dotlessi': 278,
  15312. 'lslash': 222,
  15313. 'oslash': 611,
  15314. 'oe': 944,
  15315. 'germandbls': 611,
  15316. 'Idieresis': 278,
  15317. 'eacute': 556,
  15318. 'abreve': 556,
  15319. 'uhungarumlaut': 556,
  15320. 'ecaron': 556,
  15321. 'Ydieresis': 667,
  15322. 'divide': 584,
  15323. 'Yacute': 667,
  15324. 'Acircumflex': 667,
  15325. 'aacute': 556,
  15326. 'Ucircumflex': 722,
  15327. 'yacute': 500,
  15328. 'scommaaccent': 500,
  15329. 'ecircumflex': 556,
  15330. 'Uring': 722,
  15331. 'Udieresis': 722,
  15332. 'aogonek': 556,
  15333. 'Uacute': 722,
  15334. 'uogonek': 556,
  15335. 'Edieresis': 667,
  15336. 'Dcroat': 722,
  15337. 'commaaccent': 250,
  15338. 'copyright': 737,
  15339. 'Emacron': 667,
  15340. 'ccaron': 500,
  15341. 'aring': 556,
  15342. 'Ncommaaccent': 722,
  15343. 'lacute': 222,
  15344. 'agrave': 556,
  15345. 'Tcommaaccent': 611,
  15346. 'Cacute': 722,
  15347. 'atilde': 556,
  15348. 'Edotaccent': 667,
  15349. 'scaron': 500,
  15350. 'scedilla': 500,
  15351. 'iacute': 278,
  15352. 'lozenge': 471,
  15353. 'Rcaron': 722,
  15354. 'Gcommaaccent': 778,
  15355. 'ucircumflex': 556,
  15356. 'acircumflex': 556,
  15357. 'Amacron': 667,
  15358. 'rcaron': 333,
  15359. 'ccedilla': 500,
  15360. 'Zdotaccent': 611,
  15361. 'Thorn': 667,
  15362. 'Omacron': 778,
  15363. 'Racute': 722,
  15364. 'Sacute': 667,
  15365. 'dcaron': 643,
  15366. 'Umacron': 722,
  15367. 'uring': 556,
  15368. 'threesuperior': 333,
  15369. 'Ograve': 778,
  15370. 'Agrave': 667,
  15371. 'Abreve': 667,
  15372. 'multiply': 584,
  15373. 'uacute': 556,
  15374. 'Tcaron': 611,
  15375. 'partialdiff': 476,
  15376. 'ydieresis': 500,
  15377. 'Nacute': 722,
  15378. 'icircumflex': 278,
  15379. 'Ecircumflex': 667,
  15380. 'adieresis': 556,
  15381. 'edieresis': 556,
  15382. 'cacute': 500,
  15383. 'nacute': 556,
  15384. 'umacron': 556,
  15385. 'Ncaron': 722,
  15386. 'Iacute': 278,
  15387. 'plusminus': 584,
  15388. 'brokenbar': 260,
  15389. 'registered': 737,
  15390. 'Gbreve': 778,
  15391. 'Idotaccent': 278,
  15392. 'summation': 600,
  15393. 'Egrave': 667,
  15394. 'racute': 333,
  15395. 'omacron': 556,
  15396. 'Zacute': 611,
  15397. 'Zcaron': 611,
  15398. 'greaterequal': 549,
  15399. 'Eth': 722,
  15400. 'Ccedilla': 722,
  15401. 'lcommaaccent': 222,
  15402. 'tcaron': 317,
  15403. 'eogonek': 556,
  15404. 'Uogonek': 722,
  15405. 'Aacute': 667,
  15406. 'Adieresis': 667,
  15407. 'egrave': 556,
  15408. 'zacute': 500,
  15409. 'iogonek': 222,
  15410. 'Oacute': 778,
  15411. 'oacute': 556,
  15412. 'amacron': 556,
  15413. 'sacute': 500,
  15414. 'idieresis': 278,
  15415. 'Ocircumflex': 778,
  15416. 'Ugrave': 722,
  15417. 'Delta': 612,
  15418. 'thorn': 556,
  15419. 'twosuperior': 333,
  15420. 'Odieresis': 778,
  15421. 'mu': 556,
  15422. 'igrave': 278,
  15423. 'ohungarumlaut': 556,
  15424. 'Eogonek': 667,
  15425. 'dcroat': 556,
  15426. 'threequarters': 834,
  15427. 'Scedilla': 667,
  15428. 'lcaron': 299,
  15429. 'Kcommaaccent': 667,
  15430. 'Lacute': 556,
  15431. 'trademark': 1000,
  15432. 'edotaccent': 556,
  15433. 'Igrave': 278,
  15434. 'Imacron': 278,
  15435. 'Lcaron': 556,
  15436. 'onehalf': 834,
  15437. 'lessequal': 549,
  15438. 'ocircumflex': 556,
  15439. 'ntilde': 556,
  15440. 'Uhungarumlaut': 722,
  15441. 'Eacute': 667,
  15442. 'emacron': 556,
  15443. 'gbreve': 556,
  15444. 'onequarter': 834,
  15445. 'Scaron': 667,
  15446. 'Scommaaccent': 667,
  15447. 'Ohungarumlaut': 778,
  15448. 'degree': 400,
  15449. 'ograve': 556,
  15450. 'Ccaron': 722,
  15451. 'ugrave': 556,
  15452. 'radical': 453,
  15453. 'Dcaron': 722,
  15454. 'rcommaaccent': 333,
  15455. 'Ntilde': 722,
  15456. 'otilde': 556,
  15457. 'Rcommaaccent': 722,
  15458. 'Lcommaaccent': 556,
  15459. 'Atilde': 667,
  15460. 'Aogonek': 667,
  15461. 'Aring': 667,
  15462. 'Otilde': 778,
  15463. 'zdotaccent': 500,
  15464. 'Ecaron': 667,
  15465. 'Iogonek': 278,
  15466. 'kcommaaccent': 500,
  15467. 'minus': 584,
  15468. 'Icircumflex': 278,
  15469. 'ncaron': 556,
  15470. 'tcommaaccent': 278,
  15471. 'logicalnot': 584,
  15472. 'odieresis': 556,
  15473. 'udieresis': 556,
  15474. 'notequal': 549,
  15475. 'gcommaaccent': 556,
  15476. 'eth': 556,
  15477. 'zcaron': 500,
  15478. 'ncommaaccent': 556,
  15479. 'onesuperior': 333,
  15480. 'imacron': 278,
  15481. 'Euro': 556
  15482. },
  15483. 'Symbol': {
  15484. 'space': 250,
  15485. 'exclam': 333,
  15486. 'universal': 713,
  15487. 'numbersign': 500,
  15488. 'existential': 549,
  15489. 'percent': 833,
  15490. 'ampersand': 778,
  15491. 'suchthat': 439,
  15492. 'parenleft': 333,
  15493. 'parenright': 333,
  15494. 'asteriskmath': 500,
  15495. 'plus': 549,
  15496. 'comma': 250,
  15497. 'minus': 549,
  15498. 'period': 250,
  15499. 'slash': 278,
  15500. 'zero': 500,
  15501. 'one': 500,
  15502. 'two': 500,
  15503. 'three': 500,
  15504. 'four': 500,
  15505. 'five': 500,
  15506. 'six': 500,
  15507. 'seven': 500,
  15508. 'eight': 500,
  15509. 'nine': 500,
  15510. 'colon': 278,
  15511. 'semicolon': 278,
  15512. 'less': 549,
  15513. 'equal': 549,
  15514. 'greater': 549,
  15515. 'question': 444,
  15516. 'congruent': 549,
  15517. 'Alpha': 722,
  15518. 'Beta': 667,
  15519. 'Chi': 722,
  15520. 'Delta': 612,
  15521. 'Epsilon': 611,
  15522. 'Phi': 763,
  15523. 'Gamma': 603,
  15524. 'Eta': 722,
  15525. 'Iota': 333,
  15526. 'theta1': 631,
  15527. 'Kappa': 722,
  15528. 'Lambda': 686,
  15529. 'Mu': 889,
  15530. 'Nu': 722,
  15531. 'Omicron': 722,
  15532. 'Pi': 768,
  15533. 'Theta': 741,
  15534. 'Rho': 556,
  15535. 'Sigma': 592,
  15536. 'Tau': 611,
  15537. 'Upsilon': 690,
  15538. 'sigma1': 439,
  15539. 'Omega': 768,
  15540. 'Xi': 645,
  15541. 'Psi': 795,
  15542. 'Zeta': 611,
  15543. 'bracketleft': 333,
  15544. 'therefore': 863,
  15545. 'bracketright': 333,
  15546. 'perpendicular': 658,
  15547. 'underscore': 500,
  15548. 'radicalex': 500,
  15549. 'alpha': 631,
  15550. 'beta': 549,
  15551. 'chi': 549,
  15552. 'delta': 494,
  15553. 'epsilon': 439,
  15554. 'phi': 521,
  15555. 'gamma': 411,
  15556. 'eta': 603,
  15557. 'iota': 329,
  15558. 'phi1': 603,
  15559. 'kappa': 549,
  15560. 'lambda': 549,
  15561. 'mu': 576,
  15562. 'nu': 521,
  15563. 'omicron': 549,
  15564. 'pi': 549,
  15565. 'theta': 521,
  15566. 'rho': 549,
  15567. 'sigma': 603,
  15568. 'tau': 439,
  15569. 'upsilon': 576,
  15570. 'omega1': 713,
  15571. 'omega': 686,
  15572. 'xi': 493,
  15573. 'psi': 686,
  15574. 'zeta': 494,
  15575. 'braceleft': 480,
  15576. 'bar': 200,
  15577. 'braceright': 480,
  15578. 'similar': 549,
  15579. 'Euro': 750,
  15580. 'Upsilon1': 620,
  15581. 'minute': 247,
  15582. 'lessequal': 549,
  15583. 'fraction': 167,
  15584. 'infinity': 713,
  15585. 'florin': 500,
  15586. 'club': 753,
  15587. 'diamond': 753,
  15588. 'heart': 753,
  15589. 'spade': 753,
  15590. 'arrowboth': 1042,
  15591. 'arrowleft': 987,
  15592. 'arrowup': 603,
  15593. 'arrowright': 987,
  15594. 'arrowdown': 603,
  15595. 'degree': 400,
  15596. 'plusminus': 549,
  15597. 'second': 411,
  15598. 'greaterequal': 549,
  15599. 'multiply': 549,
  15600. 'proportional': 713,
  15601. 'partialdiff': 494,
  15602. 'bullet': 460,
  15603. 'divide': 549,
  15604. 'notequal': 549,
  15605. 'equivalence': 549,
  15606. 'approxequal': 549,
  15607. 'ellipsis': 1000,
  15608. 'arrowvertex': 603,
  15609. 'arrowhorizex': 1000,
  15610. 'carriagereturn': 658,
  15611. 'aleph': 823,
  15612. 'Ifraktur': 686,
  15613. 'Rfraktur': 795,
  15614. 'weierstrass': 987,
  15615. 'circlemultiply': 768,
  15616. 'circleplus': 768,
  15617. 'emptyset': 823,
  15618. 'intersection': 768,
  15619. 'union': 768,
  15620. 'propersuperset': 713,
  15621. 'reflexsuperset': 713,
  15622. 'notsubset': 713,
  15623. 'propersubset': 713,
  15624. 'reflexsubset': 713,
  15625. 'element': 713,
  15626. 'notelement': 713,
  15627. 'angle': 768,
  15628. 'gradient': 713,
  15629. 'registerserif': 790,
  15630. 'copyrightserif': 790,
  15631. 'trademarkserif': 890,
  15632. 'product': 823,
  15633. 'radical': 549,
  15634. 'dotmath': 250,
  15635. 'logicalnot': 713,
  15636. 'logicaland': 603,
  15637. 'logicalor': 603,
  15638. 'arrowdblboth': 1042,
  15639. 'arrowdblleft': 987,
  15640. 'arrowdblup': 603,
  15641. 'arrowdblright': 987,
  15642. 'arrowdbldown': 603,
  15643. 'lozenge': 494,
  15644. 'angleleft': 329,
  15645. 'registersans': 790,
  15646. 'copyrightsans': 790,
  15647. 'trademarksans': 786,
  15648. 'summation': 713,
  15649. 'parenlefttp': 384,
  15650. 'parenleftex': 384,
  15651. 'parenleftbt': 384,
  15652. 'bracketlefttp': 384,
  15653. 'bracketleftex': 384,
  15654. 'bracketleftbt': 384,
  15655. 'bracelefttp': 494,
  15656. 'braceleftmid': 494,
  15657. 'braceleftbt': 494,
  15658. 'braceex': 494,
  15659. 'angleright': 329,
  15660. 'integral': 274,
  15661. 'integraltp': 686,
  15662. 'integralex': 686,
  15663. 'integralbt': 686,
  15664. 'parenrighttp': 384,
  15665. 'parenrightex': 384,
  15666. 'parenrightbt': 384,
  15667. 'bracketrighttp': 384,
  15668. 'bracketrightex': 384,
  15669. 'bracketrightbt': 384,
  15670. 'bracerighttp': 494,
  15671. 'bracerightmid': 494,
  15672. 'bracerightbt': 494,
  15673. 'apple': 790
  15674. },
  15675. 'Times-Roman': {
  15676. 'space': 250,
  15677. 'exclam': 333,
  15678. 'quotedbl': 408,
  15679. 'numbersign': 500,
  15680. 'dollar': 500,
  15681. 'percent': 833,
  15682. 'ampersand': 778,
  15683. 'quoteright': 333,
  15684. 'parenleft': 333,
  15685. 'parenright': 333,
  15686. 'asterisk': 500,
  15687. 'plus': 564,
  15688. 'comma': 250,
  15689. 'hyphen': 333,
  15690. 'period': 250,
  15691. 'slash': 278,
  15692. 'zero': 500,
  15693. 'one': 500,
  15694. 'two': 500,
  15695. 'three': 500,
  15696. 'four': 500,
  15697. 'five': 500,
  15698. 'six': 500,
  15699. 'seven': 500,
  15700. 'eight': 500,
  15701. 'nine': 500,
  15702. 'colon': 278,
  15703. 'semicolon': 278,
  15704. 'less': 564,
  15705. 'equal': 564,
  15706. 'greater': 564,
  15707. 'question': 444,
  15708. 'at': 921,
  15709. 'A': 722,
  15710. 'B': 667,
  15711. 'C': 667,
  15712. 'D': 722,
  15713. 'E': 611,
  15714. 'F': 556,
  15715. 'G': 722,
  15716. 'H': 722,
  15717. 'I': 333,
  15718. 'J': 389,
  15719. 'K': 722,
  15720. 'L': 611,
  15721. 'M': 889,
  15722. 'N': 722,
  15723. 'O': 722,
  15724. 'P': 556,
  15725. 'Q': 722,
  15726. 'R': 667,
  15727. 'S': 556,
  15728. 'T': 611,
  15729. 'U': 722,
  15730. 'V': 722,
  15731. 'W': 944,
  15732. 'X': 722,
  15733. 'Y': 722,
  15734. 'Z': 611,
  15735. 'bracketleft': 333,
  15736. 'backslash': 278,
  15737. 'bracketright': 333,
  15738. 'asciicircum': 469,
  15739. 'underscore': 500,
  15740. 'quoteleft': 333,
  15741. 'a': 444,
  15742. 'b': 500,
  15743. 'c': 444,
  15744. 'd': 500,
  15745. 'e': 444,
  15746. 'f': 333,
  15747. 'g': 500,
  15748. 'h': 500,
  15749. 'i': 278,
  15750. 'j': 278,
  15751. 'k': 500,
  15752. 'l': 278,
  15753. 'm': 778,
  15754. 'n': 500,
  15755. 'o': 500,
  15756. 'p': 500,
  15757. 'q': 500,
  15758. 'r': 333,
  15759. 's': 389,
  15760. 't': 278,
  15761. 'u': 500,
  15762. 'v': 500,
  15763. 'w': 722,
  15764. 'x': 500,
  15765. 'y': 500,
  15766. 'z': 444,
  15767. 'braceleft': 480,
  15768. 'bar': 200,
  15769. 'braceright': 480,
  15770. 'asciitilde': 541,
  15771. 'exclamdown': 333,
  15772. 'cent': 500,
  15773. 'sterling': 500,
  15774. 'fraction': 167,
  15775. 'yen': 500,
  15776. 'florin': 500,
  15777. 'section': 500,
  15778. 'currency': 500,
  15779. 'quotesingle': 180,
  15780. 'quotedblleft': 444,
  15781. 'guillemotleft': 500,
  15782. 'guilsinglleft': 333,
  15783. 'guilsinglright': 333,
  15784. 'fi': 556,
  15785. 'fl': 556,
  15786. 'endash': 500,
  15787. 'dagger': 500,
  15788. 'daggerdbl': 500,
  15789. 'periodcentered': 250,
  15790. 'paragraph': 453,
  15791. 'bullet': 350,
  15792. 'quotesinglbase': 333,
  15793. 'quotedblbase': 444,
  15794. 'quotedblright': 444,
  15795. 'guillemotright': 500,
  15796. 'ellipsis': 1000,
  15797. 'perthousand': 1000,
  15798. 'questiondown': 444,
  15799. 'grave': 333,
  15800. 'acute': 333,
  15801. 'circumflex': 333,
  15802. 'tilde': 333,
  15803. 'macron': 333,
  15804. 'breve': 333,
  15805. 'dotaccent': 333,
  15806. 'dieresis': 333,
  15807. 'ring': 333,
  15808. 'cedilla': 333,
  15809. 'hungarumlaut': 333,
  15810. 'ogonek': 333,
  15811. 'caron': 333,
  15812. 'emdash': 1000,
  15813. 'AE': 889,
  15814. 'ordfeminine': 276,
  15815. 'Lslash': 611,
  15816. 'Oslash': 722,
  15817. 'OE': 889,
  15818. 'ordmasculine': 310,
  15819. 'ae': 667,
  15820. 'dotlessi': 278,
  15821. 'lslash': 278,
  15822. 'oslash': 500,
  15823. 'oe': 722,
  15824. 'germandbls': 500,
  15825. 'Idieresis': 333,
  15826. 'eacute': 444,
  15827. 'abreve': 444,
  15828. 'uhungarumlaut': 500,
  15829. 'ecaron': 444,
  15830. 'Ydieresis': 722,
  15831. 'divide': 564,
  15832. 'Yacute': 722,
  15833. 'Acircumflex': 722,
  15834. 'aacute': 444,
  15835. 'Ucircumflex': 722,
  15836. 'yacute': 500,
  15837. 'scommaaccent': 389,
  15838. 'ecircumflex': 444,
  15839. 'Uring': 722,
  15840. 'Udieresis': 722,
  15841. 'aogonek': 444,
  15842. 'Uacute': 722,
  15843. 'uogonek': 500,
  15844. 'Edieresis': 611,
  15845. 'Dcroat': 722,
  15846. 'commaaccent': 250,
  15847. 'copyright': 760,
  15848. 'Emacron': 611,
  15849. 'ccaron': 444,
  15850. 'aring': 444,
  15851. 'Ncommaaccent': 722,
  15852. 'lacute': 278,
  15853. 'agrave': 444,
  15854. 'Tcommaaccent': 611,
  15855. 'Cacute': 667,
  15856. 'atilde': 444,
  15857. 'Edotaccent': 611,
  15858. 'scaron': 389,
  15859. 'scedilla': 389,
  15860. 'iacute': 278,
  15861. 'lozenge': 471,
  15862. 'Rcaron': 667,
  15863. 'Gcommaaccent': 722,
  15864. 'ucircumflex': 500,
  15865. 'acircumflex': 444,
  15866. 'Amacron': 722,
  15867. 'rcaron': 333,
  15868. 'ccedilla': 444,
  15869. 'Zdotaccent': 611,
  15870. 'Thorn': 556,
  15871. 'Omacron': 722,
  15872. 'Racute': 667,
  15873. 'Sacute': 556,
  15874. 'dcaron': 588,
  15875. 'Umacron': 722,
  15876. 'uring': 500,
  15877. 'threesuperior': 300,
  15878. 'Ograve': 722,
  15879. 'Agrave': 722,
  15880. 'Abreve': 722,
  15881. 'multiply': 564,
  15882. 'uacute': 500,
  15883. 'Tcaron': 611,
  15884. 'partialdiff': 476,
  15885. 'ydieresis': 500,
  15886. 'Nacute': 722,
  15887. 'icircumflex': 278,
  15888. 'Ecircumflex': 611,
  15889. 'adieresis': 444,
  15890. 'edieresis': 444,
  15891. 'cacute': 444,
  15892. 'nacute': 500,
  15893. 'umacron': 500,
  15894. 'Ncaron': 722,
  15895. 'Iacute': 333,
  15896. 'plusminus': 564,
  15897. 'brokenbar': 200,
  15898. 'registered': 760,
  15899. 'Gbreve': 722,
  15900. 'Idotaccent': 333,
  15901. 'summation': 600,
  15902. 'Egrave': 611,
  15903. 'racute': 333,
  15904. 'omacron': 500,
  15905. 'Zacute': 611,
  15906. 'Zcaron': 611,
  15907. 'greaterequal': 549,
  15908. 'Eth': 722,
  15909. 'Ccedilla': 667,
  15910. 'lcommaaccent': 278,
  15911. 'tcaron': 326,
  15912. 'eogonek': 444,
  15913. 'Uogonek': 722,
  15914. 'Aacute': 722,
  15915. 'Adieresis': 722,
  15916. 'egrave': 444,
  15917. 'zacute': 444,
  15918. 'iogonek': 278,
  15919. 'Oacute': 722,
  15920. 'oacute': 500,
  15921. 'amacron': 444,
  15922. 'sacute': 389,
  15923. 'idieresis': 278,
  15924. 'Ocircumflex': 722,
  15925. 'Ugrave': 722,
  15926. 'Delta': 612,
  15927. 'thorn': 500,
  15928. 'twosuperior': 300,
  15929. 'Odieresis': 722,
  15930. 'mu': 500,
  15931. 'igrave': 278,
  15932. 'ohungarumlaut': 500,
  15933. 'Eogonek': 611,
  15934. 'dcroat': 500,
  15935. 'threequarters': 750,
  15936. 'Scedilla': 556,
  15937. 'lcaron': 344,
  15938. 'Kcommaaccent': 722,
  15939. 'Lacute': 611,
  15940. 'trademark': 980,
  15941. 'edotaccent': 444,
  15942. 'Igrave': 333,
  15943. 'Imacron': 333,
  15944. 'Lcaron': 611,
  15945. 'onehalf': 750,
  15946. 'lessequal': 549,
  15947. 'ocircumflex': 500,
  15948. 'ntilde': 500,
  15949. 'Uhungarumlaut': 722,
  15950. 'Eacute': 611,
  15951. 'emacron': 444,
  15952. 'gbreve': 500,
  15953. 'onequarter': 750,
  15954. 'Scaron': 556,
  15955. 'Scommaaccent': 556,
  15956. 'Ohungarumlaut': 722,
  15957. 'degree': 400,
  15958. 'ograve': 500,
  15959. 'Ccaron': 667,
  15960. 'ugrave': 500,
  15961. 'radical': 453,
  15962. 'Dcaron': 722,
  15963. 'rcommaaccent': 333,
  15964. 'Ntilde': 722,
  15965. 'otilde': 500,
  15966. 'Rcommaaccent': 667,
  15967. 'Lcommaaccent': 611,
  15968. 'Atilde': 722,
  15969. 'Aogonek': 722,
  15970. 'Aring': 722,
  15971. 'Otilde': 722,
  15972. 'zdotaccent': 444,
  15973. 'Ecaron': 611,
  15974. 'Iogonek': 333,
  15975. 'kcommaaccent': 500,
  15976. 'minus': 564,
  15977. 'Icircumflex': 333,
  15978. 'ncaron': 500,
  15979. 'tcommaaccent': 278,
  15980. 'logicalnot': 564,
  15981. 'odieresis': 500,
  15982. 'udieresis': 500,
  15983. 'notequal': 549,
  15984. 'gcommaaccent': 500,
  15985. 'eth': 500,
  15986. 'zcaron': 444,
  15987. 'ncommaaccent': 500,
  15988. 'onesuperior': 300,
  15989. 'imacron': 278,
  15990. 'Euro': 500
  15991. },
  15992. 'Times-Bold': {
  15993. 'space': 250,
  15994. 'exclam': 333,
  15995. 'quotedbl': 555,
  15996. 'numbersign': 500,
  15997. 'dollar': 500,
  15998. 'percent': 1000,
  15999. 'ampersand': 833,
  16000. 'quoteright': 333,
  16001. 'parenleft': 333,
  16002. 'parenright': 333,
  16003. 'asterisk': 500,
  16004. 'plus': 570,
  16005. 'comma': 250,
  16006. 'hyphen': 333,
  16007. 'period': 250,
  16008. 'slash': 278,
  16009. 'zero': 500,
  16010. 'one': 500,
  16011. 'two': 500,
  16012. 'three': 500,
  16013. 'four': 500,
  16014. 'five': 500,
  16015. 'six': 500,
  16016. 'seven': 500,
  16017. 'eight': 500,
  16018. 'nine': 500,
  16019. 'colon': 333,
  16020. 'semicolon': 333,
  16021. 'less': 570,
  16022. 'equal': 570,
  16023. 'greater': 570,
  16024. 'question': 500,
  16025. 'at': 930,
  16026. 'A': 722,
  16027. 'B': 667,
  16028. 'C': 722,
  16029. 'D': 722,
  16030. 'E': 667,
  16031. 'F': 611,
  16032. 'G': 778,
  16033. 'H': 778,
  16034. 'I': 389,
  16035. 'J': 500,
  16036. 'K': 778,
  16037. 'L': 667,
  16038. 'M': 944,
  16039. 'N': 722,
  16040. 'O': 778,
  16041. 'P': 611,
  16042. 'Q': 778,
  16043. 'R': 722,
  16044. 'S': 556,
  16045. 'T': 667,
  16046. 'U': 722,
  16047. 'V': 722,
  16048. 'W': 1000,
  16049. 'X': 722,
  16050. 'Y': 722,
  16051. 'Z': 667,
  16052. 'bracketleft': 333,
  16053. 'backslash': 278,
  16054. 'bracketright': 333,
  16055. 'asciicircum': 581,
  16056. 'underscore': 500,
  16057. 'quoteleft': 333,
  16058. 'a': 500,
  16059. 'b': 556,
  16060. 'c': 444,
  16061. 'd': 556,
  16062. 'e': 444,
  16063. 'f': 333,
  16064. 'g': 500,
  16065. 'h': 556,
  16066. 'i': 278,
  16067. 'j': 333,
  16068. 'k': 556,
  16069. 'l': 278,
  16070. 'm': 833,
  16071. 'n': 556,
  16072. 'o': 500,
  16073. 'p': 556,
  16074. 'q': 556,
  16075. 'r': 444,
  16076. 's': 389,
  16077. 't': 333,
  16078. 'u': 556,
  16079. 'v': 500,
  16080. 'w': 722,
  16081. 'x': 500,
  16082. 'y': 500,
  16083. 'z': 444,
  16084. 'braceleft': 394,
  16085. 'bar': 220,
  16086. 'braceright': 394,
  16087. 'asciitilde': 520,
  16088. 'exclamdown': 333,
  16089. 'cent': 500,
  16090. 'sterling': 500,
  16091. 'fraction': 167,
  16092. 'yen': 500,
  16093. 'florin': 500,
  16094. 'section': 500,
  16095. 'currency': 500,
  16096. 'quotesingle': 278,
  16097. 'quotedblleft': 500,
  16098. 'guillemotleft': 500,
  16099. 'guilsinglleft': 333,
  16100. 'guilsinglright': 333,
  16101. 'fi': 556,
  16102. 'fl': 556,
  16103. 'endash': 500,
  16104. 'dagger': 500,
  16105. 'daggerdbl': 500,
  16106. 'periodcentered': 250,
  16107. 'paragraph': 540,
  16108. 'bullet': 350,
  16109. 'quotesinglbase': 333,
  16110. 'quotedblbase': 500,
  16111. 'quotedblright': 500,
  16112. 'guillemotright': 500,
  16113. 'ellipsis': 1000,
  16114. 'perthousand': 1000,
  16115. 'questiondown': 500,
  16116. 'grave': 333,
  16117. 'acute': 333,
  16118. 'circumflex': 333,
  16119. 'tilde': 333,
  16120. 'macron': 333,
  16121. 'breve': 333,
  16122. 'dotaccent': 333,
  16123. 'dieresis': 333,
  16124. 'ring': 333,
  16125. 'cedilla': 333,
  16126. 'hungarumlaut': 333,
  16127. 'ogonek': 333,
  16128. 'caron': 333,
  16129. 'emdash': 1000,
  16130. 'AE': 1000,
  16131. 'ordfeminine': 300,
  16132. 'Lslash': 667,
  16133. 'Oslash': 778,
  16134. 'OE': 1000,
  16135. 'ordmasculine': 330,
  16136. 'ae': 722,
  16137. 'dotlessi': 278,
  16138. 'lslash': 278,
  16139. 'oslash': 500,
  16140. 'oe': 722,
  16141. 'germandbls': 556,
  16142. 'Idieresis': 389,
  16143. 'eacute': 444,
  16144. 'abreve': 500,
  16145. 'uhungarumlaut': 556,
  16146. 'ecaron': 444,
  16147. 'Ydieresis': 722,
  16148. 'divide': 570,
  16149. 'Yacute': 722,
  16150. 'Acircumflex': 722,
  16151. 'aacute': 500,
  16152. 'Ucircumflex': 722,
  16153. 'yacute': 500,
  16154. 'scommaaccent': 389,
  16155. 'ecircumflex': 444,
  16156. 'Uring': 722,
  16157. 'Udieresis': 722,
  16158. 'aogonek': 500,
  16159. 'Uacute': 722,
  16160. 'uogonek': 556,
  16161. 'Edieresis': 667,
  16162. 'Dcroat': 722,
  16163. 'commaaccent': 250,
  16164. 'copyright': 747,
  16165. 'Emacron': 667,
  16166. 'ccaron': 444,
  16167. 'aring': 500,
  16168. 'Ncommaaccent': 722,
  16169. 'lacute': 278,
  16170. 'agrave': 500,
  16171. 'Tcommaaccent': 667,
  16172. 'Cacute': 722,
  16173. 'atilde': 500,
  16174. 'Edotaccent': 667,
  16175. 'scaron': 389,
  16176. 'scedilla': 389,
  16177. 'iacute': 278,
  16178. 'lozenge': 494,
  16179. 'Rcaron': 722,
  16180. 'Gcommaaccent': 778,
  16181. 'ucircumflex': 556,
  16182. 'acircumflex': 500,
  16183. 'Amacron': 722,
  16184. 'rcaron': 444,
  16185. 'ccedilla': 444,
  16186. 'Zdotaccent': 667,
  16187. 'Thorn': 611,
  16188. 'Omacron': 778,
  16189. 'Racute': 722,
  16190. 'Sacute': 556,
  16191. 'dcaron': 672,
  16192. 'Umacron': 722,
  16193. 'uring': 556,
  16194. 'threesuperior': 300,
  16195. 'Ograve': 778,
  16196. 'Agrave': 722,
  16197. 'Abreve': 722,
  16198. 'multiply': 570,
  16199. 'uacute': 556,
  16200. 'Tcaron': 667,
  16201. 'partialdiff': 494,
  16202. 'ydieresis': 500,
  16203. 'Nacute': 722,
  16204. 'icircumflex': 278,
  16205. 'Ecircumflex': 667,
  16206. 'adieresis': 500,
  16207. 'edieresis': 444,
  16208. 'cacute': 444,
  16209. 'nacute': 556,
  16210. 'umacron': 556,
  16211. 'Ncaron': 722,
  16212. 'Iacute': 389,
  16213. 'plusminus': 570,
  16214. 'brokenbar': 220,
  16215. 'registered': 747,
  16216. 'Gbreve': 778,
  16217. 'Idotaccent': 389,
  16218. 'summation': 600,
  16219. 'Egrave': 667,
  16220. 'racute': 444,
  16221. 'omacron': 500,
  16222. 'Zacute': 667,
  16223. 'Zcaron': 667,
  16224. 'greaterequal': 549,
  16225. 'Eth': 722,
  16226. 'Ccedilla': 722,
  16227. 'lcommaaccent': 278,
  16228. 'tcaron': 416,
  16229. 'eogonek': 444,
  16230. 'Uogonek': 722,
  16231. 'Aacute': 722,
  16232. 'Adieresis': 722,
  16233. 'egrave': 444,
  16234. 'zacute': 444,
  16235. 'iogonek': 278,
  16236. 'Oacute': 778,
  16237. 'oacute': 500,
  16238. 'amacron': 500,
  16239. 'sacute': 389,
  16240. 'idieresis': 278,
  16241. 'Ocircumflex': 778,
  16242. 'Ugrave': 722,
  16243. 'Delta': 612,
  16244. 'thorn': 556,
  16245. 'twosuperior': 300,
  16246. 'Odieresis': 778,
  16247. 'mu': 556,
  16248. 'igrave': 278,
  16249. 'ohungarumlaut': 500,
  16250. 'Eogonek': 667,
  16251. 'dcroat': 556,
  16252. 'threequarters': 750,
  16253. 'Scedilla': 556,
  16254. 'lcaron': 394,
  16255. 'Kcommaaccent': 778,
  16256. 'Lacute': 667,
  16257. 'trademark': 1000,
  16258. 'edotaccent': 444,
  16259. 'Igrave': 389,
  16260. 'Imacron': 389,
  16261. 'Lcaron': 667,
  16262. 'onehalf': 750,
  16263. 'lessequal': 549,
  16264. 'ocircumflex': 500,
  16265. 'ntilde': 556,
  16266. 'Uhungarumlaut': 722,
  16267. 'Eacute': 667,
  16268. 'emacron': 444,
  16269. 'gbreve': 500,
  16270. 'onequarter': 750,
  16271. 'Scaron': 556,
  16272. 'Scommaaccent': 556,
  16273. 'Ohungarumlaut': 778,
  16274. 'degree': 400,
  16275. 'ograve': 500,
  16276. 'Ccaron': 722,
  16277. 'ugrave': 556,
  16278. 'radical': 549,
  16279. 'Dcaron': 722,
  16280. 'rcommaaccent': 444,
  16281. 'Ntilde': 722,
  16282. 'otilde': 500,
  16283. 'Rcommaaccent': 722,
  16284. 'Lcommaaccent': 667,
  16285. 'Atilde': 722,
  16286. 'Aogonek': 722,
  16287. 'Aring': 722,
  16288. 'Otilde': 778,
  16289. 'zdotaccent': 444,
  16290. 'Ecaron': 667,
  16291. 'Iogonek': 389,
  16292. 'kcommaaccent': 556,
  16293. 'minus': 570,
  16294. 'Icircumflex': 389,
  16295. 'ncaron': 556,
  16296. 'tcommaaccent': 333,
  16297. 'logicalnot': 570,
  16298. 'odieresis': 500,
  16299. 'udieresis': 556,
  16300. 'notequal': 549,
  16301. 'gcommaaccent': 500,
  16302. 'eth': 500,
  16303. 'zcaron': 444,
  16304. 'ncommaaccent': 556,
  16305. 'onesuperior': 300,
  16306. 'imacron': 278,
  16307. 'Euro': 500
  16308. },
  16309. 'Times-BoldItalic': {
  16310. 'space': 250,
  16311. 'exclam': 389,
  16312. 'quotedbl': 555,
  16313. 'numbersign': 500,
  16314. 'dollar': 500,
  16315. 'percent': 833,
  16316. 'ampersand': 778,
  16317. 'quoteright': 333,
  16318. 'parenleft': 333,
  16319. 'parenright': 333,
  16320. 'asterisk': 500,
  16321. 'plus': 570,
  16322. 'comma': 250,
  16323. 'hyphen': 333,
  16324. 'period': 250,
  16325. 'slash': 278,
  16326. 'zero': 500,
  16327. 'one': 500,
  16328. 'two': 500,
  16329. 'three': 500,
  16330. 'four': 500,
  16331. 'five': 500,
  16332. 'six': 500,
  16333. 'seven': 500,
  16334. 'eight': 500,
  16335. 'nine': 500,
  16336. 'colon': 333,
  16337. 'semicolon': 333,
  16338. 'less': 570,
  16339. 'equal': 570,
  16340. 'greater': 570,
  16341. 'question': 500,
  16342. 'at': 832,
  16343. 'A': 667,
  16344. 'B': 667,
  16345. 'C': 667,
  16346. 'D': 722,
  16347. 'E': 667,
  16348. 'F': 667,
  16349. 'G': 722,
  16350. 'H': 778,
  16351. 'I': 389,
  16352. 'J': 500,
  16353. 'K': 667,
  16354. 'L': 611,
  16355. 'M': 889,
  16356. 'N': 722,
  16357. 'O': 722,
  16358. 'P': 611,
  16359. 'Q': 722,
  16360. 'R': 667,
  16361. 'S': 556,
  16362. 'T': 611,
  16363. 'U': 722,
  16364. 'V': 667,
  16365. 'W': 889,
  16366. 'X': 667,
  16367. 'Y': 611,
  16368. 'Z': 611,
  16369. 'bracketleft': 333,
  16370. 'backslash': 278,
  16371. 'bracketright': 333,
  16372. 'asciicircum': 570,
  16373. 'underscore': 500,
  16374. 'quoteleft': 333,
  16375. 'a': 500,
  16376. 'b': 500,
  16377. 'c': 444,
  16378. 'd': 500,
  16379. 'e': 444,
  16380. 'f': 333,
  16381. 'g': 500,
  16382. 'h': 556,
  16383. 'i': 278,
  16384. 'j': 278,
  16385. 'k': 500,
  16386. 'l': 278,
  16387. 'm': 778,
  16388. 'n': 556,
  16389. 'o': 500,
  16390. 'p': 500,
  16391. 'q': 500,
  16392. 'r': 389,
  16393. 's': 389,
  16394. 't': 278,
  16395. 'u': 556,
  16396. 'v': 444,
  16397. 'w': 667,
  16398. 'x': 500,
  16399. 'y': 444,
  16400. 'z': 389,
  16401. 'braceleft': 348,
  16402. 'bar': 220,
  16403. 'braceright': 348,
  16404. 'asciitilde': 570,
  16405. 'exclamdown': 389,
  16406. 'cent': 500,
  16407. 'sterling': 500,
  16408. 'fraction': 167,
  16409. 'yen': 500,
  16410. 'florin': 500,
  16411. 'section': 500,
  16412. 'currency': 500,
  16413. 'quotesingle': 278,
  16414. 'quotedblleft': 500,
  16415. 'guillemotleft': 500,
  16416. 'guilsinglleft': 333,
  16417. 'guilsinglright': 333,
  16418. 'fi': 556,
  16419. 'fl': 556,
  16420. 'endash': 500,
  16421. 'dagger': 500,
  16422. 'daggerdbl': 500,
  16423. 'periodcentered': 250,
  16424. 'paragraph': 500,
  16425. 'bullet': 350,
  16426. 'quotesinglbase': 333,
  16427. 'quotedblbase': 500,
  16428. 'quotedblright': 500,
  16429. 'guillemotright': 500,
  16430. 'ellipsis': 1000,
  16431. 'perthousand': 1000,
  16432. 'questiondown': 500,
  16433. 'grave': 333,
  16434. 'acute': 333,
  16435. 'circumflex': 333,
  16436. 'tilde': 333,
  16437. 'macron': 333,
  16438. 'breve': 333,
  16439. 'dotaccent': 333,
  16440. 'dieresis': 333,
  16441. 'ring': 333,
  16442. 'cedilla': 333,
  16443. 'hungarumlaut': 333,
  16444. 'ogonek': 333,
  16445. 'caron': 333,
  16446. 'emdash': 1000,
  16447. 'AE': 944,
  16448. 'ordfeminine': 266,
  16449. 'Lslash': 611,
  16450. 'Oslash': 722,
  16451. 'OE': 944,
  16452. 'ordmasculine': 300,
  16453. 'ae': 722,
  16454. 'dotlessi': 278,
  16455. 'lslash': 278,
  16456. 'oslash': 500,
  16457. 'oe': 722,
  16458. 'germandbls': 500,
  16459. 'Idieresis': 389,
  16460. 'eacute': 444,
  16461. 'abreve': 500,
  16462. 'uhungarumlaut': 556,
  16463. 'ecaron': 444,
  16464. 'Ydieresis': 611,
  16465. 'divide': 570,
  16466. 'Yacute': 611,
  16467. 'Acircumflex': 667,
  16468. 'aacute': 500,
  16469. 'Ucircumflex': 722,
  16470. 'yacute': 444,
  16471. 'scommaaccent': 389,
  16472. 'ecircumflex': 444,
  16473. 'Uring': 722,
  16474. 'Udieresis': 722,
  16475. 'aogonek': 500,
  16476. 'Uacute': 722,
  16477. 'uogonek': 556,
  16478. 'Edieresis': 667,
  16479. 'Dcroat': 722,
  16480. 'commaaccent': 250,
  16481. 'copyright': 747,
  16482. 'Emacron': 667,
  16483. 'ccaron': 444,
  16484. 'aring': 500,
  16485. 'Ncommaaccent': 722,
  16486. 'lacute': 278,
  16487. 'agrave': 500,
  16488. 'Tcommaaccent': 611,
  16489. 'Cacute': 667,
  16490. 'atilde': 500,
  16491. 'Edotaccent': 667,
  16492. 'scaron': 389,
  16493. 'scedilla': 389,
  16494. 'iacute': 278,
  16495. 'lozenge': 494,
  16496. 'Rcaron': 667,
  16497. 'Gcommaaccent': 722,
  16498. 'ucircumflex': 556,
  16499. 'acircumflex': 500,
  16500. 'Amacron': 667,
  16501. 'rcaron': 389,
  16502. 'ccedilla': 444,
  16503. 'Zdotaccent': 611,
  16504. 'Thorn': 611,
  16505. 'Omacron': 722,
  16506. 'Racute': 667,
  16507. 'Sacute': 556,
  16508. 'dcaron': 608,
  16509. 'Umacron': 722,
  16510. 'uring': 556,
  16511. 'threesuperior': 300,
  16512. 'Ograve': 722,
  16513. 'Agrave': 667,
  16514. 'Abreve': 667,
  16515. 'multiply': 570,
  16516. 'uacute': 556,
  16517. 'Tcaron': 611,
  16518. 'partialdiff': 494,
  16519. 'ydieresis': 444,
  16520. 'Nacute': 722,
  16521. 'icircumflex': 278,
  16522. 'Ecircumflex': 667,
  16523. 'adieresis': 500,
  16524. 'edieresis': 444,
  16525. 'cacute': 444,
  16526. 'nacute': 556,
  16527. 'umacron': 556,
  16528. 'Ncaron': 722,
  16529. 'Iacute': 389,
  16530. 'plusminus': 570,
  16531. 'brokenbar': 220,
  16532. 'registered': 747,
  16533. 'Gbreve': 722,
  16534. 'Idotaccent': 389,
  16535. 'summation': 600,
  16536. 'Egrave': 667,
  16537. 'racute': 389,
  16538. 'omacron': 500,
  16539. 'Zacute': 611,
  16540. 'Zcaron': 611,
  16541. 'greaterequal': 549,
  16542. 'Eth': 722,
  16543. 'Ccedilla': 667,
  16544. 'lcommaaccent': 278,
  16545. 'tcaron': 366,
  16546. 'eogonek': 444,
  16547. 'Uogonek': 722,
  16548. 'Aacute': 667,
  16549. 'Adieresis': 667,
  16550. 'egrave': 444,
  16551. 'zacute': 389,
  16552. 'iogonek': 278,
  16553. 'Oacute': 722,
  16554. 'oacute': 500,
  16555. 'amacron': 500,
  16556. 'sacute': 389,
  16557. 'idieresis': 278,
  16558. 'Ocircumflex': 722,
  16559. 'Ugrave': 722,
  16560. 'Delta': 612,
  16561. 'thorn': 500,
  16562. 'twosuperior': 300,
  16563. 'Odieresis': 722,
  16564. 'mu': 576,
  16565. 'igrave': 278,
  16566. 'ohungarumlaut': 500,
  16567. 'Eogonek': 667,
  16568. 'dcroat': 500,
  16569. 'threequarters': 750,
  16570. 'Scedilla': 556,
  16571. 'lcaron': 382,
  16572. 'Kcommaaccent': 667,
  16573. 'Lacute': 611,
  16574. 'trademark': 1000,
  16575. 'edotaccent': 444,
  16576. 'Igrave': 389,
  16577. 'Imacron': 389,
  16578. 'Lcaron': 611,
  16579. 'onehalf': 750,
  16580. 'lessequal': 549,
  16581. 'ocircumflex': 500,
  16582. 'ntilde': 556,
  16583. 'Uhungarumlaut': 722,
  16584. 'Eacute': 667,
  16585. 'emacron': 444,
  16586. 'gbreve': 500,
  16587. 'onequarter': 750,
  16588. 'Scaron': 556,
  16589. 'Scommaaccent': 556,
  16590. 'Ohungarumlaut': 722,
  16591. 'degree': 400,
  16592. 'ograve': 500,
  16593. 'Ccaron': 667,
  16594. 'ugrave': 556,
  16595. 'radical': 549,
  16596. 'Dcaron': 722,
  16597. 'rcommaaccent': 389,
  16598. 'Ntilde': 722,
  16599. 'otilde': 500,
  16600. 'Rcommaaccent': 667,
  16601. 'Lcommaaccent': 611,
  16602. 'Atilde': 667,
  16603. 'Aogonek': 667,
  16604. 'Aring': 667,
  16605. 'Otilde': 722,
  16606. 'zdotaccent': 389,
  16607. 'Ecaron': 667,
  16608. 'Iogonek': 389,
  16609. 'kcommaaccent': 500,
  16610. 'minus': 606,
  16611. 'Icircumflex': 389,
  16612. 'ncaron': 556,
  16613. 'tcommaaccent': 278,
  16614. 'logicalnot': 606,
  16615. 'odieresis': 500,
  16616. 'udieresis': 556,
  16617. 'notequal': 549,
  16618. 'gcommaaccent': 500,
  16619. 'eth': 500,
  16620. 'zcaron': 389,
  16621. 'ncommaaccent': 556,
  16622. 'onesuperior': 300,
  16623. 'imacron': 278,
  16624. 'Euro': 500
  16625. },
  16626. 'Times-Italic': {
  16627. 'space': 250,
  16628. 'exclam': 333,
  16629. 'quotedbl': 420,
  16630. 'numbersign': 500,
  16631. 'dollar': 500,
  16632. 'percent': 833,
  16633. 'ampersand': 778,
  16634. 'quoteright': 333,
  16635. 'parenleft': 333,
  16636. 'parenright': 333,
  16637. 'asterisk': 500,
  16638. 'plus': 675,
  16639. 'comma': 250,
  16640. 'hyphen': 333,
  16641. 'period': 250,
  16642. 'slash': 278,
  16643. 'zero': 500,
  16644. 'one': 500,
  16645. 'two': 500,
  16646. 'three': 500,
  16647. 'four': 500,
  16648. 'five': 500,
  16649. 'six': 500,
  16650. 'seven': 500,
  16651. 'eight': 500,
  16652. 'nine': 500,
  16653. 'colon': 333,
  16654. 'semicolon': 333,
  16655. 'less': 675,
  16656. 'equal': 675,
  16657. 'greater': 675,
  16658. 'question': 500,
  16659. 'at': 920,
  16660. 'A': 611,
  16661. 'B': 611,
  16662. 'C': 667,
  16663. 'D': 722,
  16664. 'E': 611,
  16665. 'F': 611,
  16666. 'G': 722,
  16667. 'H': 722,
  16668. 'I': 333,
  16669. 'J': 444,
  16670. 'K': 667,
  16671. 'L': 556,
  16672. 'M': 833,
  16673. 'N': 667,
  16674. 'O': 722,
  16675. 'P': 611,
  16676. 'Q': 722,
  16677. 'R': 611,
  16678. 'S': 500,
  16679. 'T': 556,
  16680. 'U': 722,
  16681. 'V': 611,
  16682. 'W': 833,
  16683. 'X': 611,
  16684. 'Y': 556,
  16685. 'Z': 556,
  16686. 'bracketleft': 389,
  16687. 'backslash': 278,
  16688. 'bracketright': 389,
  16689. 'asciicircum': 422,
  16690. 'underscore': 500,
  16691. 'quoteleft': 333,
  16692. 'a': 500,
  16693. 'b': 500,
  16694. 'c': 444,
  16695. 'd': 500,
  16696. 'e': 444,
  16697. 'f': 278,
  16698. 'g': 500,
  16699. 'h': 500,
  16700. 'i': 278,
  16701. 'j': 278,
  16702. 'k': 444,
  16703. 'l': 278,
  16704. 'm': 722,
  16705. 'n': 500,
  16706. 'o': 500,
  16707. 'p': 500,
  16708. 'q': 500,
  16709. 'r': 389,
  16710. 's': 389,
  16711. 't': 278,
  16712. 'u': 500,
  16713. 'v': 444,
  16714. 'w': 667,
  16715. 'x': 444,
  16716. 'y': 444,
  16717. 'z': 389,
  16718. 'braceleft': 400,
  16719. 'bar': 275,
  16720. 'braceright': 400,
  16721. 'asciitilde': 541,
  16722. 'exclamdown': 389,
  16723. 'cent': 500,
  16724. 'sterling': 500,
  16725. 'fraction': 167,
  16726. 'yen': 500,
  16727. 'florin': 500,
  16728. 'section': 500,
  16729. 'currency': 500,
  16730. 'quotesingle': 214,
  16731. 'quotedblleft': 556,
  16732. 'guillemotleft': 500,
  16733. 'guilsinglleft': 333,
  16734. 'guilsinglright': 333,
  16735. 'fi': 500,
  16736. 'fl': 500,
  16737. 'endash': 500,
  16738. 'dagger': 500,
  16739. 'daggerdbl': 500,
  16740. 'periodcentered': 250,
  16741. 'paragraph': 523,
  16742. 'bullet': 350,
  16743. 'quotesinglbase': 333,
  16744. 'quotedblbase': 556,
  16745. 'quotedblright': 556,
  16746. 'guillemotright': 500,
  16747. 'ellipsis': 889,
  16748. 'perthousand': 1000,
  16749. 'questiondown': 500,
  16750. 'grave': 333,
  16751. 'acute': 333,
  16752. 'circumflex': 333,
  16753. 'tilde': 333,
  16754. 'macron': 333,
  16755. 'breve': 333,
  16756. 'dotaccent': 333,
  16757. 'dieresis': 333,
  16758. 'ring': 333,
  16759. 'cedilla': 333,
  16760. 'hungarumlaut': 333,
  16761. 'ogonek': 333,
  16762. 'caron': 333,
  16763. 'emdash': 889,
  16764. 'AE': 889,
  16765. 'ordfeminine': 276,
  16766. 'Lslash': 556,
  16767. 'Oslash': 722,
  16768. 'OE': 944,
  16769. 'ordmasculine': 310,
  16770. 'ae': 667,
  16771. 'dotlessi': 278,
  16772. 'lslash': 278,
  16773. 'oslash': 500,
  16774. 'oe': 667,
  16775. 'germandbls': 500,
  16776. 'Idieresis': 333,
  16777. 'eacute': 444,
  16778. 'abreve': 500,
  16779. 'uhungarumlaut': 500,
  16780. 'ecaron': 444,
  16781. 'Ydieresis': 556,
  16782. 'divide': 675,
  16783. 'Yacute': 556,
  16784. 'Acircumflex': 611,
  16785. 'aacute': 500,
  16786. 'Ucircumflex': 722,
  16787. 'yacute': 444,
  16788. 'scommaaccent': 389,
  16789. 'ecircumflex': 444,
  16790. 'Uring': 722,
  16791. 'Udieresis': 722,
  16792. 'aogonek': 500,
  16793. 'Uacute': 722,
  16794. 'uogonek': 500,
  16795. 'Edieresis': 611,
  16796. 'Dcroat': 722,
  16797. 'commaaccent': 250,
  16798. 'copyright': 760,
  16799. 'Emacron': 611,
  16800. 'ccaron': 444,
  16801. 'aring': 500,
  16802. 'Ncommaaccent': 667,
  16803. 'lacute': 278,
  16804. 'agrave': 500,
  16805. 'Tcommaaccent': 556,
  16806. 'Cacute': 667,
  16807. 'atilde': 500,
  16808. 'Edotaccent': 611,
  16809. 'scaron': 389,
  16810. 'scedilla': 389,
  16811. 'iacute': 278,
  16812. 'lozenge': 471,
  16813. 'Rcaron': 611,
  16814. 'Gcommaaccent': 722,
  16815. 'ucircumflex': 500,
  16816. 'acircumflex': 500,
  16817. 'Amacron': 611,
  16818. 'rcaron': 389,
  16819. 'ccedilla': 444,
  16820. 'Zdotaccent': 556,
  16821. 'Thorn': 611,
  16822. 'Omacron': 722,
  16823. 'Racute': 611,
  16824. 'Sacute': 500,
  16825. 'dcaron': 544,
  16826. 'Umacron': 722,
  16827. 'uring': 500,
  16828. 'threesuperior': 300,
  16829. 'Ograve': 722,
  16830. 'Agrave': 611,
  16831. 'Abreve': 611,
  16832. 'multiply': 675,
  16833. 'uacute': 500,
  16834. 'Tcaron': 556,
  16835. 'partialdiff': 476,
  16836. 'ydieresis': 444,
  16837. 'Nacute': 667,
  16838. 'icircumflex': 278,
  16839. 'Ecircumflex': 611,
  16840. 'adieresis': 500,
  16841. 'edieresis': 444,
  16842. 'cacute': 444,
  16843. 'nacute': 500,
  16844. 'umacron': 500,
  16845. 'Ncaron': 667,
  16846. 'Iacute': 333,
  16847. 'plusminus': 675,
  16848. 'brokenbar': 275,
  16849. 'registered': 760,
  16850. 'Gbreve': 722,
  16851. 'Idotaccent': 333,
  16852. 'summation': 600,
  16853. 'Egrave': 611,
  16854. 'racute': 389,
  16855. 'omacron': 500,
  16856. 'Zacute': 556,
  16857. 'Zcaron': 556,
  16858. 'greaterequal': 549,
  16859. 'Eth': 722,
  16860. 'Ccedilla': 667,
  16861. 'lcommaaccent': 278,
  16862. 'tcaron': 300,
  16863. 'eogonek': 444,
  16864. 'Uogonek': 722,
  16865. 'Aacute': 611,
  16866. 'Adieresis': 611,
  16867. 'egrave': 444,
  16868. 'zacute': 389,
  16869. 'iogonek': 278,
  16870. 'Oacute': 722,
  16871. 'oacute': 500,
  16872. 'amacron': 500,
  16873. 'sacute': 389,
  16874. 'idieresis': 278,
  16875. 'Ocircumflex': 722,
  16876. 'Ugrave': 722,
  16877. 'Delta': 612,
  16878. 'thorn': 500,
  16879. 'twosuperior': 300,
  16880. 'Odieresis': 722,
  16881. 'mu': 500,
  16882. 'igrave': 278,
  16883. 'ohungarumlaut': 500,
  16884. 'Eogonek': 611,
  16885. 'dcroat': 500,
  16886. 'threequarters': 750,
  16887. 'Scedilla': 500,
  16888. 'lcaron': 300,
  16889. 'Kcommaaccent': 667,
  16890. 'Lacute': 556,
  16891. 'trademark': 980,
  16892. 'edotaccent': 444,
  16893. 'Igrave': 333,
  16894. 'Imacron': 333,
  16895. 'Lcaron': 611,
  16896. 'onehalf': 750,
  16897. 'lessequal': 549,
  16898. 'ocircumflex': 500,
  16899. 'ntilde': 500,
  16900. 'Uhungarumlaut': 722,
  16901. 'Eacute': 611,
  16902. 'emacron': 444,
  16903. 'gbreve': 500,
  16904. 'onequarter': 750,
  16905. 'Scaron': 500,
  16906. 'Scommaaccent': 500,
  16907. 'Ohungarumlaut': 722,
  16908. 'degree': 400,
  16909. 'ograve': 500,
  16910. 'Ccaron': 667,
  16911. 'ugrave': 500,
  16912. 'radical': 453,
  16913. 'Dcaron': 722,
  16914. 'rcommaaccent': 389,
  16915. 'Ntilde': 667,
  16916. 'otilde': 500,
  16917. 'Rcommaaccent': 611,
  16918. 'Lcommaaccent': 556,
  16919. 'Atilde': 611,
  16920. 'Aogonek': 611,
  16921. 'Aring': 611,
  16922. 'Otilde': 722,
  16923. 'zdotaccent': 389,
  16924. 'Ecaron': 611,
  16925. 'Iogonek': 333,
  16926. 'kcommaaccent': 444,
  16927. 'minus': 675,
  16928. 'Icircumflex': 333,
  16929. 'ncaron': 500,
  16930. 'tcommaaccent': 278,
  16931. 'logicalnot': 675,
  16932. 'odieresis': 500,
  16933. 'udieresis': 500,
  16934. 'notequal': 549,
  16935. 'gcommaaccent': 500,
  16936. 'eth': 500,
  16937. 'zcaron': 389,
  16938. 'ncommaaccent': 500,
  16939. 'onesuperior': 300,
  16940. 'imacron': 278,
  16941. 'Euro': 500
  16942. },
  16943. 'ZapfDingbats': {
  16944. 'space': 278,
  16945. 'a1': 974,
  16946. 'a2': 961,
  16947. 'a202': 974,
  16948. 'a3': 980,
  16949. 'a4': 719,
  16950. 'a5': 789,
  16951. 'a119': 790,
  16952. 'a118': 791,
  16953. 'a117': 690,
  16954. 'a11': 960,
  16955. 'a12': 939,
  16956. 'a13': 549,
  16957. 'a14': 855,
  16958. 'a15': 911,
  16959. 'a16': 933,
  16960. 'a105': 911,
  16961. 'a17': 945,
  16962. 'a18': 974,
  16963. 'a19': 755,
  16964. 'a20': 846,
  16965. 'a21': 762,
  16966. 'a22': 761,
  16967. 'a23': 571,
  16968. 'a24': 677,
  16969. 'a25': 763,
  16970. 'a26': 760,
  16971. 'a27': 759,
  16972. 'a28': 754,
  16973. 'a6': 494,
  16974. 'a7': 552,
  16975. 'a8': 537,
  16976. 'a9': 577,
  16977. 'a10': 692,
  16978. 'a29': 786,
  16979. 'a30': 788,
  16980. 'a31': 788,
  16981. 'a32': 790,
  16982. 'a33': 793,
  16983. 'a34': 794,
  16984. 'a35': 816,
  16985. 'a36': 823,
  16986. 'a37': 789,
  16987. 'a38': 841,
  16988. 'a39': 823,
  16989. 'a40': 833,
  16990. 'a41': 816,
  16991. 'a42': 831,
  16992. 'a43': 923,
  16993. 'a44': 744,
  16994. 'a45': 723,
  16995. 'a46': 749,
  16996. 'a47': 790,
  16997. 'a48': 792,
  16998. 'a49': 695,
  16999. 'a50': 776,
  17000. 'a51': 768,
  17001. 'a52': 792,
  17002. 'a53': 759,
  17003. 'a54': 707,
  17004. 'a55': 708,
  17005. 'a56': 682,
  17006. 'a57': 701,
  17007. 'a58': 826,
  17008. 'a59': 815,
  17009. 'a60': 789,
  17010. 'a61': 789,
  17011. 'a62': 707,
  17012. 'a63': 687,
  17013. 'a64': 696,
  17014. 'a65': 689,
  17015. 'a66': 786,
  17016. 'a67': 787,
  17017. 'a68': 713,
  17018. 'a69': 791,
  17019. 'a70': 785,
  17020. 'a71': 791,
  17021. 'a72': 873,
  17022. 'a73': 761,
  17023. 'a74': 762,
  17024. 'a203': 762,
  17025. 'a75': 759,
  17026. 'a204': 759,
  17027. 'a76': 892,
  17028. 'a77': 892,
  17029. 'a78': 788,
  17030. 'a79': 784,
  17031. 'a81': 438,
  17032. 'a82': 138,
  17033. 'a83': 277,
  17034. 'a84': 415,
  17035. 'a97': 392,
  17036. 'a98': 392,
  17037. 'a99': 668,
  17038. 'a100': 668,
  17039. 'a89': 390,
  17040. 'a90': 390,
  17041. 'a93': 317,
  17042. 'a94': 317,
  17043. 'a91': 276,
  17044. 'a92': 276,
  17045. 'a205': 509,
  17046. 'a85': 509,
  17047. 'a206': 410,
  17048. 'a86': 410,
  17049. 'a87': 234,
  17050. 'a88': 234,
  17051. 'a95': 334,
  17052. 'a96': 334,
  17053. 'a101': 732,
  17054. 'a102': 544,
  17055. 'a103': 544,
  17056. 'a104': 910,
  17057. 'a106': 667,
  17058. 'a107': 760,
  17059. 'a108': 760,
  17060. 'a112': 776,
  17061. 'a111': 595,
  17062. 'a110': 694,
  17063. 'a109': 626,
  17064. 'a120': 788,
  17065. 'a121': 788,
  17066. 'a122': 788,
  17067. 'a123': 788,
  17068. 'a124': 788,
  17069. 'a125': 788,
  17070. 'a126': 788,
  17071. 'a127': 788,
  17072. 'a128': 788,
  17073. 'a129': 788,
  17074. 'a130': 788,
  17075. 'a131': 788,
  17076. 'a132': 788,
  17077. 'a133': 788,
  17078. 'a134': 788,
  17079. 'a135': 788,
  17080. 'a136': 788,
  17081. 'a137': 788,
  17082. 'a138': 788,
  17083. 'a139': 788,
  17084. 'a140': 788,
  17085. 'a141': 788,
  17086. 'a142': 788,
  17087. 'a143': 788,
  17088. 'a144': 788,
  17089. 'a145': 788,
  17090. 'a146': 788,
  17091. 'a147': 788,
  17092. 'a148': 788,
  17093. 'a149': 788,
  17094. 'a150': 788,
  17095. 'a151': 788,
  17096. 'a152': 788,
  17097. 'a153': 788,
  17098. 'a154': 788,
  17099. 'a155': 788,
  17100. 'a156': 788,
  17101. 'a157': 788,
  17102. 'a158': 788,
  17103. 'a159': 788,
  17104. 'a160': 894,
  17105. 'a161': 838,
  17106. 'a163': 1016,
  17107. 'a164': 458,
  17108. 'a196': 748,
  17109. 'a165': 924,
  17110. 'a192': 748,
  17111. 'a166': 918,
  17112. 'a167': 927,
  17113. 'a168': 928,
  17114. 'a169': 928,
  17115. 'a170': 834,
  17116. 'a171': 873,
  17117. 'a172': 828,
  17118. 'a173': 924,
  17119. 'a162': 924,
  17120. 'a174': 917,
  17121. 'a175': 930,
  17122. 'a176': 931,
  17123. 'a177': 463,
  17124. 'a178': 883,
  17125. 'a179': 836,
  17126. 'a193': 836,
  17127. 'a180': 867,
  17128. 'a199': 867,
  17129. 'a181': 696,
  17130. 'a200': 696,
  17131. 'a182': 874,
  17132. 'a201': 874,
  17133. 'a183': 760,
  17134. 'a184': 946,
  17135. 'a197': 771,
  17136. 'a185': 865,
  17137. 'a194': 771,
  17138. 'a198': 888,
  17139. 'a186': 967,
  17140. 'a195': 888,
  17141. 'a187': 831,
  17142. 'a188': 873,
  17143. 'a189': 927,
  17144. 'a190': 970,
  17145. 'a191': 918
  17146. }
  17147. };
  17148. exports.Metrics = Metrics;
  17149. }));
  17150. (function (root, factory) {
  17151. {
  17152. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  17153. }
  17154. }(this, function (exports, sharedGlobal) {
  17155. var PDFJS = sharedGlobal.PDFJS;
  17156. var bidi = PDFJS.bidi = (function bidiClosure() {
  17157. // Character types for symbols from 0000 to 00FF.
  17158. var baseTypes = [
  17159. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  17160. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  17161. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  17162. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  17163. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  17164. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17165. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  17166. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17167. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17168. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  17169. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  17170. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  17171. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  17172. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  17173. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17174. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17175. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17176. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  17177. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  17178. ];
  17179. // Character types for symbols from 0600 to 06FF
  17180. var arabicTypes = [
  17181. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17182. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  17183. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17184. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17185. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17186. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17187. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  17188. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  17189. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  17190. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  17191. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17192. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17193. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17194. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17195. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17196. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17197. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17198. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17199. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  17200. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  17201. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  17202. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  17203. ];
  17204. function isOdd(i) {
  17205. return (i & 1) !== 0;
  17206. }
  17207. function isEven(i) {
  17208. return (i & 1) === 0;
  17209. }
  17210. function findUnequal(arr, start, value) {
  17211. for (var j = start, jj = arr.length; j < jj; ++j) {
  17212. if (arr[j] !== value) {
  17213. return j;
  17214. }
  17215. }
  17216. return j;
  17217. }
  17218. function setValues(arr, start, end, value) {
  17219. for (var j = start; j < end; ++j) {
  17220. arr[j] = value;
  17221. }
  17222. }
  17223. function reverseValues(arr, start, end) {
  17224. for (var i = start, j = end - 1; i < j; ++i, --j) {
  17225. var temp = arr[i];
  17226. arr[i] = arr[j];
  17227. arr[j] = temp;
  17228. }
  17229. }
  17230. function createBidiText(str, isLTR, vertical) {
  17231. return {
  17232. str: str,
  17233. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  17234. };
  17235. }
  17236. // These are used in bidi(), which is called frequently. We re-use them on
  17237. // each call to avoid unnecessary allocations.
  17238. var chars = [];
  17239. var types = [];
  17240. function bidi(str, startLevel, vertical) {
  17241. var isLTR = true;
  17242. var strLength = str.length;
  17243. if (strLength === 0 || vertical) {
  17244. return createBidiText(str, isLTR, vertical);
  17245. }
  17246. // Get types and fill arrays
  17247. chars.length = strLength;
  17248. types.length = strLength;
  17249. var numBidi = 0;
  17250. var i, ii;
  17251. for (i = 0; i < strLength; ++i) {
  17252. chars[i] = str.charAt(i);
  17253. var charCode = str.charCodeAt(i);
  17254. var charType = 'L';
  17255. if (charCode <= 0x00ff) {
  17256. charType = baseTypes[charCode];
  17257. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  17258. charType = 'R';
  17259. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  17260. charType = arabicTypes[charCode & 0xff];
  17261. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  17262. charType = 'AL';
  17263. }
  17264. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  17265. numBidi++;
  17266. }
  17267. types[i] = charType;
  17268. }
  17269. // Detect the bidi method
  17270. // - If there are no rtl characters then no bidi needed
  17271. // - If less than 30% chars are rtl then string is primarily ltr
  17272. // - If more than 30% chars are rtl then string is primarily rtl
  17273. if (numBidi === 0) {
  17274. isLTR = true;
  17275. return createBidiText(str, isLTR);
  17276. }
  17277. if (startLevel === -1) {
  17278. if ((strLength / numBidi) < 0.3) {
  17279. isLTR = true;
  17280. startLevel = 0;
  17281. } else {
  17282. isLTR = false;
  17283. startLevel = 1;
  17284. }
  17285. }
  17286. var levels = [];
  17287. for (i = 0; i < strLength; ++i) {
  17288. levels[i] = startLevel;
  17289. }
  17290. /*
  17291. X1-X10: skip most of this, since we are NOT doing the embeddings.
  17292. */
  17293. var e = (isOdd(startLevel) ? 'R' : 'L');
  17294. var sor = e;
  17295. var eor = sor;
  17296. /*
  17297. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  17298. type of the NSM to the type of the previous character. If the NSM is at the
  17299. start of the level run, it will get the type of sor.
  17300. */
  17301. var lastType = sor;
  17302. for (i = 0; i < strLength; ++i) {
  17303. if (types[i] === 'NSM') {
  17304. types[i] = lastType;
  17305. } else {
  17306. lastType = types[i];
  17307. }
  17308. }
  17309. /*
  17310. W2. Search backwards from each instance of a European number until the
  17311. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  17312. the type of the European number to Arabic number.
  17313. */
  17314. lastType = sor;
  17315. var t;
  17316. for (i = 0; i < strLength; ++i) {
  17317. t = types[i];
  17318. if (t === 'EN') {
  17319. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  17320. } else if (t === 'R' || t === 'L' || t === 'AL') {
  17321. lastType = t;
  17322. }
  17323. }
  17324. /*
  17325. W3. Change all ALs to R.
  17326. */
  17327. for (i = 0; i < strLength; ++i) {
  17328. t = types[i];
  17329. if (t === 'AL') {
  17330. types[i] = 'R';
  17331. }
  17332. }
  17333. /*
  17334. W4. A single European separator between two European numbers changes to a
  17335. European number. A single common separator between two numbers of the same
  17336. type changes to that type:
  17337. */
  17338. for (i = 1; i < strLength - 1; ++i) {
  17339. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  17340. types[i] = 'EN';
  17341. }
  17342. if (types[i] === 'CS' &&
  17343. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  17344. types[i + 1] === types[i - 1]) {
  17345. types[i] = types[i - 1];
  17346. }
  17347. }
  17348. /*
  17349. W5. A sequence of European terminators adjacent to European numbers changes
  17350. to all European numbers:
  17351. */
  17352. for (i = 0; i < strLength; ++i) {
  17353. if (types[i] === 'EN') {
  17354. // do before
  17355. var j;
  17356. for (j = i - 1; j >= 0; --j) {
  17357. if (types[j] !== 'ET') {
  17358. break;
  17359. }
  17360. types[j] = 'EN';
  17361. }
  17362. // do after
  17363. for (j = i + 1; j < strLength; --j) {
  17364. if (types[j] !== 'ET') {
  17365. break;
  17366. }
  17367. types[j] = 'EN';
  17368. }
  17369. }
  17370. }
  17371. /*
  17372. W6. Otherwise, separators and terminators change to Other Neutral:
  17373. */
  17374. for (i = 0; i < strLength; ++i) {
  17375. t = types[i];
  17376. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  17377. types[i] = 'ON';
  17378. }
  17379. }
  17380. /*
  17381. W7. Search backwards from each instance of a European number until the
  17382. first strong type (R, L, or sor) is found. If an L is found, then change
  17383. the type of the European number to L.
  17384. */
  17385. lastType = sor;
  17386. for (i = 0; i < strLength; ++i) {
  17387. t = types[i];
  17388. if (t === 'EN') {
  17389. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  17390. } else if (t === 'R' || t === 'L') {
  17391. lastType = t;
  17392. }
  17393. }
  17394. /*
  17395. N1. A sequence of neutrals takes the direction of the surrounding strong
  17396. text if the text on both sides has the same direction. European and Arabic
  17397. numbers are treated as though they were R. Start-of-level-run (sor) and
  17398. end-of-level-run (eor) are used at level run boundaries.
  17399. */
  17400. for (i = 0; i < strLength; ++i) {
  17401. if (types[i] === 'ON') {
  17402. var end = findUnequal(types, i + 1, 'ON');
  17403. var before = sor;
  17404. if (i > 0) {
  17405. before = types[i - 1];
  17406. }
  17407. var after = eor;
  17408. if (end + 1 < strLength) {
  17409. after = types[end + 1];
  17410. }
  17411. if (before !== 'L') {
  17412. before = 'R';
  17413. }
  17414. if (after !== 'L') {
  17415. after = 'R';
  17416. }
  17417. if (before === after) {
  17418. setValues(types, i, end, before);
  17419. }
  17420. i = end - 1; // reset to end (-1 so next iteration is ok)
  17421. }
  17422. }
  17423. /*
  17424. N2. Any remaining neutrals take the embedding direction.
  17425. */
  17426. for (i = 0; i < strLength; ++i) {
  17427. if (types[i] === 'ON') {
  17428. types[i] = e;
  17429. }
  17430. }
  17431. /*
  17432. I1. For all characters with an even (left-to-right) embedding direction,
  17433. those of type R go up one level and those of type AN or EN go up two
  17434. levels.
  17435. I2. For all characters with an odd (right-to-left) embedding direction,
  17436. those of type L, EN or AN go up one level.
  17437. */
  17438. for (i = 0; i < strLength; ++i) {
  17439. t = types[i];
  17440. if (isEven(levels[i])) {
  17441. if (t === 'R') {
  17442. levels[i] += 1;
  17443. } else if (t === 'AN' || t === 'EN') {
  17444. levels[i] += 2;
  17445. }
  17446. } else { // isOdd
  17447. if (t === 'L' || t === 'AN' || t === 'EN') {
  17448. levels[i] += 1;
  17449. }
  17450. }
  17451. }
  17452. /*
  17453. L1. On each line, reset the embedding level of the following characters to
  17454. the paragraph embedding level:
  17455. segment separators,
  17456. paragraph separators,
  17457. any sequence of whitespace characters preceding a segment separator or
  17458. paragraph separator, and any sequence of white space characters at the end
  17459. of the line.
  17460. */
  17461. // don't bother as text is only single line
  17462. /*
  17463. L2. From the highest level found in the text to the lowest odd level on
  17464. each line, reverse any contiguous sequence of characters that are at that
  17465. level or higher.
  17466. */
  17467. // find highest level & lowest odd level
  17468. var highestLevel = -1;
  17469. var lowestOddLevel = 99;
  17470. var level;
  17471. for (i = 0, ii = levels.length; i < ii; ++i) {
  17472. level = levels[i];
  17473. if (highestLevel < level) {
  17474. highestLevel = level;
  17475. }
  17476. if (lowestOddLevel > level && isOdd(level)) {
  17477. lowestOddLevel = level;
  17478. }
  17479. }
  17480. // now reverse between those limits
  17481. for (level = highestLevel; level >= lowestOddLevel; --level) {
  17482. // find segments to reverse
  17483. var start = -1;
  17484. for (i = 0, ii = levels.length; i < ii; ++i) {
  17485. if (levels[i] < level) {
  17486. if (start >= 0) {
  17487. reverseValues(chars, start, i);
  17488. start = -1;
  17489. }
  17490. } else if (start < 0) {
  17491. start = i;
  17492. }
  17493. }
  17494. if (start >= 0) {
  17495. reverseValues(chars, start, levels.length);
  17496. }
  17497. }
  17498. /*
  17499. L3. Combining marks applied to a right-to-left base character will at this
  17500. point precede their base character. If the rendering engine expects them to
  17501. follow the base characters in the final display process, then the ordering
  17502. of the marks and the base character must be reversed.
  17503. */
  17504. // don't bother for now
  17505. /*
  17506. L4. A character that possesses the mirrored property as specified by
  17507. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  17508. directionality of that character is R.
  17509. */
  17510. // don't mirror as characters are already mirrored in the pdf
  17511. // Finally, return string
  17512. for (i = 0, ii = chars.length; i < ii; ++i) {
  17513. var ch = chars[i];
  17514. if (ch === '<' || ch === '>') {
  17515. chars[i] = '';
  17516. }
  17517. }
  17518. return createBidiText(chars.join(''), isLTR);
  17519. }
  17520. return bidi;
  17521. })();
  17522. exports.bidi = bidi;
  17523. }));
  17524. (function (root, factory) {
  17525. {
  17526. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  17527. }
  17528. }(this, function (exports, sharedUtil) {
  17529. var MissingDataException = sharedUtil.MissingDataException;
  17530. var assert = sharedUtil.assert;
  17531. var createPromiseCapability = sharedUtil.createPromiseCapability;
  17532. var isInt = sharedUtil.isInt;
  17533. var isEmptyObj = sharedUtil.isEmptyObj;
  17534. var ChunkedStream = (function ChunkedStreamClosure() {
  17535. function ChunkedStream(length, chunkSize, manager) {
  17536. this.bytes = new Uint8Array(length);
  17537. this.start = 0;
  17538. this.pos = 0;
  17539. this.end = length;
  17540. this.chunkSize = chunkSize;
  17541. this.loadedChunks = [];
  17542. this.numChunksLoaded = 0;
  17543. this.numChunks = Math.ceil(length / chunkSize);
  17544. this.manager = manager;
  17545. this.progressiveDataLength = 0;
  17546. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  17547. }
  17548. // required methods for a stream. if a particular stream does not
  17549. // implement these, an error should be thrown
  17550. ChunkedStream.prototype = {
  17551. getMissingChunks: function ChunkedStream_getMissingChunks() {
  17552. var chunks = [];
  17553. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  17554. if (!this.loadedChunks[chunk]) {
  17555. chunks.push(chunk);
  17556. }
  17557. }
  17558. return chunks;
  17559. },
  17560. getBaseStreams: function ChunkedStream_getBaseStreams() {
  17561. return [this];
  17562. },
  17563. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  17564. return this.numChunksLoaded === this.numChunks;
  17565. },
  17566. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  17567. var end = begin + chunk.byteLength;
  17568. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  17569. // Using this.length is inaccurate here since this.start can be moved
  17570. // See ChunkedStream.moveStart()
  17571. var length = this.bytes.length;
  17572. assert(end % this.chunkSize === 0 || end === length,
  17573. 'Bad end offset: ' + end);
  17574. this.bytes.set(new Uint8Array(chunk), begin);
  17575. var chunkSize = this.chunkSize;
  17576. var beginChunk = Math.floor(begin / chunkSize);
  17577. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  17578. var curChunk;
  17579. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  17580. if (!this.loadedChunks[curChunk]) {
  17581. this.loadedChunks[curChunk] = true;
  17582. ++this.numChunksLoaded;
  17583. }
  17584. }
  17585. },
  17586. onReceiveProgressiveData:
  17587. function ChunkedStream_onReceiveProgressiveData(data) {
  17588. var position = this.progressiveDataLength;
  17589. var beginChunk = Math.floor(position / this.chunkSize);
  17590. this.bytes.set(new Uint8Array(data), position);
  17591. position += data.byteLength;
  17592. this.progressiveDataLength = position;
  17593. var endChunk = position >= this.end ? this.numChunks :
  17594. Math.floor(position / this.chunkSize);
  17595. var curChunk;
  17596. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  17597. if (!this.loadedChunks[curChunk]) {
  17598. this.loadedChunks[curChunk] = true;
  17599. ++this.numChunksLoaded;
  17600. }
  17601. }
  17602. },
  17603. ensureByte: function ChunkedStream_ensureByte(pos) {
  17604. var chunk = Math.floor(pos / this.chunkSize);
  17605. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  17606. return;
  17607. }
  17608. if (!this.loadedChunks[chunk]) {
  17609. throw new MissingDataException(pos, pos + 1);
  17610. }
  17611. this.lastSuccessfulEnsureByteChunk = chunk;
  17612. },
  17613. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  17614. if (begin >= end) {
  17615. return;
  17616. }
  17617. if (end <= this.progressiveDataLength) {
  17618. return;
  17619. }
  17620. var chunkSize = this.chunkSize;
  17621. var beginChunk = Math.floor(begin / chunkSize);
  17622. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  17623. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17624. if (!this.loadedChunks[chunk]) {
  17625. throw new MissingDataException(begin, end);
  17626. }
  17627. }
  17628. },
  17629. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  17630. var chunk, numChunks = this.numChunks;
  17631. for (var i = 0; i < numChunks; ++i) {
  17632. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  17633. if (!this.loadedChunks[chunk]) {
  17634. return chunk;
  17635. }
  17636. }
  17637. return null;
  17638. },
  17639. hasChunk: function ChunkedStream_hasChunk(chunk) {
  17640. return !!this.loadedChunks[chunk];
  17641. },
  17642. get length() {
  17643. return this.end - this.start;
  17644. },
  17645. get isEmpty() {
  17646. return this.length === 0;
  17647. },
  17648. getByte: function ChunkedStream_getByte() {
  17649. var pos = this.pos;
  17650. if (pos >= this.end) {
  17651. return -1;
  17652. }
  17653. this.ensureByte(pos);
  17654. return this.bytes[this.pos++];
  17655. },
  17656. getUint16: function ChunkedStream_getUint16() {
  17657. var b0 = this.getByte();
  17658. var b1 = this.getByte();
  17659. if (b0 === -1 || b1 === -1) {
  17660. return -1;
  17661. }
  17662. return (b0 << 8) + b1;
  17663. },
  17664. getInt32: function ChunkedStream_getInt32() {
  17665. var b0 = this.getByte();
  17666. var b1 = this.getByte();
  17667. var b2 = this.getByte();
  17668. var b3 = this.getByte();
  17669. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17670. },
  17671. // returns subarray of original buffer
  17672. // should only be read
  17673. getBytes: function ChunkedStream_getBytes(length) {
  17674. var bytes = this.bytes;
  17675. var pos = this.pos;
  17676. var strEnd = this.end;
  17677. if (!length) {
  17678. this.ensureRange(pos, strEnd);
  17679. return bytes.subarray(pos, strEnd);
  17680. }
  17681. var end = pos + length;
  17682. if (end > strEnd) {
  17683. end = strEnd;
  17684. }
  17685. this.ensureRange(pos, end);
  17686. this.pos = end;
  17687. return bytes.subarray(pos, end);
  17688. },
  17689. peekByte: function ChunkedStream_peekByte() {
  17690. var peekedByte = this.getByte();
  17691. this.pos--;
  17692. return peekedByte;
  17693. },
  17694. peekBytes: function ChunkedStream_peekBytes(length) {
  17695. var bytes = this.getBytes(length);
  17696. this.pos -= bytes.length;
  17697. return bytes;
  17698. },
  17699. getByteRange: function ChunkedStream_getBytes(begin, end) {
  17700. this.ensureRange(begin, end);
  17701. return this.bytes.subarray(begin, end);
  17702. },
  17703. skip: function ChunkedStream_skip(n) {
  17704. if (!n) {
  17705. n = 1;
  17706. }
  17707. this.pos += n;
  17708. },
  17709. reset: function ChunkedStream_reset() {
  17710. this.pos = this.start;
  17711. },
  17712. moveStart: function ChunkedStream_moveStart() {
  17713. this.start = this.pos;
  17714. },
  17715. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  17716. this.ensureRange(start, start + length);
  17717. function ChunkedStreamSubstream() {}
  17718. ChunkedStreamSubstream.prototype = Object.create(this);
  17719. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  17720. var chunkSize = this.chunkSize;
  17721. var beginChunk = Math.floor(this.start / chunkSize);
  17722. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  17723. var missingChunks = [];
  17724. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17725. if (!this.loadedChunks[chunk]) {
  17726. missingChunks.push(chunk);
  17727. }
  17728. }
  17729. return missingChunks;
  17730. };
  17731. var subStream = new ChunkedStreamSubstream();
  17732. subStream.pos = subStream.start = start;
  17733. subStream.end = start + length || this.end;
  17734. subStream.dict = dict;
  17735. return subStream;
  17736. },
  17737. isStream: true
  17738. };
  17739. return ChunkedStream;
  17740. })();
  17741. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  17742. function ChunkedStreamManager(length, chunkSize, url, args) {
  17743. this.stream = new ChunkedStream(length, chunkSize, this);
  17744. this.length = length;
  17745. this.chunkSize = chunkSize;
  17746. this.url = url;
  17747. this.disableAutoFetch = args.disableAutoFetch;
  17748. var msgHandler = this.msgHandler = args.msgHandler;
  17749. if (args.chunkedViewerLoading) {
  17750. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  17751. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  17752. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  17753. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  17754. };
  17755. } else {
  17756. var getXhr = function getXhr() {
  17757. return new XMLHttpRequest();
  17758. };
  17759. this.networkManager = new NetworkManager(this.url, {
  17760. getXhr: getXhr,
  17761. httpHeaders: args.httpHeaders,
  17762. withCredentials: args.withCredentials
  17763. });
  17764. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  17765. this.networkManager.requestRange(begin, end, {
  17766. onDone: this.onReceiveData.bind(this),
  17767. onProgress: this.onProgress.bind(this)
  17768. });
  17769. };
  17770. }
  17771. this.currRequestId = 0;
  17772. this.chunksNeededByRequest = {};
  17773. this.requestsByChunk = {};
  17774. this.promisesByRequest = {};
  17775. this.progressiveDataLength = 0;
  17776. this._loadedStreamCapability = createPromiseCapability();
  17777. if (args.initialData) {
  17778. this.onReceiveData({chunk: args.initialData});
  17779. }
  17780. }
  17781. ChunkedStreamManager.prototype = {
  17782. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  17783. return this._loadedStreamCapability.promise;
  17784. },
  17785. // Get all the chunks that are not yet loaded and groups them into
  17786. // contiguous ranges to load in as few requests as possible
  17787. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  17788. var missingChunks = this.stream.getMissingChunks();
  17789. this._requestChunks(missingChunks);
  17790. return this._loadedStreamCapability.promise;
  17791. },
  17792. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  17793. var requestId = this.currRequestId++;
  17794. var chunksNeeded;
  17795. var i, ii;
  17796. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  17797. for (i = 0, ii = chunks.length; i < ii; i++) {
  17798. if (!this.stream.hasChunk(chunks[i])) {
  17799. chunksNeeded[chunks[i]] = true;
  17800. }
  17801. }
  17802. if (isEmptyObj(chunksNeeded)) {
  17803. return Promise.resolve();
  17804. }
  17805. var capability = createPromiseCapability();
  17806. this.promisesByRequest[requestId] = capability;
  17807. var chunksToRequest = [];
  17808. for (var chunk in chunksNeeded) {
  17809. chunk = chunk | 0;
  17810. if (!(chunk in this.requestsByChunk)) {
  17811. this.requestsByChunk[chunk] = [];
  17812. chunksToRequest.push(chunk);
  17813. }
  17814. this.requestsByChunk[chunk].push(requestId);
  17815. }
  17816. if (!chunksToRequest.length) {
  17817. return capability.promise;
  17818. }
  17819. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  17820. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  17821. var groupedChunk = groupedChunksToRequest[i];
  17822. var begin = groupedChunk.beginChunk * this.chunkSize;
  17823. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  17824. this.sendRequest(begin, end);
  17825. }
  17826. return capability.promise;
  17827. },
  17828. getStream: function ChunkedStreamManager_getStream() {
  17829. return this.stream;
  17830. },
  17831. // Loads any chunks in the requested range that are not yet loaded
  17832. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  17833. end = Math.min(end, this.length);
  17834. var beginChunk = this.getBeginChunk(begin);
  17835. var endChunk = this.getEndChunk(end);
  17836. var chunks = [];
  17837. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17838. chunks.push(chunk);
  17839. }
  17840. return this._requestChunks(chunks);
  17841. },
  17842. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  17843. ranges = ranges || [];
  17844. var chunksToRequest = [];
  17845. for (var i = 0; i < ranges.length; i++) {
  17846. var beginChunk = this.getBeginChunk(ranges[i].begin);
  17847. var endChunk = this.getEndChunk(ranges[i].end);
  17848. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17849. if (chunksToRequest.indexOf(chunk) < 0) {
  17850. chunksToRequest.push(chunk);
  17851. }
  17852. }
  17853. }
  17854. chunksToRequest.sort(function(a, b) { return a - b; });
  17855. return this._requestChunks(chunksToRequest);
  17856. },
  17857. // Groups a sorted array of chunks into as few contiguous larger
  17858. // chunks as possible
  17859. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  17860. var groupedChunks = [];
  17861. var beginChunk = -1;
  17862. var prevChunk = -1;
  17863. for (var i = 0; i < chunks.length; ++i) {
  17864. var chunk = chunks[i];
  17865. if (beginChunk < 0) {
  17866. beginChunk = chunk;
  17867. }
  17868. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  17869. groupedChunks.push({ beginChunk: beginChunk,
  17870. endChunk: prevChunk + 1 });
  17871. beginChunk = chunk;
  17872. }
  17873. if (i + 1 === chunks.length) {
  17874. groupedChunks.push({ beginChunk: beginChunk,
  17875. endChunk: chunk + 1 });
  17876. }
  17877. prevChunk = chunk;
  17878. }
  17879. return groupedChunks;
  17880. },
  17881. onProgress: function ChunkedStreamManager_onProgress(args) {
  17882. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  17883. args.loaded);
  17884. this.msgHandler.send('DocProgress', {
  17885. loaded: bytesLoaded,
  17886. total: this.length
  17887. });
  17888. },
  17889. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  17890. var chunk = args.chunk;
  17891. var isProgressive = args.begin === undefined;
  17892. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  17893. var end = begin + chunk.byteLength;
  17894. var beginChunk = Math.floor(begin / this.chunkSize);
  17895. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  17896. Math.ceil(end / this.chunkSize);
  17897. if (isProgressive) {
  17898. this.stream.onReceiveProgressiveData(chunk);
  17899. this.progressiveDataLength = end;
  17900. } else {
  17901. this.stream.onReceiveData(begin, chunk);
  17902. }
  17903. if (this.stream.allChunksLoaded()) {
  17904. this._loadedStreamCapability.resolve(this.stream);
  17905. }
  17906. var loadedRequests = [];
  17907. var i, requestId;
  17908. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  17909. // The server might return more chunks than requested
  17910. var requestIds = this.requestsByChunk[chunk] || [];
  17911. delete this.requestsByChunk[chunk];
  17912. for (i = 0; i < requestIds.length; ++i) {
  17913. requestId = requestIds[i];
  17914. var chunksNeeded = this.chunksNeededByRequest[requestId];
  17915. if (chunk in chunksNeeded) {
  17916. delete chunksNeeded[chunk];
  17917. }
  17918. if (!isEmptyObj(chunksNeeded)) {
  17919. continue;
  17920. }
  17921. loadedRequests.push(requestId);
  17922. }
  17923. }
  17924. // If there are no pending requests, automatically fetch the next
  17925. // unfetched chunk of the PDF
  17926. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  17927. var nextEmptyChunk;
  17928. if (this.stream.numChunksLoaded === 1) {
  17929. // This is a special optimization so that after fetching the first
  17930. // chunk, rather than fetching the second chunk, we fetch the last
  17931. // chunk.
  17932. var lastChunk = this.stream.numChunks - 1;
  17933. if (!this.stream.hasChunk(lastChunk)) {
  17934. nextEmptyChunk = lastChunk;
  17935. }
  17936. } else {
  17937. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  17938. }
  17939. if (isInt(nextEmptyChunk)) {
  17940. this._requestChunks([nextEmptyChunk]);
  17941. }
  17942. }
  17943. for (i = 0; i < loadedRequests.length; ++i) {
  17944. requestId = loadedRequests[i];
  17945. var capability = this.promisesByRequest[requestId];
  17946. delete this.promisesByRequest[requestId];
  17947. capability.resolve();
  17948. }
  17949. this.msgHandler.send('DocProgress', {
  17950. loaded: this.stream.numChunksLoaded * this.chunkSize,
  17951. total: this.length
  17952. });
  17953. },
  17954. onError: function ChunkedStreamManager_onError(err) {
  17955. this._loadedStreamCapability.reject(err);
  17956. },
  17957. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  17958. var chunk = Math.floor(begin / this.chunkSize);
  17959. return chunk;
  17960. },
  17961. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  17962. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  17963. return chunk;
  17964. },
  17965. abort: function ChunkedStreamManager_abort() {
  17966. if (this.networkManager) {
  17967. this.networkManager.abortAllRequests();
  17968. }
  17969. for(var requestId in this.promisesByRequest) {
  17970. var capability = this.promisesByRequest[requestId];
  17971. capability.reject(new Error('Request was aborted'));
  17972. }
  17973. }
  17974. };
  17975. return ChunkedStreamManager;
  17976. })();
  17977. exports.ChunkedStream = ChunkedStream;
  17978. exports.ChunkedStreamManager = ChunkedStreamManager;
  17979. }));
  17980. (function (root, factory) {
  17981. {
  17982. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  17983. root.pdfjsCoreArithmeticDecoder);
  17984. }
  17985. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  17986. var error = sharedUtil.error;
  17987. var log2 = sharedUtil.log2;
  17988. var readInt8 = sharedUtil.readInt8;
  17989. var readUint16 = sharedUtil.readUint16;
  17990. var readUint32 = sharedUtil.readUint32;
  17991. var shadow = sharedUtil.shadow;
  17992. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  17993. var Jbig2Image = (function Jbig2ImageClosure() {
  17994. // Utility data structures
  17995. function ContextCache() {}
  17996. ContextCache.prototype = {
  17997. getContexts: function(id) {
  17998. if (id in this) {
  17999. return this[id];
  18000. }
  18001. return (this[id] = new Int8Array(1 << 16));
  18002. }
  18003. };
  18004. function DecodingContext(data, start, end) {
  18005. this.data = data;
  18006. this.start = start;
  18007. this.end = end;
  18008. }
  18009. DecodingContext.prototype = {
  18010. get decoder() {
  18011. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  18012. return shadow(this, 'decoder', decoder);
  18013. },
  18014. get contextCache() {
  18015. var cache = new ContextCache();
  18016. return shadow(this, 'contextCache', cache);
  18017. }
  18018. };
  18019. // Annex A. Arithmetic Integer Decoding Procedure
  18020. // A.2 Procedure for decoding values
  18021. function decodeInteger(contextCache, procedure, decoder) {
  18022. var contexts = contextCache.getContexts(procedure);
  18023. var prev = 1;
  18024. function readBits(length) {
  18025. var v = 0;
  18026. for (var i = 0; i < length; i++) {
  18027. var bit = decoder.readBit(contexts, prev);
  18028. prev = (prev < 256 ? (prev << 1) | bit :
  18029. (((prev << 1) | bit) & 511) | 256);
  18030. v = (v << 1) | bit;
  18031. }
  18032. return v >>> 0;
  18033. }
  18034. var sign = readBits(1);
  18035. var value = readBits(1) ?
  18036. (readBits(1) ?
  18037. (readBits(1) ?
  18038. (readBits(1) ?
  18039. (readBits(1) ?
  18040. (readBits(32) + 4436) :
  18041. readBits(12) + 340) :
  18042. readBits(8) + 84) :
  18043. readBits(6) + 20) :
  18044. readBits(4) + 4) :
  18045. readBits(2);
  18046. return (sign === 0 ? value : (value > 0 ? -value : null));
  18047. }
  18048. // A.3 The IAID decoding procedure
  18049. function decodeIAID(contextCache, decoder, codeLength) {
  18050. var contexts = contextCache.getContexts('IAID');
  18051. var prev = 1;
  18052. for (var i = 0; i < codeLength; i++) {
  18053. var bit = decoder.readBit(contexts, prev);
  18054. prev = (prev << 1) | bit;
  18055. }
  18056. if (codeLength < 31) {
  18057. return prev & ((1 << codeLength) - 1);
  18058. }
  18059. return prev & 0x7FFFFFFF;
  18060. }
  18061. // 7.3 Segment types
  18062. var SegmentTypes = [
  18063. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  18064. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  18065. null, null, null, null, null, 'patternDictionary', null, null, null,
  18066. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  18067. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  18068. null, null, null, null, null, 'IntermediateGenericRegion', null,
  18069. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  18070. 'IntermediateGenericRefinementRegion', null,
  18071. 'ImmediateGenericRefinementRegion',
  18072. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  18073. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  18074. 'Tables', null, null, null, null, null, null, null, null,
  18075. 'Extension'
  18076. ];
  18077. var CodingTemplates = [
  18078. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  18079. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  18080. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  18081. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  18082. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  18083. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  18084. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  18085. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  18086. {x: -1, y: 0}],
  18087. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  18088. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  18089. ];
  18090. var RefinementTemplates = [
  18091. {
  18092. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  18093. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  18094. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  18095. },
  18096. {
  18097. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  18098. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  18099. {x: 0, y: 1}, {x: 1, y: 1}]
  18100. }
  18101. ];
  18102. // See 6.2.5.7 Decoding the bitmap.
  18103. var ReusedContexts = [
  18104. 0x9B25, // 10011 0110010 0101
  18105. 0x0795, // 0011 110010 101
  18106. 0x00E5, // 001 11001 01
  18107. 0x0195 // 011001 0101
  18108. ];
  18109. var RefinementReusedContexts = [
  18110. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  18111. 0x0008 // '0000' + '001000'
  18112. ];
  18113. function decodeBitmapTemplate0(width, height, decodingContext) {
  18114. var decoder = decodingContext.decoder;
  18115. var contexts = decodingContext.contextCache.getContexts('GB');
  18116. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  18117. // ...ooooo....
  18118. // ..ooooooo... Context template for current pixel (X)
  18119. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  18120. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  18121. for (i = 0; i < height; i++) {
  18122. row = bitmap[i] = new Uint8Array(width);
  18123. row1 = (i < 1) ? row : bitmap[i - 1];
  18124. row2 = (i < 2) ? row : bitmap[i - 2];
  18125. // At the beginning of each row:
  18126. // Fill contextLabel with pixels that are above/right of (X)
  18127. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  18128. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  18129. (row1[3] << 4);
  18130. for (j = 0; j < width; j++) {
  18131. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  18132. // At each pixel: Clear contextLabel pixels that are shifted
  18133. // out of the context, then add new ones.
  18134. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  18135. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  18136. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  18137. }
  18138. }
  18139. return bitmap;
  18140. }
  18141. // 6.2 Generic Region Decoding Procedure
  18142. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  18143. decodingContext) {
  18144. if (mmr) {
  18145. error('JBIG2 error: MMR encoding is not supported');
  18146. }
  18147. // Use optimized version for the most common case
  18148. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  18149. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  18150. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  18151. return decodeBitmapTemplate0(width, height, decodingContext);
  18152. }
  18153. var useskip = !!skip;
  18154. var template = CodingTemplates[templateIndex].concat(at);
  18155. // Sorting is non-standard, and it is not required. But sorting increases
  18156. // the number of template bits that can be reused from the previous
  18157. // contextLabel in the main loop.
  18158. template.sort(function (a, b) {
  18159. return (a.y - b.y) || (a.x - b.x);
  18160. });
  18161. var templateLength = template.length;
  18162. var templateX = new Int8Array(templateLength);
  18163. var templateY = new Int8Array(templateLength);
  18164. var changingTemplateEntries = [];
  18165. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  18166. var c, k;
  18167. for (k = 0; k < templateLength; k++) {
  18168. templateX[k] = template[k].x;
  18169. templateY[k] = template[k].y;
  18170. minX = Math.min(minX, template[k].x);
  18171. maxX = Math.max(maxX, template[k].x);
  18172. minY = Math.min(minY, template[k].y);
  18173. // Check if the template pixel appears in two consecutive context labels,
  18174. // so it can be reused. Otherwise, we add it to the list of changing
  18175. // template entries.
  18176. if (k < templateLength - 1 &&
  18177. template[k].y === template[k + 1].y &&
  18178. template[k].x === template[k + 1].x - 1) {
  18179. reuseMask |= 1 << (templateLength - 1 - k);
  18180. } else {
  18181. changingTemplateEntries.push(k);
  18182. }
  18183. }
  18184. var changingEntriesLength = changingTemplateEntries.length;
  18185. var changingTemplateX = new Int8Array(changingEntriesLength);
  18186. var changingTemplateY = new Int8Array(changingEntriesLength);
  18187. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  18188. for (c = 0; c < changingEntriesLength; c++) {
  18189. k = changingTemplateEntries[c];
  18190. changingTemplateX[c] = template[k].x;
  18191. changingTemplateY[c] = template[k].y;
  18192. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  18193. }
  18194. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  18195. var sbb_left = -minX;
  18196. var sbb_top = -minY;
  18197. var sbb_right = width - maxX;
  18198. var pseudoPixelContext = ReusedContexts[templateIndex];
  18199. var row = new Uint8Array(width);
  18200. var bitmap = [];
  18201. var decoder = decodingContext.decoder;
  18202. var contexts = decodingContext.contextCache.getContexts('GB');
  18203. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  18204. for (var i = 0; i < height; i++) {
  18205. if (prediction) {
  18206. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  18207. ltp ^= sltp;
  18208. if (ltp) {
  18209. bitmap.push(row); // duplicate previous row
  18210. continue;
  18211. }
  18212. }
  18213. row = new Uint8Array(row);
  18214. bitmap.push(row);
  18215. for (j = 0; j < width; j++) {
  18216. if (useskip && skip[i][j]) {
  18217. row[j] = 0;
  18218. continue;
  18219. }
  18220. // Are we in the middle of a scanline, so we can reuse contextLabel
  18221. // bits?
  18222. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  18223. // If yes, we can just shift the bits that are reusable and only
  18224. // fetch the remaining ones.
  18225. contextLabel = (contextLabel << 1) & reuseMask;
  18226. for (k = 0; k < changingEntriesLength; k++) {
  18227. i0 = i + changingTemplateY[k];
  18228. j0 = j + changingTemplateX[k];
  18229. bit = bitmap[i0][j0];
  18230. if (bit) {
  18231. bit = changingTemplateBit[k];
  18232. contextLabel |= bit;
  18233. }
  18234. }
  18235. } else {
  18236. // compute the contextLabel from scratch
  18237. contextLabel = 0;
  18238. shift = templateLength - 1;
  18239. for (k = 0; k < templateLength; k++, shift--) {
  18240. j0 = j + templateX[k];
  18241. if (j0 >= 0 && j0 < width) {
  18242. i0 = i + templateY[k];
  18243. if (i0 >= 0) {
  18244. bit = bitmap[i0][j0];
  18245. if (bit) {
  18246. contextLabel |= bit << shift;
  18247. }
  18248. }
  18249. }
  18250. }
  18251. }
  18252. var pixel = decoder.readBit(contexts, contextLabel);
  18253. row[j] = pixel;
  18254. }
  18255. }
  18256. return bitmap;
  18257. }
  18258. // 6.3.2 Generic Refinement Region Decoding Procedure
  18259. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  18260. offsetX, offsetY, prediction, at,
  18261. decodingContext) {
  18262. var codingTemplate = RefinementTemplates[templateIndex].coding;
  18263. if (templateIndex === 0) {
  18264. codingTemplate = codingTemplate.concat([at[0]]);
  18265. }
  18266. var codingTemplateLength = codingTemplate.length;
  18267. var codingTemplateX = new Int32Array(codingTemplateLength);
  18268. var codingTemplateY = new Int32Array(codingTemplateLength);
  18269. var k;
  18270. for (k = 0; k < codingTemplateLength; k++) {
  18271. codingTemplateX[k] = codingTemplate[k].x;
  18272. codingTemplateY[k] = codingTemplate[k].y;
  18273. }
  18274. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  18275. if (templateIndex === 0) {
  18276. referenceTemplate = referenceTemplate.concat([at[1]]);
  18277. }
  18278. var referenceTemplateLength = referenceTemplate.length;
  18279. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  18280. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  18281. for (k = 0; k < referenceTemplateLength; k++) {
  18282. referenceTemplateX[k] = referenceTemplate[k].x;
  18283. referenceTemplateY[k] = referenceTemplate[k].y;
  18284. }
  18285. var referenceWidth = referenceBitmap[0].length;
  18286. var referenceHeight = referenceBitmap.length;
  18287. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  18288. var bitmap = [];
  18289. var decoder = decodingContext.decoder;
  18290. var contexts = decodingContext.contextCache.getContexts('GR');
  18291. var ltp = 0;
  18292. for (var i = 0; i < height; i++) {
  18293. if (prediction) {
  18294. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  18295. ltp ^= sltp;
  18296. if (ltp) {
  18297. error('JBIG2 error: prediction is not supported');
  18298. }
  18299. }
  18300. var row = new Uint8Array(width);
  18301. bitmap.push(row);
  18302. for (var j = 0; j < width; j++) {
  18303. var i0, j0;
  18304. var contextLabel = 0;
  18305. for (k = 0; k < codingTemplateLength; k++) {
  18306. i0 = i + codingTemplateY[k];
  18307. j0 = j + codingTemplateX[k];
  18308. if (i0 < 0 || j0 < 0 || j0 >= width) {
  18309. contextLabel <<= 1; // out of bound pixel
  18310. } else {
  18311. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  18312. }
  18313. }
  18314. for (k = 0; k < referenceTemplateLength; k++) {
  18315. i0 = i + referenceTemplateY[k] + offsetY;
  18316. j0 = j + referenceTemplateX[k] + offsetX;
  18317. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  18318. j0 >= referenceWidth) {
  18319. contextLabel <<= 1; // out of bound pixel
  18320. } else {
  18321. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  18322. }
  18323. }
  18324. var pixel = decoder.readBit(contexts, contextLabel);
  18325. row[j] = pixel;
  18326. }
  18327. }
  18328. return bitmap;
  18329. }
  18330. // 6.5.5 Decoding the symbol dictionary
  18331. function decodeSymbolDictionary(huffman, refinement, symbols,
  18332. numberOfNewSymbols, numberOfExportedSymbols,
  18333. huffmanTables, templateIndex, at,
  18334. refinementTemplateIndex, refinementAt,
  18335. decodingContext) {
  18336. if (huffman) {
  18337. error('JBIG2 error: huffman is not supported');
  18338. }
  18339. var newSymbols = [];
  18340. var currentHeight = 0;
  18341. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  18342. var decoder = decodingContext.decoder;
  18343. var contextCache = decodingContext.contextCache;
  18344. while (newSymbols.length < numberOfNewSymbols) {
  18345. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  18346. currentHeight += deltaHeight;
  18347. var currentWidth = 0;
  18348. var totalWidth = 0;
  18349. while (true) {
  18350. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  18351. if (deltaWidth === null) {
  18352. break; // OOB
  18353. }
  18354. currentWidth += deltaWidth;
  18355. totalWidth += currentWidth;
  18356. var bitmap;
  18357. if (refinement) {
  18358. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  18359. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  18360. if (numberOfInstances > 1) {
  18361. bitmap = decodeTextRegion(huffman, refinement,
  18362. currentWidth, currentHeight, 0,
  18363. numberOfInstances, 1, //strip size
  18364. symbols.concat(newSymbols),
  18365. symbolCodeLength,
  18366. 0, //transposed
  18367. 0, //ds offset
  18368. 1, //top left 7.4.3.1.1
  18369. 0, //OR operator
  18370. huffmanTables,
  18371. refinementTemplateIndex, refinementAt,
  18372. decodingContext);
  18373. } else {
  18374. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  18375. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  18376. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  18377. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  18378. newSymbols[symbolId - symbols.length]);
  18379. bitmap = decodeRefinement(currentWidth, currentHeight,
  18380. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  18381. decodingContext);
  18382. }
  18383. } else {
  18384. // 6.5.8.1 Direct-coded symbol bitmap
  18385. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  18386. templateIndex, false, null, at, decodingContext);
  18387. }
  18388. newSymbols.push(bitmap);
  18389. }
  18390. }
  18391. // 6.5.10 Exported symbols
  18392. var exportedSymbols = [];
  18393. var flags = [], currentFlag = false;
  18394. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  18395. while (flags.length < totalSymbolsLength) {
  18396. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  18397. while (runLength--) {
  18398. flags.push(currentFlag);
  18399. }
  18400. currentFlag = !currentFlag;
  18401. }
  18402. for (var i = 0, ii = symbols.length; i < ii; i++) {
  18403. if (flags[i]) {
  18404. exportedSymbols.push(symbols[i]);
  18405. }
  18406. }
  18407. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  18408. if (flags[i]) {
  18409. exportedSymbols.push(newSymbols[j]);
  18410. }
  18411. }
  18412. return exportedSymbols;
  18413. }
  18414. function decodeTextRegion(huffman, refinement, width, height,
  18415. defaultPixelValue, numberOfSymbolInstances,
  18416. stripSize, inputSymbols, symbolCodeLength,
  18417. transposed, dsOffset, referenceCorner,
  18418. combinationOperator, huffmanTables,
  18419. refinementTemplateIndex, refinementAt,
  18420. decodingContext) {
  18421. if (huffman) {
  18422. error('JBIG2 error: huffman is not supported');
  18423. }
  18424. // Prepare bitmap
  18425. var bitmap = [];
  18426. var i, row;
  18427. for (i = 0; i < height; i++) {
  18428. row = new Uint8Array(width);
  18429. if (defaultPixelValue) {
  18430. for (var j = 0; j < width; j++) {
  18431. row[j] = defaultPixelValue;
  18432. }
  18433. }
  18434. bitmap.push(row);
  18435. }
  18436. var decoder = decodingContext.decoder;
  18437. var contextCache = decodingContext.contextCache;
  18438. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  18439. var firstS = 0;
  18440. i = 0;
  18441. while (i < numberOfSymbolInstances) {
  18442. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  18443. stripT += deltaT;
  18444. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  18445. firstS += deltaFirstS;
  18446. var currentS = firstS;
  18447. do {
  18448. var currentT = (stripSize === 1 ? 0 :
  18449. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  18450. var t = stripSize * stripT + currentT;
  18451. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  18452. var applyRefinement = (refinement &&
  18453. decodeInteger(contextCache, 'IARI', decoder));
  18454. var symbolBitmap = inputSymbols[symbolId];
  18455. var symbolWidth = symbolBitmap[0].length;
  18456. var symbolHeight = symbolBitmap.length;
  18457. if (applyRefinement) {
  18458. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  18459. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  18460. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  18461. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  18462. symbolWidth += rdw;
  18463. symbolHeight += rdh;
  18464. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  18465. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  18466. (rdh >> 1) + rdy, false, refinementAt,
  18467. decodingContext);
  18468. }
  18469. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  18470. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  18471. var s2, t2, symbolRow;
  18472. if (transposed) {
  18473. // Place Symbol Bitmap from T1,S1
  18474. for (s2 = 0; s2 < symbolHeight; s2++) {
  18475. row = bitmap[offsetS + s2];
  18476. if (!row) {
  18477. continue;
  18478. }
  18479. symbolRow = symbolBitmap[s2];
  18480. // To ignore Parts of Symbol bitmap which goes
  18481. // outside bitmap region
  18482. var maxWidth = Math.min(width - offsetT, symbolWidth);
  18483. switch (combinationOperator) {
  18484. case 0: // OR
  18485. for (t2 = 0; t2 < maxWidth; t2++) {
  18486. row[offsetT + t2] |= symbolRow[t2];
  18487. }
  18488. break;
  18489. case 2: // XOR
  18490. for (t2 = 0; t2 < maxWidth; t2++) {
  18491. row[offsetT + t2] ^= symbolRow[t2];
  18492. }
  18493. break;
  18494. default:
  18495. error('JBIG2 error: operator ' + combinationOperator +
  18496. ' is not supported');
  18497. }
  18498. }
  18499. currentS += symbolHeight - 1;
  18500. } else {
  18501. for (t2 = 0; t2 < symbolHeight; t2++) {
  18502. row = bitmap[offsetT + t2];
  18503. if (!row) {
  18504. continue;
  18505. }
  18506. symbolRow = symbolBitmap[t2];
  18507. switch (combinationOperator) {
  18508. case 0: // OR
  18509. for (s2 = 0; s2 < symbolWidth; s2++) {
  18510. row[offsetS + s2] |= symbolRow[s2];
  18511. }
  18512. break;
  18513. case 2: // XOR
  18514. for (s2 = 0; s2 < symbolWidth; s2++) {
  18515. row[offsetS + s2] ^= symbolRow[s2];
  18516. }
  18517. break;
  18518. default:
  18519. error('JBIG2 error: operator ' + combinationOperator +
  18520. ' is not supported');
  18521. }
  18522. }
  18523. currentS += symbolWidth - 1;
  18524. }
  18525. i++;
  18526. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  18527. if (deltaS === null) {
  18528. break; // OOB
  18529. }
  18530. currentS += deltaS + dsOffset;
  18531. } while (true);
  18532. }
  18533. return bitmap;
  18534. }
  18535. function readSegmentHeader(data, start) {
  18536. var segmentHeader = {};
  18537. segmentHeader.number = readUint32(data, start);
  18538. var flags = data[start + 4];
  18539. var segmentType = flags & 0x3F;
  18540. if (!SegmentTypes[segmentType]) {
  18541. error('JBIG2 error: invalid segment type: ' + segmentType);
  18542. }
  18543. segmentHeader.type = segmentType;
  18544. segmentHeader.typeName = SegmentTypes[segmentType];
  18545. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  18546. var pageAssociationFieldSize = !!(flags & 0x40);
  18547. var referredFlags = data[start + 5];
  18548. var referredToCount = (referredFlags >> 5) & 7;
  18549. var retainBits = [referredFlags & 31];
  18550. var position = start + 6;
  18551. if (referredFlags === 7) {
  18552. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  18553. position += 3;
  18554. var bytes = (referredToCount + 7) >> 3;
  18555. retainBits[0] = data[position++];
  18556. while (--bytes > 0) {
  18557. retainBits.push(data[position++]);
  18558. }
  18559. } else if (referredFlags === 5 || referredFlags === 6) {
  18560. error('JBIG2 error: invalid referred-to flags');
  18561. }
  18562. segmentHeader.retainBits = retainBits;
  18563. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  18564. (segmentHeader.number <= 65536 ? 2 : 4));
  18565. var referredTo = [];
  18566. var i, ii;
  18567. for (i = 0; i < referredToCount; i++) {
  18568. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  18569. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  18570. readUint32(data, position)));
  18571. referredTo.push(number);
  18572. position += referredToSegmentNumberSize;
  18573. }
  18574. segmentHeader.referredTo = referredTo;
  18575. if (!pageAssociationFieldSize) {
  18576. segmentHeader.pageAssociation = data[position++];
  18577. } else {
  18578. segmentHeader.pageAssociation = readUint32(data, position);
  18579. position += 4;
  18580. }
  18581. segmentHeader.length = readUint32(data, position);
  18582. position += 4;
  18583. if (segmentHeader.length === 0xFFFFFFFF) {
  18584. // 7.2.7 Segment data length, unknown segment length
  18585. if (segmentType === 38) { // ImmediateGenericRegion
  18586. var genericRegionInfo = readRegionSegmentInformation(data, position);
  18587. var genericRegionSegmentFlags = data[position +
  18588. RegionSegmentInformationFieldLength];
  18589. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  18590. // searching for the segment end
  18591. var searchPatternLength = 6;
  18592. var searchPattern = new Uint8Array(searchPatternLength);
  18593. if (!genericRegionMmr) {
  18594. searchPattern[0] = 0xFF;
  18595. searchPattern[1] = 0xAC;
  18596. }
  18597. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  18598. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  18599. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  18600. searchPattern[5] = genericRegionInfo.height & 0xFF;
  18601. for (i = position, ii = data.length; i < ii; i++) {
  18602. var j = 0;
  18603. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  18604. j++;
  18605. }
  18606. if (j === searchPatternLength) {
  18607. segmentHeader.length = i + searchPatternLength;
  18608. break;
  18609. }
  18610. }
  18611. if (segmentHeader.length === 0xFFFFFFFF) {
  18612. error('JBIG2 error: segment end was not found');
  18613. }
  18614. } else {
  18615. error('JBIG2 error: invalid unknown segment length');
  18616. }
  18617. }
  18618. segmentHeader.headerEnd = position;
  18619. return segmentHeader;
  18620. }
  18621. function readSegments(header, data, start, end) {
  18622. var segments = [];
  18623. var position = start;
  18624. while (position < end) {
  18625. var segmentHeader = readSegmentHeader(data, position);
  18626. position = segmentHeader.headerEnd;
  18627. var segment = {
  18628. header: segmentHeader,
  18629. data: data
  18630. };
  18631. if (!header.randomAccess) {
  18632. segment.start = position;
  18633. position += segmentHeader.length;
  18634. segment.end = position;
  18635. }
  18636. segments.push(segment);
  18637. if (segmentHeader.type === 51) {
  18638. break; // end of file is found
  18639. }
  18640. }
  18641. if (header.randomAccess) {
  18642. for (var i = 0, ii = segments.length; i < ii; i++) {
  18643. segments[i].start = position;
  18644. position += segments[i].header.length;
  18645. segments[i].end = position;
  18646. }
  18647. }
  18648. return segments;
  18649. }
  18650. // 7.4.1 Region segment information field
  18651. function readRegionSegmentInformation(data, start) {
  18652. return {
  18653. width: readUint32(data, start),
  18654. height: readUint32(data, start + 4),
  18655. x: readUint32(data, start + 8),
  18656. y: readUint32(data, start + 12),
  18657. combinationOperator: data[start + 16] & 7
  18658. };
  18659. }
  18660. var RegionSegmentInformationFieldLength = 17;
  18661. function processSegment(segment, visitor) {
  18662. var header = segment.header;
  18663. var data = segment.data, position = segment.start, end = segment.end;
  18664. var args, at, i, atLength;
  18665. switch (header.type) {
  18666. case 0: // SymbolDictionary
  18667. // 7.4.2 Symbol dictionary segment syntax
  18668. var dictionary = {};
  18669. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  18670. dictionary.huffman = !!(dictionaryFlags & 1);
  18671. dictionary.refinement = !!(dictionaryFlags & 2);
  18672. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  18673. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  18674. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  18675. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  18676. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  18677. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  18678. dictionary.template = (dictionaryFlags >> 10) & 3;
  18679. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  18680. position += 2;
  18681. if (!dictionary.huffman) {
  18682. atLength = dictionary.template === 0 ? 4 : 1;
  18683. at = [];
  18684. for (i = 0; i < atLength; i++) {
  18685. at.push({
  18686. x: readInt8(data, position),
  18687. y: readInt8(data, position + 1)
  18688. });
  18689. position += 2;
  18690. }
  18691. dictionary.at = at;
  18692. }
  18693. if (dictionary.refinement && !dictionary.refinementTemplate) {
  18694. at = [];
  18695. for (i = 0; i < 2; i++) {
  18696. at.push({
  18697. x: readInt8(data, position),
  18698. y: readInt8(data, position + 1)
  18699. });
  18700. position += 2;
  18701. }
  18702. dictionary.refinementAt = at;
  18703. }
  18704. dictionary.numberOfExportedSymbols = readUint32(data, position);
  18705. position += 4;
  18706. dictionary.numberOfNewSymbols = readUint32(data, position);
  18707. position += 4;
  18708. args = [dictionary, header.number, header.referredTo,
  18709. data, position, end];
  18710. break;
  18711. case 6: // ImmediateTextRegion
  18712. case 7: // ImmediateLosslessTextRegion
  18713. var textRegion = {};
  18714. textRegion.info = readRegionSegmentInformation(data, position);
  18715. position += RegionSegmentInformationFieldLength;
  18716. var textRegionSegmentFlags = readUint16(data, position);
  18717. position += 2;
  18718. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  18719. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  18720. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  18721. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  18722. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  18723. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  18724. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  18725. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  18726. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  18727. if (textRegion.huffman) {
  18728. var textRegionHuffmanFlags = readUint16(data, position);
  18729. position += 2;
  18730. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  18731. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  18732. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  18733. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  18734. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  18735. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  18736. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  18737. textRegion.huffmanRefinementSizeSelector =
  18738. !!(textRegionHuffmanFlags & 14);
  18739. }
  18740. if (textRegion.refinement && !textRegion.refinementTemplate) {
  18741. at = [];
  18742. for (i = 0; i < 2; i++) {
  18743. at.push({
  18744. x: readInt8(data, position),
  18745. y: readInt8(data, position + 1)
  18746. });
  18747. position += 2;
  18748. }
  18749. textRegion.refinementAt = at;
  18750. }
  18751. textRegion.numberOfSymbolInstances = readUint32(data, position);
  18752. position += 4;
  18753. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  18754. if (textRegion.huffman) {
  18755. error('JBIG2 error: huffman is not supported');
  18756. }
  18757. args = [textRegion, header.referredTo, data, position, end];
  18758. break;
  18759. case 38: // ImmediateGenericRegion
  18760. case 39: // ImmediateLosslessGenericRegion
  18761. var genericRegion = {};
  18762. genericRegion.info = readRegionSegmentInformation(data, position);
  18763. position += RegionSegmentInformationFieldLength;
  18764. var genericRegionSegmentFlags = data[position++];
  18765. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  18766. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  18767. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  18768. if (!genericRegion.mmr) {
  18769. atLength = genericRegion.template === 0 ? 4 : 1;
  18770. at = [];
  18771. for (i = 0; i < atLength; i++) {
  18772. at.push({
  18773. x: readInt8(data, position),
  18774. y: readInt8(data, position + 1)
  18775. });
  18776. position += 2;
  18777. }
  18778. genericRegion.at = at;
  18779. }
  18780. args = [genericRegion, data, position, end];
  18781. break;
  18782. case 48: // PageInformation
  18783. var pageInfo = {
  18784. width: readUint32(data, position),
  18785. height: readUint32(data, position + 4),
  18786. resolutionX: readUint32(data, position + 8),
  18787. resolutionY: readUint32(data, position + 12)
  18788. };
  18789. if (pageInfo.height === 0xFFFFFFFF) {
  18790. delete pageInfo.height;
  18791. }
  18792. var pageSegmentFlags = data[position + 16];
  18793. var pageStripingInformation = readUint16(data, position + 17);
  18794. pageInfo.lossless = !!(pageSegmentFlags & 1);
  18795. pageInfo.refinement = !!(pageSegmentFlags & 2);
  18796. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  18797. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  18798. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  18799. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  18800. args = [pageInfo];
  18801. break;
  18802. case 49: // EndOfPage
  18803. break;
  18804. case 50: // EndOfStripe
  18805. break;
  18806. case 51: // EndOfFile
  18807. break;
  18808. case 62: // 7.4.15 defines 2 extension types which
  18809. // are comments and can be ignored.
  18810. break;
  18811. default:
  18812. error('JBIG2 error: segment type ' + header.typeName + '(' +
  18813. header.type + ') is not implemented');
  18814. }
  18815. var callbackName = 'on' + header.typeName;
  18816. if (callbackName in visitor) {
  18817. visitor[callbackName].apply(visitor, args);
  18818. }
  18819. }
  18820. function processSegments(segments, visitor) {
  18821. for (var i = 0, ii = segments.length; i < ii; i++) {
  18822. processSegment(segments[i], visitor);
  18823. }
  18824. }
  18825. function parseJbig2(data, start, end) {
  18826. var position = start;
  18827. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  18828. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  18829. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  18830. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  18831. error('JBIG2 error: invalid header');
  18832. }
  18833. var header = {};
  18834. position += 8;
  18835. var flags = data[position++];
  18836. header.randomAccess = !(flags & 1);
  18837. if (!(flags & 2)) {
  18838. header.numberOfPages = readUint32(data, position);
  18839. position += 4;
  18840. }
  18841. var segments = readSegments(header, data, position, end);
  18842. error('Not implemented');
  18843. // processSegments(segments, new SimpleSegmentVisitor());
  18844. }
  18845. function parseJbig2Chunks(chunks) {
  18846. var visitor = new SimpleSegmentVisitor();
  18847. for (var i = 0, ii = chunks.length; i < ii; i++) {
  18848. var chunk = chunks[i];
  18849. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  18850. processSegments(segments, visitor);
  18851. }
  18852. return visitor.buffer;
  18853. }
  18854. function SimpleSegmentVisitor() {}
  18855. SimpleSegmentVisitor.prototype = {
  18856. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  18857. this.currentPageInfo = info;
  18858. var rowSize = (info.width + 7) >> 3;
  18859. var buffer = new Uint8Array(rowSize * info.height);
  18860. // The contents of ArrayBuffers are initialized to 0.
  18861. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  18862. if (info.defaultPixelValue) {
  18863. for (var i = 0, ii = buffer.length; i < ii; i++) {
  18864. buffer[i] = 0xFF;
  18865. }
  18866. }
  18867. this.buffer = buffer;
  18868. },
  18869. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  18870. var pageInfo = this.currentPageInfo;
  18871. var width = regionInfo.width, height = regionInfo.height;
  18872. var rowSize = (pageInfo.width + 7) >> 3;
  18873. var combinationOperator = pageInfo.combinationOperatorOverride ?
  18874. regionInfo.combinationOperator : pageInfo.combinationOperator;
  18875. var buffer = this.buffer;
  18876. var mask0 = 128 >> (regionInfo.x & 7);
  18877. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  18878. var i, j, mask, offset;
  18879. switch (combinationOperator) {
  18880. case 0: // OR
  18881. for (i = 0; i < height; i++) {
  18882. mask = mask0;
  18883. offset = offset0;
  18884. for (j = 0; j < width; j++) {
  18885. if (bitmap[i][j]) {
  18886. buffer[offset] |= mask;
  18887. }
  18888. mask >>= 1;
  18889. if (!mask) {
  18890. mask = 128;
  18891. offset++;
  18892. }
  18893. }
  18894. offset0 += rowSize;
  18895. }
  18896. break;
  18897. case 2: // XOR
  18898. for (i = 0; i < height; i++) {
  18899. mask = mask0;
  18900. offset = offset0;
  18901. for (j = 0; j < width; j++) {
  18902. if (bitmap[i][j]) {
  18903. buffer[offset] ^= mask;
  18904. }
  18905. mask >>= 1;
  18906. if (!mask) {
  18907. mask = 128;
  18908. offset++;
  18909. }
  18910. }
  18911. offset0 += rowSize;
  18912. }
  18913. break;
  18914. default:
  18915. error('JBIG2 error: operator ' + combinationOperator +
  18916. ' is not supported');
  18917. }
  18918. },
  18919. onImmediateGenericRegion:
  18920. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  18921. start, end) {
  18922. var regionInfo = region.info;
  18923. var decodingContext = new DecodingContext(data, start, end);
  18924. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  18925. region.template, region.prediction, null,
  18926. region.at, decodingContext);
  18927. this.drawBitmap(regionInfo, bitmap);
  18928. },
  18929. onImmediateLosslessGenericRegion:
  18930. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  18931. this.onImmediateGenericRegion.apply(this, arguments);
  18932. },
  18933. onSymbolDictionary:
  18934. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  18935. currentSegment,
  18936. referredSegments,
  18937. data, start, end) {
  18938. var huffmanTables;
  18939. if (dictionary.huffman) {
  18940. error('JBIG2 error: huffman is not supported');
  18941. }
  18942. // Combines exported symbols from all referred segments
  18943. var symbols = this.symbols;
  18944. if (!symbols) {
  18945. this.symbols = symbols = {};
  18946. }
  18947. var inputSymbols = [];
  18948. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  18949. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  18950. }
  18951. var decodingContext = new DecodingContext(data, start, end);
  18952. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  18953. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  18954. dictionary.numberOfExportedSymbols, huffmanTables,
  18955. dictionary.template, dictionary.at,
  18956. dictionary.refinementTemplate, dictionary.refinementAt,
  18957. decodingContext);
  18958. },
  18959. onImmediateTextRegion:
  18960. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  18961. referredSegments,
  18962. data, start, end) {
  18963. var regionInfo = region.info;
  18964. var huffmanTables;
  18965. // Combines exported symbols from all referred segments
  18966. var symbols = this.symbols;
  18967. var inputSymbols = [];
  18968. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  18969. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  18970. }
  18971. var symbolCodeLength = log2(inputSymbols.length);
  18972. var decodingContext = new DecodingContext(data, start, end);
  18973. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  18974. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  18975. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  18976. symbolCodeLength, region.transposed, region.dsOffset,
  18977. region.referenceCorner, region.combinationOperator, huffmanTables,
  18978. region.refinementTemplate, region.refinementAt, decodingContext);
  18979. this.drawBitmap(regionInfo, bitmap);
  18980. },
  18981. onImmediateLosslessTextRegion:
  18982. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  18983. this.onImmediateTextRegion.apply(this, arguments);
  18984. }
  18985. };
  18986. function Jbig2Image() {}
  18987. Jbig2Image.prototype = {
  18988. parseChunks: function Jbig2Image_parseChunks(chunks) {
  18989. return parseJbig2Chunks(chunks);
  18990. }
  18991. };
  18992. return Jbig2Image;
  18993. })();
  18994. exports.Jbig2Image = Jbig2Image;
  18995. }));
  18996. (function (root, factory) {
  18997. {
  18998. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  18999. root.pdfjsCoreArithmeticDecoder);
  19000. }
  19001. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  19002. var info = sharedUtil.info;
  19003. var log2 = sharedUtil.log2;
  19004. var readUint16 = sharedUtil.readUint16;
  19005. var readUint32 = sharedUtil.readUint32;
  19006. var warn = sharedUtil.warn;
  19007. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  19008. var JpxImage = (function JpxImageClosure() {
  19009. // Table E.1
  19010. var SubbandsGainLog2 = {
  19011. 'LL': 0,
  19012. 'LH': 1,
  19013. 'HL': 1,
  19014. 'HH': 2
  19015. };
  19016. function JpxImage() {
  19017. this.failOnCorruptedImage = false;
  19018. }
  19019. JpxImage.prototype = {
  19020. parse: function JpxImage_parse(data) {
  19021. var head = readUint16(data, 0);
  19022. // No box header, immediate start of codestream (SOC)
  19023. if (head === 0xFF4F) {
  19024. this.parseCodestream(data, 0, data.length);
  19025. return;
  19026. }
  19027. var position = 0, length = data.length;
  19028. while (position < length) {
  19029. var headerSize = 8;
  19030. var lbox = readUint32(data, position);
  19031. var tbox = readUint32(data, position + 4);
  19032. position += headerSize;
  19033. if (lbox === 1) {
  19034. // XLBox: read UInt64 according to spec.
  19035. // JavaScript's int precision of 53 bit should be sufficient here.
  19036. lbox = readUint32(data, position) * 4294967296 +
  19037. readUint32(data, position + 4);
  19038. position += 8;
  19039. headerSize += 8;
  19040. }
  19041. if (lbox === 0) {
  19042. lbox = length - position + headerSize;
  19043. }
  19044. if (lbox < headerSize) {
  19045. throw new Error('JPX Error: Invalid box field size');
  19046. }
  19047. var dataLength = lbox - headerSize;
  19048. var jumpDataLength = true;
  19049. switch (tbox) {
  19050. case 0x6A703268: // 'jp2h'
  19051. jumpDataLength = false; // parsing child boxes
  19052. break;
  19053. case 0x636F6C72: // 'colr'
  19054. // Colorspaces are not used, the CS from the PDF is used.
  19055. var method = data[position];
  19056. if (method === 1) {
  19057. // enumerated colorspace
  19058. var colorspace = readUint32(data, position + 3);
  19059. switch (colorspace) {
  19060. case 16: // this indicates a sRGB colorspace
  19061. case 17: // this indicates a grayscale colorspace
  19062. case 18: // this indicates a YUV colorspace
  19063. break;
  19064. default:
  19065. warn('Unknown colorspace ' + colorspace);
  19066. break;
  19067. }
  19068. } else if (method === 2) {
  19069. info('ICC profile not supported');
  19070. }
  19071. break;
  19072. case 0x6A703263: // 'jp2c'
  19073. this.parseCodestream(data, position, position + dataLength);
  19074. break;
  19075. case 0x6A502020: // 'jP\024\024'
  19076. if (0x0d0a870a !== readUint32(data, position)) {
  19077. warn('Invalid JP2 signature');
  19078. }
  19079. break;
  19080. // The following header types are valid but currently not used:
  19081. case 0x6A501A1A: // 'jP\032\032'
  19082. case 0x66747970: // 'ftyp'
  19083. case 0x72726571: // 'rreq'
  19084. case 0x72657320: // 'res '
  19085. case 0x69686472: // 'ihdr'
  19086. break;
  19087. default:
  19088. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  19089. (tbox >> 16) & 0xFF,
  19090. (tbox >> 8) & 0xFF,
  19091. tbox & 0xFF);
  19092. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  19093. break;
  19094. }
  19095. if (jumpDataLength) {
  19096. position += dataLength;
  19097. }
  19098. }
  19099. },
  19100. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  19101. var newByte = stream.getByte();
  19102. while (newByte >= 0) {
  19103. var oldByte = newByte;
  19104. newByte = stream.getByte();
  19105. var code = (oldByte << 8) | newByte;
  19106. // Image and tile size (SIZ)
  19107. if (code === 0xFF51) {
  19108. stream.skip(4);
  19109. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  19110. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  19111. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  19112. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  19113. stream.skip(16);
  19114. var Csiz = stream.getUint16(); // Byte 36
  19115. this.width = Xsiz - XOsiz;
  19116. this.height = Ysiz - YOsiz;
  19117. this.componentsCount = Csiz;
  19118. // Results are always returned as Uint8Arrays
  19119. this.bitsPerComponent = 8;
  19120. return;
  19121. }
  19122. }
  19123. throw new Error('JPX Error: No size marker found in JPX stream');
  19124. },
  19125. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  19126. var context = {};
  19127. try {
  19128. var doNotRecover = false;
  19129. var position = start;
  19130. while (position + 1 < end) {
  19131. var code = readUint16(data, position);
  19132. position += 2;
  19133. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  19134. switch (code) {
  19135. case 0xFF4F: // Start of codestream (SOC)
  19136. context.mainHeader = true;
  19137. break;
  19138. case 0xFFD9: // End of codestream (EOC)
  19139. break;
  19140. case 0xFF51: // Image and tile size (SIZ)
  19141. length = readUint16(data, position);
  19142. var siz = {};
  19143. siz.Xsiz = readUint32(data, position + 4);
  19144. siz.Ysiz = readUint32(data, position + 8);
  19145. siz.XOsiz = readUint32(data, position + 12);
  19146. siz.YOsiz = readUint32(data, position + 16);
  19147. siz.XTsiz = readUint32(data, position + 20);
  19148. siz.YTsiz = readUint32(data, position + 24);
  19149. siz.XTOsiz = readUint32(data, position + 28);
  19150. siz.YTOsiz = readUint32(data, position + 32);
  19151. var componentsCount = readUint16(data, position + 36);
  19152. siz.Csiz = componentsCount;
  19153. var components = [];
  19154. j = position + 38;
  19155. for (var i = 0; i < componentsCount; i++) {
  19156. var component = {
  19157. precision: (data[j] & 0x7F) + 1,
  19158. isSigned: !!(data[j] & 0x80),
  19159. XRsiz: data[j + 1],
  19160. YRsiz: data[j + 1]
  19161. };
  19162. calculateComponentDimensions(component, siz);
  19163. components.push(component);
  19164. }
  19165. context.SIZ = siz;
  19166. context.components = components;
  19167. calculateTileGrids(context, components);
  19168. context.QCC = [];
  19169. context.COC = [];
  19170. break;
  19171. case 0xFF5C: // Quantization default (QCD)
  19172. length = readUint16(data, position);
  19173. var qcd = {};
  19174. j = position + 2;
  19175. sqcd = data[j++];
  19176. switch (sqcd & 0x1F) {
  19177. case 0:
  19178. spqcdSize = 8;
  19179. scalarExpounded = true;
  19180. break;
  19181. case 1:
  19182. spqcdSize = 16;
  19183. scalarExpounded = false;
  19184. break;
  19185. case 2:
  19186. spqcdSize = 16;
  19187. scalarExpounded = true;
  19188. break;
  19189. default:
  19190. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  19191. }
  19192. qcd.noQuantization = (spqcdSize === 8);
  19193. qcd.scalarExpounded = scalarExpounded;
  19194. qcd.guardBits = sqcd >> 5;
  19195. spqcds = [];
  19196. while (j < length + position) {
  19197. var spqcd = {};
  19198. if (spqcdSize === 8) {
  19199. spqcd.epsilon = data[j++] >> 3;
  19200. spqcd.mu = 0;
  19201. } else {
  19202. spqcd.epsilon = data[j] >> 3;
  19203. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  19204. j += 2;
  19205. }
  19206. spqcds.push(spqcd);
  19207. }
  19208. qcd.SPqcds = spqcds;
  19209. if (context.mainHeader) {
  19210. context.QCD = qcd;
  19211. } else {
  19212. context.currentTile.QCD = qcd;
  19213. context.currentTile.QCC = [];
  19214. }
  19215. break;
  19216. case 0xFF5D: // Quantization component (QCC)
  19217. length = readUint16(data, position);
  19218. var qcc = {};
  19219. j = position + 2;
  19220. var cqcc;
  19221. if (context.SIZ.Csiz < 257) {
  19222. cqcc = data[j++];
  19223. } else {
  19224. cqcc = readUint16(data, j);
  19225. j += 2;
  19226. }
  19227. sqcd = data[j++];
  19228. switch (sqcd & 0x1F) {
  19229. case 0:
  19230. spqcdSize = 8;
  19231. scalarExpounded = true;
  19232. break;
  19233. case 1:
  19234. spqcdSize = 16;
  19235. scalarExpounded = false;
  19236. break;
  19237. case 2:
  19238. spqcdSize = 16;
  19239. scalarExpounded = true;
  19240. break;
  19241. default:
  19242. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  19243. }
  19244. qcc.noQuantization = (spqcdSize === 8);
  19245. qcc.scalarExpounded = scalarExpounded;
  19246. qcc.guardBits = sqcd >> 5;
  19247. spqcds = [];
  19248. while (j < (length + position)) {
  19249. spqcd = {};
  19250. if (spqcdSize === 8) {
  19251. spqcd.epsilon = data[j++] >> 3;
  19252. spqcd.mu = 0;
  19253. } else {
  19254. spqcd.epsilon = data[j] >> 3;
  19255. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  19256. j += 2;
  19257. }
  19258. spqcds.push(spqcd);
  19259. }
  19260. qcc.SPqcds = spqcds;
  19261. if (context.mainHeader) {
  19262. context.QCC[cqcc] = qcc;
  19263. } else {
  19264. context.currentTile.QCC[cqcc] = qcc;
  19265. }
  19266. break;
  19267. case 0xFF52: // Coding style default (COD)
  19268. length = readUint16(data, position);
  19269. var cod = {};
  19270. j = position + 2;
  19271. var scod = data[j++];
  19272. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  19273. cod.sopMarkerUsed = !!(scod & 2);
  19274. cod.ephMarkerUsed = !!(scod & 4);
  19275. cod.progressionOrder = data[j++];
  19276. cod.layersCount = readUint16(data, j);
  19277. j += 2;
  19278. cod.multipleComponentTransform = data[j++];
  19279. cod.decompositionLevelsCount = data[j++];
  19280. cod.xcb = (data[j++] & 0xF) + 2;
  19281. cod.ycb = (data[j++] & 0xF) + 2;
  19282. var blockStyle = data[j++];
  19283. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  19284. cod.resetContextProbabilities = !!(blockStyle & 2);
  19285. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  19286. cod.verticalyStripe = !!(blockStyle & 8);
  19287. cod.predictableTermination = !!(blockStyle & 16);
  19288. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  19289. cod.reversibleTransformation = data[j++];
  19290. if (cod.entropyCoderWithCustomPrecincts) {
  19291. var precinctsSizes = [];
  19292. while (j < length + position) {
  19293. var precinctsSize = data[j++];
  19294. precinctsSizes.push({
  19295. PPx: precinctsSize & 0xF,
  19296. PPy: precinctsSize >> 4
  19297. });
  19298. }
  19299. cod.precinctsSizes = precinctsSizes;
  19300. }
  19301. var unsupported = [];
  19302. if (cod.selectiveArithmeticCodingBypass) {
  19303. unsupported.push('selectiveArithmeticCodingBypass');
  19304. }
  19305. if (cod.resetContextProbabilities) {
  19306. unsupported.push('resetContextProbabilities');
  19307. }
  19308. if (cod.terminationOnEachCodingPass) {
  19309. unsupported.push('terminationOnEachCodingPass');
  19310. }
  19311. if (cod.verticalyStripe) {
  19312. unsupported.push('verticalyStripe');
  19313. }
  19314. if (cod.predictableTermination) {
  19315. unsupported.push('predictableTermination');
  19316. }
  19317. if (unsupported.length > 0) {
  19318. doNotRecover = true;
  19319. throw new Error('JPX Error: Unsupported COD options (' +
  19320. unsupported.join(', ') + ')');
  19321. }
  19322. if (context.mainHeader) {
  19323. context.COD = cod;
  19324. } else {
  19325. context.currentTile.COD = cod;
  19326. context.currentTile.COC = [];
  19327. }
  19328. break;
  19329. case 0xFF90: // Start of tile-part (SOT)
  19330. length = readUint16(data, position);
  19331. tile = {};
  19332. tile.index = readUint16(data, position + 2);
  19333. tile.length = readUint32(data, position + 4);
  19334. tile.dataEnd = tile.length + position - 2;
  19335. tile.partIndex = data[position + 8];
  19336. tile.partsCount = data[position + 9];
  19337. context.mainHeader = false;
  19338. if (tile.partIndex === 0) {
  19339. // reset component specific settings
  19340. tile.COD = context.COD;
  19341. tile.COC = context.COC.slice(0); // clone of the global COC
  19342. tile.QCD = context.QCD;
  19343. tile.QCC = context.QCC.slice(0); // clone of the global COC
  19344. }
  19345. context.currentTile = tile;
  19346. break;
  19347. case 0xFF93: // Start of data (SOD)
  19348. tile = context.currentTile;
  19349. if (tile.partIndex === 0) {
  19350. initializeTile(context, tile.index);
  19351. buildPackets(context);
  19352. }
  19353. // moving to the end of the data
  19354. length = tile.dataEnd - position;
  19355. parseTilePackets(context, data, position, length);
  19356. break;
  19357. case 0xFF55: // Tile-part lengths, main header (TLM)
  19358. case 0xFF57: // Packet length, main header (PLM)
  19359. case 0xFF58: // Packet length, tile-part header (PLT)
  19360. case 0xFF64: // Comment (COM)
  19361. length = readUint16(data, position);
  19362. // skipping content
  19363. break;
  19364. case 0xFF53: // Coding style component (COC)
  19365. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  19366. 'not implemented');
  19367. default:
  19368. throw new Error('JPX Error: Unknown codestream code: ' +
  19369. code.toString(16));
  19370. }
  19371. position += length;
  19372. }
  19373. } catch (e) {
  19374. if (doNotRecover || this.failOnCorruptedImage) {
  19375. throw e;
  19376. } else {
  19377. warn('Trying to recover from ' + e.message);
  19378. }
  19379. }
  19380. this.tiles = transformComponents(context);
  19381. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  19382. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  19383. this.componentsCount = context.SIZ.Csiz;
  19384. }
  19385. };
  19386. function calculateComponentDimensions(component, siz) {
  19387. // Section B.2 Component mapping
  19388. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  19389. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  19390. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  19391. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  19392. component.width = component.x1 - component.x0;
  19393. component.height = component.y1 - component.y0;
  19394. }
  19395. function calculateTileGrids(context, components) {
  19396. var siz = context.SIZ;
  19397. // Section B.3 Division into tile and tile-components
  19398. var tile, tiles = [];
  19399. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  19400. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  19401. for (var q = 0; q < numYtiles; q++) {
  19402. for (var p = 0; p < numXtiles; p++) {
  19403. tile = {};
  19404. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  19405. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  19406. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  19407. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  19408. tile.width = tile.tx1 - tile.tx0;
  19409. tile.height = tile.ty1 - tile.ty0;
  19410. tile.components = [];
  19411. tiles.push(tile);
  19412. }
  19413. }
  19414. context.tiles = tiles;
  19415. var componentsCount = siz.Csiz;
  19416. for (var i = 0, ii = componentsCount; i < ii; i++) {
  19417. var component = components[i];
  19418. for (var j = 0, jj = tiles.length; j < jj; j++) {
  19419. var tileComponent = {};
  19420. tile = tiles[j];
  19421. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  19422. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  19423. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  19424. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  19425. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  19426. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  19427. tile.components[i] = tileComponent;
  19428. }
  19429. }
  19430. }
  19431. function getBlocksDimensions(context, component, r) {
  19432. var codOrCoc = component.codingStyleParameters;
  19433. var result = {};
  19434. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  19435. result.PPx = 15;
  19436. result.PPy = 15;
  19437. } else {
  19438. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  19439. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  19440. }
  19441. // calculate codeblock size as described in section B.7
  19442. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  19443. Math.min(codOrCoc.xcb, result.PPx));
  19444. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  19445. Math.min(codOrCoc.ycb, result.PPy));
  19446. return result;
  19447. }
  19448. function buildPrecincts(context, resolution, dimensions) {
  19449. // Section B.6 Division resolution to precincts
  19450. var precinctWidth = 1 << dimensions.PPx;
  19451. var precinctHeight = 1 << dimensions.PPy;
  19452. // Jasper introduces codeblock groups for mapping each subband codeblocks
  19453. // to precincts. Precinct partition divides a resolution according to width
  19454. // and height parameters. The subband that belongs to the resolution level
  19455. // has a different size than the level, unless it is the zero resolution.
  19456. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  19457. // The precinct partitioning for a particular subband is derived from a
  19458. // partitioning of its parent LL band (i.e., the LL band at the next higher
  19459. // resolution level)... The LL band associated with each resolution level is
  19460. // divided into precincts... Each of the resulting precinct regions is then
  19461. // mapped into its child subbands (if any) at the next lower resolution
  19462. // level. This is accomplished by using the coordinate transformation
  19463. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  19464. // coordinates of a point in the LL band and child subband, respectively.
  19465. var isZeroRes = resolution.resLevel === 0;
  19466. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  19467. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  19468. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  19469. Math.ceil(resolution.trx1 / precinctWidth) -
  19470. Math.floor(resolution.trx0 / precinctWidth) : 0);
  19471. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  19472. Math.ceil(resolution.try1 / precinctHeight) -
  19473. Math.floor(resolution.try0 / precinctHeight) : 0);
  19474. var numprecincts = numprecinctswide * numprecinctshigh;
  19475. resolution.precinctParameters = {
  19476. precinctWidth: precinctWidth,
  19477. precinctHeight: precinctHeight,
  19478. numprecinctswide: numprecinctswide,
  19479. numprecinctshigh: numprecinctshigh,
  19480. numprecincts: numprecincts,
  19481. precinctWidthInSubband: precinctWidthInSubband,
  19482. precinctHeightInSubband: precinctHeightInSubband
  19483. };
  19484. }
  19485. function buildCodeblocks(context, subband, dimensions) {
  19486. // Section B.7 Division sub-band into code-blocks
  19487. var xcb_ = dimensions.xcb_;
  19488. var ycb_ = dimensions.ycb_;
  19489. var codeblockWidth = 1 << xcb_;
  19490. var codeblockHeight = 1 << ycb_;
  19491. var cbx0 = subband.tbx0 >> xcb_;
  19492. var cby0 = subband.tby0 >> ycb_;
  19493. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  19494. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  19495. var precinctParameters = subband.resolution.precinctParameters;
  19496. var codeblocks = [];
  19497. var precincts = [];
  19498. var i, j, codeblock, precinctNumber;
  19499. for (j = cby0; j < cby1; j++) {
  19500. for (i = cbx0; i < cbx1; i++) {
  19501. codeblock = {
  19502. cbx: i,
  19503. cby: j,
  19504. tbx0: codeblockWidth * i,
  19505. tby0: codeblockHeight * j,
  19506. tbx1: codeblockWidth * (i + 1),
  19507. tby1: codeblockHeight * (j + 1)
  19508. };
  19509. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  19510. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  19511. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  19512. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  19513. // Calculate precinct number for this codeblock, codeblock position
  19514. // should be relative to its subband, use actual dimension and position
  19515. // See comment about codeblock group width and height
  19516. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  19517. precinctParameters.precinctWidthInSubband);
  19518. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  19519. precinctParameters.precinctHeightInSubband);
  19520. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  19521. codeblock.precinctNumber = precinctNumber;
  19522. codeblock.subbandType = subband.type;
  19523. codeblock.Lblock = 3;
  19524. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  19525. codeblock.tby1_ <= codeblock.tby0_) {
  19526. continue;
  19527. }
  19528. codeblocks.push(codeblock);
  19529. // building precinct for the sub-band
  19530. var precinct = precincts[precinctNumber];
  19531. if (precinct !== undefined) {
  19532. if (i < precinct.cbxMin) {
  19533. precinct.cbxMin = i;
  19534. } else if (i > precinct.cbxMax) {
  19535. precinct.cbxMax = i;
  19536. }
  19537. if (j < precinct.cbyMin) {
  19538. precinct.cbxMin = j;
  19539. } else if (j > precinct.cbyMax) {
  19540. precinct.cbyMax = j;
  19541. }
  19542. } else {
  19543. precincts[precinctNumber] = precinct = {
  19544. cbxMin: i,
  19545. cbyMin: j,
  19546. cbxMax: i,
  19547. cbyMax: j
  19548. };
  19549. }
  19550. codeblock.precinct = precinct;
  19551. }
  19552. }
  19553. subband.codeblockParameters = {
  19554. codeblockWidth: xcb_,
  19555. codeblockHeight: ycb_,
  19556. numcodeblockwide: cbx1 - cbx0 + 1,
  19557. numcodeblockhigh: cby1 - cby0 + 1
  19558. };
  19559. subband.codeblocks = codeblocks;
  19560. subband.precincts = precincts;
  19561. }
  19562. function createPacket(resolution, precinctNumber, layerNumber) {
  19563. var precinctCodeblocks = [];
  19564. // Section B.10.8 Order of info in packet
  19565. var subbands = resolution.subbands;
  19566. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  19567. for (var i = 0, ii = subbands.length; i < ii; i++) {
  19568. var subband = subbands[i];
  19569. var codeblocks = subband.codeblocks;
  19570. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  19571. var codeblock = codeblocks[j];
  19572. if (codeblock.precinctNumber !== precinctNumber) {
  19573. continue;
  19574. }
  19575. precinctCodeblocks.push(codeblock);
  19576. }
  19577. }
  19578. return {
  19579. layerNumber: layerNumber,
  19580. codeblocks: precinctCodeblocks
  19581. };
  19582. }
  19583. function LayerResolutionComponentPositionIterator(context) {
  19584. var siz = context.SIZ;
  19585. var tileIndex = context.currentTile.index;
  19586. var tile = context.tiles[tileIndex];
  19587. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19588. var componentsCount = siz.Csiz;
  19589. var maxDecompositionLevelsCount = 0;
  19590. for (var q = 0; q < componentsCount; q++) {
  19591. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19592. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  19593. }
  19594. var l = 0, r = 0, i = 0, k = 0;
  19595. this.nextPacket = function JpxImage_nextPacket() {
  19596. // Section B.12.1.1 Layer-resolution-component-position
  19597. for (; l < layersCount; l++) {
  19598. for (; r <= maxDecompositionLevelsCount; r++) {
  19599. for (; i < componentsCount; i++) {
  19600. var component = tile.components[i];
  19601. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19602. continue;
  19603. }
  19604. var resolution = component.resolutions[r];
  19605. var numprecincts = resolution.precinctParameters.numprecincts;
  19606. for (; k < numprecincts;) {
  19607. var packet = createPacket(resolution, k, l);
  19608. k++;
  19609. return packet;
  19610. }
  19611. k = 0;
  19612. }
  19613. i = 0;
  19614. }
  19615. r = 0;
  19616. }
  19617. throw new Error('JPX Error: Out of packets');
  19618. };
  19619. }
  19620. function ResolutionLayerComponentPositionIterator(context) {
  19621. var siz = context.SIZ;
  19622. var tileIndex = context.currentTile.index;
  19623. var tile = context.tiles[tileIndex];
  19624. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19625. var componentsCount = siz.Csiz;
  19626. var maxDecompositionLevelsCount = 0;
  19627. for (var q = 0; q < componentsCount; q++) {
  19628. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19629. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  19630. }
  19631. var r = 0, l = 0, i = 0, k = 0;
  19632. this.nextPacket = function JpxImage_nextPacket() {
  19633. // Section B.12.1.2 Resolution-layer-component-position
  19634. for (; r <= maxDecompositionLevelsCount; r++) {
  19635. for (; l < layersCount; l++) {
  19636. for (; i < componentsCount; i++) {
  19637. var component = tile.components[i];
  19638. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19639. continue;
  19640. }
  19641. var resolution = component.resolutions[r];
  19642. var numprecincts = resolution.precinctParameters.numprecincts;
  19643. for (; k < numprecincts;) {
  19644. var packet = createPacket(resolution, k, l);
  19645. k++;
  19646. return packet;
  19647. }
  19648. k = 0;
  19649. }
  19650. i = 0;
  19651. }
  19652. l = 0;
  19653. }
  19654. throw new Error('JPX Error: Out of packets');
  19655. };
  19656. }
  19657. function ResolutionPositionComponentLayerIterator(context) {
  19658. var siz = context.SIZ;
  19659. var tileIndex = context.currentTile.index;
  19660. var tile = context.tiles[tileIndex];
  19661. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19662. var componentsCount = siz.Csiz;
  19663. var l, r, c, p;
  19664. var maxDecompositionLevelsCount = 0;
  19665. for (c = 0; c < componentsCount; c++) {
  19666. var component = tile.components[c];
  19667. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19668. component.codingStyleParameters.decompositionLevelsCount);
  19669. }
  19670. var maxNumPrecinctsInLevel = new Int32Array(
  19671. maxDecompositionLevelsCount + 1);
  19672. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  19673. var maxNumPrecincts = 0;
  19674. for (c = 0; c < componentsCount; ++c) {
  19675. var resolutions = tile.components[c].resolutions;
  19676. if (r < resolutions.length) {
  19677. maxNumPrecincts = Math.max(maxNumPrecincts,
  19678. resolutions[r].precinctParameters.numprecincts);
  19679. }
  19680. }
  19681. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  19682. }
  19683. l = 0;
  19684. r = 0;
  19685. c = 0;
  19686. p = 0;
  19687. this.nextPacket = function JpxImage_nextPacket() {
  19688. // Section B.12.1.3 Resolution-position-component-layer
  19689. for (; r <= maxDecompositionLevelsCount; r++) {
  19690. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  19691. for (; c < componentsCount; c++) {
  19692. var component = tile.components[c];
  19693. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19694. continue;
  19695. }
  19696. var resolution = component.resolutions[r];
  19697. var numprecincts = resolution.precinctParameters.numprecincts;
  19698. if (p >= numprecincts) {
  19699. continue;
  19700. }
  19701. for (; l < layersCount;) {
  19702. var packet = createPacket(resolution, p, l);
  19703. l++;
  19704. return packet;
  19705. }
  19706. l = 0;
  19707. }
  19708. c = 0;
  19709. }
  19710. p = 0;
  19711. }
  19712. throw new Error('JPX Error: Out of packets');
  19713. };
  19714. }
  19715. function PositionComponentResolutionLayerIterator(context) {
  19716. var siz = context.SIZ;
  19717. var tileIndex = context.currentTile.index;
  19718. var tile = context.tiles[tileIndex];
  19719. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19720. var componentsCount = siz.Csiz;
  19721. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  19722. var precinctsIterationSizes = precinctsSizes;
  19723. var l = 0, r = 0, c = 0, px = 0, py = 0;
  19724. this.nextPacket = function JpxImage_nextPacket() {
  19725. // Section B.12.1.4 Position-component-resolution-layer
  19726. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  19727. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  19728. for (; c < componentsCount; c++) {
  19729. var component = tile.components[c];
  19730. var decompositionLevelsCount =
  19731. component.codingStyleParameters.decompositionLevelsCount;
  19732. for (; r <= decompositionLevelsCount; r++) {
  19733. var resolution = component.resolutions[r];
  19734. var sizeInImageScale =
  19735. precinctsSizes.components[c].resolutions[r];
  19736. var k = getPrecinctIndexIfExist(
  19737. px,
  19738. py,
  19739. sizeInImageScale,
  19740. precinctsIterationSizes,
  19741. resolution);
  19742. if (k === null) {
  19743. continue;
  19744. }
  19745. for (; l < layersCount;) {
  19746. var packet = createPacket(resolution, k, l);
  19747. l++;
  19748. return packet;
  19749. }
  19750. l = 0;
  19751. }
  19752. r = 0;
  19753. }
  19754. c = 0;
  19755. }
  19756. px = 0;
  19757. }
  19758. throw new Error('JPX Error: Out of packets');
  19759. };
  19760. }
  19761. function ComponentPositionResolutionLayerIterator(context) {
  19762. var siz = context.SIZ;
  19763. var tileIndex = context.currentTile.index;
  19764. var tile = context.tiles[tileIndex];
  19765. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19766. var componentsCount = siz.Csiz;
  19767. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  19768. var l = 0, r = 0, c = 0, px = 0, py = 0;
  19769. this.nextPacket = function JpxImage_nextPacket() {
  19770. // Section B.12.1.5 Component-position-resolution-layer
  19771. for (; c < componentsCount; ++c) {
  19772. var component = tile.components[c];
  19773. var precinctsIterationSizes = precinctsSizes.components[c];
  19774. var decompositionLevelsCount =
  19775. component.codingStyleParameters.decompositionLevelsCount;
  19776. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  19777. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  19778. for (; r <= decompositionLevelsCount; r++) {
  19779. var resolution = component.resolutions[r];
  19780. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  19781. var k = getPrecinctIndexIfExist(
  19782. px,
  19783. py,
  19784. sizeInImageScale,
  19785. precinctsIterationSizes,
  19786. resolution);
  19787. if (k === null) {
  19788. continue;
  19789. }
  19790. for (; l < layersCount;) {
  19791. var packet = createPacket(resolution, k, l);
  19792. l++;
  19793. return packet;
  19794. }
  19795. l = 0;
  19796. }
  19797. r = 0;
  19798. }
  19799. px = 0;
  19800. }
  19801. py = 0;
  19802. }
  19803. throw new Error('JPX Error: Out of packets');
  19804. };
  19805. }
  19806. function getPrecinctIndexIfExist(
  19807. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  19808. var posX = pxIndex * precinctIterationSizes.minWidth;
  19809. var posY = pyIndex * precinctIterationSizes.minHeight;
  19810. if (posX % sizeInImageScale.width !== 0 ||
  19811. posY % sizeInImageScale.height !== 0) {
  19812. return null;
  19813. }
  19814. var startPrecinctRowIndex =
  19815. (posY / sizeInImageScale.width) *
  19816. resolution.precinctParameters.numprecinctswide;
  19817. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  19818. }
  19819. function getPrecinctSizesInImageScale(tile) {
  19820. var componentsCount = tile.components.length;
  19821. var minWidth = Number.MAX_VALUE;
  19822. var minHeight = Number.MAX_VALUE;
  19823. var maxNumWide = 0;
  19824. var maxNumHigh = 0;
  19825. var sizePerComponent = new Array(componentsCount);
  19826. for (var c = 0; c < componentsCount; c++) {
  19827. var component = tile.components[c];
  19828. var decompositionLevelsCount =
  19829. component.codingStyleParameters.decompositionLevelsCount;
  19830. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  19831. var minWidthCurrentComponent = Number.MAX_VALUE;
  19832. var minHeightCurrentComponent = Number.MAX_VALUE;
  19833. var maxNumWideCurrentComponent = 0;
  19834. var maxNumHighCurrentComponent = 0;
  19835. var scale = 1;
  19836. for (var r = decompositionLevelsCount; r >= 0; --r) {
  19837. var resolution = component.resolutions[r];
  19838. var widthCurrentResolution =
  19839. scale * resolution.precinctParameters.precinctWidth;
  19840. var heightCurrentResolution =
  19841. scale * resolution.precinctParameters.precinctHeight;
  19842. minWidthCurrentComponent = Math.min(
  19843. minWidthCurrentComponent,
  19844. widthCurrentResolution);
  19845. minHeightCurrentComponent = Math.min(
  19846. minHeightCurrentComponent,
  19847. heightCurrentResolution);
  19848. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  19849. resolution.precinctParameters.numprecinctswide);
  19850. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  19851. resolution.precinctParameters.numprecinctshigh);
  19852. sizePerResolution[r] = {
  19853. width: widthCurrentResolution,
  19854. height: heightCurrentResolution
  19855. };
  19856. scale <<= 1;
  19857. }
  19858. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  19859. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  19860. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  19861. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  19862. sizePerComponent[c] = {
  19863. resolutions: sizePerResolution,
  19864. minWidth: minWidthCurrentComponent,
  19865. minHeight: minHeightCurrentComponent,
  19866. maxNumWide: maxNumWideCurrentComponent,
  19867. maxNumHigh: maxNumHighCurrentComponent
  19868. };
  19869. }
  19870. return {
  19871. components: sizePerComponent,
  19872. minWidth: minWidth,
  19873. minHeight: minHeight,
  19874. maxNumWide: maxNumWide,
  19875. maxNumHigh: maxNumHigh
  19876. };
  19877. }
  19878. function buildPackets(context) {
  19879. var siz = context.SIZ;
  19880. var tileIndex = context.currentTile.index;
  19881. var tile = context.tiles[tileIndex];
  19882. var componentsCount = siz.Csiz;
  19883. // Creating resolutions and sub-bands for each component
  19884. for (var c = 0; c < componentsCount; c++) {
  19885. var component = tile.components[c];
  19886. var decompositionLevelsCount =
  19887. component.codingStyleParameters.decompositionLevelsCount;
  19888. // Section B.5 Resolution levels and sub-bands
  19889. var resolutions = [];
  19890. var subbands = [];
  19891. for (var r = 0; r <= decompositionLevelsCount; r++) {
  19892. var blocksDimensions = getBlocksDimensions(context, component, r);
  19893. var resolution = {};
  19894. var scale = 1 << (decompositionLevelsCount - r);
  19895. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  19896. resolution.try0 = Math.ceil(component.tcy0 / scale);
  19897. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  19898. resolution.try1 = Math.ceil(component.tcy1 / scale);
  19899. resolution.resLevel = r;
  19900. buildPrecincts(context, resolution, blocksDimensions);
  19901. resolutions.push(resolution);
  19902. var subband;
  19903. if (r === 0) {
  19904. // one sub-band (LL) with last decomposition
  19905. subband = {};
  19906. subband.type = 'LL';
  19907. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  19908. subband.tby0 = Math.ceil(component.tcy0 / scale);
  19909. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  19910. subband.tby1 = Math.ceil(component.tcy1 / scale);
  19911. subband.resolution = resolution;
  19912. buildCodeblocks(context, subband, blocksDimensions);
  19913. subbands.push(subband);
  19914. resolution.subbands = [subband];
  19915. } else {
  19916. var bscale = 1 << (decompositionLevelsCount - r + 1);
  19917. var resolutionSubbands = [];
  19918. // three sub-bands (HL, LH and HH) with rest of decompositions
  19919. subband = {};
  19920. subband.type = 'HL';
  19921. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  19922. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  19923. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  19924. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  19925. subband.resolution = resolution;
  19926. buildCodeblocks(context, subband, blocksDimensions);
  19927. subbands.push(subband);
  19928. resolutionSubbands.push(subband);
  19929. subband = {};
  19930. subband.type = 'LH';
  19931. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  19932. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  19933. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  19934. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  19935. subband.resolution = resolution;
  19936. buildCodeblocks(context, subband, blocksDimensions);
  19937. subbands.push(subband);
  19938. resolutionSubbands.push(subband);
  19939. subband = {};
  19940. subband.type = 'HH';
  19941. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  19942. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  19943. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  19944. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  19945. subband.resolution = resolution;
  19946. buildCodeblocks(context, subband, blocksDimensions);
  19947. subbands.push(subband);
  19948. resolutionSubbands.push(subband);
  19949. resolution.subbands = resolutionSubbands;
  19950. }
  19951. }
  19952. component.resolutions = resolutions;
  19953. component.subbands = subbands;
  19954. }
  19955. // Generate the packets sequence
  19956. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  19957. switch (progressionOrder) {
  19958. case 0:
  19959. tile.packetsIterator =
  19960. new LayerResolutionComponentPositionIterator(context);
  19961. break;
  19962. case 1:
  19963. tile.packetsIterator =
  19964. new ResolutionLayerComponentPositionIterator(context);
  19965. break;
  19966. case 2:
  19967. tile.packetsIterator =
  19968. new ResolutionPositionComponentLayerIterator(context);
  19969. break;
  19970. case 3:
  19971. tile.packetsIterator =
  19972. new PositionComponentResolutionLayerIterator(context);
  19973. break;
  19974. case 4:
  19975. tile.packetsIterator =
  19976. new ComponentPositionResolutionLayerIterator(context);
  19977. break;
  19978. default:
  19979. throw new Error('JPX Error: Unsupported progression order ' +
  19980. progressionOrder);
  19981. }
  19982. }
  19983. function parseTilePackets(context, data, offset, dataLength) {
  19984. var position = 0;
  19985. var buffer, bufferSize = 0, skipNextBit = false;
  19986. function readBits(count) {
  19987. while (bufferSize < count) {
  19988. var b = data[offset + position];
  19989. position++;
  19990. if (skipNextBit) {
  19991. buffer = (buffer << 7) | b;
  19992. bufferSize += 7;
  19993. skipNextBit = false;
  19994. } else {
  19995. buffer = (buffer << 8) | b;
  19996. bufferSize += 8;
  19997. }
  19998. if (b === 0xFF) {
  19999. skipNextBit = true;
  20000. }
  20001. }
  20002. bufferSize -= count;
  20003. return (buffer >>> bufferSize) & ((1 << count) - 1);
  20004. }
  20005. function skipMarkerIfEqual(value) {
  20006. if (data[offset + position - 1] === 0xFF &&
  20007. data[offset + position] === value) {
  20008. skipBytes(1);
  20009. return true;
  20010. } else if (data[offset + position] === 0xFF &&
  20011. data[offset + position + 1] === value) {
  20012. skipBytes(2);
  20013. return true;
  20014. }
  20015. return false;
  20016. }
  20017. function skipBytes(count) {
  20018. position += count;
  20019. }
  20020. function alignToByte() {
  20021. bufferSize = 0;
  20022. if (skipNextBit) {
  20023. position++;
  20024. skipNextBit = false;
  20025. }
  20026. }
  20027. function readCodingpasses() {
  20028. if (readBits(1) === 0) {
  20029. return 1;
  20030. }
  20031. if (readBits(1) === 0) {
  20032. return 2;
  20033. }
  20034. var value = readBits(2);
  20035. if (value < 3) {
  20036. return value + 3;
  20037. }
  20038. value = readBits(5);
  20039. if (value < 31) {
  20040. return value + 6;
  20041. }
  20042. value = readBits(7);
  20043. return value + 37;
  20044. }
  20045. var tileIndex = context.currentTile.index;
  20046. var tile = context.tiles[tileIndex];
  20047. var sopMarkerUsed = context.COD.sopMarkerUsed;
  20048. var ephMarkerUsed = context.COD.ephMarkerUsed;
  20049. var packetsIterator = tile.packetsIterator;
  20050. while (position < dataLength) {
  20051. alignToByte();
  20052. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  20053. // Skip also marker segment length and packet sequence ID
  20054. skipBytes(4);
  20055. }
  20056. var packet = packetsIterator.nextPacket();
  20057. if (!readBits(1)) {
  20058. continue;
  20059. }
  20060. var layerNumber = packet.layerNumber;
  20061. var queue = [], codeblock;
  20062. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  20063. codeblock = packet.codeblocks[i];
  20064. var precinct = codeblock.precinct;
  20065. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  20066. var codeblockRow = codeblock.cby - precinct.cbyMin;
  20067. var codeblockIncluded = false;
  20068. var firstTimeInclusion = false;
  20069. var valueReady;
  20070. if (codeblock['included'] !== undefined) {
  20071. codeblockIncluded = !!readBits(1);
  20072. } else {
  20073. // reading inclusion tree
  20074. precinct = codeblock.precinct;
  20075. var inclusionTree, zeroBitPlanesTree;
  20076. if (precinct['inclusionTree'] !== undefined) {
  20077. inclusionTree = precinct.inclusionTree;
  20078. } else {
  20079. // building inclusion and zero bit-planes trees
  20080. var width = precinct.cbxMax - precinct.cbxMin + 1;
  20081. var height = precinct.cbyMax - precinct.cbyMin + 1;
  20082. inclusionTree = new InclusionTree(width, height, layerNumber);
  20083. zeroBitPlanesTree = new TagTree(width, height);
  20084. precinct.inclusionTree = inclusionTree;
  20085. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  20086. }
  20087. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  20088. while (true) {
  20089. if (readBits(1)) {
  20090. valueReady = !inclusionTree.nextLevel();
  20091. if (valueReady) {
  20092. codeblock.included = true;
  20093. codeblockIncluded = firstTimeInclusion = true;
  20094. break;
  20095. }
  20096. } else {
  20097. inclusionTree.incrementValue(layerNumber);
  20098. break;
  20099. }
  20100. }
  20101. }
  20102. }
  20103. if (!codeblockIncluded) {
  20104. continue;
  20105. }
  20106. if (firstTimeInclusion) {
  20107. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  20108. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  20109. while (true) {
  20110. if (readBits(1)) {
  20111. valueReady = !zeroBitPlanesTree.nextLevel();
  20112. if (valueReady) {
  20113. break;
  20114. }
  20115. } else {
  20116. zeroBitPlanesTree.incrementValue();
  20117. }
  20118. }
  20119. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  20120. }
  20121. var codingpasses = readCodingpasses();
  20122. while (readBits(1)) {
  20123. codeblock.Lblock++;
  20124. }
  20125. var codingpassesLog2 = log2(codingpasses);
  20126. // rounding down log2
  20127. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  20128. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  20129. var codedDataLength = readBits(bits);
  20130. queue.push({
  20131. codeblock: codeblock,
  20132. codingpasses: codingpasses,
  20133. dataLength: codedDataLength
  20134. });
  20135. }
  20136. alignToByte();
  20137. if (ephMarkerUsed) {
  20138. skipMarkerIfEqual(0x92);
  20139. }
  20140. while (queue.length > 0) {
  20141. var packetItem = queue.shift();
  20142. codeblock = packetItem.codeblock;
  20143. if (codeblock['data'] === undefined) {
  20144. codeblock.data = [];
  20145. }
  20146. codeblock.data.push({
  20147. data: data,
  20148. start: offset + position,
  20149. end: offset + position + packetItem.dataLength,
  20150. codingpasses: packetItem.codingpasses
  20151. });
  20152. position += packetItem.dataLength;
  20153. }
  20154. }
  20155. return position;
  20156. }
  20157. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  20158. delta, mb, reversible, segmentationSymbolUsed) {
  20159. var x0 = subband.tbx0;
  20160. var y0 = subband.tby0;
  20161. var width = subband.tbx1 - subband.tbx0;
  20162. var codeblocks = subband.codeblocks;
  20163. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  20164. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  20165. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  20166. var codeblock = codeblocks[i];
  20167. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  20168. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  20169. if (blockWidth === 0 || blockHeight === 0) {
  20170. continue;
  20171. }
  20172. if (codeblock['data'] === undefined) {
  20173. continue;
  20174. }
  20175. var bitModel, currentCodingpassType;
  20176. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  20177. codeblock.zeroBitPlanes, mb);
  20178. currentCodingpassType = 2; // first bit plane starts from cleanup
  20179. // collect data
  20180. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  20181. var j, jj, dataItem;
  20182. for (j = 0, jj = data.length; j < jj; j++) {
  20183. dataItem = data[j];
  20184. totalLength += dataItem.end - dataItem.start;
  20185. codingpasses += dataItem.codingpasses;
  20186. }
  20187. var encodedData = new Uint8Array(totalLength);
  20188. var position = 0;
  20189. for (j = 0, jj = data.length; j < jj; j++) {
  20190. dataItem = data[j];
  20191. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  20192. encodedData.set(chunk, position);
  20193. position += chunk.length;
  20194. }
  20195. // decoding the item
  20196. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  20197. bitModel.setDecoder(decoder);
  20198. for (j = 0; j < codingpasses; j++) {
  20199. switch (currentCodingpassType) {
  20200. case 0:
  20201. bitModel.runSignificancePropogationPass();
  20202. break;
  20203. case 1:
  20204. bitModel.runMagnitudeRefinementPass();
  20205. break;
  20206. case 2:
  20207. bitModel.runCleanupPass();
  20208. if (segmentationSymbolUsed) {
  20209. bitModel.checkSegmentationSymbol();
  20210. }
  20211. break;
  20212. }
  20213. currentCodingpassType = (currentCodingpassType + 1) % 3;
  20214. }
  20215. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  20216. var sign = bitModel.coefficentsSign;
  20217. var magnitude = bitModel.coefficentsMagnitude;
  20218. var bitsDecoded = bitModel.bitsDecoded;
  20219. var magnitudeCorrection = reversible ? 0 : 0.5;
  20220. var k, n, nb;
  20221. position = 0;
  20222. // Do the interleaving of Section F.3.3 here, so we do not need
  20223. // to copy later. LL level is not interleaved, just copied.
  20224. var interleave = (subband.type !== 'LL');
  20225. for (j = 0; j < blockHeight; j++) {
  20226. var row = (offset / width) | 0; // row in the non-interleaved subband
  20227. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  20228. for (k = 0; k < blockWidth; k++) {
  20229. n = magnitude[position];
  20230. if (n !== 0) {
  20231. n = (n + magnitudeCorrection) * delta;
  20232. if (sign[position] !== 0) {
  20233. n = -n;
  20234. }
  20235. nb = bitsDecoded[position];
  20236. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  20237. if (reversible && (nb >= mb)) {
  20238. coefficients[pos] = n;
  20239. } else {
  20240. coefficients[pos] = n * (1 << (mb - nb));
  20241. }
  20242. }
  20243. offset++;
  20244. position++;
  20245. }
  20246. offset += width - blockWidth;
  20247. }
  20248. }
  20249. }
  20250. function transformTile(context, tile, c) {
  20251. var component = tile.components[c];
  20252. var codingStyleParameters = component.codingStyleParameters;
  20253. var quantizationParameters = component.quantizationParameters;
  20254. var decompositionLevelsCount =
  20255. codingStyleParameters.decompositionLevelsCount;
  20256. var spqcds = quantizationParameters.SPqcds;
  20257. var scalarExpounded = quantizationParameters.scalarExpounded;
  20258. var guardBits = quantizationParameters.guardBits;
  20259. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  20260. var precision = context.components[c].precision;
  20261. var reversible = codingStyleParameters.reversibleTransformation;
  20262. var transform = (reversible ? new ReversibleTransform() :
  20263. new IrreversibleTransform());
  20264. var subbandCoefficients = [];
  20265. var b = 0;
  20266. for (var i = 0; i <= decompositionLevelsCount; i++) {
  20267. var resolution = component.resolutions[i];
  20268. var width = resolution.trx1 - resolution.trx0;
  20269. var height = resolution.try1 - resolution.try0;
  20270. // Allocate space for the whole sublevel.
  20271. var coefficients = new Float32Array(width * height);
  20272. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  20273. var mu, epsilon;
  20274. if (!scalarExpounded) {
  20275. // formula E-5
  20276. mu = spqcds[0].mu;
  20277. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  20278. } else {
  20279. mu = spqcds[b].mu;
  20280. epsilon = spqcds[b].epsilon;
  20281. b++;
  20282. }
  20283. var subband = resolution.subbands[j];
  20284. var gainLog2 = SubbandsGainLog2[subband.type];
  20285. // calulate quantization coefficient (Section E.1.1.1)
  20286. var delta = (reversible ? 1 :
  20287. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  20288. var mb = (guardBits + epsilon - 1);
  20289. // In the first resolution level, copyCoefficients will fill the
  20290. // whole array with coefficients. In the succeding passes,
  20291. // copyCoefficients will consecutively fill in the values that belong
  20292. // to the interleaved positions of the HL, LH, and HH coefficients.
  20293. // The LL coefficients will then be interleaved in Transform.iterate().
  20294. copyCoefficients(coefficients, width, height, subband, delta, mb,
  20295. reversible, segmentationSymbolUsed);
  20296. }
  20297. subbandCoefficients.push({
  20298. width: width,
  20299. height: height,
  20300. items: coefficients
  20301. });
  20302. }
  20303. var result = transform.calculate(subbandCoefficients,
  20304. component.tcx0, component.tcy0);
  20305. return {
  20306. left: component.tcx0,
  20307. top: component.tcy0,
  20308. width: result.width,
  20309. height: result.height,
  20310. items: result.items
  20311. };
  20312. }
  20313. function transformComponents(context) {
  20314. var siz = context.SIZ;
  20315. var components = context.components;
  20316. var componentsCount = siz.Csiz;
  20317. var resultImages = [];
  20318. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  20319. var tile = context.tiles[i];
  20320. var transformedTiles = [];
  20321. var c;
  20322. for (c = 0; c < componentsCount; c++) {
  20323. transformedTiles[c] = transformTile(context, tile, c);
  20324. }
  20325. var tile0 = transformedTiles[0];
  20326. var out = new Uint8Array(tile0.items.length * componentsCount);
  20327. var result = {
  20328. left: tile0.left,
  20329. top: tile0.top,
  20330. width: tile0.width,
  20331. height: tile0.height,
  20332. items: out
  20333. };
  20334. // Section G.2.2 Inverse multi component transform
  20335. var shift, offset, max, min, maxK;
  20336. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  20337. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  20338. var fourComponents = componentsCount === 4;
  20339. var y0items = transformedTiles[0].items;
  20340. var y1items = transformedTiles[1].items;
  20341. var y2items = transformedTiles[2].items;
  20342. var y3items = fourComponents ? transformedTiles[3].items : null;
  20343. // HACK: The multiple component transform formulas below assume that
  20344. // all components have the same precision. With this in mind, we
  20345. // compute shift and offset only once.
  20346. shift = components[0].precision - 8;
  20347. offset = (128 << shift) + 0.5;
  20348. max = 255 * (1 << shift);
  20349. maxK = max * 0.5;
  20350. min = -maxK;
  20351. var component0 = tile.components[0];
  20352. var alpha01 = componentsCount - 3;
  20353. jj = y0items.length;
  20354. if (!component0.codingStyleParameters.reversibleTransformation) {
  20355. // inverse irreversible multiple component transform
  20356. for (j = 0; j < jj; j++, pos += alpha01) {
  20357. y0 = y0items[j] + offset;
  20358. y1 = y1items[j];
  20359. y2 = y2items[j];
  20360. r = y0 + 1.402 * y2;
  20361. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  20362. b = y0 + 1.772 * y1;
  20363. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  20364. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  20365. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  20366. }
  20367. } else {
  20368. // inverse reversible multiple component transform
  20369. for (j = 0; j < jj; j++, pos += alpha01) {
  20370. y0 = y0items[j] + offset;
  20371. y1 = y1items[j];
  20372. y2 = y2items[j];
  20373. g = y0 - ((y2 + y1) >> 2);
  20374. r = g + y2;
  20375. b = g + y1;
  20376. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  20377. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  20378. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  20379. }
  20380. }
  20381. if (fourComponents) {
  20382. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  20383. k = y3items[j];
  20384. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  20385. }
  20386. }
  20387. } else { // no multi-component transform
  20388. for (c = 0; c < componentsCount; c++) {
  20389. var items = transformedTiles[c].items;
  20390. shift = components[c].precision - 8;
  20391. offset = (128 << shift) + 0.5;
  20392. max = (127.5 * (1 << shift));
  20393. min = -max;
  20394. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  20395. val = items[j];
  20396. out[pos] = val <= min ? 0 :
  20397. val >= max ? 255 : (val + offset) >> shift;
  20398. pos += componentsCount;
  20399. }
  20400. }
  20401. }
  20402. resultImages.push(result);
  20403. }
  20404. return resultImages;
  20405. }
  20406. function initializeTile(context, tileIndex) {
  20407. var siz = context.SIZ;
  20408. var componentsCount = siz.Csiz;
  20409. var tile = context.tiles[tileIndex];
  20410. for (var c = 0; c < componentsCount; c++) {
  20411. var component = tile.components[c];
  20412. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  20413. context.currentTile.QCC[c] : context.currentTile.QCD);
  20414. component.quantizationParameters = qcdOrQcc;
  20415. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  20416. context.currentTile.COC[c] : context.currentTile.COD);
  20417. component.codingStyleParameters = codOrCoc;
  20418. }
  20419. tile.codingStyleDefaultParameters = context.currentTile.COD;
  20420. }
  20421. // Section B.10.2 Tag trees
  20422. var TagTree = (function TagTreeClosure() {
  20423. function TagTree(width, height) {
  20424. var levelsLength = log2(Math.max(width, height)) + 1;
  20425. this.levels = [];
  20426. for (var i = 0; i < levelsLength; i++) {
  20427. var level = {
  20428. width: width,
  20429. height: height,
  20430. items: []
  20431. };
  20432. this.levels.push(level);
  20433. width = Math.ceil(width / 2);
  20434. height = Math.ceil(height / 2);
  20435. }
  20436. }
  20437. TagTree.prototype = {
  20438. reset: function TagTree_reset(i, j) {
  20439. var currentLevel = 0, value = 0, level;
  20440. while (currentLevel < this.levels.length) {
  20441. level = this.levels[currentLevel];
  20442. var index = i + j * level.width;
  20443. if (level.items[index] !== undefined) {
  20444. value = level.items[index];
  20445. break;
  20446. }
  20447. level.index = index;
  20448. i >>= 1;
  20449. j >>= 1;
  20450. currentLevel++;
  20451. }
  20452. currentLevel--;
  20453. level = this.levels[currentLevel];
  20454. level.items[level.index] = value;
  20455. this.currentLevel = currentLevel;
  20456. delete this.value;
  20457. },
  20458. incrementValue: function TagTree_incrementValue() {
  20459. var level = this.levels[this.currentLevel];
  20460. level.items[level.index]++;
  20461. },
  20462. nextLevel: function TagTree_nextLevel() {
  20463. var currentLevel = this.currentLevel;
  20464. var level = this.levels[currentLevel];
  20465. var value = level.items[level.index];
  20466. currentLevel--;
  20467. if (currentLevel < 0) {
  20468. this.value = value;
  20469. return false;
  20470. }
  20471. this.currentLevel = currentLevel;
  20472. level = this.levels[currentLevel];
  20473. level.items[level.index] = value;
  20474. return true;
  20475. }
  20476. };
  20477. return TagTree;
  20478. })();
  20479. var InclusionTree = (function InclusionTreeClosure() {
  20480. function InclusionTree(width, height, defaultValue) {
  20481. var levelsLength = log2(Math.max(width, height)) + 1;
  20482. this.levels = [];
  20483. for (var i = 0; i < levelsLength; i++) {
  20484. var items = new Uint8Array(width * height);
  20485. for (var j = 0, jj = items.length; j < jj; j++) {
  20486. items[j] = defaultValue;
  20487. }
  20488. var level = {
  20489. width: width,
  20490. height: height,
  20491. items: items
  20492. };
  20493. this.levels.push(level);
  20494. width = Math.ceil(width / 2);
  20495. height = Math.ceil(height / 2);
  20496. }
  20497. }
  20498. InclusionTree.prototype = {
  20499. reset: function InclusionTree_reset(i, j, stopValue) {
  20500. var currentLevel = 0;
  20501. while (currentLevel < this.levels.length) {
  20502. var level = this.levels[currentLevel];
  20503. var index = i + j * level.width;
  20504. level.index = index;
  20505. var value = level.items[index];
  20506. if (value === 0xFF) {
  20507. break;
  20508. }
  20509. if (value > stopValue) {
  20510. this.currentLevel = currentLevel;
  20511. // already know about this one, propagating the value to top levels
  20512. this.propagateValues();
  20513. return false;
  20514. }
  20515. i >>= 1;
  20516. j >>= 1;
  20517. currentLevel++;
  20518. }
  20519. this.currentLevel = currentLevel - 1;
  20520. return true;
  20521. },
  20522. incrementValue: function InclusionTree_incrementValue(stopValue) {
  20523. var level = this.levels[this.currentLevel];
  20524. level.items[level.index] = stopValue + 1;
  20525. this.propagateValues();
  20526. },
  20527. propagateValues: function InclusionTree_propagateValues() {
  20528. var levelIndex = this.currentLevel;
  20529. var level = this.levels[levelIndex];
  20530. var currentValue = level.items[level.index];
  20531. while (--levelIndex >= 0) {
  20532. level = this.levels[levelIndex];
  20533. level.items[level.index] = currentValue;
  20534. }
  20535. },
  20536. nextLevel: function InclusionTree_nextLevel() {
  20537. var currentLevel = this.currentLevel;
  20538. var level = this.levels[currentLevel];
  20539. var value = level.items[level.index];
  20540. level.items[level.index] = 0xFF;
  20541. currentLevel--;
  20542. if (currentLevel < 0) {
  20543. return false;
  20544. }
  20545. this.currentLevel = currentLevel;
  20546. level = this.levels[currentLevel];
  20547. level.items[level.index] = value;
  20548. return true;
  20549. }
  20550. };
  20551. return InclusionTree;
  20552. })();
  20553. // Section D. Coefficient bit modeling
  20554. var BitModel = (function BitModelClosure() {
  20555. var UNIFORM_CONTEXT = 17;
  20556. var RUNLENGTH_CONTEXT = 18;
  20557. // Table D-1
  20558. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  20559. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  20560. var LLAndLHContextsLabel = new Uint8Array([
  20561. 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,
  20562. 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,
  20563. 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
  20564. ]);
  20565. var HLContextLabel = new Uint8Array([
  20566. 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,
  20567. 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,
  20568. 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
  20569. ]);
  20570. var HHContextLabel = new Uint8Array([
  20571. 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,
  20572. 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,
  20573. 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
  20574. ]);
  20575. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  20576. this.width = width;
  20577. this.height = height;
  20578. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  20579. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  20580. var coefficientCount = width * height;
  20581. // coefficients outside the encoding region treated as insignificant
  20582. // add border state cells for significanceState
  20583. this.neighborsSignificance = new Uint8Array(coefficientCount);
  20584. this.coefficentsSign = new Uint8Array(coefficientCount);
  20585. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  20586. mb > 6 ? new Uint16Array(coefficientCount) :
  20587. new Uint8Array(coefficientCount);
  20588. this.processingFlags = new Uint8Array(coefficientCount);
  20589. var bitsDecoded = new Uint8Array(coefficientCount);
  20590. if (zeroBitPlanes !== 0) {
  20591. for (var i = 0; i < coefficientCount; i++) {
  20592. bitsDecoded[i] = zeroBitPlanes;
  20593. }
  20594. }
  20595. this.bitsDecoded = bitsDecoded;
  20596. this.reset();
  20597. }
  20598. BitModel.prototype = {
  20599. setDecoder: function BitModel_setDecoder(decoder) {
  20600. this.decoder = decoder;
  20601. },
  20602. reset: function BitModel_reset() {
  20603. // We have 17 contexts that are accessed via context labels,
  20604. // plus the uniform and runlength context.
  20605. this.contexts = new Int8Array(19);
  20606. // Contexts are packed into 1 byte:
  20607. // highest 7 bits carry the index, lowest bit carries mps
  20608. this.contexts[0] = (4 << 1) | 0;
  20609. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  20610. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  20611. },
  20612. setNeighborsSignificance:
  20613. function BitModel_setNeighborsSignificance(row, column, index) {
  20614. var neighborsSignificance = this.neighborsSignificance;
  20615. var width = this.width, height = this.height;
  20616. var left = (column > 0);
  20617. var right = (column + 1 < width);
  20618. var i;
  20619. if (row > 0) {
  20620. i = index - width;
  20621. if (left) {
  20622. neighborsSignificance[i - 1] += 0x10;
  20623. }
  20624. if (right) {
  20625. neighborsSignificance[i + 1] += 0x10;
  20626. }
  20627. neighborsSignificance[i] += 0x04;
  20628. }
  20629. if (row + 1 < height) {
  20630. i = index + width;
  20631. if (left) {
  20632. neighborsSignificance[i - 1] += 0x10;
  20633. }
  20634. if (right) {
  20635. neighborsSignificance[i + 1] += 0x10;
  20636. }
  20637. neighborsSignificance[i] += 0x04;
  20638. }
  20639. if (left) {
  20640. neighborsSignificance[index - 1] += 0x01;
  20641. }
  20642. if (right) {
  20643. neighborsSignificance[index + 1] += 0x01;
  20644. }
  20645. neighborsSignificance[index] |= 0x80;
  20646. },
  20647. runSignificancePropogationPass:
  20648. function BitModel_runSignificancePropogationPass() {
  20649. var decoder = this.decoder;
  20650. var width = this.width, height = this.height;
  20651. var coefficentsMagnitude = this.coefficentsMagnitude;
  20652. var coefficentsSign = this.coefficentsSign;
  20653. var neighborsSignificance = this.neighborsSignificance;
  20654. var processingFlags = this.processingFlags;
  20655. var contexts = this.contexts;
  20656. var labels = this.contextLabelTable;
  20657. var bitsDecoded = this.bitsDecoded;
  20658. var processedInverseMask = ~1;
  20659. var processedMask = 1;
  20660. var firstMagnitudeBitMask = 2;
  20661. for (var i0 = 0; i0 < height; i0 += 4) {
  20662. for (var j = 0; j < width; j++) {
  20663. var index = i0 * width + j;
  20664. for (var i1 = 0; i1 < 4; i1++, index += width) {
  20665. var i = i0 + i1;
  20666. if (i >= height) {
  20667. break;
  20668. }
  20669. // clear processed flag first
  20670. processingFlags[index] &= processedInverseMask;
  20671. if (coefficentsMagnitude[index] ||
  20672. !neighborsSignificance[index]) {
  20673. continue;
  20674. }
  20675. var contextLabel = labels[neighborsSignificance[index]];
  20676. var decision = decoder.readBit(contexts, contextLabel);
  20677. if (decision) {
  20678. var sign = this.decodeSignBit(i, j, index);
  20679. coefficentsSign[index] = sign;
  20680. coefficentsMagnitude[index] = 1;
  20681. this.setNeighborsSignificance(i, j, index);
  20682. processingFlags[index] |= firstMagnitudeBitMask;
  20683. }
  20684. bitsDecoded[index]++;
  20685. processingFlags[index] |= processedMask;
  20686. }
  20687. }
  20688. }
  20689. },
  20690. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  20691. var width = this.width, height = this.height;
  20692. var coefficentsMagnitude = this.coefficentsMagnitude;
  20693. var coefficentsSign = this.coefficentsSign;
  20694. var contribution, sign0, sign1, significance1;
  20695. var contextLabel, decoded;
  20696. // calculate horizontal contribution
  20697. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  20698. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  20699. sign1 = coefficentsSign[index + 1];
  20700. if (significance1) {
  20701. sign0 = coefficentsSign[index - 1];
  20702. contribution = 1 - sign1 - sign0;
  20703. } else {
  20704. contribution = 1 - sign1 - sign1;
  20705. }
  20706. } else if (significance1) {
  20707. sign0 = coefficentsSign[index - 1];
  20708. contribution = 1 - sign0 - sign0;
  20709. } else {
  20710. contribution = 0;
  20711. }
  20712. var horizontalContribution = 3 * contribution;
  20713. // calculate vertical contribution and combine with the horizontal
  20714. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  20715. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  20716. sign1 = coefficentsSign[index + width];
  20717. if (significance1) {
  20718. sign0 = coefficentsSign[index - width];
  20719. contribution = 1 - sign1 - sign0 + horizontalContribution;
  20720. } else {
  20721. contribution = 1 - sign1 - sign1 + horizontalContribution;
  20722. }
  20723. } else if (significance1) {
  20724. sign0 = coefficentsSign[index - width];
  20725. contribution = 1 - sign0 - sign0 + horizontalContribution;
  20726. } else {
  20727. contribution = horizontalContribution;
  20728. }
  20729. if (contribution >= 0) {
  20730. contextLabel = 9 + contribution;
  20731. decoded = this.decoder.readBit(this.contexts, contextLabel);
  20732. } else {
  20733. contextLabel = 9 - contribution;
  20734. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  20735. }
  20736. return decoded;
  20737. },
  20738. runMagnitudeRefinementPass:
  20739. function BitModel_runMagnitudeRefinementPass() {
  20740. var decoder = this.decoder;
  20741. var width = this.width, height = this.height;
  20742. var coefficentsMagnitude = this.coefficentsMagnitude;
  20743. var neighborsSignificance = this.neighborsSignificance;
  20744. var contexts = this.contexts;
  20745. var bitsDecoded = this.bitsDecoded;
  20746. var processingFlags = this.processingFlags;
  20747. var processedMask = 1;
  20748. var firstMagnitudeBitMask = 2;
  20749. var length = width * height;
  20750. var width4 = width * 4;
  20751. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  20752. indexNext = Math.min(length, index0 + width4);
  20753. for (var j = 0; j < width; j++) {
  20754. for (var index = index0 + j; index < indexNext; index += width) {
  20755. // significant but not those that have just become
  20756. if (!coefficentsMagnitude[index] ||
  20757. (processingFlags[index] & processedMask) !== 0) {
  20758. continue;
  20759. }
  20760. var contextLabel = 16;
  20761. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  20762. processingFlags[index] ^= firstMagnitudeBitMask;
  20763. // first refinement
  20764. var significance = neighborsSignificance[index] & 127;
  20765. contextLabel = significance === 0 ? 15 : 14;
  20766. }
  20767. var bit = decoder.readBit(contexts, contextLabel);
  20768. coefficentsMagnitude[index] =
  20769. (coefficentsMagnitude[index] << 1) | bit;
  20770. bitsDecoded[index]++;
  20771. processingFlags[index] |= processedMask;
  20772. }
  20773. }
  20774. }
  20775. },
  20776. runCleanupPass: function BitModel_runCleanupPass() {
  20777. var decoder = this.decoder;
  20778. var width = this.width, height = this.height;
  20779. var neighborsSignificance = this.neighborsSignificance;
  20780. var coefficentsMagnitude = this.coefficentsMagnitude;
  20781. var coefficentsSign = this.coefficentsSign;
  20782. var contexts = this.contexts;
  20783. var labels = this.contextLabelTable;
  20784. var bitsDecoded = this.bitsDecoded;
  20785. var processingFlags = this.processingFlags;
  20786. var processedMask = 1;
  20787. var firstMagnitudeBitMask = 2;
  20788. var oneRowDown = width;
  20789. var twoRowsDown = width * 2;
  20790. var threeRowsDown = width * 3;
  20791. var iNext;
  20792. for (var i0 = 0; i0 < height; i0 = iNext) {
  20793. iNext = Math.min(i0 + 4, height);
  20794. var indexBase = i0 * width;
  20795. var checkAllEmpty = i0 + 3 < height;
  20796. for (var j = 0; j < width; j++) {
  20797. var index0 = indexBase + j;
  20798. // using the property: labels[neighborsSignificance[index]] === 0
  20799. // when neighborsSignificance[index] === 0
  20800. var allEmpty = (checkAllEmpty &&
  20801. processingFlags[index0] === 0 &&
  20802. processingFlags[index0 + oneRowDown] === 0 &&
  20803. processingFlags[index0 + twoRowsDown] === 0 &&
  20804. processingFlags[index0 + threeRowsDown] === 0 &&
  20805. neighborsSignificance[index0] === 0 &&
  20806. neighborsSignificance[index0 + oneRowDown] === 0 &&
  20807. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  20808. neighborsSignificance[index0 + threeRowsDown] === 0);
  20809. var i1 = 0, index = index0;
  20810. var i = i0, sign;
  20811. if (allEmpty) {
  20812. var hasSignificantCoefficent =
  20813. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  20814. if (!hasSignificantCoefficent) {
  20815. bitsDecoded[index0]++;
  20816. bitsDecoded[index0 + oneRowDown]++;
  20817. bitsDecoded[index0 + twoRowsDown]++;
  20818. bitsDecoded[index0 + threeRowsDown]++;
  20819. continue; // next column
  20820. }
  20821. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  20822. decoder.readBit(contexts, UNIFORM_CONTEXT);
  20823. if (i1 !== 0) {
  20824. i = i0 + i1;
  20825. index += i1 * width;
  20826. }
  20827. sign = this.decodeSignBit(i, j, index);
  20828. coefficentsSign[index] = sign;
  20829. coefficentsMagnitude[index] = 1;
  20830. this.setNeighborsSignificance(i, j, index);
  20831. processingFlags[index] |= firstMagnitudeBitMask;
  20832. index = index0;
  20833. for (var i2 = i0; i2 <= i; i2++, index += width) {
  20834. bitsDecoded[index]++;
  20835. }
  20836. i1++;
  20837. }
  20838. for (i = i0 + i1; i < iNext; i++, index += width) {
  20839. if (coefficentsMagnitude[index] ||
  20840. (processingFlags[index] & processedMask) !== 0) {
  20841. continue;
  20842. }
  20843. var contextLabel = labels[neighborsSignificance[index]];
  20844. var decision = decoder.readBit(contexts, contextLabel);
  20845. if (decision === 1) {
  20846. sign = this.decodeSignBit(i, j, index);
  20847. coefficentsSign[index] = sign;
  20848. coefficentsMagnitude[index] = 1;
  20849. this.setNeighborsSignificance(i, j, index);
  20850. processingFlags[index] |= firstMagnitudeBitMask;
  20851. }
  20852. bitsDecoded[index]++;
  20853. }
  20854. }
  20855. }
  20856. },
  20857. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  20858. var decoder = this.decoder;
  20859. var contexts = this.contexts;
  20860. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  20861. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  20862. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  20863. decoder.readBit(contexts, UNIFORM_CONTEXT);
  20864. if (symbol !== 0xA) {
  20865. throw new Error('JPX Error: Invalid segmentation symbol');
  20866. }
  20867. }
  20868. };
  20869. return BitModel;
  20870. })();
  20871. // Section F, Discrete wavelet transformation
  20872. var Transform = (function TransformClosure() {
  20873. function Transform() {}
  20874. Transform.prototype.calculate =
  20875. function transformCalculate(subbands, u0, v0) {
  20876. var ll = subbands[0];
  20877. for (var i = 1, ii = subbands.length; i < ii; i++) {
  20878. ll = this.iterate(ll, subbands[i], u0, v0);
  20879. }
  20880. return ll;
  20881. };
  20882. Transform.prototype.extend = function extend(buffer, offset, size) {
  20883. // Section F.3.7 extending... using max extension of 4
  20884. var i1 = offset - 1, j1 = offset + 1;
  20885. var i2 = offset + size - 2, j2 = offset + size;
  20886. buffer[i1--] = buffer[j1++];
  20887. buffer[j2++] = buffer[i2--];
  20888. buffer[i1--] = buffer[j1++];
  20889. buffer[j2++] = buffer[i2--];
  20890. buffer[i1--] = buffer[j1++];
  20891. buffer[j2++] = buffer[i2--];
  20892. buffer[i1] = buffer[j1];
  20893. buffer[j2] = buffer[i2];
  20894. };
  20895. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  20896. u0, v0) {
  20897. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  20898. var width = hl_lh_hh.width;
  20899. var height = hl_lh_hh.height;
  20900. var items = hl_lh_hh.items;
  20901. var i, j, k, l, u, v;
  20902. // Interleave LL according to Section F.3.3
  20903. for (k = 0, i = 0; i < llHeight; i++) {
  20904. l = i * 2 * width;
  20905. for (j = 0; j < llWidth; j++, k++, l += 2) {
  20906. items[l] = llItems[k];
  20907. }
  20908. }
  20909. // The LL band is not needed anymore.
  20910. llItems = ll.items = null;
  20911. var bufferPadding = 4;
  20912. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  20913. // Section F.3.4 HOR_SR
  20914. if (width === 1) {
  20915. // if width = 1, when u0 even keep items as is, when odd divide by 2
  20916. if ((u0 & 1) !== 0) {
  20917. for (v = 0, k = 0; v < height; v++, k += width) {
  20918. items[k] *= 0.5;
  20919. }
  20920. }
  20921. } else {
  20922. for (v = 0, k = 0; v < height; v++, k += width) {
  20923. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  20924. this.extend(rowBuffer, bufferPadding, width);
  20925. this.filter(rowBuffer, bufferPadding, width);
  20926. items.set(
  20927. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  20928. k);
  20929. }
  20930. }
  20931. // Accesses to the items array can take long, because it may not fit into
  20932. // CPU cache and has to be fetched from main memory. Since subsequent
  20933. // accesses to the items array are not local when reading columns, we
  20934. // have a cache miss every time. To reduce cache misses, get up to
  20935. // 'numBuffers' items at a time and store them into the individual
  20936. // buffers. The colBuffers should be small enough to fit into CPU cache.
  20937. var numBuffers = 16;
  20938. var colBuffers = [];
  20939. for (i = 0; i < numBuffers; i++) {
  20940. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  20941. }
  20942. var b, currentBuffer = 0;
  20943. ll = bufferPadding + height;
  20944. // Section F.3.5 VER_SR
  20945. if (height === 1) {
  20946. // if height = 1, when v0 even keep items as is, when odd divide by 2
  20947. if ((v0 & 1) !== 0) {
  20948. for (u = 0; u < width; u++) {
  20949. items[u] *= 0.5;
  20950. }
  20951. }
  20952. } else {
  20953. for (u = 0; u < width; u++) {
  20954. // if we ran out of buffers, copy several image columns at once
  20955. if (currentBuffer === 0) {
  20956. numBuffers = Math.min(width - u, numBuffers);
  20957. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  20958. for (b = 0; b < numBuffers; b++) {
  20959. colBuffers[b][l] = items[k + b];
  20960. }
  20961. }
  20962. currentBuffer = numBuffers;
  20963. }
  20964. currentBuffer--;
  20965. var buffer = colBuffers[currentBuffer];
  20966. this.extend(buffer, bufferPadding, height);
  20967. this.filter(buffer, bufferPadding, height);
  20968. // If this is last buffer in this group of buffers, flush all buffers.
  20969. if (currentBuffer === 0) {
  20970. k = u - numBuffers + 1;
  20971. for (l = bufferPadding; l < ll; k += width, l++) {
  20972. for (b = 0; b < numBuffers; b++) {
  20973. items[k + b] = colBuffers[b][l];
  20974. }
  20975. }
  20976. }
  20977. }
  20978. }
  20979. return {
  20980. width: width,
  20981. height: height,
  20982. items: items
  20983. };
  20984. };
  20985. return Transform;
  20986. })();
  20987. // Section 3.8.2 Irreversible 9-7 filter
  20988. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  20989. function IrreversibleTransform() {
  20990. Transform.call(this);
  20991. }
  20992. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  20993. IrreversibleTransform.prototype.filter =
  20994. function irreversibleTransformFilter(x, offset, length) {
  20995. var len = length >> 1;
  20996. offset = offset | 0;
  20997. var j, n, current, next;
  20998. var alpha = -1.586134342059924;
  20999. var beta = -0.052980118572961;
  21000. var gamma = 0.882911075530934;
  21001. var delta = 0.443506852043971;
  21002. var K = 1.230174104914001;
  21003. var K_ = 1 / K;
  21004. // step 1 is combined with step 3
  21005. // step 2
  21006. j = offset - 3;
  21007. for (n = len + 4; n--; j += 2) {
  21008. x[j] *= K_;
  21009. }
  21010. // step 1 & 3
  21011. j = offset - 2;
  21012. current = delta * x[j -1];
  21013. for (n = len + 3; n--; j += 2) {
  21014. next = delta * x[j + 1];
  21015. x[j] = K * x[j] - current - next;
  21016. if (n--) {
  21017. j += 2;
  21018. current = delta * x[j + 1];
  21019. x[j] = K * x[j] - current - next;
  21020. } else {
  21021. break;
  21022. }
  21023. }
  21024. // step 4
  21025. j = offset - 1;
  21026. current = gamma * x[j - 1];
  21027. for (n = len + 2; n--; j += 2) {
  21028. next = gamma * x[j + 1];
  21029. x[j] -= current + next;
  21030. if (n--) {
  21031. j += 2;
  21032. current = gamma * x[j + 1];
  21033. x[j] -= current + next;
  21034. } else {
  21035. break;
  21036. }
  21037. }
  21038. // step 5
  21039. j = offset;
  21040. current = beta * x[j - 1];
  21041. for (n = len + 1; n--; j += 2) {
  21042. next = beta * x[j + 1];
  21043. x[j] -= current + next;
  21044. if (n--) {
  21045. j += 2;
  21046. current = beta * x[j + 1];
  21047. x[j] -= current + next;
  21048. } else {
  21049. break;
  21050. }
  21051. }
  21052. // step 6
  21053. if (len !== 0) {
  21054. j = offset + 1;
  21055. current = alpha * x[j - 1];
  21056. for (n = len; n--; j += 2) {
  21057. next = alpha * x[j + 1];
  21058. x[j] -= current + next;
  21059. if (n--) {
  21060. j += 2;
  21061. current = alpha * x[j + 1];
  21062. x[j] -= current + next;
  21063. } else {
  21064. break;
  21065. }
  21066. }
  21067. }
  21068. };
  21069. return IrreversibleTransform;
  21070. })();
  21071. // Section 3.8.1 Reversible 5-3 filter
  21072. var ReversibleTransform = (function ReversibleTransformClosure() {
  21073. function ReversibleTransform() {
  21074. Transform.call(this);
  21075. }
  21076. ReversibleTransform.prototype = Object.create(Transform.prototype);
  21077. ReversibleTransform.prototype.filter =
  21078. function reversibleTransformFilter(x, offset, length) {
  21079. var len = length >> 1;
  21080. offset = offset | 0;
  21081. var j, n;
  21082. for (j = offset, n = len + 1; n--; j += 2) {
  21083. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  21084. }
  21085. for (j = offset + 1, n = len; n--; j += 2) {
  21086. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  21087. }
  21088. };
  21089. return ReversibleTransform;
  21090. })();
  21091. return JpxImage;
  21092. })();
  21093. exports.JpxImage = JpxImage;
  21094. }));
  21095. (function (root, factory) {
  21096. {
  21097. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  21098. }
  21099. }(this, function (exports, sharedUtil) {
  21100. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  21101. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  21102. // Workaround for missing math precison in JS.
  21103. var MASK_HIGH = 0xffff0000;
  21104. var MASK_LOW = 0xffff;
  21105. function MurmurHash3_64 (seed) {
  21106. var SEED = 0xc3d2e1f0;
  21107. this.h1 = seed ? seed & 0xffffffff : SEED;
  21108. this.h2 = seed ? seed & 0xffffffff : SEED;
  21109. }
  21110. var alwaysUseUint32ArrayView = false;
  21111. // old webkits have issues with non-aligned arrays
  21112. try {
  21113. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  21114. } catch (e) {
  21115. alwaysUseUint32ArrayView = true;
  21116. }
  21117. MurmurHash3_64.prototype = {
  21118. update: function MurmurHash3_64_update(input) {
  21119. var useUint32ArrayView = alwaysUseUint32ArrayView;
  21120. var i;
  21121. if (typeof input === 'string') {
  21122. var data = new Uint8Array(input.length * 2);
  21123. var length = 0;
  21124. for (i = 0; i < input.length; i++) {
  21125. var code = input.charCodeAt(i);
  21126. if (code <= 0xff) {
  21127. data[length++] = code;
  21128. }
  21129. else {
  21130. data[length++] = code >>> 8;
  21131. data[length++] = code & 0xff;
  21132. }
  21133. }
  21134. } else if (input instanceof Uint8Array) {
  21135. data = input;
  21136. length = data.length;
  21137. } else if (typeof input === 'object' && ('length' in input)) {
  21138. // processing regular arrays as well, e.g. for IE9
  21139. data = input;
  21140. length = data.length;
  21141. useUint32ArrayView = true;
  21142. } else {
  21143. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  21144. 'Input must be a string or array.');
  21145. }
  21146. var blockCounts = length >> 2;
  21147. var tailLength = length - blockCounts * 4;
  21148. // we don't care about endianness here
  21149. var dataUint32 = useUint32ArrayView ?
  21150. new Uint32ArrayView(data, blockCounts) :
  21151. new Uint32Array(data.buffer, 0, blockCounts);
  21152. var k1 = 0;
  21153. var k2 = 0;
  21154. var h1 = this.h1;
  21155. var h2 = this.h2;
  21156. var C1 = 0xcc9e2d51;
  21157. var C2 = 0x1b873593;
  21158. var C1_LOW = C1 & MASK_LOW;
  21159. var C2_LOW = C2 & MASK_LOW;
  21160. for (i = 0; i < blockCounts; i++) {
  21161. if (i & 1) {
  21162. k1 = dataUint32[i];
  21163. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  21164. k1 = k1 << 15 | k1 >>> 17;
  21165. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  21166. h1 ^= k1;
  21167. h1 = h1 << 13 | h1 >>> 19;
  21168. h1 = h1 * 5 + 0xe6546b64;
  21169. } else {
  21170. k2 = dataUint32[i];
  21171. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  21172. k2 = k2 << 15 | k2 >>> 17;
  21173. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  21174. h2 ^= k2;
  21175. h2 = h2 << 13 | h2 >>> 19;
  21176. h2 = h2 * 5 + 0xe6546b64;
  21177. }
  21178. }
  21179. k1 = 0;
  21180. switch (tailLength) {
  21181. case 3:
  21182. k1 ^= data[blockCounts * 4 + 2] << 16;
  21183. /* falls through */
  21184. case 2:
  21185. k1 ^= data[blockCounts * 4 + 1] << 8;
  21186. /* falls through */
  21187. case 1:
  21188. k1 ^= data[blockCounts * 4];
  21189. /* falls through */
  21190. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  21191. k1 = k1 << 15 | k1 >>> 17;
  21192. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  21193. if (blockCounts & 1) {
  21194. h1 ^= k1;
  21195. } else {
  21196. h2 ^= k1;
  21197. }
  21198. }
  21199. this.h1 = h1;
  21200. this.h2 = h2;
  21201. return this;
  21202. },
  21203. hexdigest: function MurmurHash3_64_hexdigest () {
  21204. var h1 = this.h1;
  21205. var h2 = this.h2;
  21206. h1 ^= h2 >>> 1;
  21207. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  21208. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  21209. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  21210. h1 ^= h2 >>> 1;
  21211. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  21212. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  21213. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  21214. h1 ^= h2 >>> 1;
  21215. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  21216. var hex = (arr[i] >>> 0).toString(16);
  21217. while (hex.length < 8) {
  21218. hex = '0' + hex;
  21219. }
  21220. str += hex;
  21221. }
  21222. return str;
  21223. }
  21224. };
  21225. return MurmurHash3_64;
  21226. })();
  21227. exports.MurmurHash3_64 = MurmurHash3_64;
  21228. }));
  21229. (function (root, factory) {
  21230. {
  21231. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  21232. }
  21233. }(this, function (exports, sharedUtil) {
  21234. var isArray = sharedUtil.isArray;
  21235. var Name = (function NameClosure() {
  21236. function Name(name) {
  21237. this.name = name;
  21238. }
  21239. Name.prototype = {};
  21240. var nameCache = {};
  21241. Name.get = function Name_get(name) {
  21242. var nameValue = nameCache[name];
  21243. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  21244. };
  21245. return Name;
  21246. })();
  21247. var Cmd = (function CmdClosure() {
  21248. function Cmd(cmd) {
  21249. this.cmd = cmd;
  21250. }
  21251. Cmd.prototype = {};
  21252. var cmdCache = {};
  21253. Cmd.get = function Cmd_get(cmd) {
  21254. var cmdValue = cmdCache[cmd];
  21255. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  21256. };
  21257. return Cmd;
  21258. })();
  21259. var Dict = (function DictClosure() {
  21260. var nonSerializable = function nonSerializableClosure() {
  21261. return nonSerializable; // creating closure on some variable
  21262. };
  21263. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  21264. 'Background': true,
  21265. 'ExtGState': true,
  21266. 'Halftone': true,
  21267. 'Layout': true,
  21268. 'Mask': true,
  21269. 'Pagination': true,
  21270. 'Printing': true
  21271. };
  21272. function isRecursionAllowedFor(dict) {
  21273. if (!isName(dict.Type)) {
  21274. return true;
  21275. }
  21276. var dictType = dict.Type.name;
  21277. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  21278. }
  21279. // xref is optional
  21280. function Dict(xref) {
  21281. // Map should only be used internally, use functions below to access.
  21282. this.map = Object.create(null);
  21283. this.xref = xref;
  21284. this.objId = null;
  21285. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  21286. }
  21287. Dict.prototype = {
  21288. assignXref: function Dict_assignXref(newXref) {
  21289. this.xref = newXref;
  21290. },
  21291. // automatically dereferences Ref objects
  21292. get: function Dict_get(key1, key2, key3) {
  21293. var value;
  21294. var xref = this.xref;
  21295. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  21296. typeof key2 === 'undefined') {
  21297. return xref ? xref.fetchIfRef(value) : value;
  21298. }
  21299. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  21300. typeof key3 === 'undefined') {
  21301. return xref ? xref.fetchIfRef(value) : value;
  21302. }
  21303. value = this.map[key3] || null;
  21304. return xref ? xref.fetchIfRef(value) : value;
  21305. },
  21306. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21307. getAsync: function Dict_getAsync(key1, key2, key3) {
  21308. var value;
  21309. var xref = this.xref;
  21310. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  21311. typeof key2 === 'undefined') {
  21312. if (xref) {
  21313. return xref.fetchIfRefAsync(value);
  21314. }
  21315. return Promise.resolve(value);
  21316. }
  21317. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  21318. typeof key3 === 'undefined') {
  21319. if (xref) {
  21320. return xref.fetchIfRefAsync(value);
  21321. }
  21322. return Promise.resolve(value);
  21323. }
  21324. value = this.map[key3] || null;
  21325. if (xref) {
  21326. return xref.fetchIfRefAsync(value);
  21327. }
  21328. return Promise.resolve(value);
  21329. },
  21330. // Same as get(), but dereferences all elements if the result is an Array.
  21331. getArray: function Dict_getArray(key1, key2, key3) {
  21332. var value = this.get(key1, key2, key3);
  21333. var xref = this.xref;
  21334. if (!isArray(value) || !xref) {
  21335. return value;
  21336. }
  21337. value = value.slice(); // Ensure that we don't modify the Dict data.
  21338. for (var i = 0, ii = value.length; i < ii; i++) {
  21339. if (!isRef(value[i])) {
  21340. continue;
  21341. }
  21342. value[i] = xref.fetch(value[i]);
  21343. }
  21344. return value;
  21345. },
  21346. // no dereferencing
  21347. getRaw: function Dict_getRaw(key) {
  21348. return this.map[key];
  21349. },
  21350. // creates new map and dereferences all Refs
  21351. getAll: function Dict_getAll() {
  21352. var all = Object.create(null);
  21353. var queue = null;
  21354. var key, obj;
  21355. for (key in this.map) {
  21356. obj = this.get(key);
  21357. if (obj instanceof Dict) {
  21358. if (isRecursionAllowedFor(obj)) {
  21359. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  21360. } else {
  21361. all[key] = this.getRaw(key);
  21362. }
  21363. } else {
  21364. all[key] = obj;
  21365. }
  21366. }
  21367. if (!queue) {
  21368. return all;
  21369. }
  21370. // trying to take cyclic references into the account
  21371. var processed = Object.create(null);
  21372. while (queue.length > 0) {
  21373. var item = queue.shift();
  21374. var itemObj = item.obj;
  21375. var objId = itemObj.objId;
  21376. if (objId && objId in processed) {
  21377. item.target[item.key] = processed[objId];
  21378. continue;
  21379. }
  21380. var dereferenced = Object.create(null);
  21381. for (key in itemObj.map) {
  21382. obj = itemObj.get(key);
  21383. if (obj instanceof Dict) {
  21384. if (isRecursionAllowedFor(obj)) {
  21385. queue.push({target: dereferenced, key: key, obj: obj});
  21386. } else {
  21387. dereferenced[key] = itemObj.getRaw(key);
  21388. }
  21389. } else {
  21390. dereferenced[key] = obj;
  21391. }
  21392. }
  21393. if (objId) {
  21394. processed[objId] = dereferenced;
  21395. }
  21396. item.target[item.key] = dereferenced;
  21397. }
  21398. return all;
  21399. },
  21400. getKeys: function Dict_getKeys() {
  21401. return Object.keys(this.map);
  21402. },
  21403. set: function Dict_set(key, value) {
  21404. this.map[key] = value;
  21405. },
  21406. has: function Dict_has(key) {
  21407. return key in this.map;
  21408. },
  21409. forEach: function Dict_forEach(callback) {
  21410. for (var key in this.map) {
  21411. callback(key, this.get(key));
  21412. }
  21413. }
  21414. };
  21415. Dict.empty = new Dict(null);
  21416. Dict.merge = function Dict_merge(xref, dictArray) {
  21417. var mergedDict = new Dict(xref);
  21418. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21419. var dict = dictArray[i];
  21420. if (!isDict(dict)) {
  21421. continue;
  21422. }
  21423. for (var keyName in dict.map) {
  21424. if (mergedDict.map[keyName]) {
  21425. continue;
  21426. }
  21427. mergedDict.map[keyName] = dict.map[keyName];
  21428. }
  21429. }
  21430. return mergedDict;
  21431. };
  21432. return Dict;
  21433. })();
  21434. var Ref = (function RefClosure() {
  21435. function Ref(num, gen) {
  21436. this.num = num;
  21437. this.gen = gen;
  21438. }
  21439. Ref.prototype = {
  21440. toString: function Ref_toString() {
  21441. // This function is hot, so we make the string as compact as possible.
  21442. // |this.gen| is almost always zero, so we treat that case specially.
  21443. var str = this.num + 'R';
  21444. if (this.gen !== 0) {
  21445. str += this.gen;
  21446. }
  21447. return str;
  21448. }
  21449. };
  21450. return Ref;
  21451. })();
  21452. // The reference is identified by number and generation.
  21453. // This structure stores only one instance of the reference.
  21454. var RefSet = (function RefSetClosure() {
  21455. function RefSet() {
  21456. this.dict = {};
  21457. }
  21458. RefSet.prototype = {
  21459. has: function RefSet_has(ref) {
  21460. return ref.toString() in this.dict;
  21461. },
  21462. put: function RefSet_put(ref) {
  21463. this.dict[ref.toString()] = true;
  21464. },
  21465. remove: function RefSet_remove(ref) {
  21466. delete this.dict[ref.toString()];
  21467. }
  21468. };
  21469. return RefSet;
  21470. })();
  21471. var RefSetCache = (function RefSetCacheClosure() {
  21472. function RefSetCache() {
  21473. this.dict = Object.create(null);
  21474. }
  21475. RefSetCache.prototype = {
  21476. get: function RefSetCache_get(ref) {
  21477. return this.dict[ref.toString()];
  21478. },
  21479. has: function RefSetCache_has(ref) {
  21480. return ref.toString() in this.dict;
  21481. },
  21482. put: function RefSetCache_put(ref, obj) {
  21483. this.dict[ref.toString()] = obj;
  21484. },
  21485. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21486. this.dict[ref.toString()] = this.get(aliasRef);
  21487. },
  21488. forEach: function RefSetCache_forEach(fn, thisArg) {
  21489. for (var i in this.dict) {
  21490. fn.call(thisArg, this.dict[i]);
  21491. }
  21492. },
  21493. clear: function RefSetCache_clear() {
  21494. this.dict = Object.create(null);
  21495. }
  21496. };
  21497. return RefSetCache;
  21498. })();
  21499. function isName(v) {
  21500. return v instanceof Name;
  21501. }
  21502. function isCmd(v, cmd) {
  21503. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21504. }
  21505. function isDict(v, type) {
  21506. if (!(v instanceof Dict)) {
  21507. return false;
  21508. }
  21509. if (!type) {
  21510. return true;
  21511. }
  21512. var dictType = v.get('Type');
  21513. return isName(dictType) && dictType.name === type;
  21514. }
  21515. function isRef(v) {
  21516. return v instanceof Ref;
  21517. }
  21518. function isStream(v) {
  21519. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21520. }
  21521. exports.Cmd = Cmd;
  21522. exports.Dict = Dict;
  21523. exports.Name = Name;
  21524. exports.Ref = Ref;
  21525. exports.RefSet = RefSet;
  21526. exports.RefSetCache = RefSetCache;
  21527. exports.isCmd = isCmd;
  21528. exports.isDict = isDict;
  21529. exports.isName = isName;
  21530. exports.isRef = isRef;
  21531. exports.isStream = isStream;
  21532. }));
  21533. (function (root, factory) {
  21534. {
  21535. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  21536. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  21537. root.pdfjsCoreJpx);
  21538. }
  21539. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  21540. coreJpx) {
  21541. var Util = sharedUtil.Util;
  21542. var error = sharedUtil.error;
  21543. var info = sharedUtil.info;
  21544. var isArray = sharedUtil.isArray;
  21545. var shadow = sharedUtil.shadow;
  21546. var warn = sharedUtil.warn;
  21547. var Dict = corePrimitives.Dict;
  21548. var Jbig2Image = coreJbig2.Jbig2Image;
  21549. var JpegImage = coreJpg.JpegImage;
  21550. var JpxImage = coreJpx.JpxImage;
  21551. var coreParser; // see _setCoreParser below
  21552. var EOF; // = coreParser.EOF;
  21553. var Lexer; // = coreParser.Lexer;
  21554. var coreColorSpace; // see _setCoreColorSpace below
  21555. var ColorSpace; // = coreColorSpace.ColorSpace;
  21556. var Stream = (function StreamClosure() {
  21557. function Stream(arrayBuffer, start, length, dict) {
  21558. this.bytes = (arrayBuffer instanceof Uint8Array ?
  21559. arrayBuffer : new Uint8Array(arrayBuffer));
  21560. this.start = start || 0;
  21561. this.pos = this.start;
  21562. this.end = (start + length) || this.bytes.length;
  21563. this.dict = dict;
  21564. }
  21565. // required methods for a stream. if a particular stream does not
  21566. // implement these, an error should be thrown
  21567. Stream.prototype = {
  21568. get length() {
  21569. return this.end - this.start;
  21570. },
  21571. get isEmpty() {
  21572. return this.length === 0;
  21573. },
  21574. getByte: function Stream_getByte() {
  21575. if (this.pos >= this.end) {
  21576. return -1;
  21577. }
  21578. return this.bytes[this.pos++];
  21579. },
  21580. getUint16: function Stream_getUint16() {
  21581. var b0 = this.getByte();
  21582. var b1 = this.getByte();
  21583. if (b0 === -1 || b1 === -1) {
  21584. return -1;
  21585. }
  21586. return (b0 << 8) + b1;
  21587. },
  21588. getInt32: function Stream_getInt32() {
  21589. var b0 = this.getByte();
  21590. var b1 = this.getByte();
  21591. var b2 = this.getByte();
  21592. var b3 = this.getByte();
  21593. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21594. },
  21595. // returns subarray of original buffer
  21596. // should only be read
  21597. getBytes: function Stream_getBytes(length) {
  21598. var bytes = this.bytes;
  21599. var pos = this.pos;
  21600. var strEnd = this.end;
  21601. if (!length) {
  21602. return bytes.subarray(pos, strEnd);
  21603. }
  21604. var end = pos + length;
  21605. if (end > strEnd) {
  21606. end = strEnd;
  21607. }
  21608. this.pos = end;
  21609. return bytes.subarray(pos, end);
  21610. },
  21611. peekByte: function Stream_peekByte() {
  21612. var peekedByte = this.getByte();
  21613. this.pos--;
  21614. return peekedByte;
  21615. },
  21616. peekBytes: function Stream_peekBytes(length) {
  21617. var bytes = this.getBytes(length);
  21618. this.pos -= bytes.length;
  21619. return bytes;
  21620. },
  21621. skip: function Stream_skip(n) {
  21622. if (!n) {
  21623. n = 1;
  21624. }
  21625. this.pos += n;
  21626. },
  21627. reset: function Stream_reset() {
  21628. this.pos = this.start;
  21629. },
  21630. moveStart: function Stream_moveStart() {
  21631. this.start = this.pos;
  21632. },
  21633. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  21634. return new Stream(this.bytes.buffer, start, length, dict);
  21635. },
  21636. isStream: true
  21637. };
  21638. return Stream;
  21639. })();
  21640. var StringStream = (function StringStreamClosure() {
  21641. function StringStream(str) {
  21642. var length = str.length;
  21643. var bytes = new Uint8Array(length);
  21644. for (var n = 0; n < length; ++n) {
  21645. bytes[n] = str.charCodeAt(n);
  21646. }
  21647. Stream.call(this, bytes);
  21648. }
  21649. StringStream.prototype = Stream.prototype;
  21650. return StringStream;
  21651. })();
  21652. // super class for the decoding streams
  21653. var DecodeStream = (function DecodeStreamClosure() {
  21654. // Lots of DecodeStreams are created whose buffers are never used. For these
  21655. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  21656. // having special cases that would be required if we used |null| for an empty
  21657. // buffer.
  21658. var emptyBuffer = new Uint8Array(0);
  21659. function DecodeStream(maybeMinBufferLength) {
  21660. this.pos = 0;
  21661. this.bufferLength = 0;
  21662. this.eof = false;
  21663. this.buffer = emptyBuffer;
  21664. this.minBufferLength = 512;
  21665. if (maybeMinBufferLength) {
  21666. // Compute the first power of two that is as big as maybeMinBufferLength.
  21667. while (this.minBufferLength < maybeMinBufferLength) {
  21668. this.minBufferLength *= 2;
  21669. }
  21670. }
  21671. }
  21672. DecodeStream.prototype = {
  21673. get isEmpty() {
  21674. while (!this.eof && this.bufferLength === 0) {
  21675. this.readBlock();
  21676. }
  21677. return this.bufferLength === 0;
  21678. },
  21679. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  21680. var buffer = this.buffer;
  21681. if (requested <= buffer.byteLength) {
  21682. return buffer;
  21683. }
  21684. var size = this.minBufferLength;
  21685. while (size < requested) {
  21686. size *= 2;
  21687. }
  21688. var buffer2 = new Uint8Array(size);
  21689. buffer2.set(buffer);
  21690. return (this.buffer = buffer2);
  21691. },
  21692. getByte: function DecodeStream_getByte() {
  21693. var pos = this.pos;
  21694. while (this.bufferLength <= pos) {
  21695. if (this.eof) {
  21696. return -1;
  21697. }
  21698. this.readBlock();
  21699. }
  21700. return this.buffer[this.pos++];
  21701. },
  21702. getUint16: function DecodeStream_getUint16() {
  21703. var b0 = this.getByte();
  21704. var b1 = this.getByte();
  21705. if (b0 === -1 || b1 === -1) {
  21706. return -1;
  21707. }
  21708. return (b0 << 8) + b1;
  21709. },
  21710. getInt32: function DecodeStream_getInt32() {
  21711. var b0 = this.getByte();
  21712. var b1 = this.getByte();
  21713. var b2 = this.getByte();
  21714. var b3 = this.getByte();
  21715. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21716. },
  21717. getBytes: function DecodeStream_getBytes(length) {
  21718. var end, pos = this.pos;
  21719. if (length) {
  21720. this.ensureBuffer(pos + length);
  21721. end = pos + length;
  21722. while (!this.eof && this.bufferLength < end) {
  21723. this.readBlock();
  21724. }
  21725. var bufEnd = this.bufferLength;
  21726. if (end > bufEnd) {
  21727. end = bufEnd;
  21728. }
  21729. } else {
  21730. while (!this.eof) {
  21731. this.readBlock();
  21732. }
  21733. end = this.bufferLength;
  21734. }
  21735. this.pos = end;
  21736. return this.buffer.subarray(pos, end);
  21737. },
  21738. peekByte: function DecodeStream_peekByte() {
  21739. var peekedByte = this.getByte();
  21740. this.pos--;
  21741. return peekedByte;
  21742. },
  21743. peekBytes: function DecodeStream_peekBytes(length) {
  21744. var bytes = this.getBytes(length);
  21745. this.pos -= bytes.length;
  21746. return bytes;
  21747. },
  21748. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  21749. var end = start + length;
  21750. while (this.bufferLength <= end && !this.eof) {
  21751. this.readBlock();
  21752. }
  21753. return new Stream(this.buffer, start, length, dict);
  21754. },
  21755. skip: function DecodeStream_skip(n) {
  21756. if (!n) {
  21757. n = 1;
  21758. }
  21759. this.pos += n;
  21760. },
  21761. reset: function DecodeStream_reset() {
  21762. this.pos = 0;
  21763. },
  21764. getBaseStreams: function DecodeStream_getBaseStreams() {
  21765. if (this.str && this.str.getBaseStreams) {
  21766. return this.str.getBaseStreams();
  21767. }
  21768. return [];
  21769. }
  21770. };
  21771. return DecodeStream;
  21772. })();
  21773. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  21774. function StreamsSequenceStream(streams) {
  21775. this.streams = streams;
  21776. DecodeStream.call(this, /* maybeLength = */ null);
  21777. }
  21778. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  21779. StreamsSequenceStream.prototype.readBlock =
  21780. function streamSequenceStreamReadBlock() {
  21781. var streams = this.streams;
  21782. if (streams.length === 0) {
  21783. this.eof = true;
  21784. return;
  21785. }
  21786. var stream = streams.shift();
  21787. var chunk = stream.getBytes();
  21788. var bufferLength = this.bufferLength;
  21789. var newLength = bufferLength + chunk.length;
  21790. var buffer = this.ensureBuffer(newLength);
  21791. buffer.set(chunk, bufferLength);
  21792. this.bufferLength = newLength;
  21793. };
  21794. StreamsSequenceStream.prototype.getBaseStreams =
  21795. function StreamsSequenceStream_getBaseStreams() {
  21796. var baseStreams = [];
  21797. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  21798. var stream = this.streams[i];
  21799. if (stream.getBaseStreams) {
  21800. Util.appendToArray(baseStreams, stream.getBaseStreams());
  21801. }
  21802. }
  21803. return baseStreams;
  21804. };
  21805. return StreamsSequenceStream;
  21806. })();
  21807. var FlateStream = (function FlateStreamClosure() {
  21808. var codeLenCodeMap = new Int32Array([
  21809. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  21810. ]);
  21811. var lengthDecode = new Int32Array([
  21812. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  21813. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  21814. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  21815. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  21816. ]);
  21817. var distDecode = new Int32Array([
  21818. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  21819. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  21820. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  21821. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  21822. ]);
  21823. var fixedLitCodeTab = [new Int32Array([
  21824. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  21825. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  21826. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  21827. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  21828. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  21829. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  21830. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  21831. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  21832. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  21833. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  21834. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  21835. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  21836. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  21837. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  21838. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  21839. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  21840. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  21841. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  21842. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  21843. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  21844. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  21845. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  21846. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  21847. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  21848. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  21849. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  21850. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  21851. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  21852. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  21853. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  21854. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  21855. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  21856. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  21857. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  21858. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  21859. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  21860. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  21861. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  21862. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  21863. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  21864. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  21865. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  21866. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  21867. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  21868. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  21869. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  21870. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  21871. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  21872. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  21873. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  21874. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  21875. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  21876. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  21877. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  21878. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  21879. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  21880. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  21881. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  21882. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  21883. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  21884. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  21885. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  21886. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  21887. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  21888. ]), 9];
  21889. var fixedDistCodeTab = [new Int32Array([
  21890. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  21891. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  21892. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  21893. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  21894. ]), 5];
  21895. function FlateStream(str, maybeLength) {
  21896. this.str = str;
  21897. this.dict = str.dict;
  21898. var cmf = str.getByte();
  21899. var flg = str.getByte();
  21900. if (cmf === -1 || flg === -1) {
  21901. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  21902. }
  21903. if ((cmf & 0x0f) !== 0x08) {
  21904. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  21905. }
  21906. if ((((cmf << 8) + flg) % 31) !== 0) {
  21907. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  21908. }
  21909. if (flg & 0x20) {
  21910. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  21911. }
  21912. this.codeSize = 0;
  21913. this.codeBuf = 0;
  21914. DecodeStream.call(this, maybeLength);
  21915. }
  21916. FlateStream.prototype = Object.create(DecodeStream.prototype);
  21917. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  21918. var str = this.str;
  21919. var codeSize = this.codeSize;
  21920. var codeBuf = this.codeBuf;
  21921. var b;
  21922. while (codeSize < bits) {
  21923. if ((b = str.getByte()) === -1) {
  21924. error('Bad encoding in flate stream');
  21925. }
  21926. codeBuf |= b << codeSize;
  21927. codeSize += 8;
  21928. }
  21929. b = codeBuf & ((1 << bits) - 1);
  21930. this.codeBuf = codeBuf >> bits;
  21931. this.codeSize = codeSize -= bits;
  21932. return b;
  21933. };
  21934. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  21935. var str = this.str;
  21936. var codes = table[0];
  21937. var maxLen = table[1];
  21938. var codeSize = this.codeSize;
  21939. var codeBuf = this.codeBuf;
  21940. var b;
  21941. while (codeSize < maxLen) {
  21942. if ((b = str.getByte()) === -1) {
  21943. // premature end of stream. code might however still be valid.
  21944. // codeSize < codeLen check below guards against incomplete codeVal.
  21945. break;
  21946. }
  21947. codeBuf |= (b << codeSize);
  21948. codeSize += 8;
  21949. }
  21950. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  21951. var codeLen = code >> 16;
  21952. var codeVal = code & 0xffff;
  21953. if (codeLen < 1 || codeSize < codeLen) {
  21954. error('Bad encoding in flate stream');
  21955. }
  21956. this.codeBuf = (codeBuf >> codeLen);
  21957. this.codeSize = (codeSize - codeLen);
  21958. return codeVal;
  21959. };
  21960. FlateStream.prototype.generateHuffmanTable =
  21961. function flateStreamGenerateHuffmanTable(lengths) {
  21962. var n = lengths.length;
  21963. // find max code length
  21964. var maxLen = 0;
  21965. var i;
  21966. for (i = 0; i < n; ++i) {
  21967. if (lengths[i] > maxLen) {
  21968. maxLen = lengths[i];
  21969. }
  21970. }
  21971. // build the table
  21972. var size = 1 << maxLen;
  21973. var codes = new Int32Array(size);
  21974. for (var len = 1, code = 0, skip = 2;
  21975. len <= maxLen;
  21976. ++len, code <<= 1, skip <<= 1) {
  21977. for (var val = 0; val < n; ++val) {
  21978. if (lengths[val] === len) {
  21979. // bit-reverse the code
  21980. var code2 = 0;
  21981. var t = code;
  21982. for (i = 0; i < len; ++i) {
  21983. code2 = (code2 << 1) | (t & 1);
  21984. t >>= 1;
  21985. }
  21986. // fill the table entries
  21987. for (i = code2; i < size; i += skip) {
  21988. codes[i] = (len << 16) | val;
  21989. }
  21990. ++code;
  21991. }
  21992. }
  21993. }
  21994. return [codes, maxLen];
  21995. };
  21996. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  21997. var buffer, len;
  21998. var str = this.str;
  21999. // read block header
  22000. var hdr = this.getBits(3);
  22001. if (hdr & 1) {
  22002. this.eof = true;
  22003. }
  22004. hdr >>= 1;
  22005. if (hdr === 0) { // uncompressed block
  22006. var b;
  22007. if ((b = str.getByte()) === -1) {
  22008. error('Bad block header in flate stream');
  22009. }
  22010. var blockLen = b;
  22011. if ((b = str.getByte()) === -1) {
  22012. error('Bad block header in flate stream');
  22013. }
  22014. blockLen |= (b << 8);
  22015. if ((b = str.getByte()) === -1) {
  22016. error('Bad block header in flate stream');
  22017. }
  22018. var check = b;
  22019. if ((b = str.getByte()) === -1) {
  22020. error('Bad block header in flate stream');
  22021. }
  22022. check |= (b << 8);
  22023. if (check !== (~blockLen & 0xffff) &&
  22024. (blockLen !== 0 || check !== 0)) {
  22025. // Ignoring error for bad "empty" block (see issue 1277)
  22026. error('Bad uncompressed block length in flate stream');
  22027. }
  22028. this.codeBuf = 0;
  22029. this.codeSize = 0;
  22030. var bufferLength = this.bufferLength;
  22031. buffer = this.ensureBuffer(bufferLength + blockLen);
  22032. var end = bufferLength + blockLen;
  22033. this.bufferLength = end;
  22034. if (blockLen === 0) {
  22035. if (str.peekByte() === -1) {
  22036. this.eof = true;
  22037. }
  22038. } else {
  22039. for (var n = bufferLength; n < end; ++n) {
  22040. if ((b = str.getByte()) === -1) {
  22041. this.eof = true;
  22042. break;
  22043. }
  22044. buffer[n] = b;
  22045. }
  22046. }
  22047. return;
  22048. }
  22049. var litCodeTable;
  22050. var distCodeTable;
  22051. if (hdr === 1) { // compressed block, fixed codes
  22052. litCodeTable = fixedLitCodeTab;
  22053. distCodeTable = fixedDistCodeTab;
  22054. } else if (hdr === 2) { // compressed block, dynamic codes
  22055. var numLitCodes = this.getBits(5) + 257;
  22056. var numDistCodes = this.getBits(5) + 1;
  22057. var numCodeLenCodes = this.getBits(4) + 4;
  22058. // build the code lengths code table
  22059. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  22060. var i;
  22061. for (i = 0; i < numCodeLenCodes; ++i) {
  22062. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  22063. }
  22064. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  22065. // build the literal and distance code tables
  22066. len = 0;
  22067. i = 0;
  22068. var codes = numLitCodes + numDistCodes;
  22069. var codeLengths = new Uint8Array(codes);
  22070. var bitsLength, bitsOffset, what;
  22071. while (i < codes) {
  22072. var code = this.getCode(codeLenCodeTab);
  22073. if (code === 16) {
  22074. bitsLength = 2; bitsOffset = 3; what = len;
  22075. } else if (code === 17) {
  22076. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  22077. } else if (code === 18) {
  22078. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  22079. } else {
  22080. codeLengths[i++] = len = code;
  22081. continue;
  22082. }
  22083. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  22084. while (repeatLength-- > 0) {
  22085. codeLengths[i++] = what;
  22086. }
  22087. }
  22088. litCodeTable =
  22089. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  22090. distCodeTable =
  22091. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  22092. } else {
  22093. error('Unknown block type in flate stream');
  22094. }
  22095. buffer = this.buffer;
  22096. var limit = buffer ? buffer.length : 0;
  22097. var pos = this.bufferLength;
  22098. while (true) {
  22099. var code1 = this.getCode(litCodeTable);
  22100. if (code1 < 256) {
  22101. if (pos + 1 >= limit) {
  22102. buffer = this.ensureBuffer(pos + 1);
  22103. limit = buffer.length;
  22104. }
  22105. buffer[pos++] = code1;
  22106. continue;
  22107. }
  22108. if (code1 === 256) {
  22109. this.bufferLength = pos;
  22110. return;
  22111. }
  22112. code1 -= 257;
  22113. code1 = lengthDecode[code1];
  22114. var code2 = code1 >> 16;
  22115. if (code2 > 0) {
  22116. code2 = this.getBits(code2);
  22117. }
  22118. len = (code1 & 0xffff) + code2;
  22119. code1 = this.getCode(distCodeTable);
  22120. code1 = distDecode[code1];
  22121. code2 = code1 >> 16;
  22122. if (code2 > 0) {
  22123. code2 = this.getBits(code2);
  22124. }
  22125. var dist = (code1 & 0xffff) + code2;
  22126. if (pos + len >= limit) {
  22127. buffer = this.ensureBuffer(pos + len);
  22128. limit = buffer.length;
  22129. }
  22130. for (var k = 0; k < len; ++k, ++pos) {
  22131. buffer[pos] = buffer[pos - dist];
  22132. }
  22133. }
  22134. };
  22135. return FlateStream;
  22136. })();
  22137. var PredictorStream = (function PredictorStreamClosure() {
  22138. function PredictorStream(str, maybeLength, params) {
  22139. var predictor = this.predictor = params.get('Predictor') || 1;
  22140. if (predictor <= 1) {
  22141. return str; // no prediction
  22142. }
  22143. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  22144. error('Unsupported predictor: ' + predictor);
  22145. }
  22146. if (predictor === 2) {
  22147. this.readBlock = this.readBlockTiff;
  22148. } else {
  22149. this.readBlock = this.readBlockPng;
  22150. }
  22151. this.str = str;
  22152. this.dict = str.dict;
  22153. var colors = this.colors = params.get('Colors') || 1;
  22154. var bits = this.bits = params.get('BitsPerComponent') || 8;
  22155. var columns = this.columns = params.get('Columns') || 1;
  22156. this.pixBytes = (colors * bits + 7) >> 3;
  22157. this.rowBytes = (columns * colors * bits + 7) >> 3;
  22158. DecodeStream.call(this, maybeLength);
  22159. return this;
  22160. }
  22161. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  22162. PredictorStream.prototype.readBlockTiff =
  22163. function predictorStreamReadBlockTiff() {
  22164. var rowBytes = this.rowBytes;
  22165. var bufferLength = this.bufferLength;
  22166. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  22167. var bits = this.bits;
  22168. var colors = this.colors;
  22169. var rawBytes = this.str.getBytes(rowBytes);
  22170. this.eof = !rawBytes.length;
  22171. if (this.eof) {
  22172. return;
  22173. }
  22174. var inbuf = 0, outbuf = 0;
  22175. var inbits = 0, outbits = 0;
  22176. var pos = bufferLength;
  22177. var i;
  22178. if (bits === 1) {
  22179. for (i = 0; i < rowBytes; ++i) {
  22180. var c = rawBytes[i];
  22181. inbuf = (inbuf << 8) | c;
  22182. // bitwise addition is exclusive or
  22183. // first shift inbuf and then add
  22184. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  22185. // truncate inbuf (assumes colors < 16)
  22186. inbuf &= 0xFFFF;
  22187. }
  22188. } else if (bits === 8) {
  22189. for (i = 0; i < colors; ++i) {
  22190. buffer[pos++] = rawBytes[i];
  22191. }
  22192. for (; i < rowBytes; ++i) {
  22193. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  22194. pos++;
  22195. }
  22196. } else {
  22197. var compArray = new Uint8Array(colors + 1);
  22198. var bitMask = (1 << bits) - 1;
  22199. var j = 0, k = bufferLength;
  22200. var columns = this.columns;
  22201. for (i = 0; i < columns; ++i) {
  22202. for (var kk = 0; kk < colors; ++kk) {
  22203. if (inbits < bits) {
  22204. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  22205. inbits += 8;
  22206. }
  22207. compArray[kk] = (compArray[kk] +
  22208. (inbuf >> (inbits - bits))) & bitMask;
  22209. inbits -= bits;
  22210. outbuf = (outbuf << bits) | compArray[kk];
  22211. outbits += bits;
  22212. if (outbits >= 8) {
  22213. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  22214. outbits -= 8;
  22215. }
  22216. }
  22217. }
  22218. if (outbits > 0) {
  22219. buffer[k++] = (outbuf << (8 - outbits)) +
  22220. (inbuf & ((1 << (8 - outbits)) - 1));
  22221. }
  22222. }
  22223. this.bufferLength += rowBytes;
  22224. };
  22225. PredictorStream.prototype.readBlockPng =
  22226. function predictorStreamReadBlockPng() {
  22227. var rowBytes = this.rowBytes;
  22228. var pixBytes = this.pixBytes;
  22229. var predictor = this.str.getByte();
  22230. var rawBytes = this.str.getBytes(rowBytes);
  22231. this.eof = !rawBytes.length;
  22232. if (this.eof) {
  22233. return;
  22234. }
  22235. var bufferLength = this.bufferLength;
  22236. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  22237. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  22238. if (prevRow.length === 0) {
  22239. prevRow = new Uint8Array(rowBytes);
  22240. }
  22241. var i, j = bufferLength, up, c;
  22242. switch (predictor) {
  22243. case 0:
  22244. for (i = 0; i < rowBytes; ++i) {
  22245. buffer[j++] = rawBytes[i];
  22246. }
  22247. break;
  22248. case 1:
  22249. for (i = 0; i < pixBytes; ++i) {
  22250. buffer[j++] = rawBytes[i];
  22251. }
  22252. for (; i < rowBytes; ++i) {
  22253. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  22254. j++;
  22255. }
  22256. break;
  22257. case 2:
  22258. for (i = 0; i < rowBytes; ++i) {
  22259. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  22260. }
  22261. break;
  22262. case 3:
  22263. for (i = 0; i < pixBytes; ++i) {
  22264. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  22265. }
  22266. for (; i < rowBytes; ++i) {
  22267. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  22268. rawBytes[i]) & 0xFF;
  22269. j++;
  22270. }
  22271. break;
  22272. case 4:
  22273. // we need to save the up left pixels values. the simplest way
  22274. // is to create a new buffer
  22275. for (i = 0; i < pixBytes; ++i) {
  22276. up = prevRow[i];
  22277. c = rawBytes[i];
  22278. buffer[j++] = up + c;
  22279. }
  22280. for (; i < rowBytes; ++i) {
  22281. up = prevRow[i];
  22282. var upLeft = prevRow[i - pixBytes];
  22283. var left = buffer[j - pixBytes];
  22284. var p = left + up - upLeft;
  22285. var pa = p - left;
  22286. if (pa < 0) {
  22287. pa = -pa;
  22288. }
  22289. var pb = p - up;
  22290. if (pb < 0) {
  22291. pb = -pb;
  22292. }
  22293. var pc = p - upLeft;
  22294. if (pc < 0) {
  22295. pc = -pc;
  22296. }
  22297. c = rawBytes[i];
  22298. if (pa <= pb && pa <= pc) {
  22299. buffer[j++] = left + c;
  22300. } else if (pb <= pc) {
  22301. buffer[j++] = up + c;
  22302. } else {
  22303. buffer[j++] = upLeft + c;
  22304. }
  22305. }
  22306. break;
  22307. default:
  22308. error('Unsupported predictor: ' + predictor);
  22309. }
  22310. this.bufferLength += rowBytes;
  22311. };
  22312. return PredictorStream;
  22313. })();
  22314. /**
  22315. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  22316. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  22317. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  22318. * a library to decode these images and the stream behaves like all the other
  22319. * DecodeStreams.
  22320. */
  22321. var JpegStream = (function JpegStreamClosure() {
  22322. function JpegStream(stream, maybeLength, dict, xref) {
  22323. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  22324. // Note: this seems to mainly affect inline images.
  22325. var ch;
  22326. while ((ch = stream.getByte()) !== -1) {
  22327. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  22328. stream.skip(-1); // Reset the stream position to the SOI.
  22329. break;
  22330. }
  22331. }
  22332. this.stream = stream;
  22333. this.maybeLength = maybeLength;
  22334. this.dict = dict;
  22335. DecodeStream.call(this, maybeLength);
  22336. }
  22337. JpegStream.prototype = Object.create(DecodeStream.prototype);
  22338. Object.defineProperty(JpegStream.prototype, 'bytes', {
  22339. get: function JpegStream_bytes() {
  22340. // If this.maybeLength is null, we'll get the entire stream.
  22341. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22342. },
  22343. configurable: true
  22344. });
  22345. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  22346. if (this.bufferLength) {
  22347. return;
  22348. }
  22349. try {
  22350. var jpegImage = new JpegImage();
  22351. // checking if values needs to be transformed before conversion
  22352. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  22353. var decodeArr = this.dict.get('Decode');
  22354. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  22355. var decodeArrLength = decodeArr.length;
  22356. var transform = new Int32Array(decodeArrLength);
  22357. var transformNeeded = false;
  22358. var maxValue = (1 << bitsPerComponent) - 1;
  22359. for (var i = 0; i < decodeArrLength; i += 2) {
  22360. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  22361. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  22362. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  22363. transformNeeded = true;
  22364. }
  22365. }
  22366. if (transformNeeded) {
  22367. jpegImage.decodeTransform = transform;
  22368. }
  22369. }
  22370. jpegImage.parse(this.bytes);
  22371. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  22372. this.forceRGB);
  22373. this.buffer = data;
  22374. this.bufferLength = data.length;
  22375. this.eof = true;
  22376. } catch (e) {
  22377. error('JPEG error: ' + e);
  22378. }
  22379. };
  22380. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  22381. this.ensureBuffer();
  22382. return this.buffer;
  22383. };
  22384. JpegStream.prototype.getIR = function JpegStream_getIR() {
  22385. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  22386. };
  22387. /**
  22388. * Checks if the image can be decoded and displayed by the browser without any
  22389. * further processing such as color space conversions.
  22390. */
  22391. JpegStream.prototype.isNativelySupported =
  22392. function JpegStream_isNativelySupported(xref, res) {
  22393. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  22394. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  22395. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  22396. };
  22397. /**
  22398. * Checks if the image can be decoded by the browser.
  22399. */
  22400. JpegStream.prototype.isNativelyDecodable =
  22401. function JpegStream_isNativelyDecodable(xref, res) {
  22402. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  22403. return (cs.numComps === 1 || cs.numComps === 3) &&
  22404. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  22405. };
  22406. return JpegStream;
  22407. })();
  22408. /**
  22409. * For JPEG 2000's we use a library to decode these images and
  22410. * the stream behaves like all the other DecodeStreams.
  22411. */
  22412. var JpxStream = (function JpxStreamClosure() {
  22413. function JpxStream(stream, maybeLength, dict) {
  22414. this.stream = stream;
  22415. this.maybeLength = maybeLength;
  22416. this.dict = dict;
  22417. DecodeStream.call(this, maybeLength);
  22418. }
  22419. JpxStream.prototype = Object.create(DecodeStream.prototype);
  22420. Object.defineProperty(JpxStream.prototype, 'bytes', {
  22421. get: function JpxStream_bytes() {
  22422. // If this.maybeLength is null, we'll get the entire stream.
  22423. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22424. },
  22425. configurable: true
  22426. });
  22427. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  22428. if (this.bufferLength) {
  22429. return;
  22430. }
  22431. var jpxImage = new JpxImage();
  22432. jpxImage.parse(this.bytes);
  22433. var width = jpxImage.width;
  22434. var height = jpxImage.height;
  22435. var componentsCount = jpxImage.componentsCount;
  22436. var tileCount = jpxImage.tiles.length;
  22437. if (tileCount === 1) {
  22438. this.buffer = jpxImage.tiles[0].items;
  22439. } else {
  22440. var data = new Uint8Array(width * height * componentsCount);
  22441. for (var k = 0; k < tileCount; k++) {
  22442. var tileComponents = jpxImage.tiles[k];
  22443. var tileWidth = tileComponents.width;
  22444. var tileHeight = tileComponents.height;
  22445. var tileLeft = tileComponents.left;
  22446. var tileTop = tileComponents.top;
  22447. var src = tileComponents.items;
  22448. var srcPosition = 0;
  22449. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  22450. var imgRowSize = width * componentsCount;
  22451. var tileRowSize = tileWidth * componentsCount;
  22452. for (var j = 0; j < tileHeight; j++) {
  22453. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  22454. data.set(rowBytes, dataPosition);
  22455. srcPosition += tileRowSize;
  22456. dataPosition += imgRowSize;
  22457. }
  22458. }
  22459. this.buffer = data;
  22460. }
  22461. this.bufferLength = this.buffer.length;
  22462. this.eof = true;
  22463. };
  22464. return JpxStream;
  22465. })();
  22466. /**
  22467. * For JBIG2's we use a library to decode these images and
  22468. * the stream behaves like all the other DecodeStreams.
  22469. */
  22470. var Jbig2Stream = (function Jbig2StreamClosure() {
  22471. function Jbig2Stream(stream, maybeLength, dict) {
  22472. this.stream = stream;
  22473. this.maybeLength = maybeLength;
  22474. this.dict = dict;
  22475. DecodeStream.call(this, maybeLength);
  22476. }
  22477. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  22478. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  22479. get: function Jbig2Stream_bytes() {
  22480. // If this.maybeLength is null, we'll get the entire stream.
  22481. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22482. },
  22483. configurable: true
  22484. });
  22485. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  22486. if (this.bufferLength) {
  22487. return;
  22488. }
  22489. var jbig2Image = new Jbig2Image();
  22490. var chunks = [], xref = this.dict.xref;
  22491. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  22492. // According to the PDF specification, DecodeParms can be either
  22493. // a dictionary, or an array whose elements are dictionaries.
  22494. if (isArray(decodeParams)) {
  22495. if (decodeParams.length > 1) {
  22496. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  22497. 'not supported.');
  22498. }
  22499. decodeParams = xref.fetchIfRef(decodeParams[0]);
  22500. }
  22501. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  22502. var globalsStream = decodeParams.get('JBIG2Globals');
  22503. var globals = globalsStream.getBytes();
  22504. chunks.push({data: globals, start: 0, end: globals.length});
  22505. }
  22506. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  22507. var data = jbig2Image.parseChunks(chunks);
  22508. var dataLength = data.length;
  22509. // JBIG2 had black as 1 and white as 0, inverting the colors
  22510. for (var i = 0; i < dataLength; i++) {
  22511. data[i] ^= 0xFF;
  22512. }
  22513. this.buffer = data;
  22514. this.bufferLength = dataLength;
  22515. this.eof = true;
  22516. };
  22517. return Jbig2Stream;
  22518. })();
  22519. var DecryptStream = (function DecryptStreamClosure() {
  22520. function DecryptStream(str, maybeLength, decrypt) {
  22521. this.str = str;
  22522. this.dict = str.dict;
  22523. this.decrypt = decrypt;
  22524. this.nextChunk = null;
  22525. this.initialized = false;
  22526. DecodeStream.call(this, maybeLength);
  22527. }
  22528. var chunkSize = 512;
  22529. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  22530. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  22531. var chunk;
  22532. if (this.initialized) {
  22533. chunk = this.nextChunk;
  22534. } else {
  22535. chunk = this.str.getBytes(chunkSize);
  22536. this.initialized = true;
  22537. }
  22538. if (!chunk || chunk.length === 0) {
  22539. this.eof = true;
  22540. return;
  22541. }
  22542. this.nextChunk = this.str.getBytes(chunkSize);
  22543. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  22544. var decrypt = this.decrypt;
  22545. chunk = decrypt(chunk, !hasMoreData);
  22546. var bufferLength = this.bufferLength;
  22547. var i, n = chunk.length;
  22548. var buffer = this.ensureBuffer(bufferLength + n);
  22549. for (i = 0; i < n; i++) {
  22550. buffer[bufferLength++] = chunk[i];
  22551. }
  22552. this.bufferLength = bufferLength;
  22553. };
  22554. return DecryptStream;
  22555. })();
  22556. var Ascii85Stream = (function Ascii85StreamClosure() {
  22557. function Ascii85Stream(str, maybeLength) {
  22558. this.str = str;
  22559. this.dict = str.dict;
  22560. this.input = new Uint8Array(5);
  22561. // Most streams increase in size when decoded, but Ascii85 streams
  22562. // typically shrink by ~20%.
  22563. if (maybeLength) {
  22564. maybeLength = 0.8 * maybeLength;
  22565. }
  22566. DecodeStream.call(this, maybeLength);
  22567. }
  22568. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  22569. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  22570. var TILDA_CHAR = 0x7E; // '~'
  22571. var Z_LOWER_CHAR = 0x7A; // 'z'
  22572. var EOF = -1;
  22573. var str = this.str;
  22574. var c = str.getByte();
  22575. while (Lexer.isSpace(c)) {
  22576. c = str.getByte();
  22577. }
  22578. if (c === EOF || c === TILDA_CHAR) {
  22579. this.eof = true;
  22580. return;
  22581. }
  22582. var bufferLength = this.bufferLength, buffer;
  22583. var i;
  22584. // special code for z
  22585. if (c === Z_LOWER_CHAR) {
  22586. buffer = this.ensureBuffer(bufferLength + 4);
  22587. for (i = 0; i < 4; ++i) {
  22588. buffer[bufferLength + i] = 0;
  22589. }
  22590. this.bufferLength += 4;
  22591. } else {
  22592. var input = this.input;
  22593. input[0] = c;
  22594. for (i = 1; i < 5; ++i) {
  22595. c = str.getByte();
  22596. while (Lexer.isSpace(c)) {
  22597. c = str.getByte();
  22598. }
  22599. input[i] = c;
  22600. if (c === EOF || c === TILDA_CHAR) {
  22601. break;
  22602. }
  22603. }
  22604. buffer = this.ensureBuffer(bufferLength + i - 1);
  22605. this.bufferLength += i - 1;
  22606. // partial ending;
  22607. if (i < 5) {
  22608. for (; i < 5; ++i) {
  22609. input[i] = 0x21 + 84;
  22610. }
  22611. this.eof = true;
  22612. }
  22613. var t = 0;
  22614. for (i = 0; i < 5; ++i) {
  22615. t = t * 85 + (input[i] - 0x21);
  22616. }
  22617. for (i = 3; i >= 0; --i) {
  22618. buffer[bufferLength + i] = t & 0xFF;
  22619. t >>= 8;
  22620. }
  22621. }
  22622. };
  22623. return Ascii85Stream;
  22624. })();
  22625. var AsciiHexStream = (function AsciiHexStreamClosure() {
  22626. function AsciiHexStream(str, maybeLength) {
  22627. this.str = str;
  22628. this.dict = str.dict;
  22629. this.firstDigit = -1;
  22630. // Most streams increase in size when decoded, but AsciiHex streams shrink
  22631. // by 50%.
  22632. if (maybeLength) {
  22633. maybeLength = 0.5 * maybeLength;
  22634. }
  22635. DecodeStream.call(this, maybeLength);
  22636. }
  22637. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  22638. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  22639. var UPSTREAM_BLOCK_SIZE = 8000;
  22640. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  22641. if (!bytes.length) {
  22642. this.eof = true;
  22643. return;
  22644. }
  22645. var maxDecodeLength = (bytes.length + 1) >> 1;
  22646. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  22647. var bufferLength = this.bufferLength;
  22648. var firstDigit = this.firstDigit;
  22649. for (var i = 0, ii = bytes.length; i < ii; i++) {
  22650. var ch = bytes[i], digit;
  22651. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  22652. digit = ch & 0x0F;
  22653. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  22654. // 'A'-'Z', 'a'-'z'
  22655. digit = (ch & 0x0F) + 9;
  22656. } else if (ch === 0x3E) { // '>'
  22657. this.eof = true;
  22658. break;
  22659. } else { // probably whitespace
  22660. continue; // ignoring
  22661. }
  22662. if (firstDigit < 0) {
  22663. firstDigit = digit;
  22664. } else {
  22665. buffer[bufferLength++] = (firstDigit << 4) | digit;
  22666. firstDigit = -1;
  22667. }
  22668. }
  22669. if (firstDigit >= 0 && this.eof) {
  22670. // incomplete byte
  22671. buffer[bufferLength++] = (firstDigit << 4);
  22672. firstDigit = -1;
  22673. }
  22674. this.firstDigit = firstDigit;
  22675. this.bufferLength = bufferLength;
  22676. };
  22677. return AsciiHexStream;
  22678. })();
  22679. var RunLengthStream = (function RunLengthStreamClosure() {
  22680. function RunLengthStream(str, maybeLength) {
  22681. this.str = str;
  22682. this.dict = str.dict;
  22683. DecodeStream.call(this, maybeLength);
  22684. }
  22685. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  22686. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  22687. // The repeatHeader has following format. The first byte defines type of run
  22688. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  22689. // (in addition to the second byte from the header), n = 129 through 255 -
  22690. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  22691. var repeatHeader = this.str.getBytes(2);
  22692. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  22693. this.eof = true;
  22694. return;
  22695. }
  22696. var buffer;
  22697. var bufferLength = this.bufferLength;
  22698. var n = repeatHeader[0];
  22699. if (n < 128) {
  22700. // copy n bytes
  22701. buffer = this.ensureBuffer(bufferLength + n + 1);
  22702. buffer[bufferLength++] = repeatHeader[1];
  22703. if (n > 0) {
  22704. var source = this.str.getBytes(n);
  22705. buffer.set(source, bufferLength);
  22706. bufferLength += n;
  22707. }
  22708. } else {
  22709. n = 257 - n;
  22710. var b = repeatHeader[1];
  22711. buffer = this.ensureBuffer(bufferLength + n + 1);
  22712. for (var i = 0; i < n; i++) {
  22713. buffer[bufferLength++] = b;
  22714. }
  22715. }
  22716. this.bufferLength = bufferLength;
  22717. };
  22718. return RunLengthStream;
  22719. })();
  22720. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  22721. var ccittEOL = -2;
  22722. var twoDimPass = 0;
  22723. var twoDimHoriz = 1;
  22724. var twoDimVert0 = 2;
  22725. var twoDimVertR1 = 3;
  22726. var twoDimVertL1 = 4;
  22727. var twoDimVertR2 = 5;
  22728. var twoDimVertL2 = 6;
  22729. var twoDimVertR3 = 7;
  22730. var twoDimVertL3 = 8;
  22731. var twoDimTable = [
  22732. [-1, -1], [-1, -1], // 000000x
  22733. [7, twoDimVertL3], // 0000010
  22734. [7, twoDimVertR3], // 0000011
  22735. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  22736. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  22737. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  22738. [4, twoDimPass], [4, twoDimPass],
  22739. [4, twoDimPass], [4, twoDimPass],
  22740. [4, twoDimPass], [4, twoDimPass],
  22741. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  22742. [3, twoDimHoriz], [3, twoDimHoriz],
  22743. [3, twoDimHoriz], [3, twoDimHoriz],
  22744. [3, twoDimHoriz], [3, twoDimHoriz],
  22745. [3, twoDimHoriz], [3, twoDimHoriz],
  22746. [3, twoDimHoriz], [3, twoDimHoriz],
  22747. [3, twoDimHoriz], [3, twoDimHoriz],
  22748. [3, twoDimHoriz], [3, twoDimHoriz],
  22749. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  22750. [3, twoDimVertL1], [3, twoDimVertL1],
  22751. [3, twoDimVertL1], [3, twoDimVertL1],
  22752. [3, twoDimVertL1], [3, twoDimVertL1],
  22753. [3, twoDimVertL1], [3, twoDimVertL1],
  22754. [3, twoDimVertL1], [3, twoDimVertL1],
  22755. [3, twoDimVertL1], [3, twoDimVertL1],
  22756. [3, twoDimVertL1], [3, twoDimVertL1],
  22757. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  22758. [3, twoDimVertR1], [3, twoDimVertR1],
  22759. [3, twoDimVertR1], [3, twoDimVertR1],
  22760. [3, twoDimVertR1], [3, twoDimVertR1],
  22761. [3, twoDimVertR1], [3, twoDimVertR1],
  22762. [3, twoDimVertR1], [3, twoDimVertR1],
  22763. [3, twoDimVertR1], [3, twoDimVertR1],
  22764. [3, twoDimVertR1], [3, twoDimVertR1],
  22765. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  22766. [1, twoDimVert0], [1, twoDimVert0],
  22767. [1, twoDimVert0], [1, twoDimVert0],
  22768. [1, twoDimVert0], [1, twoDimVert0],
  22769. [1, twoDimVert0], [1, twoDimVert0],
  22770. [1, twoDimVert0], [1, twoDimVert0],
  22771. [1, twoDimVert0], [1, twoDimVert0],
  22772. [1, twoDimVert0], [1, twoDimVert0],
  22773. [1, twoDimVert0], [1, twoDimVert0],
  22774. [1, twoDimVert0], [1, twoDimVert0],
  22775. [1, twoDimVert0], [1, twoDimVert0],
  22776. [1, twoDimVert0], [1, twoDimVert0],
  22777. [1, twoDimVert0], [1, twoDimVert0],
  22778. [1, twoDimVert0], [1, twoDimVert0],
  22779. [1, twoDimVert0], [1, twoDimVert0],
  22780. [1, twoDimVert0], [1, twoDimVert0],
  22781. [1, twoDimVert0], [1, twoDimVert0],
  22782. [1, twoDimVert0], [1, twoDimVert0],
  22783. [1, twoDimVert0], [1, twoDimVert0],
  22784. [1, twoDimVert0], [1, twoDimVert0],
  22785. [1, twoDimVert0], [1, twoDimVert0],
  22786. [1, twoDimVert0], [1, twoDimVert0],
  22787. [1, twoDimVert0], [1, twoDimVert0],
  22788. [1, twoDimVert0], [1, twoDimVert0],
  22789. [1, twoDimVert0], [1, twoDimVert0],
  22790. [1, twoDimVert0], [1, twoDimVert0],
  22791. [1, twoDimVert0], [1, twoDimVert0],
  22792. [1, twoDimVert0], [1, twoDimVert0],
  22793. [1, twoDimVert0], [1, twoDimVert0],
  22794. [1, twoDimVert0], [1, twoDimVert0],
  22795. [1, twoDimVert0], [1, twoDimVert0],
  22796. [1, twoDimVert0], [1, twoDimVert0]
  22797. ];
  22798. var whiteTable1 = [
  22799. [-1, -1], // 00000
  22800. [12, ccittEOL], // 00001
  22801. [-1, -1], [-1, -1], // 0001x
  22802. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  22803. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  22804. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  22805. [11, 1792], [11, 1792], // 1000x
  22806. [12, 1984], // 10010
  22807. [12, 2048], // 10011
  22808. [12, 2112], // 10100
  22809. [12, 2176], // 10101
  22810. [12, 2240], // 10110
  22811. [12, 2304], // 10111
  22812. [11, 1856], [11, 1856], // 1100x
  22813. [11, 1920], [11, 1920], // 1101x
  22814. [12, 2368], // 11100
  22815. [12, 2432], // 11101
  22816. [12, 2496], // 11110
  22817. [12, 2560] // 11111
  22818. ];
  22819. var whiteTable2 = [
  22820. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  22821. [8, 29], [8, 29], // 00000010x
  22822. [8, 30], [8, 30], // 00000011x
  22823. [8, 45], [8, 45], // 00000100x
  22824. [8, 46], [8, 46], // 00000101x
  22825. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  22826. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  22827. [8, 47], [8, 47], // 00001010x
  22828. [8, 48], [8, 48], // 00001011x
  22829. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  22830. [6, 13], [6, 13], [6, 13], [6, 13],
  22831. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  22832. [8, 33], [8, 33], // 00010010x
  22833. [8, 34], [8, 34], // 00010011x
  22834. [8, 35], [8, 35], // 00010100x
  22835. [8, 36], [8, 36], // 00010101x
  22836. [8, 37], [8, 37], // 00010110x
  22837. [8, 38], [8, 38], // 00010111x
  22838. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  22839. [8, 31], [8, 31], // 00011010x
  22840. [8, 32], [8, 32], // 00011011x
  22841. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  22842. [6, 1], [6, 1], [6, 1], [6, 1],
  22843. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  22844. [6, 12], [6, 12], [6, 12], [6, 12],
  22845. [8, 53], [8, 53], // 00100100x
  22846. [8, 54], [8, 54], // 00100101x
  22847. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  22848. [8, 39], [8, 39], // 00101000x
  22849. [8, 40], [8, 40], // 00101001x
  22850. [8, 41], [8, 41], // 00101010x
  22851. [8, 42], [8, 42], // 00101011x
  22852. [8, 43], [8, 43], // 00101100x
  22853. [8, 44], [8, 44], // 00101101x
  22854. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  22855. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  22856. [8, 61], [8, 61], // 00110010x
  22857. [8, 62], [8, 62], // 00110011x
  22858. [8, 63], [8, 63], // 00110100x
  22859. [8, 0], [8, 0], // 00110101x
  22860. [8, 320], [8, 320], // 00110110x
  22861. [8, 384], [8, 384], // 00110111x
  22862. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  22863. [5, 10], [5, 10], [5, 10], [5, 10],
  22864. [5, 10], [5, 10], [5, 10], [5, 10],
  22865. [5, 10], [5, 10], [5, 10], [5, 10],
  22866. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  22867. [5, 11], [5, 11], [5, 11], [5, 11],
  22868. [5, 11], [5, 11], [5, 11], [5, 11],
  22869. [5, 11], [5, 11], [5, 11], [5, 11],
  22870. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  22871. [8, 59], [8, 59], // 01001010x
  22872. [8, 60], [8, 60], // 01001011x
  22873. [9, 1472], // 010011000
  22874. [9, 1536], // 010011001
  22875. [9, 1600], // 010011010
  22876. [9, 1728], // 010011011
  22877. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  22878. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  22879. [8, 49], [8, 49], // 01010010x
  22880. [8, 50], [8, 50], // 01010011x
  22881. [8, 51], [8, 51], // 01010100x
  22882. [8, 52], [8, 52], // 01010101x
  22883. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  22884. [8, 55], [8, 55], // 01011000x
  22885. [8, 56], [8, 56], // 01011001x
  22886. [8, 57], [8, 57], // 01011010x
  22887. [8, 58], [8, 58], // 01011011x
  22888. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  22889. [6, 192], [6, 192], [6, 192], [6, 192],
  22890. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  22891. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  22892. [8, 448], [8, 448], // 01100100x
  22893. [8, 512], [8, 512], // 01100101x
  22894. [9, 704], // 011001100
  22895. [9, 768], // 011001101
  22896. [8, 640], [8, 640], // 01100111x
  22897. [8, 576], [8, 576], // 01101000x
  22898. [9, 832], // 011010010
  22899. [9, 896], // 011010011
  22900. [9, 960], // 011010100
  22901. [9, 1024], // 011010101
  22902. [9, 1088], // 011010110
  22903. [9, 1152], // 011010111
  22904. [9, 1216], // 011011000
  22905. [9, 1280], // 011011001
  22906. [9, 1344], // 011011010
  22907. [9, 1408], // 011011011
  22908. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  22909. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  22910. [4, 2], [4, 2], [4, 2], [4, 2],
  22911. [4, 2], [4, 2], [4, 2], [4, 2],
  22912. [4, 2], [4, 2], [4, 2], [4, 2],
  22913. [4, 2], [4, 2], [4, 2], [4, 2],
  22914. [4, 2], [4, 2], [4, 2], [4, 2],
  22915. [4, 2], [4, 2], [4, 2], [4, 2],
  22916. [4, 2], [4, 2], [4, 2], [4, 2],
  22917. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  22918. [4, 3], [4, 3], [4, 3], [4, 3],
  22919. [4, 3], [4, 3], [4, 3], [4, 3],
  22920. [4, 3], [4, 3], [4, 3], [4, 3],
  22921. [4, 3], [4, 3], [4, 3], [4, 3],
  22922. [4, 3], [4, 3], [4, 3], [4, 3],
  22923. [4, 3], [4, 3], [4, 3], [4, 3],
  22924. [4, 3], [4, 3], [4, 3], [4, 3],
  22925. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  22926. [5, 128], [5, 128], [5, 128], [5, 128],
  22927. [5, 128], [5, 128], [5, 128], [5, 128],
  22928. [5, 128], [5, 128], [5, 128], [5, 128],
  22929. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  22930. [5, 8], [5, 8], [5, 8], [5, 8],
  22931. [5, 8], [5, 8], [5, 8], [5, 8],
  22932. [5, 8], [5, 8], [5, 8], [5, 8],
  22933. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  22934. [5, 9], [5, 9], [5, 9], [5, 9],
  22935. [5, 9], [5, 9], [5, 9], [5, 9],
  22936. [5, 9], [5, 9], [5, 9], [5, 9],
  22937. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  22938. [6, 16], [6, 16], [6, 16], [6, 16],
  22939. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  22940. [6, 17], [6, 17], [6, 17], [6, 17],
  22941. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  22942. [4, 4], [4, 4], [4, 4], [4, 4],
  22943. [4, 4], [4, 4], [4, 4], [4, 4],
  22944. [4, 4], [4, 4], [4, 4], [4, 4],
  22945. [4, 4], [4, 4], [4, 4], [4, 4],
  22946. [4, 4], [4, 4], [4, 4], [4, 4],
  22947. [4, 4], [4, 4], [4, 4], [4, 4],
  22948. [4, 4], [4, 4], [4, 4], [4, 4],
  22949. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  22950. [4, 5], [4, 5], [4, 5], [4, 5],
  22951. [4, 5], [4, 5], [4, 5], [4, 5],
  22952. [4, 5], [4, 5], [4, 5], [4, 5],
  22953. [4, 5], [4, 5], [4, 5], [4, 5],
  22954. [4, 5], [4, 5], [4, 5], [4, 5],
  22955. [4, 5], [4, 5], [4, 5], [4, 5],
  22956. [4, 5], [4, 5], [4, 5], [4, 5],
  22957. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  22958. [6, 14], [6, 14], [6, 14], [6, 14],
  22959. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  22960. [6, 15], [6, 15], [6, 15], [6, 15],
  22961. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  22962. [5, 64], [5, 64], [5, 64], [5, 64],
  22963. [5, 64], [5, 64], [5, 64], [5, 64],
  22964. [5, 64], [5, 64], [5, 64], [5, 64],
  22965. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  22966. [4, 6], [4, 6], [4, 6], [4, 6],
  22967. [4, 6], [4, 6], [4, 6], [4, 6],
  22968. [4, 6], [4, 6], [4, 6], [4, 6],
  22969. [4, 6], [4, 6], [4, 6], [4, 6],
  22970. [4, 6], [4, 6], [4, 6], [4, 6],
  22971. [4, 6], [4, 6], [4, 6], [4, 6],
  22972. [4, 6], [4, 6], [4, 6], [4, 6],
  22973. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  22974. [4, 7], [4, 7], [4, 7], [4, 7],
  22975. [4, 7], [4, 7], [4, 7], [4, 7],
  22976. [4, 7], [4, 7], [4, 7], [4, 7],
  22977. [4, 7], [4, 7], [4, 7], [4, 7],
  22978. [4, 7], [4, 7], [4, 7], [4, 7],
  22979. [4, 7], [4, 7], [4, 7], [4, 7],
  22980. [4, 7], [4, 7], [4, 7], [4, 7]
  22981. ];
  22982. var blackTable1 = [
  22983. [-1, -1], [-1, -1], // 000000000000x
  22984. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  22985. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  22986. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  22987. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  22988. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  22989. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  22990. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  22991. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  22992. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  22993. [12, 1984], [12, 1984], // 000000010010x
  22994. [12, 2048], [12, 2048], // 000000010011x
  22995. [12, 2112], [12, 2112], // 000000010100x
  22996. [12, 2176], [12, 2176], // 000000010101x
  22997. [12, 2240], [12, 2240], // 000000010110x
  22998. [12, 2304], [12, 2304], // 000000010111x
  22999. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  23000. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  23001. [12, 2368], [12, 2368], // 000000011100x
  23002. [12, 2432], [12, 2432], // 000000011101x
  23003. [12, 2496], [12, 2496], // 000000011110x
  23004. [12, 2560], [12, 2560], // 000000011111x
  23005. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  23006. [10, 18], [10, 18], [10, 18], [10, 18],
  23007. [12, 52], [12, 52], // 000000100100x
  23008. [13, 640], // 0000001001010
  23009. [13, 704], // 0000001001011
  23010. [13, 768], // 0000001001100
  23011. [13, 832], // 0000001001101
  23012. [12, 55], [12, 55], // 000000100111x
  23013. [12, 56], [12, 56], // 000000101000x
  23014. [13, 1280], // 0000001010010
  23015. [13, 1344], // 0000001010011
  23016. [13, 1408], // 0000001010100
  23017. [13, 1472], // 0000001010101
  23018. [12, 59], [12, 59], // 000000101011x
  23019. [12, 60], [12, 60], // 000000101100x
  23020. [13, 1536], // 0000001011010
  23021. [13, 1600], // 0000001011011
  23022. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  23023. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  23024. [13, 1664], // 0000001100100
  23025. [13, 1728], // 0000001100101
  23026. [12, 320], [12, 320], // 000000110011x
  23027. [12, 384], [12, 384], // 000000110100x
  23028. [12, 448], [12, 448], // 000000110101x
  23029. [13, 512], // 0000001101100
  23030. [13, 576], // 0000001101101
  23031. [12, 53], [12, 53], // 000000110111x
  23032. [12, 54], [12, 54], // 000000111000x
  23033. [13, 896], // 0000001110010
  23034. [13, 960], // 0000001110011
  23035. [13, 1024], // 0000001110100
  23036. [13, 1088], // 0000001110101
  23037. [13, 1152], // 0000001110110
  23038. [13, 1216], // 0000001110111
  23039. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  23040. [10, 64], [10, 64], [10, 64], [10, 64]
  23041. ];
  23042. var blackTable2 = [
  23043. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  23044. [8, 13], [8, 13], [8, 13], [8, 13],
  23045. [8, 13], [8, 13], [8, 13], [8, 13],
  23046. [8, 13], [8, 13], [8, 13], [8, 13],
  23047. [11, 23], [11, 23], // 00000101000x
  23048. [12, 50], // 000001010010
  23049. [12, 51], // 000001010011
  23050. [12, 44], // 000001010100
  23051. [12, 45], // 000001010101
  23052. [12, 46], // 000001010110
  23053. [12, 47], // 000001010111
  23054. [12, 57], // 000001011000
  23055. [12, 58], // 000001011001
  23056. [12, 61], // 000001011010
  23057. [12, 256], // 000001011011
  23058. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  23059. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  23060. [12, 48], // 000001100100
  23061. [12, 49], // 000001100101
  23062. [12, 62], // 000001100110
  23063. [12, 63], // 000001100111
  23064. [12, 30], // 000001101000
  23065. [12, 31], // 000001101001
  23066. [12, 32], // 000001101010
  23067. [12, 33], // 000001101011
  23068. [12, 40], // 000001101100
  23069. [12, 41], // 000001101101
  23070. [11, 22], [11, 22], // 00000110111x
  23071. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  23072. [8, 14], [8, 14], [8, 14], [8, 14],
  23073. [8, 14], [8, 14], [8, 14], [8, 14],
  23074. [8, 14], [8, 14], [8, 14], [8, 14],
  23075. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  23076. [7, 10], [7, 10], [7, 10], [7, 10],
  23077. [7, 10], [7, 10], [7, 10], [7, 10],
  23078. [7, 10], [7, 10], [7, 10], [7, 10],
  23079. [7, 10], [7, 10], [7, 10], [7, 10],
  23080. [7, 10], [7, 10], [7, 10], [7, 10],
  23081. [7, 10], [7, 10], [7, 10], [7, 10],
  23082. [7, 10], [7, 10], [7, 10], [7, 10],
  23083. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  23084. [7, 11], [7, 11], [7, 11], [7, 11],
  23085. [7, 11], [7, 11], [7, 11], [7, 11],
  23086. [7, 11], [7, 11], [7, 11], [7, 11],
  23087. [7, 11], [7, 11], [7, 11], [7, 11],
  23088. [7, 11], [7, 11], [7, 11], [7, 11],
  23089. [7, 11], [7, 11], [7, 11], [7, 11],
  23090. [7, 11], [7, 11], [7, 11], [7, 11],
  23091. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  23092. [9, 15], [9, 15], [9, 15], [9, 15],
  23093. [12, 128], // 000011001000
  23094. [12, 192], // 000011001001
  23095. [12, 26], // 000011001010
  23096. [12, 27], // 000011001011
  23097. [12, 28], // 000011001100
  23098. [12, 29], // 000011001101
  23099. [11, 19], [11, 19], // 00001100111x
  23100. [11, 20], [11, 20], // 00001101000x
  23101. [12, 34], // 000011010010
  23102. [12, 35], // 000011010011
  23103. [12, 36], // 000011010100
  23104. [12, 37], // 000011010101
  23105. [12, 38], // 000011010110
  23106. [12, 39], // 000011010111
  23107. [11, 21], [11, 21], // 00001101100x
  23108. [12, 42], // 000011011010
  23109. [12, 43], // 000011011011
  23110. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  23111. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  23112. [7, 12], [7, 12], [7, 12], [7, 12],
  23113. [7, 12], [7, 12], [7, 12], [7, 12],
  23114. [7, 12], [7, 12], [7, 12], [7, 12],
  23115. [7, 12], [7, 12], [7, 12], [7, 12],
  23116. [7, 12], [7, 12], [7, 12], [7, 12],
  23117. [7, 12], [7, 12], [7, 12], [7, 12],
  23118. [7, 12], [7, 12], [7, 12], [7, 12]
  23119. ];
  23120. var blackTable3 = [
  23121. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  23122. [6, 9], // 000100
  23123. [6, 8], // 000101
  23124. [5, 7], [5, 7], // 00011x
  23125. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  23126. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  23127. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  23128. [3, 1], [3, 1], [3, 1], [3, 1],
  23129. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  23130. [3, 4], [3, 4], [3, 4], [3, 4],
  23131. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  23132. [2, 3], [2, 3], [2, 3], [2, 3],
  23133. [2, 3], [2, 3], [2, 3], [2, 3],
  23134. [2, 3], [2, 3], [2, 3], [2, 3],
  23135. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  23136. [2, 2], [2, 2], [2, 2], [2, 2],
  23137. [2, 2], [2, 2], [2, 2], [2, 2],
  23138. [2, 2], [2, 2], [2, 2], [2, 2]
  23139. ];
  23140. function CCITTFaxStream(str, maybeLength, params) {
  23141. this.str = str;
  23142. this.dict = str.dict;
  23143. params = params || Dict.empty;
  23144. this.encoding = params.get('K') || 0;
  23145. this.eoline = params.get('EndOfLine') || false;
  23146. this.byteAlign = params.get('EncodedByteAlign') || false;
  23147. this.columns = params.get('Columns') || 1728;
  23148. this.rows = params.get('Rows') || 0;
  23149. var eoblock = params.get('EndOfBlock');
  23150. if (eoblock === null || eoblock === undefined) {
  23151. eoblock = true;
  23152. }
  23153. this.eoblock = eoblock;
  23154. this.black = params.get('BlackIs1') || false;
  23155. this.codingLine = new Uint32Array(this.columns + 1);
  23156. this.refLine = new Uint32Array(this.columns + 2);
  23157. this.codingLine[0] = this.columns;
  23158. this.codingPos = 0;
  23159. this.row = 0;
  23160. this.nextLine2D = this.encoding < 0;
  23161. this.inputBits = 0;
  23162. this.inputBuf = 0;
  23163. this.outputBits = 0;
  23164. var code1;
  23165. while ((code1 = this.lookBits(12)) === 0) {
  23166. this.eatBits(1);
  23167. }
  23168. if (code1 === 1) {
  23169. this.eatBits(12);
  23170. }
  23171. if (this.encoding > 0) {
  23172. this.nextLine2D = !this.lookBits(1);
  23173. this.eatBits(1);
  23174. }
  23175. DecodeStream.call(this, maybeLength);
  23176. }
  23177. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  23178. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  23179. while (!this.eof) {
  23180. var c = this.lookChar();
  23181. this.ensureBuffer(this.bufferLength + 1);
  23182. this.buffer[this.bufferLength++] = c;
  23183. }
  23184. };
  23185. CCITTFaxStream.prototype.addPixels =
  23186. function ccittFaxStreamAddPixels(a1, blackPixels) {
  23187. var codingLine = this.codingLine;
  23188. var codingPos = this.codingPos;
  23189. if (a1 > codingLine[codingPos]) {
  23190. if (a1 > this.columns) {
  23191. info('row is wrong length');
  23192. this.err = true;
  23193. a1 = this.columns;
  23194. }
  23195. if ((codingPos & 1) ^ blackPixels) {
  23196. ++codingPos;
  23197. }
  23198. codingLine[codingPos] = a1;
  23199. }
  23200. this.codingPos = codingPos;
  23201. };
  23202. CCITTFaxStream.prototype.addPixelsNeg =
  23203. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  23204. var codingLine = this.codingLine;
  23205. var codingPos = this.codingPos;
  23206. if (a1 > codingLine[codingPos]) {
  23207. if (a1 > this.columns) {
  23208. info('row is wrong length');
  23209. this.err = true;
  23210. a1 = this.columns;
  23211. }
  23212. if ((codingPos & 1) ^ blackPixels) {
  23213. ++codingPos;
  23214. }
  23215. codingLine[codingPos] = a1;
  23216. } else if (a1 < codingLine[codingPos]) {
  23217. if (a1 < 0) {
  23218. info('invalid code');
  23219. this.err = true;
  23220. a1 = 0;
  23221. }
  23222. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  23223. --codingPos;
  23224. }
  23225. codingLine[codingPos] = a1;
  23226. }
  23227. this.codingPos = codingPos;
  23228. };
  23229. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  23230. var refLine = this.refLine;
  23231. var codingLine = this.codingLine;
  23232. var columns = this.columns;
  23233. var refPos, blackPixels, bits, i;
  23234. if (this.outputBits === 0) {
  23235. if (this.eof) {
  23236. return null;
  23237. }
  23238. this.err = false;
  23239. var code1, code2, code3;
  23240. if (this.nextLine2D) {
  23241. for (i = 0; codingLine[i] < columns; ++i) {
  23242. refLine[i] = codingLine[i];
  23243. }
  23244. refLine[i++] = columns;
  23245. refLine[i] = columns;
  23246. codingLine[0] = 0;
  23247. this.codingPos = 0;
  23248. refPos = 0;
  23249. blackPixels = 0;
  23250. while (codingLine[this.codingPos] < columns) {
  23251. code1 = this.getTwoDimCode();
  23252. switch (code1) {
  23253. case twoDimPass:
  23254. this.addPixels(refLine[refPos + 1], blackPixels);
  23255. if (refLine[refPos + 1] < columns) {
  23256. refPos += 2;
  23257. }
  23258. break;
  23259. case twoDimHoriz:
  23260. code1 = code2 = 0;
  23261. if (blackPixels) {
  23262. do {
  23263. code1 += (code3 = this.getBlackCode());
  23264. } while (code3 >= 64);
  23265. do {
  23266. code2 += (code3 = this.getWhiteCode());
  23267. } while (code3 >= 64);
  23268. } else {
  23269. do {
  23270. code1 += (code3 = this.getWhiteCode());
  23271. } while (code3 >= 64);
  23272. do {
  23273. code2 += (code3 = this.getBlackCode());
  23274. } while (code3 >= 64);
  23275. }
  23276. this.addPixels(codingLine[this.codingPos] +
  23277. code1, blackPixels);
  23278. if (codingLine[this.codingPos] < columns) {
  23279. this.addPixels(codingLine[this.codingPos] + code2,
  23280. blackPixels ^ 1);
  23281. }
  23282. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23283. refLine[refPos] < columns) {
  23284. refPos += 2;
  23285. }
  23286. break;
  23287. case twoDimVertR3:
  23288. this.addPixels(refLine[refPos] + 3, blackPixels);
  23289. blackPixels ^= 1;
  23290. if (codingLine[this.codingPos] < columns) {
  23291. ++refPos;
  23292. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23293. refLine[refPos] < columns) {
  23294. refPos += 2;
  23295. }
  23296. }
  23297. break;
  23298. case twoDimVertR2:
  23299. this.addPixels(refLine[refPos] + 2, blackPixels);
  23300. blackPixels ^= 1;
  23301. if (codingLine[this.codingPos] < columns) {
  23302. ++refPos;
  23303. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23304. refLine[refPos] < columns) {
  23305. refPos += 2;
  23306. }
  23307. }
  23308. break;
  23309. case twoDimVertR1:
  23310. this.addPixels(refLine[refPos] + 1, blackPixels);
  23311. blackPixels ^= 1;
  23312. if (codingLine[this.codingPos] < columns) {
  23313. ++refPos;
  23314. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23315. refLine[refPos] < columns) {
  23316. refPos += 2;
  23317. }
  23318. }
  23319. break;
  23320. case twoDimVert0:
  23321. this.addPixels(refLine[refPos], blackPixels);
  23322. blackPixels ^= 1;
  23323. if (codingLine[this.codingPos] < columns) {
  23324. ++refPos;
  23325. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23326. refLine[refPos] < columns) {
  23327. refPos += 2;
  23328. }
  23329. }
  23330. break;
  23331. case twoDimVertL3:
  23332. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  23333. blackPixels ^= 1;
  23334. if (codingLine[this.codingPos] < columns) {
  23335. if (refPos > 0) {
  23336. --refPos;
  23337. } else {
  23338. ++refPos;
  23339. }
  23340. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23341. refLine[refPos] < columns) {
  23342. refPos += 2;
  23343. }
  23344. }
  23345. break;
  23346. case twoDimVertL2:
  23347. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  23348. blackPixels ^= 1;
  23349. if (codingLine[this.codingPos] < columns) {
  23350. if (refPos > 0) {
  23351. --refPos;
  23352. } else {
  23353. ++refPos;
  23354. }
  23355. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23356. refLine[refPos] < columns) {
  23357. refPos += 2;
  23358. }
  23359. }
  23360. break;
  23361. case twoDimVertL1:
  23362. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  23363. blackPixels ^= 1;
  23364. if (codingLine[this.codingPos] < columns) {
  23365. if (refPos > 0) {
  23366. --refPos;
  23367. } else {
  23368. ++refPos;
  23369. }
  23370. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23371. refLine[refPos] < columns) {
  23372. refPos += 2;
  23373. }
  23374. }
  23375. break;
  23376. case EOF:
  23377. this.addPixels(columns, 0);
  23378. this.eof = true;
  23379. break;
  23380. default:
  23381. info('bad 2d code');
  23382. this.addPixels(columns, 0);
  23383. this.err = true;
  23384. }
  23385. }
  23386. } else {
  23387. codingLine[0] = 0;
  23388. this.codingPos = 0;
  23389. blackPixels = 0;
  23390. while (codingLine[this.codingPos] < columns) {
  23391. code1 = 0;
  23392. if (blackPixels) {
  23393. do {
  23394. code1 += (code3 = this.getBlackCode());
  23395. } while (code3 >= 64);
  23396. } else {
  23397. do {
  23398. code1 += (code3 = this.getWhiteCode());
  23399. } while (code3 >= 64);
  23400. }
  23401. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  23402. blackPixels ^= 1;
  23403. }
  23404. }
  23405. var gotEOL = false;
  23406. if (this.byteAlign) {
  23407. this.inputBits &= ~7;
  23408. }
  23409. if (!this.eoblock && this.row === this.rows - 1) {
  23410. this.eof = true;
  23411. } else {
  23412. code1 = this.lookBits(12);
  23413. if (this.eoline) {
  23414. while (code1 !== EOF && code1 !== 1) {
  23415. this.eatBits(1);
  23416. code1 = this.lookBits(12);
  23417. }
  23418. } else {
  23419. while (code1 === 0) {
  23420. this.eatBits(1);
  23421. code1 = this.lookBits(12);
  23422. }
  23423. }
  23424. if (code1 === 1) {
  23425. this.eatBits(12);
  23426. gotEOL = true;
  23427. } else if (code1 === EOF) {
  23428. this.eof = true;
  23429. }
  23430. }
  23431. if (!this.eof && this.encoding > 0) {
  23432. this.nextLine2D = !this.lookBits(1);
  23433. this.eatBits(1);
  23434. }
  23435. if (this.eoblock && gotEOL && this.byteAlign) {
  23436. code1 = this.lookBits(12);
  23437. if (code1 === 1) {
  23438. this.eatBits(12);
  23439. if (this.encoding > 0) {
  23440. this.lookBits(1);
  23441. this.eatBits(1);
  23442. }
  23443. if (this.encoding >= 0) {
  23444. for (i = 0; i < 4; ++i) {
  23445. code1 = this.lookBits(12);
  23446. if (code1 !== 1) {
  23447. info('bad rtc code: ' + code1);
  23448. }
  23449. this.eatBits(12);
  23450. if (this.encoding > 0) {
  23451. this.lookBits(1);
  23452. this.eatBits(1);
  23453. }
  23454. }
  23455. }
  23456. this.eof = true;
  23457. }
  23458. } else if (this.err && this.eoline) {
  23459. while (true) {
  23460. code1 = this.lookBits(13);
  23461. if (code1 === EOF) {
  23462. this.eof = true;
  23463. return null;
  23464. }
  23465. if ((code1 >> 1) === 1) {
  23466. break;
  23467. }
  23468. this.eatBits(1);
  23469. }
  23470. this.eatBits(12);
  23471. if (this.encoding > 0) {
  23472. this.eatBits(1);
  23473. this.nextLine2D = !(code1 & 1);
  23474. }
  23475. }
  23476. if (codingLine[0] > 0) {
  23477. this.outputBits = codingLine[this.codingPos = 0];
  23478. } else {
  23479. this.outputBits = codingLine[this.codingPos = 1];
  23480. }
  23481. this.row++;
  23482. }
  23483. var c;
  23484. if (this.outputBits >= 8) {
  23485. c = (this.codingPos & 1) ? 0 : 0xFF;
  23486. this.outputBits -= 8;
  23487. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  23488. this.codingPos++;
  23489. this.outputBits = (codingLine[this.codingPos] -
  23490. codingLine[this.codingPos - 1]);
  23491. }
  23492. } else {
  23493. bits = 8;
  23494. c = 0;
  23495. do {
  23496. if (this.outputBits > bits) {
  23497. c <<= bits;
  23498. if (!(this.codingPos & 1)) {
  23499. c |= 0xFF >> (8 - bits);
  23500. }
  23501. this.outputBits -= bits;
  23502. bits = 0;
  23503. } else {
  23504. c <<= this.outputBits;
  23505. if (!(this.codingPos & 1)) {
  23506. c |= 0xFF >> (8 - this.outputBits);
  23507. }
  23508. bits -= this.outputBits;
  23509. this.outputBits = 0;
  23510. if (codingLine[this.codingPos] < columns) {
  23511. this.codingPos++;
  23512. this.outputBits = (codingLine[this.codingPos] -
  23513. codingLine[this.codingPos - 1]);
  23514. } else if (bits > 0) {
  23515. c <<= bits;
  23516. bits = 0;
  23517. }
  23518. }
  23519. } while (bits);
  23520. }
  23521. if (this.black) {
  23522. c ^= 0xFF;
  23523. }
  23524. return c;
  23525. };
  23526. // This functions returns the code found from the table.
  23527. // The start and end parameters set the boundaries for searching the table.
  23528. // The limit parameter is optional. Function returns an array with three
  23529. // values. The first array element indicates whether a valid code is being
  23530. // returned. The second array element is the actual code. The third array
  23531. // element indicates whether EOF was reached.
  23532. CCITTFaxStream.prototype.findTableCode =
  23533. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  23534. var limitValue = limit || 0;
  23535. for (var i = start; i <= end; ++i) {
  23536. var code = this.lookBits(i);
  23537. if (code === EOF) {
  23538. return [true, 1, false];
  23539. }
  23540. if (i < end) {
  23541. code <<= end - i;
  23542. }
  23543. if (!limitValue || code >= limitValue) {
  23544. var p = table[code - limitValue];
  23545. if (p[0] === i) {
  23546. this.eatBits(i);
  23547. return [true, p[1], true];
  23548. }
  23549. }
  23550. }
  23551. return [false, 0, false];
  23552. };
  23553. CCITTFaxStream.prototype.getTwoDimCode =
  23554. function ccittFaxStreamGetTwoDimCode() {
  23555. var code = 0;
  23556. var p;
  23557. if (this.eoblock) {
  23558. code = this.lookBits(7);
  23559. p = twoDimTable[code];
  23560. if (p && p[0] > 0) {
  23561. this.eatBits(p[0]);
  23562. return p[1];
  23563. }
  23564. } else {
  23565. var result = this.findTableCode(1, 7, twoDimTable);
  23566. if (result[0] && result[2]) {
  23567. return result[1];
  23568. }
  23569. }
  23570. info('Bad two dim code');
  23571. return EOF;
  23572. };
  23573. CCITTFaxStream.prototype.getWhiteCode =
  23574. function ccittFaxStreamGetWhiteCode() {
  23575. var code = 0;
  23576. var p;
  23577. if (this.eoblock) {
  23578. code = this.lookBits(12);
  23579. if (code === EOF) {
  23580. return 1;
  23581. }
  23582. if ((code >> 5) === 0) {
  23583. p = whiteTable1[code];
  23584. } else {
  23585. p = whiteTable2[code >> 3];
  23586. }
  23587. if (p[0] > 0) {
  23588. this.eatBits(p[0]);
  23589. return p[1];
  23590. }
  23591. } else {
  23592. var result = this.findTableCode(1, 9, whiteTable2);
  23593. if (result[0]) {
  23594. return result[1];
  23595. }
  23596. result = this.findTableCode(11, 12, whiteTable1);
  23597. if (result[0]) {
  23598. return result[1];
  23599. }
  23600. }
  23601. info('bad white code');
  23602. this.eatBits(1);
  23603. return 1;
  23604. };
  23605. CCITTFaxStream.prototype.getBlackCode =
  23606. function ccittFaxStreamGetBlackCode() {
  23607. var code, p;
  23608. if (this.eoblock) {
  23609. code = this.lookBits(13);
  23610. if (code === EOF) {
  23611. return 1;
  23612. }
  23613. if ((code >> 7) === 0) {
  23614. p = blackTable1[code];
  23615. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  23616. p = blackTable2[(code >> 1) - 64];
  23617. } else {
  23618. p = blackTable3[code >> 7];
  23619. }
  23620. if (p[0] > 0) {
  23621. this.eatBits(p[0]);
  23622. return p[1];
  23623. }
  23624. } else {
  23625. var result = this.findTableCode(2, 6, blackTable3);
  23626. if (result[0]) {
  23627. return result[1];
  23628. }
  23629. result = this.findTableCode(7, 12, blackTable2, 64);
  23630. if (result[0]) {
  23631. return result[1];
  23632. }
  23633. result = this.findTableCode(10, 13, blackTable1);
  23634. if (result[0]) {
  23635. return result[1];
  23636. }
  23637. }
  23638. info('bad black code');
  23639. this.eatBits(1);
  23640. return 1;
  23641. };
  23642. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  23643. var c;
  23644. while (this.inputBits < n) {
  23645. if ((c = this.str.getByte()) === -1) {
  23646. if (this.inputBits === 0) {
  23647. return EOF;
  23648. }
  23649. return ((this.inputBuf << (n - this.inputBits)) &
  23650. (0xFFFF >> (16 - n)));
  23651. }
  23652. this.inputBuf = (this.inputBuf << 8) + c;
  23653. this.inputBits += 8;
  23654. }
  23655. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  23656. };
  23657. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  23658. if ((this.inputBits -= n) < 0) {
  23659. this.inputBits = 0;
  23660. }
  23661. };
  23662. return CCITTFaxStream;
  23663. })();
  23664. var LZWStream = (function LZWStreamClosure() {
  23665. function LZWStream(str, maybeLength, earlyChange) {
  23666. this.str = str;
  23667. this.dict = str.dict;
  23668. this.cachedData = 0;
  23669. this.bitsCached = 0;
  23670. var maxLzwDictionarySize = 4096;
  23671. var lzwState = {
  23672. earlyChange: earlyChange,
  23673. codeLength: 9,
  23674. nextCode: 258,
  23675. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  23676. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  23677. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  23678. currentSequence: new Uint8Array(maxLzwDictionarySize),
  23679. currentSequenceLength: 0
  23680. };
  23681. for (var i = 0; i < 256; ++i) {
  23682. lzwState.dictionaryValues[i] = i;
  23683. lzwState.dictionaryLengths[i] = 1;
  23684. }
  23685. this.lzwState = lzwState;
  23686. DecodeStream.call(this, maybeLength);
  23687. }
  23688. LZWStream.prototype = Object.create(DecodeStream.prototype);
  23689. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  23690. var bitsCached = this.bitsCached;
  23691. var cachedData = this.cachedData;
  23692. while (bitsCached < n) {
  23693. var c = this.str.getByte();
  23694. if (c === -1) {
  23695. this.eof = true;
  23696. return null;
  23697. }
  23698. cachedData = (cachedData << 8) | c;
  23699. bitsCached += 8;
  23700. }
  23701. this.bitsCached = (bitsCached -= n);
  23702. this.cachedData = cachedData;
  23703. this.lastCode = null;
  23704. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  23705. };
  23706. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  23707. var blockSize = 512;
  23708. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  23709. var i, j, q;
  23710. var lzwState = this.lzwState;
  23711. if (!lzwState) {
  23712. return; // eof was found
  23713. }
  23714. var earlyChange = lzwState.earlyChange;
  23715. var nextCode = lzwState.nextCode;
  23716. var dictionaryValues = lzwState.dictionaryValues;
  23717. var dictionaryLengths = lzwState.dictionaryLengths;
  23718. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  23719. var codeLength = lzwState.codeLength;
  23720. var prevCode = lzwState.prevCode;
  23721. var currentSequence = lzwState.currentSequence;
  23722. var currentSequenceLength = lzwState.currentSequenceLength;
  23723. var decodedLength = 0;
  23724. var currentBufferLength = this.bufferLength;
  23725. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  23726. for (i = 0; i < blockSize; i++) {
  23727. var code = this.readBits(codeLength);
  23728. var hasPrev = currentSequenceLength > 0;
  23729. if (code < 256) {
  23730. currentSequence[0] = code;
  23731. currentSequenceLength = 1;
  23732. } else if (code >= 258) {
  23733. if (code < nextCode) {
  23734. currentSequenceLength = dictionaryLengths[code];
  23735. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  23736. currentSequence[j] = dictionaryValues[q];
  23737. q = dictionaryPrevCodes[q];
  23738. }
  23739. } else {
  23740. currentSequence[currentSequenceLength++] = currentSequence[0];
  23741. }
  23742. } else if (code === 256) {
  23743. codeLength = 9;
  23744. nextCode = 258;
  23745. currentSequenceLength = 0;
  23746. continue;
  23747. } else {
  23748. this.eof = true;
  23749. delete this.lzwState;
  23750. break;
  23751. }
  23752. if (hasPrev) {
  23753. dictionaryPrevCodes[nextCode] = prevCode;
  23754. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  23755. dictionaryValues[nextCode] = currentSequence[0];
  23756. nextCode++;
  23757. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  23758. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  23759. 0.6931471805599453 + 1, 12) | 0;
  23760. }
  23761. prevCode = code;
  23762. decodedLength += currentSequenceLength;
  23763. if (estimatedDecodedSize < decodedLength) {
  23764. do {
  23765. estimatedDecodedSize += decodedSizeDelta;
  23766. } while (estimatedDecodedSize < decodedLength);
  23767. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  23768. }
  23769. for (j = 0; j < currentSequenceLength; j++) {
  23770. buffer[currentBufferLength++] = currentSequence[j];
  23771. }
  23772. }
  23773. lzwState.nextCode = nextCode;
  23774. lzwState.codeLength = codeLength;
  23775. lzwState.prevCode = prevCode;
  23776. lzwState.currentSequenceLength = currentSequenceLength;
  23777. this.bufferLength = currentBufferLength;
  23778. };
  23779. return LZWStream;
  23780. })();
  23781. var NullStream = (function NullStreamClosure() {
  23782. function NullStream() {
  23783. Stream.call(this, new Uint8Array(0));
  23784. }
  23785. NullStream.prototype = Stream.prototype;
  23786. return NullStream;
  23787. })();
  23788. // TODO refactor to remove dependency on parser.js
  23789. function _setCoreParser(coreParser_) {
  23790. coreParser = coreParser_;
  23791. EOF = coreParser_.EOF;
  23792. Lexer = coreParser_.Lexer;
  23793. }
  23794. exports._setCoreParser = _setCoreParser;
  23795. // TODO refactor to remove dependency on colorspace.js
  23796. function _setCoreColorSpace(coreColorSpace_) {
  23797. coreColorSpace = coreColorSpace_;
  23798. ColorSpace = coreColorSpace_.ColorSpace;
  23799. }
  23800. exports._setCoreColorSpace = _setCoreColorSpace;
  23801. exports.Ascii85Stream = Ascii85Stream;
  23802. exports.AsciiHexStream = AsciiHexStream;
  23803. exports.CCITTFaxStream = CCITTFaxStream;
  23804. exports.DecryptStream = DecryptStream;
  23805. exports.DecodeStream = DecodeStream;
  23806. exports.FlateStream = FlateStream;
  23807. exports.Jbig2Stream = Jbig2Stream;
  23808. exports.JpegStream = JpegStream;
  23809. exports.JpxStream = JpxStream;
  23810. exports.NullStream = NullStream;
  23811. exports.PredictorStream = PredictorStream;
  23812. exports.RunLengthStream = RunLengthStream;
  23813. exports.Stream = Stream;
  23814. exports.StreamsSequenceStream = StreamsSequenceStream;
  23815. exports.StringStream = StringStream;
  23816. exports.LZWStream = LZWStream;
  23817. }));
  23818. (function (root, factory) {
  23819. {
  23820. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  23821. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23822. }
  23823. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23824. var PasswordException = sharedUtil.PasswordException;
  23825. var PasswordResponses = sharedUtil.PasswordResponses;
  23826. var bytesToString = sharedUtil.bytesToString;
  23827. var error = sharedUtil.error;
  23828. var isInt = sharedUtil.isInt;
  23829. var stringToBytes = sharedUtil.stringToBytes;
  23830. var utf8StringToString = sharedUtil.utf8StringToString;
  23831. var warn = sharedUtil.warn;
  23832. var Name = corePrimitives.Name;
  23833. var isName = corePrimitives.isName;
  23834. var DecryptStream = coreStream.DecryptStream;
  23835. var ARCFourCipher = (function ARCFourCipherClosure() {
  23836. function ARCFourCipher(key) {
  23837. this.a = 0;
  23838. this.b = 0;
  23839. var s = new Uint8Array(256);
  23840. var i, j = 0, tmp, keyLength = key.length;
  23841. for (i = 0; i < 256; ++i) {
  23842. s[i] = i;
  23843. }
  23844. for (i = 0; i < 256; ++i) {
  23845. tmp = s[i];
  23846. j = (j + tmp + key[i % keyLength]) & 0xFF;
  23847. s[i] = s[j];
  23848. s[j] = tmp;
  23849. }
  23850. this.s = s;
  23851. }
  23852. ARCFourCipher.prototype = {
  23853. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  23854. var i, n = data.length, tmp, tmp2;
  23855. var a = this.a, b = this.b, s = this.s;
  23856. var output = new Uint8Array(n);
  23857. for (i = 0; i < n; ++i) {
  23858. a = (a + 1) & 0xFF;
  23859. tmp = s[a];
  23860. b = (b + tmp) & 0xFF;
  23861. tmp2 = s[b];
  23862. s[a] = tmp2;
  23863. s[b] = tmp;
  23864. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  23865. }
  23866. this.a = a;
  23867. this.b = b;
  23868. return output;
  23869. }
  23870. };
  23871. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  23872. return ARCFourCipher;
  23873. })();
  23874. var calculateMD5 = (function calculateMD5Closure() {
  23875. var r = new Uint8Array([
  23876. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  23877. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  23878. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  23879. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  23880. var k = new Int32Array([
  23881. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  23882. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  23883. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  23884. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  23885. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  23886. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  23887. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  23888. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  23889. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  23890. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  23891. -145523070, -1120210379, 718787259, -343485551]);
  23892. function hash(data, offset, length) {
  23893. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  23894. // pre-processing
  23895. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  23896. var padded = new Uint8Array(paddedLength);
  23897. var i, j, n;
  23898. for (i = 0; i < length; ++i) {
  23899. padded[i] = data[offset++];
  23900. }
  23901. padded[i++] = 0x80;
  23902. n = paddedLength - 8;
  23903. while (i < n) {
  23904. padded[i++] = 0;
  23905. }
  23906. padded[i++] = (length << 3) & 0xFF;
  23907. padded[i++] = (length >> 5) & 0xFF;
  23908. padded[i++] = (length >> 13) & 0xFF;
  23909. padded[i++] = (length >> 21) & 0xFF;
  23910. padded[i++] = (length >>> 29) & 0xFF;
  23911. padded[i++] = 0;
  23912. padded[i++] = 0;
  23913. padded[i++] = 0;
  23914. var w = new Int32Array(16);
  23915. for (i = 0; i < paddedLength;) {
  23916. for (j = 0; j < 16; ++j, i += 4) {
  23917. w[j] = (padded[i] | (padded[i + 1] << 8) |
  23918. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  23919. }
  23920. var a = h0, b = h1, c = h2, d = h3, f, g;
  23921. for (j = 0; j < 64; ++j) {
  23922. if (j < 16) {
  23923. f = (b & c) | ((~b) & d);
  23924. g = j;
  23925. } else if (j < 32) {
  23926. f = (d & b) | ((~d) & c);
  23927. g = (5 * j + 1) & 15;
  23928. } else if (j < 48) {
  23929. f = b ^ c ^ d;
  23930. g = (3 * j + 5) & 15;
  23931. } else {
  23932. f = c ^ (b | (~d));
  23933. g = (7 * j) & 15;
  23934. }
  23935. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  23936. d = c;
  23937. c = b;
  23938. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  23939. a = tmp;
  23940. }
  23941. h0 = (h0 + a) | 0;
  23942. h1 = (h1 + b) | 0;
  23943. h2 = (h2 + c) | 0;
  23944. h3 = (h3 + d) | 0;
  23945. }
  23946. return new Uint8Array([
  23947. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  23948. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  23949. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  23950. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  23951. ]);
  23952. }
  23953. return hash;
  23954. })();
  23955. var Word64 = (function Word64Closure() {
  23956. function Word64(highInteger, lowInteger) {
  23957. this.high = highInteger | 0;
  23958. this.low = lowInteger | 0;
  23959. }
  23960. Word64.prototype = {
  23961. and: function Word64_and(word) {
  23962. this.high &= word.high;
  23963. this.low &= word.low;
  23964. },
  23965. xor: function Word64_xor(word) {
  23966. this.high ^= word.high;
  23967. this.low ^= word.low;
  23968. },
  23969. or: function Word64_or(word) {
  23970. this.high |= word.high;
  23971. this.low |= word.low;
  23972. },
  23973. shiftRight: function Word64_shiftRight(places) {
  23974. if (places >= 32) {
  23975. this.low = (this.high >>> (places - 32)) | 0;
  23976. this.high = 0;
  23977. } else {
  23978. this.low = (this.low >>> places) | (this.high << (32 - places));
  23979. this.high = (this.high >>> places) | 0;
  23980. }
  23981. },
  23982. shiftLeft: function Word64_shiftLeft(places) {
  23983. if (places >= 32) {
  23984. this.high = this.low << (places - 32);
  23985. this.low = 0;
  23986. } else {
  23987. this.high = (this.high << places) | (this.low >>> (32 - places));
  23988. this.low = this.low << places;
  23989. }
  23990. },
  23991. rotateRight: function Word64_rotateRight(places) {
  23992. var low, high;
  23993. if (places & 32) {
  23994. high = this.low;
  23995. low = this.high;
  23996. } else {
  23997. low = this.low;
  23998. high = this.high;
  23999. }
  24000. places &= 31;
  24001. this.low = (low >>> places) | (high << (32 - places));
  24002. this.high = (high >>> places) | (low << (32 - places));
  24003. },
  24004. not: function Word64_not() {
  24005. this.high = ~this.high;
  24006. this.low = ~this.low;
  24007. },
  24008. add: function Word64_add(word) {
  24009. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  24010. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  24011. if (lowAdd > 0xFFFFFFFF) {
  24012. highAdd += 1;
  24013. }
  24014. this.low = lowAdd | 0;
  24015. this.high = highAdd | 0;
  24016. },
  24017. copyTo: function Word64_copyTo(bytes, offset) {
  24018. bytes[offset] = (this.high >>> 24) & 0xFF;
  24019. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  24020. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  24021. bytes[offset + 3] = this.high & 0xFF;
  24022. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  24023. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  24024. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  24025. bytes[offset + 7] = this.low & 0xFF;
  24026. },
  24027. assign: function Word64_assign(word) {
  24028. this.high = word.high;
  24029. this.low = word.low;
  24030. }
  24031. };
  24032. return Word64;
  24033. })();
  24034. var calculateSHA256 = (function calculateSHA256Closure() {
  24035. function rotr(x, n) {
  24036. return (x >>> n) | (x << 32 - n);
  24037. }
  24038. function ch(x, y, z) {
  24039. return (x & y) ^ (~x & z);
  24040. }
  24041. function maj(x, y, z) {
  24042. return (x & y) ^ (x & z) ^ (y & z);
  24043. }
  24044. function sigma(x) {
  24045. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  24046. }
  24047. function sigmaPrime(x) {
  24048. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  24049. }
  24050. function littleSigma(x) {
  24051. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  24052. }
  24053. function littleSigmaPrime(x) {
  24054. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  24055. }
  24056. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  24057. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  24058. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  24059. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  24060. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  24061. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  24062. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  24063. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  24064. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  24065. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  24066. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  24067. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  24068. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  24069. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  24070. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  24071. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  24072. function hash(data, offset, length) {
  24073. // initial hash values
  24074. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  24075. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  24076. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  24077. // pre-processing
  24078. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  24079. var padded = new Uint8Array(paddedLength);
  24080. var i, j, n;
  24081. for (i = 0; i < length; ++i) {
  24082. padded[i] = data[offset++];
  24083. }
  24084. padded[i++] = 0x80;
  24085. n = paddedLength - 8;
  24086. while (i < n) {
  24087. padded[i++] = 0;
  24088. }
  24089. padded[i++] = 0;
  24090. padded[i++] = 0;
  24091. padded[i++] = 0;
  24092. padded[i++] = (length >>> 29) & 0xFF;
  24093. padded[i++] = (length >> 21) & 0xFF;
  24094. padded[i++] = (length >> 13) & 0xFF;
  24095. padded[i++] = (length >> 5) & 0xFF;
  24096. padded[i++] = (length << 3) & 0xFF;
  24097. var w = new Uint32Array(64);
  24098. // for each 512 bit block
  24099. for (i = 0; i < paddedLength;) {
  24100. for (j = 0; j < 16; ++j) {
  24101. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  24102. (padded[i + 2] << 8) | (padded[i + 3]));
  24103. i += 4;
  24104. }
  24105. for (j = 16; j < 64; ++j) {
  24106. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  24107. littleSigma(w[j - 15]) + w[j - 16] | 0;
  24108. }
  24109. var a = h0, b = h1, c = h2, d = h3, e = h4,
  24110. f = h5, g = h6, h = h7, t1, t2;
  24111. for (j = 0; j < 64; ++j) {
  24112. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  24113. t2 = sigma(a) + maj(a, b, c);
  24114. h = g;
  24115. g = f;
  24116. f = e;
  24117. e = (d + t1) | 0;
  24118. d = c;
  24119. c = b;
  24120. b = a;
  24121. a = (t1 + t2) | 0;
  24122. }
  24123. h0 = (h0 + a) | 0;
  24124. h1 = (h1 + b) | 0;
  24125. h2 = (h2 + c) | 0;
  24126. h3 = (h3 + d) | 0;
  24127. h4 = (h4 + e) | 0;
  24128. h5 = (h5 + f) | 0;
  24129. h6 = (h6 + g) | 0;
  24130. h7 = (h7 + h) | 0;
  24131. }
  24132. return new Uint8Array([
  24133. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  24134. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  24135. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  24136. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  24137. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  24138. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  24139. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  24140. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  24141. ]);
  24142. }
  24143. return hash;
  24144. })();
  24145. var calculateSHA512 = (function calculateSHA512Closure() {
  24146. function ch(result, x, y, z, tmp) {
  24147. result.assign(x);
  24148. result.and(y);
  24149. tmp.assign(x);
  24150. tmp.not();
  24151. tmp.and(z);
  24152. result.xor(tmp);
  24153. }
  24154. function maj(result, x, y, z, tmp) {
  24155. result.assign(x);
  24156. result.and(y);
  24157. tmp.assign(x);
  24158. tmp.and(z);
  24159. result.xor(tmp);
  24160. tmp.assign(y);
  24161. tmp.and(z);
  24162. result.xor(tmp);
  24163. }
  24164. function sigma(result, x, tmp) {
  24165. result.assign(x);
  24166. result.rotateRight(28);
  24167. tmp.assign(x);
  24168. tmp.rotateRight(34);
  24169. result.xor(tmp);
  24170. tmp.assign(x);
  24171. tmp.rotateRight(39);
  24172. result.xor(tmp);
  24173. }
  24174. function sigmaPrime(result, x, tmp) {
  24175. result.assign(x);
  24176. result.rotateRight(14);
  24177. tmp.assign(x);
  24178. tmp.rotateRight(18);
  24179. result.xor(tmp);
  24180. tmp.assign(x);
  24181. tmp.rotateRight(41);
  24182. result.xor(tmp);
  24183. }
  24184. function littleSigma(result, x, tmp) {
  24185. result.assign(x);
  24186. result.rotateRight(1);
  24187. tmp.assign(x);
  24188. tmp.rotateRight(8);
  24189. result.xor(tmp);
  24190. tmp.assign(x);
  24191. tmp.shiftRight(7);
  24192. result.xor(tmp);
  24193. }
  24194. function littleSigmaPrime(result, x, tmp) {
  24195. result.assign(x);
  24196. result.rotateRight(19);
  24197. tmp.assign(x);
  24198. tmp.rotateRight(61);
  24199. result.xor(tmp);
  24200. tmp.assign(x);
  24201. tmp.shiftRight(6);
  24202. result.xor(tmp);
  24203. }
  24204. var k = [
  24205. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  24206. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  24207. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  24208. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  24209. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  24210. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  24211. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  24212. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  24213. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  24214. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  24215. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  24216. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  24217. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  24218. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  24219. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  24220. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  24221. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  24222. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  24223. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  24224. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  24225. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  24226. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  24227. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  24228. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  24229. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  24230. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  24231. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  24232. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  24233. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  24234. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  24235. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  24236. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  24237. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  24238. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  24239. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  24240. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  24241. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  24242. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  24243. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  24244. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  24245. function hash(data, offset, length, mode384) {
  24246. mode384 = !!mode384;
  24247. // initial hash values
  24248. var h0, h1, h2, h3, h4, h5, h6, h7;
  24249. if (!mode384) {
  24250. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  24251. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  24252. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  24253. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  24254. h4 = new Word64(0x510e527f, 0xade682d1);
  24255. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  24256. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  24257. h7 = new Word64(0x5be0cd19, 0x137e2179);
  24258. }
  24259. else {
  24260. // SHA384 is exactly the same
  24261. // except with different starting values and a trimmed result
  24262. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  24263. h1 = new Word64(0x629a292a, 0x367cd507);
  24264. h2 = new Word64(0x9159015a, 0x3070dd17);
  24265. h3 = new Word64(0x152fecd8, 0xf70e5939);
  24266. h4 = new Word64(0x67332667, 0xffc00b31);
  24267. h5 = new Word64(0x8eb44a87, 0x68581511);
  24268. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  24269. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  24270. }
  24271. // pre-processing
  24272. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  24273. var padded = new Uint8Array(paddedLength);
  24274. var i, j, n;
  24275. for (i = 0; i < length; ++i) {
  24276. padded[i] = data[offset++];
  24277. }
  24278. padded[i++] = 0x80;
  24279. n = paddedLength - 16;
  24280. while (i < n) {
  24281. padded[i++] = 0;
  24282. }
  24283. padded[i++] = 0;
  24284. padded[i++] = 0;
  24285. padded[i++] = 0;
  24286. padded[i++] = 0;
  24287. padded[i++] = 0;
  24288. padded[i++] = 0;
  24289. padded[i++] = 0;
  24290. padded[i++] = 0;
  24291. padded[i++] = 0;
  24292. padded[i++] = 0;
  24293. padded[i++] = 0;
  24294. padded[i++] = (length >>> 29) & 0xFF;
  24295. padded[i++] = (length >> 21) & 0xFF;
  24296. padded[i++] = (length >> 13) & 0xFF;
  24297. padded[i++] = (length >> 5) & 0xFF;
  24298. padded[i++] = (length << 3) & 0xFF;
  24299. var w = new Array(80);
  24300. for (i = 0; i < 80; i++) {
  24301. w[i] = new Word64(0, 0);
  24302. }
  24303. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  24304. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  24305. var g = new Word64(0, 0), h = new Word64(0, 0);
  24306. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  24307. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  24308. // for each 1024 bit block
  24309. for (i = 0; i < paddedLength;) {
  24310. for (j = 0; j < 16; ++j) {
  24311. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  24312. (padded[i + 2] << 8) | (padded[i + 3]);
  24313. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  24314. (padded[i + 6]) << 8 | (padded[i + 7]);
  24315. i += 8;
  24316. }
  24317. for (j = 16; j < 80; ++j) {
  24318. tmp3 = w[j];
  24319. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  24320. tmp3.add(w[j - 7]);
  24321. littleSigma(tmp1, w[j - 15], tmp2);
  24322. tmp3.add(tmp1);
  24323. tmp3.add(w[j - 16]);
  24324. }
  24325. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  24326. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  24327. for (j = 0; j < 80; ++j) {
  24328. t1.assign(h);
  24329. sigmaPrime(tmp1, e, tmp2);
  24330. t1.add(tmp1);
  24331. ch(tmp1, e, f, g, tmp2);
  24332. t1.add(tmp1);
  24333. t1.add(k[j]);
  24334. t1.add(w[j]);
  24335. sigma(t2, a, tmp2);
  24336. maj(tmp1, a, b, c, tmp2);
  24337. t2.add(tmp1);
  24338. tmp3 = h;
  24339. h = g;
  24340. g = f;
  24341. f = e;
  24342. d.add(t1);
  24343. e = d;
  24344. d = c;
  24345. c = b;
  24346. b = a;
  24347. tmp3.assign(t1);
  24348. tmp3.add(t2);
  24349. a = tmp3;
  24350. }
  24351. h0.add(a);
  24352. h1.add(b);
  24353. h2.add(c);
  24354. h3.add(d);
  24355. h4.add(e);
  24356. h5.add(f);
  24357. h6.add(g);
  24358. h7.add(h);
  24359. }
  24360. var result;
  24361. if (!mode384) {
  24362. result = new Uint8Array(64);
  24363. h0.copyTo(result,0);
  24364. h1.copyTo(result,8);
  24365. h2.copyTo(result,16);
  24366. h3.copyTo(result,24);
  24367. h4.copyTo(result,32);
  24368. h5.copyTo(result,40);
  24369. h6.copyTo(result,48);
  24370. h7.copyTo(result,56);
  24371. }
  24372. else {
  24373. result = new Uint8Array(48);
  24374. h0.copyTo(result,0);
  24375. h1.copyTo(result,8);
  24376. h2.copyTo(result,16);
  24377. h3.copyTo(result,24);
  24378. h4.copyTo(result,32);
  24379. h5.copyTo(result,40);
  24380. }
  24381. return result;
  24382. }
  24383. return hash;
  24384. })();
  24385. var calculateSHA384 = (function calculateSHA384Closure() {
  24386. function hash(data, offset, length) {
  24387. return calculateSHA512(data, offset, length, true);
  24388. }
  24389. return hash;
  24390. })();
  24391. var NullCipher = (function NullCipherClosure() {
  24392. function NullCipher() {
  24393. }
  24394. NullCipher.prototype = {
  24395. decryptBlock: function NullCipher_decryptBlock(data) {
  24396. return data;
  24397. }
  24398. };
  24399. return NullCipher;
  24400. })();
  24401. var AES128Cipher = (function AES128CipherClosure() {
  24402. var rcon = new Uint8Array([
  24403. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24404. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24405. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24406. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24407. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24408. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24409. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24410. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24411. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24412. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24413. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24414. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24415. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24416. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24417. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24418. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24419. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24420. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24421. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24422. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24423. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24424. 0x74, 0xe8, 0xcb, 0x8d]);
  24425. var s = new Uint8Array([
  24426. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24427. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24428. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24429. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24430. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24431. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24432. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24433. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24434. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24435. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24436. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24437. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24438. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24439. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24440. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24441. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24442. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24443. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24444. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24445. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24446. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24447. 0xb0, 0x54, 0xbb, 0x16]);
  24448. var inv_s = new Uint8Array([
  24449. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24450. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24451. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24452. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24453. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24454. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24455. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24456. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24457. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24458. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24459. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24460. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24461. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24462. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24463. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24464. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24465. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24466. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24467. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24468. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24469. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24470. 0x55, 0x21, 0x0c, 0x7d]);
  24471. var mixCol = new Uint8Array(256);
  24472. for (var i = 0; i < 256; i++) {
  24473. if (i < 128) {
  24474. mixCol[i] = i << 1;
  24475. } else {
  24476. mixCol[i] = (i << 1) ^ 0x1b;
  24477. }
  24478. }
  24479. var mix = new Uint32Array([
  24480. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24481. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24482. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24483. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24484. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24485. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24486. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24487. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24488. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24489. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24490. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24491. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24492. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24493. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24494. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24495. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24496. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24497. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24498. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24499. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24500. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24501. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24502. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24503. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24504. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24505. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24506. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24507. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24508. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24509. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24510. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24511. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24512. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24513. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24514. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24515. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24516. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24517. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24518. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24519. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24520. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24521. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24522. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24523. function expandKey128(cipherKey) {
  24524. var b = 176, result = new Uint8Array(b);
  24525. result.set(cipherKey);
  24526. for (var j = 16, i = 1; j < b; ++i) {
  24527. // RotWord
  24528. var t1 = result[j - 3], t2 = result[j - 2],
  24529. t3 = result[j - 1], t4 = result[j - 4];
  24530. // SubWord
  24531. t1 = s[t1];
  24532. t2 = s[t2];
  24533. t3 = s[t3];
  24534. t4 = s[t4];
  24535. // Rcon
  24536. t1 = t1 ^ rcon[i];
  24537. for (var n = 0; n < 4; ++n) {
  24538. result[j] = (t1 ^= result[j - 16]);
  24539. j++;
  24540. result[j] = (t2 ^= result[j - 16]);
  24541. j++;
  24542. result[j] = (t3 ^= result[j - 16]);
  24543. j++;
  24544. result[j] = (t4 ^= result[j - 16]);
  24545. j++;
  24546. }
  24547. }
  24548. return result;
  24549. }
  24550. function decrypt128(input, key) {
  24551. var state = new Uint8Array(16);
  24552. state.set(input);
  24553. var i, j, k;
  24554. var t, u, v;
  24555. // AddRoundKey
  24556. for (j = 0, k = 160; j < 16; ++j, ++k) {
  24557. state[j] ^= key[k];
  24558. }
  24559. for (i = 9; i >= 1; --i) {
  24560. // InvShiftRows
  24561. t = state[13];
  24562. state[13] = state[9];
  24563. state[9] = state[5];
  24564. state[5] = state[1];
  24565. state[1] = t;
  24566. t = state[14];
  24567. u = state[10];
  24568. state[14] = state[6];
  24569. state[10] = state[2];
  24570. state[6] = t;
  24571. state[2] = u;
  24572. t = state[15];
  24573. u = state[11];
  24574. v = state[7];
  24575. state[15] = state[3];
  24576. state[11] = t;
  24577. state[7] = u;
  24578. state[3] = v;
  24579. // InvSubBytes
  24580. for (j = 0; j < 16; ++j) {
  24581. state[j] = inv_s[state[j]];
  24582. }
  24583. // AddRoundKey
  24584. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24585. state[j] ^= key[k];
  24586. }
  24587. // InvMixColumns
  24588. for (j = 0; j < 16; j += 4) {
  24589. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24590. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24591. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24592. (s3 >>> 24) ^ (s3 << 8));
  24593. state[j] = (t >>> 24) & 0xFF;
  24594. state[j + 1] = (t >> 16) & 0xFF;
  24595. state[j + 2] = (t >> 8) & 0xFF;
  24596. state[j + 3] = t & 0xFF;
  24597. }
  24598. }
  24599. // InvShiftRows
  24600. t = state[13];
  24601. state[13] = state[9];
  24602. state[9] = state[5];
  24603. state[5] = state[1];
  24604. state[1] = t;
  24605. t = state[14];
  24606. u = state[10];
  24607. state[14] = state[6];
  24608. state[10] = state[2];
  24609. state[6] = t;
  24610. state[2] = u;
  24611. t = state[15];
  24612. u = state[11];
  24613. v = state[7];
  24614. state[15] = state[3];
  24615. state[11] = t;
  24616. state[7] = u;
  24617. state[3] = v;
  24618. for (j = 0; j < 16; ++j) {
  24619. // InvSubBytes
  24620. state[j] = inv_s[state[j]];
  24621. // AddRoundKey
  24622. state[j] ^= key[j];
  24623. }
  24624. return state;
  24625. }
  24626. function encrypt128(input, key) {
  24627. var t, u, v, k;
  24628. var state = new Uint8Array(16);
  24629. state.set(input);
  24630. for (j = 0; j < 16; ++j) {
  24631. // AddRoundKey
  24632. state[j] ^= key[j];
  24633. }
  24634. for (i = 1; i < 10; i++) {
  24635. //SubBytes
  24636. for (j = 0; j < 16; ++j) {
  24637. state[j] = s[state[j]];
  24638. }
  24639. //ShiftRows
  24640. v = state[1];
  24641. state[1] = state[5];
  24642. state[5] = state[9];
  24643. state[9] = state[13];
  24644. state[13] = v;
  24645. v = state[2];
  24646. u = state[6];
  24647. state[2] = state[10];
  24648. state[6] = state[14];
  24649. state[10] = v;
  24650. state[14] = u;
  24651. v = state[3];
  24652. u = state[7];
  24653. t = state[11];
  24654. state[3] = state[15];
  24655. state[7] = v;
  24656. state[11] = u;
  24657. state[15] = t;
  24658. //MixColumns
  24659. for (var j = 0; j < 16; j += 4) {
  24660. var s0 = state[j + 0], s1 = state[j + 1];
  24661. var s2 = state[j + 2], s3 = state[j + 3];
  24662. t = s0 ^ s1 ^ s2 ^ s3;
  24663. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24664. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24665. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24666. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24667. }
  24668. //AddRoundKey
  24669. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24670. state[j] ^= key[k];
  24671. }
  24672. }
  24673. //SubBytes
  24674. for (j = 0; j < 16; ++j) {
  24675. state[j] = s[state[j]];
  24676. }
  24677. //ShiftRows
  24678. v = state[1];
  24679. state[1] = state[5];
  24680. state[5] = state[9];
  24681. state[9] = state[13];
  24682. state[13] = v;
  24683. v = state[2];
  24684. u = state[6];
  24685. state[2] = state[10];
  24686. state[6] = state[14];
  24687. state[10] = v;
  24688. state[14] = u;
  24689. v = state[3];
  24690. u = state[7];
  24691. t = state[11];
  24692. state[3] = state[15];
  24693. state[7] = v;
  24694. state[11] = u;
  24695. state[15] = t;
  24696. //AddRoundKey
  24697. for (j = 0, k = 160; j < 16; ++j, ++k) {
  24698. state[j] ^= key[k];
  24699. }
  24700. return state;
  24701. }
  24702. function AES128Cipher(key) {
  24703. this.key = expandKey128(key);
  24704. this.buffer = new Uint8Array(16);
  24705. this.bufferPosition = 0;
  24706. }
  24707. function decryptBlock2(data, finalize) {
  24708. var i, j, ii, sourceLength = data.length,
  24709. buffer = this.buffer, bufferLength = this.bufferPosition,
  24710. result = [], iv = this.iv;
  24711. for (i = 0; i < sourceLength; ++i) {
  24712. buffer[bufferLength] = data[i];
  24713. ++bufferLength;
  24714. if (bufferLength < 16) {
  24715. continue;
  24716. }
  24717. // buffer is full, decrypting
  24718. var plain = decrypt128(buffer, this.key);
  24719. // xor-ing the IV vector to get plain text
  24720. for (j = 0; j < 16; ++j) {
  24721. plain[j] ^= iv[j];
  24722. }
  24723. iv = buffer;
  24724. result.push(plain);
  24725. buffer = new Uint8Array(16);
  24726. bufferLength = 0;
  24727. }
  24728. // saving incomplete buffer
  24729. this.buffer = buffer;
  24730. this.bufferLength = bufferLength;
  24731. this.iv = iv;
  24732. if (result.length === 0) {
  24733. return new Uint8Array([]);
  24734. }
  24735. // combining plain text blocks into one
  24736. var outputLength = 16 * result.length;
  24737. if (finalize) {
  24738. // undo a padding that is described in RFC 2898
  24739. var lastBlock = result[result.length - 1];
  24740. var psLen = lastBlock[15];
  24741. if (psLen <= 16) {
  24742. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24743. if (lastBlock[i] !== psLen) {
  24744. // Invalid padding, assume that the block has no padding.
  24745. psLen = 0;
  24746. break;
  24747. }
  24748. }
  24749. outputLength -= psLen;
  24750. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24751. }
  24752. }
  24753. var output = new Uint8Array(outputLength);
  24754. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24755. output.set(result[i], j);
  24756. }
  24757. return output;
  24758. }
  24759. AES128Cipher.prototype = {
  24760. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  24761. var i, sourceLength = data.length;
  24762. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24763. // waiting for IV values -- they are at the start of the stream
  24764. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  24765. buffer[bufferLength] = data[i];
  24766. }
  24767. if (bufferLength < 16) {
  24768. // need more data
  24769. this.bufferLength = bufferLength;
  24770. return new Uint8Array([]);
  24771. }
  24772. this.iv = buffer;
  24773. this.buffer = new Uint8Array(16);
  24774. this.bufferLength = 0;
  24775. // starting decryption
  24776. this.decryptBlock = decryptBlock2;
  24777. return this.decryptBlock(data.subarray(16), finalize);
  24778. },
  24779. encrypt: function AES128Cipher_encrypt(data, iv) {
  24780. var i, j, ii, sourceLength = data.length,
  24781. buffer = this.buffer, bufferLength = this.bufferPosition,
  24782. result = [];
  24783. if (!iv) {
  24784. iv = new Uint8Array(16);
  24785. }
  24786. for (i = 0; i < sourceLength; ++i) {
  24787. buffer[bufferLength] = data[i];
  24788. ++bufferLength;
  24789. if (bufferLength < 16) {
  24790. continue;
  24791. }
  24792. for (j = 0; j < 16; ++j) {
  24793. buffer[j] ^= iv[j];
  24794. }
  24795. // buffer is full, encrypting
  24796. var cipher = encrypt128(buffer, this.key);
  24797. iv = cipher;
  24798. result.push(cipher);
  24799. buffer = new Uint8Array(16);
  24800. bufferLength = 0;
  24801. }
  24802. // saving incomplete buffer
  24803. this.buffer = buffer;
  24804. this.bufferLength = bufferLength;
  24805. this.iv = iv;
  24806. if (result.length === 0) {
  24807. return new Uint8Array([]);
  24808. }
  24809. // combining plain text blocks into one
  24810. var outputLength = 16 * result.length;
  24811. var output = new Uint8Array(outputLength);
  24812. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24813. output.set(result[i], j);
  24814. }
  24815. return output;
  24816. }
  24817. };
  24818. return AES128Cipher;
  24819. })();
  24820. var AES256Cipher = (function AES256CipherClosure() {
  24821. var rcon = new Uint8Array([
  24822. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24823. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24824. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24825. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24826. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24827. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24828. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24829. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24830. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24831. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24832. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24833. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24834. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24835. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24836. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24837. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24838. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24839. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24840. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24841. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24842. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24843. 0x74, 0xe8, 0xcb, 0x8d]);
  24844. var s = new Uint8Array([
  24845. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24846. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24847. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24848. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24849. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24850. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24851. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24852. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24853. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24854. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24855. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24856. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24857. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24858. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24859. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24860. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24861. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24862. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24863. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24864. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24865. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24866. 0xb0, 0x54, 0xbb, 0x16]);
  24867. var inv_s = new Uint8Array([
  24868. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24869. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24870. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24871. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24872. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24873. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24874. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24875. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24876. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24877. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24878. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24879. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24880. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24881. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24882. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24883. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24884. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24885. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24886. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24887. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24888. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24889. 0x55, 0x21, 0x0c, 0x7d]);
  24890. var mixCol = new Uint8Array(256);
  24891. for (var i = 0; i < 256; i++) {
  24892. if (i < 128) {
  24893. mixCol[i] = i << 1;
  24894. } else {
  24895. mixCol[i] = (i << 1) ^ 0x1b;
  24896. }
  24897. }
  24898. var mix = new Uint32Array([
  24899. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24900. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24901. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24902. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24903. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24904. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24905. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24906. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24907. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24908. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24909. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24910. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24911. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24912. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24913. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24914. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24915. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24916. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24917. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24918. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24919. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24920. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24921. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24922. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24923. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24924. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24925. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24926. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24927. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24928. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24929. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24930. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24931. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24932. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24933. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24934. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24935. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24936. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24937. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24938. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24939. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24940. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24941. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24942. function expandKey256(cipherKey) {
  24943. var b = 240, result = new Uint8Array(b);
  24944. var r = 1;
  24945. result.set(cipherKey);
  24946. for (var j = 32, i = 1; j < b; ++i) {
  24947. if (j % 32 === 16) {
  24948. t1 = s[t1];
  24949. t2 = s[t2];
  24950. t3 = s[t3];
  24951. t4 = s[t4];
  24952. } else if (j % 32 === 0) {
  24953. // RotWord
  24954. var t1 = result[j - 3], t2 = result[j - 2],
  24955. t3 = result[j - 1], t4 = result[j - 4];
  24956. // SubWord
  24957. t1 = s[t1];
  24958. t2 = s[t2];
  24959. t3 = s[t3];
  24960. t4 = s[t4];
  24961. // Rcon
  24962. t1 = t1 ^ r;
  24963. if ((r <<= 1) >= 256) {
  24964. r = (r ^ 0x1b) & 0xFF;
  24965. }
  24966. }
  24967. for (var n = 0; n < 4; ++n) {
  24968. result[j] = (t1 ^= result[j - 32]);
  24969. j++;
  24970. result[j] = (t2 ^= result[j - 32]);
  24971. j++;
  24972. result[j] = (t3 ^= result[j - 32]);
  24973. j++;
  24974. result[j] = (t4 ^= result[j - 32]);
  24975. j++;
  24976. }
  24977. }
  24978. return result;
  24979. }
  24980. function decrypt256(input, key) {
  24981. var state = new Uint8Array(16);
  24982. state.set(input);
  24983. var i, j, k;
  24984. var t, u, v;
  24985. // AddRoundKey
  24986. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24987. state[j] ^= key[k];
  24988. }
  24989. for (i = 13; i >= 1; --i) {
  24990. // InvShiftRows
  24991. t = state[13];
  24992. state[13] = state[9];
  24993. state[9] = state[5];
  24994. state[5] = state[1];
  24995. state[1] = t;
  24996. t = state[14];
  24997. u = state[10];
  24998. state[14] = state[6];
  24999. state[10] = state[2];
  25000. state[6] = t;
  25001. state[2] = u;
  25002. t = state[15];
  25003. u = state[11];
  25004. v = state[7];
  25005. state[15] = state[3];
  25006. state[11] = t;
  25007. state[7] = u;
  25008. state[3] = v;
  25009. // InvSubBytes
  25010. for (j = 0; j < 16; ++j) {
  25011. state[j] = inv_s[state[j]];
  25012. }
  25013. // AddRoundKey
  25014. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25015. state[j] ^= key[k];
  25016. }
  25017. // InvMixColumns
  25018. for (j = 0; j < 16; j += 4) {
  25019. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  25020. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  25021. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  25022. (s3 >>> 24) ^ (s3 << 8));
  25023. state[j] = (t >>> 24) & 0xFF;
  25024. state[j + 1] = (t >> 16) & 0xFF;
  25025. state[j + 2] = (t >> 8) & 0xFF;
  25026. state[j + 3] = t & 0xFF;
  25027. }
  25028. }
  25029. // InvShiftRows
  25030. t = state[13];
  25031. state[13] = state[9];
  25032. state[9] = state[5];
  25033. state[5] = state[1];
  25034. state[1] = t;
  25035. t = state[14];
  25036. u = state[10];
  25037. state[14] = state[6];
  25038. state[10] = state[2];
  25039. state[6] = t;
  25040. state[2] = u;
  25041. t = state[15];
  25042. u = state[11];
  25043. v = state[7];
  25044. state[15] = state[3];
  25045. state[11] = t;
  25046. state[7] = u;
  25047. state[3] = v;
  25048. for (j = 0; j < 16; ++j) {
  25049. // InvSubBytes
  25050. state[j] = inv_s[state[j]];
  25051. // AddRoundKey
  25052. state[j] ^= key[j];
  25053. }
  25054. return state;
  25055. }
  25056. function encrypt256(input, key) {
  25057. var t, u, v, k;
  25058. var state = new Uint8Array(16);
  25059. state.set(input);
  25060. for (j = 0; j < 16; ++j) {
  25061. // AddRoundKey
  25062. state[j] ^= key[j];
  25063. }
  25064. for (i = 1; i < 14; i++) {
  25065. //SubBytes
  25066. for (j = 0; j < 16; ++j) {
  25067. state[j] = s[state[j]];
  25068. }
  25069. //ShiftRows
  25070. v = state[1];
  25071. state[1] = state[5];
  25072. state[5] = state[9];
  25073. state[9] = state[13];
  25074. state[13] = v;
  25075. v = state[2];
  25076. u = state[6];
  25077. state[2] = state[10];
  25078. state[6] = state[14];
  25079. state[10] = v;
  25080. state[14] = u;
  25081. v = state[3];
  25082. u = state[7];
  25083. t = state[11];
  25084. state[3] = state[15];
  25085. state[7] = v;
  25086. state[11] = u;
  25087. state[15] = t;
  25088. //MixColumns
  25089. for (var j = 0; j < 16; j += 4) {
  25090. var s0 = state[j + 0], s1 = state[j + 1];
  25091. var s2 = state[j + 2], s3 = state[j + 3];
  25092. t = s0 ^ s1 ^ s2 ^ s3;
  25093. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  25094. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  25095. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  25096. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  25097. }
  25098. //AddRoundKey
  25099. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  25100. state[j] ^= key[k];
  25101. }
  25102. }
  25103. //SubBytes
  25104. for (j = 0; j < 16; ++j) {
  25105. state[j] = s[state[j]];
  25106. }
  25107. //ShiftRows
  25108. v = state[1];
  25109. state[1] = state[5];
  25110. state[5] = state[9];
  25111. state[9] = state[13];
  25112. state[13] = v;
  25113. v = state[2];
  25114. u = state[6];
  25115. state[2] = state[10];
  25116. state[6] = state[14];
  25117. state[10] = v;
  25118. state[14] = u;
  25119. v = state[3];
  25120. u = state[7];
  25121. t = state[11];
  25122. state[3] = state[15];
  25123. state[7] = v;
  25124. state[11] = u;
  25125. state[15] = t;
  25126. //AddRoundKey
  25127. for (j = 0, k = 224; j < 16; ++j, ++k) {
  25128. state[j] ^= key[k];
  25129. }
  25130. return state;
  25131. }
  25132. function AES256Cipher(key) {
  25133. this.key = expandKey256(key);
  25134. this.buffer = new Uint8Array(16);
  25135. this.bufferPosition = 0;
  25136. }
  25137. function decryptBlock2(data, finalize) {
  25138. var i, j, ii, sourceLength = data.length,
  25139. buffer = this.buffer, bufferLength = this.bufferPosition,
  25140. result = [], iv = this.iv;
  25141. for (i = 0; i < sourceLength; ++i) {
  25142. buffer[bufferLength] = data[i];
  25143. ++bufferLength;
  25144. if (bufferLength < 16) {
  25145. continue;
  25146. }
  25147. // buffer is full, decrypting
  25148. var plain = decrypt256(buffer, this.key);
  25149. // xor-ing the IV vector to get plain text
  25150. for (j = 0; j < 16; ++j) {
  25151. plain[j] ^= iv[j];
  25152. }
  25153. iv = buffer;
  25154. result.push(plain);
  25155. buffer = new Uint8Array(16);
  25156. bufferLength = 0;
  25157. }
  25158. // saving incomplete buffer
  25159. this.buffer = buffer;
  25160. this.bufferLength = bufferLength;
  25161. this.iv = iv;
  25162. if (result.length === 0) {
  25163. return new Uint8Array([]);
  25164. }
  25165. // combining plain text blocks into one
  25166. var outputLength = 16 * result.length;
  25167. if (finalize) {
  25168. // undo a padding that is described in RFC 2898
  25169. var lastBlock = result[result.length - 1];
  25170. var psLen = lastBlock[15];
  25171. if (psLen <= 16) {
  25172. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  25173. if (lastBlock[i] !== psLen) {
  25174. // Invalid padding, assume that the block has no padding.
  25175. psLen = 0;
  25176. break;
  25177. }
  25178. }
  25179. outputLength -= psLen;
  25180. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  25181. }
  25182. }
  25183. var output = new Uint8Array(outputLength);
  25184. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25185. output.set(result[i], j);
  25186. }
  25187. return output;
  25188. }
  25189. AES256Cipher.prototype = {
  25190. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  25191. var i, sourceLength = data.length;
  25192. var buffer = this.buffer, bufferLength = this.bufferPosition;
  25193. // if not supplied an IV wait for IV values
  25194. // they are at the start of the stream
  25195. if (iv) {
  25196. this.iv = iv;
  25197. } else {
  25198. for (i = 0; bufferLength < 16 &&
  25199. i < sourceLength; ++i, ++bufferLength) {
  25200. buffer[bufferLength] = data[i];
  25201. }
  25202. if (bufferLength < 16) {
  25203. //need more data
  25204. this.bufferLength = bufferLength;
  25205. return new Uint8Array([]);
  25206. }
  25207. this.iv = buffer;
  25208. data = data.subarray(16);
  25209. }
  25210. this.buffer = new Uint8Array(16);
  25211. this.bufferLength = 0;
  25212. // starting decryption
  25213. this.decryptBlock = decryptBlock2;
  25214. return this.decryptBlock(data, finalize);
  25215. },
  25216. encrypt: function AES256Cipher_encrypt(data, iv) {
  25217. var i, j, ii, sourceLength = data.length,
  25218. buffer = this.buffer, bufferLength = this.bufferPosition,
  25219. result = [];
  25220. if (!iv) {
  25221. iv = new Uint8Array(16);
  25222. }
  25223. for (i = 0; i < sourceLength; ++i) {
  25224. buffer[bufferLength] = data[i];
  25225. ++bufferLength;
  25226. if (bufferLength < 16) {
  25227. continue;
  25228. }
  25229. for (j = 0; j < 16; ++j) {
  25230. buffer[j] ^= iv[j];
  25231. }
  25232. // buffer is full, encrypting
  25233. var cipher = encrypt256(buffer, this.key);
  25234. this.iv = cipher;
  25235. result.push(cipher);
  25236. buffer = new Uint8Array(16);
  25237. bufferLength = 0;
  25238. }
  25239. // saving incomplete buffer
  25240. this.buffer = buffer;
  25241. this.bufferLength = bufferLength;
  25242. this.iv = iv;
  25243. if (result.length === 0) {
  25244. return new Uint8Array([]);
  25245. }
  25246. // combining plain text blocks into one
  25247. var outputLength = 16 * result.length;
  25248. var output = new Uint8Array(outputLength);
  25249. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  25250. output.set(result[i], j);
  25251. }
  25252. return output;
  25253. }
  25254. };
  25255. return AES256Cipher;
  25256. })();
  25257. var PDF17 = (function PDF17Closure() {
  25258. function compareByteArrays(array1, array2) {
  25259. if (array1.length !== array2.length) {
  25260. return false;
  25261. }
  25262. for (var i = 0; i < array1.length; i++) {
  25263. if (array1[i] !== array2[i]) {
  25264. return false;
  25265. }
  25266. }
  25267. return true;
  25268. }
  25269. function PDF17() {
  25270. }
  25271. PDF17.prototype = {
  25272. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  25273. ownerValidationSalt,
  25274. userBytes,
  25275. ownerPassword) {
  25276. var hashData = new Uint8Array(password.length + 56);
  25277. hashData.set(password, 0);
  25278. hashData.set(ownerValidationSalt, password.length);
  25279. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  25280. var result = calculateSHA256(hashData, 0, hashData.length);
  25281. return compareByteArrays(result, ownerPassword);
  25282. },
  25283. checkUserPassword: function PDF17_checkUserPassword(password,
  25284. userValidationSalt,
  25285. userPassword) {
  25286. var hashData = new Uint8Array(password.length + 8);
  25287. hashData.set(password, 0);
  25288. hashData.set(userValidationSalt, password.length);
  25289. var result = calculateSHA256(hashData, 0, hashData.length);
  25290. return compareByteArrays(result, userPassword);
  25291. },
  25292. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  25293. ownerEncryption) {
  25294. var hashData = new Uint8Array(password.length + 56);
  25295. hashData.set(password, 0);
  25296. hashData.set(ownerKeySalt, password.length);
  25297. hashData.set(userBytes, password.length + ownerKeySalt.length);
  25298. var key = calculateSHA256(hashData, 0, hashData.length);
  25299. var cipher = new AES256Cipher(key);
  25300. return cipher.decryptBlock(ownerEncryption,
  25301. false,
  25302. new Uint8Array(16));
  25303. },
  25304. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  25305. userEncryption) {
  25306. var hashData = new Uint8Array(password.length + 8);
  25307. hashData.set(password, 0);
  25308. hashData.set(userKeySalt, password.length);
  25309. //key is the decryption key for the UE string
  25310. var key = calculateSHA256(hashData, 0, hashData.length);
  25311. var cipher = new AES256Cipher(key);
  25312. return cipher.decryptBlock(userEncryption,
  25313. false,
  25314. new Uint8Array(16));
  25315. }
  25316. };
  25317. return PDF17;
  25318. })();
  25319. var PDF20 = (function PDF20Closure() {
  25320. function concatArrays(array1, array2) {
  25321. var t = new Uint8Array(array1.length + array2.length);
  25322. t.set(array1, 0);
  25323. t.set(array2, array1.length);
  25324. return t;
  25325. }
  25326. function calculatePDF20Hash(password, input, userBytes) {
  25327. //This refers to Algorithm 2.B as defined in ISO 32000-2
  25328. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  25329. var e = [0];
  25330. var i = 0;
  25331. while (i < 64 || e[e.length - 1] > i - 32) {
  25332. var arrayLength = password.length + k.length + userBytes.length;
  25333. var k1 = new Uint8Array(arrayLength * 64);
  25334. var array = concatArrays(password, k);
  25335. array = concatArrays(array, userBytes);
  25336. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  25337. k1.set(array, pos);
  25338. }
  25339. //AES128 CBC NO PADDING with
  25340. //first 16 bytes of k as the key and the second 16 as the iv.
  25341. var cipher = new AES128Cipher(k.subarray(0, 16));
  25342. e = cipher.encrypt(k1, k.subarray(16, 32));
  25343. //Now we have to take the first 16 bytes of an unsigned
  25344. //big endian integer... and compute the remainder
  25345. //modulo 3.... That is a fairly large number and
  25346. //JavaScript isn't going to handle that well...
  25347. //So we're using a trick that allows us to perform
  25348. //modulo math byte by byte
  25349. var remainder = 0;
  25350. for (var z = 0; z < 16; z++) {
  25351. remainder *= (256 % 3);
  25352. remainder %= 3;
  25353. remainder += ((e[z] >>> 0) % 3);
  25354. remainder %= 3;
  25355. }
  25356. if (remainder === 0) {
  25357. k = calculateSHA256(e, 0, e.length);
  25358. }
  25359. else if (remainder === 1) {
  25360. k = calculateSHA384(e, 0, e.length);
  25361. }
  25362. else if (remainder === 2) {
  25363. k = calculateSHA512(e, 0, e.length);
  25364. }
  25365. i++;
  25366. }
  25367. return k.subarray(0, 32);
  25368. }
  25369. function PDF20() {
  25370. }
  25371. function compareByteArrays(array1, array2) {
  25372. if (array1.length !== array2.length) {
  25373. return false;
  25374. }
  25375. for (var i = 0; i < array1.length; i++) {
  25376. if (array1[i] !== array2[i]) {
  25377. return false;
  25378. }
  25379. }
  25380. return true;
  25381. }
  25382. PDF20.prototype = {
  25383. hash: function PDF20_hash(password, concatBytes, userBytes) {
  25384. return calculatePDF20Hash(password, concatBytes, userBytes);
  25385. },
  25386. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  25387. ownerValidationSalt,
  25388. userBytes,
  25389. ownerPassword) {
  25390. var hashData = new Uint8Array(password.length + 56);
  25391. hashData.set(password, 0);
  25392. hashData.set(ownerValidationSalt, password.length);
  25393. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  25394. var result = calculatePDF20Hash(password, hashData, userBytes);
  25395. return compareByteArrays(result, ownerPassword);
  25396. },
  25397. checkUserPassword: function PDF20_checkUserPassword(password,
  25398. userValidationSalt,
  25399. userPassword) {
  25400. var hashData = new Uint8Array(password.length + 8);
  25401. hashData.set(password, 0);
  25402. hashData.set(userValidationSalt, password.length);
  25403. var result = calculatePDF20Hash(password, hashData, []);
  25404. return compareByteArrays(result, userPassword);
  25405. },
  25406. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  25407. ownerEncryption) {
  25408. var hashData = new Uint8Array(password.length + 56);
  25409. hashData.set(password, 0);
  25410. hashData.set(ownerKeySalt, password.length);
  25411. hashData.set(userBytes, password.length + ownerKeySalt.length);
  25412. var key = calculatePDF20Hash(password, hashData, userBytes);
  25413. var cipher = new AES256Cipher(key);
  25414. return cipher.decryptBlock(ownerEncryption,
  25415. false,
  25416. new Uint8Array(16));
  25417. },
  25418. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  25419. userEncryption) {
  25420. var hashData = new Uint8Array(password.length + 8);
  25421. hashData.set(password, 0);
  25422. hashData.set(userKeySalt, password.length);
  25423. //key is the decryption key for the UE string
  25424. var key = calculatePDF20Hash(password, hashData, []);
  25425. var cipher = new AES256Cipher(key);
  25426. return cipher.decryptBlock(userEncryption,
  25427. false,
  25428. new Uint8Array(16));
  25429. }
  25430. };
  25431. return PDF20;
  25432. })();
  25433. var CipherTransform = (function CipherTransformClosure() {
  25434. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  25435. this.stringCipherConstructor = stringCipherConstructor;
  25436. this.streamCipherConstructor = streamCipherConstructor;
  25437. }
  25438. CipherTransform.prototype = {
  25439. createStream: function CipherTransform_createStream(stream, length) {
  25440. var cipher = new this.streamCipherConstructor();
  25441. return new DecryptStream(stream, length,
  25442. function cipherTransformDecryptStream(data, finalize) {
  25443. return cipher.decryptBlock(data, finalize);
  25444. }
  25445. );
  25446. },
  25447. decryptString: function CipherTransform_decryptString(s) {
  25448. var cipher = new this.stringCipherConstructor();
  25449. var data = stringToBytes(s);
  25450. data = cipher.decryptBlock(data, true);
  25451. return bytesToString(data);
  25452. }
  25453. };
  25454. return CipherTransform;
  25455. })();
  25456. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  25457. var defaultPasswordBytes = new Uint8Array([
  25458. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  25459. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  25460. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  25461. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  25462. function createEncryptionKey20(revision, password, ownerPassword,
  25463. ownerValidationSalt, ownerKeySalt, uBytes,
  25464. userPassword, userValidationSalt, userKeySalt,
  25465. ownerEncryption, userEncryption, perms) {
  25466. if (password) {
  25467. var passwordLength = Math.min(127, password.length);
  25468. password = password.subarray(0, passwordLength);
  25469. } else {
  25470. password = [];
  25471. }
  25472. var pdfAlgorithm;
  25473. if (revision === 6) {
  25474. pdfAlgorithm = new PDF20();
  25475. } else {
  25476. pdfAlgorithm = new PDF17();
  25477. }
  25478. if (pdfAlgorithm) {
  25479. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  25480. userPassword)) {
  25481. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  25482. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  25483. ownerValidationSalt,
  25484. uBytes,
  25485. ownerPassword)) {
  25486. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  25487. ownerEncryption);
  25488. }
  25489. }
  25490. return null;
  25491. }
  25492. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  25493. flags, revision, keyLength, encryptMetadata) {
  25494. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  25495. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  25496. if (password) {
  25497. n = Math.min(32, password.length);
  25498. for (; i < n; ++i) {
  25499. hashData[i] = password[i];
  25500. }
  25501. }
  25502. j = 0;
  25503. while (i < 32) {
  25504. hashData[i++] = defaultPasswordBytes[j++];
  25505. }
  25506. // as now the padded password in the hashData[0..i]
  25507. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  25508. hashData[i++] = ownerPassword[j];
  25509. }
  25510. hashData[i++] = flags & 0xFF;
  25511. hashData[i++] = (flags >> 8) & 0xFF;
  25512. hashData[i++] = (flags >> 16) & 0xFF;
  25513. hashData[i++] = (flags >>> 24) & 0xFF;
  25514. for (j = 0, n = fileId.length; j < n; ++j) {
  25515. hashData[i++] = fileId[j];
  25516. }
  25517. if (revision >= 4 && !encryptMetadata) {
  25518. hashData[i++] = 0xFF;
  25519. hashData[i++] = 0xFF;
  25520. hashData[i++] = 0xFF;
  25521. hashData[i++] = 0xFF;
  25522. }
  25523. var hash = calculateMD5(hashData, 0, i);
  25524. var keyLengthInBytes = keyLength >> 3;
  25525. if (revision >= 3) {
  25526. for (j = 0; j < 50; ++j) {
  25527. hash = calculateMD5(hash, 0, keyLengthInBytes);
  25528. }
  25529. }
  25530. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  25531. var cipher, checkData;
  25532. if (revision >= 3) {
  25533. for (i = 0; i < 32; ++i) {
  25534. hashData[i] = defaultPasswordBytes[i];
  25535. }
  25536. for (j = 0, n = fileId.length; j < n; ++j) {
  25537. hashData[i++] = fileId[j];
  25538. }
  25539. cipher = new ARCFourCipher(encryptionKey);
  25540. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  25541. n = encryptionKey.length;
  25542. var derivedKey = new Uint8Array(n), k;
  25543. for (j = 1; j <= 19; ++j) {
  25544. for (k = 0; k < n; ++k) {
  25545. derivedKey[k] = encryptionKey[k] ^ j;
  25546. }
  25547. cipher = new ARCFourCipher(derivedKey);
  25548. checkData = cipher.encryptBlock(checkData);
  25549. }
  25550. for (j = 0, n = checkData.length; j < n; ++j) {
  25551. if (userPassword[j] !== checkData[j]) {
  25552. return null;
  25553. }
  25554. }
  25555. } else {
  25556. cipher = new ARCFourCipher(encryptionKey);
  25557. checkData = cipher.encryptBlock(defaultPasswordBytes);
  25558. for (j = 0, n = checkData.length; j < n; ++j) {
  25559. if (userPassword[j] !== checkData[j]) {
  25560. return null;
  25561. }
  25562. }
  25563. }
  25564. return encryptionKey;
  25565. }
  25566. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  25567. var hashData = new Uint8Array(32), i = 0, j, n;
  25568. n = Math.min(32, password.length);
  25569. for (; i < n; ++i) {
  25570. hashData[i] = password[i];
  25571. }
  25572. j = 0;
  25573. while (i < 32) {
  25574. hashData[i++] = defaultPasswordBytes[j++];
  25575. }
  25576. var hash = calculateMD5(hashData, 0, i);
  25577. var keyLengthInBytes = keyLength >> 3;
  25578. if (revision >= 3) {
  25579. for (j = 0; j < 50; ++j) {
  25580. hash = calculateMD5(hash, 0, hash.length);
  25581. }
  25582. }
  25583. var cipher, userPassword;
  25584. if (revision >= 3) {
  25585. userPassword = ownerPassword;
  25586. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  25587. for (j = 19; j >= 0; j--) {
  25588. for (k = 0; k < keyLengthInBytes; ++k) {
  25589. derivedKey[k] = hash[k] ^ j;
  25590. }
  25591. cipher = new ARCFourCipher(derivedKey);
  25592. userPassword = cipher.encryptBlock(userPassword);
  25593. }
  25594. } else {
  25595. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  25596. userPassword = cipher.encryptBlock(ownerPassword);
  25597. }
  25598. return userPassword;
  25599. }
  25600. var identityName = Name.get('Identity');
  25601. function CipherTransformFactory(dict, fileId, password) {
  25602. var filter = dict.get('Filter');
  25603. if (!isName(filter) || filter.name !== 'Standard') {
  25604. error('unknown encryption method');
  25605. }
  25606. this.dict = dict;
  25607. var algorithm = dict.get('V');
  25608. if (!isInt(algorithm) ||
  25609. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  25610. algorithm !== 5)) {
  25611. error('unsupported encryption algorithm');
  25612. }
  25613. this.algorithm = algorithm;
  25614. var keyLength = dict.get('Length') || 40;
  25615. if (!isInt(keyLength) ||
  25616. keyLength < 40 || (keyLength % 8) !== 0) {
  25617. error('invalid key length');
  25618. }
  25619. // prepare keys
  25620. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  25621. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  25622. var flags = dict.get('P');
  25623. var revision = dict.get('R');
  25624. // meaningful when V is 4 or 5
  25625. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  25626. dict.get('EncryptMetadata') !== false);
  25627. this.encryptMetadata = encryptMetadata;
  25628. var fileIdBytes = stringToBytes(fileId);
  25629. var passwordBytes;
  25630. if (password) {
  25631. if (revision === 6) {
  25632. try {
  25633. password = utf8StringToString(password);
  25634. } catch (ex) {
  25635. warn('CipherTransformFactory: ' +
  25636. 'Unable to convert UTF8 encoded password.');
  25637. }
  25638. }
  25639. passwordBytes = stringToBytes(password);
  25640. }
  25641. var encryptionKey;
  25642. if (algorithm !== 5) {
  25643. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  25644. ownerPassword, userPassword, flags,
  25645. revision, keyLength, encryptMetadata);
  25646. }
  25647. else {
  25648. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  25649. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  25650. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  25651. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  25652. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  25653. var ownerEncryption = stringToBytes(dict.get('OE'));
  25654. var userEncryption = stringToBytes(dict.get('UE'));
  25655. var perms = stringToBytes(dict.get('Perms'));
  25656. encryptionKey =
  25657. createEncryptionKey20(revision, passwordBytes,
  25658. ownerPassword, ownerValidationSalt,
  25659. ownerKeySalt, uBytes,
  25660. userPassword, userValidationSalt,
  25661. userKeySalt, ownerEncryption,
  25662. userEncryption, perms);
  25663. }
  25664. if (!encryptionKey && !password) {
  25665. throw new PasswordException('No password given',
  25666. PasswordResponses.NEED_PASSWORD);
  25667. } else if (!encryptionKey && password) {
  25668. // Attempting use the password as an owner password
  25669. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  25670. revision, keyLength);
  25671. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  25672. ownerPassword, userPassword, flags,
  25673. revision, keyLength, encryptMetadata);
  25674. }
  25675. if (!encryptionKey) {
  25676. throw new PasswordException('Incorrect Password',
  25677. PasswordResponses.INCORRECT_PASSWORD);
  25678. }
  25679. this.encryptionKey = encryptionKey;
  25680. if (algorithm >= 4) {
  25681. this.cf = dict.get('CF');
  25682. this.stmf = dict.get('StmF') || identityName;
  25683. this.strf = dict.get('StrF') || identityName;
  25684. this.eff = dict.get('EFF') || this.stmf;
  25685. }
  25686. }
  25687. function buildObjectKey(num, gen, encryptionKey, isAes) {
  25688. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  25689. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  25690. key[i] = encryptionKey[i];
  25691. }
  25692. key[i++] = num & 0xFF;
  25693. key[i++] = (num >> 8) & 0xFF;
  25694. key[i++] = (num >> 16) & 0xFF;
  25695. key[i++] = gen & 0xFF;
  25696. key[i++] = (gen >> 8) & 0xFF;
  25697. if (isAes) {
  25698. key[i++] = 0x73;
  25699. key[i++] = 0x41;
  25700. key[i++] = 0x6C;
  25701. key[i++] = 0x54;
  25702. }
  25703. var hash = calculateMD5(key, 0, i);
  25704. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  25705. }
  25706. function buildCipherConstructor(cf, name, num, gen, key) {
  25707. var cryptFilter = cf.get(name.name);
  25708. var cfm;
  25709. if (cryptFilter !== null && cryptFilter !== undefined) {
  25710. cfm = cryptFilter.get('CFM');
  25711. }
  25712. if (!cfm || cfm.name === 'None') {
  25713. return function cipherTransformFactoryBuildCipherConstructorNone() {
  25714. return new NullCipher();
  25715. };
  25716. }
  25717. if ('V2' === cfm.name) {
  25718. return function cipherTransformFactoryBuildCipherConstructorV2() {
  25719. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  25720. };
  25721. }
  25722. if ('AESV2' === cfm.name) {
  25723. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  25724. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  25725. };
  25726. }
  25727. if ('AESV3' === cfm.name) {
  25728. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  25729. return new AES256Cipher(key);
  25730. };
  25731. }
  25732. error('Unknown crypto method');
  25733. }
  25734. CipherTransformFactory.prototype = {
  25735. createCipherTransform:
  25736. function CipherTransformFactory_createCipherTransform(num, gen) {
  25737. if (this.algorithm === 4 || this.algorithm === 5) {
  25738. return new CipherTransform(
  25739. buildCipherConstructor(this.cf, this.stmf,
  25740. num, gen, this.encryptionKey),
  25741. buildCipherConstructor(this.cf, this.strf,
  25742. num, gen, this.encryptionKey));
  25743. }
  25744. // algorithms 1 and 2
  25745. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  25746. var cipherConstructor = function buildCipherCipherConstructor() {
  25747. return new ARCFourCipher(key);
  25748. };
  25749. return new CipherTransform(cipherConstructor, cipherConstructor);
  25750. }
  25751. };
  25752. return CipherTransformFactory;
  25753. })();
  25754. exports.AES128Cipher = AES128Cipher;
  25755. exports.AES256Cipher = AES256Cipher;
  25756. exports.ARCFourCipher = ARCFourCipher;
  25757. exports.CipherTransformFactory = CipherTransformFactory;
  25758. exports.PDF17 = PDF17;
  25759. exports.PDF20 = PDF20;
  25760. exports.calculateMD5 = calculateMD5;
  25761. exports.calculateSHA256 = calculateSHA256;
  25762. exports.calculateSHA384 = calculateSHA384;
  25763. exports.calculateSHA512 = calculateSHA512;
  25764. }));
  25765. (function (root, factory) {
  25766. {
  25767. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  25768. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  25769. }
  25770. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  25771. var Util = sharedUtil.Util;
  25772. var bytesToString = sharedUtil.bytesToString;
  25773. var error = sharedUtil.error;
  25774. var Stream = coreStream.Stream;
  25775. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  25776. var coreFonts; // see _setCoreFonts below
  25777. var CFFParser; // = coreFonts.CFFParser;
  25778. var Encodings; // = coreFonts.Encodings;
  25779. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25780. function getLong(data, offset) {
  25781. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25782. (data[offset + 2] << 8) | data[offset + 3];
  25783. }
  25784. function getUshort(data, offset) {
  25785. return (data[offset] << 8) | data[offset + 1];
  25786. }
  25787. function parseCmap(data, start, end) {
  25788. var offset = (getUshort(data, start + 2) === 1 ?
  25789. getLong(data, start + 8) : getLong(data, start + 16));
  25790. var format = getUshort(data, start + offset);
  25791. var length, ranges, p, i;
  25792. if (format === 4) {
  25793. length = getUshort(data, start + offset + 2);
  25794. var segCount = getUshort(data, start + offset + 6) >> 1;
  25795. p = start + offset + 14;
  25796. ranges = [];
  25797. for (i = 0; i < segCount; i++, p += 2) {
  25798. ranges[i] = {end: getUshort(data, p)};
  25799. }
  25800. p += 2;
  25801. for (i = 0; i < segCount; i++, p += 2) {
  25802. ranges[i].start = getUshort(data, p);
  25803. }
  25804. for (i = 0; i < segCount; i++, p += 2) {
  25805. ranges[i].idDelta = getUshort(data, p);
  25806. }
  25807. for (i = 0; i < segCount; i++, p += 2) {
  25808. var idOffset = getUshort(data, p);
  25809. if (idOffset === 0) {
  25810. continue;
  25811. }
  25812. ranges[i].ids = [];
  25813. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25814. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25815. idOffset += 2;
  25816. }
  25817. }
  25818. return ranges;
  25819. } else if (format === 12) {
  25820. length = getLong(data, start + offset + 4);
  25821. var groups = getLong(data, start + offset + 12);
  25822. p = start + offset + 16;
  25823. ranges = [];
  25824. for (i = 0; i < groups; i++) {
  25825. ranges.push({
  25826. start: getLong(data, p),
  25827. end: getLong(data, p + 4),
  25828. idDelta: getLong(data, p + 8) - getLong(data, p)
  25829. });
  25830. p += 12;
  25831. }
  25832. return ranges;
  25833. }
  25834. error('not supported cmap: ' + format);
  25835. }
  25836. function parseCff(data, start, end) {
  25837. var properties = {};
  25838. var parser = new CFFParser(new Stream(data, start, end - start),
  25839. properties);
  25840. var cff = parser.parse();
  25841. return {
  25842. glyphs: cff.charStrings.objects,
  25843. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25844. cff.topDict.privateDict.subrsIndex.objects),
  25845. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25846. };
  25847. }
  25848. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25849. var itemSize, itemDecode;
  25850. if (isGlyphLocationsLong) {
  25851. itemSize = 4;
  25852. itemDecode = function fontItemDecodeLong(data, offset) {
  25853. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25854. (data[offset + 2] << 8) | data[offset + 3];
  25855. };
  25856. } else {
  25857. itemSize = 2;
  25858. itemDecode = function fontItemDecode(data, offset) {
  25859. return (data[offset] << 9) | (data[offset + 1] << 1);
  25860. };
  25861. }
  25862. var glyphs = [];
  25863. var startOffset = itemDecode(loca, 0);
  25864. for (var j = itemSize; j < loca.length; j += itemSize) {
  25865. var endOffset = itemDecode(loca, j);
  25866. glyphs.push(glyf.subarray(startOffset, endOffset));
  25867. startOffset = endOffset;
  25868. }
  25869. return glyphs;
  25870. }
  25871. function lookupCmap(ranges, unicode) {
  25872. var code = unicode.charCodeAt(0);
  25873. var l = 0, r = ranges.length - 1;
  25874. while (l < r) {
  25875. var c = (l + r + 1) >> 1;
  25876. if (code < ranges[c].start) {
  25877. r = c - 1;
  25878. } else {
  25879. l = c;
  25880. }
  25881. }
  25882. if (ranges[l].start <= code && code <= ranges[l].end) {
  25883. return (ranges[l].idDelta + (ranges[l].ids ?
  25884. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25885. }
  25886. return 0;
  25887. }
  25888. function compileGlyf(code, cmds, font) {
  25889. function moveTo(x, y) {
  25890. cmds.push({cmd: 'moveTo', args: [x, y]});
  25891. }
  25892. function lineTo(x, y) {
  25893. cmds.push({cmd: 'lineTo', args: [x, y]});
  25894. }
  25895. function quadraticCurveTo(xa, ya, x, y) {
  25896. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25897. }
  25898. var i = 0;
  25899. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25900. var flags;
  25901. var x = 0, y = 0;
  25902. i += 10;
  25903. if (numberOfContours < 0) {
  25904. // composite glyph
  25905. do {
  25906. flags = (code[i] << 8) | code[i + 1];
  25907. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25908. i += 4;
  25909. var arg1, arg2;
  25910. if ((flags & 0x01)) {
  25911. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25912. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25913. i += 4;
  25914. } else {
  25915. arg1 = code[i++]; arg2 = code[i++];
  25916. }
  25917. if ((flags & 0x02)) {
  25918. x = arg1;
  25919. y = arg2;
  25920. } else {
  25921. x = 0; y = 0; // TODO "they are points" ?
  25922. }
  25923. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25924. if ((flags & 0x08)) {
  25925. scaleX =
  25926. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25927. i += 2;
  25928. } else if ((flags & 0x40)) {
  25929. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25930. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25931. i += 4;
  25932. } else if ((flags & 0x80)) {
  25933. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25934. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25935. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25936. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25937. i += 8;
  25938. }
  25939. var subglyph = font.glyphs[glyphIndex];
  25940. if (subglyph) {
  25941. cmds.push({cmd: 'save'});
  25942. cmds.push({cmd: 'transform',
  25943. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25944. compileGlyf(subglyph, cmds, font);
  25945. cmds.push({cmd: 'restore'});
  25946. }
  25947. } while ((flags & 0x20));
  25948. } else {
  25949. // simple glyph
  25950. var endPtsOfContours = [];
  25951. var j, jj;
  25952. for (j = 0; j < numberOfContours; j++) {
  25953. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25954. i += 2;
  25955. }
  25956. var instructionLength = (code[i] << 8) | code[i + 1];
  25957. i += 2 + instructionLength; // skipping the instructions
  25958. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25959. var points = [];
  25960. while (points.length < numberOfPoints) {
  25961. flags = code[i++];
  25962. var repeat = 1;
  25963. if ((flags & 0x08)) {
  25964. repeat += code[i++];
  25965. }
  25966. while (repeat-- > 0) {
  25967. points.push({flags: flags});
  25968. }
  25969. }
  25970. for (j = 0; j < numberOfPoints; j++) {
  25971. switch (points[j].flags & 0x12) {
  25972. case 0x00:
  25973. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25974. i += 2;
  25975. break;
  25976. case 0x02:
  25977. x -= code[i++];
  25978. break;
  25979. case 0x12:
  25980. x += code[i++];
  25981. break;
  25982. }
  25983. points[j].x = x;
  25984. }
  25985. for (j = 0; j < numberOfPoints; j++) {
  25986. switch (points[j].flags & 0x24) {
  25987. case 0x00:
  25988. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25989. i += 2;
  25990. break;
  25991. case 0x04:
  25992. y -= code[i++];
  25993. break;
  25994. case 0x24:
  25995. y += code[i++];
  25996. break;
  25997. }
  25998. points[j].y = y;
  25999. }
  26000. var startPoint = 0;
  26001. for (i = 0; i < numberOfContours; i++) {
  26002. var endPoint = endPtsOfContours[i];
  26003. // contours might have implicit points, which is located in the middle
  26004. // between two neighboring off-curve points
  26005. var contour = points.slice(startPoint, endPoint + 1);
  26006. if ((contour[0].flags & 1)) {
  26007. contour.push(contour[0]); // using start point at the contour end
  26008. } else if ((contour[contour.length - 1].flags & 1)) {
  26009. // first is off-curve point, trying to use one from the end
  26010. contour.unshift(contour[contour.length - 1]);
  26011. } else {
  26012. // start and end are off-curve points, creating implicit one
  26013. var p = {
  26014. flags: 1,
  26015. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26016. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26017. };
  26018. contour.unshift(p);
  26019. contour.push(p);
  26020. }
  26021. moveTo(contour[0].x, contour[0].y);
  26022. for (j = 1, jj = contour.length; j < jj; j++) {
  26023. if ((contour[j].flags & 1)) {
  26024. lineTo(contour[j].x, contour[j].y);
  26025. } else if ((contour[j + 1].flags & 1)){
  26026. quadraticCurveTo(contour[j].x, contour[j].y,
  26027. contour[j + 1].x, contour[j + 1].y);
  26028. j++;
  26029. } else {
  26030. quadraticCurveTo(contour[j].x, contour[j].y,
  26031. (contour[j].x + contour[j + 1].x) / 2,
  26032. (contour[j].y + contour[j + 1].y) / 2);
  26033. }
  26034. }
  26035. startPoint = endPoint + 1;
  26036. }
  26037. }
  26038. }
  26039. function compileCharString(code, cmds, font) {
  26040. var stack = [];
  26041. var x = 0, y = 0;
  26042. var stems = 0;
  26043. function moveTo(x, y) {
  26044. cmds.push({cmd: 'moveTo', args: [x, y]});
  26045. }
  26046. function lineTo(x, y) {
  26047. cmds.push({cmd: 'lineTo', args: [x, y]});
  26048. }
  26049. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26050. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26051. }
  26052. function parse(code) {
  26053. var i = 0;
  26054. while (i < code.length) {
  26055. var stackClean = false;
  26056. var v = code[i++];
  26057. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26058. switch (v) {
  26059. case 1: // hstem
  26060. stems += stack.length >> 1;
  26061. stackClean = true;
  26062. break;
  26063. case 3: // vstem
  26064. stems += stack.length >> 1;
  26065. stackClean = true;
  26066. break;
  26067. case 4: // vmoveto
  26068. y += stack.pop();
  26069. moveTo(x, y);
  26070. stackClean = true;
  26071. break;
  26072. case 5: // rlineto
  26073. while (stack.length > 0) {
  26074. x += stack.shift();
  26075. y += stack.shift();
  26076. lineTo(x, y);
  26077. }
  26078. break;
  26079. case 6: // hlineto
  26080. while (stack.length > 0) {
  26081. x += stack.shift();
  26082. lineTo(x, y);
  26083. if (stack.length === 0) {
  26084. break;
  26085. }
  26086. y += stack.shift();
  26087. lineTo(x, y);
  26088. }
  26089. break;
  26090. case 7: // vlineto
  26091. while (stack.length > 0) {
  26092. y += stack.shift();
  26093. lineTo(x, y);
  26094. if (stack.length === 0) {
  26095. break;
  26096. }
  26097. x += stack.shift();
  26098. lineTo(x, y);
  26099. }
  26100. break;
  26101. case 8: // rrcurveto
  26102. while (stack.length > 0) {
  26103. xa = x + stack.shift(); ya = y + stack.shift();
  26104. xb = xa + stack.shift(); yb = ya + stack.shift();
  26105. x = xb + stack.shift(); y = yb + stack.shift();
  26106. bezierCurveTo(xa, ya, xb, yb, x, y);
  26107. }
  26108. break;
  26109. case 10: // callsubr
  26110. n = stack.pop() + font.subrsBias;
  26111. subrCode = font.subrs[n];
  26112. if (subrCode) {
  26113. parse(subrCode);
  26114. }
  26115. break;
  26116. case 11: // return
  26117. return;
  26118. case 12:
  26119. v = code[i++];
  26120. switch (v) {
  26121. case 34: // flex
  26122. xa = x + stack.shift();
  26123. xb = xa + stack.shift(); y1 = y + stack.shift();
  26124. x = xb + stack.shift();
  26125. bezierCurveTo(xa, y, xb, y1, x, y1);
  26126. xa = x + stack.shift();
  26127. xb = xa + stack.shift();
  26128. x = xb + stack.shift();
  26129. bezierCurveTo(xa, y1, xb, y, x, y);
  26130. break;
  26131. case 35: // flex
  26132. xa = x + stack.shift(); ya = y + stack.shift();
  26133. xb = xa + stack.shift(); yb = ya + stack.shift();
  26134. x = xb + stack.shift(); y = yb + stack.shift();
  26135. bezierCurveTo(xa, ya, xb, yb, x, y);
  26136. xa = x + stack.shift(); ya = y + stack.shift();
  26137. xb = xa + stack.shift(); yb = ya + stack.shift();
  26138. x = xb + stack.shift(); y = yb + stack.shift();
  26139. bezierCurveTo(xa, ya, xb, yb, x, y);
  26140. stack.pop(); // fd
  26141. break;
  26142. case 36: // hflex1
  26143. xa = x + stack.shift(); y1 = y + stack.shift();
  26144. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  26145. x = xb + stack.shift();
  26146. bezierCurveTo(xa, y1, xb, y2, x, y2);
  26147. xa = x + stack.shift();
  26148. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  26149. x = xb + stack.shift();
  26150. bezierCurveTo(xa, y2, xb, y3, x, y);
  26151. break;
  26152. case 37: // flex1
  26153. var x0 = x, y0 = y;
  26154. xa = x + stack.shift(); ya = y + stack.shift();
  26155. xb = xa + stack.shift(); yb = ya + stack.shift();
  26156. x = xb + stack.shift(); y = yb + stack.shift();
  26157. bezierCurveTo(xa, ya, xb, yb, x, y);
  26158. xa = x + stack.shift(); ya = y + stack.shift();
  26159. xb = xa + stack.shift(); yb = ya + stack.shift();
  26160. x = xb; y = yb;
  26161. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  26162. x += stack.shift();
  26163. } else {
  26164. y += stack.shift();
  26165. }
  26166. bezierCurveTo(xa, ya, xb, yb, x, y);
  26167. break;
  26168. default:
  26169. error('unknown operator: 12 ' + v);
  26170. }
  26171. break;
  26172. case 14: // endchar
  26173. if (stack.length >= 4) {
  26174. var achar = stack.pop();
  26175. var bchar = stack.pop();
  26176. y = stack.pop();
  26177. x = stack.pop();
  26178. cmds.push({cmd: 'save'});
  26179. cmds.push({cmd: 'translate', args: [x, y]});
  26180. var gid = lookupCmap(font.cmap, String.fromCharCode(
  26181. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  26182. compileCharString(font.glyphs[gid], cmds, font);
  26183. cmds.push({cmd: 'restore'});
  26184. gid = lookupCmap(font.cmap, String.fromCharCode(
  26185. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  26186. compileCharString(font.glyphs[gid], cmds, font);
  26187. }
  26188. return;
  26189. case 18: // hstemhm
  26190. stems += stack.length >> 1;
  26191. stackClean = true;
  26192. break;
  26193. case 19: // hintmask
  26194. stems += stack.length >> 1;
  26195. i += (stems + 7) >> 3;
  26196. stackClean = true;
  26197. break;
  26198. case 20: // cntrmask
  26199. stems += stack.length >> 1;
  26200. i += (stems + 7) >> 3;
  26201. stackClean = true;
  26202. break;
  26203. case 21: // rmoveto
  26204. y += stack.pop();
  26205. x += stack.pop();
  26206. moveTo(x, y);
  26207. stackClean = true;
  26208. break;
  26209. case 22: // hmoveto
  26210. x += stack.pop();
  26211. moveTo(x, y);
  26212. stackClean = true;
  26213. break;
  26214. case 23: // vstemhm
  26215. stems += stack.length >> 1;
  26216. stackClean = true;
  26217. break;
  26218. case 24: // rcurveline
  26219. while (stack.length > 2) {
  26220. xa = x + stack.shift(); ya = y + stack.shift();
  26221. xb = xa + stack.shift(); yb = ya + stack.shift();
  26222. x = xb + stack.shift(); y = yb + stack.shift();
  26223. bezierCurveTo(xa, ya, xb, yb, x, y);
  26224. }
  26225. x += stack.shift();
  26226. y += stack.shift();
  26227. lineTo(x, y);
  26228. break;
  26229. case 25: // rlinecurve
  26230. while (stack.length > 6) {
  26231. x += stack.shift();
  26232. y += stack.shift();
  26233. lineTo(x, y);
  26234. }
  26235. xa = x + stack.shift(); ya = y + stack.shift();
  26236. xb = xa + stack.shift(); yb = ya + stack.shift();
  26237. x = xb + stack.shift(); y = yb + stack.shift();
  26238. bezierCurveTo(xa, ya, xb, yb, x, y);
  26239. break;
  26240. case 26: // vvcurveto
  26241. if (stack.length % 2) {
  26242. x += stack.shift();
  26243. }
  26244. while (stack.length > 0) {
  26245. xa = x; ya = y + stack.shift();
  26246. xb = xa + stack.shift(); yb = ya + stack.shift();
  26247. x = xb; y = yb + stack.shift();
  26248. bezierCurveTo(xa, ya, xb, yb, x, y);
  26249. }
  26250. break;
  26251. case 27: // hhcurveto
  26252. if (stack.length % 2) {
  26253. y += stack.shift();
  26254. }
  26255. while (stack.length > 0) {
  26256. xa = x + stack.shift(); ya = y;
  26257. xb = xa + stack.shift(); yb = ya + stack.shift();
  26258. x = xb + stack.shift(); y = yb;
  26259. bezierCurveTo(xa, ya, xb, yb, x, y);
  26260. }
  26261. break;
  26262. case 28:
  26263. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  26264. i += 2;
  26265. break;
  26266. case 29: // callgsubr
  26267. n = stack.pop() + font.gsubrsBias;
  26268. subrCode = font.gsubrs[n];
  26269. if (subrCode) {
  26270. parse(subrCode);
  26271. }
  26272. break;
  26273. case 30: // vhcurveto
  26274. while (stack.length > 0) {
  26275. xa = x; ya = y + stack.shift();
  26276. xb = xa + stack.shift(); yb = ya + stack.shift();
  26277. x = xb + stack.shift();
  26278. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26279. bezierCurveTo(xa, ya, xb, yb, x, y);
  26280. if (stack.length === 0) {
  26281. break;
  26282. }
  26283. xa = x + stack.shift(); ya = y;
  26284. xb = xa + stack.shift(); yb = ya + stack.shift();
  26285. y = yb + stack.shift();
  26286. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26287. bezierCurveTo(xa, ya, xb, yb, x, y);
  26288. }
  26289. break;
  26290. case 31: // hvcurveto
  26291. while (stack.length > 0) {
  26292. xa = x + stack.shift(); ya = y;
  26293. xb = xa + stack.shift(); yb = ya + stack.shift();
  26294. y = yb + stack.shift();
  26295. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26296. bezierCurveTo(xa, ya, xb, yb, x, y);
  26297. if (stack.length === 0) {
  26298. break;
  26299. }
  26300. xa = x; ya = y + stack.shift();
  26301. xb = xa + stack.shift(); yb = ya + stack.shift();
  26302. x = xb + stack.shift();
  26303. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26304. bezierCurveTo(xa, ya, xb, yb, x, y);
  26305. }
  26306. break;
  26307. default:
  26308. if (v < 32) {
  26309. error('unknown operator: ' + v);
  26310. }
  26311. if (v < 247) {
  26312. stack.push(v - 139);
  26313. } else if (v < 251) {
  26314. stack.push((v - 247) * 256 + code[i++] + 108);
  26315. } else if (v < 255) {
  26316. stack.push(-(v - 251) * 256 - code[i++] - 108);
  26317. } else {
  26318. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  26319. (code[i + 2] << 8) | code[i + 3]) / 65536);
  26320. i += 4;
  26321. }
  26322. break;
  26323. }
  26324. if (stackClean) {
  26325. stack.length = 0;
  26326. }
  26327. }
  26328. }
  26329. parse(code);
  26330. }
  26331. var noop = '';
  26332. function CompiledFont(fontMatrix) {
  26333. this.compiledGlyphs = {};
  26334. this.fontMatrix = fontMatrix;
  26335. }
  26336. CompiledFont.prototype = {
  26337. getPathJs: function (unicode) {
  26338. var gid = lookupCmap(this.cmap, unicode);
  26339. var fn = this.compiledGlyphs[gid];
  26340. if (!fn) {
  26341. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  26342. }
  26343. return fn;
  26344. },
  26345. compileGlyph: function (code) {
  26346. if (!code || code.length === 0 || code[0] === 14) {
  26347. return noop;
  26348. }
  26349. var cmds = [];
  26350. cmds.push({cmd: 'save'});
  26351. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  26352. cmds.push({cmd: 'scale', args: ['size', '-size']});
  26353. this.compileGlyphImpl(code, cmds);
  26354. cmds.push({cmd: 'restore'});
  26355. return cmds;
  26356. },
  26357. compileGlyphImpl: function () {
  26358. error('Children classes should implement this.');
  26359. },
  26360. hasBuiltPath: function (unicode) {
  26361. var gid = lookupCmap(this.cmap, unicode);
  26362. return gid in this.compiledGlyphs;
  26363. }
  26364. };
  26365. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  26366. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  26367. CompiledFont.call(this, fontMatrix);
  26368. this.glyphs = glyphs;
  26369. this.cmap = cmap;
  26370. this.compiledGlyphs = [];
  26371. }
  26372. Util.inherit(TrueTypeCompiled, CompiledFont, {
  26373. compileGlyphImpl: function (code, cmds) {
  26374. compileGlyf(code, cmds, this);
  26375. }
  26376. });
  26377. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  26378. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  26379. CompiledFont.call(this, fontMatrix);
  26380. this.glyphs = cffInfo.glyphs;
  26381. this.gsubrs = cffInfo.gsubrs || [];
  26382. this.subrs = cffInfo.subrs || [];
  26383. this.cmap = cmap;
  26384. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  26385. this.compiledGlyphs = [];
  26386. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  26387. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  26388. this.subrsBias = (this.subrs.length < 1240 ?
  26389. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  26390. }
  26391. Util.inherit(Type2Compiled, CompiledFont, {
  26392. compileGlyphImpl: function (code, cmds) {
  26393. compileCharString(code, cmds, this);
  26394. }
  26395. });
  26396. return {
  26397. create: function FontRendererFactory_create(font) {
  26398. var data = new Uint8Array(font.data);
  26399. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  26400. var numTables = getUshort(data, 4);
  26401. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  26402. var tag = bytesToString(data.subarray(p, p + 4));
  26403. var offset = getLong(data, p + 8);
  26404. var length = getLong(data, p + 12);
  26405. switch (tag) {
  26406. case 'cmap':
  26407. cmap = parseCmap(data, offset, offset + length);
  26408. break;
  26409. case 'glyf':
  26410. glyf = data.subarray(offset, offset + length);
  26411. break;
  26412. case 'loca':
  26413. loca = data.subarray(offset, offset + length);
  26414. break;
  26415. case 'head':
  26416. unitsPerEm = getUshort(data, offset + 18);
  26417. indexToLocFormat = getUshort(data, offset + 50);
  26418. break;
  26419. case 'CFF ':
  26420. cff = parseCff(data, offset, offset + length);
  26421. break;
  26422. }
  26423. }
  26424. if (glyf) {
  26425. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  26426. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  26427. return new TrueTypeCompiled(
  26428. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  26429. } else {
  26430. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  26431. }
  26432. }
  26433. };
  26434. })();
  26435. // TODO refactor to remove cyclic dependency on fonts.js
  26436. function _setCoreFonts(coreFonts_) {
  26437. coreFonts = coreFonts_;
  26438. Encodings = coreFonts_.Encodings;
  26439. CFFParser = coreFonts_.CFFParser;
  26440. }
  26441. exports._setCoreFonts = _setCoreFonts;
  26442. exports.FontRendererFactory = FontRendererFactory;
  26443. }));
  26444. (function (root, factory) {
  26445. {
  26446. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  26447. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  26448. }
  26449. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  26450. var MissingDataException = sharedUtil.MissingDataException;
  26451. var StreamType = sharedUtil.StreamType;
  26452. var assert = sharedUtil.assert;
  26453. var error = sharedUtil.error;
  26454. var info = sharedUtil.info;
  26455. var isArray = sharedUtil.isArray;
  26456. var isInt = sharedUtil.isInt;
  26457. var isNum = sharedUtil.isNum;
  26458. var isString = sharedUtil.isString;
  26459. var warn = sharedUtil.warn;
  26460. var Cmd = corePrimitives.Cmd;
  26461. var Dict = corePrimitives.Dict;
  26462. var Name = corePrimitives.Name;
  26463. var Ref = corePrimitives.Ref;
  26464. var isCmd = corePrimitives.isCmd;
  26465. var isDict = corePrimitives.isDict;
  26466. var isName = corePrimitives.isName;
  26467. var Ascii85Stream = coreStream.Ascii85Stream;
  26468. var AsciiHexStream = coreStream.AsciiHexStream;
  26469. var CCITTFaxStream = coreStream.CCITTFaxStream;
  26470. var FlateStream = coreStream.FlateStream;
  26471. var Jbig2Stream = coreStream.Jbig2Stream;
  26472. var JpegStream = coreStream.JpegStream;
  26473. var JpxStream = coreStream.JpxStream;
  26474. var LZWStream = coreStream.LZWStream;
  26475. var NullStream = coreStream.NullStream;
  26476. var PredictorStream = coreStream.PredictorStream;
  26477. var RunLengthStream = coreStream.RunLengthStream;
  26478. var EOF = {};
  26479. function isEOF(v) {
  26480. return (v === EOF);
  26481. }
  26482. var MAX_LENGTH_TO_CACHE = 1000;
  26483. var Parser = (function ParserClosure() {
  26484. function Parser(lexer, allowStreams, xref) {
  26485. this.lexer = lexer;
  26486. this.allowStreams = allowStreams;
  26487. this.xref = xref;
  26488. this.imageCache = {};
  26489. this.refill();
  26490. }
  26491. Parser.prototype = {
  26492. refill: function Parser_refill() {
  26493. this.buf1 = this.lexer.getObj();
  26494. this.buf2 = this.lexer.getObj();
  26495. },
  26496. shift: function Parser_shift() {
  26497. if (isCmd(this.buf2, 'ID')) {
  26498. this.buf1 = this.buf2;
  26499. this.buf2 = null;
  26500. } else {
  26501. this.buf1 = this.buf2;
  26502. this.buf2 = this.lexer.getObj();
  26503. }
  26504. },
  26505. tryShift: function Parser_tryShift() {
  26506. try {
  26507. this.shift();
  26508. return true;
  26509. } catch (e) {
  26510. if (e instanceof MissingDataException) {
  26511. throw e;
  26512. }
  26513. // Upon failure, the caller should reset this.lexer.pos to a known good
  26514. // state and call this.shift() twice to reset the buffers.
  26515. return false;
  26516. }
  26517. },
  26518. getObj: function Parser_getObj(cipherTransform) {
  26519. var buf1 = this.buf1;
  26520. this.shift();
  26521. if (buf1 instanceof Cmd) {
  26522. switch (buf1.cmd) {
  26523. case 'BI': // inline image
  26524. return this.makeInlineImage(cipherTransform);
  26525. case '[': // array
  26526. var array = [];
  26527. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  26528. array.push(this.getObj(cipherTransform));
  26529. }
  26530. if (isEOF(this.buf1)) {
  26531. error('End of file inside array');
  26532. }
  26533. this.shift();
  26534. return array;
  26535. case '<<': // dictionary or stream
  26536. var dict = new Dict(this.xref);
  26537. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  26538. if (!isName(this.buf1)) {
  26539. info('Malformed dictionary: key must be a name object');
  26540. this.shift();
  26541. continue;
  26542. }
  26543. var key = this.buf1.name;
  26544. this.shift();
  26545. if (isEOF(this.buf1)) {
  26546. break;
  26547. }
  26548. dict.set(key, this.getObj(cipherTransform));
  26549. }
  26550. if (isEOF(this.buf1)) {
  26551. error('End of file inside dictionary');
  26552. }
  26553. // Stream objects are not allowed inside content streams or
  26554. // object streams.
  26555. if (isCmd(this.buf2, 'stream')) {
  26556. return (this.allowStreams ?
  26557. this.makeStream(dict, cipherTransform) : dict);
  26558. }
  26559. this.shift();
  26560. return dict;
  26561. default: // simple object
  26562. return buf1;
  26563. }
  26564. }
  26565. if (isInt(buf1)) { // indirect reference or integer
  26566. var num = buf1;
  26567. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  26568. var ref = new Ref(num, this.buf1);
  26569. this.shift();
  26570. this.shift();
  26571. return ref;
  26572. }
  26573. return num;
  26574. }
  26575. if (isString(buf1)) { // string
  26576. var str = buf1;
  26577. if (cipherTransform) {
  26578. str = cipherTransform.decryptString(str);
  26579. }
  26580. return str;
  26581. }
  26582. // simple object
  26583. return buf1;
  26584. },
  26585. /**
  26586. * Find the end of the stream by searching for the /EI\s/.
  26587. * @returns {number} The inline stream length.
  26588. */
  26589. findDefaultInlineStreamEnd:
  26590. function Parser_findDefaultInlineStreamEnd(stream) {
  26591. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  26592. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  26593. while ((ch = stream.getByte()) !== -1) {
  26594. if (state === 0) {
  26595. state = (ch === E) ? 1 : 0;
  26596. } else if (state === 1) {
  26597. state = (ch === I) ? 2 : 0;
  26598. } else {
  26599. assert(state === 2);
  26600. if (ch === SPACE || ch === LF || ch === CR) {
  26601. // Let's check the next five bytes are ASCII... just be sure.
  26602. n = 5;
  26603. followingBytes = stream.peekBytes(n);
  26604. for (i = 0; i < n; i++) {
  26605. ch = followingBytes[i];
  26606. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  26607. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  26608. // it's binary stuff. Resetting the state.
  26609. state = 0;
  26610. break;
  26611. }
  26612. }
  26613. if (state === 2) {
  26614. break; // Finished!
  26615. }
  26616. } else {
  26617. state = 0;
  26618. }
  26619. }
  26620. }
  26621. return ((stream.pos - 4) - startPos);
  26622. },
  26623. /**
  26624. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  26625. * @returns {number} The inline stream length.
  26626. */
  26627. findDCTDecodeInlineStreamEnd:
  26628. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  26629. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  26630. while ((b = stream.getByte()) !== -1) {
  26631. if (b !== 0xFF) { // Not a valid marker.
  26632. continue;
  26633. }
  26634. switch (stream.getByte()) {
  26635. case 0x00: // Byte stuffing.
  26636. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  26637. break;
  26638. case 0xFF: // Fill byte.
  26639. // Avoid skipping a valid marker, resetting the stream position.
  26640. stream.skip(-1);
  26641. break;
  26642. case 0xD9: // EOI
  26643. foundEOI = true;
  26644. break;
  26645. case 0xC0: // SOF0
  26646. case 0xC1: // SOF1
  26647. case 0xC2: // SOF2
  26648. case 0xC3: // SOF3
  26649. case 0xC5: // SOF5
  26650. case 0xC6: // SOF6
  26651. case 0xC7: // SOF7
  26652. case 0xC9: // SOF9
  26653. case 0xCA: // SOF10
  26654. case 0xCB: // SOF11
  26655. case 0xCD: // SOF13
  26656. case 0xCE: // SOF14
  26657. case 0xCF: // SOF15
  26658. case 0xC4: // DHT
  26659. case 0xCC: // DAC
  26660. case 0xDA: // SOS
  26661. case 0xDB: // DQT
  26662. case 0xDC: // DNL
  26663. case 0xDD: // DRI
  26664. case 0xDE: // DHP
  26665. case 0xDF: // EXP
  26666. case 0xE0: // APP0
  26667. case 0xE1: // APP1
  26668. case 0xE2: // APP2
  26669. case 0xE3: // APP3
  26670. case 0xE4: // APP4
  26671. case 0xE5: // APP5
  26672. case 0xE6: // APP6
  26673. case 0xE7: // APP7
  26674. case 0xE8: // APP8
  26675. case 0xE9: // APP9
  26676. case 0xEA: // APP10
  26677. case 0xEB: // APP11
  26678. case 0xEC: // APP12
  26679. case 0xED: // APP13
  26680. case 0xEE: // APP14
  26681. case 0xEF: // APP15
  26682. case 0xFE: // COM
  26683. // The marker should be followed by the length of the segment.
  26684. markerLength = stream.getUint16();
  26685. if (markerLength > 2) {
  26686. // |markerLength| contains the byte length of the marker segment,
  26687. // including its own length (2 bytes) and excluding the marker.
  26688. stream.skip(markerLength - 2); // Jump to the next marker.
  26689. } else {
  26690. // The marker length is invalid, resetting the stream position.
  26691. stream.skip(-2);
  26692. }
  26693. break;
  26694. }
  26695. if (foundEOI) {
  26696. break;
  26697. }
  26698. }
  26699. length = stream.pos - startPos;
  26700. if (b === -1) {
  26701. warn('Inline DCTDecode image stream: ' +
  26702. 'EOI marker not found, searching for /EI/ instead.');
  26703. stream.skip(-length); // Reset the stream position.
  26704. return this.findDefaultInlineStreamEnd(stream);
  26705. }
  26706. this.inlineStreamSkipEI(stream);
  26707. return length;
  26708. },
  26709. /**
  26710. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  26711. * @returns {number} The inline stream length.
  26712. */
  26713. findASCII85DecodeInlineStreamEnd:
  26714. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  26715. var TILDE = 0x7E, GT = 0x3E;
  26716. var startPos = stream.pos, ch, length;
  26717. while ((ch = stream.getByte()) !== -1) {
  26718. if (ch === TILDE && stream.peekByte() === GT) {
  26719. stream.skip();
  26720. break;
  26721. }
  26722. }
  26723. length = stream.pos - startPos;
  26724. if (ch === -1) {
  26725. warn('Inline ASCII85Decode image stream: ' +
  26726. 'EOD marker not found, searching for /EI/ instead.');
  26727. stream.skip(-length); // Reset the stream position.
  26728. return this.findDefaultInlineStreamEnd(stream);
  26729. }
  26730. this.inlineStreamSkipEI(stream);
  26731. return length;
  26732. },
  26733. /**
  26734. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  26735. * @returns {number} The inline stream length.
  26736. */
  26737. findASCIIHexDecodeInlineStreamEnd:
  26738. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  26739. var GT = 0x3E;
  26740. var startPos = stream.pos, ch, length;
  26741. while ((ch = stream.getByte()) !== -1) {
  26742. if (ch === GT) {
  26743. break;
  26744. }
  26745. }
  26746. length = stream.pos - startPos;
  26747. if (ch === -1) {
  26748. warn('Inline ASCIIHexDecode image stream: ' +
  26749. 'EOD marker not found, searching for /EI/ instead.');
  26750. stream.skip(-length); // Reset the stream position.
  26751. return this.findDefaultInlineStreamEnd(stream);
  26752. }
  26753. this.inlineStreamSkipEI(stream);
  26754. return length;
  26755. },
  26756. /**
  26757. * Skip over the /EI/ for streams where we search for an EOD marker.
  26758. */
  26759. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  26760. var E = 0x45, I = 0x49;
  26761. var state = 0, ch;
  26762. while ((ch = stream.getByte()) !== -1) {
  26763. if (state === 0) {
  26764. state = (ch === E) ? 1 : 0;
  26765. } else if (state === 1) {
  26766. state = (ch === I) ? 2 : 0;
  26767. } else if (state === 2) {
  26768. break;
  26769. }
  26770. }
  26771. },
  26772. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  26773. var lexer = this.lexer;
  26774. var stream = lexer.stream;
  26775. // Parse dictionary.
  26776. var dict = new Dict(this.xref);
  26777. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  26778. if (!isName(this.buf1)) {
  26779. error('Dictionary key must be a name object');
  26780. }
  26781. var key = this.buf1.name;
  26782. this.shift();
  26783. if (isEOF(this.buf1)) {
  26784. break;
  26785. }
  26786. dict.set(key, this.getObj(cipherTransform));
  26787. }
  26788. // Extract the name of the first (i.e. the current) image filter.
  26789. var filter = dict.get('Filter', 'F'), filterName;
  26790. if (isName(filter)) {
  26791. filterName = filter.name;
  26792. } else if (isArray(filter) && isName(filter[0])) {
  26793. filterName = filter[0].name;
  26794. }
  26795. // Parse image stream.
  26796. var startPos = stream.pos, length, i, ii;
  26797. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  26798. length = this.findDCTDecodeInlineStreamEnd(stream);
  26799. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  26800. length = this.findASCII85DecodeInlineStreamEnd(stream);
  26801. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  26802. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  26803. } else {
  26804. length = this.findDefaultInlineStreamEnd(stream);
  26805. }
  26806. var imageStream = stream.makeSubStream(startPos, length, dict);
  26807. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  26808. // adler32 checksum.
  26809. var adler32;
  26810. if (length < MAX_LENGTH_TO_CACHE) {
  26811. var imageBytes = imageStream.getBytes();
  26812. imageStream.reset();
  26813. var a = 1;
  26814. var b = 0;
  26815. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  26816. // No modulo required in the loop if imageBytes.length < 5552.
  26817. a += imageBytes[i] & 0xff;
  26818. b += a;
  26819. }
  26820. adler32 = ((b % 65521) << 16) | (a % 65521);
  26821. if (this.imageCache.adler32 === adler32) {
  26822. this.buf2 = Cmd.get('EI');
  26823. this.shift();
  26824. this.imageCache[adler32].reset();
  26825. return this.imageCache[adler32];
  26826. }
  26827. }
  26828. if (cipherTransform) {
  26829. imageStream = cipherTransform.createStream(imageStream, length);
  26830. }
  26831. imageStream = this.filter(imageStream, dict, length);
  26832. imageStream.dict = dict;
  26833. if (adler32 !== undefined) {
  26834. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  26835. this.imageCache[adler32] = imageStream;
  26836. }
  26837. this.buf2 = Cmd.get('EI');
  26838. this.shift();
  26839. return imageStream;
  26840. },
  26841. makeStream: function Parser_makeStream(dict, cipherTransform) {
  26842. var lexer = this.lexer;
  26843. var stream = lexer.stream;
  26844. // get stream start position
  26845. lexer.skipToNextLine();
  26846. var pos = stream.pos - 1;
  26847. // get length
  26848. var length = dict.get('Length');
  26849. if (!isInt(length)) {
  26850. info('Bad ' + length + ' attribute in stream');
  26851. length = 0;
  26852. }
  26853. // skip over the stream data
  26854. stream.pos = pos + length;
  26855. lexer.nextChar();
  26856. // Shift '>>' and check whether the new object marks the end of the stream
  26857. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  26858. this.shift(); // 'stream'
  26859. } else {
  26860. // bad stream length, scanning for endstream
  26861. stream.pos = pos;
  26862. var SCAN_BLOCK_SIZE = 2048;
  26863. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  26864. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  26865. 0x61, 0x6D];
  26866. var skipped = 0, found = false, i, j;
  26867. while (stream.pos < stream.end) {
  26868. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  26869. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  26870. if (scanLength <= 0) {
  26871. break;
  26872. }
  26873. found = false;
  26874. for (i = 0, j = 0; i < scanLength; i++) {
  26875. var b = scanBytes[i];
  26876. if (b !== ENDSTREAM_SIGNATURE[j]) {
  26877. i -= j;
  26878. j = 0;
  26879. } else {
  26880. j++;
  26881. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  26882. i++;
  26883. found = true;
  26884. break;
  26885. }
  26886. }
  26887. }
  26888. if (found) {
  26889. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  26890. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  26891. break;
  26892. }
  26893. skipped += scanLength;
  26894. stream.pos += scanLength;
  26895. }
  26896. if (!found) {
  26897. error('Missing endstream');
  26898. }
  26899. length = skipped;
  26900. lexer.nextChar();
  26901. this.shift();
  26902. this.shift();
  26903. }
  26904. this.shift(); // 'endstream'
  26905. stream = stream.makeSubStream(pos, length, dict);
  26906. if (cipherTransform) {
  26907. stream = cipherTransform.createStream(stream, length);
  26908. }
  26909. stream = this.filter(stream, dict, length);
  26910. stream.dict = dict;
  26911. return stream;
  26912. },
  26913. filter: function Parser_filter(stream, dict, length) {
  26914. var filter = dict.get('Filter', 'F');
  26915. var params = dict.get('DecodeParms', 'DP');
  26916. if (isName(filter)) {
  26917. return this.makeFilter(stream, filter.name, length, params);
  26918. }
  26919. var maybeLength = length;
  26920. if (isArray(filter)) {
  26921. var filterArray = filter;
  26922. var paramsArray = params;
  26923. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  26924. filter = filterArray[i];
  26925. if (!isName(filter)) {
  26926. error('Bad filter name: ' + filter);
  26927. }
  26928. params = null;
  26929. if (isArray(paramsArray) && (i in paramsArray)) {
  26930. params = paramsArray[i];
  26931. }
  26932. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  26933. // after the first stream the length variable is invalid
  26934. maybeLength = null;
  26935. }
  26936. }
  26937. return stream;
  26938. },
  26939. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  26940. if (stream.dict.get('Length') === 0 && !maybeLength) {
  26941. warn('Empty "' + name + '" stream.');
  26942. return new NullStream(stream);
  26943. }
  26944. try {
  26945. if (params && this.xref) {
  26946. params = this.xref.fetchIfRef(params);
  26947. }
  26948. var xrefStreamStats = this.xref.stats.streamTypes;
  26949. if (name === 'FlateDecode' || name === 'Fl') {
  26950. xrefStreamStats[StreamType.FLATE] = true;
  26951. if (params) {
  26952. return new PredictorStream(new FlateStream(stream, maybeLength),
  26953. maybeLength, params);
  26954. }
  26955. return new FlateStream(stream, maybeLength);
  26956. }
  26957. if (name === 'LZWDecode' || name === 'LZW') {
  26958. xrefStreamStats[StreamType.LZW] = true;
  26959. var earlyChange = 1;
  26960. if (params) {
  26961. if (params.has('EarlyChange')) {
  26962. earlyChange = params.get('EarlyChange');
  26963. }
  26964. return new PredictorStream(
  26965. new LZWStream(stream, maybeLength, earlyChange),
  26966. maybeLength, params);
  26967. }
  26968. return new LZWStream(stream, maybeLength, earlyChange);
  26969. }
  26970. if (name === 'DCTDecode' || name === 'DCT') {
  26971. xrefStreamStats[StreamType.DCT] = true;
  26972. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  26973. }
  26974. if (name === 'JPXDecode' || name === 'JPX') {
  26975. xrefStreamStats[StreamType.JPX] = true;
  26976. return new JpxStream(stream, maybeLength, stream.dict);
  26977. }
  26978. if (name === 'ASCII85Decode' || name === 'A85') {
  26979. xrefStreamStats[StreamType.A85] = true;
  26980. return new Ascii85Stream(stream, maybeLength);
  26981. }
  26982. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  26983. xrefStreamStats[StreamType.AHX] = true;
  26984. return new AsciiHexStream(stream, maybeLength);
  26985. }
  26986. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  26987. xrefStreamStats[StreamType.CCF] = true;
  26988. return new CCITTFaxStream(stream, maybeLength, params);
  26989. }
  26990. if (name === 'RunLengthDecode' || name === 'RL') {
  26991. xrefStreamStats[StreamType.RL] = true;
  26992. return new RunLengthStream(stream, maybeLength);
  26993. }
  26994. if (name === 'JBIG2Decode') {
  26995. xrefStreamStats[StreamType.JBIG] = true;
  26996. return new Jbig2Stream(stream, maybeLength, stream.dict);
  26997. }
  26998. warn('filter "' + name + '" not supported yet');
  26999. return stream;
  27000. } catch (ex) {
  27001. if (ex instanceof MissingDataException) {
  27002. throw ex;
  27003. }
  27004. warn('Invalid stream: \"' + ex + '\"');
  27005. return new NullStream(stream);
  27006. }
  27007. }
  27008. };
  27009. return Parser;
  27010. })();
  27011. var Lexer = (function LexerClosure() {
  27012. function Lexer(stream, knownCommands) {
  27013. this.stream = stream;
  27014. this.nextChar();
  27015. // While lexing, we build up many strings one char at a time. Using += for
  27016. // this can result in lots of garbage strings. It's better to build an
  27017. // array of single-char strings and then join() them together at the end.
  27018. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27019. // purpose uses less memory than using a new array for each string.
  27020. this.strBuf = [];
  27021. // The PDFs might have "glued" commands with other commands, operands or
  27022. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27023. // commands and their prefixes. The prefixes are built the following way:
  27024. // if there a command that is a prefix of the other valid command or
  27025. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27026. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27027. // other commands or literals as a prefix. The knowCommands is optional.
  27028. this.knownCommands = knownCommands;
  27029. }
  27030. Lexer.isSpace = function Lexer_isSpace(ch) {
  27031. // Space is one of the following characters: SPACE, TAB, CR or LF.
  27032. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  27033. };
  27034. // A '1' in this array means the character is white space. A '1' or
  27035. // '2' means the character ends a name or command.
  27036. var specialChars = [
  27037. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27039. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27053. ];
  27054. function toHexDigit(ch) {
  27055. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27056. return ch & 0x0F;
  27057. }
  27058. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27059. // 'A'-'F', 'a'-'f'
  27060. return (ch & 0x0F) + 9;
  27061. }
  27062. return -1;
  27063. }
  27064. Lexer.prototype = {
  27065. nextChar: function Lexer_nextChar() {
  27066. return (this.currentChar = this.stream.getByte());
  27067. },
  27068. peekChar: function Lexer_peekChar() {
  27069. return this.stream.peekByte();
  27070. },
  27071. getNumber: function Lexer_getNumber() {
  27072. var ch = this.currentChar;
  27073. var eNotation = false;
  27074. var divideBy = 0; // different from 0 if it's a floating point value
  27075. var sign = 1;
  27076. if (ch === 0x2D) { // '-'
  27077. sign = -1;
  27078. ch = this.nextChar();
  27079. if (ch === 0x2D) { // '-'
  27080. // Ignore double negative (this is consistent with Adobe Reader).
  27081. ch = this.nextChar();
  27082. }
  27083. } else if (ch === 0x2B) { // '+'
  27084. ch = this.nextChar();
  27085. }
  27086. if (ch === 0x2E) { // '.'
  27087. divideBy = 10;
  27088. ch = this.nextChar();
  27089. }
  27090. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27091. error('Invalid number: ' + String.fromCharCode(ch));
  27092. return 0;
  27093. }
  27094. var baseValue = ch - 0x30; // '0'
  27095. var powerValue = 0;
  27096. var powerValueSign = 1;
  27097. while ((ch = this.nextChar()) >= 0) {
  27098. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  27099. var currentDigit = ch - 0x30; // '0'
  27100. if (eNotation) { // We are after an 'e' or 'E'
  27101. powerValue = powerValue * 10 + currentDigit;
  27102. } else {
  27103. if (divideBy !== 0) { // We are after a point
  27104. divideBy *= 10;
  27105. }
  27106. baseValue = baseValue * 10 + currentDigit;
  27107. }
  27108. } else if (ch === 0x2E) { // '.'
  27109. if (divideBy === 0) {
  27110. divideBy = 1;
  27111. } else {
  27112. // A number can have only one '.'
  27113. break;
  27114. }
  27115. } else if (ch === 0x2D) { // '-'
  27116. // ignore minus signs in the middle of numbers to match
  27117. // Adobe's behavior
  27118. warn('Badly formated number');
  27119. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  27120. // 'E' can be either a scientific notation or the beginning of a new
  27121. // operator
  27122. ch = this.peekChar();
  27123. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  27124. powerValueSign = (ch === 0x2D) ? -1 : 1;
  27125. this.nextChar(); // Consume the sign character
  27126. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27127. // The 'E' must be the beginning of a new operator
  27128. break;
  27129. }
  27130. eNotation = true;
  27131. } else {
  27132. // the last character doesn't belong to us
  27133. break;
  27134. }
  27135. }
  27136. if (divideBy !== 0) {
  27137. baseValue /= divideBy;
  27138. }
  27139. if (eNotation) {
  27140. baseValue *= Math.pow(10, powerValueSign * powerValue);
  27141. }
  27142. return sign * baseValue;
  27143. },
  27144. getString: function Lexer_getString() {
  27145. var numParen = 1;
  27146. var done = false;
  27147. var strBuf = this.strBuf;
  27148. strBuf.length = 0;
  27149. var ch = this.nextChar();
  27150. while (true) {
  27151. var charBuffered = false;
  27152. switch (ch | 0) {
  27153. case -1:
  27154. warn('Unterminated string');
  27155. done = true;
  27156. break;
  27157. case 0x28: // '('
  27158. ++numParen;
  27159. strBuf.push('(');
  27160. break;
  27161. case 0x29: // ')'
  27162. if (--numParen === 0) {
  27163. this.nextChar(); // consume strings ')'
  27164. done = true;
  27165. } else {
  27166. strBuf.push(')');
  27167. }
  27168. break;
  27169. case 0x5C: // '\\'
  27170. ch = this.nextChar();
  27171. switch (ch) {
  27172. case -1:
  27173. warn('Unterminated string');
  27174. done = true;
  27175. break;
  27176. case 0x6E: // 'n'
  27177. strBuf.push('\n');
  27178. break;
  27179. case 0x72: // 'r'
  27180. strBuf.push('\r');
  27181. break;
  27182. case 0x74: // 't'
  27183. strBuf.push('\t');
  27184. break;
  27185. case 0x62: // 'b'
  27186. strBuf.push('\b');
  27187. break;
  27188. case 0x66: // 'f'
  27189. strBuf.push('\f');
  27190. break;
  27191. case 0x5C: // '\'
  27192. case 0x28: // '('
  27193. case 0x29: // ')'
  27194. strBuf.push(String.fromCharCode(ch));
  27195. break;
  27196. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  27197. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  27198. var x = ch & 0x0F;
  27199. ch = this.nextChar();
  27200. charBuffered = true;
  27201. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27202. x = (x << 3) + (ch & 0x0F);
  27203. ch = this.nextChar();
  27204. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27205. charBuffered = false;
  27206. x = (x << 3) + (ch & 0x0F);
  27207. }
  27208. }
  27209. strBuf.push(String.fromCharCode(x));
  27210. break;
  27211. case 0x0D: // CR
  27212. if (this.peekChar() === 0x0A) { // LF
  27213. this.nextChar();
  27214. }
  27215. break;
  27216. case 0x0A: // LF
  27217. break;
  27218. default:
  27219. strBuf.push(String.fromCharCode(ch));
  27220. break;
  27221. }
  27222. break;
  27223. default:
  27224. strBuf.push(String.fromCharCode(ch));
  27225. break;
  27226. }
  27227. if (done) {
  27228. break;
  27229. }
  27230. if (!charBuffered) {
  27231. ch = this.nextChar();
  27232. }
  27233. }
  27234. return strBuf.join('');
  27235. },
  27236. getName: function Lexer_getName() {
  27237. var ch, previousCh;
  27238. var strBuf = this.strBuf;
  27239. strBuf.length = 0;
  27240. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27241. if (ch === 0x23) { // '#'
  27242. ch = this.nextChar();
  27243. if (specialChars[ch]) {
  27244. warn('Lexer_getName: ' +
  27245. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  27246. strBuf.push('#');
  27247. break;
  27248. }
  27249. var x = toHexDigit(ch);
  27250. if (x !== -1) {
  27251. previousCh = ch;
  27252. ch = this.nextChar();
  27253. var x2 = toHexDigit(ch);
  27254. if (x2 === -1) {
  27255. warn('Lexer_getName: Illegal digit (' +
  27256. String.fromCharCode(ch) +') in hexadecimal number.');
  27257. strBuf.push('#', String.fromCharCode(previousCh));
  27258. if (specialChars[ch]) {
  27259. break;
  27260. }
  27261. strBuf.push(String.fromCharCode(ch));
  27262. continue;
  27263. }
  27264. strBuf.push(String.fromCharCode((x << 4) | x2));
  27265. } else {
  27266. strBuf.push('#', String.fromCharCode(ch));
  27267. }
  27268. } else {
  27269. strBuf.push(String.fromCharCode(ch));
  27270. }
  27271. }
  27272. if (strBuf.length > 127) {
  27273. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  27274. }
  27275. return Name.get(strBuf.join(''));
  27276. },
  27277. getHexString: function Lexer_getHexString() {
  27278. var strBuf = this.strBuf;
  27279. strBuf.length = 0;
  27280. var ch = this.currentChar;
  27281. var isFirstHex = true;
  27282. var firstDigit;
  27283. var secondDigit;
  27284. while (true) {
  27285. if (ch < 0) {
  27286. warn('Unterminated hex string');
  27287. break;
  27288. } else if (ch === 0x3E) { // '>'
  27289. this.nextChar();
  27290. break;
  27291. } else if (specialChars[ch] === 1) {
  27292. ch = this.nextChar();
  27293. continue;
  27294. } else {
  27295. if (isFirstHex) {
  27296. firstDigit = toHexDigit(ch);
  27297. if (firstDigit === -1) {
  27298. warn('Ignoring invalid character "' + ch + '" in hex string');
  27299. ch = this.nextChar();
  27300. continue;
  27301. }
  27302. } else {
  27303. secondDigit = toHexDigit(ch);
  27304. if (secondDigit === -1) {
  27305. warn('Ignoring invalid character "' + ch + '" in hex string');
  27306. ch = this.nextChar();
  27307. continue;
  27308. }
  27309. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  27310. }
  27311. isFirstHex = !isFirstHex;
  27312. ch = this.nextChar();
  27313. }
  27314. }
  27315. return strBuf.join('');
  27316. },
  27317. getObj: function Lexer_getObj() {
  27318. // skip whitespace and comments
  27319. var comment = false;
  27320. var ch = this.currentChar;
  27321. while (true) {
  27322. if (ch < 0) {
  27323. return EOF;
  27324. }
  27325. if (comment) {
  27326. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  27327. comment = false;
  27328. }
  27329. } else if (ch === 0x25) { // '%'
  27330. comment = true;
  27331. } else if (specialChars[ch] !== 1) {
  27332. break;
  27333. }
  27334. ch = this.nextChar();
  27335. }
  27336. // start reading token
  27337. switch (ch | 0) {
  27338. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  27339. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  27340. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  27341. return this.getNumber();
  27342. case 0x28: // '('
  27343. return this.getString();
  27344. case 0x2F: // '/'
  27345. return this.getName();
  27346. // array punctuation
  27347. case 0x5B: // '['
  27348. this.nextChar();
  27349. return Cmd.get('[');
  27350. case 0x5D: // ']'
  27351. this.nextChar();
  27352. return Cmd.get(']');
  27353. // hex string or dict punctuation
  27354. case 0x3C: // '<'
  27355. ch = this.nextChar();
  27356. if (ch === 0x3C) {
  27357. // dict punctuation
  27358. this.nextChar();
  27359. return Cmd.get('<<');
  27360. }
  27361. return this.getHexString();
  27362. // dict punctuation
  27363. case 0x3E: // '>'
  27364. ch = this.nextChar();
  27365. if (ch === 0x3E) {
  27366. this.nextChar();
  27367. return Cmd.get('>>');
  27368. }
  27369. return Cmd.get('>');
  27370. case 0x7B: // '{'
  27371. this.nextChar();
  27372. return Cmd.get('{');
  27373. case 0x7D: // '}'
  27374. this.nextChar();
  27375. return Cmd.get('}');
  27376. case 0x29: // ')'
  27377. error('Illegal character: ' + ch);
  27378. break;
  27379. }
  27380. // command
  27381. var str = String.fromCharCode(ch);
  27382. var knownCommands = this.knownCommands;
  27383. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27384. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27385. // stop if known command is found and next character does not make
  27386. // the str a command
  27387. var possibleCommand = str + String.fromCharCode(ch);
  27388. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  27389. break;
  27390. }
  27391. if (str.length === 128) {
  27392. error('Command token too long: ' + str.length);
  27393. }
  27394. str = possibleCommand;
  27395. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27396. }
  27397. if (str === 'true') {
  27398. return true;
  27399. }
  27400. if (str === 'false') {
  27401. return false;
  27402. }
  27403. if (str === 'null') {
  27404. return null;
  27405. }
  27406. return Cmd.get(str);
  27407. },
  27408. skipToNextLine: function Lexer_skipToNextLine() {
  27409. var ch = this.currentChar;
  27410. while (ch >= 0) {
  27411. if (ch === 0x0D) { // CR
  27412. ch = this.nextChar();
  27413. if (ch === 0x0A) { // LF
  27414. this.nextChar();
  27415. }
  27416. break;
  27417. } else if (ch === 0x0A) { // LF
  27418. this.nextChar();
  27419. break;
  27420. }
  27421. ch = this.nextChar();
  27422. }
  27423. }
  27424. };
  27425. return Lexer;
  27426. })();
  27427. var Linearization = {
  27428. create: function LinearizationCreate(stream) {
  27429. function getInt(name, allowZeroValue) {
  27430. var obj = linDict.get(name);
  27431. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  27432. return obj;
  27433. }
  27434. throw new Error('The "' + name + '" parameter in the linearization ' +
  27435. 'dictionary is invalid.');
  27436. }
  27437. function getHints() {
  27438. var hints = linDict.get('H'), hintsLength, item;
  27439. if (isArray(hints) &&
  27440. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  27441. for (var index = 0; index < hintsLength; index++) {
  27442. if (!(isInt(item = hints[index]) && item > 0)) {
  27443. throw new Error('Hint (' + index +
  27444. ') in the linearization dictionary is invalid.');
  27445. }
  27446. }
  27447. return hints;
  27448. }
  27449. throw new Error('Hint array in the linearization dictionary is invalid.');
  27450. }
  27451. var parser = new Parser(new Lexer(stream), false, null);
  27452. var obj1 = parser.getObj();
  27453. var obj2 = parser.getObj();
  27454. var obj3 = parser.getObj();
  27455. var linDict = parser.getObj();
  27456. var obj, length;
  27457. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  27458. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  27459. return null; // No valid linearization dictionary found.
  27460. } else if ((length = getInt('L')) !== stream.length) {
  27461. throw new Error('The "L" parameter in the linearization dictionary ' +
  27462. 'does not equal the stream length.');
  27463. }
  27464. return {
  27465. length: length,
  27466. hints: getHints(),
  27467. objectNumberFirst: getInt('O'),
  27468. endFirst: getInt('E'),
  27469. numPages: getInt('N'),
  27470. mainXRefEntriesOffset: getInt('T'),
  27471. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  27472. };
  27473. }
  27474. };
  27475. exports.EOF = EOF;
  27476. exports.Lexer = Lexer;
  27477. exports.Linearization = Linearization;
  27478. exports.Parser = Parser;
  27479. exports.isEOF = isEOF;
  27480. // TODO refactor to remove dependency on stream.js
  27481. coreStream._setCoreParser(exports);
  27482. }));
  27483. (function (root, factory) {
  27484. {
  27485. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  27486. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  27487. }
  27488. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  27489. var Util = sharedUtil.Util;
  27490. var assert = sharedUtil.assert;
  27491. var error = sharedUtil.error;
  27492. var isInt = sharedUtil.isInt;
  27493. var isString = sharedUtil.isString;
  27494. var warn = sharedUtil.warn;
  27495. var isName = corePrimitives.isName;
  27496. var isCmd = corePrimitives.isCmd;
  27497. var isStream = corePrimitives.isStream;
  27498. var StringStream = coreStream.StringStream;
  27499. var Lexer = coreParser.Lexer;
  27500. var isEOF = coreParser.isEOF;
  27501. var BUILT_IN_CMAPS = [
  27502. // << Start unicode maps.
  27503. 'Adobe-GB1-UCS2',
  27504. 'Adobe-CNS1-UCS2',
  27505. 'Adobe-Japan1-UCS2',
  27506. 'Adobe-Korea1-UCS2',
  27507. // >> End unicode maps.
  27508. '78-EUC-H',
  27509. '78-EUC-V',
  27510. '78-H',
  27511. '78-RKSJ-H',
  27512. '78-RKSJ-V',
  27513. '78-V',
  27514. '78ms-RKSJ-H',
  27515. '78ms-RKSJ-V',
  27516. '83pv-RKSJ-H',
  27517. '90ms-RKSJ-H',
  27518. '90ms-RKSJ-V',
  27519. '90msp-RKSJ-H',
  27520. '90msp-RKSJ-V',
  27521. '90pv-RKSJ-H',
  27522. '90pv-RKSJ-V',
  27523. 'Add-H',
  27524. 'Add-RKSJ-H',
  27525. 'Add-RKSJ-V',
  27526. 'Add-V',
  27527. 'Adobe-CNS1-0',
  27528. 'Adobe-CNS1-1',
  27529. 'Adobe-CNS1-2',
  27530. 'Adobe-CNS1-3',
  27531. 'Adobe-CNS1-4',
  27532. 'Adobe-CNS1-5',
  27533. 'Adobe-CNS1-6',
  27534. 'Adobe-GB1-0',
  27535. 'Adobe-GB1-1',
  27536. 'Adobe-GB1-2',
  27537. 'Adobe-GB1-3',
  27538. 'Adobe-GB1-4',
  27539. 'Adobe-GB1-5',
  27540. 'Adobe-Japan1-0',
  27541. 'Adobe-Japan1-1',
  27542. 'Adobe-Japan1-2',
  27543. 'Adobe-Japan1-3',
  27544. 'Adobe-Japan1-4',
  27545. 'Adobe-Japan1-5',
  27546. 'Adobe-Japan1-6',
  27547. 'Adobe-Korea1-0',
  27548. 'Adobe-Korea1-1',
  27549. 'Adobe-Korea1-2',
  27550. 'B5-H',
  27551. 'B5-V',
  27552. 'B5pc-H',
  27553. 'B5pc-V',
  27554. 'CNS-EUC-H',
  27555. 'CNS-EUC-V',
  27556. 'CNS1-H',
  27557. 'CNS1-V',
  27558. 'CNS2-H',
  27559. 'CNS2-V',
  27560. 'ETHK-B5-H',
  27561. 'ETHK-B5-V',
  27562. 'ETen-B5-H',
  27563. 'ETen-B5-V',
  27564. 'ETenms-B5-H',
  27565. 'ETenms-B5-V',
  27566. 'EUC-H',
  27567. 'EUC-V',
  27568. 'Ext-H',
  27569. 'Ext-RKSJ-H',
  27570. 'Ext-RKSJ-V',
  27571. 'Ext-V',
  27572. 'GB-EUC-H',
  27573. 'GB-EUC-V',
  27574. 'GB-H',
  27575. 'GB-V',
  27576. 'GBK-EUC-H',
  27577. 'GBK-EUC-V',
  27578. 'GBK2K-H',
  27579. 'GBK2K-V',
  27580. 'GBKp-EUC-H',
  27581. 'GBKp-EUC-V',
  27582. 'GBT-EUC-H',
  27583. 'GBT-EUC-V',
  27584. 'GBT-H',
  27585. 'GBT-V',
  27586. 'GBTpc-EUC-H',
  27587. 'GBTpc-EUC-V',
  27588. 'GBpc-EUC-H',
  27589. 'GBpc-EUC-V',
  27590. 'H',
  27591. 'HKdla-B5-H',
  27592. 'HKdla-B5-V',
  27593. 'HKdlb-B5-H',
  27594. 'HKdlb-B5-V',
  27595. 'HKgccs-B5-H',
  27596. 'HKgccs-B5-V',
  27597. 'HKm314-B5-H',
  27598. 'HKm314-B5-V',
  27599. 'HKm471-B5-H',
  27600. 'HKm471-B5-V',
  27601. 'HKscs-B5-H',
  27602. 'HKscs-B5-V',
  27603. 'Hankaku',
  27604. 'Hiragana',
  27605. 'KSC-EUC-H',
  27606. 'KSC-EUC-V',
  27607. 'KSC-H',
  27608. 'KSC-Johab-H',
  27609. 'KSC-Johab-V',
  27610. 'KSC-V',
  27611. 'KSCms-UHC-H',
  27612. 'KSCms-UHC-HW-H',
  27613. 'KSCms-UHC-HW-V',
  27614. 'KSCms-UHC-V',
  27615. 'KSCpc-EUC-H',
  27616. 'KSCpc-EUC-V',
  27617. 'Katakana',
  27618. 'NWP-H',
  27619. 'NWP-V',
  27620. 'RKSJ-H',
  27621. 'RKSJ-V',
  27622. 'Roman',
  27623. 'UniCNS-UCS2-H',
  27624. 'UniCNS-UCS2-V',
  27625. 'UniCNS-UTF16-H',
  27626. 'UniCNS-UTF16-V',
  27627. 'UniCNS-UTF32-H',
  27628. 'UniCNS-UTF32-V',
  27629. 'UniCNS-UTF8-H',
  27630. 'UniCNS-UTF8-V',
  27631. 'UniGB-UCS2-H',
  27632. 'UniGB-UCS2-V',
  27633. 'UniGB-UTF16-H',
  27634. 'UniGB-UTF16-V',
  27635. 'UniGB-UTF32-H',
  27636. 'UniGB-UTF32-V',
  27637. 'UniGB-UTF8-H',
  27638. 'UniGB-UTF8-V',
  27639. 'UniJIS-UCS2-H',
  27640. 'UniJIS-UCS2-HW-H',
  27641. 'UniJIS-UCS2-HW-V',
  27642. 'UniJIS-UCS2-V',
  27643. 'UniJIS-UTF16-H',
  27644. 'UniJIS-UTF16-V',
  27645. 'UniJIS-UTF32-H',
  27646. 'UniJIS-UTF32-V',
  27647. 'UniJIS-UTF8-H',
  27648. 'UniJIS-UTF8-V',
  27649. 'UniJIS2004-UTF16-H',
  27650. 'UniJIS2004-UTF16-V',
  27651. 'UniJIS2004-UTF32-H',
  27652. 'UniJIS2004-UTF32-V',
  27653. 'UniJIS2004-UTF8-H',
  27654. 'UniJIS2004-UTF8-V',
  27655. 'UniJISPro-UCS2-HW-V',
  27656. 'UniJISPro-UCS2-V',
  27657. 'UniJISPro-UTF8-V',
  27658. 'UniJISX0213-UTF32-H',
  27659. 'UniJISX0213-UTF32-V',
  27660. 'UniJISX02132004-UTF32-H',
  27661. 'UniJISX02132004-UTF32-V',
  27662. 'UniKS-UCS2-H',
  27663. 'UniKS-UCS2-V',
  27664. 'UniKS-UTF16-H',
  27665. 'UniKS-UTF16-V',
  27666. 'UniKS-UTF32-H',
  27667. 'UniKS-UTF32-V',
  27668. 'UniKS-UTF8-H',
  27669. 'UniKS-UTF8-V',
  27670. 'V',
  27671. 'WP-Symbol'];
  27672. // CMap, not to be confused with TrueType's cmap.
  27673. var CMap = (function CMapClosure() {
  27674. function CMap(builtInCMap) {
  27675. // Codespace ranges are stored as follows:
  27676. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  27677. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  27678. this.codespaceRanges = [[], [], [], []];
  27679. this.numCodespaceRanges = 0;
  27680. // Map entries have one of two forms.
  27681. // - cid chars are 16-bit unsigned integers, stored as integers.
  27682. // - bf chars are variable-length byte sequences, stored as strings, with
  27683. // one byte per character.
  27684. this._map = [];
  27685. this.name = '';
  27686. this.vertical = false;
  27687. this.useCMap = null;
  27688. this.builtInCMap = builtInCMap;
  27689. }
  27690. CMap.prototype = {
  27691. addCodespaceRange: function(n, low, high) {
  27692. this.codespaceRanges[n - 1].push(low, high);
  27693. this.numCodespaceRanges++;
  27694. },
  27695. mapCidRange: function(low, high, dstLow) {
  27696. while (low <= high) {
  27697. this._map[low++] = dstLow++;
  27698. }
  27699. },
  27700. mapBfRange: function(low, high, dstLow) {
  27701. var lastByte = dstLow.length - 1;
  27702. while (low <= high) {
  27703. this._map[low++] = dstLow;
  27704. // Only the last byte has to be incremented.
  27705. dstLow = dstLow.substr(0, lastByte) +
  27706. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  27707. }
  27708. },
  27709. mapBfRangeToArray: function(low, high, array) {
  27710. var i = 0, ii = array.length;
  27711. while (low <= high && i < ii) {
  27712. this._map[low] = array[i++];
  27713. ++low;
  27714. }
  27715. },
  27716. // This is used for both bf and cid chars.
  27717. mapOne: function(src, dst) {
  27718. this._map[src] = dst;
  27719. },
  27720. lookup: function(code) {
  27721. return this._map[code];
  27722. },
  27723. contains: function(code) {
  27724. return this._map[code] !== undefined;
  27725. },
  27726. forEach: function(callback) {
  27727. // Most maps have fewer than 65536 entries, and for those we use normal
  27728. // array iteration. But really sparse tables are possible -- e.g. with
  27729. // indices in the *billions*. For such tables we use for..in, which isn't
  27730. // ideal because it stringifies the indices for all present elements, but
  27731. // it does avoid iterating over every undefined entry.
  27732. var map = this._map;
  27733. var length = map.length;
  27734. var i;
  27735. if (length <= 0x10000) {
  27736. for (i = 0; i < length; i++) {
  27737. if (map[i] !== undefined) {
  27738. callback(i, map[i]);
  27739. }
  27740. }
  27741. } else {
  27742. for (i in this._map) {
  27743. callback(i, map[i]);
  27744. }
  27745. }
  27746. },
  27747. charCodeOf: function(value) {
  27748. return this._map.indexOf(value);
  27749. },
  27750. getMap: function() {
  27751. return this._map;
  27752. },
  27753. readCharCode: function(str, offset, out) {
  27754. var c = 0;
  27755. var codespaceRanges = this.codespaceRanges;
  27756. var codespaceRangesLen = this.codespaceRanges.length;
  27757. // 9.7.6.2 CMap Mapping
  27758. // The code length is at most 4.
  27759. for (var n = 0; n < codespaceRangesLen; n++) {
  27760. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  27761. // Check each codespace range to see if it falls within.
  27762. var codespaceRange = codespaceRanges[n];
  27763. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  27764. var low = codespaceRange[k++];
  27765. var high = codespaceRange[k++];
  27766. if (c >= low && c <= high) {
  27767. out.charcode = c;
  27768. out.length = n + 1;
  27769. return;
  27770. }
  27771. }
  27772. }
  27773. out.charcode = 0;
  27774. out.length = 1;
  27775. },
  27776. get length() {
  27777. return this._map.length;
  27778. },
  27779. get isIdentityCMap() {
  27780. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  27781. return false;
  27782. }
  27783. if (this._map.length !== 0x10000) {
  27784. return false;
  27785. }
  27786. for (var i = 0; i < 0x10000; i++) {
  27787. if (this._map[i] !== i) {
  27788. return false;
  27789. }
  27790. }
  27791. return true;
  27792. }
  27793. };
  27794. return CMap;
  27795. })();
  27796. // A special case of CMap, where the _map array implicitly has a length of
  27797. // 65536 and each element is equal to its index.
  27798. var IdentityCMap = (function IdentityCMapClosure() {
  27799. function IdentityCMap(vertical, n) {
  27800. CMap.call(this);
  27801. this.vertical = vertical;
  27802. this.addCodespaceRange(n, 0, 0xffff);
  27803. }
  27804. Util.inherit(IdentityCMap, CMap, {});
  27805. IdentityCMap.prototype = {
  27806. addCodespaceRange: CMap.prototype.addCodespaceRange,
  27807. mapCidRange: function(low, high, dstLow) {
  27808. error('should not call mapCidRange');
  27809. },
  27810. mapBfRange: function(low, high, dstLow) {
  27811. error('should not call mapBfRange');
  27812. },
  27813. mapBfRangeToArray: function(low, high, array) {
  27814. error('should not call mapBfRangeToArray');
  27815. },
  27816. mapOne: function(src, dst) {
  27817. error('should not call mapCidOne');
  27818. },
  27819. lookup: function(code) {
  27820. return (isInt(code) && code <= 0xffff) ? code : undefined;
  27821. },
  27822. contains: function(code) {
  27823. return isInt(code) && code <= 0xffff;
  27824. },
  27825. forEach: function(callback) {
  27826. for (var i = 0; i <= 0xffff; i++) {
  27827. callback(i, i);
  27828. }
  27829. },
  27830. charCodeOf: function(value) {
  27831. return (isInt(value) && value <= 0xffff) ? value : -1;
  27832. },
  27833. getMap: function() {
  27834. // Sometimes identity maps must be instantiated, but it's rare.
  27835. var map = new Array(0x10000);
  27836. for (var i = 0; i <= 0xffff; i++) {
  27837. map[i] = i;
  27838. }
  27839. return map;
  27840. },
  27841. readCharCode: CMap.prototype.readCharCode,
  27842. get length() {
  27843. return 0x10000;
  27844. },
  27845. get isIdentityCMap() {
  27846. error('should not access .isIdentityCMap');
  27847. }
  27848. };
  27849. return IdentityCMap;
  27850. })();
  27851. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  27852. function fetchBinaryData(url) {
  27853. var nonBinaryRequest = PDFJS.disableWorker;
  27854. var request = new XMLHttpRequest();
  27855. request.open('GET', url, false);
  27856. if (!nonBinaryRequest) {
  27857. try {
  27858. request.responseType = 'arraybuffer';
  27859. nonBinaryRequest = request.responseType !== 'arraybuffer';
  27860. } catch (e) {
  27861. nonBinaryRequest = true;
  27862. }
  27863. }
  27864. if (nonBinaryRequest && request.overrideMimeType) {
  27865. request.overrideMimeType('text/plain; charset=x-user-defined');
  27866. }
  27867. request.send(null);
  27868. if (nonBinaryRequest ? !request.responseText : !request.response) {
  27869. error('Unable to get binary cMap at: ' + url);
  27870. }
  27871. if (nonBinaryRequest) {
  27872. var data = Array.prototype.map.call(request.responseText, function (ch) {
  27873. return ch.charCodeAt(0) & 255;
  27874. });
  27875. return new Uint8Array(data);
  27876. }
  27877. return new Uint8Array(request.response);
  27878. }
  27879. function hexToInt(a, size) {
  27880. var n = 0;
  27881. for (var i = 0; i <= size; i++) {
  27882. n = (n << 8) | a[i];
  27883. }
  27884. return n >>> 0;
  27885. }
  27886. function hexToStr(a, size) {
  27887. // This code is hot. Special-case some common values to avoid creating an
  27888. // object with subarray().
  27889. if (size === 1) {
  27890. return String.fromCharCode(a[0], a[1]);
  27891. }
  27892. if (size === 3) {
  27893. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  27894. }
  27895. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  27896. }
  27897. function addHex(a, b, size) {
  27898. var c = 0;
  27899. for (var i = size; i >= 0; i--) {
  27900. c += a[i] + b[i];
  27901. a[i] = c & 255;
  27902. c >>= 8;
  27903. }
  27904. }
  27905. function incHex(a, size) {
  27906. var c = 1;
  27907. for (var i = size; i >= 0 && c > 0; i--) {
  27908. c += a[i];
  27909. a[i] = c & 255;
  27910. c >>= 8;
  27911. }
  27912. }
  27913. var MAX_NUM_SIZE = 16;
  27914. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  27915. function BinaryCMapStream(data) {
  27916. this.buffer = data;
  27917. this.pos = 0;
  27918. this.end = data.length;
  27919. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  27920. }
  27921. BinaryCMapStream.prototype = {
  27922. readByte: function () {
  27923. if (this.pos >= this.end) {
  27924. return -1;
  27925. }
  27926. return this.buffer[this.pos++];
  27927. },
  27928. readNumber: function () {
  27929. var n = 0;
  27930. var last;
  27931. do {
  27932. var b = this.readByte();
  27933. if (b < 0) {
  27934. error('unexpected EOF in bcmap');
  27935. }
  27936. last = !(b & 0x80);
  27937. n = (n << 7) | (b & 0x7F);
  27938. } while (!last);
  27939. return n;
  27940. },
  27941. readSigned: function () {
  27942. var n = this.readNumber();
  27943. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  27944. },
  27945. readHex: function (num, size) {
  27946. num.set(this.buffer.subarray(this.pos,
  27947. this.pos + size + 1));
  27948. this.pos += size + 1;
  27949. },
  27950. readHexNumber: function (num, size) {
  27951. var last;
  27952. var stack = this.tmpBuf, sp = 0;
  27953. do {
  27954. var b = this.readByte();
  27955. if (b < 0) {
  27956. error('unexpected EOF in bcmap');
  27957. }
  27958. last = !(b & 0x80);
  27959. stack[sp++] = b & 0x7F;
  27960. } while (!last);
  27961. var i = size, buffer = 0, bufferSize = 0;
  27962. while (i >= 0) {
  27963. while (bufferSize < 8 && stack.length > 0) {
  27964. buffer = (stack[--sp] << bufferSize) | buffer;
  27965. bufferSize += 7;
  27966. }
  27967. num[i] = buffer & 255;
  27968. i--;
  27969. buffer >>= 8;
  27970. bufferSize -= 8;
  27971. }
  27972. },
  27973. readHexSigned: function (num, size) {
  27974. this.readHexNumber(num, size);
  27975. var sign = num[size] & 1 ? 255 : 0;
  27976. var c = 0;
  27977. for (var i = 0; i <= size; i++) {
  27978. c = ((c & 1) << 8) | num[i];
  27979. num[i] = (c >> 1) ^ sign;
  27980. }
  27981. },
  27982. readString: function () {
  27983. var len = this.readNumber();
  27984. var s = '';
  27985. for (var i = 0; i < len; i++) {
  27986. s += String.fromCharCode(this.readNumber());
  27987. }
  27988. return s;
  27989. }
  27990. };
  27991. function processBinaryCMap(url, cMap, extend) {
  27992. var data = fetchBinaryData(url);
  27993. var stream = new BinaryCMapStream(data);
  27994. var header = stream.readByte();
  27995. cMap.vertical = !!(header & 1);
  27996. var useCMap = null;
  27997. var start = new Uint8Array(MAX_NUM_SIZE);
  27998. var end = new Uint8Array(MAX_NUM_SIZE);
  27999. var char = new Uint8Array(MAX_NUM_SIZE);
  28000. var charCode = new Uint8Array(MAX_NUM_SIZE);
  28001. var tmp = new Uint8Array(MAX_NUM_SIZE);
  28002. var code;
  28003. var b;
  28004. while ((b = stream.readByte()) >= 0) {
  28005. var type = b >> 5;
  28006. if (type === 7) { // metadata, e.g. comment or usecmap
  28007. switch (b & 0x1F) {
  28008. case 0:
  28009. stream.readString(); // skipping comment
  28010. break;
  28011. case 1:
  28012. useCMap = stream.readString();
  28013. break;
  28014. }
  28015. continue;
  28016. }
  28017. var sequence = !!(b & 0x10);
  28018. var dataSize = b & 15;
  28019. assert(dataSize + 1 <= MAX_NUM_SIZE);
  28020. var ucs2DataSize = 1;
  28021. var subitemsCount = stream.readNumber();
  28022. var i;
  28023. switch (type) {
  28024. case 0: // codespacerange
  28025. stream.readHex(start, dataSize);
  28026. stream.readHexNumber(end, dataSize);
  28027. addHex(end, start, dataSize);
  28028. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  28029. hexToInt(end, dataSize));
  28030. for (i = 1; i < subitemsCount; i++) {
  28031. incHex(end, dataSize);
  28032. stream.readHexNumber(start, dataSize);
  28033. addHex(start, end, dataSize);
  28034. stream.readHexNumber(end, dataSize);
  28035. addHex(end, start, dataSize);
  28036. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  28037. hexToInt(end, dataSize));
  28038. }
  28039. break;
  28040. case 1: // notdefrange
  28041. stream.readHex(start, dataSize);
  28042. stream.readHexNumber(end, dataSize);
  28043. addHex(end, start, dataSize);
  28044. code = stream.readNumber();
  28045. // undefined range, skipping
  28046. for (i = 1; i < subitemsCount; i++) {
  28047. incHex(end, dataSize);
  28048. stream.readHexNumber(start, dataSize);
  28049. addHex(start, end, dataSize);
  28050. stream.readHexNumber(end, dataSize);
  28051. addHex(end, start, dataSize);
  28052. code = stream.readNumber();
  28053. // nop
  28054. }
  28055. break;
  28056. case 2: // cidchar
  28057. stream.readHex(char, dataSize);
  28058. code = stream.readNumber();
  28059. cMap.mapOne(hexToInt(char, dataSize), code);
  28060. for (i = 1; i < subitemsCount; i++) {
  28061. incHex(char, dataSize);
  28062. if (!sequence) {
  28063. stream.readHexNumber(tmp, dataSize);
  28064. addHex(char, tmp, dataSize);
  28065. }
  28066. code = stream.readSigned() + (code + 1);
  28067. cMap.mapOne(hexToInt(char, dataSize), code);
  28068. }
  28069. break;
  28070. case 3: // cidrange
  28071. stream.readHex(start, dataSize);
  28072. stream.readHexNumber(end, dataSize);
  28073. addHex(end, start, dataSize);
  28074. code = stream.readNumber();
  28075. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  28076. code);
  28077. for (i = 1; i < subitemsCount; i++) {
  28078. incHex(end, dataSize);
  28079. if (!sequence) {
  28080. stream.readHexNumber(start, dataSize);
  28081. addHex(start, end, dataSize);
  28082. } else {
  28083. start.set(end);
  28084. }
  28085. stream.readHexNumber(end, dataSize);
  28086. addHex(end, start, dataSize);
  28087. code = stream.readNumber();
  28088. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  28089. code);
  28090. }
  28091. break;
  28092. case 4: // bfchar
  28093. stream.readHex(char, ucs2DataSize);
  28094. stream.readHex(charCode, dataSize);
  28095. cMap.mapOne(hexToInt(char, ucs2DataSize),
  28096. hexToStr(charCode, dataSize));
  28097. for (i = 1; i < subitemsCount; i++) {
  28098. incHex(char, ucs2DataSize);
  28099. if (!sequence) {
  28100. stream.readHexNumber(tmp, ucs2DataSize);
  28101. addHex(char, tmp, ucs2DataSize);
  28102. }
  28103. incHex(charCode, dataSize);
  28104. stream.readHexSigned(tmp, dataSize);
  28105. addHex(charCode, tmp, dataSize);
  28106. cMap.mapOne(hexToInt(char, ucs2DataSize),
  28107. hexToStr(charCode, dataSize));
  28108. }
  28109. break;
  28110. case 5: // bfrange
  28111. stream.readHex(start, ucs2DataSize);
  28112. stream.readHexNumber(end, ucs2DataSize);
  28113. addHex(end, start, ucs2DataSize);
  28114. stream.readHex(charCode, dataSize);
  28115. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  28116. hexToInt(end, ucs2DataSize),
  28117. hexToStr(charCode, dataSize));
  28118. for (i = 1; i < subitemsCount; i++) {
  28119. incHex(end, ucs2DataSize);
  28120. if (!sequence) {
  28121. stream.readHexNumber(start, ucs2DataSize);
  28122. addHex(start, end, ucs2DataSize);
  28123. } else {
  28124. start.set(end);
  28125. }
  28126. stream.readHexNumber(end, ucs2DataSize);
  28127. addHex(end, start, ucs2DataSize);
  28128. stream.readHex(charCode, dataSize);
  28129. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  28130. hexToInt(end, ucs2DataSize),
  28131. hexToStr(charCode, dataSize));
  28132. }
  28133. break;
  28134. default:
  28135. error('Unknown type: ' + type);
  28136. break;
  28137. }
  28138. }
  28139. if (useCMap) {
  28140. extend(useCMap);
  28141. }
  28142. return cMap;
  28143. }
  28144. function BinaryCMapReader() {}
  28145. BinaryCMapReader.prototype = {
  28146. read: processBinaryCMap
  28147. };
  28148. return BinaryCMapReader;
  28149. })();
  28150. var CMapFactory = (function CMapFactoryClosure() {
  28151. function strToInt(str) {
  28152. var a = 0;
  28153. for (var i = 0; i < str.length; i++) {
  28154. a = (a << 8) | str.charCodeAt(i);
  28155. }
  28156. return a >>> 0;
  28157. }
  28158. function expectString(obj) {
  28159. if (!isString(obj)) {
  28160. error('Malformed CMap: expected string.');
  28161. }
  28162. }
  28163. function expectInt(obj) {
  28164. if (!isInt(obj)) {
  28165. error('Malformed CMap: expected int.');
  28166. }
  28167. }
  28168. function parseBfChar(cMap, lexer) {
  28169. while (true) {
  28170. var obj = lexer.getObj();
  28171. if (isEOF(obj)) {
  28172. break;
  28173. }
  28174. if (isCmd(obj, 'endbfchar')) {
  28175. return;
  28176. }
  28177. expectString(obj);
  28178. var src = strToInt(obj);
  28179. obj = lexer.getObj();
  28180. // TODO are /dstName used?
  28181. expectString(obj);
  28182. var dst = obj;
  28183. cMap.mapOne(src, dst);
  28184. }
  28185. }
  28186. function parseBfRange(cMap, lexer) {
  28187. while (true) {
  28188. var obj = lexer.getObj();
  28189. if (isEOF(obj)) {
  28190. break;
  28191. }
  28192. if (isCmd(obj, 'endbfrange')) {
  28193. return;
  28194. }
  28195. expectString(obj);
  28196. var low = strToInt(obj);
  28197. obj = lexer.getObj();
  28198. expectString(obj);
  28199. var high = strToInt(obj);
  28200. obj = lexer.getObj();
  28201. if (isInt(obj) || isString(obj)) {
  28202. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  28203. cMap.mapBfRange(low, high, dstLow);
  28204. } else if (isCmd(obj, '[')) {
  28205. obj = lexer.getObj();
  28206. var array = [];
  28207. while (!isCmd(obj, ']') && !isEOF(obj)) {
  28208. array.push(obj);
  28209. obj = lexer.getObj();
  28210. }
  28211. cMap.mapBfRangeToArray(low, high, array);
  28212. } else {
  28213. break;
  28214. }
  28215. }
  28216. error('Invalid bf range.');
  28217. }
  28218. function parseCidChar(cMap, lexer) {
  28219. while (true) {
  28220. var obj = lexer.getObj();
  28221. if (isEOF(obj)) {
  28222. break;
  28223. }
  28224. if (isCmd(obj, 'endcidchar')) {
  28225. return;
  28226. }
  28227. expectString(obj);
  28228. var src = strToInt(obj);
  28229. obj = lexer.getObj();
  28230. expectInt(obj);
  28231. var dst = obj;
  28232. cMap.mapOne(src, dst);
  28233. }
  28234. }
  28235. function parseCidRange(cMap, lexer) {
  28236. while (true) {
  28237. var obj = lexer.getObj();
  28238. if (isEOF(obj)) {
  28239. break;
  28240. }
  28241. if (isCmd(obj, 'endcidrange')) {
  28242. return;
  28243. }
  28244. expectString(obj);
  28245. var low = strToInt(obj);
  28246. obj = lexer.getObj();
  28247. expectString(obj);
  28248. var high = strToInt(obj);
  28249. obj = lexer.getObj();
  28250. expectInt(obj);
  28251. var dstLow = obj;
  28252. cMap.mapCidRange(low, high, dstLow);
  28253. }
  28254. }
  28255. function parseCodespaceRange(cMap, lexer) {
  28256. while (true) {
  28257. var obj = lexer.getObj();
  28258. if (isEOF(obj)) {
  28259. break;
  28260. }
  28261. if (isCmd(obj, 'endcodespacerange')) {
  28262. return;
  28263. }
  28264. if (!isString(obj)) {
  28265. break;
  28266. }
  28267. var low = strToInt(obj);
  28268. obj = lexer.getObj();
  28269. if (!isString(obj)) {
  28270. break;
  28271. }
  28272. var high = strToInt(obj);
  28273. cMap.addCodespaceRange(obj.length, low, high);
  28274. }
  28275. error('Invalid codespace range.');
  28276. }
  28277. function parseWMode(cMap, lexer) {
  28278. var obj = lexer.getObj();
  28279. if (isInt(obj)) {
  28280. cMap.vertical = !!obj;
  28281. }
  28282. }
  28283. function parseCMapName(cMap, lexer) {
  28284. var obj = lexer.getObj();
  28285. if (isName(obj) && isString(obj.name)) {
  28286. cMap.name = obj.name;
  28287. }
  28288. }
  28289. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  28290. var previous;
  28291. var embededUseCMap;
  28292. objLoop: while (true) {
  28293. var obj = lexer.getObj();
  28294. if (isEOF(obj)) {
  28295. break;
  28296. } else if (isName(obj)) {
  28297. if (obj.name === 'WMode') {
  28298. parseWMode(cMap, lexer);
  28299. } else if (obj.name === 'CMapName') {
  28300. parseCMapName(cMap, lexer);
  28301. }
  28302. previous = obj;
  28303. } else if (isCmd(obj)) {
  28304. switch (obj.cmd) {
  28305. case 'endcmap':
  28306. break objLoop;
  28307. case 'usecmap':
  28308. if (isName(previous)) {
  28309. embededUseCMap = previous.name;
  28310. }
  28311. break;
  28312. case 'begincodespacerange':
  28313. parseCodespaceRange(cMap, lexer);
  28314. break;
  28315. case 'beginbfchar':
  28316. parseBfChar(cMap, lexer);
  28317. break;
  28318. case 'begincidchar':
  28319. parseCidChar(cMap, lexer);
  28320. break;
  28321. case 'beginbfrange':
  28322. parseBfRange(cMap, lexer);
  28323. break;
  28324. case 'begincidrange':
  28325. parseCidRange(cMap, lexer);
  28326. break;
  28327. }
  28328. }
  28329. }
  28330. if (!useCMap && embededUseCMap) {
  28331. // Load the usecmap definition from the file only if there wasn't one
  28332. // specified.
  28333. useCMap = embededUseCMap;
  28334. }
  28335. if (useCMap) {
  28336. extendCMap(cMap, builtInCMapParams, useCMap);
  28337. }
  28338. }
  28339. function extendCMap(cMap, builtInCMapParams, useCMap) {
  28340. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  28341. // If there aren't any code space ranges defined clone all the parent ones
  28342. // into this cMap.
  28343. if (cMap.numCodespaceRanges === 0) {
  28344. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  28345. for (var i = 0; i < useCodespaceRanges.length; i++) {
  28346. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  28347. }
  28348. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  28349. }
  28350. // Merge the map into the current one, making sure not to override
  28351. // any previously defined entries.
  28352. cMap.useCMap.forEach(function(key, value) {
  28353. if (!cMap.contains(key)) {
  28354. cMap.mapOne(key, cMap.useCMap.lookup(key));
  28355. }
  28356. });
  28357. }
  28358. function parseBinaryCMap(name, builtInCMapParams) {
  28359. var url = builtInCMapParams.url + name + '.bcmap';
  28360. var cMap = new CMap(true);
  28361. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  28362. extendCMap(cMap, builtInCMapParams, useCMap);
  28363. });
  28364. return cMap;
  28365. }
  28366. function createBuiltInCMap(name, builtInCMapParams) {
  28367. if (name === 'Identity-H') {
  28368. return new IdentityCMap(false, 2);
  28369. } else if (name === 'Identity-V') {
  28370. return new IdentityCMap(true, 2);
  28371. }
  28372. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  28373. error('Unknown cMap name: ' + name);
  28374. }
  28375. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  28376. if (builtInCMapParams.packed) {
  28377. return parseBinaryCMap(name, builtInCMapParams);
  28378. }
  28379. var request = new XMLHttpRequest();
  28380. var url = builtInCMapParams.url + name;
  28381. request.open('GET', url, false);
  28382. request.send(null);
  28383. if (!request.responseText) {
  28384. error('Unable to get cMap at: ' + url);
  28385. }
  28386. var cMap = new CMap(true);
  28387. var lexer = new Lexer(new StringStream(request.responseText));
  28388. parseCMap(cMap, lexer, builtInCMapParams, null);
  28389. return cMap;
  28390. }
  28391. return {
  28392. create: function (encoding, builtInCMapParams, useCMap) {
  28393. if (isName(encoding)) {
  28394. return createBuiltInCMap(encoding.name, builtInCMapParams);
  28395. } else if (isStream(encoding)) {
  28396. var cMap = new CMap();
  28397. var lexer = new Lexer(encoding);
  28398. try {
  28399. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  28400. } catch (e) {
  28401. warn('Invalid CMap data. ' + e);
  28402. }
  28403. if (cMap.isIdentityCMap) {
  28404. return createBuiltInCMap(cMap.name, builtInCMapParams);
  28405. }
  28406. return cMap;
  28407. }
  28408. error('Encoding required.');
  28409. }
  28410. };
  28411. })();
  28412. exports.CMap = CMap;
  28413. exports.CMapFactory = CMapFactory;
  28414. exports.IdentityCMap = IdentityCMap;
  28415. }));
  28416. (function (root, factory) {
  28417. {
  28418. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  28419. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  28420. root.pdfjsCoreChunkedStream);
  28421. }
  28422. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  28423. coreChunkedStream) {
  28424. var InvalidPDFException = sharedUtil.InvalidPDFException;
  28425. var MissingDataException = sharedUtil.MissingDataException;
  28426. var XRefParseException = sharedUtil.XRefParseException;
  28427. var assert = sharedUtil.assert;
  28428. var bytesToString = sharedUtil.bytesToString;
  28429. var createPromiseCapability = sharedUtil.createPromiseCapability;
  28430. var error = sharedUtil.error;
  28431. var info = sharedUtil.info;
  28432. var isArray = sharedUtil.isArray;
  28433. var isInt = sharedUtil.isInt;
  28434. var isString = sharedUtil.isString;
  28435. var shadow = sharedUtil.shadow;
  28436. var stringToPDFString = sharedUtil.stringToPDFString;
  28437. var stringToUTF8String = sharedUtil.stringToUTF8String;
  28438. var warn = sharedUtil.warn;
  28439. var Ref = corePrimitives.Ref;
  28440. var RefSet = corePrimitives.RefSet;
  28441. var RefSetCache = corePrimitives.RefSetCache;
  28442. var isName = corePrimitives.isName;
  28443. var isCmd = corePrimitives.isCmd;
  28444. var isDict = corePrimitives.isDict;
  28445. var isRef = corePrimitives.isRef;
  28446. var isStream = corePrimitives.isStream;
  28447. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  28448. var Lexer = coreParser.Lexer;
  28449. var Parser = coreParser.Parser;
  28450. var ChunkedStream = coreChunkedStream.ChunkedStream;
  28451. var Catalog = (function CatalogClosure() {
  28452. function Catalog(pdfManager, xref, pageFactory) {
  28453. this.pdfManager = pdfManager;
  28454. this.xref = xref;
  28455. this.catDict = xref.getCatalogObj();
  28456. this.fontCache = new RefSetCache();
  28457. assert(isDict(this.catDict),
  28458. 'catalog object is not a dictionary');
  28459. // TODO refactor to move getPage() to the PDFDocument.
  28460. this.pageFactory = pageFactory;
  28461. this.pagePromises = [];
  28462. }
  28463. Catalog.prototype = {
  28464. get metadata() {
  28465. var streamRef = this.catDict.getRaw('Metadata');
  28466. if (!isRef(streamRef)) {
  28467. return shadow(this, 'metadata', null);
  28468. }
  28469. var encryptMetadata = (!this.xref.encrypt ? false :
  28470. this.xref.encrypt.encryptMetadata);
  28471. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  28472. var metadata;
  28473. if (stream && isDict(stream.dict)) {
  28474. var type = stream.dict.get('Type');
  28475. var subtype = stream.dict.get('Subtype');
  28476. if (isName(type) && isName(subtype) &&
  28477. type.name === 'Metadata' && subtype.name === 'XML') {
  28478. // XXX: This should examine the charset the XML document defines,
  28479. // however since there are currently no real means to decode
  28480. // arbitrary charsets, let's just hope that the author of the PDF
  28481. // was reasonable enough to stick with the XML default charset,
  28482. // which is UTF-8.
  28483. try {
  28484. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  28485. } catch (e) {
  28486. info('Skipping invalid metadata.');
  28487. }
  28488. }
  28489. }
  28490. return shadow(this, 'metadata', metadata);
  28491. },
  28492. get toplevelPagesDict() {
  28493. var pagesObj = this.catDict.get('Pages');
  28494. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  28495. // shadow the prototype getter
  28496. return shadow(this, 'toplevelPagesDict', pagesObj);
  28497. },
  28498. get documentOutline() {
  28499. var obj = null;
  28500. try {
  28501. obj = this.readDocumentOutline();
  28502. } catch (ex) {
  28503. if (ex instanceof MissingDataException) {
  28504. throw ex;
  28505. }
  28506. warn('Unable to read document outline');
  28507. }
  28508. return shadow(this, 'documentOutline', obj);
  28509. },
  28510. readDocumentOutline: function Catalog_readDocumentOutline() {
  28511. var xref = this.xref;
  28512. var obj = this.catDict.get('Outlines');
  28513. var root = { items: [] };
  28514. if (isDict(obj)) {
  28515. obj = obj.getRaw('First');
  28516. var processed = new RefSet();
  28517. if (isRef(obj)) {
  28518. var queue = [{obj: obj, parent: root}];
  28519. // to avoid recursion keeping track of the items
  28520. // in the processed dictionary
  28521. processed.put(obj);
  28522. while (queue.length > 0) {
  28523. var i = queue.shift();
  28524. var outlineDict = xref.fetchIfRef(i.obj);
  28525. if (outlineDict === null) {
  28526. continue;
  28527. }
  28528. if (!outlineDict.has('Title')) {
  28529. error('Invalid outline item');
  28530. }
  28531. var dest = outlineDict.get('A');
  28532. if (dest) {
  28533. dest = dest.get('D');
  28534. } else if (outlineDict.has('Dest')) {
  28535. dest = outlineDict.getRaw('Dest');
  28536. if (isName(dest)) {
  28537. dest = dest.name;
  28538. }
  28539. }
  28540. var title = outlineDict.get('Title');
  28541. var outlineItem = {
  28542. dest: dest,
  28543. title: stringToPDFString(title),
  28544. color: outlineDict.get('C') || [0, 0, 0],
  28545. count: outlineDict.get('Count'),
  28546. bold: !!(outlineDict.get('F') & 2),
  28547. italic: !!(outlineDict.get('F') & 1),
  28548. items: []
  28549. };
  28550. i.parent.items.push(outlineItem);
  28551. obj = outlineDict.getRaw('First');
  28552. if (isRef(obj) && !processed.has(obj)) {
  28553. queue.push({obj: obj, parent: outlineItem});
  28554. processed.put(obj);
  28555. }
  28556. obj = outlineDict.getRaw('Next');
  28557. if (isRef(obj) && !processed.has(obj)) {
  28558. queue.push({obj: obj, parent: i.parent});
  28559. processed.put(obj);
  28560. }
  28561. }
  28562. }
  28563. }
  28564. return (root.items.length > 0 ? root.items : null);
  28565. },
  28566. get numPages() {
  28567. var obj = this.toplevelPagesDict.get('Count');
  28568. assert(
  28569. isInt(obj),
  28570. 'page count in top level pages object is not an integer'
  28571. );
  28572. // shadow the prototype getter
  28573. return shadow(this, 'num', obj);
  28574. },
  28575. get destinations() {
  28576. function fetchDestination(dest) {
  28577. return isDict(dest) ? dest.get('D') : dest;
  28578. }
  28579. var xref = this.xref;
  28580. var dests = {}, nameTreeRef, nameDictionaryRef;
  28581. var obj = this.catDict.get('Names');
  28582. if (obj && obj.has('Dests')) {
  28583. nameTreeRef = obj.getRaw('Dests');
  28584. } else if (this.catDict.has('Dests')) {
  28585. nameDictionaryRef = this.catDict.get('Dests');
  28586. }
  28587. if (nameDictionaryRef) {
  28588. // reading simple destination dictionary
  28589. obj = nameDictionaryRef;
  28590. obj.forEach(function catalogForEach(key, value) {
  28591. if (!value) {
  28592. return;
  28593. }
  28594. dests[key] = fetchDestination(value);
  28595. });
  28596. }
  28597. if (nameTreeRef) {
  28598. var nameTree = new NameTree(nameTreeRef, xref);
  28599. var names = nameTree.getAll();
  28600. for (var name in names) {
  28601. if (!names.hasOwnProperty(name)) {
  28602. continue;
  28603. }
  28604. dests[name] = fetchDestination(names[name]);
  28605. }
  28606. }
  28607. return shadow(this, 'destinations', dests);
  28608. },
  28609. getDestination: function Catalog_getDestination(destinationId) {
  28610. function fetchDestination(dest) {
  28611. return isDict(dest) ? dest.get('D') : dest;
  28612. }
  28613. var xref = this.xref;
  28614. var dest = null, nameTreeRef, nameDictionaryRef;
  28615. var obj = this.catDict.get('Names');
  28616. if (obj && obj.has('Dests')) {
  28617. nameTreeRef = obj.getRaw('Dests');
  28618. } else if (this.catDict.has('Dests')) {
  28619. nameDictionaryRef = this.catDict.get('Dests');
  28620. }
  28621. if (nameDictionaryRef) { // Simple destination dictionary.
  28622. var value = nameDictionaryRef.get(destinationId);
  28623. if (value) {
  28624. dest = fetchDestination(value);
  28625. }
  28626. }
  28627. if (nameTreeRef) {
  28628. var nameTree = new NameTree(nameTreeRef, xref);
  28629. dest = fetchDestination(nameTree.get(destinationId));
  28630. }
  28631. return dest;
  28632. },
  28633. get attachments() {
  28634. var xref = this.xref;
  28635. var attachments = null, nameTreeRef;
  28636. var obj = this.catDict.get('Names');
  28637. if (obj) {
  28638. nameTreeRef = obj.getRaw('EmbeddedFiles');
  28639. }
  28640. if (nameTreeRef) {
  28641. var nameTree = new NameTree(nameTreeRef, xref);
  28642. var names = nameTree.getAll();
  28643. for (var name in names) {
  28644. if (!names.hasOwnProperty(name)) {
  28645. continue;
  28646. }
  28647. var fs = new FileSpec(names[name], xref);
  28648. if (!attachments) {
  28649. attachments = {};
  28650. }
  28651. attachments[stringToPDFString(name)] = fs.serializable;
  28652. }
  28653. }
  28654. return shadow(this, 'attachments', attachments);
  28655. },
  28656. get javaScript() {
  28657. var xref = this.xref;
  28658. var obj = this.catDict.get('Names');
  28659. var javaScript = [];
  28660. function appendIfJavaScriptDict(jsDict) {
  28661. var type = jsDict.get('S');
  28662. if (!isName(type) || type.name !== 'JavaScript') {
  28663. return;
  28664. }
  28665. var js = jsDict.get('JS');
  28666. if (isStream(js)) {
  28667. js = bytesToString(js.getBytes());
  28668. } else if (!isString(js)) {
  28669. return;
  28670. }
  28671. javaScript.push(stringToPDFString(js));
  28672. }
  28673. if (obj && obj.has('JavaScript')) {
  28674. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  28675. var names = nameTree.getAll();
  28676. for (var name in names) {
  28677. if (!names.hasOwnProperty(name)) {
  28678. continue;
  28679. }
  28680. // We don't really use the JavaScript right now. This code is
  28681. // defensive so we don't cause errors on document load.
  28682. var jsDict = names[name];
  28683. if (isDict(jsDict)) {
  28684. appendIfJavaScriptDict(jsDict);
  28685. }
  28686. }
  28687. }
  28688. // Append OpenAction actions to javaScript array
  28689. var openactionDict = this.catDict.get('OpenAction');
  28690. if (isDict(openactionDict, 'Action')) {
  28691. var actionType = openactionDict.get('S');
  28692. if (isName(actionType) && actionType.name === 'Named') {
  28693. // The named Print action is not a part of the PDF 1.7 specification,
  28694. // but is supported by many PDF readers/writers (including Adobe's).
  28695. var action = openactionDict.get('N');
  28696. if (isName(action) && action.name === 'Print') {
  28697. javaScript.push('print({});');
  28698. }
  28699. } else {
  28700. appendIfJavaScriptDict(openactionDict);
  28701. }
  28702. }
  28703. return shadow(this, 'javaScript', javaScript);
  28704. },
  28705. cleanup: function Catalog_cleanup() {
  28706. var promises = [];
  28707. this.fontCache.forEach(function (promise) {
  28708. promises.push(promise);
  28709. });
  28710. return Promise.all(promises).then(function (translatedFonts) {
  28711. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  28712. var font = translatedFonts[i].dict;
  28713. delete font.translated;
  28714. }
  28715. this.fontCache.clear();
  28716. }.bind(this));
  28717. },
  28718. getPage: function Catalog_getPage(pageIndex) {
  28719. if (!(pageIndex in this.pagePromises)) {
  28720. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  28721. function (a) {
  28722. var dict = a[0];
  28723. var ref = a[1];
  28724. return this.pageFactory.createPage(pageIndex, dict, ref,
  28725. this.fontCache);
  28726. }.bind(this)
  28727. );
  28728. }
  28729. return this.pagePromises[pageIndex];
  28730. },
  28731. getPageDict: function Catalog_getPageDict(pageIndex) {
  28732. var capability = createPromiseCapability();
  28733. var nodesToVisit = [this.catDict.getRaw('Pages')];
  28734. var currentPageIndex = 0;
  28735. var xref = this.xref;
  28736. var checkAllKids = false;
  28737. function next() {
  28738. while (nodesToVisit.length) {
  28739. var currentNode = nodesToVisit.pop();
  28740. if (isRef(currentNode)) {
  28741. xref.fetchAsync(currentNode).then(function (obj) {
  28742. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  28743. if (pageIndex === currentPageIndex) {
  28744. capability.resolve([obj, currentNode]);
  28745. } else {
  28746. currentPageIndex++;
  28747. next();
  28748. }
  28749. return;
  28750. }
  28751. nodesToVisit.push(obj);
  28752. next();
  28753. }, capability.reject);
  28754. return;
  28755. }
  28756. // Must be a child page dictionary.
  28757. assert(
  28758. isDict(currentNode),
  28759. 'page dictionary kid reference points to wrong type of object'
  28760. );
  28761. var count = currentNode.get('Count');
  28762. // If the current node doesn't have any children, avoid getting stuck
  28763. // in an empty node further down in the tree (see issue5644.pdf).
  28764. if (count === 0) {
  28765. checkAllKids = true;
  28766. }
  28767. // Skip nodes where the page can't be.
  28768. if (currentPageIndex + count <= pageIndex) {
  28769. currentPageIndex += count;
  28770. continue;
  28771. }
  28772. var kids = currentNode.get('Kids');
  28773. assert(isArray(kids), 'page dictionary kids object is not an array');
  28774. if (!checkAllKids && count === kids.length) {
  28775. // Nodes that don't have the page have been skipped and this is the
  28776. // bottom of the tree which means the page requested must be a
  28777. // descendant of this pages node. Ideally we would just resolve the
  28778. // promise with the page ref here, but there is the case where more
  28779. // pages nodes could link to single a page (see issue 3666 pdf). To
  28780. // handle this push it back on the queue so if it is a pages node it
  28781. // will be descended into.
  28782. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  28783. currentPageIndex = pageIndex;
  28784. continue;
  28785. } else {
  28786. for (var last = kids.length - 1; last >= 0; last--) {
  28787. nodesToVisit.push(kids[last]);
  28788. }
  28789. }
  28790. }
  28791. capability.reject('Page index ' + pageIndex + ' not found.');
  28792. }
  28793. next();
  28794. return capability.promise;
  28795. },
  28796. getPageIndex: function Catalog_getPageIndex(ref) {
  28797. // The page tree nodes have the count of all the leaves below them. To get
  28798. // how many pages are before we just have to walk up the tree and keep
  28799. // adding the count of siblings to the left of the node.
  28800. var xref = this.xref;
  28801. function pagesBeforeRef(kidRef) {
  28802. var total = 0;
  28803. var parentRef;
  28804. return xref.fetchAsync(kidRef).then(function (node) {
  28805. if (!node) {
  28806. return null;
  28807. }
  28808. parentRef = node.getRaw('Parent');
  28809. return node.getAsync('Parent');
  28810. }).then(function (parent) {
  28811. if (!parent) {
  28812. return null;
  28813. }
  28814. return parent.getAsync('Kids');
  28815. }).then(function (kids) {
  28816. if (!kids) {
  28817. return null;
  28818. }
  28819. var kidPromises = [];
  28820. var found = false;
  28821. for (var i = 0; i < kids.length; i++) {
  28822. var kid = kids[i];
  28823. assert(isRef(kid), 'kids must be a ref');
  28824. if (kid.num === kidRef.num) {
  28825. found = true;
  28826. break;
  28827. }
  28828. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  28829. if (kid.has('Count')) {
  28830. var count = kid.get('Count');
  28831. total += count;
  28832. } else { // page leaf node
  28833. total++;
  28834. }
  28835. }));
  28836. }
  28837. if (!found) {
  28838. error('kid ref not found in parents kids');
  28839. }
  28840. return Promise.all(kidPromises).then(function () {
  28841. return [total, parentRef];
  28842. });
  28843. });
  28844. }
  28845. var total = 0;
  28846. function next(ref) {
  28847. return pagesBeforeRef(ref).then(function (args) {
  28848. if (!args) {
  28849. return total;
  28850. }
  28851. var count = args[0];
  28852. var parentRef = args[1];
  28853. total += count;
  28854. return next(parentRef);
  28855. });
  28856. }
  28857. return next(ref);
  28858. }
  28859. };
  28860. return Catalog;
  28861. })();
  28862. var XRef = (function XRefClosure() {
  28863. function XRef(stream, password) {
  28864. this.stream = stream;
  28865. this.entries = [];
  28866. this.xrefstms = {};
  28867. // prepare the XRef cache
  28868. this.cache = [];
  28869. this.password = password;
  28870. this.stats = {
  28871. streamTypes: [],
  28872. fontTypes: []
  28873. };
  28874. }
  28875. XRef.prototype = {
  28876. setStartXRef: function XRef_setStartXRef(startXRef) {
  28877. // Store the starting positions of xref tables as we process them
  28878. // so we can recover from missing data errors
  28879. this.startXRefQueue = [startXRef];
  28880. },
  28881. parse: function XRef_parse(recoveryMode) {
  28882. var trailerDict;
  28883. if (!recoveryMode) {
  28884. trailerDict = this.readXRef();
  28885. } else {
  28886. warn('Indexing all PDF objects');
  28887. trailerDict = this.indexObjects();
  28888. }
  28889. trailerDict.assignXref(this);
  28890. this.trailer = trailerDict;
  28891. var encrypt = trailerDict.get('Encrypt');
  28892. if (encrypt) {
  28893. var ids = trailerDict.get('ID');
  28894. var fileId = (ids && ids.length) ? ids[0] : '';
  28895. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  28896. this.password);
  28897. }
  28898. // get the root dictionary (catalog) object
  28899. if (!(this.root = trailerDict.get('Root'))) {
  28900. error('Invalid root reference');
  28901. }
  28902. },
  28903. processXRefTable: function XRef_processXRefTable(parser) {
  28904. if (!('tableState' in this)) {
  28905. // Stores state of the table as we process it so we can resume
  28906. // from middle of table in case of missing data error
  28907. this.tableState = {
  28908. entryNum: 0,
  28909. streamPos: parser.lexer.stream.pos,
  28910. parserBuf1: parser.buf1,
  28911. parserBuf2: parser.buf2
  28912. };
  28913. }
  28914. var obj = this.readXRefTable(parser);
  28915. // Sanity check
  28916. if (!isCmd(obj, 'trailer')) {
  28917. error('Invalid XRef table: could not find trailer dictionary');
  28918. }
  28919. // Read trailer dictionary, e.g.
  28920. // trailer
  28921. // << /Size 22
  28922. // /Root 20R
  28923. // /Info 10R
  28924. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  28925. // >>
  28926. // The parser goes through the entire stream << ... >> and provides
  28927. // a getter interface for the key-value table
  28928. var dict = parser.getObj();
  28929. // The pdflib PDF generator can generate a nested trailer dictionary
  28930. if (!isDict(dict) && dict.dict) {
  28931. dict = dict.dict;
  28932. }
  28933. if (!isDict(dict)) {
  28934. error('Invalid XRef table: could not parse trailer dictionary');
  28935. }
  28936. delete this.tableState;
  28937. return dict;
  28938. },
  28939. readXRefTable: function XRef_readXRefTable(parser) {
  28940. // Example of cross-reference table:
  28941. // xref
  28942. // 0 1 <-- subsection header (first obj #, obj count)
  28943. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  28944. // 23 2 <-- subsection header ... and so on ...
  28945. // 0000025518 00002 n
  28946. // 0000025635 00000 n
  28947. // trailer
  28948. // ...
  28949. var stream = parser.lexer.stream;
  28950. var tableState = this.tableState;
  28951. stream.pos = tableState.streamPos;
  28952. parser.buf1 = tableState.parserBuf1;
  28953. parser.buf2 = tableState.parserBuf2;
  28954. // Outer loop is over subsection headers
  28955. var obj;
  28956. while (true) {
  28957. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  28958. if (isCmd(obj = parser.getObj(), 'trailer')) {
  28959. break;
  28960. }
  28961. tableState.firstEntryNum = obj;
  28962. tableState.entryCount = parser.getObj();
  28963. }
  28964. var first = tableState.firstEntryNum;
  28965. var count = tableState.entryCount;
  28966. if (!isInt(first) || !isInt(count)) {
  28967. error('Invalid XRef table: wrong types in subsection header');
  28968. }
  28969. // Inner loop is over objects themselves
  28970. for (var i = tableState.entryNum; i < count; i++) {
  28971. tableState.streamPos = stream.pos;
  28972. tableState.entryNum = i;
  28973. tableState.parserBuf1 = parser.buf1;
  28974. tableState.parserBuf2 = parser.buf2;
  28975. var entry = {};
  28976. entry.offset = parser.getObj();
  28977. entry.gen = parser.getObj();
  28978. var type = parser.getObj();
  28979. if (isCmd(type, 'f')) {
  28980. entry.free = true;
  28981. } else if (isCmd(type, 'n')) {
  28982. entry.uncompressed = true;
  28983. }
  28984. // Validate entry obj
  28985. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  28986. !(entry.free || entry.uncompressed)) {
  28987. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  28988. }
  28989. if (!this.entries[i + first]) {
  28990. this.entries[i + first] = entry;
  28991. }
  28992. }
  28993. tableState.entryNum = 0;
  28994. tableState.streamPos = stream.pos;
  28995. tableState.parserBuf1 = parser.buf1;
  28996. tableState.parserBuf2 = parser.buf2;
  28997. delete tableState.firstEntryNum;
  28998. delete tableState.entryCount;
  28999. }
  29000. // Per issue 3248: hp scanners generate bad XRef
  29001. if (first === 1 && this.entries[1] && this.entries[1].free) {
  29002. // shifting the entries
  29003. this.entries.shift();
  29004. }
  29005. // Sanity check: as per spec, first object must be free
  29006. if (this.entries[0] && !this.entries[0].free) {
  29007. error('Invalid XRef table: unexpected first object');
  29008. }
  29009. return obj;
  29010. },
  29011. processXRefStream: function XRef_processXRefStream(stream) {
  29012. if (!('streamState' in this)) {
  29013. // Stores state of the stream as we process it so we can resume
  29014. // from middle of stream in case of missing data error
  29015. var streamParameters = stream.dict;
  29016. var byteWidths = streamParameters.get('W');
  29017. var range = streamParameters.get('Index');
  29018. if (!range) {
  29019. range = [0, streamParameters.get('Size')];
  29020. }
  29021. this.streamState = {
  29022. entryRanges: range,
  29023. byteWidths: byteWidths,
  29024. entryNum: 0,
  29025. streamPos: stream.pos
  29026. };
  29027. }
  29028. this.readXRefStream(stream);
  29029. delete this.streamState;
  29030. return stream.dict;
  29031. },
  29032. readXRefStream: function XRef_readXRefStream(stream) {
  29033. var i, j;
  29034. var streamState = this.streamState;
  29035. stream.pos = streamState.streamPos;
  29036. var byteWidths = streamState.byteWidths;
  29037. var typeFieldWidth = byteWidths[0];
  29038. var offsetFieldWidth = byteWidths[1];
  29039. var generationFieldWidth = byteWidths[2];
  29040. var entryRanges = streamState.entryRanges;
  29041. while (entryRanges.length > 0) {
  29042. var first = entryRanges[0];
  29043. var n = entryRanges[1];
  29044. if (!isInt(first) || !isInt(n)) {
  29045. error('Invalid XRef range fields: ' + first + ', ' + n);
  29046. }
  29047. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  29048. !isInt(generationFieldWidth)) {
  29049. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  29050. }
  29051. for (i = streamState.entryNum; i < n; ++i) {
  29052. streamState.entryNum = i;
  29053. streamState.streamPos = stream.pos;
  29054. var type = 0, offset = 0, generation = 0;
  29055. for (j = 0; j < typeFieldWidth; ++j) {
  29056. type = (type << 8) | stream.getByte();
  29057. }
  29058. // if type field is absent, its default value is 1
  29059. if (typeFieldWidth === 0) {
  29060. type = 1;
  29061. }
  29062. for (j = 0; j < offsetFieldWidth; ++j) {
  29063. offset = (offset << 8) | stream.getByte();
  29064. }
  29065. for (j = 0; j < generationFieldWidth; ++j) {
  29066. generation = (generation << 8) | stream.getByte();
  29067. }
  29068. var entry = {};
  29069. entry.offset = offset;
  29070. entry.gen = generation;
  29071. switch (type) {
  29072. case 0:
  29073. entry.free = true;
  29074. break;
  29075. case 1:
  29076. entry.uncompressed = true;
  29077. break;
  29078. case 2:
  29079. break;
  29080. default:
  29081. error('Invalid XRef entry type: ' + type);
  29082. }
  29083. if (!this.entries[first + i]) {
  29084. this.entries[first + i] = entry;
  29085. }
  29086. }
  29087. streamState.entryNum = 0;
  29088. streamState.streamPos = stream.pos;
  29089. entryRanges.splice(0, 2);
  29090. }
  29091. },
  29092. indexObjects: function XRef_indexObjects() {
  29093. // Simple scan through the PDF content to find objects,
  29094. // trailers and XRef streams.
  29095. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  29096. var PERCENT = 0x25, LT = 0x3C;
  29097. function readToken(data, offset) {
  29098. var token = '', ch = data[offset];
  29099. while (ch !== LF && ch !== CR && ch !== LT) {
  29100. if (++offset >= data.length) {
  29101. break;
  29102. }
  29103. token += String.fromCharCode(ch);
  29104. ch = data[offset];
  29105. }
  29106. return token;
  29107. }
  29108. function skipUntil(data, offset, what) {
  29109. var length = what.length, dataLength = data.length;
  29110. var skipped = 0;
  29111. // finding byte sequence
  29112. while (offset < dataLength) {
  29113. var i = 0;
  29114. while (i < length && data[offset + i] === what[i]) {
  29115. ++i;
  29116. }
  29117. if (i >= length) {
  29118. break; // sequence found
  29119. }
  29120. offset++;
  29121. skipped++;
  29122. }
  29123. return skipped;
  29124. }
  29125. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  29126. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  29127. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  29128. 101, 102]);
  29129. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  29130. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  29131. // Clear out any existing entries, since they may be bogus.
  29132. this.entries.length = 0;
  29133. var stream = this.stream;
  29134. stream.pos = 0;
  29135. var buffer = stream.getBytes();
  29136. var position = stream.start, length = buffer.length;
  29137. var trailers = [], xrefStms = [];
  29138. while (position < length) {
  29139. var ch = buffer[position];
  29140. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  29141. ++position;
  29142. continue;
  29143. }
  29144. if (ch === PERCENT) { // %-comment
  29145. do {
  29146. ++position;
  29147. if (position >= length) {
  29148. break;
  29149. }
  29150. ch = buffer[position];
  29151. } while (ch !== LF && ch !== CR);
  29152. continue;
  29153. }
  29154. var token = readToken(buffer, position);
  29155. var m;
  29156. if (token.indexOf('xref') === 0 &&
  29157. (token.length === 4 || /\s/.test(token[4]))) {
  29158. position += skipUntil(buffer, position, trailerBytes);
  29159. trailers.push(position);
  29160. position += skipUntil(buffer, position, startxrefBytes);
  29161. } else if ((m = objRegExp.exec(token))) {
  29162. if (typeof this.entries[m[1]] === 'undefined') {
  29163. this.entries[m[1]] = {
  29164. offset: position - stream.start,
  29165. gen: m[2] | 0,
  29166. uncompressed: true
  29167. };
  29168. }
  29169. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  29170. var content = buffer.subarray(position, position + contentLength);
  29171. // checking XRef stream suspect
  29172. // (it shall have '/XRef' and next char is not a letter)
  29173. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  29174. if (xrefTagOffset < contentLength &&
  29175. content[xrefTagOffset + 5] < 64) {
  29176. xrefStms.push(position - stream.start);
  29177. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  29178. }
  29179. position += contentLength;
  29180. } else if (token.indexOf('trailer') === 0 &&
  29181. (token.length === 7 || /\s/.test(token[7]))) {
  29182. trailers.push(position);
  29183. position += skipUntil(buffer, position, startxrefBytes);
  29184. } else {
  29185. position += token.length + 1;
  29186. }
  29187. }
  29188. // reading XRef streams
  29189. var i, ii;
  29190. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  29191. this.startXRefQueue.push(xrefStms[i]);
  29192. this.readXRef(/* recoveryMode */ true);
  29193. }
  29194. // finding main trailer
  29195. var dict;
  29196. for (i = 0, ii = trailers.length; i < ii; ++i) {
  29197. stream.pos = trailers[i];
  29198. var parser = new Parser(new Lexer(stream), true, this);
  29199. var obj = parser.getObj();
  29200. if (!isCmd(obj, 'trailer')) {
  29201. continue;
  29202. }
  29203. // read the trailer dictionary
  29204. if (!isDict(dict = parser.getObj())) {
  29205. continue;
  29206. }
  29207. // taking the first one with 'ID'
  29208. if (dict.has('ID')) {
  29209. return dict;
  29210. }
  29211. }
  29212. // no tailer with 'ID', taking last one (if exists)
  29213. if (dict) {
  29214. return dict;
  29215. }
  29216. // nothing helps
  29217. // calling error() would reject worker with an UnknownErrorException.
  29218. throw new InvalidPDFException('Invalid PDF structure');
  29219. },
  29220. readXRef: function XRef_readXRef(recoveryMode) {
  29221. var stream = this.stream;
  29222. try {
  29223. while (this.startXRefQueue.length) {
  29224. var startXRef = this.startXRefQueue[0];
  29225. stream.pos = startXRef + stream.start;
  29226. var parser = new Parser(new Lexer(stream), true, this);
  29227. var obj = parser.getObj();
  29228. var dict;
  29229. // Get dictionary
  29230. if (isCmd(obj, 'xref')) {
  29231. // Parse end-of-file XRef
  29232. dict = this.processXRefTable(parser);
  29233. if (!this.topDict) {
  29234. this.topDict = dict;
  29235. }
  29236. // Recursively get other XRefs 'XRefStm', if any
  29237. obj = dict.get('XRefStm');
  29238. if (isInt(obj)) {
  29239. var pos = obj;
  29240. // ignore previously loaded xref streams
  29241. // (possible infinite recursion)
  29242. if (!(pos in this.xrefstms)) {
  29243. this.xrefstms[pos] = 1;
  29244. this.startXRefQueue.push(pos);
  29245. }
  29246. }
  29247. } else if (isInt(obj)) {
  29248. // Parse in-stream XRef
  29249. if (!isInt(parser.getObj()) ||
  29250. !isCmd(parser.getObj(), 'obj') ||
  29251. !isStream(obj = parser.getObj())) {
  29252. error('Invalid XRef stream');
  29253. }
  29254. dict = this.processXRefStream(obj);
  29255. if (!this.topDict) {
  29256. this.topDict = dict;
  29257. }
  29258. if (!dict) {
  29259. error('Failed to read XRef stream');
  29260. }
  29261. } else {
  29262. error('Invalid XRef stream header');
  29263. }
  29264. // Recursively get previous dictionary, if any
  29265. obj = dict.get('Prev');
  29266. if (isInt(obj)) {
  29267. this.startXRefQueue.push(obj);
  29268. } else if (isRef(obj)) {
  29269. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  29270. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  29271. this.startXRefQueue.push(obj.num);
  29272. }
  29273. this.startXRefQueue.shift();
  29274. }
  29275. return this.topDict;
  29276. } catch (e) {
  29277. if (e instanceof MissingDataException) {
  29278. throw e;
  29279. }
  29280. info('(while reading XRef): ' + e);
  29281. }
  29282. if (recoveryMode) {
  29283. return;
  29284. }
  29285. throw new XRefParseException();
  29286. },
  29287. getEntry: function XRef_getEntry(i) {
  29288. var xrefEntry = this.entries[i];
  29289. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  29290. return xrefEntry;
  29291. }
  29292. return null;
  29293. },
  29294. fetchIfRef: function XRef_fetchIfRef(obj) {
  29295. if (!isRef(obj)) {
  29296. return obj;
  29297. }
  29298. return this.fetch(obj);
  29299. },
  29300. fetch: function XRef_fetch(ref, suppressEncryption) {
  29301. assert(isRef(ref), 'ref object is not a reference');
  29302. var num = ref.num;
  29303. if (num in this.cache) {
  29304. var cacheEntry = this.cache[num];
  29305. return cacheEntry;
  29306. }
  29307. var xrefEntry = this.getEntry(num);
  29308. // the referenced entry can be free
  29309. if (xrefEntry === null) {
  29310. return (this.cache[num] = null);
  29311. }
  29312. if (xrefEntry.uncompressed) {
  29313. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  29314. } else {
  29315. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  29316. }
  29317. if (isDict(xrefEntry)){
  29318. xrefEntry.objId = ref.toString();
  29319. } else if (isStream(xrefEntry)) {
  29320. xrefEntry.dict.objId = ref.toString();
  29321. }
  29322. return xrefEntry;
  29323. },
  29324. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  29325. suppressEncryption) {
  29326. var gen = ref.gen;
  29327. var num = ref.num;
  29328. if (xrefEntry.gen !== gen) {
  29329. error('inconsistent generation in XRef');
  29330. }
  29331. var stream = this.stream.makeSubStream(xrefEntry.offset +
  29332. this.stream.start);
  29333. var parser = new Parser(new Lexer(stream), true, this);
  29334. var obj1 = parser.getObj();
  29335. var obj2 = parser.getObj();
  29336. var obj3 = parser.getObj();
  29337. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  29338. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  29339. !isCmd(obj3)) {
  29340. error('bad XRef entry');
  29341. }
  29342. if (!isCmd(obj3, 'obj')) {
  29343. // some bad PDFs use "obj1234" and really mean 1234
  29344. if (obj3.cmd.indexOf('obj') === 0) {
  29345. num = parseInt(obj3.cmd.substring(3), 10);
  29346. if (!isNaN(num)) {
  29347. return num;
  29348. }
  29349. }
  29350. error('bad XRef entry');
  29351. }
  29352. if (this.encrypt && !suppressEncryption) {
  29353. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  29354. } else {
  29355. xrefEntry = parser.getObj();
  29356. }
  29357. if (!isStream(xrefEntry)) {
  29358. this.cache[num] = xrefEntry;
  29359. }
  29360. return xrefEntry;
  29361. },
  29362. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  29363. suppressEncryption) {
  29364. var tableOffset = xrefEntry.offset;
  29365. var stream = this.fetch(new Ref(tableOffset, 0));
  29366. if (!isStream(stream)) {
  29367. error('bad ObjStm stream');
  29368. }
  29369. var first = stream.dict.get('First');
  29370. var n = stream.dict.get('N');
  29371. if (!isInt(first) || !isInt(n)) {
  29372. error('invalid first and n parameters for ObjStm stream');
  29373. }
  29374. var parser = new Parser(new Lexer(stream), false, this);
  29375. parser.allowStreams = true;
  29376. var i, entries = [], num, nums = [];
  29377. // read the object numbers to populate cache
  29378. for (i = 0; i < n; ++i) {
  29379. num = parser.getObj();
  29380. if (!isInt(num)) {
  29381. error('invalid object number in the ObjStm stream: ' + num);
  29382. }
  29383. nums.push(num);
  29384. var offset = parser.getObj();
  29385. if (!isInt(offset)) {
  29386. error('invalid object offset in the ObjStm stream: ' + offset);
  29387. }
  29388. }
  29389. // read stream objects for cache
  29390. for (i = 0; i < n; ++i) {
  29391. entries.push(parser.getObj());
  29392. num = nums[i];
  29393. var entry = this.entries[num];
  29394. if (entry && entry.offset === tableOffset && entry.gen === i) {
  29395. this.cache[num] = entries[i];
  29396. }
  29397. }
  29398. xrefEntry = entries[xrefEntry.gen];
  29399. if (xrefEntry === undefined) {
  29400. error('bad XRef entry for compressed object');
  29401. }
  29402. return xrefEntry;
  29403. },
  29404. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  29405. if (!isRef(obj)) {
  29406. return Promise.resolve(obj);
  29407. }
  29408. return this.fetchAsync(obj);
  29409. },
  29410. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  29411. var streamManager = this.stream.manager;
  29412. var xref = this;
  29413. return new Promise(function tryFetch(resolve, reject) {
  29414. try {
  29415. resolve(xref.fetch(ref, suppressEncryption));
  29416. } catch (e) {
  29417. if (e instanceof MissingDataException) {
  29418. streamManager.requestRange(e.begin, e.end).then(function () {
  29419. tryFetch(resolve, reject);
  29420. }, reject);
  29421. return;
  29422. }
  29423. reject(e);
  29424. }
  29425. });
  29426. },
  29427. getCatalogObj: function XRef_getCatalogObj() {
  29428. return this.root;
  29429. }
  29430. };
  29431. return XRef;
  29432. })();
  29433. /**
  29434. * A NameTree is like a Dict but has some advantageous properties, see the
  29435. * spec (7.9.6) for more details.
  29436. * TODO: implement all the Dict functions and make this more efficent.
  29437. */
  29438. var NameTree = (function NameTreeClosure() {
  29439. function NameTree(root, xref) {
  29440. this.root = root;
  29441. this.xref = xref;
  29442. }
  29443. NameTree.prototype = {
  29444. getAll: function NameTree_getAll() {
  29445. var dict = {};
  29446. if (!this.root) {
  29447. return dict;
  29448. }
  29449. var xref = this.xref;
  29450. // reading name tree
  29451. var processed = new RefSet();
  29452. processed.put(this.root);
  29453. var queue = [this.root];
  29454. while (queue.length > 0) {
  29455. var i, n;
  29456. var obj = xref.fetchIfRef(queue.shift());
  29457. if (!isDict(obj)) {
  29458. continue;
  29459. }
  29460. if (obj.has('Kids')) {
  29461. var kids = obj.get('Kids');
  29462. for (i = 0, n = kids.length; i < n; i++) {
  29463. var kid = kids[i];
  29464. if (processed.has(kid)) {
  29465. error('invalid destinations');
  29466. }
  29467. queue.push(kid);
  29468. processed.put(kid);
  29469. }
  29470. continue;
  29471. }
  29472. var names = obj.get('Names');
  29473. if (names) {
  29474. for (i = 0, n = names.length; i < n; i += 2) {
  29475. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  29476. }
  29477. }
  29478. }
  29479. return dict;
  29480. },
  29481. get: function NameTree_get(destinationId) {
  29482. if (!this.root) {
  29483. return null;
  29484. }
  29485. var xref = this.xref;
  29486. var kidsOrNames = xref.fetchIfRef(this.root);
  29487. var loopCount = 0;
  29488. var MAX_NAMES_LEVELS = 10;
  29489. var l, r, m;
  29490. // Perform a binary search to quickly find the entry that
  29491. // contains the named destination we are looking for.
  29492. while (kidsOrNames.has('Kids')) {
  29493. loopCount++;
  29494. if (loopCount > MAX_NAMES_LEVELS) {
  29495. warn('Search depth limit for named destionations has been reached.');
  29496. return null;
  29497. }
  29498. var kids = kidsOrNames.get('Kids');
  29499. if (!isArray(kids)) {
  29500. return null;
  29501. }
  29502. l = 0;
  29503. r = kids.length - 1;
  29504. while (l <= r) {
  29505. m = (l + r) >> 1;
  29506. var kid = xref.fetchIfRef(kids[m]);
  29507. var limits = kid.get('Limits');
  29508. if (destinationId < xref.fetchIfRef(limits[0])) {
  29509. r = m - 1;
  29510. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  29511. l = m + 1;
  29512. } else {
  29513. kidsOrNames = xref.fetchIfRef(kids[m]);
  29514. break;
  29515. }
  29516. }
  29517. if (l > r) {
  29518. return null;
  29519. }
  29520. }
  29521. // If we get here, then we have found the right entry. Now
  29522. // go through the named destinations in the Named dictionary
  29523. // until we find the exact destination we're looking for.
  29524. var names = kidsOrNames.get('Names');
  29525. if (isArray(names)) {
  29526. // Perform a binary search to reduce the lookup time.
  29527. l = 0;
  29528. r = names.length - 2;
  29529. while (l <= r) {
  29530. // Check only even indices (0, 2, 4, ...) because the
  29531. // odd indices contain the actual D array.
  29532. m = (l + r) & ~1;
  29533. if (destinationId < xref.fetchIfRef(names[m])) {
  29534. r = m - 2;
  29535. } else if (destinationId > xref.fetchIfRef(names[m])) {
  29536. l = m + 2;
  29537. } else {
  29538. return xref.fetchIfRef(names[m + 1]);
  29539. }
  29540. }
  29541. }
  29542. return null;
  29543. }
  29544. };
  29545. return NameTree;
  29546. })();
  29547. /**
  29548. * "A PDF file can refer to the contents of another file by using a File
  29549. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  29550. * NOTE: Only embedded files are supported (as part of the attachments support)
  29551. * TODO: support the 'URL' file system (with caching if !/V), portable
  29552. * collections attributes and related files (/RF)
  29553. */
  29554. var FileSpec = (function FileSpecClosure() {
  29555. function FileSpec(root, xref) {
  29556. if (!root || !isDict(root)) {
  29557. return;
  29558. }
  29559. this.xref = xref;
  29560. this.root = root;
  29561. if (root.has('FS')) {
  29562. this.fs = root.get('FS');
  29563. }
  29564. this.description = root.has('Desc') ?
  29565. stringToPDFString(root.get('Desc')) :
  29566. '';
  29567. if (root.has('RF')) {
  29568. warn('Related file specifications are not supported');
  29569. }
  29570. this.contentAvailable = true;
  29571. if (!root.has('EF')) {
  29572. this.contentAvailable = false;
  29573. warn('Non-embedded file specifications are not supported');
  29574. }
  29575. }
  29576. function pickPlatformItem(dict) {
  29577. // Look for the filename in this order:
  29578. // UF, F, Unix, Mac, DOS
  29579. if (dict.has('UF')) {
  29580. return dict.get('UF');
  29581. } else if (dict.has('F')) {
  29582. return dict.get('F');
  29583. } else if (dict.has('Unix')) {
  29584. return dict.get('Unix');
  29585. } else if (dict.has('Mac')) {
  29586. return dict.get('Mac');
  29587. } else if (dict.has('DOS')) {
  29588. return dict.get('DOS');
  29589. } else {
  29590. return null;
  29591. }
  29592. }
  29593. FileSpec.prototype = {
  29594. get filename() {
  29595. if (!this._filename && this.root) {
  29596. var filename = pickPlatformItem(this.root) || 'unnamed';
  29597. this._filename = stringToPDFString(filename).
  29598. replace(/\\\\/g, '\\').
  29599. replace(/\\\//g, '/').
  29600. replace(/\\/g, '/');
  29601. }
  29602. return this._filename;
  29603. },
  29604. get content() {
  29605. if (!this.contentAvailable) {
  29606. return null;
  29607. }
  29608. if (!this.contentRef && this.root) {
  29609. this.contentRef = pickPlatformItem(this.root.get('EF'));
  29610. }
  29611. var content = null;
  29612. if (this.contentRef) {
  29613. var xref = this.xref;
  29614. var fileObj = xref.fetchIfRef(this.contentRef);
  29615. if (fileObj && isStream(fileObj)) {
  29616. content = fileObj.getBytes();
  29617. } else {
  29618. warn('Embedded file specification points to non-existing/invalid ' +
  29619. 'content');
  29620. }
  29621. } else {
  29622. warn('Embedded file specification does not have a content');
  29623. }
  29624. return content;
  29625. },
  29626. get serializable() {
  29627. return {
  29628. filename: this.filename,
  29629. content: this.content
  29630. };
  29631. }
  29632. };
  29633. return FileSpec;
  29634. })();
  29635. /**
  29636. * A helper for loading missing data in object graphs. It traverses the graph
  29637. * depth first and queues up any objects that have missing data. Once it has
  29638. * has traversed as many objects that are available it attempts to bundle the
  29639. * missing data requests and then resume from the nodes that weren't ready.
  29640. *
  29641. * NOTE: It provides protection from circular references by keeping track of
  29642. * of loaded references. However, you must be careful not to load any graphs
  29643. * that have references to the catalog or other pages since that will cause the
  29644. * entire PDF document object graph to be traversed.
  29645. */
  29646. var ObjectLoader = (function() {
  29647. function mayHaveChildren(value) {
  29648. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  29649. }
  29650. function addChildren(node, nodesToVisit) {
  29651. var value;
  29652. if (isDict(node) || isStream(node)) {
  29653. var map;
  29654. if (isDict(node)) {
  29655. map = node.map;
  29656. } else {
  29657. map = node.dict.map;
  29658. }
  29659. for (var key in map) {
  29660. value = map[key];
  29661. if (mayHaveChildren(value)) {
  29662. nodesToVisit.push(value);
  29663. }
  29664. }
  29665. } else if (isArray(node)) {
  29666. for (var i = 0, ii = node.length; i < ii; i++) {
  29667. value = node[i];
  29668. if (mayHaveChildren(value)) {
  29669. nodesToVisit.push(value);
  29670. }
  29671. }
  29672. }
  29673. }
  29674. function ObjectLoader(obj, keys, xref) {
  29675. this.obj = obj;
  29676. this.keys = keys;
  29677. this.xref = xref;
  29678. this.refSet = null;
  29679. this.capability = null;
  29680. }
  29681. ObjectLoader.prototype = {
  29682. load: function ObjectLoader_load() {
  29683. var keys = this.keys;
  29684. this.capability = createPromiseCapability();
  29685. // Don't walk the graph if all the data is already loaded.
  29686. if (!(this.xref.stream instanceof ChunkedStream) ||
  29687. this.xref.stream.getMissingChunks().length === 0) {
  29688. this.capability.resolve();
  29689. return this.capability.promise;
  29690. }
  29691. this.refSet = new RefSet();
  29692. // Setup the initial nodes to visit.
  29693. var nodesToVisit = [];
  29694. for (var i = 0; i < keys.length; i++) {
  29695. nodesToVisit.push(this.obj[keys[i]]);
  29696. }
  29697. this._walk(nodesToVisit);
  29698. return this.capability.promise;
  29699. },
  29700. _walk: function ObjectLoader_walk(nodesToVisit) {
  29701. var nodesToRevisit = [];
  29702. var pendingRequests = [];
  29703. // DFS walk of the object graph.
  29704. while (nodesToVisit.length) {
  29705. var currentNode = nodesToVisit.pop();
  29706. // Only references or chunked streams can cause missing data exceptions.
  29707. if (isRef(currentNode)) {
  29708. // Skip nodes that have already been visited.
  29709. if (this.refSet.has(currentNode)) {
  29710. continue;
  29711. }
  29712. try {
  29713. var ref = currentNode;
  29714. this.refSet.put(ref);
  29715. currentNode = this.xref.fetch(currentNode);
  29716. } catch (e) {
  29717. if (!(e instanceof MissingDataException)) {
  29718. throw e;
  29719. }
  29720. nodesToRevisit.push(currentNode);
  29721. pendingRequests.push({ begin: e.begin, end: e.end });
  29722. }
  29723. }
  29724. if (currentNode && currentNode.getBaseStreams) {
  29725. var baseStreams = currentNode.getBaseStreams();
  29726. var foundMissingData = false;
  29727. for (var i = 0; i < baseStreams.length; i++) {
  29728. var stream = baseStreams[i];
  29729. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  29730. foundMissingData = true;
  29731. pendingRequests.push({
  29732. begin: stream.start,
  29733. end: stream.end
  29734. });
  29735. }
  29736. }
  29737. if (foundMissingData) {
  29738. nodesToRevisit.push(currentNode);
  29739. }
  29740. }
  29741. addChildren(currentNode, nodesToVisit);
  29742. }
  29743. if (pendingRequests.length) {
  29744. this.xref.stream.manager.requestRanges(pendingRequests).then(
  29745. function pendingRequestCallback() {
  29746. nodesToVisit = nodesToRevisit;
  29747. for (var i = 0; i < nodesToRevisit.length; i++) {
  29748. var node = nodesToRevisit[i];
  29749. // Remove any reference nodes from the currrent refset so they
  29750. // aren't skipped when we revist them.
  29751. if (isRef(node)) {
  29752. this.refSet.remove(node);
  29753. }
  29754. }
  29755. this._walk(nodesToVisit);
  29756. }.bind(this), this.capability.reject);
  29757. return;
  29758. }
  29759. // Everything is loaded.
  29760. this.refSet = null;
  29761. this.capability.resolve();
  29762. }
  29763. };
  29764. return ObjectLoader;
  29765. })();
  29766. exports.Catalog = Catalog;
  29767. exports.ObjectLoader = ObjectLoader;
  29768. exports.XRef = XRef;
  29769. }));
  29770. (function (root, factory) {
  29771. {
  29772. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29773. root.pdfjsCoreParser);
  29774. }
  29775. }(this, function (exports, sharedUtil, coreParser) {
  29776. var error = sharedUtil.error;
  29777. var EOF = coreParser.EOF;
  29778. var Lexer = coreParser.Lexer;
  29779. var PostScriptParser = (function PostScriptParserClosure() {
  29780. function PostScriptParser(lexer) {
  29781. this.lexer = lexer;
  29782. this.operators = [];
  29783. this.token = null;
  29784. this.prev = null;
  29785. }
  29786. PostScriptParser.prototype = {
  29787. nextToken: function PostScriptParser_nextToken() {
  29788. this.prev = this.token;
  29789. this.token = this.lexer.getToken();
  29790. },
  29791. accept: function PostScriptParser_accept(type) {
  29792. if (this.token.type === type) {
  29793. this.nextToken();
  29794. return true;
  29795. }
  29796. return false;
  29797. },
  29798. expect: function PostScriptParser_expect(type) {
  29799. if (this.accept(type)) {
  29800. return true;
  29801. }
  29802. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29803. type + '.');
  29804. },
  29805. parse: function PostScriptParser_parse() {
  29806. this.nextToken();
  29807. this.expect(PostScriptTokenTypes.LBRACE);
  29808. this.parseBlock();
  29809. this.expect(PostScriptTokenTypes.RBRACE);
  29810. return this.operators;
  29811. },
  29812. parseBlock: function PostScriptParser_parseBlock() {
  29813. while (true) {
  29814. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29815. this.operators.push(this.prev.value);
  29816. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29817. this.operators.push(this.prev.value);
  29818. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29819. this.parseCondition();
  29820. } else {
  29821. return;
  29822. }
  29823. }
  29824. },
  29825. parseCondition: function PostScriptParser_parseCondition() {
  29826. // Add two place holders that will be updated later
  29827. var conditionLocation = this.operators.length;
  29828. this.operators.push(null, null);
  29829. this.parseBlock();
  29830. this.expect(PostScriptTokenTypes.RBRACE);
  29831. if (this.accept(PostScriptTokenTypes.IF)) {
  29832. // The true block is right after the 'if' so it just falls through on
  29833. // true else it jumps and skips the true block.
  29834. this.operators[conditionLocation] = this.operators.length;
  29835. this.operators[conditionLocation + 1] = 'jz';
  29836. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29837. var jumpLocation = this.operators.length;
  29838. this.operators.push(null, null);
  29839. var endOfTrue = this.operators.length;
  29840. this.parseBlock();
  29841. this.expect(PostScriptTokenTypes.RBRACE);
  29842. this.expect(PostScriptTokenTypes.IFELSE);
  29843. // The jump is added at the end of the true block to skip the false
  29844. // block.
  29845. this.operators[jumpLocation] = this.operators.length;
  29846. this.operators[jumpLocation + 1] = 'j';
  29847. this.operators[conditionLocation] = endOfTrue;
  29848. this.operators[conditionLocation + 1] = 'jz';
  29849. } else {
  29850. error('PS Function: error parsing conditional.');
  29851. }
  29852. }
  29853. };
  29854. return PostScriptParser;
  29855. })();
  29856. var PostScriptTokenTypes = {
  29857. LBRACE: 0,
  29858. RBRACE: 1,
  29859. NUMBER: 2,
  29860. OPERATOR: 3,
  29861. IF: 4,
  29862. IFELSE: 5
  29863. };
  29864. var PostScriptToken = (function PostScriptTokenClosure() {
  29865. function PostScriptToken(type, value) {
  29866. this.type = type;
  29867. this.value = value;
  29868. }
  29869. var opCache = {};
  29870. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29871. var opValue = opCache[op];
  29872. if (opValue) {
  29873. return opValue;
  29874. }
  29875. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29876. };
  29877. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29878. '{');
  29879. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29880. '}');
  29881. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29882. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29883. 'IFELSE');
  29884. return PostScriptToken;
  29885. })();
  29886. var PostScriptLexer = (function PostScriptLexerClosure() {
  29887. function PostScriptLexer(stream) {
  29888. this.stream = stream;
  29889. this.nextChar();
  29890. this.strBuf = [];
  29891. }
  29892. PostScriptLexer.prototype = {
  29893. nextChar: function PostScriptLexer_nextChar() {
  29894. return (this.currentChar = this.stream.getByte());
  29895. },
  29896. getToken: function PostScriptLexer_getToken() {
  29897. var comment = false;
  29898. var ch = this.currentChar;
  29899. // skip comments
  29900. while (true) {
  29901. if (ch < 0) {
  29902. return EOF;
  29903. }
  29904. if (comment) {
  29905. if (ch === 0x0A || ch === 0x0D) {
  29906. comment = false;
  29907. }
  29908. } else if (ch === 0x25) { // '%'
  29909. comment = true;
  29910. } else if (!Lexer.isSpace(ch)) {
  29911. break;
  29912. }
  29913. ch = this.nextChar();
  29914. }
  29915. switch (ch | 0) {
  29916. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29917. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29918. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29919. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29920. this.getNumber());
  29921. case 0x7B: // '{'
  29922. this.nextChar();
  29923. return PostScriptToken.LBRACE;
  29924. case 0x7D: // '}'
  29925. this.nextChar();
  29926. return PostScriptToken.RBRACE;
  29927. }
  29928. // operator
  29929. var strBuf = this.strBuf;
  29930. strBuf.length = 0;
  29931. strBuf[0] = String.fromCharCode(ch);
  29932. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29933. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29934. strBuf.push(String.fromCharCode(ch));
  29935. }
  29936. var str = strBuf.join('');
  29937. switch (str.toLowerCase()) {
  29938. case 'if':
  29939. return PostScriptToken.IF;
  29940. case 'ifelse':
  29941. return PostScriptToken.IFELSE;
  29942. default:
  29943. return PostScriptToken.getOperator(str);
  29944. }
  29945. },
  29946. getNumber: function PostScriptLexer_getNumber() {
  29947. var ch = this.currentChar;
  29948. var strBuf = this.strBuf;
  29949. strBuf.length = 0;
  29950. strBuf[0] = String.fromCharCode(ch);
  29951. while ((ch = this.nextChar()) >= 0) {
  29952. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29953. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29954. strBuf.push(String.fromCharCode(ch));
  29955. } else {
  29956. break;
  29957. }
  29958. }
  29959. var value = parseFloat(strBuf.join(''));
  29960. if (isNaN(value)) {
  29961. error('Invalid floating point number: ' + value);
  29962. }
  29963. return value;
  29964. }
  29965. };
  29966. return PostScriptLexer;
  29967. })();
  29968. exports.PostScriptLexer = PostScriptLexer;
  29969. exports.PostScriptParser = PostScriptParser;
  29970. }));
  29971. (function (root, factory) {
  29972. {
  29973. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  29974. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  29975. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  29976. root.pdfjsCoreFontRenderer);
  29977. }
  29978. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  29979. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  29980. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  29981. var FontType = sharedUtil.FontType;
  29982. var Util = sharedUtil.Util;
  29983. var assert = sharedUtil.assert;
  29984. var bytesToString = sharedUtil.bytesToString;
  29985. var error = sharedUtil.error;
  29986. var info = sharedUtil.info;
  29987. var isArray = sharedUtil.isArray;
  29988. var isInt = sharedUtil.isInt;
  29989. var isNum = sharedUtil.isNum;
  29990. var readUint32 = sharedUtil.readUint32;
  29991. var shadow = sharedUtil.shadow;
  29992. var stringToBytes = sharedUtil.stringToBytes;
  29993. var string32 = sharedUtil.string32;
  29994. var warn = sharedUtil.warn;
  29995. var Name = corePrimitives.Name;
  29996. var Stream = coreStream.Stream;
  29997. var Lexer = coreParser.Lexer;
  29998. var CMapFactory = coreCMap.CMapFactory;
  29999. var IdentityCMap = coreCMap.IdentityCMap;
  30000. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  30001. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  30002. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  30003. var ExpertCharset = coreCharsets.ExpertCharset;
  30004. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  30005. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  30006. // Unicode Private Use Area
  30007. var PRIVATE_USE_OFFSET_START = 0xE000;
  30008. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  30009. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  30010. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  30011. // except for Type 3 fonts
  30012. var PDF_GLYPH_SPACE_UNITS = 1000;
  30013. // Hinting is currently disabled due to unknown problems on windows
  30014. // in tracemonkey and various other pdfs with type1 fonts.
  30015. var HINTING_ENABLED = false;
  30016. // Accented charactars are not displayed properly on windows, using this flag
  30017. // to control analysis of seac charstrings.
  30018. var SEAC_ANALYSIS_ENABLED = false;
  30019. var FontFlags = {
  30020. FixedPitch: 1,
  30021. Serif: 2,
  30022. Symbolic: 4,
  30023. Script: 8,
  30024. Nonsymbolic: 32,
  30025. Italic: 64,
  30026. AllCap: 65536,
  30027. SmallCap: 131072,
  30028. ForceBold: 262144
  30029. };
  30030. var Encodings = {
  30031. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30032. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30033. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  30034. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  30035. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  30036. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  30037. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  30038. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  30039. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  30040. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  30041. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  30042. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  30043. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  30044. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  30045. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  30046. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  30047. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  30048. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  30049. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  30050. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30051. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  30052. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  30053. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  30054. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  30055. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  30056. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  30057. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  30058. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  30059. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  30060. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  30061. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  30062. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  30063. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  30064. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  30065. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  30066. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  30067. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  30068. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  30069. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  30070. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  30071. 'Ydieresissmall'],
  30072. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30073. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30074. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  30075. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  30076. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  30077. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  30078. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  30079. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  30080. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  30081. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  30082. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  30083. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  30084. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  30085. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  30086. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  30087. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  30088. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  30089. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  30090. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  30091. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  30092. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  30093. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  30094. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  30095. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  30096. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  30097. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  30098. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  30099. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  30100. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  30101. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  30102. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  30103. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  30104. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  30105. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  30106. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  30107. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  30108. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  30109. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  30110. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  30111. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  30112. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30113. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30114. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30115. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30116. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30117. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30118. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30119. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30120. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30121. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30122. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30123. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  30124. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  30125. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  30126. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30127. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  30128. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  30129. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  30130. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  30131. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  30132. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  30133. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  30134. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  30135. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  30136. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  30137. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  30138. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  30139. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  30140. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  30141. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  30142. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  30143. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  30144. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  30145. 'ogonek', 'caron'],
  30146. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30147. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30148. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30149. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  30150. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30151. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30152. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30153. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30154. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30155. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  30156. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  30157. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30158. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30159. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  30160. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  30161. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  30162. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  30163. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  30164. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  30165. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  30166. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  30167. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  30168. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  30169. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  30170. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  30171. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30172. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30173. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  30174. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  30175. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  30176. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  30177. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  30178. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  30179. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  30180. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  30181. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  30182. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  30183. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  30184. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  30185. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  30186. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  30187. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  30188. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  30189. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  30190. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  30191. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  30192. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  30193. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  30194. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  30195. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  30196. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  30197. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  30198. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  30199. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  30200. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  30201. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  30202. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  30203. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  30204. 'ydieresis'],
  30205. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30206. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30207. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  30208. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  30209. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  30210. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  30211. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  30212. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  30213. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  30214. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  30215. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  30216. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  30217. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  30218. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  30219. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  30220. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30221. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  30222. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  30223. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  30224. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  30225. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  30226. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  30227. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  30228. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  30229. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  30230. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  30231. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  30232. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  30233. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  30234. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  30235. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  30236. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  30237. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  30238. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  30239. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  30240. 'bracerightbt'],
  30241. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30242. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  30243. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  30244. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  30245. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  30246. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  30247. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  30248. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  30249. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  30250. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  30251. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  30252. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  30253. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  30254. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  30255. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  30256. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  30257. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  30258. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  30259. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  30260. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  30261. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  30262. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  30263. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  30264. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  30265. };
  30266. /**
  30267. * Hold a map of decoded fonts and of the standard fourteen Type1
  30268. * fonts and their acronyms.
  30269. */
  30270. var stdFontMap = {
  30271. 'ArialNarrow': 'Helvetica',
  30272. 'ArialNarrow-Bold': 'Helvetica-Bold',
  30273. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  30274. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  30275. 'ArialBlack': 'Helvetica',
  30276. 'ArialBlack-Bold': 'Helvetica-Bold',
  30277. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  30278. 'ArialBlack-Italic': 'Helvetica-Oblique',
  30279. 'Arial': 'Helvetica',
  30280. 'Arial-Bold': 'Helvetica-Bold',
  30281. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  30282. 'Arial-Italic': 'Helvetica-Oblique',
  30283. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  30284. 'Arial-BoldMT': 'Helvetica-Bold',
  30285. 'Arial-ItalicMT': 'Helvetica-Oblique',
  30286. 'ArialMT': 'Helvetica',
  30287. 'Courier-Bold': 'Courier-Bold',
  30288. 'Courier-BoldItalic': 'Courier-BoldOblique',
  30289. 'Courier-Italic': 'Courier-Oblique',
  30290. 'CourierNew': 'Courier',
  30291. 'CourierNew-Bold': 'Courier-Bold',
  30292. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  30293. 'CourierNew-Italic': 'Courier-Oblique',
  30294. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  30295. 'CourierNewPS-BoldMT': 'Courier-Bold',
  30296. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  30297. 'CourierNewPSMT': 'Courier',
  30298. 'Helvetica': 'Helvetica',
  30299. 'Helvetica-Bold': 'Helvetica-Bold',
  30300. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  30301. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  30302. 'Helvetica-Italic': 'Helvetica-Oblique',
  30303. 'Helvetica-Oblique':'Helvetica-Oblique',
  30304. 'Symbol-Bold': 'Symbol',
  30305. 'Symbol-BoldItalic': 'Symbol',
  30306. 'Symbol-Italic': 'Symbol',
  30307. 'TimesNewRoman': 'Times-Roman',
  30308. 'TimesNewRoman-Bold': 'Times-Bold',
  30309. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  30310. 'TimesNewRoman-Italic': 'Times-Italic',
  30311. 'TimesNewRomanPS': 'Times-Roman',
  30312. 'TimesNewRomanPS-Bold': 'Times-Bold',
  30313. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  30314. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  30315. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  30316. 'TimesNewRomanPS-Italic': 'Times-Italic',
  30317. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  30318. 'TimesNewRomanPSMT': 'Times-Roman',
  30319. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  30320. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  30321. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  30322. };
  30323. /**
  30324. * Holds the map of the non-standard fonts that might be included as a standard
  30325. * fonts without glyph data.
  30326. */
  30327. var nonStdFontMap = {
  30328. 'CenturyGothic': 'Helvetica',
  30329. 'CenturyGothic-Bold': 'Helvetica-Bold',
  30330. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  30331. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  30332. 'ComicSansMS': 'Comic Sans MS',
  30333. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  30334. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  30335. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  30336. 'LucidaConsole': 'Courier',
  30337. 'LucidaConsole-Bold': 'Courier-Bold',
  30338. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  30339. 'LucidaConsole-Italic': 'Courier-Oblique',
  30340. 'MS-Gothic': 'MS Gothic',
  30341. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  30342. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  30343. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  30344. 'MS-Mincho': 'MS Mincho',
  30345. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  30346. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  30347. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  30348. 'MS-PGothic': 'MS PGothic',
  30349. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  30350. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  30351. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  30352. 'MS-PMincho': 'MS PMincho',
  30353. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  30354. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  30355. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  30356. 'Wingdings': 'ZapfDingbats'
  30357. };
  30358. var serifFonts = {
  30359. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  30360. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  30361. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  30362. 'Arno': true, 'Aster': true, 'Aurora': true,
  30363. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  30364. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  30365. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  30366. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  30367. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  30368. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  30369. 'Cartier': true, 'Caslon': true, 'Catull': true,
  30370. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  30371. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  30372. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  30373. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  30374. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  30375. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  30376. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  30377. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  30378. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  30379. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  30380. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  30381. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  30382. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  30383. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  30384. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  30385. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  30386. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  30387. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  30388. 'Miller': true, 'Minion': true, 'Modern': true,
  30389. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  30390. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  30391. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  30392. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  30393. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  30394. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  30395. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  30396. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  30397. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  30398. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  30399. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  30400. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  30401. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  30402. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  30403. };
  30404. var symbolsFonts = {
  30405. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  30406. };
  30407. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  30408. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  30409. // glyphs, but common for some set of the standard fonts.
  30410. var GlyphMapForStandardFonts = {
  30411. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  30412. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  30413. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  30414. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  30415. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  30416. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  30417. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  30418. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  30419. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  30420. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  30421. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  30422. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  30423. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  30424. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  30425. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  30426. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  30427. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  30428. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  30429. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  30430. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  30431. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  30432. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  30433. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  30434. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  30435. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  30436. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  30437. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  30438. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  30439. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  30440. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  30441. '298': 380, '305': 963,
  30442. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  30443. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  30444. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  30445. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  30446. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  30447. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  30448. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  30449. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  30450. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  30451. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  30452. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  30453. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  30454. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  30455. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  30456. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  30457. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  30458. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  30459. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  30460. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  30461. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  30462. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  30463. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  30464. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  30465. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  30466. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  30467. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  30468. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  30469. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  30470. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  30471. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  30472. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  30473. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  30474. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  30475. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  30476. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  30477. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  30478. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  30479. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  30480. };
  30481. // The glyph map for ArialBlack differs slightly from the glyph map used for
  30482. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  30483. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  30484. var SupplementalGlyphMapForArialBlack = {
  30485. '227': 322, '264': 261, '291': 346,
  30486. };
  30487. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  30488. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  30489. // to the similar equivalents in the normal characters range.
  30490. var SpecialPUASymbols = {
  30491. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  30492. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  30493. '63720': 0x00AE, // registersans (0xF8E8) => registered
  30494. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  30495. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  30496. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  30497. '63729': 0x23A7, // bracelefttp (0xF8F1)
  30498. '63730': 0x23A8, // braceleftmid (0xF8F2)
  30499. '63731': 0x23A9, // braceleftbt (0xF8F3)
  30500. '63740': 0x23AB, // bracerighttp (0xF8FC)
  30501. '63741': 0x23AC, // bracerightmid (0xF8FD)
  30502. '63742': 0x23AD, // bracerightbt (0xF8FE)
  30503. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  30504. '63727': 0x23A2, // bracketleftex (0xF8EF)
  30505. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  30506. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  30507. '63738': 0x23A5, // bracketrightex (0xF8FA)
  30508. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  30509. '63723': 0x239B, // parenlefttp (0xF8EB)
  30510. '63724': 0x239C, // parenleftex (0xF8EC)
  30511. '63725': 0x239D, // parenleftbt (0xF8ED)
  30512. '63734': 0x239E, // parenrighttp (0xF8F6)
  30513. '63735': 0x239F, // parenrightex (0xF8F7)
  30514. '63736': 0x23A0, // parenrightbt (0xF8F8)
  30515. };
  30516. function mapSpecialUnicodeValues(code) {
  30517. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  30518. return 0;
  30519. } else if (code >= 0xF600 && code <= 0xF8FF) {
  30520. return (SpecialPUASymbols[code] || code);
  30521. }
  30522. return code;
  30523. }
  30524. var UnicodeRanges = [
  30525. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  30526. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  30527. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  30528. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  30529. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  30530. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  30531. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  30532. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  30533. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  30534. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  30535. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  30536. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  30537. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  30538. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  30539. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  30540. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  30541. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  30542. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  30543. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  30544. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  30545. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  30546. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  30547. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  30548. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  30549. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  30550. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  30551. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  30552. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  30553. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  30554. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  30555. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  30556. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  30557. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  30558. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  30559. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  30560. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  30561. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  30562. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  30563. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  30564. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  30565. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  30566. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  30567. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  30568. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  30569. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  30570. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  30571. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  30572. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  30573. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  30574. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  30575. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  30576. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  30577. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  30578. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  30579. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  30580. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  30581. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  30582. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  30583. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  30584. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  30585. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  30586. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  30587. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  30588. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  30589. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  30590. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  30591. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  30592. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  30593. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  30594. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  30595. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  30596. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  30597. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  30598. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  30599. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  30600. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  30601. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  30602. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  30603. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  30604. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  30605. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  30606. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  30607. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  30608. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  30609. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  30610. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  30611. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  30612. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  30613. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  30614. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  30615. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  30616. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  30617. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  30618. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  30619. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  30620. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  30621. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  30622. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  30623. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  30624. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  30625. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  30626. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  30627. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  30628. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  30629. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  30630. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  30631. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  30632. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  30633. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  30634. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  30635. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  30636. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  30637. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  30638. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  30639. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  30640. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  30641. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  30642. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  30643. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  30644. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  30645. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  30646. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  30647. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  30648. ];
  30649. var MacStandardGlyphOrdering = [
  30650. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30651. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30652. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30653. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30654. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30655. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30656. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30657. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30658. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30659. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30660. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30661. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30662. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30663. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30664. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30665. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30666. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30667. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30668. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30669. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30670. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30671. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30672. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30673. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30674. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30675. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30676. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30677. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30678. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30679. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30680. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30681. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30682. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30683. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30684. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30685. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30686. function getUnicodeRangeFor(value) {
  30687. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  30688. var range = UnicodeRanges[i];
  30689. if (value >= range.begin && value < range.end) {
  30690. return i;
  30691. }
  30692. }
  30693. return -1;
  30694. }
  30695. function isRTLRangeFor(value) {
  30696. var range = UnicodeRanges[13];
  30697. if (value >= range.begin && value < range.end) {
  30698. return true;
  30699. }
  30700. range = UnicodeRanges[11];
  30701. if (value >= range.begin && value < range.end) {
  30702. return true;
  30703. }
  30704. return false;
  30705. }
  30706. // The normalization table is obtained by filtering the Unicode characters
  30707. // database with <compat> entries.
  30708. var NormalizedUnicodes = {
  30709. '\u00A8': '\u0020\u0308',
  30710. '\u00AF': '\u0020\u0304',
  30711. '\u00B4': '\u0020\u0301',
  30712. '\u00B5': '\u03BC',
  30713. '\u00B8': '\u0020\u0327',
  30714. '\u0132': '\u0049\u004A',
  30715. '\u0133': '\u0069\u006A',
  30716. '\u013F': '\u004C\u00B7',
  30717. '\u0140': '\u006C\u00B7',
  30718. '\u0149': '\u02BC\u006E',
  30719. '\u017F': '\u0073',
  30720. '\u01C4': '\u0044\u017D',
  30721. '\u01C5': '\u0044\u017E',
  30722. '\u01C6': '\u0064\u017E',
  30723. '\u01C7': '\u004C\u004A',
  30724. '\u01C8': '\u004C\u006A',
  30725. '\u01C9': '\u006C\u006A',
  30726. '\u01CA': '\u004E\u004A',
  30727. '\u01CB': '\u004E\u006A',
  30728. '\u01CC': '\u006E\u006A',
  30729. '\u01F1': '\u0044\u005A',
  30730. '\u01F2': '\u0044\u007A',
  30731. '\u01F3': '\u0064\u007A',
  30732. '\u02D8': '\u0020\u0306',
  30733. '\u02D9': '\u0020\u0307',
  30734. '\u02DA': '\u0020\u030A',
  30735. '\u02DB': '\u0020\u0328',
  30736. '\u02DC': '\u0020\u0303',
  30737. '\u02DD': '\u0020\u030B',
  30738. '\u037A': '\u0020\u0345',
  30739. '\u0384': '\u0020\u0301',
  30740. '\u03D0': '\u03B2',
  30741. '\u03D1': '\u03B8',
  30742. '\u03D2': '\u03A5',
  30743. '\u03D5': '\u03C6',
  30744. '\u03D6': '\u03C0',
  30745. '\u03F0': '\u03BA',
  30746. '\u03F1': '\u03C1',
  30747. '\u03F2': '\u03C2',
  30748. '\u03F4': '\u0398',
  30749. '\u03F5': '\u03B5',
  30750. '\u03F9': '\u03A3',
  30751. '\u0587': '\u0565\u0582',
  30752. '\u0675': '\u0627\u0674',
  30753. '\u0676': '\u0648\u0674',
  30754. '\u0677': '\u06C7\u0674',
  30755. '\u0678': '\u064A\u0674',
  30756. '\u0E33': '\u0E4D\u0E32',
  30757. '\u0EB3': '\u0ECD\u0EB2',
  30758. '\u0EDC': '\u0EAB\u0E99',
  30759. '\u0EDD': '\u0EAB\u0EA1',
  30760. '\u0F77': '\u0FB2\u0F81',
  30761. '\u0F79': '\u0FB3\u0F81',
  30762. '\u1E9A': '\u0061\u02BE',
  30763. '\u1FBD': '\u0020\u0313',
  30764. '\u1FBF': '\u0020\u0313',
  30765. '\u1FC0': '\u0020\u0342',
  30766. '\u1FFE': '\u0020\u0314',
  30767. '\u2002': '\u0020',
  30768. '\u2003': '\u0020',
  30769. '\u2004': '\u0020',
  30770. '\u2005': '\u0020',
  30771. '\u2006': '\u0020',
  30772. '\u2008': '\u0020',
  30773. '\u2009': '\u0020',
  30774. '\u200A': '\u0020',
  30775. '\u2017': '\u0020\u0333',
  30776. '\u2024': '\u002E',
  30777. '\u2025': '\u002E\u002E',
  30778. '\u2026': '\u002E\u002E\u002E',
  30779. '\u2033': '\u2032\u2032',
  30780. '\u2034': '\u2032\u2032\u2032',
  30781. '\u2036': '\u2035\u2035',
  30782. '\u2037': '\u2035\u2035\u2035',
  30783. '\u203C': '\u0021\u0021',
  30784. '\u203E': '\u0020\u0305',
  30785. '\u2047': '\u003F\u003F',
  30786. '\u2048': '\u003F\u0021',
  30787. '\u2049': '\u0021\u003F',
  30788. '\u2057': '\u2032\u2032\u2032\u2032',
  30789. '\u205F': '\u0020',
  30790. '\u20A8': '\u0052\u0073',
  30791. '\u2100': '\u0061\u002F\u0063',
  30792. '\u2101': '\u0061\u002F\u0073',
  30793. '\u2103': '\u00B0\u0043',
  30794. '\u2105': '\u0063\u002F\u006F',
  30795. '\u2106': '\u0063\u002F\u0075',
  30796. '\u2107': '\u0190',
  30797. '\u2109': '\u00B0\u0046',
  30798. '\u2116': '\u004E\u006F',
  30799. '\u2121': '\u0054\u0045\u004C',
  30800. '\u2135': '\u05D0',
  30801. '\u2136': '\u05D1',
  30802. '\u2137': '\u05D2',
  30803. '\u2138': '\u05D3',
  30804. '\u213B': '\u0046\u0041\u0058',
  30805. '\u2160': '\u0049',
  30806. '\u2161': '\u0049\u0049',
  30807. '\u2162': '\u0049\u0049\u0049',
  30808. '\u2163': '\u0049\u0056',
  30809. '\u2164': '\u0056',
  30810. '\u2165': '\u0056\u0049',
  30811. '\u2166': '\u0056\u0049\u0049',
  30812. '\u2167': '\u0056\u0049\u0049\u0049',
  30813. '\u2168': '\u0049\u0058',
  30814. '\u2169': '\u0058',
  30815. '\u216A': '\u0058\u0049',
  30816. '\u216B': '\u0058\u0049\u0049',
  30817. '\u216C': '\u004C',
  30818. '\u216D': '\u0043',
  30819. '\u216E': '\u0044',
  30820. '\u216F': '\u004D',
  30821. '\u2170': '\u0069',
  30822. '\u2171': '\u0069\u0069',
  30823. '\u2172': '\u0069\u0069\u0069',
  30824. '\u2173': '\u0069\u0076',
  30825. '\u2174': '\u0076',
  30826. '\u2175': '\u0076\u0069',
  30827. '\u2176': '\u0076\u0069\u0069',
  30828. '\u2177': '\u0076\u0069\u0069\u0069',
  30829. '\u2178': '\u0069\u0078',
  30830. '\u2179': '\u0078',
  30831. '\u217A': '\u0078\u0069',
  30832. '\u217B': '\u0078\u0069\u0069',
  30833. '\u217C': '\u006C',
  30834. '\u217D': '\u0063',
  30835. '\u217E': '\u0064',
  30836. '\u217F': '\u006D',
  30837. '\u222C': '\u222B\u222B',
  30838. '\u222D': '\u222B\u222B\u222B',
  30839. '\u222F': '\u222E\u222E',
  30840. '\u2230': '\u222E\u222E\u222E',
  30841. '\u2474': '\u0028\u0031\u0029',
  30842. '\u2475': '\u0028\u0032\u0029',
  30843. '\u2476': '\u0028\u0033\u0029',
  30844. '\u2477': '\u0028\u0034\u0029',
  30845. '\u2478': '\u0028\u0035\u0029',
  30846. '\u2479': '\u0028\u0036\u0029',
  30847. '\u247A': '\u0028\u0037\u0029',
  30848. '\u247B': '\u0028\u0038\u0029',
  30849. '\u247C': '\u0028\u0039\u0029',
  30850. '\u247D': '\u0028\u0031\u0030\u0029',
  30851. '\u247E': '\u0028\u0031\u0031\u0029',
  30852. '\u247F': '\u0028\u0031\u0032\u0029',
  30853. '\u2480': '\u0028\u0031\u0033\u0029',
  30854. '\u2481': '\u0028\u0031\u0034\u0029',
  30855. '\u2482': '\u0028\u0031\u0035\u0029',
  30856. '\u2483': '\u0028\u0031\u0036\u0029',
  30857. '\u2484': '\u0028\u0031\u0037\u0029',
  30858. '\u2485': '\u0028\u0031\u0038\u0029',
  30859. '\u2486': '\u0028\u0031\u0039\u0029',
  30860. '\u2487': '\u0028\u0032\u0030\u0029',
  30861. '\u2488': '\u0031\u002E',
  30862. '\u2489': '\u0032\u002E',
  30863. '\u248A': '\u0033\u002E',
  30864. '\u248B': '\u0034\u002E',
  30865. '\u248C': '\u0035\u002E',
  30866. '\u248D': '\u0036\u002E',
  30867. '\u248E': '\u0037\u002E',
  30868. '\u248F': '\u0038\u002E',
  30869. '\u2490': '\u0039\u002E',
  30870. '\u2491': '\u0031\u0030\u002E',
  30871. '\u2492': '\u0031\u0031\u002E',
  30872. '\u2493': '\u0031\u0032\u002E',
  30873. '\u2494': '\u0031\u0033\u002E',
  30874. '\u2495': '\u0031\u0034\u002E',
  30875. '\u2496': '\u0031\u0035\u002E',
  30876. '\u2497': '\u0031\u0036\u002E',
  30877. '\u2498': '\u0031\u0037\u002E',
  30878. '\u2499': '\u0031\u0038\u002E',
  30879. '\u249A': '\u0031\u0039\u002E',
  30880. '\u249B': '\u0032\u0030\u002E',
  30881. '\u249C': '\u0028\u0061\u0029',
  30882. '\u249D': '\u0028\u0062\u0029',
  30883. '\u249E': '\u0028\u0063\u0029',
  30884. '\u249F': '\u0028\u0064\u0029',
  30885. '\u24A0': '\u0028\u0065\u0029',
  30886. '\u24A1': '\u0028\u0066\u0029',
  30887. '\u24A2': '\u0028\u0067\u0029',
  30888. '\u24A3': '\u0028\u0068\u0029',
  30889. '\u24A4': '\u0028\u0069\u0029',
  30890. '\u24A5': '\u0028\u006A\u0029',
  30891. '\u24A6': '\u0028\u006B\u0029',
  30892. '\u24A7': '\u0028\u006C\u0029',
  30893. '\u24A8': '\u0028\u006D\u0029',
  30894. '\u24A9': '\u0028\u006E\u0029',
  30895. '\u24AA': '\u0028\u006F\u0029',
  30896. '\u24AB': '\u0028\u0070\u0029',
  30897. '\u24AC': '\u0028\u0071\u0029',
  30898. '\u24AD': '\u0028\u0072\u0029',
  30899. '\u24AE': '\u0028\u0073\u0029',
  30900. '\u24AF': '\u0028\u0074\u0029',
  30901. '\u24B0': '\u0028\u0075\u0029',
  30902. '\u24B1': '\u0028\u0076\u0029',
  30903. '\u24B2': '\u0028\u0077\u0029',
  30904. '\u24B3': '\u0028\u0078\u0029',
  30905. '\u24B4': '\u0028\u0079\u0029',
  30906. '\u24B5': '\u0028\u007A\u0029',
  30907. '\u2A0C': '\u222B\u222B\u222B\u222B',
  30908. '\u2A74': '\u003A\u003A\u003D',
  30909. '\u2A75': '\u003D\u003D',
  30910. '\u2A76': '\u003D\u003D\u003D',
  30911. '\u2E9F': '\u6BCD',
  30912. '\u2EF3': '\u9F9F',
  30913. '\u2F00': '\u4E00',
  30914. '\u2F01': '\u4E28',
  30915. '\u2F02': '\u4E36',
  30916. '\u2F03': '\u4E3F',
  30917. '\u2F04': '\u4E59',
  30918. '\u2F05': '\u4E85',
  30919. '\u2F06': '\u4E8C',
  30920. '\u2F07': '\u4EA0',
  30921. '\u2F08': '\u4EBA',
  30922. '\u2F09': '\u513F',
  30923. '\u2F0A': '\u5165',
  30924. '\u2F0B': '\u516B',
  30925. '\u2F0C': '\u5182',
  30926. '\u2F0D': '\u5196',
  30927. '\u2F0E': '\u51AB',
  30928. '\u2F0F': '\u51E0',
  30929. '\u2F10': '\u51F5',
  30930. '\u2F11': '\u5200',
  30931. '\u2F12': '\u529B',
  30932. '\u2F13': '\u52F9',
  30933. '\u2F14': '\u5315',
  30934. '\u2F15': '\u531A',
  30935. '\u2F16': '\u5338',
  30936. '\u2F17': '\u5341',
  30937. '\u2F18': '\u535C',
  30938. '\u2F19': '\u5369',
  30939. '\u2F1A': '\u5382',
  30940. '\u2F1B': '\u53B6',
  30941. '\u2F1C': '\u53C8',
  30942. '\u2F1D': '\u53E3',
  30943. '\u2F1E': '\u56D7',
  30944. '\u2F1F': '\u571F',
  30945. '\u2F20': '\u58EB',
  30946. '\u2F21': '\u5902',
  30947. '\u2F22': '\u590A',
  30948. '\u2F23': '\u5915',
  30949. '\u2F24': '\u5927',
  30950. '\u2F25': '\u5973',
  30951. '\u2F26': '\u5B50',
  30952. '\u2F27': '\u5B80',
  30953. '\u2F28': '\u5BF8',
  30954. '\u2F29': '\u5C0F',
  30955. '\u2F2A': '\u5C22',
  30956. '\u2F2B': '\u5C38',
  30957. '\u2F2C': '\u5C6E',
  30958. '\u2F2D': '\u5C71',
  30959. '\u2F2E': '\u5DDB',
  30960. '\u2F2F': '\u5DE5',
  30961. '\u2F30': '\u5DF1',
  30962. '\u2F31': '\u5DFE',
  30963. '\u2F32': '\u5E72',
  30964. '\u2F33': '\u5E7A',
  30965. '\u2F34': '\u5E7F',
  30966. '\u2F35': '\u5EF4',
  30967. '\u2F36': '\u5EFE',
  30968. '\u2F37': '\u5F0B',
  30969. '\u2F38': '\u5F13',
  30970. '\u2F39': '\u5F50',
  30971. '\u2F3A': '\u5F61',
  30972. '\u2F3B': '\u5F73',
  30973. '\u2F3C': '\u5FC3',
  30974. '\u2F3D': '\u6208',
  30975. '\u2F3E': '\u6236',
  30976. '\u2F3F': '\u624B',
  30977. '\u2F40': '\u652F',
  30978. '\u2F41': '\u6534',
  30979. '\u2F42': '\u6587',
  30980. '\u2F43': '\u6597',
  30981. '\u2F44': '\u65A4',
  30982. '\u2F45': '\u65B9',
  30983. '\u2F46': '\u65E0',
  30984. '\u2F47': '\u65E5',
  30985. '\u2F48': '\u66F0',
  30986. '\u2F49': '\u6708',
  30987. '\u2F4A': '\u6728',
  30988. '\u2F4B': '\u6B20',
  30989. '\u2F4C': '\u6B62',
  30990. '\u2F4D': '\u6B79',
  30991. '\u2F4E': '\u6BB3',
  30992. '\u2F4F': '\u6BCB',
  30993. '\u2F50': '\u6BD4',
  30994. '\u2F51': '\u6BDB',
  30995. '\u2F52': '\u6C0F',
  30996. '\u2F53': '\u6C14',
  30997. '\u2F54': '\u6C34',
  30998. '\u2F55': '\u706B',
  30999. '\u2F56': '\u722A',
  31000. '\u2F57': '\u7236',
  31001. '\u2F58': '\u723B',
  31002. '\u2F59': '\u723F',
  31003. '\u2F5A': '\u7247',
  31004. '\u2F5B': '\u7259',
  31005. '\u2F5C': '\u725B',
  31006. '\u2F5D': '\u72AC',
  31007. '\u2F5E': '\u7384',
  31008. '\u2F5F': '\u7389',
  31009. '\u2F60': '\u74DC',
  31010. '\u2F61': '\u74E6',
  31011. '\u2F62': '\u7518',
  31012. '\u2F63': '\u751F',
  31013. '\u2F64': '\u7528',
  31014. '\u2F65': '\u7530',
  31015. '\u2F66': '\u758B',
  31016. '\u2F67': '\u7592',
  31017. '\u2F68': '\u7676',
  31018. '\u2F69': '\u767D',
  31019. '\u2F6A': '\u76AE',
  31020. '\u2F6B': '\u76BF',
  31021. '\u2F6C': '\u76EE',
  31022. '\u2F6D': '\u77DB',
  31023. '\u2F6E': '\u77E2',
  31024. '\u2F6F': '\u77F3',
  31025. '\u2F70': '\u793A',
  31026. '\u2F71': '\u79B8',
  31027. '\u2F72': '\u79BE',
  31028. '\u2F73': '\u7A74',
  31029. '\u2F74': '\u7ACB',
  31030. '\u2F75': '\u7AF9',
  31031. '\u2F76': '\u7C73',
  31032. '\u2F77': '\u7CF8',
  31033. '\u2F78': '\u7F36',
  31034. '\u2F79': '\u7F51',
  31035. '\u2F7A': '\u7F8A',
  31036. '\u2F7B': '\u7FBD',
  31037. '\u2F7C': '\u8001',
  31038. '\u2F7D': '\u800C',
  31039. '\u2F7E': '\u8012',
  31040. '\u2F7F': '\u8033',
  31041. '\u2F80': '\u807F',
  31042. '\u2F81': '\u8089',
  31043. '\u2F82': '\u81E3',
  31044. '\u2F83': '\u81EA',
  31045. '\u2F84': '\u81F3',
  31046. '\u2F85': '\u81FC',
  31047. '\u2F86': '\u820C',
  31048. '\u2F87': '\u821B',
  31049. '\u2F88': '\u821F',
  31050. '\u2F89': '\u826E',
  31051. '\u2F8A': '\u8272',
  31052. '\u2F8B': '\u8278',
  31053. '\u2F8C': '\u864D',
  31054. '\u2F8D': '\u866B',
  31055. '\u2F8E': '\u8840',
  31056. '\u2F8F': '\u884C',
  31057. '\u2F90': '\u8863',
  31058. '\u2F91': '\u897E',
  31059. '\u2F92': '\u898B',
  31060. '\u2F93': '\u89D2',
  31061. '\u2F94': '\u8A00',
  31062. '\u2F95': '\u8C37',
  31063. '\u2F96': '\u8C46',
  31064. '\u2F97': '\u8C55',
  31065. '\u2F98': '\u8C78',
  31066. '\u2F99': '\u8C9D',
  31067. '\u2F9A': '\u8D64',
  31068. '\u2F9B': '\u8D70',
  31069. '\u2F9C': '\u8DB3',
  31070. '\u2F9D': '\u8EAB',
  31071. '\u2F9E': '\u8ECA',
  31072. '\u2F9F': '\u8F9B',
  31073. '\u2FA0': '\u8FB0',
  31074. '\u2FA1': '\u8FB5',
  31075. '\u2FA2': '\u9091',
  31076. '\u2FA3': '\u9149',
  31077. '\u2FA4': '\u91C6',
  31078. '\u2FA5': '\u91CC',
  31079. '\u2FA6': '\u91D1',
  31080. '\u2FA7': '\u9577',
  31081. '\u2FA8': '\u9580',
  31082. '\u2FA9': '\u961C',
  31083. '\u2FAA': '\u96B6',
  31084. '\u2FAB': '\u96B9',
  31085. '\u2FAC': '\u96E8',
  31086. '\u2FAD': '\u9751',
  31087. '\u2FAE': '\u975E',
  31088. '\u2FAF': '\u9762',
  31089. '\u2FB0': '\u9769',
  31090. '\u2FB1': '\u97CB',
  31091. '\u2FB2': '\u97ED',
  31092. '\u2FB3': '\u97F3',
  31093. '\u2FB4': '\u9801',
  31094. '\u2FB5': '\u98A8',
  31095. '\u2FB6': '\u98DB',
  31096. '\u2FB7': '\u98DF',
  31097. '\u2FB8': '\u9996',
  31098. '\u2FB9': '\u9999',
  31099. '\u2FBA': '\u99AC',
  31100. '\u2FBB': '\u9AA8',
  31101. '\u2FBC': '\u9AD8',
  31102. '\u2FBD': '\u9ADF',
  31103. '\u2FBE': '\u9B25',
  31104. '\u2FBF': '\u9B2F',
  31105. '\u2FC0': '\u9B32',
  31106. '\u2FC1': '\u9B3C',
  31107. '\u2FC2': '\u9B5A',
  31108. '\u2FC3': '\u9CE5',
  31109. '\u2FC4': '\u9E75',
  31110. '\u2FC5': '\u9E7F',
  31111. '\u2FC6': '\u9EA5',
  31112. '\u2FC7': '\u9EBB',
  31113. '\u2FC8': '\u9EC3',
  31114. '\u2FC9': '\u9ECD',
  31115. '\u2FCA': '\u9ED1',
  31116. '\u2FCB': '\u9EF9',
  31117. '\u2FCC': '\u9EFD',
  31118. '\u2FCD': '\u9F0E',
  31119. '\u2FCE': '\u9F13',
  31120. '\u2FCF': '\u9F20',
  31121. '\u2FD0': '\u9F3B',
  31122. '\u2FD1': '\u9F4A',
  31123. '\u2FD2': '\u9F52',
  31124. '\u2FD3': '\u9F8D',
  31125. '\u2FD4': '\u9F9C',
  31126. '\u2FD5': '\u9FA0',
  31127. '\u3036': '\u3012',
  31128. '\u3038': '\u5341',
  31129. '\u3039': '\u5344',
  31130. '\u303A': '\u5345',
  31131. '\u309B': '\u0020\u3099',
  31132. '\u309C': '\u0020\u309A',
  31133. '\u3131': '\u1100',
  31134. '\u3132': '\u1101',
  31135. '\u3133': '\u11AA',
  31136. '\u3134': '\u1102',
  31137. '\u3135': '\u11AC',
  31138. '\u3136': '\u11AD',
  31139. '\u3137': '\u1103',
  31140. '\u3138': '\u1104',
  31141. '\u3139': '\u1105',
  31142. '\u313A': '\u11B0',
  31143. '\u313B': '\u11B1',
  31144. '\u313C': '\u11B2',
  31145. '\u313D': '\u11B3',
  31146. '\u313E': '\u11B4',
  31147. '\u313F': '\u11B5',
  31148. '\u3140': '\u111A',
  31149. '\u3141': '\u1106',
  31150. '\u3142': '\u1107',
  31151. '\u3143': '\u1108',
  31152. '\u3144': '\u1121',
  31153. '\u3145': '\u1109',
  31154. '\u3146': '\u110A',
  31155. '\u3147': '\u110B',
  31156. '\u3148': '\u110C',
  31157. '\u3149': '\u110D',
  31158. '\u314A': '\u110E',
  31159. '\u314B': '\u110F',
  31160. '\u314C': '\u1110',
  31161. '\u314D': '\u1111',
  31162. '\u314E': '\u1112',
  31163. '\u314F': '\u1161',
  31164. '\u3150': '\u1162',
  31165. '\u3151': '\u1163',
  31166. '\u3152': '\u1164',
  31167. '\u3153': '\u1165',
  31168. '\u3154': '\u1166',
  31169. '\u3155': '\u1167',
  31170. '\u3156': '\u1168',
  31171. '\u3157': '\u1169',
  31172. '\u3158': '\u116A',
  31173. '\u3159': '\u116B',
  31174. '\u315A': '\u116C',
  31175. '\u315B': '\u116D',
  31176. '\u315C': '\u116E',
  31177. '\u315D': '\u116F',
  31178. '\u315E': '\u1170',
  31179. '\u315F': '\u1171',
  31180. '\u3160': '\u1172',
  31181. '\u3161': '\u1173',
  31182. '\u3162': '\u1174',
  31183. '\u3163': '\u1175',
  31184. '\u3164': '\u1160',
  31185. '\u3165': '\u1114',
  31186. '\u3166': '\u1115',
  31187. '\u3167': '\u11C7',
  31188. '\u3168': '\u11C8',
  31189. '\u3169': '\u11CC',
  31190. '\u316A': '\u11CE',
  31191. '\u316B': '\u11D3',
  31192. '\u316C': '\u11D7',
  31193. '\u316D': '\u11D9',
  31194. '\u316E': '\u111C',
  31195. '\u316F': '\u11DD',
  31196. '\u3170': '\u11DF',
  31197. '\u3171': '\u111D',
  31198. '\u3172': '\u111E',
  31199. '\u3173': '\u1120',
  31200. '\u3174': '\u1122',
  31201. '\u3175': '\u1123',
  31202. '\u3176': '\u1127',
  31203. '\u3177': '\u1129',
  31204. '\u3178': '\u112B',
  31205. '\u3179': '\u112C',
  31206. '\u317A': '\u112D',
  31207. '\u317B': '\u112E',
  31208. '\u317C': '\u112F',
  31209. '\u317D': '\u1132',
  31210. '\u317E': '\u1136',
  31211. '\u317F': '\u1140',
  31212. '\u3180': '\u1147',
  31213. '\u3181': '\u114C',
  31214. '\u3182': '\u11F1',
  31215. '\u3183': '\u11F2',
  31216. '\u3184': '\u1157',
  31217. '\u3185': '\u1158',
  31218. '\u3186': '\u1159',
  31219. '\u3187': '\u1184',
  31220. '\u3188': '\u1185',
  31221. '\u3189': '\u1188',
  31222. '\u318A': '\u1191',
  31223. '\u318B': '\u1192',
  31224. '\u318C': '\u1194',
  31225. '\u318D': '\u119E',
  31226. '\u318E': '\u11A1',
  31227. '\u3200': '\u0028\u1100\u0029',
  31228. '\u3201': '\u0028\u1102\u0029',
  31229. '\u3202': '\u0028\u1103\u0029',
  31230. '\u3203': '\u0028\u1105\u0029',
  31231. '\u3204': '\u0028\u1106\u0029',
  31232. '\u3205': '\u0028\u1107\u0029',
  31233. '\u3206': '\u0028\u1109\u0029',
  31234. '\u3207': '\u0028\u110B\u0029',
  31235. '\u3208': '\u0028\u110C\u0029',
  31236. '\u3209': '\u0028\u110E\u0029',
  31237. '\u320A': '\u0028\u110F\u0029',
  31238. '\u320B': '\u0028\u1110\u0029',
  31239. '\u320C': '\u0028\u1111\u0029',
  31240. '\u320D': '\u0028\u1112\u0029',
  31241. '\u320E': '\u0028\u1100\u1161\u0029',
  31242. '\u320F': '\u0028\u1102\u1161\u0029',
  31243. '\u3210': '\u0028\u1103\u1161\u0029',
  31244. '\u3211': '\u0028\u1105\u1161\u0029',
  31245. '\u3212': '\u0028\u1106\u1161\u0029',
  31246. '\u3213': '\u0028\u1107\u1161\u0029',
  31247. '\u3214': '\u0028\u1109\u1161\u0029',
  31248. '\u3215': '\u0028\u110B\u1161\u0029',
  31249. '\u3216': '\u0028\u110C\u1161\u0029',
  31250. '\u3217': '\u0028\u110E\u1161\u0029',
  31251. '\u3218': '\u0028\u110F\u1161\u0029',
  31252. '\u3219': '\u0028\u1110\u1161\u0029',
  31253. '\u321A': '\u0028\u1111\u1161\u0029',
  31254. '\u321B': '\u0028\u1112\u1161\u0029',
  31255. '\u321C': '\u0028\u110C\u116E\u0029',
  31256. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  31257. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  31258. '\u3220': '\u0028\u4E00\u0029',
  31259. '\u3221': '\u0028\u4E8C\u0029',
  31260. '\u3222': '\u0028\u4E09\u0029',
  31261. '\u3223': '\u0028\u56DB\u0029',
  31262. '\u3224': '\u0028\u4E94\u0029',
  31263. '\u3225': '\u0028\u516D\u0029',
  31264. '\u3226': '\u0028\u4E03\u0029',
  31265. '\u3227': '\u0028\u516B\u0029',
  31266. '\u3228': '\u0028\u4E5D\u0029',
  31267. '\u3229': '\u0028\u5341\u0029',
  31268. '\u322A': '\u0028\u6708\u0029',
  31269. '\u322B': '\u0028\u706B\u0029',
  31270. '\u322C': '\u0028\u6C34\u0029',
  31271. '\u322D': '\u0028\u6728\u0029',
  31272. '\u322E': '\u0028\u91D1\u0029',
  31273. '\u322F': '\u0028\u571F\u0029',
  31274. '\u3230': '\u0028\u65E5\u0029',
  31275. '\u3231': '\u0028\u682A\u0029',
  31276. '\u3232': '\u0028\u6709\u0029',
  31277. '\u3233': '\u0028\u793E\u0029',
  31278. '\u3234': '\u0028\u540D\u0029',
  31279. '\u3235': '\u0028\u7279\u0029',
  31280. '\u3236': '\u0028\u8CA1\u0029',
  31281. '\u3237': '\u0028\u795D\u0029',
  31282. '\u3238': '\u0028\u52B4\u0029',
  31283. '\u3239': '\u0028\u4EE3\u0029',
  31284. '\u323A': '\u0028\u547C\u0029',
  31285. '\u323B': '\u0028\u5B66\u0029',
  31286. '\u323C': '\u0028\u76E3\u0029',
  31287. '\u323D': '\u0028\u4F01\u0029',
  31288. '\u323E': '\u0028\u8CC7\u0029',
  31289. '\u323F': '\u0028\u5354\u0029',
  31290. '\u3240': '\u0028\u796D\u0029',
  31291. '\u3241': '\u0028\u4F11\u0029',
  31292. '\u3242': '\u0028\u81EA\u0029',
  31293. '\u3243': '\u0028\u81F3\u0029',
  31294. '\u32C0': '\u0031\u6708',
  31295. '\u32C1': '\u0032\u6708',
  31296. '\u32C2': '\u0033\u6708',
  31297. '\u32C3': '\u0034\u6708',
  31298. '\u32C4': '\u0035\u6708',
  31299. '\u32C5': '\u0036\u6708',
  31300. '\u32C6': '\u0037\u6708',
  31301. '\u32C7': '\u0038\u6708',
  31302. '\u32C8': '\u0039\u6708',
  31303. '\u32C9': '\u0031\u0030\u6708',
  31304. '\u32CA': '\u0031\u0031\u6708',
  31305. '\u32CB': '\u0031\u0032\u6708',
  31306. '\u3358': '\u0030\u70B9',
  31307. '\u3359': '\u0031\u70B9',
  31308. '\u335A': '\u0032\u70B9',
  31309. '\u335B': '\u0033\u70B9',
  31310. '\u335C': '\u0034\u70B9',
  31311. '\u335D': '\u0035\u70B9',
  31312. '\u335E': '\u0036\u70B9',
  31313. '\u335F': '\u0037\u70B9',
  31314. '\u3360': '\u0038\u70B9',
  31315. '\u3361': '\u0039\u70B9',
  31316. '\u3362': '\u0031\u0030\u70B9',
  31317. '\u3363': '\u0031\u0031\u70B9',
  31318. '\u3364': '\u0031\u0032\u70B9',
  31319. '\u3365': '\u0031\u0033\u70B9',
  31320. '\u3366': '\u0031\u0034\u70B9',
  31321. '\u3367': '\u0031\u0035\u70B9',
  31322. '\u3368': '\u0031\u0036\u70B9',
  31323. '\u3369': '\u0031\u0037\u70B9',
  31324. '\u336A': '\u0031\u0038\u70B9',
  31325. '\u336B': '\u0031\u0039\u70B9',
  31326. '\u336C': '\u0032\u0030\u70B9',
  31327. '\u336D': '\u0032\u0031\u70B9',
  31328. '\u336E': '\u0032\u0032\u70B9',
  31329. '\u336F': '\u0032\u0033\u70B9',
  31330. '\u3370': '\u0032\u0034\u70B9',
  31331. '\u33E0': '\u0031\u65E5',
  31332. '\u33E1': '\u0032\u65E5',
  31333. '\u33E2': '\u0033\u65E5',
  31334. '\u33E3': '\u0034\u65E5',
  31335. '\u33E4': '\u0035\u65E5',
  31336. '\u33E5': '\u0036\u65E5',
  31337. '\u33E6': '\u0037\u65E5',
  31338. '\u33E7': '\u0038\u65E5',
  31339. '\u33E8': '\u0039\u65E5',
  31340. '\u33E9': '\u0031\u0030\u65E5',
  31341. '\u33EA': '\u0031\u0031\u65E5',
  31342. '\u33EB': '\u0031\u0032\u65E5',
  31343. '\u33EC': '\u0031\u0033\u65E5',
  31344. '\u33ED': '\u0031\u0034\u65E5',
  31345. '\u33EE': '\u0031\u0035\u65E5',
  31346. '\u33EF': '\u0031\u0036\u65E5',
  31347. '\u33F0': '\u0031\u0037\u65E5',
  31348. '\u33F1': '\u0031\u0038\u65E5',
  31349. '\u33F2': '\u0031\u0039\u65E5',
  31350. '\u33F3': '\u0032\u0030\u65E5',
  31351. '\u33F4': '\u0032\u0031\u65E5',
  31352. '\u33F5': '\u0032\u0032\u65E5',
  31353. '\u33F6': '\u0032\u0033\u65E5',
  31354. '\u33F7': '\u0032\u0034\u65E5',
  31355. '\u33F8': '\u0032\u0035\u65E5',
  31356. '\u33F9': '\u0032\u0036\u65E5',
  31357. '\u33FA': '\u0032\u0037\u65E5',
  31358. '\u33FB': '\u0032\u0038\u65E5',
  31359. '\u33FC': '\u0032\u0039\u65E5',
  31360. '\u33FD': '\u0033\u0030\u65E5',
  31361. '\u33FE': '\u0033\u0031\u65E5',
  31362. '\uFB00': '\u0066\u0066',
  31363. '\uFB01': '\u0066\u0069',
  31364. '\uFB02': '\u0066\u006C',
  31365. '\uFB03': '\u0066\u0066\u0069',
  31366. '\uFB04': '\u0066\u0066\u006C',
  31367. '\uFB05': '\u017F\u0074',
  31368. '\uFB06': '\u0073\u0074',
  31369. '\uFB13': '\u0574\u0576',
  31370. '\uFB14': '\u0574\u0565',
  31371. '\uFB15': '\u0574\u056B',
  31372. '\uFB16': '\u057E\u0576',
  31373. '\uFB17': '\u0574\u056D',
  31374. '\uFB4F': '\u05D0\u05DC',
  31375. '\uFB50': '\u0671',
  31376. '\uFB51': '\u0671',
  31377. '\uFB52': '\u067B',
  31378. '\uFB53': '\u067B',
  31379. '\uFB54': '\u067B',
  31380. '\uFB55': '\u067B',
  31381. '\uFB56': '\u067E',
  31382. '\uFB57': '\u067E',
  31383. '\uFB58': '\u067E',
  31384. '\uFB59': '\u067E',
  31385. '\uFB5A': '\u0680',
  31386. '\uFB5B': '\u0680',
  31387. '\uFB5C': '\u0680',
  31388. '\uFB5D': '\u0680',
  31389. '\uFB5E': '\u067A',
  31390. '\uFB5F': '\u067A',
  31391. '\uFB60': '\u067A',
  31392. '\uFB61': '\u067A',
  31393. '\uFB62': '\u067F',
  31394. '\uFB63': '\u067F',
  31395. '\uFB64': '\u067F',
  31396. '\uFB65': '\u067F',
  31397. '\uFB66': '\u0679',
  31398. '\uFB67': '\u0679',
  31399. '\uFB68': '\u0679',
  31400. '\uFB69': '\u0679',
  31401. '\uFB6A': '\u06A4',
  31402. '\uFB6B': '\u06A4',
  31403. '\uFB6C': '\u06A4',
  31404. '\uFB6D': '\u06A4',
  31405. '\uFB6E': '\u06A6',
  31406. '\uFB6F': '\u06A6',
  31407. '\uFB70': '\u06A6',
  31408. '\uFB71': '\u06A6',
  31409. '\uFB72': '\u0684',
  31410. '\uFB73': '\u0684',
  31411. '\uFB74': '\u0684',
  31412. '\uFB75': '\u0684',
  31413. '\uFB76': '\u0683',
  31414. '\uFB77': '\u0683',
  31415. '\uFB78': '\u0683',
  31416. '\uFB79': '\u0683',
  31417. '\uFB7A': '\u0686',
  31418. '\uFB7B': '\u0686',
  31419. '\uFB7C': '\u0686',
  31420. '\uFB7D': '\u0686',
  31421. '\uFB7E': '\u0687',
  31422. '\uFB7F': '\u0687',
  31423. '\uFB80': '\u0687',
  31424. '\uFB81': '\u0687',
  31425. '\uFB82': '\u068D',
  31426. '\uFB83': '\u068D',
  31427. '\uFB84': '\u068C',
  31428. '\uFB85': '\u068C',
  31429. '\uFB86': '\u068E',
  31430. '\uFB87': '\u068E',
  31431. '\uFB88': '\u0688',
  31432. '\uFB89': '\u0688',
  31433. '\uFB8A': '\u0698',
  31434. '\uFB8B': '\u0698',
  31435. '\uFB8C': '\u0691',
  31436. '\uFB8D': '\u0691',
  31437. '\uFB8E': '\u06A9',
  31438. '\uFB8F': '\u06A9',
  31439. '\uFB90': '\u06A9',
  31440. '\uFB91': '\u06A9',
  31441. '\uFB92': '\u06AF',
  31442. '\uFB93': '\u06AF',
  31443. '\uFB94': '\u06AF',
  31444. '\uFB95': '\u06AF',
  31445. '\uFB96': '\u06B3',
  31446. '\uFB97': '\u06B3',
  31447. '\uFB98': '\u06B3',
  31448. '\uFB99': '\u06B3',
  31449. '\uFB9A': '\u06B1',
  31450. '\uFB9B': '\u06B1',
  31451. '\uFB9C': '\u06B1',
  31452. '\uFB9D': '\u06B1',
  31453. '\uFB9E': '\u06BA',
  31454. '\uFB9F': '\u06BA',
  31455. '\uFBA0': '\u06BB',
  31456. '\uFBA1': '\u06BB',
  31457. '\uFBA2': '\u06BB',
  31458. '\uFBA3': '\u06BB',
  31459. '\uFBA4': '\u06C0',
  31460. '\uFBA5': '\u06C0',
  31461. '\uFBA6': '\u06C1',
  31462. '\uFBA7': '\u06C1',
  31463. '\uFBA8': '\u06C1',
  31464. '\uFBA9': '\u06C1',
  31465. '\uFBAA': '\u06BE',
  31466. '\uFBAB': '\u06BE',
  31467. '\uFBAC': '\u06BE',
  31468. '\uFBAD': '\u06BE',
  31469. '\uFBAE': '\u06D2',
  31470. '\uFBAF': '\u06D2',
  31471. '\uFBB0': '\u06D3',
  31472. '\uFBB1': '\u06D3',
  31473. '\uFBD3': '\u06AD',
  31474. '\uFBD4': '\u06AD',
  31475. '\uFBD5': '\u06AD',
  31476. '\uFBD6': '\u06AD',
  31477. '\uFBD7': '\u06C7',
  31478. '\uFBD8': '\u06C7',
  31479. '\uFBD9': '\u06C6',
  31480. '\uFBDA': '\u06C6',
  31481. '\uFBDB': '\u06C8',
  31482. '\uFBDC': '\u06C8',
  31483. '\uFBDD': '\u0677',
  31484. '\uFBDE': '\u06CB',
  31485. '\uFBDF': '\u06CB',
  31486. '\uFBE0': '\u06C5',
  31487. '\uFBE1': '\u06C5',
  31488. '\uFBE2': '\u06C9',
  31489. '\uFBE3': '\u06C9',
  31490. '\uFBE4': '\u06D0',
  31491. '\uFBE5': '\u06D0',
  31492. '\uFBE6': '\u06D0',
  31493. '\uFBE7': '\u06D0',
  31494. '\uFBE8': '\u0649',
  31495. '\uFBE9': '\u0649',
  31496. '\uFBEA': '\u0626\u0627',
  31497. '\uFBEB': '\u0626\u0627',
  31498. '\uFBEC': '\u0626\u06D5',
  31499. '\uFBED': '\u0626\u06D5',
  31500. '\uFBEE': '\u0626\u0648',
  31501. '\uFBEF': '\u0626\u0648',
  31502. '\uFBF0': '\u0626\u06C7',
  31503. '\uFBF1': '\u0626\u06C7',
  31504. '\uFBF2': '\u0626\u06C6',
  31505. '\uFBF3': '\u0626\u06C6',
  31506. '\uFBF4': '\u0626\u06C8',
  31507. '\uFBF5': '\u0626\u06C8',
  31508. '\uFBF6': '\u0626\u06D0',
  31509. '\uFBF7': '\u0626\u06D0',
  31510. '\uFBF8': '\u0626\u06D0',
  31511. '\uFBF9': '\u0626\u0649',
  31512. '\uFBFA': '\u0626\u0649',
  31513. '\uFBFB': '\u0626\u0649',
  31514. '\uFBFC': '\u06CC',
  31515. '\uFBFD': '\u06CC',
  31516. '\uFBFE': '\u06CC',
  31517. '\uFBFF': '\u06CC',
  31518. '\uFC00': '\u0626\u062C',
  31519. '\uFC01': '\u0626\u062D',
  31520. '\uFC02': '\u0626\u0645',
  31521. '\uFC03': '\u0626\u0649',
  31522. '\uFC04': '\u0626\u064A',
  31523. '\uFC05': '\u0628\u062C',
  31524. '\uFC06': '\u0628\u062D',
  31525. '\uFC07': '\u0628\u062E',
  31526. '\uFC08': '\u0628\u0645',
  31527. '\uFC09': '\u0628\u0649',
  31528. '\uFC0A': '\u0628\u064A',
  31529. '\uFC0B': '\u062A\u062C',
  31530. '\uFC0C': '\u062A\u062D',
  31531. '\uFC0D': '\u062A\u062E',
  31532. '\uFC0E': '\u062A\u0645',
  31533. '\uFC0F': '\u062A\u0649',
  31534. '\uFC10': '\u062A\u064A',
  31535. '\uFC11': '\u062B\u062C',
  31536. '\uFC12': '\u062B\u0645',
  31537. '\uFC13': '\u062B\u0649',
  31538. '\uFC14': '\u062B\u064A',
  31539. '\uFC15': '\u062C\u062D',
  31540. '\uFC16': '\u062C\u0645',
  31541. '\uFC17': '\u062D\u062C',
  31542. '\uFC18': '\u062D\u0645',
  31543. '\uFC19': '\u062E\u062C',
  31544. '\uFC1A': '\u062E\u062D',
  31545. '\uFC1B': '\u062E\u0645',
  31546. '\uFC1C': '\u0633\u062C',
  31547. '\uFC1D': '\u0633\u062D',
  31548. '\uFC1E': '\u0633\u062E',
  31549. '\uFC1F': '\u0633\u0645',
  31550. '\uFC20': '\u0635\u062D',
  31551. '\uFC21': '\u0635\u0645',
  31552. '\uFC22': '\u0636\u062C',
  31553. '\uFC23': '\u0636\u062D',
  31554. '\uFC24': '\u0636\u062E',
  31555. '\uFC25': '\u0636\u0645',
  31556. '\uFC26': '\u0637\u062D',
  31557. '\uFC27': '\u0637\u0645',
  31558. '\uFC28': '\u0638\u0645',
  31559. '\uFC29': '\u0639\u062C',
  31560. '\uFC2A': '\u0639\u0645',
  31561. '\uFC2B': '\u063A\u062C',
  31562. '\uFC2C': '\u063A\u0645',
  31563. '\uFC2D': '\u0641\u062C',
  31564. '\uFC2E': '\u0641\u062D',
  31565. '\uFC2F': '\u0641\u062E',
  31566. '\uFC30': '\u0641\u0645',
  31567. '\uFC31': '\u0641\u0649',
  31568. '\uFC32': '\u0641\u064A',
  31569. '\uFC33': '\u0642\u062D',
  31570. '\uFC34': '\u0642\u0645',
  31571. '\uFC35': '\u0642\u0649',
  31572. '\uFC36': '\u0642\u064A',
  31573. '\uFC37': '\u0643\u0627',
  31574. '\uFC38': '\u0643\u062C',
  31575. '\uFC39': '\u0643\u062D',
  31576. '\uFC3A': '\u0643\u062E',
  31577. '\uFC3B': '\u0643\u0644',
  31578. '\uFC3C': '\u0643\u0645',
  31579. '\uFC3D': '\u0643\u0649',
  31580. '\uFC3E': '\u0643\u064A',
  31581. '\uFC3F': '\u0644\u062C',
  31582. '\uFC40': '\u0644\u062D',
  31583. '\uFC41': '\u0644\u062E',
  31584. '\uFC42': '\u0644\u0645',
  31585. '\uFC43': '\u0644\u0649',
  31586. '\uFC44': '\u0644\u064A',
  31587. '\uFC45': '\u0645\u062C',
  31588. '\uFC46': '\u0645\u062D',
  31589. '\uFC47': '\u0645\u062E',
  31590. '\uFC48': '\u0645\u0645',
  31591. '\uFC49': '\u0645\u0649',
  31592. '\uFC4A': '\u0645\u064A',
  31593. '\uFC4B': '\u0646\u062C',
  31594. '\uFC4C': '\u0646\u062D',
  31595. '\uFC4D': '\u0646\u062E',
  31596. '\uFC4E': '\u0646\u0645',
  31597. '\uFC4F': '\u0646\u0649',
  31598. '\uFC50': '\u0646\u064A',
  31599. '\uFC51': '\u0647\u062C',
  31600. '\uFC52': '\u0647\u0645',
  31601. '\uFC53': '\u0647\u0649',
  31602. '\uFC54': '\u0647\u064A',
  31603. '\uFC55': '\u064A\u062C',
  31604. '\uFC56': '\u064A\u062D',
  31605. '\uFC57': '\u064A\u062E',
  31606. '\uFC58': '\u064A\u0645',
  31607. '\uFC59': '\u064A\u0649',
  31608. '\uFC5A': '\u064A\u064A',
  31609. '\uFC5B': '\u0630\u0670',
  31610. '\uFC5C': '\u0631\u0670',
  31611. '\uFC5D': '\u0649\u0670',
  31612. '\uFC5E': '\u0020\u064C\u0651',
  31613. '\uFC5F': '\u0020\u064D\u0651',
  31614. '\uFC60': '\u0020\u064E\u0651',
  31615. '\uFC61': '\u0020\u064F\u0651',
  31616. '\uFC62': '\u0020\u0650\u0651',
  31617. '\uFC63': '\u0020\u0651\u0670',
  31618. '\uFC64': '\u0626\u0631',
  31619. '\uFC65': '\u0626\u0632',
  31620. '\uFC66': '\u0626\u0645',
  31621. '\uFC67': '\u0626\u0646',
  31622. '\uFC68': '\u0626\u0649',
  31623. '\uFC69': '\u0626\u064A',
  31624. '\uFC6A': '\u0628\u0631',
  31625. '\uFC6B': '\u0628\u0632',
  31626. '\uFC6C': '\u0628\u0645',
  31627. '\uFC6D': '\u0628\u0646',
  31628. '\uFC6E': '\u0628\u0649',
  31629. '\uFC6F': '\u0628\u064A',
  31630. '\uFC70': '\u062A\u0631',
  31631. '\uFC71': '\u062A\u0632',
  31632. '\uFC72': '\u062A\u0645',
  31633. '\uFC73': '\u062A\u0646',
  31634. '\uFC74': '\u062A\u0649',
  31635. '\uFC75': '\u062A\u064A',
  31636. '\uFC76': '\u062B\u0631',
  31637. '\uFC77': '\u062B\u0632',
  31638. '\uFC78': '\u062B\u0645',
  31639. '\uFC79': '\u062B\u0646',
  31640. '\uFC7A': '\u062B\u0649',
  31641. '\uFC7B': '\u062B\u064A',
  31642. '\uFC7C': '\u0641\u0649',
  31643. '\uFC7D': '\u0641\u064A',
  31644. '\uFC7E': '\u0642\u0649',
  31645. '\uFC7F': '\u0642\u064A',
  31646. '\uFC80': '\u0643\u0627',
  31647. '\uFC81': '\u0643\u0644',
  31648. '\uFC82': '\u0643\u0645',
  31649. '\uFC83': '\u0643\u0649',
  31650. '\uFC84': '\u0643\u064A',
  31651. '\uFC85': '\u0644\u0645',
  31652. '\uFC86': '\u0644\u0649',
  31653. '\uFC87': '\u0644\u064A',
  31654. '\uFC88': '\u0645\u0627',
  31655. '\uFC89': '\u0645\u0645',
  31656. '\uFC8A': '\u0646\u0631',
  31657. '\uFC8B': '\u0646\u0632',
  31658. '\uFC8C': '\u0646\u0645',
  31659. '\uFC8D': '\u0646\u0646',
  31660. '\uFC8E': '\u0646\u0649',
  31661. '\uFC8F': '\u0646\u064A',
  31662. '\uFC90': '\u0649\u0670',
  31663. '\uFC91': '\u064A\u0631',
  31664. '\uFC92': '\u064A\u0632',
  31665. '\uFC93': '\u064A\u0645',
  31666. '\uFC94': '\u064A\u0646',
  31667. '\uFC95': '\u064A\u0649',
  31668. '\uFC96': '\u064A\u064A',
  31669. '\uFC97': '\u0626\u062C',
  31670. '\uFC98': '\u0626\u062D',
  31671. '\uFC99': '\u0626\u062E',
  31672. '\uFC9A': '\u0626\u0645',
  31673. '\uFC9B': '\u0626\u0647',
  31674. '\uFC9C': '\u0628\u062C',
  31675. '\uFC9D': '\u0628\u062D',
  31676. '\uFC9E': '\u0628\u062E',
  31677. '\uFC9F': '\u0628\u0645',
  31678. '\uFCA0': '\u0628\u0647',
  31679. '\uFCA1': '\u062A\u062C',
  31680. '\uFCA2': '\u062A\u062D',
  31681. '\uFCA3': '\u062A\u062E',
  31682. '\uFCA4': '\u062A\u0645',
  31683. '\uFCA5': '\u062A\u0647',
  31684. '\uFCA6': '\u062B\u0645',
  31685. '\uFCA7': '\u062C\u062D',
  31686. '\uFCA8': '\u062C\u0645',
  31687. '\uFCA9': '\u062D\u062C',
  31688. '\uFCAA': '\u062D\u0645',
  31689. '\uFCAB': '\u062E\u062C',
  31690. '\uFCAC': '\u062E\u0645',
  31691. '\uFCAD': '\u0633\u062C',
  31692. '\uFCAE': '\u0633\u062D',
  31693. '\uFCAF': '\u0633\u062E',
  31694. '\uFCB0': '\u0633\u0645',
  31695. '\uFCB1': '\u0635\u062D',
  31696. '\uFCB2': '\u0635\u062E',
  31697. '\uFCB3': '\u0635\u0645',
  31698. '\uFCB4': '\u0636\u062C',
  31699. '\uFCB5': '\u0636\u062D',
  31700. '\uFCB6': '\u0636\u062E',
  31701. '\uFCB7': '\u0636\u0645',
  31702. '\uFCB8': '\u0637\u062D',
  31703. '\uFCB9': '\u0638\u0645',
  31704. '\uFCBA': '\u0639\u062C',
  31705. '\uFCBB': '\u0639\u0645',
  31706. '\uFCBC': '\u063A\u062C',
  31707. '\uFCBD': '\u063A\u0645',
  31708. '\uFCBE': '\u0641\u062C',
  31709. '\uFCBF': '\u0641\u062D',
  31710. '\uFCC0': '\u0641\u062E',
  31711. '\uFCC1': '\u0641\u0645',
  31712. '\uFCC2': '\u0642\u062D',
  31713. '\uFCC3': '\u0642\u0645',
  31714. '\uFCC4': '\u0643\u062C',
  31715. '\uFCC5': '\u0643\u062D',
  31716. '\uFCC6': '\u0643\u062E',
  31717. '\uFCC7': '\u0643\u0644',
  31718. '\uFCC8': '\u0643\u0645',
  31719. '\uFCC9': '\u0644\u062C',
  31720. '\uFCCA': '\u0644\u062D',
  31721. '\uFCCB': '\u0644\u062E',
  31722. '\uFCCC': '\u0644\u0645',
  31723. '\uFCCD': '\u0644\u0647',
  31724. '\uFCCE': '\u0645\u062C',
  31725. '\uFCCF': '\u0645\u062D',
  31726. '\uFCD0': '\u0645\u062E',
  31727. '\uFCD1': '\u0645\u0645',
  31728. '\uFCD2': '\u0646\u062C',
  31729. '\uFCD3': '\u0646\u062D',
  31730. '\uFCD4': '\u0646\u062E',
  31731. '\uFCD5': '\u0646\u0645',
  31732. '\uFCD6': '\u0646\u0647',
  31733. '\uFCD7': '\u0647\u062C',
  31734. '\uFCD8': '\u0647\u0645',
  31735. '\uFCD9': '\u0647\u0670',
  31736. '\uFCDA': '\u064A\u062C',
  31737. '\uFCDB': '\u064A\u062D',
  31738. '\uFCDC': '\u064A\u062E',
  31739. '\uFCDD': '\u064A\u0645',
  31740. '\uFCDE': '\u064A\u0647',
  31741. '\uFCDF': '\u0626\u0645',
  31742. '\uFCE0': '\u0626\u0647',
  31743. '\uFCE1': '\u0628\u0645',
  31744. '\uFCE2': '\u0628\u0647',
  31745. '\uFCE3': '\u062A\u0645',
  31746. '\uFCE4': '\u062A\u0647',
  31747. '\uFCE5': '\u062B\u0645',
  31748. '\uFCE6': '\u062B\u0647',
  31749. '\uFCE7': '\u0633\u0645',
  31750. '\uFCE8': '\u0633\u0647',
  31751. '\uFCE9': '\u0634\u0645',
  31752. '\uFCEA': '\u0634\u0647',
  31753. '\uFCEB': '\u0643\u0644',
  31754. '\uFCEC': '\u0643\u0645',
  31755. '\uFCED': '\u0644\u0645',
  31756. '\uFCEE': '\u0646\u0645',
  31757. '\uFCEF': '\u0646\u0647',
  31758. '\uFCF0': '\u064A\u0645',
  31759. '\uFCF1': '\u064A\u0647',
  31760. '\uFCF2': '\u0640\u064E\u0651',
  31761. '\uFCF3': '\u0640\u064F\u0651',
  31762. '\uFCF4': '\u0640\u0650\u0651',
  31763. '\uFCF5': '\u0637\u0649',
  31764. '\uFCF6': '\u0637\u064A',
  31765. '\uFCF7': '\u0639\u0649',
  31766. '\uFCF8': '\u0639\u064A',
  31767. '\uFCF9': '\u063A\u0649',
  31768. '\uFCFA': '\u063A\u064A',
  31769. '\uFCFB': '\u0633\u0649',
  31770. '\uFCFC': '\u0633\u064A',
  31771. '\uFCFD': '\u0634\u0649',
  31772. '\uFCFE': '\u0634\u064A',
  31773. '\uFCFF': '\u062D\u0649',
  31774. '\uFD00': '\u062D\u064A',
  31775. '\uFD01': '\u062C\u0649',
  31776. '\uFD02': '\u062C\u064A',
  31777. '\uFD03': '\u062E\u0649',
  31778. '\uFD04': '\u062E\u064A',
  31779. '\uFD05': '\u0635\u0649',
  31780. '\uFD06': '\u0635\u064A',
  31781. '\uFD07': '\u0636\u0649',
  31782. '\uFD08': '\u0636\u064A',
  31783. '\uFD09': '\u0634\u062C',
  31784. '\uFD0A': '\u0634\u062D',
  31785. '\uFD0B': '\u0634\u062E',
  31786. '\uFD0C': '\u0634\u0645',
  31787. '\uFD0D': '\u0634\u0631',
  31788. '\uFD0E': '\u0633\u0631',
  31789. '\uFD0F': '\u0635\u0631',
  31790. '\uFD10': '\u0636\u0631',
  31791. '\uFD11': '\u0637\u0649',
  31792. '\uFD12': '\u0637\u064A',
  31793. '\uFD13': '\u0639\u0649',
  31794. '\uFD14': '\u0639\u064A',
  31795. '\uFD15': '\u063A\u0649',
  31796. '\uFD16': '\u063A\u064A',
  31797. '\uFD17': '\u0633\u0649',
  31798. '\uFD18': '\u0633\u064A',
  31799. '\uFD19': '\u0634\u0649',
  31800. '\uFD1A': '\u0634\u064A',
  31801. '\uFD1B': '\u062D\u0649',
  31802. '\uFD1C': '\u062D\u064A',
  31803. '\uFD1D': '\u062C\u0649',
  31804. '\uFD1E': '\u062C\u064A',
  31805. '\uFD1F': '\u062E\u0649',
  31806. '\uFD20': '\u062E\u064A',
  31807. '\uFD21': '\u0635\u0649',
  31808. '\uFD22': '\u0635\u064A',
  31809. '\uFD23': '\u0636\u0649',
  31810. '\uFD24': '\u0636\u064A',
  31811. '\uFD25': '\u0634\u062C',
  31812. '\uFD26': '\u0634\u062D',
  31813. '\uFD27': '\u0634\u062E',
  31814. '\uFD28': '\u0634\u0645',
  31815. '\uFD29': '\u0634\u0631',
  31816. '\uFD2A': '\u0633\u0631',
  31817. '\uFD2B': '\u0635\u0631',
  31818. '\uFD2C': '\u0636\u0631',
  31819. '\uFD2D': '\u0634\u062C',
  31820. '\uFD2E': '\u0634\u062D',
  31821. '\uFD2F': '\u0634\u062E',
  31822. '\uFD30': '\u0634\u0645',
  31823. '\uFD31': '\u0633\u0647',
  31824. '\uFD32': '\u0634\u0647',
  31825. '\uFD33': '\u0637\u0645',
  31826. '\uFD34': '\u0633\u062C',
  31827. '\uFD35': '\u0633\u062D',
  31828. '\uFD36': '\u0633\u062E',
  31829. '\uFD37': '\u0634\u062C',
  31830. '\uFD38': '\u0634\u062D',
  31831. '\uFD39': '\u0634\u062E',
  31832. '\uFD3A': '\u0637\u0645',
  31833. '\uFD3B': '\u0638\u0645',
  31834. '\uFD3C': '\u0627\u064B',
  31835. '\uFD3D': '\u0627\u064B',
  31836. '\uFD50': '\u062A\u062C\u0645',
  31837. '\uFD51': '\u062A\u062D\u062C',
  31838. '\uFD52': '\u062A\u062D\u062C',
  31839. '\uFD53': '\u062A\u062D\u0645',
  31840. '\uFD54': '\u062A\u062E\u0645',
  31841. '\uFD55': '\u062A\u0645\u062C',
  31842. '\uFD56': '\u062A\u0645\u062D',
  31843. '\uFD57': '\u062A\u0645\u062E',
  31844. '\uFD58': '\u062C\u0645\u062D',
  31845. '\uFD59': '\u062C\u0645\u062D',
  31846. '\uFD5A': '\u062D\u0645\u064A',
  31847. '\uFD5B': '\u062D\u0645\u0649',
  31848. '\uFD5C': '\u0633\u062D\u062C',
  31849. '\uFD5D': '\u0633\u062C\u062D',
  31850. '\uFD5E': '\u0633\u062C\u0649',
  31851. '\uFD5F': '\u0633\u0645\u062D',
  31852. '\uFD60': '\u0633\u0645\u062D',
  31853. '\uFD61': '\u0633\u0645\u062C',
  31854. '\uFD62': '\u0633\u0645\u0645',
  31855. '\uFD63': '\u0633\u0645\u0645',
  31856. '\uFD64': '\u0635\u062D\u062D',
  31857. '\uFD65': '\u0635\u062D\u062D',
  31858. '\uFD66': '\u0635\u0645\u0645',
  31859. '\uFD67': '\u0634\u062D\u0645',
  31860. '\uFD68': '\u0634\u062D\u0645',
  31861. '\uFD69': '\u0634\u062C\u064A',
  31862. '\uFD6A': '\u0634\u0645\u062E',
  31863. '\uFD6B': '\u0634\u0645\u062E',
  31864. '\uFD6C': '\u0634\u0645\u0645',
  31865. '\uFD6D': '\u0634\u0645\u0645',
  31866. '\uFD6E': '\u0636\u062D\u0649',
  31867. '\uFD6F': '\u0636\u062E\u0645',
  31868. '\uFD70': '\u0636\u062E\u0645',
  31869. '\uFD71': '\u0637\u0645\u062D',
  31870. '\uFD72': '\u0637\u0645\u062D',
  31871. '\uFD73': '\u0637\u0645\u0645',
  31872. '\uFD74': '\u0637\u0645\u064A',
  31873. '\uFD75': '\u0639\u062C\u0645',
  31874. '\uFD76': '\u0639\u0645\u0645',
  31875. '\uFD77': '\u0639\u0645\u0645',
  31876. '\uFD78': '\u0639\u0645\u0649',
  31877. '\uFD79': '\u063A\u0645\u0645',
  31878. '\uFD7A': '\u063A\u0645\u064A',
  31879. '\uFD7B': '\u063A\u0645\u0649',
  31880. '\uFD7C': '\u0641\u062E\u0645',
  31881. '\uFD7D': '\u0641\u062E\u0645',
  31882. '\uFD7E': '\u0642\u0645\u062D',
  31883. '\uFD7F': '\u0642\u0645\u0645',
  31884. '\uFD80': '\u0644\u062D\u0645',
  31885. '\uFD81': '\u0644\u062D\u064A',
  31886. '\uFD82': '\u0644\u062D\u0649',
  31887. '\uFD83': '\u0644\u062C\u062C',
  31888. '\uFD84': '\u0644\u062C\u062C',
  31889. '\uFD85': '\u0644\u062E\u0645',
  31890. '\uFD86': '\u0644\u062E\u0645',
  31891. '\uFD87': '\u0644\u0645\u062D',
  31892. '\uFD88': '\u0644\u0645\u062D',
  31893. '\uFD89': '\u0645\u062D\u062C',
  31894. '\uFD8A': '\u0645\u062D\u0645',
  31895. '\uFD8B': '\u0645\u062D\u064A',
  31896. '\uFD8C': '\u0645\u062C\u062D',
  31897. '\uFD8D': '\u0645\u062C\u0645',
  31898. '\uFD8E': '\u0645\u062E\u062C',
  31899. '\uFD8F': '\u0645\u062E\u0645',
  31900. '\uFD92': '\u0645\u062C\u062E',
  31901. '\uFD93': '\u0647\u0645\u062C',
  31902. '\uFD94': '\u0647\u0645\u0645',
  31903. '\uFD95': '\u0646\u062D\u0645',
  31904. '\uFD96': '\u0646\u062D\u0649',
  31905. '\uFD97': '\u0646\u062C\u0645',
  31906. '\uFD98': '\u0646\u062C\u0645',
  31907. '\uFD99': '\u0646\u062C\u0649',
  31908. '\uFD9A': '\u0646\u0645\u064A',
  31909. '\uFD9B': '\u0646\u0645\u0649',
  31910. '\uFD9C': '\u064A\u0645\u0645',
  31911. '\uFD9D': '\u064A\u0645\u0645',
  31912. '\uFD9E': '\u0628\u062E\u064A',
  31913. '\uFD9F': '\u062A\u062C\u064A',
  31914. '\uFDA0': '\u062A\u062C\u0649',
  31915. '\uFDA1': '\u062A\u062E\u064A',
  31916. '\uFDA2': '\u062A\u062E\u0649',
  31917. '\uFDA3': '\u062A\u0645\u064A',
  31918. '\uFDA4': '\u062A\u0645\u0649',
  31919. '\uFDA5': '\u062C\u0645\u064A',
  31920. '\uFDA6': '\u062C\u062D\u0649',
  31921. '\uFDA7': '\u062C\u0645\u0649',
  31922. '\uFDA8': '\u0633\u062E\u0649',
  31923. '\uFDA9': '\u0635\u062D\u064A',
  31924. '\uFDAA': '\u0634\u062D\u064A',
  31925. '\uFDAB': '\u0636\u062D\u064A',
  31926. '\uFDAC': '\u0644\u062C\u064A',
  31927. '\uFDAD': '\u0644\u0645\u064A',
  31928. '\uFDAE': '\u064A\u062D\u064A',
  31929. '\uFDAF': '\u064A\u062C\u064A',
  31930. '\uFDB0': '\u064A\u0645\u064A',
  31931. '\uFDB1': '\u0645\u0645\u064A',
  31932. '\uFDB2': '\u0642\u0645\u064A',
  31933. '\uFDB3': '\u0646\u062D\u064A',
  31934. '\uFDB4': '\u0642\u0645\u062D',
  31935. '\uFDB5': '\u0644\u062D\u0645',
  31936. '\uFDB6': '\u0639\u0645\u064A',
  31937. '\uFDB7': '\u0643\u0645\u064A',
  31938. '\uFDB8': '\u0646\u062C\u062D',
  31939. '\uFDB9': '\u0645\u062E\u064A',
  31940. '\uFDBA': '\u0644\u062C\u0645',
  31941. '\uFDBB': '\u0643\u0645\u0645',
  31942. '\uFDBC': '\u0644\u062C\u0645',
  31943. '\uFDBD': '\u0646\u062C\u062D',
  31944. '\uFDBE': '\u062C\u062D\u064A',
  31945. '\uFDBF': '\u062D\u062C\u064A',
  31946. '\uFDC0': '\u0645\u062C\u064A',
  31947. '\uFDC1': '\u0641\u0645\u064A',
  31948. '\uFDC2': '\u0628\u062D\u064A',
  31949. '\uFDC3': '\u0643\u0645\u0645',
  31950. '\uFDC4': '\u0639\u062C\u0645',
  31951. '\uFDC5': '\u0635\u0645\u0645',
  31952. '\uFDC6': '\u0633\u062E\u064A',
  31953. '\uFDC7': '\u0646\u062C\u064A',
  31954. '\uFE49': '\u203E',
  31955. '\uFE4A': '\u203E',
  31956. '\uFE4B': '\u203E',
  31957. '\uFE4C': '\u203E',
  31958. '\uFE4D': '\u005F',
  31959. '\uFE4E': '\u005F',
  31960. '\uFE4F': '\u005F',
  31961. '\uFE80': '\u0621',
  31962. '\uFE81': '\u0622',
  31963. '\uFE82': '\u0622',
  31964. '\uFE83': '\u0623',
  31965. '\uFE84': '\u0623',
  31966. '\uFE85': '\u0624',
  31967. '\uFE86': '\u0624',
  31968. '\uFE87': '\u0625',
  31969. '\uFE88': '\u0625',
  31970. '\uFE89': '\u0626',
  31971. '\uFE8A': '\u0626',
  31972. '\uFE8B': '\u0626',
  31973. '\uFE8C': '\u0626',
  31974. '\uFE8D': '\u0627',
  31975. '\uFE8E': '\u0627',
  31976. '\uFE8F': '\u0628',
  31977. '\uFE90': '\u0628',
  31978. '\uFE91': '\u0628',
  31979. '\uFE92': '\u0628',
  31980. '\uFE93': '\u0629',
  31981. '\uFE94': '\u0629',
  31982. '\uFE95': '\u062A',
  31983. '\uFE96': '\u062A',
  31984. '\uFE97': '\u062A',
  31985. '\uFE98': '\u062A',
  31986. '\uFE99': '\u062B',
  31987. '\uFE9A': '\u062B',
  31988. '\uFE9B': '\u062B',
  31989. '\uFE9C': '\u062B',
  31990. '\uFE9D': '\u062C',
  31991. '\uFE9E': '\u062C',
  31992. '\uFE9F': '\u062C',
  31993. '\uFEA0': '\u062C',
  31994. '\uFEA1': '\u062D',
  31995. '\uFEA2': '\u062D',
  31996. '\uFEA3': '\u062D',
  31997. '\uFEA4': '\u062D',
  31998. '\uFEA5': '\u062E',
  31999. '\uFEA6': '\u062E',
  32000. '\uFEA7': '\u062E',
  32001. '\uFEA8': '\u062E',
  32002. '\uFEA9': '\u062F',
  32003. '\uFEAA': '\u062F',
  32004. '\uFEAB': '\u0630',
  32005. '\uFEAC': '\u0630',
  32006. '\uFEAD': '\u0631',
  32007. '\uFEAE': '\u0631',
  32008. '\uFEAF': '\u0632',
  32009. '\uFEB0': '\u0632',
  32010. '\uFEB1': '\u0633',
  32011. '\uFEB2': '\u0633',
  32012. '\uFEB3': '\u0633',
  32013. '\uFEB4': '\u0633',
  32014. '\uFEB5': '\u0634',
  32015. '\uFEB6': '\u0634',
  32016. '\uFEB7': '\u0634',
  32017. '\uFEB8': '\u0634',
  32018. '\uFEB9': '\u0635',
  32019. '\uFEBA': '\u0635',
  32020. '\uFEBB': '\u0635',
  32021. '\uFEBC': '\u0635',
  32022. '\uFEBD': '\u0636',
  32023. '\uFEBE': '\u0636',
  32024. '\uFEBF': '\u0636',
  32025. '\uFEC0': '\u0636',
  32026. '\uFEC1': '\u0637',
  32027. '\uFEC2': '\u0637',
  32028. '\uFEC3': '\u0637',
  32029. '\uFEC4': '\u0637',
  32030. '\uFEC5': '\u0638',
  32031. '\uFEC6': '\u0638',
  32032. '\uFEC7': '\u0638',
  32033. '\uFEC8': '\u0638',
  32034. '\uFEC9': '\u0639',
  32035. '\uFECA': '\u0639',
  32036. '\uFECB': '\u0639',
  32037. '\uFECC': '\u0639',
  32038. '\uFECD': '\u063A',
  32039. '\uFECE': '\u063A',
  32040. '\uFECF': '\u063A',
  32041. '\uFED0': '\u063A',
  32042. '\uFED1': '\u0641',
  32043. '\uFED2': '\u0641',
  32044. '\uFED3': '\u0641',
  32045. '\uFED4': '\u0641',
  32046. '\uFED5': '\u0642',
  32047. '\uFED6': '\u0642',
  32048. '\uFED7': '\u0642',
  32049. '\uFED8': '\u0642',
  32050. '\uFED9': '\u0643',
  32051. '\uFEDA': '\u0643',
  32052. '\uFEDB': '\u0643',
  32053. '\uFEDC': '\u0643',
  32054. '\uFEDD': '\u0644',
  32055. '\uFEDE': '\u0644',
  32056. '\uFEDF': '\u0644',
  32057. '\uFEE0': '\u0644',
  32058. '\uFEE1': '\u0645',
  32059. '\uFEE2': '\u0645',
  32060. '\uFEE3': '\u0645',
  32061. '\uFEE4': '\u0645',
  32062. '\uFEE5': '\u0646',
  32063. '\uFEE6': '\u0646',
  32064. '\uFEE7': '\u0646',
  32065. '\uFEE8': '\u0646',
  32066. '\uFEE9': '\u0647',
  32067. '\uFEEA': '\u0647',
  32068. '\uFEEB': '\u0647',
  32069. '\uFEEC': '\u0647',
  32070. '\uFEED': '\u0648',
  32071. '\uFEEE': '\u0648',
  32072. '\uFEEF': '\u0649',
  32073. '\uFEF0': '\u0649',
  32074. '\uFEF1': '\u064A',
  32075. '\uFEF2': '\u064A',
  32076. '\uFEF3': '\u064A',
  32077. '\uFEF4': '\u064A',
  32078. '\uFEF5': '\u0644\u0622',
  32079. '\uFEF6': '\u0644\u0622',
  32080. '\uFEF7': '\u0644\u0623',
  32081. '\uFEF8': '\u0644\u0623',
  32082. '\uFEF9': '\u0644\u0625',
  32083. '\uFEFA': '\u0644\u0625',
  32084. '\uFEFB': '\u0644\u0627',
  32085. '\uFEFC': '\u0644\u0627'
  32086. };
  32087. function reverseIfRtl(chars) {
  32088. var charsLength = chars.length;
  32089. //reverse an arabic ligature
  32090. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  32091. return chars;
  32092. }
  32093. var s = '';
  32094. for (var ii = charsLength - 1; ii >= 0; ii--) {
  32095. s += chars[ii];
  32096. }
  32097. return s;
  32098. }
  32099. function adjustWidths(properties) {
  32100. if (!properties.fontMatrix) {
  32101. return;
  32102. }
  32103. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  32104. return;
  32105. }
  32106. // adjusting width to fontMatrix scale
  32107. var scale = 0.001 / properties.fontMatrix[0];
  32108. var glyphsWidths = properties.widths;
  32109. for (var glyph in glyphsWidths) {
  32110. glyphsWidths[glyph] *= scale;
  32111. }
  32112. properties.defaultWidth *= scale;
  32113. }
  32114. function getFontType(type, subtype) {
  32115. switch (type) {
  32116. case 'Type1':
  32117. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  32118. case 'CIDFontType0':
  32119. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  32120. FontType.CIDFONTTYPE0;
  32121. case 'OpenType':
  32122. return FontType.OPENTYPE;
  32123. case 'TrueType':
  32124. return FontType.TRUETYPE;
  32125. case 'CIDFontType2':
  32126. return FontType.CIDFONTTYPE2;
  32127. case 'MMType1':
  32128. return FontType.MMTYPE1;
  32129. case 'Type0':
  32130. return FontType.TYPE0;
  32131. default:
  32132. return FontType.UNKNOWN;
  32133. }
  32134. }
  32135. var Glyph = (function GlyphClosure() {
  32136. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  32137. isSpace) {
  32138. this.fontChar = fontChar;
  32139. this.unicode = unicode;
  32140. this.accent = accent;
  32141. this.width = width;
  32142. this.vmetric = vmetric;
  32143. this.operatorListId = operatorListId;
  32144. this.isSpace = isSpace;
  32145. }
  32146. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  32147. vmetric, operatorListId, isSpace) {
  32148. return this.fontChar === fontChar &&
  32149. this.unicode === unicode &&
  32150. this.accent === accent &&
  32151. this.width === width &&
  32152. this.vmetric === vmetric &&
  32153. this.operatorListId === operatorListId &&
  32154. this.isSpace === isSpace;
  32155. };
  32156. return Glyph;
  32157. })();
  32158. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  32159. function ToUnicodeMap(cmap) {
  32160. // The elements of this._map can be integers or strings, depending on how
  32161. // |cmap| was created.
  32162. this._map = cmap;
  32163. }
  32164. ToUnicodeMap.prototype = {
  32165. get length() {
  32166. return this._map.length;
  32167. },
  32168. forEach: function(callback) {
  32169. for (var charCode in this._map) {
  32170. callback(charCode, this._map[charCode].charCodeAt(0));
  32171. }
  32172. },
  32173. has: function(i) {
  32174. return this._map[i] !== undefined;
  32175. },
  32176. get: function(i) {
  32177. return this._map[i];
  32178. },
  32179. charCodeOf: function(v) {
  32180. return this._map.indexOf(v);
  32181. }
  32182. };
  32183. return ToUnicodeMap;
  32184. })();
  32185. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  32186. function IdentityToUnicodeMap(firstChar, lastChar) {
  32187. this.firstChar = firstChar;
  32188. this.lastChar = lastChar;
  32189. }
  32190. IdentityToUnicodeMap.prototype = {
  32191. get length() {
  32192. return (this.lastChar + 1) - this.firstChar;
  32193. },
  32194. forEach: function (callback) {
  32195. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  32196. callback(i, i);
  32197. }
  32198. },
  32199. has: function (i) {
  32200. return this.firstChar <= i && i <= this.lastChar;
  32201. },
  32202. get: function (i) {
  32203. if (this.firstChar <= i && i <= this.lastChar) {
  32204. return String.fromCharCode(i);
  32205. }
  32206. return undefined;
  32207. },
  32208. charCodeOf: function (v) {
  32209. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  32210. }
  32211. };
  32212. return IdentityToUnicodeMap;
  32213. })();
  32214. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  32215. function writeInt16(dest, offset, num) {
  32216. dest[offset] = (num >> 8) & 0xFF;
  32217. dest[offset + 1] = num & 0xFF;
  32218. }
  32219. function writeInt32(dest, offset, num) {
  32220. dest[offset] = (num >> 24) & 0xFF;
  32221. dest[offset + 1] = (num >> 16) & 0xFF;
  32222. dest[offset + 2] = (num >> 8) & 0xFF;
  32223. dest[offset + 3] = num & 0xFF;
  32224. }
  32225. function writeData(dest, offset, data) {
  32226. var i, ii;
  32227. if (data instanceof Uint8Array) {
  32228. dest.set(data, offset);
  32229. } else if (typeof data === 'string') {
  32230. for (i = 0, ii = data.length; i < ii; i++) {
  32231. dest[offset++] = data.charCodeAt(i) & 0xFF;
  32232. }
  32233. } else {
  32234. // treating everything else as array
  32235. for (i = 0, ii = data.length; i < ii; i++) {
  32236. dest[offset++] = data[i] & 0xFF;
  32237. }
  32238. }
  32239. }
  32240. function OpenTypeFileBuilder(sfnt) {
  32241. this.sfnt = sfnt;
  32242. this.tables = Object.create(null);
  32243. }
  32244. OpenTypeFileBuilder.getSearchParams =
  32245. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  32246. var maxPower2 = 1, log2 = 0;
  32247. while ((maxPower2 ^ entriesCount) > maxPower2) {
  32248. maxPower2 <<= 1;
  32249. log2++;
  32250. }
  32251. var searchRange = maxPower2 * entrySize;
  32252. return {
  32253. range: searchRange,
  32254. entry: log2,
  32255. rangeShift: entrySize * entriesCount - searchRange
  32256. };
  32257. };
  32258. var OTF_HEADER_SIZE = 12;
  32259. var OTF_TABLE_ENTRY_SIZE = 16;
  32260. OpenTypeFileBuilder.prototype = {
  32261. toArray: function OpenTypeFileBuilder_toArray() {
  32262. var sfnt = this.sfnt;
  32263. // Tables needs to be written by ascendant alphabetic order
  32264. var tables = this.tables;
  32265. var tablesNames = Object.keys(tables);
  32266. tablesNames.sort();
  32267. var numTables = tablesNames.length;
  32268. var i, j, jj, table, tableName;
  32269. // layout the tables data
  32270. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  32271. var tableOffsets = [offset];
  32272. for (i = 0; i < numTables; i++) {
  32273. table = tables[tablesNames[i]];
  32274. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  32275. offset += paddedLength;
  32276. tableOffsets.push(offset);
  32277. }
  32278. var file = new Uint8Array(offset);
  32279. // write the table data first (mostly for checksum)
  32280. for (i = 0; i < numTables; i++) {
  32281. table = tables[tablesNames[i]];
  32282. writeData(file, tableOffsets[i], table);
  32283. }
  32284. // sfnt version (4 bytes)
  32285. if (sfnt === 'true') {
  32286. // Windows hates the Mac TrueType sfnt version number
  32287. sfnt = string32(0x00010000);
  32288. }
  32289. file[0] = sfnt.charCodeAt(0) & 0xFF;
  32290. file[1] = sfnt.charCodeAt(1) & 0xFF;
  32291. file[2] = sfnt.charCodeAt(2) & 0xFF;
  32292. file[3] = sfnt.charCodeAt(3) & 0xFF;
  32293. // numTables (2 bytes)
  32294. writeInt16(file, 4, numTables);
  32295. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  32296. // searchRange (2 bytes)
  32297. writeInt16(file, 6, searchParams.range);
  32298. // entrySelector (2 bytes)
  32299. writeInt16(file, 8, searchParams.entry);
  32300. // rangeShift (2 bytes)
  32301. writeInt16(file, 10, searchParams.rangeShift);
  32302. offset = OTF_HEADER_SIZE;
  32303. // writing table entries
  32304. for (i = 0; i < numTables; i++) {
  32305. tableName = tablesNames[i];
  32306. file[offset] = tableName.charCodeAt(0) & 0xFF;
  32307. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  32308. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  32309. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  32310. // checksum
  32311. var checksum = 0;
  32312. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  32313. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  32314. (file[j + 2] << 8) + file[j + 3];
  32315. checksum = (checksum + quad) | 0;
  32316. }
  32317. writeInt32(file, offset + 4, checksum);
  32318. // offset
  32319. writeInt32(file, offset + 8, tableOffsets[i]);
  32320. // length
  32321. writeInt32(file, offset + 12, tables[tableName].length);
  32322. offset += OTF_TABLE_ENTRY_SIZE;
  32323. }
  32324. return file;
  32325. },
  32326. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  32327. if (tag in this.tables) {
  32328. throw new Error('Table ' + tag + ' already exists');
  32329. }
  32330. this.tables[tag] = data;
  32331. }
  32332. };
  32333. return OpenTypeFileBuilder;
  32334. })();
  32335. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  32336. // issues when they are painted on the canvas, e.g. complex-script shaping or
  32337. // control/whitespace characters. The ranges are listed in pairs: the first item
  32338. // is a code of the first problematic code, the second one is the next
  32339. // non-problematic code. The ranges must be in sorted order.
  32340. var ProblematicCharRanges = new Int32Array([
  32341. // Control characters.
  32342. 0x0000, 0x0020,
  32343. 0x007F, 0x00A1,
  32344. 0x00AD, 0x00AE,
  32345. // Chars that is used in complex-script shaping.
  32346. 0x0600, 0x0780,
  32347. 0x08A0, 0x10A0,
  32348. 0x1780, 0x1800,
  32349. // General punctuation chars.
  32350. 0x2000, 0x2010,
  32351. 0x2011, 0x2012,
  32352. 0x2028, 0x2030,
  32353. 0x205F, 0x2070,
  32354. 0x25CC, 0x25CD,
  32355. // Chars that is used in complex-script shaping.
  32356. 0xAA60, 0xAA80,
  32357. // Specials Unicode block.
  32358. 0xFFF0, 0x10000
  32359. ]);
  32360. /**
  32361. * 'Font' is the class the outside world should use, it encapsulate all the font
  32362. * decoding logics whatever type it is (assuming the font type is supported).
  32363. *
  32364. * For example to read a Type1 font and to attach it to the document:
  32365. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  32366. * type1Font.bind();
  32367. */
  32368. var Font = (function FontClosure() {
  32369. function Font(name, file, properties) {
  32370. var charCode, glyphName, fontChar;
  32371. this.name = name;
  32372. this.loadedName = properties.loadedName;
  32373. this.isType3Font = properties.isType3Font;
  32374. this.sizes = [];
  32375. this.glyphCache = {};
  32376. var names = name.split('+');
  32377. names = names.length > 1 ? names[1] : names[0];
  32378. names = names.split(/[-,_]/g)[0];
  32379. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  32380. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  32381. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  32382. var type = properties.type;
  32383. var subtype = properties.subtype;
  32384. this.type = type;
  32385. this.fallbackName = (this.isMonospace ? 'monospace' :
  32386. (this.isSerifFont ? 'serif' : 'sans-serif'));
  32387. this.differences = properties.differences;
  32388. this.widths = properties.widths;
  32389. this.defaultWidth = properties.defaultWidth;
  32390. this.composite = properties.composite;
  32391. this.wideChars = properties.wideChars;
  32392. this.cMap = properties.cMap;
  32393. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  32394. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  32395. this.fontMatrix = properties.fontMatrix;
  32396. this.bbox = properties.bbox;
  32397. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  32398. this.toFontChar = [];
  32399. if (properties.type === 'Type3') {
  32400. for (charCode = 0; charCode < 256; charCode++) {
  32401. this.toFontChar[charCode] = (this.differences[charCode] ||
  32402. properties.defaultEncoding[charCode]);
  32403. }
  32404. this.fontType = FontType.TYPE3;
  32405. return;
  32406. }
  32407. this.cidEncoding = properties.cidEncoding;
  32408. this.vertical = properties.vertical;
  32409. if (this.vertical) {
  32410. this.vmetrics = properties.vmetrics;
  32411. this.defaultVMetrics = properties.defaultVMetrics;
  32412. }
  32413. if (!file || file.isEmpty) {
  32414. if (file) {
  32415. // Some bad PDF generators will include empty font files,
  32416. // attempting to recover by assuming that no file exists.
  32417. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  32418. }
  32419. this.missingFile = true;
  32420. // The file data is not specified. Trying to fix the font name
  32421. // to be used with the canvas.font.
  32422. var fontName = name.replace(/[,_]/g, '-');
  32423. var isStandardFont = !!stdFontMap[fontName] ||
  32424. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  32425. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  32426. this.bold = (fontName.search(/bold/gi) !== -1);
  32427. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  32428. (fontName.search(/italic/gi) !== -1));
  32429. // Use 'name' instead of 'fontName' here because the original
  32430. // name ArialBlack for example will be replaced by Helvetica.
  32431. this.black = (name.search(/Black/g) !== -1);
  32432. // if at least one width is present, remeasure all chars when exists
  32433. this.remeasure = Object.keys(this.widths).length > 0;
  32434. if (isStandardFont && type === 'CIDFontType2' &&
  32435. properties.cidEncoding.indexOf('Identity-') === 0) {
  32436. // Standard fonts might be embedded as CID font without glyph mapping.
  32437. // Building one based on GlyphMapForStandardFonts.
  32438. var map = [];
  32439. for (charCode in GlyphMapForStandardFonts) {
  32440. map[+charCode] = GlyphMapForStandardFonts[charCode];
  32441. }
  32442. if (/ArialBlack/i.test(name)) {
  32443. for (charCode in SupplementalGlyphMapForArialBlack) {
  32444. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  32445. }
  32446. }
  32447. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  32448. if (!isIdentityUnicode) {
  32449. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32450. map[+charCode] = unicodeCharCode;
  32451. });
  32452. }
  32453. this.toFontChar = map;
  32454. this.toUnicode = new ToUnicodeMap(map);
  32455. } else if (/Symbol/i.test(fontName)) {
  32456. var symbols = Encodings.SymbolSetEncoding;
  32457. for (charCode in symbols) {
  32458. fontChar = GlyphsUnicode[symbols[charCode]];
  32459. if (!fontChar) {
  32460. continue;
  32461. }
  32462. this.toFontChar[charCode] = fontChar;
  32463. }
  32464. for (charCode in properties.differences) {
  32465. fontChar = GlyphsUnicode[properties.differences[charCode]];
  32466. if (!fontChar) {
  32467. continue;
  32468. }
  32469. this.toFontChar[charCode] = fontChar;
  32470. }
  32471. } else if (/Dingbats/i.test(fontName)) {
  32472. if (/Wingdings/i.test(name)) {
  32473. warn('Wingdings font without embedded font file, ' +
  32474. 'falling back to the ZapfDingbats encoding.');
  32475. }
  32476. var dingbats = Encodings.ZapfDingbatsEncoding;
  32477. for (charCode in dingbats) {
  32478. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  32479. if (!fontChar) {
  32480. continue;
  32481. }
  32482. this.toFontChar[charCode] = fontChar;
  32483. }
  32484. for (charCode in properties.differences) {
  32485. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  32486. if (!fontChar) {
  32487. continue;
  32488. }
  32489. this.toFontChar[charCode] = fontChar;
  32490. }
  32491. } else if (isStandardFont) {
  32492. this.toFontChar = [];
  32493. for (charCode in properties.defaultEncoding) {
  32494. glyphName = (properties.differences[charCode] ||
  32495. properties.defaultEncoding[charCode]);
  32496. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  32497. }
  32498. } else {
  32499. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  32500. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32501. if (notCidFont) {
  32502. glyphName = (properties.differences[charCode] ||
  32503. properties.defaultEncoding[charCode]);
  32504. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  32505. }
  32506. this.toFontChar[charCode] = unicodeCharCode;
  32507. }.bind(this));
  32508. }
  32509. this.loadedName = fontName.split('-')[0];
  32510. this.loading = false;
  32511. this.fontType = getFontType(type, subtype);
  32512. return;
  32513. }
  32514. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  32515. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  32516. // Some TrueType fonts by mistake claim Type1C
  32517. if (isTrueTypeFile(file)) {
  32518. subtype = 'TrueType';
  32519. } else {
  32520. type = 'Type1';
  32521. }
  32522. }
  32523. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  32524. type = 'CIDFontType0';
  32525. }
  32526. if (subtype === 'OpenType') {
  32527. type = 'OpenType';
  32528. }
  32529. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  32530. if (type === 'CIDFontType0') {
  32531. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  32532. }
  32533. var data;
  32534. switch (type) {
  32535. case 'MMType1':
  32536. info('MMType1 font (' + name + '), falling back to Type1.');
  32537. /* falls through */
  32538. case 'Type1':
  32539. case 'CIDFontType0':
  32540. this.mimetype = 'font/opentype';
  32541. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  32542. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  32543. adjustWidths(properties);
  32544. // Wrap the CFF data inside an OTF font file
  32545. data = this.convert(name, cff, properties);
  32546. break;
  32547. case 'OpenType':
  32548. case 'TrueType':
  32549. case 'CIDFontType2':
  32550. this.mimetype = 'font/opentype';
  32551. // Repair the TrueType file. It is can be damaged in the point of
  32552. // view of the sanitizer
  32553. data = this.checkAndRepair(name, file, properties);
  32554. if (this.isOpenType) {
  32555. adjustWidths(properties);
  32556. type = 'OpenType';
  32557. }
  32558. break;
  32559. default:
  32560. error('Font ' + type + ' is not supported');
  32561. break;
  32562. }
  32563. this.data = data;
  32564. this.fontType = getFontType(type, subtype);
  32565. // Transfer some properties again that could change during font conversion
  32566. this.fontMatrix = properties.fontMatrix;
  32567. this.widths = properties.widths;
  32568. this.defaultWidth = properties.defaultWidth;
  32569. this.encoding = properties.baseEncoding;
  32570. this.seacMap = properties.seacMap;
  32571. this.loading = true;
  32572. }
  32573. Font.getFontID = (function () {
  32574. var ID = 1;
  32575. return function Font_getFontID() {
  32576. return String(ID++);
  32577. };
  32578. })();
  32579. function int16(b0, b1) {
  32580. return (b0 << 8) + b1;
  32581. }
  32582. function int32(b0, b1, b2, b3) {
  32583. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32584. }
  32585. function string16(value) {
  32586. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32587. }
  32588. function safeString16(value) {
  32589. // clamp value to the 16-bit int range
  32590. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  32591. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32592. }
  32593. function isTrueTypeFile(file) {
  32594. var header = file.peekBytes(4);
  32595. return readUint32(header, 0) === 0x00010000;
  32596. }
  32597. function isType1File(file) {
  32598. var header = file.peekBytes(2);
  32599. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  32600. if (header[0] === 0x25 && header[1] === 0x21) {
  32601. return true;
  32602. }
  32603. // ... obviously some fonts violate that part of the specification,
  32604. // please refer to the comment in |Type1Font| below.
  32605. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  32606. return true;
  32607. }
  32608. return false;
  32609. }
  32610. /**
  32611. * Helper function for |adjustMapping|.
  32612. * @return {boolean}
  32613. */
  32614. function isProblematicUnicodeLocation(code) {
  32615. // Using binary search to find a range start.
  32616. var i = 0, j = ProblematicCharRanges.length - 1;
  32617. while (i < j) {
  32618. var c = (i + j + 1) >> 1;
  32619. if (code < ProblematicCharRanges[c]) {
  32620. j = c - 1;
  32621. } else {
  32622. i = c;
  32623. }
  32624. }
  32625. // Even index means code in problematic range.
  32626. return !(i & 1);
  32627. }
  32628. /**
  32629. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  32630. * with their unicode value. It also moves char codes that are in known
  32631. * problematic locations.
  32632. * @return {Object} Two properties:
  32633. * 'toFontChar' - maps original char codes(the value that will be read
  32634. * from commands such as show text) to the char codes that will be used in the
  32635. * font that we build
  32636. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  32637. */
  32638. function adjustMapping(charCodeToGlyphId, properties) {
  32639. var toUnicode = properties.toUnicode;
  32640. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  32641. var isIdentityUnicode =
  32642. properties.toUnicode instanceof IdentityToUnicodeMap;
  32643. var newMap = Object.create(null);
  32644. var toFontChar = [];
  32645. var usedFontCharCodes = [];
  32646. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  32647. for (var originalCharCode in charCodeToGlyphId) {
  32648. originalCharCode |= 0;
  32649. var glyphId = charCodeToGlyphId[originalCharCode];
  32650. var fontCharCode = originalCharCode;
  32651. // First try to map the value to a unicode position if a non identity map
  32652. // was created.
  32653. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  32654. var unicode = toUnicode.get(fontCharCode);
  32655. // TODO: Try to map ligatures to the correct spot.
  32656. if (unicode.length === 1) {
  32657. fontCharCode = unicode.charCodeAt(0);
  32658. }
  32659. }
  32660. // Try to move control characters, special characters and already mapped
  32661. // characters to the private use area since they will not be drawn by
  32662. // canvas if left in their current position. Also, move characters if the
  32663. // font was symbolic and there is only an identity unicode map since the
  32664. // characters probably aren't in the correct position (fixes an issue
  32665. // with firefox and thuluthfont).
  32666. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  32667. isProblematicUnicodeLocation(fontCharCode) ||
  32668. (isSymbolic && isIdentityUnicode)) &&
  32669. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  32670. // Loop to try and find a free spot in the private use area.
  32671. do {
  32672. fontCharCode = nextAvailableFontCharCode++;
  32673. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  32674. fontCharCode = 0xF020;
  32675. nextAvailableFontCharCode = fontCharCode + 1;
  32676. }
  32677. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  32678. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  32679. }
  32680. newMap[fontCharCode] = glyphId;
  32681. toFontChar[originalCharCode] = fontCharCode;
  32682. usedFontCharCodes[fontCharCode] = true;
  32683. }
  32684. return {
  32685. toFontChar: toFontChar,
  32686. charCodeToGlyphId: newMap,
  32687. nextAvailableFontCharCode: nextAvailableFontCharCode
  32688. };
  32689. }
  32690. function getRanges(glyphs, numGlyphs) {
  32691. // Array.sort() sorts by characters, not numerically, so convert to an
  32692. // array of characters.
  32693. var codes = [];
  32694. for (var charCode in glyphs) {
  32695. // Remove an invalid glyph ID mappings to make OTS happy.
  32696. if (glyphs[charCode] >= numGlyphs) {
  32697. continue;
  32698. }
  32699. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  32700. }
  32701. codes.sort(function fontGetRangesSort(a, b) {
  32702. return a.fontCharCode - b.fontCharCode;
  32703. });
  32704. // Split the sorted codes into ranges.
  32705. var ranges = [];
  32706. var length = codes.length;
  32707. for (var n = 0; n < length; ) {
  32708. var start = codes[n].fontCharCode;
  32709. var codeIndices = [codes[n].glyphId];
  32710. ++n;
  32711. var end = start;
  32712. while (n < length && end + 1 === codes[n].fontCharCode) {
  32713. codeIndices.push(codes[n].glyphId);
  32714. ++end;
  32715. ++n;
  32716. if (end === 0xFFFF) {
  32717. break;
  32718. }
  32719. }
  32720. ranges.push([start, end, codeIndices]);
  32721. }
  32722. return ranges;
  32723. }
  32724. function createCmapTable(glyphs, numGlyphs) {
  32725. var ranges = getRanges(glyphs, numGlyphs);
  32726. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  32727. var cmap = '\x00\x00' + // version
  32728. string16(numTables) + // numTables
  32729. '\x00\x03' + // platformID
  32730. '\x00\x01' + // encodingID
  32731. string32(4 + numTables * 8); // start of the table record
  32732. var i, ii, j, jj;
  32733. for (i = ranges.length - 1; i >= 0; --i) {
  32734. if (ranges[i][0] <= 0xFFFF) { break; }
  32735. }
  32736. var bmpLength = i + 1;
  32737. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  32738. ranges[i][1] = 0xFFFE;
  32739. }
  32740. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  32741. var segCount = bmpLength + trailingRangesCount;
  32742. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  32743. // Fill up the 4 parallel arrays describing the segments.
  32744. var startCount = '';
  32745. var endCount = '';
  32746. var idDeltas = '';
  32747. var idRangeOffsets = '';
  32748. var glyphsIds = '';
  32749. var bias = 0;
  32750. var range, start, end, codes;
  32751. for (i = 0, ii = bmpLength; i < ii; i++) {
  32752. range = ranges[i];
  32753. start = range[0];
  32754. end = range[1];
  32755. startCount += string16(start);
  32756. endCount += string16(end);
  32757. codes = range[2];
  32758. var contiguous = true;
  32759. for (j = 1, jj = codes.length; j < jj; ++j) {
  32760. if (codes[j] !== codes[j - 1] + 1) {
  32761. contiguous = false;
  32762. break;
  32763. }
  32764. }
  32765. if (!contiguous) {
  32766. var offset = (segCount - i) * 2 + bias * 2;
  32767. bias += (end - start + 1);
  32768. idDeltas += string16(0);
  32769. idRangeOffsets += string16(offset);
  32770. for (j = 0, jj = codes.length; j < jj; ++j) {
  32771. glyphsIds += string16(codes[j]);
  32772. }
  32773. } else {
  32774. var startCode = codes[0];
  32775. idDeltas += string16((startCode - start) & 0xFFFF);
  32776. idRangeOffsets += string16(0);
  32777. }
  32778. }
  32779. if (trailingRangesCount > 0) {
  32780. endCount += '\xFF\xFF';
  32781. startCount += '\xFF\xFF';
  32782. idDeltas += '\x00\x01';
  32783. idRangeOffsets += '\x00\x00';
  32784. }
  32785. var format314 = '\x00\x00' + // language
  32786. string16(2 * segCount) +
  32787. string16(searchParams.range) +
  32788. string16(searchParams.entry) +
  32789. string16(searchParams.rangeShift) +
  32790. endCount + '\x00\x00' + startCount +
  32791. idDeltas + idRangeOffsets + glyphsIds;
  32792. var format31012 = '';
  32793. var header31012 = '';
  32794. if (numTables > 1) {
  32795. cmap += '\x00\x03' + // platformID
  32796. '\x00\x0A' + // encodingID
  32797. string32(4 + numTables * 8 +
  32798. 4 + format314.length); // start of the table record
  32799. format31012 = '';
  32800. for (i = 0, ii = ranges.length; i < ii; i++) {
  32801. range = ranges[i];
  32802. start = range[0];
  32803. codes = range[2];
  32804. var code = codes[0];
  32805. for (j = 1, jj = codes.length; j < jj; ++j) {
  32806. if (codes[j] !== codes[j - 1] + 1) {
  32807. end = range[0] + j - 1;
  32808. format31012 += string32(start) + // startCharCode
  32809. string32(end) + // endCharCode
  32810. string32(code); // startGlyphID
  32811. start = end + 1;
  32812. code = codes[j];
  32813. }
  32814. }
  32815. format31012 += string32(start) + // startCharCode
  32816. string32(range[1]) + // endCharCode
  32817. string32(code); // startGlyphID
  32818. }
  32819. header31012 = '\x00\x0C' + // format
  32820. '\x00\x00' + // reserved
  32821. string32(format31012.length + 16) + // length
  32822. '\x00\x00\x00\x00' + // language
  32823. string32(format31012.length / 12); // nGroups
  32824. }
  32825. return cmap + '\x00\x04' + // format
  32826. string16(format314.length + 4) + // length
  32827. format314 + header31012 + format31012;
  32828. }
  32829. function validateOS2Table(os2) {
  32830. var stream = new Stream(os2.data);
  32831. var version = stream.getUint16();
  32832. // TODO verify all OS/2 tables fields, but currently we validate only those
  32833. // that give us issues
  32834. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  32835. var selection = stream.getUint16();
  32836. if (version < 4 && (selection & 0x0300)) {
  32837. return false;
  32838. }
  32839. var firstChar = stream.getUint16();
  32840. var lastChar = stream.getUint16();
  32841. if (firstChar > lastChar) {
  32842. return false;
  32843. }
  32844. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  32845. var usWinAscent = stream.getUint16();
  32846. if (usWinAscent === 0) { // makes font unreadable by windows
  32847. return false;
  32848. }
  32849. // OS/2 appears to be valid, resetting some fields
  32850. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  32851. return true;
  32852. }
  32853. function createOS2Table(properties, charstrings, override) {
  32854. override = override || {
  32855. unitsPerEm: 0,
  32856. yMax: 0,
  32857. yMin: 0,
  32858. ascent: 0,
  32859. descent: 0
  32860. };
  32861. var ulUnicodeRange1 = 0;
  32862. var ulUnicodeRange2 = 0;
  32863. var ulUnicodeRange3 = 0;
  32864. var ulUnicodeRange4 = 0;
  32865. var firstCharIndex = null;
  32866. var lastCharIndex = 0;
  32867. if (charstrings) {
  32868. for (var code in charstrings) {
  32869. code |= 0;
  32870. if (firstCharIndex > code || !firstCharIndex) {
  32871. firstCharIndex = code;
  32872. }
  32873. if (lastCharIndex < code) {
  32874. lastCharIndex = code;
  32875. }
  32876. var position = getUnicodeRangeFor(code);
  32877. if (position < 32) {
  32878. ulUnicodeRange1 |= 1 << position;
  32879. } else if (position < 64) {
  32880. ulUnicodeRange2 |= 1 << position - 32;
  32881. } else if (position < 96) {
  32882. ulUnicodeRange3 |= 1 << position - 64;
  32883. } else if (position < 123) {
  32884. ulUnicodeRange4 |= 1 << position - 96;
  32885. } else {
  32886. error('Unicode ranges Bits > 123 are reserved for internal usage');
  32887. }
  32888. }
  32889. } else {
  32890. // TODO
  32891. firstCharIndex = 0;
  32892. lastCharIndex = 255;
  32893. }
  32894. var bbox = properties.bbox || [0, 0, 0, 0];
  32895. var unitsPerEm = (override.unitsPerEm ||
  32896. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  32897. // if the font units differ to the PDF glyph space units
  32898. // then scale up the values
  32899. var scale = (properties.ascentScaled ? 1.0 :
  32900. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  32901. var typoAscent = (override.ascent ||
  32902. Math.round(scale * (properties.ascent || bbox[3])));
  32903. var typoDescent = (override.descent ||
  32904. Math.round(scale * (properties.descent || bbox[1])));
  32905. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  32906. typoDescent = -typoDescent; // fixing incorrect descent
  32907. }
  32908. var winAscent = override.yMax || typoAscent;
  32909. var winDescent = -override.yMin || -typoDescent;
  32910. return '\x00\x03' + // version
  32911. '\x02\x24' + // xAvgCharWidth
  32912. '\x01\xF4' + // usWeightClass
  32913. '\x00\x05' + // usWidthClass
  32914. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  32915. '\x02\x8A' + // ySubscriptXSize
  32916. '\x02\xBB' + // ySubscriptYSize
  32917. '\x00\x00' + // ySubscriptXOffset
  32918. '\x00\x8C' + // ySubscriptYOffset
  32919. '\x02\x8A' + // ySuperScriptXSize
  32920. '\x02\xBB' + // ySuperScriptYSize
  32921. '\x00\x00' + // ySuperScriptXOffset
  32922. '\x01\xDF' + // ySuperScriptYOffset
  32923. '\x00\x31' + // yStrikeOutSize
  32924. '\x01\x02' + // yStrikeOutPosition
  32925. '\x00\x00' + // sFamilyClass
  32926. '\x00\x00\x06' +
  32927. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  32928. '\x00\x00\x00\x00\x00\x00' + // Panose
  32929. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  32930. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  32931. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  32932. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  32933. '\x2A\x32\x31\x2A' + // achVendID
  32934. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  32935. string16(firstCharIndex ||
  32936. properties.firstChar) + // usFirstCharIndex
  32937. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  32938. string16(typoAscent) + // sTypoAscender
  32939. string16(typoDescent) + // sTypoDescender
  32940. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  32941. string16(winAscent) + // usWinAscent
  32942. string16(winDescent) + // usWinDescent
  32943. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  32944. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  32945. string16(properties.xHeight) + // sxHeight
  32946. string16(properties.capHeight) + // sCapHeight
  32947. string16(0) + // usDefaultChar
  32948. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  32949. '\x00\x03'; // usMaxContext
  32950. }
  32951. function createPostTable(properties) {
  32952. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  32953. return ('\x00\x03\x00\x00' + // Version number
  32954. string32(angle) + // italicAngle
  32955. '\x00\x00' + // underlinePosition
  32956. '\x00\x00' + // underlineThickness
  32957. string32(properties.fixedPitch) + // isFixedPitch
  32958. '\x00\x00\x00\x00' + // minMemType42
  32959. '\x00\x00\x00\x00' + // maxMemType42
  32960. '\x00\x00\x00\x00' + // minMemType1
  32961. '\x00\x00\x00\x00'); // maxMemType1
  32962. }
  32963. function createNameTable(name, proto) {
  32964. if (!proto) {
  32965. proto = [[], []]; // no strings and unicode strings
  32966. }
  32967. var strings = [
  32968. proto[0][0] || 'Original licence', // 0.Copyright
  32969. proto[0][1] || name, // 1.Font family
  32970. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  32971. proto[0][3] || 'uniqueID', // 3.Unique ID
  32972. proto[0][4] || name, // 4.Full font name
  32973. proto[0][5] || 'Version 0.11', // 5.Version
  32974. proto[0][6] || '', // 6.Postscript name
  32975. proto[0][7] || 'Unknown', // 7.Trademark
  32976. proto[0][8] || 'Unknown', // 8.Manufacturer
  32977. proto[0][9] || 'Unknown' // 9.Designer
  32978. ];
  32979. // Mac want 1-byte per character strings while Windows want
  32980. // 2-bytes per character, so duplicate the names table
  32981. var stringsUnicode = [];
  32982. var i, ii, j, jj, str;
  32983. for (i = 0, ii = strings.length; i < ii; i++) {
  32984. str = proto[1][i] || strings[i];
  32985. var strBufUnicode = [];
  32986. for (j = 0, jj = str.length; j < jj; j++) {
  32987. strBufUnicode.push(string16(str.charCodeAt(j)));
  32988. }
  32989. stringsUnicode.push(strBufUnicode.join(''));
  32990. }
  32991. var names = [strings, stringsUnicode];
  32992. var platforms = ['\x00\x01', '\x00\x03'];
  32993. var encodings = ['\x00\x00', '\x00\x01'];
  32994. var languages = ['\x00\x00', '\x04\x09'];
  32995. var namesRecordCount = strings.length * platforms.length;
  32996. var nameTable =
  32997. '\x00\x00' + // format
  32998. string16(namesRecordCount) + // Number of names Record
  32999. string16(namesRecordCount * 12 + 6); // Storage
  33000. // Build the name records field
  33001. var strOffset = 0;
  33002. for (i = 0, ii = platforms.length; i < ii; i++) {
  33003. var strs = names[i];
  33004. for (j = 0, jj = strs.length; j < jj; j++) {
  33005. str = strs[j];
  33006. var nameRecord =
  33007. platforms[i] + // platform ID
  33008. encodings[i] + // encoding ID
  33009. languages[i] + // language ID
  33010. string16(j) + // name ID
  33011. string16(str.length) +
  33012. string16(strOffset);
  33013. nameTable += nameRecord;
  33014. strOffset += str.length;
  33015. }
  33016. }
  33017. nameTable += strings.join('') + stringsUnicode.join('');
  33018. return nameTable;
  33019. }
  33020. Font.prototype = {
  33021. name: null,
  33022. font: null,
  33023. mimetype: null,
  33024. encoding: null,
  33025. get renderer() {
  33026. var renderer = FontRendererFactory.create(this);
  33027. return shadow(this, 'renderer', renderer);
  33028. },
  33029. exportData: function Font_exportData() {
  33030. var data = {};
  33031. for (var i in this) {
  33032. if (this.hasOwnProperty(i)) {
  33033. data[i] = this[i];
  33034. }
  33035. }
  33036. return data;
  33037. },
  33038. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  33039. function readTableEntry(file) {
  33040. var tag = bytesToString(file.getBytes(4));
  33041. var checksum = file.getInt32();
  33042. var offset = file.getInt32() >>> 0;
  33043. var length = file.getInt32() >>> 0;
  33044. // Read the table associated data
  33045. var previousPosition = file.pos;
  33046. file.pos = file.start ? file.start : 0;
  33047. file.skip(offset);
  33048. var data = file.getBytes(length);
  33049. file.pos = previousPosition;
  33050. if (tag === 'head') {
  33051. // clearing checksum adjustment
  33052. data[8] = data[9] = data[10] = data[11] = 0;
  33053. data[17] |= 0x20; //Set font optimized for cleartype flag
  33054. }
  33055. return {
  33056. tag: tag,
  33057. checksum: checksum,
  33058. length: length,
  33059. offset: offset,
  33060. data: data
  33061. };
  33062. }
  33063. function readOpenTypeHeader(ttf) {
  33064. return {
  33065. version: bytesToString(ttf.getBytes(4)),
  33066. numTables: ttf.getUint16(),
  33067. searchRange: ttf.getUint16(),
  33068. entrySelector: ttf.getUint16(),
  33069. rangeShift: ttf.getUint16()
  33070. };
  33071. }
  33072. /**
  33073. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  33074. * PDF spec
  33075. */
  33076. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  33077. if (!cmap) {
  33078. warn('No cmap table available.');
  33079. return {
  33080. platformId: -1,
  33081. encodingId: -1,
  33082. mappings: [],
  33083. hasShortCmap: false
  33084. };
  33085. }
  33086. var segment;
  33087. var start = (font.start ? font.start : 0) + cmap.offset;
  33088. font.pos = start;
  33089. var version = font.getUint16();
  33090. var numTables = font.getUint16();
  33091. var potentialTable;
  33092. var canBreak = false;
  33093. // There's an order of preference in terms of which cmap subtable to
  33094. // use:
  33095. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  33096. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  33097. // The following takes advantage of the fact that the tables are sorted
  33098. // to work.
  33099. for (var i = 0; i < numTables; i++) {
  33100. var platformId = font.getUint16();
  33101. var encodingId = font.getUint16();
  33102. var offset = font.getInt32() >>> 0;
  33103. var useTable = false;
  33104. if (platformId === 0 && encodingId === 0) {
  33105. useTable = true;
  33106. // Continue the loop since there still may be a higher priority
  33107. // table.
  33108. } else if (platformId === 1 && encodingId === 0) {
  33109. useTable = true;
  33110. // Continue the loop since there still may be a higher priority
  33111. // table.
  33112. } else if (platformId === 3 && encodingId === 1 &&
  33113. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  33114. useTable = true;
  33115. if (!isSymbolicFont) {
  33116. canBreak = true;
  33117. }
  33118. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  33119. useTable = true;
  33120. canBreak = true;
  33121. }
  33122. if (useTable) {
  33123. potentialTable = {
  33124. platformId: platformId,
  33125. encodingId: encodingId,
  33126. offset: offset
  33127. };
  33128. }
  33129. if (canBreak) {
  33130. break;
  33131. }
  33132. }
  33133. if (potentialTable) {
  33134. font.pos = start + potentialTable.offset;
  33135. }
  33136. if (!potentialTable || font.peekByte() === -1) {
  33137. warn('Could not find a preferred cmap table.');
  33138. return {
  33139. platformId: -1,
  33140. encodingId: -1,
  33141. mappings: [],
  33142. hasShortCmap: false
  33143. };
  33144. }
  33145. var format = font.getUint16();
  33146. var length = font.getUint16();
  33147. var language = font.getUint16();
  33148. var hasShortCmap = false;
  33149. var mappings = [];
  33150. var j, glyphId;
  33151. // TODO(mack): refactor this cmap subtable reading logic out
  33152. if (format === 0) {
  33153. for (j = 0; j < 256; j++) {
  33154. var index = font.getByte();
  33155. if (!index) {
  33156. continue;
  33157. }
  33158. mappings.push({
  33159. charCode: j,
  33160. glyphId: index
  33161. });
  33162. }
  33163. hasShortCmap = true;
  33164. } else if (format === 4) {
  33165. // re-creating the table in format 4 since the encoding
  33166. // might be changed
  33167. var segCount = (font.getUint16() >> 1);
  33168. font.getBytes(6); // skipping range fields
  33169. var segIndex, segments = [];
  33170. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33171. segments.push({ end: font.getUint16() });
  33172. }
  33173. font.getUint16();
  33174. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33175. segments[segIndex].start = font.getUint16();
  33176. }
  33177. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33178. segments[segIndex].delta = font.getUint16();
  33179. }
  33180. var offsetsCount = 0;
  33181. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33182. segment = segments[segIndex];
  33183. var rangeOffset = font.getUint16();
  33184. if (!rangeOffset) {
  33185. segment.offsetIndex = -1;
  33186. continue;
  33187. }
  33188. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  33189. segment.offsetIndex = offsetIndex;
  33190. offsetsCount = Math.max(offsetsCount, offsetIndex +
  33191. segment.end - segment.start + 1);
  33192. }
  33193. var offsets = [];
  33194. for (j = 0; j < offsetsCount; j++) {
  33195. offsets.push(font.getUint16());
  33196. }
  33197. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33198. segment = segments[segIndex];
  33199. start = segment.start;
  33200. var end = segment.end;
  33201. var delta = segment.delta;
  33202. offsetIndex = segment.offsetIndex;
  33203. for (j = start; j <= end; j++) {
  33204. if (j === 0xFFFF) {
  33205. continue;
  33206. }
  33207. glyphId = (offsetIndex < 0 ?
  33208. j : offsets[offsetIndex + j - start]);
  33209. glyphId = (glyphId + delta) & 0xFFFF;
  33210. if (glyphId === 0) {
  33211. continue;
  33212. }
  33213. mappings.push({
  33214. charCode: j,
  33215. glyphId: glyphId
  33216. });
  33217. }
  33218. }
  33219. } else if (format === 6) {
  33220. // Format 6 is a 2-bytes dense mapping, which means the font data
  33221. // lives glue together even if they are pretty far in the unicode
  33222. // table. (This looks weird, so I can have missed something), this
  33223. // works on Linux but seems to fails on Mac so let's rewrite the
  33224. // cmap table to a 3-1-4 style
  33225. var firstCode = font.getUint16();
  33226. var entryCount = font.getUint16();
  33227. for (j = 0; j < entryCount; j++) {
  33228. glyphId = font.getUint16();
  33229. var charCode = firstCode + j;
  33230. mappings.push({
  33231. charCode: charCode,
  33232. glyphId: glyphId
  33233. });
  33234. }
  33235. } else {
  33236. warn('cmap table has unsupported format: ' + format);
  33237. return {
  33238. platformId: -1,
  33239. encodingId: -1,
  33240. mappings: [],
  33241. hasShortCmap: false
  33242. };
  33243. }
  33244. // removing duplicate entries
  33245. mappings.sort(function (a, b) {
  33246. return a.charCode - b.charCode;
  33247. });
  33248. for (i = 1; i < mappings.length; i++) {
  33249. if (mappings[i - 1].charCode === mappings[i].charCode) {
  33250. mappings.splice(i, 1);
  33251. i--;
  33252. }
  33253. }
  33254. return {
  33255. platformId: potentialTable.platformId,
  33256. encodingId: potentialTable.encodingId,
  33257. mappings: mappings,
  33258. hasShortCmap: hasShortCmap
  33259. };
  33260. }
  33261. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  33262. if (!header) {
  33263. if (metrics) {
  33264. metrics.data = null;
  33265. }
  33266. return;
  33267. }
  33268. font.pos = (font.start ? font.start : 0) + header.offset;
  33269. font.pos += header.length - 2;
  33270. var numOfMetrics = font.getUint16();
  33271. if (numOfMetrics > numGlyphs) {
  33272. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  33273. 'greater than the numGlyphs (' + numGlyphs + ')');
  33274. // Reduce numOfMetrics if it is greater than numGlyphs
  33275. numOfMetrics = numGlyphs;
  33276. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  33277. header.data[35] = numOfMetrics & 0x00ff;
  33278. }
  33279. var numOfSidebearings = numGlyphs - numOfMetrics;
  33280. var numMissing = numOfSidebearings -
  33281. ((metrics.length - numOfMetrics * 4) >> 1);
  33282. if (numMissing > 0) {
  33283. // For each missing glyph, we set both the width and lsb to 0 (zero).
  33284. // Since we need to add two properties for each glyph, this explains
  33285. // the use of |numMissing * 2| when initializing the typed array.
  33286. var entries = new Uint8Array(metrics.length + numMissing * 2);
  33287. entries.set(metrics.data);
  33288. metrics.data = entries;
  33289. }
  33290. }
  33291. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  33292. hintsValid) {
  33293. if (sourceEnd - sourceStart <= 12) {
  33294. // glyph with data less than 12 is invalid one
  33295. return 0;
  33296. }
  33297. var glyf = source.subarray(sourceStart, sourceEnd);
  33298. var contoursCount = (glyf[0] << 8) | glyf[1];
  33299. if (contoursCount & 0x8000) {
  33300. // complex glyph, writing as is
  33301. dest.set(glyf, destStart);
  33302. return glyf.length;
  33303. }
  33304. var i, j = 10, flagsCount = 0;
  33305. for (i = 0; i < contoursCount; i++) {
  33306. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  33307. flagsCount = endPoint + 1;
  33308. j += 2;
  33309. }
  33310. // skipping instructions
  33311. var instructionsStart = j;
  33312. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  33313. j += 2 + instructionsLength;
  33314. var instructionsEnd = j;
  33315. // validating flags
  33316. var coordinatesLength = 0;
  33317. for (i = 0; i < flagsCount; i++) {
  33318. var flag = glyf[j++];
  33319. if (flag & 0xC0) {
  33320. // reserved flags must be zero, cleaning up
  33321. glyf[j - 1] = flag & 0x3F;
  33322. }
  33323. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  33324. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  33325. coordinatesLength += xyLength;
  33326. if (flag & 8) {
  33327. var repeat = glyf[j++];
  33328. i += repeat;
  33329. coordinatesLength += repeat * xyLength;
  33330. }
  33331. }
  33332. // glyph without coordinates will be rejected
  33333. if (coordinatesLength === 0) {
  33334. return 0;
  33335. }
  33336. var glyphDataLength = j + coordinatesLength;
  33337. if (glyphDataLength > glyf.length) {
  33338. // not enough data for coordinates
  33339. return 0;
  33340. }
  33341. if (!hintsValid && instructionsLength > 0) {
  33342. dest.set(glyf.subarray(0, instructionsStart), destStart);
  33343. dest.set([0, 0], destStart + instructionsStart);
  33344. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  33345. destStart + instructionsStart + 2);
  33346. glyphDataLength -= instructionsLength;
  33347. if (glyf.length - glyphDataLength > 3) {
  33348. glyphDataLength = (glyphDataLength + 3) & ~3;
  33349. }
  33350. return glyphDataLength;
  33351. }
  33352. if (glyf.length - glyphDataLength > 3) {
  33353. // truncating and aligning to 4 bytes the long glyph data
  33354. glyphDataLength = (glyphDataLength + 3) & ~3;
  33355. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  33356. return glyphDataLength;
  33357. }
  33358. // glyph data is fine
  33359. dest.set(glyf, destStart);
  33360. return glyf.length;
  33361. }
  33362. function sanitizeHead(head, numGlyphs, locaLength) {
  33363. var data = head.data;
  33364. // Validate version:
  33365. // Should always be 0x00010000
  33366. var version = int32(data[0], data[1], data[2], data[3]);
  33367. if (version >> 16 !== 1) {
  33368. info('Attempting to fix invalid version in head table: ' + version);
  33369. data[0] = 0;
  33370. data[1] = 1;
  33371. data[2] = 0;
  33372. data[3] = 0;
  33373. }
  33374. var indexToLocFormat = int16(data[50], data[51]);
  33375. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  33376. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  33377. indexToLocFormat);
  33378. // The value of indexToLocFormat should be 0 if the loca table
  33379. // consists of short offsets, and should be 1 if the loca table
  33380. // consists of long offsets.
  33381. //
  33382. // The number of entries in the loca table should be numGlyphs + 1.
  33383. //
  33384. // Using this information, we can work backwards to deduce if the
  33385. // size of each offset in the loca table, and thus figure out the
  33386. // appropriate value for indexToLocFormat.
  33387. var numGlyphsPlusOne = numGlyphs + 1;
  33388. if (locaLength === numGlyphsPlusOne << 1) {
  33389. // 0x0000 indicates the loca table consists of short offsets
  33390. data[50] = 0;
  33391. data[51] = 0;
  33392. } else if (locaLength === numGlyphsPlusOne << 2) {
  33393. // 0x0001 indicates the loca table consists of long offsets
  33394. data[50] = 0;
  33395. data[51] = 1;
  33396. } else {
  33397. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  33398. }
  33399. }
  33400. }
  33401. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  33402. isGlyphLocationsLong, hintsValid,
  33403. dupFirstEntry) {
  33404. var itemSize, itemDecode, itemEncode;
  33405. if (isGlyphLocationsLong) {
  33406. itemSize = 4;
  33407. itemDecode = function fontItemDecodeLong(data, offset) {
  33408. return (data[offset] << 24) | (data[offset + 1] << 16) |
  33409. (data[offset + 2] << 8) | data[offset + 3];
  33410. };
  33411. itemEncode = function fontItemEncodeLong(data, offset, value) {
  33412. data[offset] = (value >>> 24) & 0xFF;
  33413. data[offset + 1] = (value >> 16) & 0xFF;
  33414. data[offset + 2] = (value >> 8) & 0xFF;
  33415. data[offset + 3] = value & 0xFF;
  33416. };
  33417. } else {
  33418. itemSize = 2;
  33419. itemDecode = function fontItemDecode(data, offset) {
  33420. return (data[offset] << 9) | (data[offset + 1] << 1);
  33421. };
  33422. itemEncode = function fontItemEncode(data, offset, value) {
  33423. data[offset] = (value >> 9) & 0xFF;
  33424. data[offset + 1] = (value >> 1) & 0xFF;
  33425. };
  33426. }
  33427. var locaData = loca.data;
  33428. var locaDataSize = itemSize * (1 + numGlyphs);
  33429. // is loca.data too short or long?
  33430. if (locaData.length !== locaDataSize) {
  33431. locaData = new Uint8Array(locaDataSize);
  33432. locaData.set(loca.data.subarray(0, locaDataSize));
  33433. loca.data = locaData;
  33434. }
  33435. // removing the invalid glyphs
  33436. var oldGlyfData = glyf.data;
  33437. var oldGlyfDataLength = oldGlyfData.length;
  33438. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  33439. var startOffset = itemDecode(locaData, 0);
  33440. var writeOffset = 0;
  33441. var missingGlyphData = {};
  33442. itemEncode(locaData, 0, writeOffset);
  33443. var i, j;
  33444. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33445. var endOffset = itemDecode(locaData, j);
  33446. if (endOffset > oldGlyfDataLength &&
  33447. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  33448. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  33449. // the glyf table size, which makes last glyph out of range.
  33450. endOffset = oldGlyfDataLength;
  33451. }
  33452. if (endOffset > oldGlyfDataLength) {
  33453. // glyph end offset points outside glyf data, rejecting the glyph
  33454. itemEncode(locaData, j, writeOffset);
  33455. startOffset = endOffset;
  33456. continue;
  33457. }
  33458. if (startOffset === endOffset) {
  33459. missingGlyphData[i] = true;
  33460. }
  33461. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  33462. newGlyfData, writeOffset, hintsValid);
  33463. writeOffset += newLength;
  33464. itemEncode(locaData, j, writeOffset);
  33465. startOffset = endOffset;
  33466. }
  33467. if (writeOffset === 0) {
  33468. // glyf table cannot be empty -- redoing the glyf and loca tables
  33469. // to have single glyph with one point
  33470. var simpleGlyph = new Uint8Array(
  33471. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  33472. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33473. itemEncode(locaData, j, simpleGlyph.length);
  33474. }
  33475. glyf.data = simpleGlyph;
  33476. return missingGlyphData;
  33477. }
  33478. if (dupFirstEntry) {
  33479. var firstEntryLength = itemDecode(locaData, itemSize);
  33480. if (newGlyfData.length > firstEntryLength + writeOffset) {
  33481. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  33482. } else {
  33483. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  33484. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  33485. }
  33486. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  33487. itemEncode(loca.data, locaData.length - itemSize,
  33488. writeOffset + firstEntryLength);
  33489. } else {
  33490. glyf.data = newGlyfData.subarray(0, writeOffset);
  33491. }
  33492. return missingGlyphData;
  33493. }
  33494. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  33495. var start = (font.start ? font.start : 0) + post.offset;
  33496. font.pos = start;
  33497. var length = post.length, end = start + length;
  33498. var version = font.getInt32();
  33499. // skip rest to the tables
  33500. font.getBytes(28);
  33501. var glyphNames;
  33502. var valid = true;
  33503. var i;
  33504. switch (version) {
  33505. case 0x00010000:
  33506. glyphNames = MacStandardGlyphOrdering;
  33507. break;
  33508. case 0x00020000:
  33509. var numGlyphs = font.getUint16();
  33510. if (numGlyphs !== maxpNumGlyphs) {
  33511. valid = false;
  33512. break;
  33513. }
  33514. var glyphNameIndexes = [];
  33515. for (i = 0; i < numGlyphs; ++i) {
  33516. var index = font.getUint16();
  33517. if (index >= 32768) {
  33518. valid = false;
  33519. break;
  33520. }
  33521. glyphNameIndexes.push(index);
  33522. }
  33523. if (!valid) {
  33524. break;
  33525. }
  33526. var customNames = [];
  33527. var strBuf = [];
  33528. while (font.pos < end) {
  33529. var stringLength = font.getByte();
  33530. strBuf.length = stringLength;
  33531. for (i = 0; i < stringLength; ++i) {
  33532. strBuf[i] = String.fromCharCode(font.getByte());
  33533. }
  33534. customNames.push(strBuf.join(''));
  33535. }
  33536. glyphNames = [];
  33537. for (i = 0; i < numGlyphs; ++i) {
  33538. var j = glyphNameIndexes[i];
  33539. if (j < 258) {
  33540. glyphNames.push(MacStandardGlyphOrdering[j]);
  33541. continue;
  33542. }
  33543. glyphNames.push(customNames[j - 258]);
  33544. }
  33545. break;
  33546. case 0x00030000:
  33547. break;
  33548. default:
  33549. warn('Unknown/unsupported post table version ' + version);
  33550. valid = false;
  33551. if (properties.defaultEncoding) {
  33552. glyphNames = properties.defaultEncoding;
  33553. }
  33554. break;
  33555. }
  33556. properties.glyphNames = glyphNames;
  33557. return valid;
  33558. }
  33559. function readNameTable(nameTable) {
  33560. var start = (font.start ? font.start : 0) + nameTable.offset;
  33561. font.pos = start;
  33562. var names = [[], []];
  33563. var length = nameTable.length, end = start + length;
  33564. var format = font.getUint16();
  33565. var FORMAT_0_HEADER_LENGTH = 6;
  33566. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  33567. // unsupported name table format or table "too" small
  33568. return names;
  33569. }
  33570. var numRecords = font.getUint16();
  33571. var stringsStart = font.getUint16();
  33572. var records = [];
  33573. var NAME_RECORD_LENGTH = 12;
  33574. var i, ii;
  33575. for (i = 0; i < numRecords &&
  33576. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  33577. var r = {
  33578. platform: font.getUint16(),
  33579. encoding: font.getUint16(),
  33580. language: font.getUint16(),
  33581. name: font.getUint16(),
  33582. length: font.getUint16(),
  33583. offset: font.getUint16()
  33584. };
  33585. // using only Macintosh and Windows platform/encoding names
  33586. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  33587. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  33588. records.push(r);
  33589. }
  33590. }
  33591. for (i = 0, ii = records.length; i < ii; i++) {
  33592. var record = records[i];
  33593. var pos = start + stringsStart + record.offset;
  33594. if (pos + record.length > end) {
  33595. continue; // outside of name table, ignoring
  33596. }
  33597. font.pos = pos;
  33598. var nameIndex = record.name;
  33599. if (record.encoding) {
  33600. // unicode
  33601. var str = '';
  33602. for (var j = 0, jj = record.length; j < jj; j += 2) {
  33603. str += String.fromCharCode(font.getUint16());
  33604. }
  33605. names[1][nameIndex] = str;
  33606. } else {
  33607. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  33608. }
  33609. }
  33610. return names;
  33611. }
  33612. var TTOpsStackDeltas = [
  33613. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  33614. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  33615. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  33616. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  33617. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  33618. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  33619. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33620. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  33621. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  33622. // 0xC0-DF == -1 and 0xE0-FF == -2
  33623. function sanitizeTTProgram(table, ttContext) {
  33624. var data = table.data;
  33625. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  33626. var stack = [];
  33627. var callstack = [];
  33628. var functionsCalled = [];
  33629. var tooComplexToFollowFunctions =
  33630. ttContext.tooComplexToFollowFunctions;
  33631. var inFDEF = false, ifLevel = 0, inELSE = 0;
  33632. for (var ii = data.length; i < ii;) {
  33633. var op = data[i++];
  33634. // The TrueType instruction set docs can be found at
  33635. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  33636. if (op === 0x40) { // NPUSHB - pushes n bytes
  33637. n = data[i++];
  33638. if (inFDEF || inELSE) {
  33639. i += n;
  33640. } else {
  33641. for (j = 0; j < n; j++) {
  33642. stack.push(data[i++]);
  33643. }
  33644. }
  33645. } else if (op === 0x41) { // NPUSHW - pushes n words
  33646. n = data[i++];
  33647. if (inFDEF || inELSE) {
  33648. i += n * 2;
  33649. } else {
  33650. for (j = 0; j < n; j++) {
  33651. b = data[i++];
  33652. stack.push((b << 8) | data[i++]);
  33653. }
  33654. }
  33655. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  33656. n = op - 0xB0 + 1;
  33657. if (inFDEF || inELSE) {
  33658. i += n;
  33659. } else {
  33660. for (j = 0; j < n; j++) {
  33661. stack.push(data[i++]);
  33662. }
  33663. }
  33664. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  33665. n = op - 0xB8 + 1;
  33666. if (inFDEF || inELSE) {
  33667. i += n * 2;
  33668. } else {
  33669. for (j = 0; j < n; j++) {
  33670. b = data[i++];
  33671. stack.push((b << 8) | data[i++]);
  33672. }
  33673. }
  33674. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  33675. if (!inFDEF && !inELSE) {
  33676. // collecting inforamtion about which functions are used
  33677. funcId = stack[stack.length - 1];
  33678. ttContext.functionsUsed[funcId] = true;
  33679. if (funcId in ttContext.functionsStackDeltas) {
  33680. stack.length += ttContext.functionsStackDeltas[funcId];
  33681. } else if (funcId in ttContext.functionsDefined &&
  33682. functionsCalled.indexOf(funcId) < 0) {
  33683. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  33684. functionsCalled.push(funcId);
  33685. pc = ttContext.functionsDefined[funcId];
  33686. if (!pc) {
  33687. warn('TT: CALL non-existent function');
  33688. ttContext.hintsValid = false;
  33689. return;
  33690. }
  33691. data = pc.data;
  33692. i = pc.i;
  33693. }
  33694. }
  33695. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  33696. if (inFDEF || inELSE) {
  33697. warn('TT: nested FDEFs not allowed');
  33698. tooComplexToFollowFunctions = true;
  33699. }
  33700. inFDEF = true;
  33701. // collecting inforamtion about which functions are defined
  33702. lastDeff = i;
  33703. funcId = stack.pop();
  33704. ttContext.functionsDefined[funcId] = {data: data, i: i};
  33705. } else if (op === 0x2D) { // ENDF - end of function
  33706. if (inFDEF) {
  33707. inFDEF = false;
  33708. lastEndf = i;
  33709. } else {
  33710. pc = callstack.pop();
  33711. if (!pc) {
  33712. warn('TT: ENDF bad stack');
  33713. ttContext.hintsValid = false;
  33714. return;
  33715. }
  33716. funcId = functionsCalled.pop();
  33717. data = pc.data;
  33718. i = pc.i;
  33719. ttContext.functionsStackDeltas[funcId] =
  33720. stack.length - pc.stackTop;
  33721. }
  33722. } else if (op === 0x89) { // IDEF - instruction definition
  33723. if (inFDEF || inELSE) {
  33724. warn('TT: nested IDEFs not allowed');
  33725. tooComplexToFollowFunctions = true;
  33726. }
  33727. inFDEF = true;
  33728. // recording it as a function to track ENDF
  33729. lastDeff = i;
  33730. } else if (op === 0x58) { // IF
  33731. ++ifLevel;
  33732. } else if (op === 0x1B) { // ELSE
  33733. inELSE = ifLevel;
  33734. } else if (op === 0x59) { // EIF
  33735. if (inELSE === ifLevel) {
  33736. inELSE = 0;
  33737. }
  33738. --ifLevel;
  33739. } else if (op === 0x1C) { // JMPR
  33740. if (!inFDEF && !inELSE) {
  33741. var offset = stack[stack.length - 1];
  33742. // only jumping forward to prevent infinite loop
  33743. if (offset > 0) {
  33744. i += offset - 1;
  33745. }
  33746. }
  33747. }
  33748. // Adjusting stack not extactly, but just enough to get function id
  33749. if (!inFDEF && !inELSE) {
  33750. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  33751. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  33752. if (op >= 0x71 && op <= 0x75) {
  33753. n = stack.pop();
  33754. if (n === n) {
  33755. stackDelta = -n * 2;
  33756. }
  33757. }
  33758. while (stackDelta < 0 && stack.length > 0) {
  33759. stack.pop();
  33760. stackDelta++;
  33761. }
  33762. while (stackDelta > 0) {
  33763. stack.push(NaN); // pushing any number into stack
  33764. stackDelta--;
  33765. }
  33766. }
  33767. }
  33768. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  33769. var content = [data];
  33770. if (i > data.length) {
  33771. content.push(new Uint8Array(i - data.length));
  33772. }
  33773. if (lastDeff > lastEndf) {
  33774. warn('TT: complementing a missing function tail');
  33775. // new function definition started, but not finished
  33776. // complete function by [CLEAR, ENDF]
  33777. content.push(new Uint8Array([0x22, 0x2D]));
  33778. }
  33779. foldTTTable(table, content);
  33780. }
  33781. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  33782. if (ttContext.tooComplexToFollowFunctions) {
  33783. return;
  33784. }
  33785. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  33786. warn('TT: more functions defined than expected');
  33787. ttContext.hintsValid = false;
  33788. return;
  33789. }
  33790. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  33791. if (j > maxFunctionDefs) {
  33792. warn('TT: invalid function id: ' + j);
  33793. ttContext.hintsValid = false;
  33794. return;
  33795. }
  33796. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  33797. warn('TT: undefined function: ' + j);
  33798. ttContext.hintsValid = false;
  33799. return;
  33800. }
  33801. }
  33802. }
  33803. function foldTTTable(table, content) {
  33804. if (content.length > 1) {
  33805. // concatenating the content items
  33806. var newLength = 0;
  33807. var j, jj;
  33808. for (j = 0, jj = content.length; j < jj; j++) {
  33809. newLength += content[j].length;
  33810. }
  33811. newLength = (newLength + 3) & ~3;
  33812. var result = new Uint8Array(newLength);
  33813. var pos = 0;
  33814. for (j = 0, jj = content.length; j < jj; j++) {
  33815. result.set(content[j], pos);
  33816. pos += content[j].length;
  33817. }
  33818. table.data = result;
  33819. table.length = newLength;
  33820. }
  33821. }
  33822. function sanitizeTTPrograms(fpgm, prep, cvt) {
  33823. var ttContext = {
  33824. functionsDefined: [],
  33825. functionsUsed: [],
  33826. functionsStackDeltas: [],
  33827. tooComplexToFollowFunctions: false,
  33828. hintsValid: true
  33829. };
  33830. if (fpgm) {
  33831. sanitizeTTProgram(fpgm, ttContext);
  33832. }
  33833. if (prep) {
  33834. sanitizeTTProgram(prep, ttContext);
  33835. }
  33836. if (fpgm) {
  33837. checkInvalidFunctions(ttContext, maxFunctionDefs);
  33838. }
  33839. if (cvt && (cvt.length & 1)) {
  33840. var cvtData = new Uint8Array(cvt.length + 1);
  33841. cvtData.set(cvt.data);
  33842. cvt.data = cvtData;
  33843. }
  33844. return ttContext.hintsValid;
  33845. }
  33846. // The following steps modify the original font data, making copy
  33847. font = new Stream(new Uint8Array(font.getBytes()));
  33848. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  33849. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  33850. var header = readOpenTypeHeader(font);
  33851. var numTables = header.numTables;
  33852. var cff, cffFile;
  33853. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  33854. hmtx: null, maxp: null, name: null, post: null };
  33855. var table;
  33856. for (var i = 0; i < numTables; i++) {
  33857. table = readTableEntry(font);
  33858. if (VALID_TABLES.indexOf(table.tag) < 0) {
  33859. continue; // skipping table if it's not a required or optional table
  33860. }
  33861. if (table.length === 0) {
  33862. continue; // skipping empty tables
  33863. }
  33864. tables[table.tag] = table;
  33865. }
  33866. var isTrueType = !tables['CFF '];
  33867. if (!isTrueType) {
  33868. // OpenType font
  33869. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  33870. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  33871. // no major tables: throwing everything at CFFFont
  33872. cffFile = new Stream(tables['CFF '].data);
  33873. cff = new CFFFont(cffFile, properties);
  33874. adjustWidths(properties);
  33875. return this.convert(name, cff, properties);
  33876. }
  33877. delete tables.glyf;
  33878. delete tables.loca;
  33879. delete tables.fpgm;
  33880. delete tables.prep;
  33881. delete tables['cvt '];
  33882. this.isOpenType = true;
  33883. } else {
  33884. if (!tables.glyf || !tables.loca) {
  33885. error('Required "glyf" or "loca" tables are not found');
  33886. }
  33887. this.isOpenType = false;
  33888. }
  33889. if (!tables.maxp) {
  33890. error('Required "maxp" table is not found');
  33891. }
  33892. font.pos = (font.start || 0) + tables.maxp.offset;
  33893. var version = font.getInt32();
  33894. var numGlyphs = font.getUint16();
  33895. var maxFunctionDefs = 0;
  33896. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  33897. // maxZones can be invalid
  33898. font.pos += 8;
  33899. var maxZones = font.getUint16();
  33900. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  33901. tables.maxp.data[14] = 0;
  33902. tables.maxp.data[15] = 2;
  33903. }
  33904. font.pos += 4;
  33905. maxFunctionDefs = font.getUint16();
  33906. }
  33907. var dupFirstEntry = false;
  33908. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  33909. properties.toUnicode.get(0) > '\u0000') {
  33910. // oracle's defect (see 3427), duplicating first entry
  33911. dupFirstEntry = true;
  33912. numGlyphs++;
  33913. tables.maxp.data[4] = numGlyphs >> 8;
  33914. tables.maxp.data[5] = numGlyphs & 255;
  33915. }
  33916. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  33917. tables['cvt '], maxFunctionDefs);
  33918. if (!hintsValid) {
  33919. delete tables.fpgm;
  33920. delete tables.prep;
  33921. delete tables['cvt '];
  33922. }
  33923. // Ensure the hmtx table contains the advance width and
  33924. // sidebearings information for numGlyphs in the maxp table
  33925. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  33926. if (!tables.head) {
  33927. error('Required "head" table is not found');
  33928. }
  33929. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  33930. var missingGlyphs = {};
  33931. if (isTrueType) {
  33932. var isGlyphLocationsLong = int16(tables.head.data[50],
  33933. tables.head.data[51]);
  33934. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  33935. numGlyphs, isGlyphLocationsLong,
  33936. hintsValid, dupFirstEntry);
  33937. }
  33938. if (!tables.hhea) {
  33939. error('Required "hhea" table is not found');
  33940. }
  33941. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  33942. // Sometimes it's 0. That needs to be fixed
  33943. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  33944. tables.hhea.data[10] = 0xFF;
  33945. tables.hhea.data[11] = 0xFF;
  33946. }
  33947. // Extract some more font properties from the OpenType head and
  33948. // hhea tables; yMin and descent value are always negative.
  33949. var metricsOverride = {
  33950. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  33951. yMax: int16(tables.head.data[42], tables.head.data[43]),
  33952. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  33953. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  33954. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  33955. };
  33956. // PDF FontDescriptor metrics lie -- using data from actual font.
  33957. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  33958. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  33959. // The 'post' table has glyphs names.
  33960. if (tables.post) {
  33961. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  33962. if (!valid) {
  33963. tables.post = null;
  33964. }
  33965. }
  33966. var charCodeToGlyphId = [], charCode;
  33967. var toUnicode = properties.toUnicode, widths = properties.widths;
  33968. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  33969. toUnicode.length === 0x10000);
  33970. // Helper function to try to skip mapping of empty glyphs.
  33971. // Note: In some cases, just relying on the glyph data doesn't work,
  33972. // hence we also use a few heuristics to fix various PDF files.
  33973. function hasGlyph(glyphId, charCode, widthCode) {
  33974. if (!missingGlyphs[glyphId]) {
  33975. return true;
  33976. }
  33977. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  33978. return true;
  33979. }
  33980. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  33981. return true;
  33982. }
  33983. return false;
  33984. }
  33985. if (properties.type === 'CIDFontType2') {
  33986. var cidToGidMap = properties.cidToGidMap || [];
  33987. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  33988. properties.cMap.forEach(function(charCode, cid) {
  33989. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  33990. var glyphId = -1;
  33991. if (isCidToGidMapEmpty) {
  33992. glyphId = charCode;
  33993. } else if (cidToGidMap[cid] !== undefined) {
  33994. glyphId = cidToGidMap[cid];
  33995. }
  33996. if (glyphId >= 0 && glyphId < numGlyphs &&
  33997. hasGlyph(glyphId, charCode, cid)) {
  33998. charCodeToGlyphId[charCode] = glyphId;
  33999. }
  34000. });
  34001. if (dupFirstEntry) {
  34002. charCodeToGlyphId[0] = numGlyphs - 1;
  34003. }
  34004. } else {
  34005. // Most of the following logic in this code branch is based on the
  34006. // 9.6.6.4 of the PDF spec.
  34007. var hasEncoding =
  34008. properties.differences.length > 0 || !!properties.baseEncodingName;
  34009. var cmapTable =
  34010. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  34011. var cmapPlatformId = cmapTable.platformId;
  34012. var cmapEncodingId = cmapTable.encodingId;
  34013. var cmapMappings = cmapTable.mappings;
  34014. var cmapMappingsLength = cmapMappings.length;
  34015. // The spec seems to imply that if the font is symbolic the encoding
  34016. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  34017. // where the the font is symbolic and it has an encoding.
  34018. if (hasEncoding &&
  34019. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  34020. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  34021. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  34022. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  34023. // When no preferred cmap table was found and |baseEncodingName| is
  34024. // one of the predefined encodings, we seem to obtain a better
  34025. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  34026. // TODO: Note that this is a hack which should be removed as soon as
  34027. // we have proper support for more exotic cmap tables.
  34028. var baseEncoding = [];
  34029. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  34030. properties.baseEncodingName === 'WinAnsiEncoding') {
  34031. baseEncoding = Encodings[properties.baseEncodingName];
  34032. }
  34033. for (charCode = 0; charCode < 256; charCode++) {
  34034. var glyphName;
  34035. if (this.differences && charCode in this.differences) {
  34036. glyphName = this.differences[charCode];
  34037. } else if (charCode in baseEncoding &&
  34038. baseEncoding[charCode] !== '') {
  34039. glyphName = baseEncoding[charCode];
  34040. } else {
  34041. glyphName = Encodings.StandardEncoding[charCode];
  34042. }
  34043. if (!glyphName) {
  34044. continue;
  34045. }
  34046. var unicodeOrCharCode, isUnicode = false;
  34047. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  34048. unicodeOrCharCode = GlyphsUnicode[glyphName];
  34049. isUnicode = true;
  34050. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  34051. // TODO: the encoding needs to be updated with mac os table.
  34052. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  34053. }
  34054. var found = false;
  34055. for (i = 0; i < cmapMappingsLength; ++i) {
  34056. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  34057. continue;
  34058. }
  34059. var code = isUnicode ? charCode : unicodeOrCharCode;
  34060. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  34061. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34062. found = true;
  34063. break;
  34064. }
  34065. }
  34066. if (!found && properties.glyphNames) {
  34067. // Try to map using the post table.
  34068. var glyphId = properties.glyphNames.indexOf(glyphName);
  34069. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  34070. charCodeToGlyphId[charCode] = glyphId;
  34071. } else {
  34072. charCodeToGlyphId[charCode] = 0; // notdef
  34073. }
  34074. }
  34075. }
  34076. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  34077. // Default Unicode semantics, use the charcodes as is.
  34078. for (i = 0; i < cmapMappingsLength; ++i) {
  34079. charCodeToGlyphId[cmapMappings[i].charCode] =
  34080. cmapMappings[i].glyphId;
  34081. }
  34082. } else {
  34083. // For (3, 0) cmap tables:
  34084. // The charcode key being stored in charCodeToGlyphId is the lower
  34085. // byte of the two-byte charcodes of the cmap table since according to
  34086. // the spec: 'each byte from the string shall be prepended with the
  34087. // high byte of the range [of charcodes in the cmap table], to form
  34088. // a two-byte character, which shall be used to select the
  34089. // associated glyph description from the subtable'.
  34090. //
  34091. // For (1, 0) cmap tables:
  34092. // 'single bytes from the string shall be used to look up the
  34093. // associated glyph descriptions from the subtable'. This means
  34094. // charcodes in the cmap will be single bytes, so no-op since
  34095. // glyph.charCode & 0xFF === glyph.charCode
  34096. for (i = 0; i < cmapMappingsLength; ++i) {
  34097. charCode = cmapMappings[i].charCode & 0xFF;
  34098. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34099. }
  34100. }
  34101. }
  34102. if (charCodeToGlyphId.length === 0) {
  34103. // defines at least one glyph
  34104. charCodeToGlyphId[0] = 0;
  34105. }
  34106. // Converting glyphs and ids into font's cmap table
  34107. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  34108. this.toFontChar = newMapping.toFontChar;
  34109. tables.cmap = {
  34110. tag: 'cmap',
  34111. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  34112. };
  34113. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  34114. tables['OS/2'] = {
  34115. tag: 'OS/2',
  34116. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  34117. metricsOverride)
  34118. };
  34119. }
  34120. // Rewrite the 'post' table if needed
  34121. if (!tables.post) {
  34122. tables.post = {
  34123. tag: 'post',
  34124. data: createPostTable(properties)
  34125. };
  34126. }
  34127. if (!isTrueType) {
  34128. try {
  34129. // Trying to repair CFF file
  34130. cffFile = new Stream(tables['CFF '].data);
  34131. var parser = new CFFParser(cffFile, properties);
  34132. cff = parser.parse();
  34133. var compiler = new CFFCompiler(cff);
  34134. tables['CFF '].data = compiler.compile();
  34135. } catch (e) {
  34136. warn('Failed to compile font ' + properties.loadedName);
  34137. }
  34138. }
  34139. // Re-creating 'name' table
  34140. if (!tables.name) {
  34141. tables.name = {
  34142. tag: 'name',
  34143. data: createNameTable(this.name)
  34144. };
  34145. } else {
  34146. // ... using existing 'name' table as prototype
  34147. var namePrototype = readNameTable(tables.name);
  34148. tables.name.data = createNameTable(name, namePrototype);
  34149. }
  34150. var builder = new OpenTypeFileBuilder(header.version);
  34151. for (var tableTag in tables) {
  34152. builder.addTable(tableTag, tables[tableTag].data);
  34153. }
  34154. return builder.toArray();
  34155. },
  34156. convert: function Font_convert(fontName, font, properties) {
  34157. // TODO: Check the charstring widths to determine this.
  34158. properties.fixedPitch = false;
  34159. var mapping = font.getGlyphMapping(properties);
  34160. var newMapping = adjustMapping(mapping, properties);
  34161. this.toFontChar = newMapping.toFontChar;
  34162. var numGlyphs = font.numGlyphs;
  34163. function getCharCodes(charCodeToGlyphId, glyphId) {
  34164. var charCodes = null;
  34165. for (var charCode in charCodeToGlyphId) {
  34166. if (glyphId === charCodeToGlyphId[charCode]) {
  34167. if (!charCodes) {
  34168. charCodes = [];
  34169. }
  34170. charCodes.push(charCode | 0);
  34171. }
  34172. }
  34173. return charCodes;
  34174. }
  34175. function createCharCode(charCodeToGlyphId, glyphId) {
  34176. for (var charCode in charCodeToGlyphId) {
  34177. if (glyphId === charCodeToGlyphId[charCode]) {
  34178. return charCode | 0;
  34179. }
  34180. }
  34181. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  34182. glyphId;
  34183. return newMapping.nextAvailableFontCharCode++;
  34184. }
  34185. var seacs = font.seacs;
  34186. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  34187. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  34188. var charset = font.getCharset();
  34189. var seacMap = Object.create(null);
  34190. for (var glyphId in seacs) {
  34191. glyphId |= 0;
  34192. var seac = seacs[glyphId];
  34193. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  34194. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  34195. var baseGlyphId = charset.indexOf(baseGlyphName);
  34196. var accentGlyphId = charset.indexOf(accentGlyphName);
  34197. if (baseGlyphId < 0 || accentGlyphId < 0) {
  34198. continue;
  34199. }
  34200. var accentOffset = {
  34201. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  34202. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  34203. };
  34204. var charCodes = getCharCodes(mapping, glyphId);
  34205. if (!charCodes) {
  34206. // There's no point in mapping it if the char code was never mapped
  34207. // to begin with.
  34208. continue;
  34209. }
  34210. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  34211. var charCode = charCodes[i];
  34212. // Find a fontCharCode that maps to the base and accent glyphs.
  34213. // If one doesn't exists, create it.
  34214. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  34215. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  34216. baseGlyphId);
  34217. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  34218. accentGlyphId);
  34219. seacMap[charCode] = {
  34220. baseFontCharCode: baseFontCharCode,
  34221. accentFontCharCode: accentFontCharCode,
  34222. accentOffset: accentOffset
  34223. };
  34224. }
  34225. }
  34226. properties.seacMap = seacMap;
  34227. }
  34228. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  34229. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  34230. // PostScript Font Program
  34231. builder.addTable('CFF ', font.data);
  34232. // OS/2 and Windows Specific metrics
  34233. builder.addTable('OS/2', createOS2Table(properties,
  34234. newMapping.charCodeToGlyphId));
  34235. // Character to glyphs mapping
  34236. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  34237. numGlyphs));
  34238. // Font header
  34239. builder.addTable('head',
  34240. '\x00\x01\x00\x00' + // Version number
  34241. '\x00\x00\x10\x00' + // fontRevision
  34242. '\x00\x00\x00\x00' + // checksumAdjustement
  34243. '\x5F\x0F\x3C\xF5' + // magicNumber
  34244. '\x00\x00' + // Flags
  34245. safeString16(unitsPerEm) + // unitsPerEM
  34246. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  34247. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  34248. '\x00\x00' + // xMin
  34249. safeString16(properties.descent) + // yMin
  34250. '\x0F\xFF' + // xMax
  34251. safeString16(properties.ascent) + // yMax
  34252. string16(properties.italicAngle ? 2 : 0) + // macStyle
  34253. '\x00\x11' + // lowestRecPPEM
  34254. '\x00\x00' + // fontDirectionHint
  34255. '\x00\x00' + // indexToLocFormat
  34256. '\x00\x00'); // glyphDataFormat
  34257. // Horizontal header
  34258. builder.addTable('hhea',
  34259. '\x00\x01\x00\x00' + // Version number
  34260. safeString16(properties.ascent) + // Typographic Ascent
  34261. safeString16(properties.descent) + // Typographic Descent
  34262. '\x00\x00' + // Line Gap
  34263. '\xFF\xFF' + // advanceWidthMax
  34264. '\x00\x00' + // minLeftSidebearing
  34265. '\x00\x00' + // minRightSidebearing
  34266. '\x00\x00' + // xMaxExtent
  34267. safeString16(properties.capHeight) + // caretSlopeRise
  34268. safeString16(Math.tan(properties.italicAngle) *
  34269. properties.xHeight) + // caretSlopeRun
  34270. '\x00\x00' + // caretOffset
  34271. '\x00\x00' + // -reserved-
  34272. '\x00\x00' + // -reserved-
  34273. '\x00\x00' + // -reserved-
  34274. '\x00\x00' + // -reserved-
  34275. '\x00\x00' + // metricDataFormat
  34276. string16(numGlyphs)); // Number of HMetrics
  34277. // Horizontal metrics
  34278. builder.addTable('hmtx', (function fontFieldsHmtx() {
  34279. var charstrings = font.charstrings;
  34280. var cffWidths = font.cff ? font.cff.widths : null;
  34281. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  34282. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  34283. var width = 0;
  34284. if (charstrings) {
  34285. var charstring = charstrings[i - 1];
  34286. width = 'width' in charstring ? charstring.width : 0;
  34287. } else if (cffWidths) {
  34288. width = Math.ceil(cffWidths[i] || 0);
  34289. }
  34290. hmtx += string16(width) + string16(0);
  34291. }
  34292. return hmtx;
  34293. })());
  34294. // Maximum profile
  34295. builder.addTable('maxp',
  34296. '\x00\x00\x50\x00' + // Version number
  34297. string16(numGlyphs)); // Num of glyphs
  34298. // Naming tables
  34299. builder.addTable('name', createNameTable(fontName));
  34300. // PostScript informations
  34301. builder.addTable('post', createPostTable(properties));
  34302. return builder.toArray();
  34303. },
  34304. /**
  34305. * Builds a char code to unicode map based on section 9.10 of the spec.
  34306. * @param {Object} properties Font properties object.
  34307. * @return {Object} A ToUnicodeMap object.
  34308. */
  34309. buildToUnicode: function Font_buildToUnicode(properties) {
  34310. // Section 9.10.2 Mapping Character Codes to Unicode Values
  34311. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  34312. return properties.toUnicode;
  34313. }
  34314. // According to the spec if the font is a simple font we should only map
  34315. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  34316. // the differences array only contains adobe standard or symbol set names,
  34317. // in pratice it seems better to always try to create a toUnicode
  34318. // map based of the default encoding.
  34319. var toUnicode, charcode;
  34320. if (!properties.composite /* is simple font */) {
  34321. toUnicode = [];
  34322. var encoding = properties.defaultEncoding.slice();
  34323. var baseEncodingName = properties.baseEncodingName;
  34324. // Merge in the differences array.
  34325. var differences = properties.differences;
  34326. for (charcode in differences) {
  34327. encoding[charcode] = differences[charcode];
  34328. }
  34329. for (charcode in encoding) {
  34330. // a) Map the character code to a character name.
  34331. var glyphName = encoding[charcode];
  34332. // b) Look up the character name in the Adobe Glyph List (see the
  34333. // Bibliography) to obtain the corresponding Unicode value.
  34334. if (glyphName === '') {
  34335. continue;
  34336. } else if (GlyphsUnicode[glyphName] === undefined) {
  34337. // (undocumented) c) Few heuristics to recognize unknown glyphs
  34338. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  34339. var code = 0;
  34340. switch (glyphName[0]) {
  34341. case 'G': // Gxx glyph
  34342. if (glyphName.length === 3) {
  34343. code = parseInt(glyphName.substr(1), 16);
  34344. }
  34345. break;
  34346. case 'g': // g00xx glyph
  34347. if (glyphName.length === 5) {
  34348. code = parseInt(glyphName.substr(1), 16);
  34349. }
  34350. break;
  34351. case 'C': // Cddd glyph
  34352. case 'c': // cddd glyph
  34353. if (glyphName.length >= 3) {
  34354. code = +glyphName.substr(1);
  34355. }
  34356. break;
  34357. }
  34358. if (code) {
  34359. // If |baseEncodingName| is one the predefined encodings,
  34360. // and |code| equals |charcode|, using the glyph defined in the
  34361. // baseEncoding seems to yield a better |toUnicode| mapping
  34362. // (fixes issue 5070).
  34363. if (baseEncodingName && code === +charcode) {
  34364. var baseEncoding = Encodings[baseEncodingName];
  34365. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  34366. toUnicode[charcode] =
  34367. String.fromCharCode(GlyphsUnicode[glyphName]);
  34368. continue;
  34369. }
  34370. }
  34371. toUnicode[charcode] = String.fromCharCode(code);
  34372. }
  34373. continue;
  34374. }
  34375. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  34376. }
  34377. return new ToUnicodeMap(toUnicode);
  34378. }
  34379. // If the font is a composite font that uses one of the predefined CMaps
  34380. // listed in Table 118 (except Identity–H and Identity–V) or whose
  34381. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  34382. // Adobe-Korea1 character collection:
  34383. if (properties.composite && (
  34384. (properties.cMap.builtInCMap &&
  34385. !(properties.cMap instanceof IdentityCMap)) ||
  34386. (properties.cidSystemInfo.registry === 'Adobe' &&
  34387. (properties.cidSystemInfo.ordering === 'GB1' ||
  34388. properties.cidSystemInfo.ordering === 'CNS1' ||
  34389. properties.cidSystemInfo.ordering === 'Japan1' ||
  34390. properties.cidSystemInfo.ordering === 'Korea1')))) {
  34391. // Then:
  34392. // a) Map the character code to a character identifier (CID) according
  34393. // to the font’s CMap.
  34394. // b) Obtain the registry and ordering of the character collection used
  34395. // by the font’s CMap (for example, Adobe and Japan1) from its
  34396. // CIDSystemInfo dictionary.
  34397. var registry = properties.cidSystemInfo.registry;
  34398. var ordering = properties.cidSystemInfo.ordering;
  34399. // c) Construct a second CMap name by concatenating the registry and
  34400. // ordering obtained in step (b) in the format registry–ordering–UCS2
  34401. // (for example, Adobe–Japan1–UCS2).
  34402. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  34403. // d) Obtain the CMap with the name constructed in step (c) (available
  34404. // from the ASN Web site; see the Bibliography).
  34405. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  34406. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  34407. var cMap = properties.cMap;
  34408. toUnicode = [];
  34409. cMap.forEach(function(charcode, cid) {
  34410. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34411. // e) Map the CID obtained in step (a) according to the CMap obtained
  34412. // in step (d), producing a Unicode value.
  34413. var ucs2 = ucs2CMap.lookup(cid);
  34414. if (ucs2) {
  34415. toUnicode[charcode] =
  34416. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  34417. ucs2.charCodeAt(1));
  34418. }
  34419. });
  34420. return new ToUnicodeMap(toUnicode);
  34421. }
  34422. // The viewer's choice, just use an identity map.
  34423. return new IdentityToUnicodeMap(properties.firstChar,
  34424. properties.lastChar);
  34425. },
  34426. get spaceWidth() {
  34427. if ('_shadowWidth' in this) {
  34428. return this._shadowWidth;
  34429. }
  34430. // trying to estimate space character width
  34431. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  34432. var width;
  34433. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  34434. var glyphName = possibleSpaceReplacements[i];
  34435. // if possible, getting width by glyph name
  34436. if (glyphName in this.widths) {
  34437. width = this.widths[glyphName];
  34438. break;
  34439. }
  34440. var glyphUnicode = GlyphsUnicode[glyphName];
  34441. // finding the charcode via unicodeToCID map
  34442. var charcode = 0;
  34443. if (this.composite) {
  34444. if (this.cMap.contains(glyphUnicode)) {
  34445. charcode = this.cMap.lookup(glyphUnicode);
  34446. }
  34447. }
  34448. // ... via toUnicode map
  34449. if (!charcode && this.toUnicode) {
  34450. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  34451. }
  34452. // setting it to unicode if negative or undefined
  34453. if (charcode <= 0) {
  34454. charcode = glyphUnicode;
  34455. }
  34456. // trying to get width via charcode
  34457. width = this.widths[charcode];
  34458. if (width) {
  34459. break; // the non-zero width found
  34460. }
  34461. }
  34462. width = width || this.defaultWidth;
  34463. // Do not shadow the property here. See discussion:
  34464. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  34465. this._shadowWidth = width;
  34466. return width;
  34467. },
  34468. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  34469. var fontCharCode, width, operatorListId;
  34470. var widthCode = charcode;
  34471. if (this.cMap && this.cMap.contains(charcode)) {
  34472. widthCode = this.cMap.lookup(charcode);
  34473. }
  34474. width = this.widths[widthCode];
  34475. width = isNum(width) ? width : this.defaultWidth;
  34476. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  34477. var unicode = this.toUnicode.get(charcode) || charcode;
  34478. if (typeof unicode === 'number') {
  34479. unicode = String.fromCharCode(unicode);
  34480. }
  34481. // First try the toFontChar map, if it's not there then try falling
  34482. // back to the char code.
  34483. fontCharCode = this.toFontChar[charcode] || charcode;
  34484. if (this.missingFile) {
  34485. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  34486. }
  34487. if (this.isType3Font) {
  34488. // Font char code in this case is actually a glyph name.
  34489. operatorListId = fontCharCode;
  34490. }
  34491. var accent = null;
  34492. if (this.seacMap && this.seacMap[charcode]) {
  34493. var seac = this.seacMap[charcode];
  34494. fontCharCode = seac.baseFontCharCode;
  34495. accent = {
  34496. fontChar: String.fromCharCode(seac.accentFontCharCode),
  34497. offset: seac.accentOffset
  34498. };
  34499. }
  34500. var fontChar = String.fromCharCode(fontCharCode);
  34501. var glyph = this.glyphCache[charcode];
  34502. if (!glyph ||
  34503. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  34504. operatorListId, isSpace)) {
  34505. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  34506. operatorListId, isSpace);
  34507. this.glyphCache[charcode] = glyph;
  34508. }
  34509. return glyph;
  34510. },
  34511. charsToGlyphs: function Font_charsToGlyphs(chars) {
  34512. var charsCache = this.charsCache;
  34513. var glyphs, glyph, charcode;
  34514. // if we translated this string before, just grab it from the cache
  34515. if (charsCache) {
  34516. glyphs = charsCache[chars];
  34517. if (glyphs) {
  34518. return glyphs;
  34519. }
  34520. }
  34521. // lazily create the translation cache
  34522. if (!charsCache) {
  34523. charsCache = this.charsCache = Object.create(null);
  34524. }
  34525. glyphs = [];
  34526. var charsCacheKey = chars;
  34527. var i = 0, ii;
  34528. if (this.cMap) {
  34529. // composite fonts have multi-byte strings convert the string from
  34530. // single-byte to multi-byte
  34531. var c = {};
  34532. while (i < chars.length) {
  34533. this.cMap.readCharCode(chars, i, c);
  34534. charcode = c.charcode;
  34535. var length = c.length;
  34536. i += length;
  34537. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  34538. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  34539. glyph = this.charToGlyph(charcode, isSpace);
  34540. glyphs.push(glyph);
  34541. }
  34542. } else {
  34543. for (i = 0, ii = chars.length; i < ii; ++i) {
  34544. charcode = chars.charCodeAt(i);
  34545. glyph = this.charToGlyph(charcode, charcode === 0x20);
  34546. glyphs.push(glyph);
  34547. }
  34548. }
  34549. // Enter the translated string into the cache
  34550. return (charsCache[charsCacheKey] = glyphs);
  34551. }
  34552. };
  34553. return Font;
  34554. })();
  34555. var ErrorFont = (function ErrorFontClosure() {
  34556. function ErrorFont(error) {
  34557. this.error = error;
  34558. this.loadedName = 'g_font_error';
  34559. this.loading = false;
  34560. }
  34561. ErrorFont.prototype = {
  34562. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  34563. return [];
  34564. },
  34565. exportData: function ErrorFont_exportData() {
  34566. return {error: this.error};
  34567. }
  34568. };
  34569. return ErrorFont;
  34570. })();
  34571. /**
  34572. * Shared logic for building a char code to glyph id mapping for Type1 and
  34573. * simple CFF fonts. See section 9.6.6.2 of the spec.
  34574. * @param {Object} properties Font properties object.
  34575. * @param {Object} builtInEncoding The encoding contained within the actual font
  34576. * data.
  34577. * @param {Array} Array of glyph names where the index is the glyph ID.
  34578. * @returns {Object} A char code to glyph ID map.
  34579. */
  34580. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  34581. var charCodeToGlyphId = Object.create(null);
  34582. var glyphId, charCode, baseEncoding;
  34583. if (properties.baseEncodingName) {
  34584. // If a valid base encoding name was used, the mapping is initialized with
  34585. // that.
  34586. baseEncoding = Encodings[properties.baseEncodingName];
  34587. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34588. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34589. if (glyphId >= 0) {
  34590. charCodeToGlyphId[charCode] = glyphId;
  34591. } else {
  34592. charCodeToGlyphId[charCode] = 0; // notdef
  34593. }
  34594. }
  34595. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  34596. // For a symbolic font the encoding should be the fonts built-in
  34597. // encoding.
  34598. for (charCode in builtInEncoding) {
  34599. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  34600. }
  34601. } else {
  34602. // For non-symbolic fonts that don't have a base encoding the standard
  34603. // encoding should be used.
  34604. baseEncoding = Encodings.StandardEncoding;
  34605. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34606. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34607. if (glyphId >= 0) {
  34608. charCodeToGlyphId[charCode] = glyphId;
  34609. } else {
  34610. charCodeToGlyphId[charCode] = 0; // notdef
  34611. }
  34612. }
  34613. }
  34614. // Lastly, merge in the differences.
  34615. var differences = properties.differences;
  34616. if (differences) {
  34617. for (charCode in differences) {
  34618. var glyphName = differences[charCode];
  34619. glyphId = glyphNames.indexOf(glyphName);
  34620. if (glyphId >= 0) {
  34621. charCodeToGlyphId[charCode] = glyphId;
  34622. } else {
  34623. charCodeToGlyphId[charCode] = 0; // notdef
  34624. }
  34625. }
  34626. }
  34627. return charCodeToGlyphId;
  34628. }
  34629. /*
  34630. * CharStrings are encoded following the the CharString Encoding sequence
  34631. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  34632. * The value in a byte indicates a command, a number, or subsequent bytes
  34633. * that are to be interpreted in a special way.
  34634. *
  34635. * CharString Number Encoding:
  34636. * A CharString byte containing the values from 32 through 255 inclusive
  34637. * indicate an integer. These values are decoded in four ranges.
  34638. *
  34639. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  34640. * indicate the integer v - 139. Thus, the integer values from -107 through
  34641. * 107 inclusive may be encoded in single byte.
  34642. *
  34643. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  34644. * indicates an integer involving the next byte, w, according to the formula:
  34645. * [(v - 247) x 256] + w + 108
  34646. *
  34647. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  34648. * indicates an integer involving the next byte, w, according to the formula:
  34649. * -[(v - 251) * 256] - w - 108
  34650. *
  34651. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  34652. * are a two complement signed integer. The first of these bytes contains the
  34653. * highest order bits, the second byte contains the next higher order bits
  34654. * and the fourth byte contain the lowest order bits.
  34655. *
  34656. *
  34657. * CharString Command Encoding:
  34658. * CharStrings commands are encoded in 1 or 2 bytes.
  34659. *
  34660. * Single byte commands are encoded in 1 byte that contains a value between
  34661. * 0 and 31 inclusive.
  34662. * If a command byte contains the value 12, then the value in the next byte
  34663. * indicates a command. This "escape" mechanism allows many extra commands
  34664. * to be encoded and this encoding technique helps to minimize the length of
  34665. * the charStrings.
  34666. */
  34667. var Type1CharString = (function Type1CharStringClosure() {
  34668. var COMMAND_MAP = {
  34669. 'hstem': [1],
  34670. 'vstem': [3],
  34671. 'vmoveto': [4],
  34672. 'rlineto': [5],
  34673. 'hlineto': [6],
  34674. 'vlineto': [7],
  34675. 'rrcurveto': [8],
  34676. 'callsubr': [10],
  34677. 'flex': [12, 35],
  34678. 'drop' : [12, 18],
  34679. 'endchar': [14],
  34680. 'rmoveto': [21],
  34681. 'hmoveto': [22],
  34682. 'vhcurveto': [30],
  34683. 'hvcurveto': [31]
  34684. };
  34685. function Type1CharString() {
  34686. this.width = 0;
  34687. this.lsb = 0;
  34688. this.flexing = false;
  34689. this.output = [];
  34690. this.stack = [];
  34691. }
  34692. Type1CharString.prototype = {
  34693. convert: function Type1CharString_convert(encoded, subrs) {
  34694. var count = encoded.length;
  34695. var error = false;
  34696. var wx, sbx, subrNumber;
  34697. for (var i = 0; i < count; i++) {
  34698. var value = encoded[i];
  34699. if (value < 32) {
  34700. if (value === 12) {
  34701. value = (value << 8) + encoded[++i];
  34702. }
  34703. switch (value) {
  34704. case 1: // hstem
  34705. if (!HINTING_ENABLED) {
  34706. this.stack = [];
  34707. break;
  34708. }
  34709. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34710. break;
  34711. case 3: // vstem
  34712. if (!HINTING_ENABLED) {
  34713. this.stack = [];
  34714. break;
  34715. }
  34716. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34717. break;
  34718. case 4: // vmoveto
  34719. if (this.flexing) {
  34720. if (this.stack.length < 1) {
  34721. error = true;
  34722. break;
  34723. }
  34724. // Add the dx for flex and but also swap the values so they are
  34725. // the right order.
  34726. var dy = this.stack.pop();
  34727. this.stack.push(0, dy);
  34728. break;
  34729. }
  34730. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  34731. break;
  34732. case 5: // rlineto
  34733. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  34734. break;
  34735. case 6: // hlineto
  34736. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  34737. break;
  34738. case 7: // vlineto
  34739. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  34740. break;
  34741. case 8: // rrcurveto
  34742. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  34743. break;
  34744. case 9: // closepath
  34745. // closepath is a Type1 command that does not take argument and is
  34746. // useless in Type2 and it can simply be ignored.
  34747. this.stack = [];
  34748. break;
  34749. case 10: // callsubr
  34750. if (this.stack.length < 1) {
  34751. error = true;
  34752. break;
  34753. }
  34754. subrNumber = this.stack.pop();
  34755. error = this.convert(subrs[subrNumber], subrs);
  34756. break;
  34757. case 11: // return
  34758. return error;
  34759. case 13: // hsbw
  34760. if (this.stack.length < 2) {
  34761. error = true;
  34762. break;
  34763. }
  34764. // To convert to type2 we have to move the width value to the
  34765. // first part of the charstring and then use hmoveto with lsb.
  34766. wx = this.stack.pop();
  34767. sbx = this.stack.pop();
  34768. this.lsb = sbx;
  34769. this.width = wx;
  34770. this.stack.push(wx, sbx);
  34771. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  34772. break;
  34773. case 14: // endchar
  34774. this.output.push(COMMAND_MAP.endchar[0]);
  34775. break;
  34776. case 21: // rmoveto
  34777. if (this.flexing) {
  34778. break;
  34779. }
  34780. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  34781. break;
  34782. case 22: // hmoveto
  34783. if (this.flexing) {
  34784. // Add the dy for flex.
  34785. this.stack.push(0);
  34786. break;
  34787. }
  34788. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  34789. break;
  34790. case 30: // vhcurveto
  34791. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  34792. break;
  34793. case 31: // hvcurveto
  34794. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  34795. break;
  34796. case (12 << 8) + 0: // dotsection
  34797. // dotsection is a Type1 command to specify some hinting feature
  34798. // for dots that do not take a parameter and it can safely be
  34799. // ignored for Type2.
  34800. this.stack = [];
  34801. break;
  34802. case (12 << 8) + 1: // vstem3
  34803. if (!HINTING_ENABLED) {
  34804. this.stack = [];
  34805. break;
  34806. }
  34807. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  34808. // multiple parameters, so instead of returning [vh]stem3 take a
  34809. // shortcut and return [vhstem] instead.
  34810. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34811. break;
  34812. case (12 << 8) + 2: // hstem3
  34813. if (!HINTING_ENABLED) {
  34814. this.stack = [];
  34815. break;
  34816. }
  34817. // See vstem3.
  34818. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34819. break;
  34820. case (12 << 8) + 6: // seac
  34821. // seac is like type 2's special endchar but it doesn't use the
  34822. // first argument asb, so remove it.
  34823. if (SEAC_ANALYSIS_ENABLED) {
  34824. this.seac = this.stack.splice(-4, 4);
  34825. error = this.executeCommand(0, COMMAND_MAP.endchar);
  34826. } else {
  34827. error = this.executeCommand(4, COMMAND_MAP.endchar);
  34828. }
  34829. break;
  34830. case (12 << 8) + 7: // sbw
  34831. if (this.stack.length < 4) {
  34832. error = true;
  34833. break;
  34834. }
  34835. // To convert to type2 we have to move the width value to the
  34836. // first part of the charstring and then use rmoveto with
  34837. // (dx, dy). The height argument will not be used for vmtx and
  34838. // vhea tables reconstruction -- ignoring it.
  34839. var wy = this.stack.pop();
  34840. wx = this.stack.pop();
  34841. var sby = this.stack.pop();
  34842. sbx = this.stack.pop();
  34843. this.lsb = sbx;
  34844. this.width = wx;
  34845. this.stack.push(wx, sbx, sby);
  34846. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  34847. break;
  34848. case (12 << 8) + 12: // div
  34849. if (this.stack.length < 2) {
  34850. error = true;
  34851. break;
  34852. }
  34853. var num2 = this.stack.pop();
  34854. var num1 = this.stack.pop();
  34855. this.stack.push(num1 / num2);
  34856. break;
  34857. case (12 << 8) + 16: // callothersubr
  34858. if (this.stack.length < 2) {
  34859. error = true;
  34860. break;
  34861. }
  34862. subrNumber = this.stack.pop();
  34863. var numArgs = this.stack.pop();
  34864. if (subrNumber === 0 && numArgs === 3) {
  34865. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  34866. this.stack.push(
  34867. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  34868. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  34869. flexArgs[4], // bcp2x
  34870. flexArgs[5], // bcp2y
  34871. flexArgs[6], // p2x
  34872. flexArgs[7], // p2y
  34873. flexArgs[8], // bcp3x
  34874. flexArgs[9], // bcp3y
  34875. flexArgs[10], // bcp4x
  34876. flexArgs[11], // bcp4y
  34877. flexArgs[12], // p3x
  34878. flexArgs[13], // p3y
  34879. flexArgs[14] // flexDepth
  34880. // 15 = finalx unused by flex
  34881. // 16 = finaly unused by flex
  34882. );
  34883. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  34884. this.flexing = false;
  34885. this.stack.push(flexArgs[15], flexArgs[16]);
  34886. } else if (subrNumber === 1 && numArgs === 0) {
  34887. this.flexing = true;
  34888. }
  34889. break;
  34890. case (12 << 8) + 17: // pop
  34891. // Ignore this since it is only used with othersubr.
  34892. break;
  34893. case (12 << 8) + 33: // setcurrentpoint
  34894. // Ignore for now.
  34895. this.stack = [];
  34896. break;
  34897. default:
  34898. warn('Unknown type 1 charstring command of "' + value + '"');
  34899. break;
  34900. }
  34901. if (error) {
  34902. break;
  34903. }
  34904. continue;
  34905. } else if (value <= 246) {
  34906. value = value - 139;
  34907. } else if (value <= 250) {
  34908. value = ((value - 247) * 256) + encoded[++i] + 108;
  34909. } else if (value <= 254) {
  34910. value = -((value - 251) * 256) - encoded[++i] - 108;
  34911. } else {
  34912. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  34913. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  34914. }
  34915. this.stack.push(value);
  34916. }
  34917. return error;
  34918. },
  34919. executeCommand: function(howManyArgs, command, keepStack) {
  34920. var stackLength = this.stack.length;
  34921. if (howManyArgs > stackLength) {
  34922. return true;
  34923. }
  34924. var start = stackLength - howManyArgs;
  34925. for (var i = start; i < stackLength; i++) {
  34926. var value = this.stack[i];
  34927. if (value === (value | 0)) { // int
  34928. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  34929. } else { // fixed point
  34930. value = (65536 * value) | 0;
  34931. this.output.push(255,
  34932. (value >> 24) & 0xFF,
  34933. (value >> 16) & 0xFF,
  34934. (value >> 8) & 0xFF,
  34935. value & 0xFF);
  34936. }
  34937. }
  34938. this.output.push.apply(this.output, command);
  34939. if (keepStack) {
  34940. this.stack.splice(start, howManyArgs);
  34941. } else {
  34942. this.stack.length = 0;
  34943. }
  34944. return false;
  34945. }
  34946. };
  34947. return Type1CharString;
  34948. })();
  34949. /*
  34950. * Type1Parser encapsulate the needed code for parsing a Type1 font
  34951. * program. Some of its logic depends on the Type2 charstrings
  34952. * structure.
  34953. * Note: this doesn't really parse the font since that would require evaluation
  34954. * of PostScript, but it is possible in most cases to extract what we need
  34955. * without a full parse.
  34956. */
  34957. var Type1Parser = (function Type1ParserClosure() {
  34958. /*
  34959. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  34960. * of Plaintext Bytes. The function took a key as a parameter which can be
  34961. * for decrypting the eexec block of for decoding charStrings.
  34962. */
  34963. var EEXEC_ENCRYPT_KEY = 55665;
  34964. var CHAR_STRS_ENCRYPT_KEY = 4330;
  34965. function isHexDigit(code) {
  34966. return code >= 48 && code <= 57 || // '0'-'9'
  34967. code >= 65 && code <= 70 || // 'A'-'F'
  34968. code >= 97 && code <= 102; // 'a'-'f'
  34969. }
  34970. function decrypt(data, key, discardNumber) {
  34971. var r = key | 0, c1 = 52845, c2 = 22719;
  34972. var count = data.length;
  34973. var decrypted = new Uint8Array(count);
  34974. for (var i = 0; i < count; i++) {
  34975. var value = data[i];
  34976. decrypted[i] = value ^ (r >> 8);
  34977. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34978. }
  34979. return Array.prototype.slice.call(decrypted, discardNumber);
  34980. }
  34981. function decryptAscii(data, key, discardNumber) {
  34982. var r = key | 0, c1 = 52845, c2 = 22719;
  34983. var count = data.length, maybeLength = count >>> 1;
  34984. var decrypted = new Uint8Array(maybeLength);
  34985. var i, j;
  34986. for (i = 0, j = 0; i < count; i++) {
  34987. var digit1 = data[i];
  34988. if (!isHexDigit(digit1)) {
  34989. continue;
  34990. }
  34991. i++;
  34992. var digit2;
  34993. while (i < count && !isHexDigit(digit2 = data[i])) {
  34994. i++;
  34995. }
  34996. if (i < count) {
  34997. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  34998. decrypted[j++] = value ^ (r >> 8);
  34999. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  35000. }
  35001. }
  35002. return Array.prototype.slice.call(decrypted, discardNumber, j);
  35003. }
  35004. function isSpecial(c) {
  35005. return c === 0x2F || // '/'
  35006. c === 0x5B || c === 0x5D || // '[', ']'
  35007. c === 0x7B || c === 0x7D || // '{', '}'
  35008. c === 0x28 || c === 0x29; // '(', ')'
  35009. }
  35010. function Type1Parser(stream, encrypted) {
  35011. if (encrypted) {
  35012. var data = stream.getBytes();
  35013. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  35014. isHexDigit(data[2]) && isHexDigit(data[3]));
  35015. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  35016. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  35017. }
  35018. this.stream = stream;
  35019. this.nextChar();
  35020. }
  35021. Type1Parser.prototype = {
  35022. readNumberArray: function Type1Parser_readNumberArray() {
  35023. this.getToken(); // read '[' or '{' (arrays can start with either)
  35024. var array = [];
  35025. while (true) {
  35026. var token = this.getToken();
  35027. if (token === null || token === ']' || token === '}') {
  35028. break;
  35029. }
  35030. array.push(parseFloat(token || 0));
  35031. }
  35032. return array;
  35033. },
  35034. readNumber: function Type1Parser_readNumber() {
  35035. var token = this.getToken();
  35036. return parseFloat(token || 0);
  35037. },
  35038. readInt: function Type1Parser_readInt() {
  35039. // Use '| 0' to prevent setting a double into length such as the double
  35040. // does not flow into the loop variable.
  35041. var token = this.getToken();
  35042. return parseInt(token || 0, 10) | 0;
  35043. },
  35044. readBoolean: function Type1Parser_readBoolean() {
  35045. var token = this.getToken();
  35046. // Use 1 and 0 since that's what type2 charstrings use.
  35047. return token === 'true' ? 1 : 0;
  35048. },
  35049. nextChar : function Type1_nextChar() {
  35050. return (this.currentChar = this.stream.getByte());
  35051. },
  35052. getToken: function Type1Parser_getToken() {
  35053. // Eat whitespace and comments.
  35054. var comment = false;
  35055. var ch = this.currentChar;
  35056. while (true) {
  35057. if (ch === -1) {
  35058. return null;
  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. if (isSpecial(ch)) {
  35072. this.nextChar();
  35073. return String.fromCharCode(ch);
  35074. }
  35075. var token = '';
  35076. do {
  35077. token += String.fromCharCode(ch);
  35078. ch = this.nextChar();
  35079. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  35080. return token;
  35081. },
  35082. /*
  35083. * Returns an object containing a Subrs array and a CharStrings
  35084. * array extracted from and eexec encrypted block of data
  35085. */
  35086. extractFontProgram: function Type1Parser_extractFontProgram() {
  35087. var stream = this.stream;
  35088. var subrs = [], charstrings = [];
  35089. var program = {
  35090. subrs: [],
  35091. charstrings: [],
  35092. properties: {
  35093. 'privateData': {
  35094. 'lenIV': 4
  35095. }
  35096. }
  35097. };
  35098. var token, length, data, lenIV, encoded;
  35099. while ((token = this.getToken()) !== null) {
  35100. if (token !== '/') {
  35101. continue;
  35102. }
  35103. token = this.getToken();
  35104. switch (token) {
  35105. case 'CharStrings':
  35106. // The number immediately following CharStrings must be greater or
  35107. // equal to the number of CharStrings.
  35108. this.getToken();
  35109. this.getToken(); // read in 'dict'
  35110. this.getToken(); // read in 'dup'
  35111. this.getToken(); // read in 'begin'
  35112. while(true) {
  35113. token = this.getToken();
  35114. if (token === null || token === 'end') {
  35115. break;
  35116. }
  35117. if (token !== '/') {
  35118. continue;
  35119. }
  35120. var glyph = this.getToken();
  35121. length = this.readInt();
  35122. this.getToken(); // read in 'RD' or '-|'
  35123. data = stream.makeSubStream(stream.pos, length);
  35124. lenIV = program.properties.privateData['lenIV'];
  35125. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35126. // Skip past the required space and binary data.
  35127. stream.skip(length);
  35128. this.nextChar();
  35129. token = this.getToken(); // read in 'ND' or '|-'
  35130. if (token === 'noaccess') {
  35131. this.getToken(); // read in 'def'
  35132. }
  35133. charstrings.push({
  35134. glyph: glyph,
  35135. encoded: encoded
  35136. });
  35137. }
  35138. break;
  35139. case 'Subrs':
  35140. var num = this.readInt();
  35141. this.getToken(); // read in 'array'
  35142. while ((token = this.getToken()) === 'dup') {
  35143. var index = this.readInt();
  35144. length = this.readInt();
  35145. this.getToken(); // read in 'RD' or '-|'
  35146. data = stream.makeSubStream(stream.pos, length);
  35147. lenIV = program.properties.privateData['lenIV'];
  35148. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  35149. // Skip past the required space and binary data.
  35150. stream.skip(length);
  35151. this.nextChar();
  35152. token = this.getToken(); // read in 'NP' or '|'
  35153. if (token === 'noaccess') {
  35154. this.getToken(); // read in 'put'
  35155. }
  35156. subrs[index] = encoded;
  35157. }
  35158. break;
  35159. case 'BlueValues':
  35160. case 'OtherBlues':
  35161. case 'FamilyBlues':
  35162. case 'FamilyOtherBlues':
  35163. var blueArray = this.readNumberArray();
  35164. // *Blue* values may contain invalid data: disables reading of
  35165. // those values when hinting is disabled.
  35166. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  35167. HINTING_ENABLED) {
  35168. program.properties.privateData[token] = blueArray;
  35169. }
  35170. break;
  35171. case 'StemSnapH':
  35172. case 'StemSnapV':
  35173. program.properties.privateData[token] = this.readNumberArray();
  35174. break;
  35175. case 'StdHW':
  35176. case 'StdVW':
  35177. program.properties.privateData[token] =
  35178. this.readNumberArray()[0];
  35179. break;
  35180. case 'BlueShift':
  35181. case 'lenIV':
  35182. case 'BlueFuzz':
  35183. case 'BlueScale':
  35184. case 'LanguageGroup':
  35185. case 'ExpansionFactor':
  35186. program.properties.privateData[token] = this.readNumber();
  35187. break;
  35188. case 'ForceBold':
  35189. program.properties.privateData[token] = this.readBoolean();
  35190. break;
  35191. }
  35192. }
  35193. for (var i = 0; i < charstrings.length; i++) {
  35194. glyph = charstrings[i].glyph;
  35195. encoded = charstrings[i].encoded;
  35196. var charString = new Type1CharString();
  35197. var error = charString.convert(encoded, subrs);
  35198. var output = charString.output;
  35199. if (error) {
  35200. // It seems when FreeType encounters an error while evaluating a glyph
  35201. // that it completely ignores the glyph so we'll mimic that behaviour
  35202. // here and put an endchar to make the validator happy.
  35203. output = [14];
  35204. }
  35205. program.charstrings.push({
  35206. glyphName: glyph,
  35207. charstring: output,
  35208. width: charString.width,
  35209. lsb: charString.lsb,
  35210. seac: charString.seac
  35211. });
  35212. }
  35213. return program;
  35214. },
  35215. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  35216. var token;
  35217. while ((token = this.getToken()) !== null) {
  35218. if (token !== '/') {
  35219. continue;
  35220. }
  35221. token = this.getToken();
  35222. switch (token) {
  35223. case 'FontMatrix':
  35224. var matrix = this.readNumberArray();
  35225. properties.fontMatrix = matrix;
  35226. break;
  35227. case 'Encoding':
  35228. var encodingArg = this.getToken();
  35229. var encoding;
  35230. if (!/^\d+$/.test(encodingArg)) {
  35231. // encoding name is specified
  35232. encoding = Encodings[encodingArg];
  35233. } else {
  35234. encoding = [];
  35235. var size = parseInt(encodingArg, 10) | 0;
  35236. this.getToken(); // read in 'array'
  35237. for (var j = 0; j < size; j++) {
  35238. token = this.getToken();
  35239. // skipping till first dup or def (e.g. ignoring for statement)
  35240. while (token !== 'dup' && token !== 'def') {
  35241. token = this.getToken();
  35242. if (token === null) {
  35243. return; // invalid header
  35244. }
  35245. }
  35246. if (token === 'def') {
  35247. break; // read all array data
  35248. }
  35249. var index = this.readInt();
  35250. this.getToken(); // read in '/'
  35251. var glyph = this.getToken();
  35252. encoding[index] = glyph;
  35253. this.getToken(); // read the in 'put'
  35254. }
  35255. }
  35256. properties.builtInEncoding = encoding;
  35257. break;
  35258. case 'FontBBox':
  35259. var fontBBox = this.readNumberArray();
  35260. // adjusting ascent/descent
  35261. properties.ascent = fontBBox[3];
  35262. properties.descent = fontBBox[1];
  35263. properties.ascentScaled = true;
  35264. break;
  35265. }
  35266. }
  35267. }
  35268. };
  35269. return Type1Parser;
  35270. })();
  35271. /**
  35272. * The CFF class takes a Type1 file and wrap it into a
  35273. * 'Compact Font Format' which itself embed Type2 charstrings.
  35274. */
  35275. var CFFStandardStrings = [
  35276. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  35277. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  35278. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  35279. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  35280. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  35281. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  35282. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  35283. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  35284. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  35285. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  35286. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  35287. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  35288. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  35289. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  35290. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  35291. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  35292. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  35293. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  35294. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  35295. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  35296. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  35297. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  35298. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  35299. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  35300. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  35301. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  35302. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  35303. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  35304. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  35305. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  35306. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  35307. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  35308. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  35309. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  35310. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  35311. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  35312. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  35313. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  35314. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  35315. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  35316. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  35317. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  35318. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  35319. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  35320. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  35321. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  35322. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  35323. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  35324. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  35325. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  35326. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  35327. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  35328. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  35329. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  35330. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  35331. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  35332. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  35333. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  35334. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  35335. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  35336. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  35337. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  35338. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  35339. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  35340. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  35341. ];
  35342. // Type1Font is also a CIDFontType0.
  35343. var Type1Font = function Type1Font(name, file, properties) {
  35344. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  35345. // Also, length1 and length2 might be off by 6 bytes as well.
  35346. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  35347. var PFB_HEADER_SIZE = 6;
  35348. var headerBlockLength = properties.length1;
  35349. var eexecBlockLength = properties.length2;
  35350. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  35351. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  35352. if (pfbHeaderPresent) {
  35353. file.skip(PFB_HEADER_SIZE);
  35354. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35355. (pfbHeader[3] << 8) | pfbHeader[2];
  35356. }
  35357. // Get the data block containing glyphs and subrs informations
  35358. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  35359. var headerBlockParser = new Type1Parser(headerBlock);
  35360. headerBlockParser.extractFontHeader(properties);
  35361. if (pfbHeaderPresent) {
  35362. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  35363. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35364. (pfbHeader[3] << 8) | pfbHeader[2];
  35365. }
  35366. // Decrypt the data blocks and retrieve it's content
  35367. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  35368. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  35369. var data = eexecBlockParser.extractFontProgram();
  35370. for (var info in data.properties) {
  35371. properties[info] = data.properties[info];
  35372. }
  35373. var charstrings = data.charstrings;
  35374. var type2Charstrings = this.getType2Charstrings(charstrings);
  35375. var subrs = this.getType2Subrs(data.subrs);
  35376. this.charstrings = charstrings;
  35377. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  35378. subrs, properties);
  35379. this.seacs = this.getSeacs(data.charstrings);
  35380. };
  35381. Type1Font.prototype = {
  35382. get numGlyphs() {
  35383. return this.charstrings.length + 1;
  35384. },
  35385. getCharset: function Type1Font_getCharset() {
  35386. var charset = ['.notdef'];
  35387. var charstrings = this.charstrings;
  35388. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35389. charset.push(charstrings[glyphId].glyphName);
  35390. }
  35391. return charset;
  35392. },
  35393. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  35394. var charstrings = this.charstrings;
  35395. var glyphNames = ['.notdef'], glyphId;
  35396. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35397. glyphNames.push(charstrings[glyphId].glyphName);
  35398. }
  35399. var encoding = properties.builtInEncoding;
  35400. if (encoding) {
  35401. var builtInEncoding = {};
  35402. for (var charCode in encoding) {
  35403. glyphId = glyphNames.indexOf(encoding[charCode]);
  35404. if (glyphId >= 0) {
  35405. builtInEncoding[charCode] = glyphId;
  35406. }
  35407. }
  35408. }
  35409. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  35410. },
  35411. getSeacs: function Type1Font_getSeacs(charstrings) {
  35412. var i, ii;
  35413. var seacMap = [];
  35414. for (i = 0, ii = charstrings.length; i < ii; i++) {
  35415. var charstring = charstrings[i];
  35416. if (charstring.seac) {
  35417. // Offset by 1 for .notdef
  35418. seacMap[i + 1] = charstring.seac;
  35419. }
  35420. }
  35421. return seacMap;
  35422. },
  35423. getType2Charstrings: function Type1Font_getType2Charstrings(
  35424. type1Charstrings) {
  35425. var type2Charstrings = [];
  35426. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  35427. type2Charstrings.push(type1Charstrings[i].charstring);
  35428. }
  35429. return type2Charstrings;
  35430. },
  35431. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  35432. var bias = 0;
  35433. var count = type1Subrs.length;
  35434. if (count < 1133) {
  35435. bias = 107;
  35436. } else if (count < 33769) {
  35437. bias = 1131;
  35438. } else {
  35439. bias = 32768;
  35440. }
  35441. // Add a bunch of empty subrs to deal with the Type2 bias
  35442. var type2Subrs = [];
  35443. var i;
  35444. for (i = 0; i < bias; i++) {
  35445. type2Subrs.push([0x0B]);
  35446. }
  35447. for (i = 0; i < count; i++) {
  35448. type2Subrs.push(type1Subrs[i]);
  35449. }
  35450. return type2Subrs;
  35451. },
  35452. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  35453. var cff = new CFF();
  35454. cff.header = new CFFHeader(1, 0, 4, 4);
  35455. cff.names = [name];
  35456. var topDict = new CFFTopDict();
  35457. // CFF strings IDs 0...390 are predefined names, so refering
  35458. // to entries in our own String INDEX starts at SID 391.
  35459. topDict.setByName('version', 391);
  35460. topDict.setByName('Notice', 392);
  35461. topDict.setByName('FullName', 393);
  35462. topDict.setByName('FamilyName', 394);
  35463. topDict.setByName('Weight', 395);
  35464. topDict.setByName('Encoding', null); // placeholder
  35465. topDict.setByName('FontMatrix', properties.fontMatrix);
  35466. topDict.setByName('FontBBox', properties.bbox);
  35467. topDict.setByName('charset', null); // placeholder
  35468. topDict.setByName('CharStrings', null); // placeholder
  35469. topDict.setByName('Private', null); // placeholder
  35470. cff.topDict = topDict;
  35471. var strings = new CFFStrings();
  35472. strings.add('Version 0.11'); // Version
  35473. strings.add('See original notice'); // Notice
  35474. strings.add(name); // FullName
  35475. strings.add(name); // FamilyName
  35476. strings.add('Medium'); // Weight
  35477. cff.strings = strings;
  35478. cff.globalSubrIndex = new CFFIndex();
  35479. var count = glyphs.length;
  35480. var charsetArray = [0];
  35481. var i, ii;
  35482. for (i = 0; i < count; i++) {
  35483. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  35484. // TODO: Insert the string and correctly map it. Previously it was
  35485. // thought mapping names that aren't in the standard strings to .notdef
  35486. // was fine, however in issue818 when mapping them all to .notdef the
  35487. // adieresis glyph no longer worked.
  35488. if (index === -1) {
  35489. index = 0;
  35490. }
  35491. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  35492. }
  35493. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  35494. var charStringsIndex = new CFFIndex();
  35495. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  35496. for (i = 0; i < count; i++) {
  35497. charStringsIndex.add(glyphs[i]);
  35498. }
  35499. cff.charStrings = charStringsIndex;
  35500. var privateDict = new CFFPrivateDict();
  35501. privateDict.setByName('Subrs', null); // placeholder
  35502. var fields = [
  35503. 'BlueValues',
  35504. 'OtherBlues',
  35505. 'FamilyBlues',
  35506. 'FamilyOtherBlues',
  35507. 'StemSnapH',
  35508. 'StemSnapV',
  35509. 'BlueShift',
  35510. 'BlueFuzz',
  35511. 'BlueScale',
  35512. 'LanguageGroup',
  35513. 'ExpansionFactor',
  35514. 'ForceBold',
  35515. 'StdHW',
  35516. 'StdVW'
  35517. ];
  35518. for (i = 0, ii = fields.length; i < ii; i++) {
  35519. var field = fields[i];
  35520. if (!properties.privateData.hasOwnProperty(field)) {
  35521. continue;
  35522. }
  35523. var value = properties.privateData[field];
  35524. if (isArray(value)) {
  35525. // All of the private dictionary array data in CFF must be stored as
  35526. // "delta-encoded" numbers.
  35527. for (var j = value.length - 1; j > 0; j--) {
  35528. value[j] -= value[j - 1]; // ... difference from previous value
  35529. }
  35530. }
  35531. privateDict.setByName(field, value);
  35532. }
  35533. cff.topDict.privateDict = privateDict;
  35534. var subrIndex = new CFFIndex();
  35535. for (i = 0, ii = subrs.length; i < ii; i++) {
  35536. subrIndex.add(subrs[i]);
  35537. }
  35538. privateDict.subrsIndex = subrIndex;
  35539. var compiler = new CFFCompiler(cff);
  35540. return compiler.compile();
  35541. }
  35542. };
  35543. var CFFFont = (function CFFFontClosure() {
  35544. function CFFFont(file, properties) {
  35545. this.properties = properties;
  35546. var parser = new CFFParser(file, properties);
  35547. this.cff = parser.parse();
  35548. var compiler = new CFFCompiler(this.cff);
  35549. this.seacs = this.cff.seacs;
  35550. try {
  35551. this.data = compiler.compile();
  35552. } catch (e) {
  35553. warn('Failed to compile font ' + properties.loadedName);
  35554. // There may have just been an issue with the compiler, set the data
  35555. // anyway and hope the font loaded.
  35556. this.data = file;
  35557. }
  35558. }
  35559. CFFFont.prototype = {
  35560. get numGlyphs() {
  35561. return this.cff.charStrings.count;
  35562. },
  35563. getCharset: function CFFFont_getCharset() {
  35564. return this.cff.charset.charset;
  35565. },
  35566. getGlyphMapping: function CFFFont_getGlyphMapping() {
  35567. var cff = this.cff;
  35568. var properties = this.properties;
  35569. var charsets = cff.charset.charset;
  35570. var charCodeToGlyphId;
  35571. var glyphId;
  35572. if (properties.composite) {
  35573. charCodeToGlyphId = Object.create(null);
  35574. if (cff.isCIDFont) {
  35575. // If the font is actually a CID font then we should use the charset
  35576. // to map CIDs to GIDs.
  35577. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  35578. var cid = charsets[glyphId];
  35579. var charCode = properties.cMap.charCodeOf(cid);
  35580. charCodeToGlyphId[charCode] = glyphId;
  35581. }
  35582. } else {
  35583. // If it is NOT actually a CID font then CIDs should be mapped
  35584. // directly to GIDs.
  35585. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  35586. charCodeToGlyphId[glyphId] = glyphId;
  35587. }
  35588. }
  35589. return charCodeToGlyphId;
  35590. }
  35591. var encoding = cff.encoding ? cff.encoding.encoding : null;
  35592. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  35593. return charCodeToGlyphId;
  35594. }
  35595. };
  35596. return CFFFont;
  35597. })();
  35598. var CFFParser = (function CFFParserClosure() {
  35599. var CharstringValidationData = [
  35600. null,
  35601. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  35602. null,
  35603. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  35604. { id: 'vmoveto', min: 1, stackClearing: true },
  35605. { id: 'rlineto', min: 2, resetStack: true },
  35606. { id: 'hlineto', min: 1, resetStack: true },
  35607. { id: 'vlineto', min: 1, resetStack: true },
  35608. { id: 'rrcurveto', min: 6, resetStack: true },
  35609. null,
  35610. { id: 'callsubr', min: 1, undefStack: true },
  35611. { id: 'return', min: 0, undefStack: true },
  35612. null, // 12
  35613. null,
  35614. { id: 'endchar', min: 0, stackClearing: true },
  35615. null,
  35616. null,
  35617. null,
  35618. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  35619. { id: 'hintmask', min: 0, stackClearing: true },
  35620. { id: 'cntrmask', min: 0, stackClearing: true },
  35621. { id: 'rmoveto', min: 2, stackClearing: true },
  35622. { id: 'hmoveto', min: 1, stackClearing: true },
  35623. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  35624. { id: 'rcurveline', min: 8, resetStack: true },
  35625. { id: 'rlinecurve', min: 8, resetStack: true },
  35626. { id: 'vvcurveto', min: 4, resetStack: true },
  35627. { id: 'hhcurveto', min: 4, resetStack: true },
  35628. null, // shortint
  35629. { id: 'callgsubr', min: 1, undefStack: true },
  35630. { id: 'vhcurveto', min: 4, resetStack: true },
  35631. { id: 'hvcurveto', min: 4, resetStack: true }
  35632. ];
  35633. var CharstringValidationData12 = [
  35634. null,
  35635. null,
  35636. null,
  35637. { id: 'and', min: 2, stackDelta: -1 },
  35638. { id: 'or', min: 2, stackDelta: -1 },
  35639. { id: 'not', min: 1, stackDelta: 0 },
  35640. null,
  35641. null,
  35642. null,
  35643. { id: 'abs', min: 1, stackDelta: 0 },
  35644. { id: 'add', min: 2, stackDelta: -1,
  35645. stackFn: function stack_div(stack, index) {
  35646. stack[index - 2] = stack[index - 2] + stack[index - 1];
  35647. }
  35648. },
  35649. { id: 'sub', min: 2, stackDelta: -1,
  35650. stackFn: function stack_div(stack, index) {
  35651. stack[index - 2] = stack[index - 2] - stack[index - 1];
  35652. }
  35653. },
  35654. { id: 'div', min: 2, stackDelta: -1,
  35655. stackFn: function stack_div(stack, index) {
  35656. stack[index - 2] = stack[index - 2] / stack[index - 1];
  35657. }
  35658. },
  35659. null,
  35660. { id: 'neg', min: 1, stackDelta: 0,
  35661. stackFn: function stack_div(stack, index) {
  35662. stack[index - 1] = -stack[index - 1];
  35663. }
  35664. },
  35665. { id: 'eq', min: 2, stackDelta: -1 },
  35666. null,
  35667. null,
  35668. { id: 'drop', min: 1, stackDelta: -1 },
  35669. null,
  35670. { id: 'put', min: 2, stackDelta: -2 },
  35671. { id: 'get', min: 1, stackDelta: 0 },
  35672. { id: 'ifelse', min: 4, stackDelta: -3 },
  35673. { id: 'random', min: 0, stackDelta: 1 },
  35674. { id: 'mul', min: 2, stackDelta: -1,
  35675. stackFn: function stack_div(stack, index) {
  35676. stack[index - 2] = stack[index - 2] * stack[index - 1];
  35677. }
  35678. },
  35679. null,
  35680. { id: 'sqrt', min: 1, stackDelta: 0 },
  35681. { id: 'dup', min: 1, stackDelta: 1 },
  35682. { id: 'exch', min: 2, stackDelta: 0 },
  35683. { id: 'index', min: 2, stackDelta: 0 },
  35684. { id: 'roll', min: 3, stackDelta: -2 },
  35685. null,
  35686. null,
  35687. null,
  35688. { id: 'hflex', min: 7, resetStack: true },
  35689. { id: 'flex', min: 13, resetStack: true },
  35690. { id: 'hflex1', min: 9, resetStack: true },
  35691. { id: 'flex1', min: 11, resetStack: true }
  35692. ];
  35693. function CFFParser(file, properties) {
  35694. this.bytes = file.getBytes();
  35695. this.properties = properties;
  35696. }
  35697. CFFParser.prototype = {
  35698. parse: function CFFParser_parse() {
  35699. var properties = this.properties;
  35700. var cff = new CFF();
  35701. this.cff = cff;
  35702. // The first five sections must be in order, all the others are reached
  35703. // via offsets contained in one of the below.
  35704. var header = this.parseHeader();
  35705. var nameIndex = this.parseIndex(header.endPos);
  35706. var topDictIndex = this.parseIndex(nameIndex.endPos);
  35707. var stringIndex = this.parseIndex(topDictIndex.endPos);
  35708. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  35709. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  35710. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  35711. cff.header = header.obj;
  35712. cff.names = this.parseNameIndex(nameIndex.obj);
  35713. cff.strings = this.parseStringIndex(stringIndex.obj);
  35714. cff.topDict = topDict;
  35715. cff.globalSubrIndex = globalSubrIndex.obj;
  35716. this.parsePrivateDict(cff.topDict);
  35717. cff.isCIDFont = topDict.hasName('ROS');
  35718. var charStringOffset = topDict.getByName('CharStrings');
  35719. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  35720. cff.charStrings = charStringsAndSeacs.charStrings;
  35721. cff.seacs = charStringsAndSeacs.seacs;
  35722. cff.widths = charStringsAndSeacs.widths;
  35723. var fontMatrix = topDict.getByName('FontMatrix');
  35724. if (fontMatrix) {
  35725. properties.fontMatrix = fontMatrix;
  35726. }
  35727. var fontBBox = topDict.getByName('FontBBox');
  35728. if (fontBBox) {
  35729. // adjusting ascent/descent
  35730. properties.ascent = fontBBox[3];
  35731. properties.descent = fontBBox[1];
  35732. properties.ascentScaled = true;
  35733. }
  35734. var charset, encoding;
  35735. if (cff.isCIDFont) {
  35736. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  35737. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  35738. var dictRaw = fdArrayIndex.get(i);
  35739. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  35740. cff.strings);
  35741. this.parsePrivateDict(fontDict);
  35742. cff.fdArray.push(fontDict);
  35743. }
  35744. // cid fonts don't have an encoding
  35745. encoding = null;
  35746. charset = this.parseCharsets(topDict.getByName('charset'),
  35747. cff.charStrings.count, cff.strings, true);
  35748. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  35749. cff.charStrings.count);
  35750. } else {
  35751. charset = this.parseCharsets(topDict.getByName('charset'),
  35752. cff.charStrings.count, cff.strings, false);
  35753. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  35754. properties,
  35755. cff.strings, charset.charset);
  35756. }
  35757. cff.charset = charset;
  35758. cff.encoding = encoding;
  35759. return cff;
  35760. },
  35761. parseHeader: function CFFParser_parseHeader() {
  35762. var bytes = this.bytes;
  35763. var bytesLength = bytes.length;
  35764. var offset = 0;
  35765. // Prevent an infinite loop, by checking that the offset is within the
  35766. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  35767. while (offset < bytesLength && bytes[offset] !== 1) {
  35768. ++offset;
  35769. }
  35770. if (offset >= bytesLength) {
  35771. error('Invalid CFF header');
  35772. } else if (offset !== 0) {
  35773. info('cff data is shifted');
  35774. bytes = bytes.subarray(offset);
  35775. this.bytes = bytes;
  35776. }
  35777. var major = bytes[0];
  35778. var minor = bytes[1];
  35779. var hdrSize = bytes[2];
  35780. var offSize = bytes[3];
  35781. var header = new CFFHeader(major, minor, hdrSize, offSize);
  35782. return { obj: header, endPos: hdrSize };
  35783. },
  35784. parseDict: function CFFParser_parseDict(dict) {
  35785. var pos = 0;
  35786. function parseOperand() {
  35787. var value = dict[pos++];
  35788. if (value === 30) {
  35789. return parseFloatOperand(pos);
  35790. } else if (value === 28) {
  35791. value = dict[pos++];
  35792. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  35793. return value;
  35794. } else if (value === 29) {
  35795. value = dict[pos++];
  35796. value = (value << 8) | dict[pos++];
  35797. value = (value << 8) | dict[pos++];
  35798. value = (value << 8) | dict[pos++];
  35799. return value;
  35800. } else if (value >= 32 && value <= 246) {
  35801. return value - 139;
  35802. } else if (value >= 247 && value <= 250) {
  35803. return ((value - 247) * 256) + dict[pos++] + 108;
  35804. } else if (value >= 251 && value <= 254) {
  35805. return -((value - 251) * 256) - dict[pos++] - 108;
  35806. } else {
  35807. error('255 is not a valid DICT command');
  35808. }
  35809. return -1;
  35810. }
  35811. function parseFloatOperand() {
  35812. var str = '';
  35813. var eof = 15;
  35814. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  35815. '9', '.', 'E', 'E-', null, '-'];
  35816. var length = dict.length;
  35817. while (pos < length) {
  35818. var b = dict[pos++];
  35819. var b1 = b >> 4;
  35820. var b2 = b & 15;
  35821. if (b1 === eof) {
  35822. break;
  35823. }
  35824. str += lookup[b1];
  35825. if (b2 === eof) {
  35826. break;
  35827. }
  35828. str += lookup[b2];
  35829. }
  35830. return parseFloat(str);
  35831. }
  35832. var operands = [];
  35833. var entries = [];
  35834. pos = 0;
  35835. var end = dict.length;
  35836. while (pos < end) {
  35837. var b = dict[pos];
  35838. if (b <= 21) {
  35839. if (b === 12) {
  35840. b = (b << 8) | dict[++pos];
  35841. }
  35842. entries.push([b, operands]);
  35843. operands = [];
  35844. ++pos;
  35845. } else {
  35846. operands.push(parseOperand());
  35847. }
  35848. }
  35849. return entries;
  35850. },
  35851. parseIndex: function CFFParser_parseIndex(pos) {
  35852. var cffIndex = new CFFIndex();
  35853. var bytes = this.bytes;
  35854. var count = (bytes[pos++] << 8) | bytes[pos++];
  35855. var offsets = [];
  35856. var end = pos;
  35857. var i, ii;
  35858. if (count !== 0) {
  35859. var offsetSize = bytes[pos++];
  35860. // add 1 for offset to determine size of last object
  35861. var startPos = pos + ((count + 1) * offsetSize) - 1;
  35862. for (i = 0, ii = count + 1; i < ii; ++i) {
  35863. var offset = 0;
  35864. for (var j = 0; j < offsetSize; ++j) {
  35865. offset <<= 8;
  35866. offset += bytes[pos++];
  35867. }
  35868. offsets.push(startPos + offset);
  35869. }
  35870. end = offsets[count];
  35871. }
  35872. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  35873. var offsetStart = offsets[i];
  35874. var offsetEnd = offsets[i + 1];
  35875. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  35876. }
  35877. return {obj: cffIndex, endPos: end};
  35878. },
  35879. parseNameIndex: function CFFParser_parseNameIndex(index) {
  35880. var names = [];
  35881. for (var i = 0, ii = index.count; i < ii; ++i) {
  35882. var name = index.get(i);
  35883. // OTS doesn't allow names to be over 127 characters.
  35884. var length = Math.min(name.length, 127);
  35885. var data = [];
  35886. // OTS also only permits certain characters in the name.
  35887. for (var j = 0; j < length; ++j) {
  35888. var c = name[j];
  35889. if (j === 0 && c === 0) {
  35890. data[j] = c;
  35891. continue;
  35892. }
  35893. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  35894. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  35895. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  35896. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  35897. data[j] = 95;
  35898. continue;
  35899. }
  35900. data[j] = c;
  35901. }
  35902. names.push(bytesToString(data));
  35903. }
  35904. return names;
  35905. },
  35906. parseStringIndex: function CFFParser_parseStringIndex(index) {
  35907. var strings = new CFFStrings();
  35908. for (var i = 0, ii = index.count; i < ii; ++i) {
  35909. var data = index.get(i);
  35910. strings.add(bytesToString(data));
  35911. }
  35912. return strings;
  35913. },
  35914. createDict: function CFFParser_createDict(Type, dict, strings) {
  35915. var cffDict = new Type(strings);
  35916. for (var i = 0, ii = dict.length; i < ii; ++i) {
  35917. var pair = dict[i];
  35918. var key = pair[0];
  35919. var value = pair[1];
  35920. cffDict.setByKey(key, value);
  35921. }
  35922. return cffDict;
  35923. },
  35924. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  35925. var charStrings = this.parseIndex(charStringOffset).obj;
  35926. var seacs = [];
  35927. var widths = [];
  35928. var count = charStrings.count;
  35929. for (var i = 0; i < count; i++) {
  35930. var charstring = charStrings.get(i);
  35931. var stackSize = 0;
  35932. var stack = [];
  35933. var undefStack = true;
  35934. var hints = 0;
  35935. var valid = true;
  35936. var data = charstring;
  35937. var length = data.length;
  35938. var firstStackClearing = true;
  35939. for (var j = 0; j < length;) {
  35940. var value = data[j++];
  35941. var validationCommand = null;
  35942. if (value === 12) {
  35943. var q = data[j++];
  35944. if (q === 0) {
  35945. // The CFF specification state that the 'dotsection' command
  35946. // (12, 0) is deprecated and treated as a no-op, but all Type2
  35947. // charstrings processors should support them. Unfortunately
  35948. // the font sanitizer don't. As a workaround the sequence (12, 0)
  35949. // is replaced by a useless (0, hmoveto).
  35950. data[j - 2] = 139;
  35951. data[j - 1] = 22;
  35952. stackSize = 0;
  35953. } else {
  35954. validationCommand = CharstringValidationData12[q];
  35955. }
  35956. } else if (value === 28) { // number (16 bit)
  35957. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  35958. j += 2;
  35959. stackSize++;
  35960. } else if (value === 14) {
  35961. if (stackSize >= 4) {
  35962. stackSize -= 4;
  35963. if (SEAC_ANALYSIS_ENABLED) {
  35964. seacs[i] = stack.slice(stackSize, stackSize + 4);
  35965. valid = false;
  35966. }
  35967. }
  35968. validationCommand = CharstringValidationData[value];
  35969. } else if (value >= 32 && value <= 246) { // number
  35970. stack[stackSize] = value - 139;
  35971. stackSize++;
  35972. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  35973. stack[stackSize] = (value < 251 ?
  35974. ((value - 247) << 8) + data[j] + 108 :
  35975. -((value - 251) << 8) - data[j] - 108);
  35976. j++;
  35977. stackSize++;
  35978. } else if (value === 255) { // number (32 bit)
  35979. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  35980. (data[j + 2] << 8) | data[j + 3]) / 65536;
  35981. j += 4;
  35982. stackSize++;
  35983. } else if (value === 19 || value === 20) {
  35984. hints += stackSize >> 1;
  35985. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  35986. stackSize %= 2;
  35987. validationCommand = CharstringValidationData[value];
  35988. } else {
  35989. validationCommand = CharstringValidationData[value];
  35990. }
  35991. if (validationCommand) {
  35992. if (validationCommand.stem) {
  35993. hints += stackSize >> 1;
  35994. }
  35995. if ('min' in validationCommand) {
  35996. if (!undefStack && stackSize < validationCommand.min) {
  35997. warn('Not enough parameters for ' + validationCommand.id +
  35998. '; actual: ' + stackSize +
  35999. ', expected: ' + validationCommand.min);
  36000. valid = false;
  36001. break;
  36002. }
  36003. }
  36004. if (firstStackClearing && validationCommand.stackClearing) {
  36005. firstStackClearing = false;
  36006. // the optional character width can be found before the first
  36007. // stack-clearing command arguments
  36008. stackSize -= validationCommand.min;
  36009. if (stackSize >= 2 && validationCommand.stem) {
  36010. // there are even amount of arguments for stem commands
  36011. stackSize %= 2;
  36012. } else if (stackSize > 1) {
  36013. warn('Found too many parameters for stack-clearing command');
  36014. }
  36015. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  36016. widths[i] = stack[stackSize - 1];
  36017. }
  36018. }
  36019. if ('stackDelta' in validationCommand) {
  36020. if ('stackFn' in validationCommand) {
  36021. validationCommand.stackFn(stack, stackSize);
  36022. }
  36023. stackSize += validationCommand.stackDelta;
  36024. } else if (validationCommand.stackClearing) {
  36025. stackSize = 0;
  36026. } else if (validationCommand.resetStack) {
  36027. stackSize = 0;
  36028. undefStack = false;
  36029. } else if (validationCommand.undefStack) {
  36030. stackSize = 0;
  36031. undefStack = true;
  36032. firstStackClearing = false;
  36033. }
  36034. }
  36035. }
  36036. if (!valid) {
  36037. // resetting invalid charstring to single 'endchar'
  36038. charStrings.set(i, new Uint8Array([14]));
  36039. }
  36040. }
  36041. return { charStrings: charStrings, seacs: seacs, widths: widths };
  36042. },
  36043. emptyPrivateDictionary:
  36044. function CFFParser_emptyPrivateDictionary(parentDict) {
  36045. var privateDict = this.createDict(CFFPrivateDict, [],
  36046. parentDict.strings);
  36047. parentDict.setByKey(18, [0, 0]);
  36048. parentDict.privateDict = privateDict;
  36049. },
  36050. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  36051. // no private dict, do nothing
  36052. if (!parentDict.hasName('Private')) {
  36053. this.emptyPrivateDictionary(parentDict);
  36054. return;
  36055. }
  36056. var privateOffset = parentDict.getByName('Private');
  36057. // make sure the params are formatted correctly
  36058. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  36059. parentDict.removeByName('Private');
  36060. return;
  36061. }
  36062. var size = privateOffset[0];
  36063. var offset = privateOffset[1];
  36064. // remove empty dicts or ones that refer to invalid location
  36065. if (size === 0 || offset >= this.bytes.length) {
  36066. this.emptyPrivateDictionary(parentDict);
  36067. return;
  36068. }
  36069. var privateDictEnd = offset + size;
  36070. var dictData = this.bytes.subarray(offset, privateDictEnd);
  36071. var dict = this.parseDict(dictData);
  36072. var privateDict = this.createDict(CFFPrivateDict, dict,
  36073. parentDict.strings);
  36074. parentDict.privateDict = privateDict;
  36075. // Parse the Subrs index also since it's relative to the private dict.
  36076. if (!privateDict.getByName('Subrs')) {
  36077. return;
  36078. }
  36079. var subrsOffset = privateDict.getByName('Subrs');
  36080. var relativeOffset = offset + subrsOffset;
  36081. // Validate the offset.
  36082. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  36083. this.emptyPrivateDictionary(parentDict);
  36084. return;
  36085. }
  36086. var subrsIndex = this.parseIndex(relativeOffset);
  36087. privateDict.subrsIndex = subrsIndex.obj;
  36088. },
  36089. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  36090. if (pos === 0) {
  36091. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  36092. ISOAdobeCharset);
  36093. } else if (pos === 1) {
  36094. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  36095. ExpertCharset);
  36096. } else if (pos === 2) {
  36097. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  36098. ExpertSubsetCharset);
  36099. }
  36100. var bytes = this.bytes;
  36101. var start = pos;
  36102. var format = bytes[pos++];
  36103. var charset = ['.notdef'];
  36104. var id, count, i;
  36105. // subtract 1 for the .notdef glyph
  36106. length -= 1;
  36107. switch (format) {
  36108. case 0:
  36109. for (i = 0; i < length; i++) {
  36110. id = (bytes[pos++] << 8) | bytes[pos++];
  36111. charset.push(cid ? id : strings.get(id));
  36112. }
  36113. break;
  36114. case 1:
  36115. while (charset.length <= length) {
  36116. id = (bytes[pos++] << 8) | bytes[pos++];
  36117. count = bytes[pos++];
  36118. for (i = 0; i <= count; i++) {
  36119. charset.push(cid ? id++ : strings.get(id++));
  36120. }
  36121. }
  36122. break;
  36123. case 2:
  36124. while (charset.length <= length) {
  36125. id = (bytes[pos++] << 8) | bytes[pos++];
  36126. count = (bytes[pos++] << 8) | bytes[pos++];
  36127. for (i = 0; i <= count; i++) {
  36128. charset.push(cid ? id++ : strings.get(id++));
  36129. }
  36130. }
  36131. break;
  36132. default:
  36133. error('Unknown charset format');
  36134. }
  36135. // Raw won't be needed if we actually compile the charset.
  36136. var end = pos;
  36137. var raw = bytes.subarray(start, end);
  36138. return new CFFCharset(false, format, charset, raw);
  36139. },
  36140. parseEncoding: function CFFParser_parseEncoding(pos,
  36141. properties,
  36142. strings,
  36143. charset) {
  36144. var encoding = {};
  36145. var bytes = this.bytes;
  36146. var predefined = false;
  36147. var hasSupplement = false;
  36148. var format, i, ii;
  36149. var raw = null;
  36150. function readSupplement() {
  36151. var supplementsCount = bytes[pos++];
  36152. for (i = 0; i < supplementsCount; i++) {
  36153. var code = bytes[pos++];
  36154. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  36155. encoding[code] = charset.indexOf(strings.get(sid));
  36156. }
  36157. }
  36158. if (pos === 0 || pos === 1) {
  36159. predefined = true;
  36160. format = pos;
  36161. var baseEncoding = pos ? Encodings.ExpertEncoding :
  36162. Encodings.StandardEncoding;
  36163. for (i = 0, ii = charset.length; i < ii; i++) {
  36164. var index = baseEncoding.indexOf(charset[i]);
  36165. if (index !== -1) {
  36166. encoding[index] = i;
  36167. }
  36168. }
  36169. } else {
  36170. var dataStart = pos;
  36171. format = bytes[pos++];
  36172. switch (format & 0x7f) {
  36173. case 0:
  36174. var glyphsCount = bytes[pos++];
  36175. for (i = 1; i <= glyphsCount; i++) {
  36176. encoding[bytes[pos++]] = i;
  36177. }
  36178. break;
  36179. case 1:
  36180. var rangesCount = bytes[pos++];
  36181. var gid = 1;
  36182. for (i = 0; i < rangesCount; i++) {
  36183. var start = bytes[pos++];
  36184. var left = bytes[pos++];
  36185. for (var j = start; j <= start + left; j++) {
  36186. encoding[j] = gid++;
  36187. }
  36188. }
  36189. break;
  36190. default:
  36191. error('Unknow encoding format: ' + format + ' in CFF');
  36192. break;
  36193. }
  36194. var dataEnd = pos;
  36195. if (format & 0x80) {
  36196. // The font sanitizer does not support CFF encoding with a
  36197. // supplement, since the encoding is not really used to map
  36198. // between gid to glyph, let's overwrite what is declared in
  36199. // the top dictionary to let the sanitizer think the font use
  36200. // StandardEncoding, that's a lie but that's ok.
  36201. bytes[dataStart] &= 0x7f;
  36202. readSupplement();
  36203. hasSupplement = true;
  36204. }
  36205. raw = bytes.subarray(dataStart, dataEnd);
  36206. }
  36207. format = format & 0x7f;
  36208. return new CFFEncoding(predefined, format, encoding, raw);
  36209. },
  36210. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  36211. var start = pos;
  36212. var bytes = this.bytes;
  36213. var format = bytes[pos++];
  36214. var fdSelect = [];
  36215. var i;
  36216. switch (format) {
  36217. case 0:
  36218. for (i = 0; i < length; ++i) {
  36219. var id = bytes[pos++];
  36220. fdSelect.push(id);
  36221. }
  36222. break;
  36223. case 3:
  36224. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  36225. for (i = 0; i < rangesCount; ++i) {
  36226. var first = (bytes[pos++] << 8) | bytes[pos++];
  36227. var fdIndex = bytes[pos++];
  36228. var next = (bytes[pos] << 8) | bytes[pos + 1];
  36229. for (var j = first; j < next; ++j) {
  36230. fdSelect.push(fdIndex);
  36231. }
  36232. }
  36233. // Advance past the sentinel(next).
  36234. pos += 2;
  36235. break;
  36236. default:
  36237. error('Unknown fdselect format ' + format);
  36238. break;
  36239. }
  36240. var end = pos;
  36241. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  36242. }
  36243. };
  36244. return CFFParser;
  36245. })();
  36246. // Compact Font Format
  36247. var CFF = (function CFFClosure() {
  36248. function CFF() {
  36249. this.header = null;
  36250. this.names = [];
  36251. this.topDict = null;
  36252. this.strings = new CFFStrings();
  36253. this.globalSubrIndex = null;
  36254. // The following could really be per font, but since we only have one font
  36255. // store them here.
  36256. this.encoding = null;
  36257. this.charset = null;
  36258. this.charStrings = null;
  36259. this.fdArray = [];
  36260. this.fdSelect = null;
  36261. this.isCIDFont = false;
  36262. }
  36263. return CFF;
  36264. })();
  36265. var CFFHeader = (function CFFHeaderClosure() {
  36266. function CFFHeader(major, minor, hdrSize, offSize) {
  36267. this.major = major;
  36268. this.minor = minor;
  36269. this.hdrSize = hdrSize;
  36270. this.offSize = offSize;
  36271. }
  36272. return CFFHeader;
  36273. })();
  36274. var CFFStrings = (function CFFStringsClosure() {
  36275. function CFFStrings() {
  36276. this.strings = [];
  36277. }
  36278. CFFStrings.prototype = {
  36279. get: function CFFStrings_get(index) {
  36280. if (index >= 0 && index <= 390) {
  36281. return CFFStandardStrings[index];
  36282. }
  36283. if (index - 391 <= this.strings.length) {
  36284. return this.strings[index - 391];
  36285. }
  36286. return CFFStandardStrings[0];
  36287. },
  36288. add: function CFFStrings_add(value) {
  36289. this.strings.push(value);
  36290. },
  36291. get count() {
  36292. return this.strings.length;
  36293. }
  36294. };
  36295. return CFFStrings;
  36296. })();
  36297. var CFFIndex = (function CFFIndexClosure() {
  36298. function CFFIndex() {
  36299. this.objects = [];
  36300. this.length = 0;
  36301. }
  36302. CFFIndex.prototype = {
  36303. add: function CFFIndex_add(data) {
  36304. this.length += data.length;
  36305. this.objects.push(data);
  36306. },
  36307. set: function CFFIndex_set(index, data) {
  36308. this.length += data.length - this.objects[index].length;
  36309. this.objects[index] = data;
  36310. },
  36311. get: function CFFIndex_get(index) {
  36312. return this.objects[index];
  36313. },
  36314. get count() {
  36315. return this.objects.length;
  36316. }
  36317. };
  36318. return CFFIndex;
  36319. })();
  36320. var CFFDict = (function CFFDictClosure() {
  36321. function CFFDict(tables, strings) {
  36322. this.keyToNameMap = tables.keyToNameMap;
  36323. this.nameToKeyMap = tables.nameToKeyMap;
  36324. this.defaults = tables.defaults;
  36325. this.types = tables.types;
  36326. this.opcodes = tables.opcodes;
  36327. this.order = tables.order;
  36328. this.strings = strings;
  36329. this.values = {};
  36330. }
  36331. CFFDict.prototype = {
  36332. // value should always be an array
  36333. setByKey: function CFFDict_setByKey(key, value) {
  36334. if (!(key in this.keyToNameMap)) {
  36335. return false;
  36336. }
  36337. // ignore empty values
  36338. if (value.length === 0) {
  36339. return true;
  36340. }
  36341. var type = this.types[key];
  36342. // remove the array wrapping these types of values
  36343. if (type === 'num' || type === 'sid' || type === 'offset') {
  36344. value = value[0];
  36345. }
  36346. this.values[key] = value;
  36347. return true;
  36348. },
  36349. setByName: function CFFDict_setByName(name, value) {
  36350. if (!(name in this.nameToKeyMap)) {
  36351. error('Invalid dictionary name "' + name + '"');
  36352. }
  36353. this.values[this.nameToKeyMap[name]] = value;
  36354. },
  36355. hasName: function CFFDict_hasName(name) {
  36356. return this.nameToKeyMap[name] in this.values;
  36357. },
  36358. getByName: function CFFDict_getByName(name) {
  36359. if (!(name in this.nameToKeyMap)) {
  36360. error('Invalid dictionary name "' + name + '"');
  36361. }
  36362. var key = this.nameToKeyMap[name];
  36363. if (!(key in this.values)) {
  36364. return this.defaults[key];
  36365. }
  36366. return this.values[key];
  36367. },
  36368. removeByName: function CFFDict_removeByName(name) {
  36369. delete this.values[this.nameToKeyMap[name]];
  36370. }
  36371. };
  36372. CFFDict.createTables = function CFFDict_createTables(layout) {
  36373. var tables = {
  36374. keyToNameMap: {},
  36375. nameToKeyMap: {},
  36376. defaults: {},
  36377. types: {},
  36378. opcodes: {},
  36379. order: []
  36380. };
  36381. for (var i = 0, ii = layout.length; i < ii; ++i) {
  36382. var entry = layout[i];
  36383. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  36384. tables.keyToNameMap[key] = entry[1];
  36385. tables.nameToKeyMap[entry[1]] = key;
  36386. tables.types[key] = entry[2];
  36387. tables.defaults[key] = entry[3];
  36388. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  36389. tables.order.push(key);
  36390. }
  36391. return tables;
  36392. };
  36393. return CFFDict;
  36394. })();
  36395. var CFFTopDict = (function CFFTopDictClosure() {
  36396. var layout = [
  36397. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  36398. [[12, 20], 'SyntheticBase', 'num', null],
  36399. [0, 'version', 'sid', null],
  36400. [1, 'Notice', 'sid', null],
  36401. [[12, 0], 'Copyright', 'sid', null],
  36402. [2, 'FullName', 'sid', null],
  36403. [3, 'FamilyName', 'sid', null],
  36404. [4, 'Weight', 'sid', null],
  36405. [[12, 1], 'isFixedPitch', 'num', 0],
  36406. [[12, 2], 'ItalicAngle', 'num', 0],
  36407. [[12, 3], 'UnderlinePosition', 'num', -100],
  36408. [[12, 4], 'UnderlineThickness', 'num', 50],
  36409. [[12, 5], 'PaintType', 'num', 0],
  36410. [[12, 6], 'CharstringType', 'num', 2],
  36411. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  36412. [0.001, 0, 0, 0.001, 0, 0]],
  36413. [13, 'UniqueID', 'num', null],
  36414. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  36415. [[12, 8], 'StrokeWidth', 'num', 0],
  36416. [14, 'XUID', 'array', null],
  36417. [15, 'charset', 'offset', 0],
  36418. [16, 'Encoding', 'offset', 0],
  36419. [17, 'CharStrings', 'offset', 0],
  36420. [18, 'Private', ['offset', 'offset'], null],
  36421. [[12, 21], 'PostScript', 'sid', null],
  36422. [[12, 22], 'BaseFontName', 'sid', null],
  36423. [[12, 23], 'BaseFontBlend', 'delta', null],
  36424. [[12, 31], 'CIDFontVersion', 'num', 0],
  36425. [[12, 32], 'CIDFontRevision', 'num', 0],
  36426. [[12, 33], 'CIDFontType', 'num', 0],
  36427. [[12, 34], 'CIDCount', 'num', 8720],
  36428. [[12, 35], 'UIDBase', 'num', null],
  36429. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  36430. // before FDArray.
  36431. [[12, 37], 'FDSelect', 'offset', null],
  36432. [[12, 36], 'FDArray', 'offset', null],
  36433. [[12, 38], 'FontName', 'sid', null]
  36434. ];
  36435. var tables = null;
  36436. function CFFTopDict(strings) {
  36437. if (tables === null) {
  36438. tables = CFFDict.createTables(layout);
  36439. }
  36440. CFFDict.call(this, tables, strings);
  36441. this.privateDict = null;
  36442. }
  36443. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  36444. return CFFTopDict;
  36445. })();
  36446. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  36447. var layout = [
  36448. [6, 'BlueValues', 'delta', null],
  36449. [7, 'OtherBlues', 'delta', null],
  36450. [8, 'FamilyBlues', 'delta', null],
  36451. [9, 'FamilyOtherBlues', 'delta', null],
  36452. [[12, 9], 'BlueScale', 'num', 0.039625],
  36453. [[12, 10], 'BlueShift', 'num', 7],
  36454. [[12, 11], 'BlueFuzz', 'num', 1],
  36455. [10, 'StdHW', 'num', null],
  36456. [11, 'StdVW', 'num', null],
  36457. [[12, 12], 'StemSnapH', 'delta', null],
  36458. [[12, 13], 'StemSnapV', 'delta', null],
  36459. [[12, 14], 'ForceBold', 'num', 0],
  36460. [[12, 17], 'LanguageGroup', 'num', 0],
  36461. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  36462. [[12, 19], 'initialRandomSeed', 'num', 0],
  36463. [20, 'defaultWidthX', 'num', 0],
  36464. [21, 'nominalWidthX', 'num', 0],
  36465. [19, 'Subrs', 'offset', null]
  36466. ];
  36467. var tables = null;
  36468. function CFFPrivateDict(strings) {
  36469. if (tables === null) {
  36470. tables = CFFDict.createTables(layout);
  36471. }
  36472. CFFDict.call(this, tables, strings);
  36473. this.subrsIndex = null;
  36474. }
  36475. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  36476. return CFFPrivateDict;
  36477. })();
  36478. var CFFCharsetPredefinedTypes = {
  36479. ISO_ADOBE: 0,
  36480. EXPERT: 1,
  36481. EXPERT_SUBSET: 2
  36482. };
  36483. var CFFCharset = (function CFFCharsetClosure() {
  36484. function CFFCharset(predefined, format, charset, raw) {
  36485. this.predefined = predefined;
  36486. this.format = format;
  36487. this.charset = charset;
  36488. this.raw = raw;
  36489. }
  36490. return CFFCharset;
  36491. })();
  36492. var CFFEncoding = (function CFFEncodingClosure() {
  36493. function CFFEncoding(predefined, format, encoding, raw) {
  36494. this.predefined = predefined;
  36495. this.format = format;
  36496. this.encoding = encoding;
  36497. this.raw = raw;
  36498. }
  36499. return CFFEncoding;
  36500. })();
  36501. var CFFFDSelect = (function CFFFDSelectClosure() {
  36502. function CFFFDSelect(fdSelect, raw) {
  36503. this.fdSelect = fdSelect;
  36504. this.raw = raw;
  36505. }
  36506. return CFFFDSelect;
  36507. })();
  36508. // Helper class to keep track of where an offset is within the data and helps
  36509. // filling in that offset once it's known.
  36510. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  36511. function CFFOffsetTracker() {
  36512. this.offsets = {};
  36513. }
  36514. CFFOffsetTracker.prototype = {
  36515. isTracking: function CFFOffsetTracker_isTracking(key) {
  36516. return key in this.offsets;
  36517. },
  36518. track: function CFFOffsetTracker_track(key, location) {
  36519. if (key in this.offsets) {
  36520. error('Already tracking location of ' + key);
  36521. }
  36522. this.offsets[key] = location;
  36523. },
  36524. offset: function CFFOffsetTracker_offset(value) {
  36525. for (var key in this.offsets) {
  36526. this.offsets[key] += value;
  36527. }
  36528. },
  36529. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  36530. values,
  36531. output) {
  36532. if (!(key in this.offsets)) {
  36533. error('Not tracking location of ' + key);
  36534. }
  36535. var data = output.data;
  36536. var dataOffset = this.offsets[key];
  36537. var size = 5;
  36538. for (var i = 0, ii = values.length; i < ii; ++i) {
  36539. var offset0 = i * size + dataOffset;
  36540. var offset1 = offset0 + 1;
  36541. var offset2 = offset0 + 2;
  36542. var offset3 = offset0 + 3;
  36543. var offset4 = offset0 + 4;
  36544. // It's easy to screw up offsets so perform this sanity check.
  36545. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  36546. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  36547. error('writing to an offset that is not empty');
  36548. }
  36549. var value = values[i];
  36550. data[offset0] = 0x1d;
  36551. data[offset1] = (value >> 24) & 0xFF;
  36552. data[offset2] = (value >> 16) & 0xFF;
  36553. data[offset3] = (value >> 8) & 0xFF;
  36554. data[offset4] = value & 0xFF;
  36555. }
  36556. }
  36557. };
  36558. return CFFOffsetTracker;
  36559. })();
  36560. // Takes a CFF and converts it to the binary representation.
  36561. var CFFCompiler = (function CFFCompilerClosure() {
  36562. function CFFCompiler(cff) {
  36563. this.cff = cff;
  36564. }
  36565. CFFCompiler.prototype = {
  36566. compile: function CFFCompiler_compile() {
  36567. var cff = this.cff;
  36568. var output = {
  36569. data: [],
  36570. length: 0,
  36571. add: function CFFCompiler_add(data) {
  36572. this.data = this.data.concat(data);
  36573. this.length = this.data.length;
  36574. }
  36575. };
  36576. // Compile the five entries that must be in order.
  36577. var header = this.compileHeader(cff.header);
  36578. output.add(header);
  36579. var nameIndex = this.compileNameIndex(cff.names);
  36580. output.add(nameIndex);
  36581. if (cff.isCIDFont) {
  36582. // The spec is unclear on how font matrices should relate to each other
  36583. // when there is one in the main top dict and the sub top dicts.
  36584. // Windows handles this differently than linux and osx so we have to
  36585. // normalize to work on all.
  36586. // Rules based off of some mailing list discussions:
  36587. // - If main font has a matrix and subfont doesn't, use the main matrix.
  36588. // - If no main font matrix and there is a subfont matrix, use the
  36589. // subfont matrix.
  36590. // - If both have matrices, concat together.
  36591. // - If neither have matrices, use default.
  36592. // To make this work on all platforms we move the top matrix into each
  36593. // sub top dict and concat if necessary.
  36594. if (cff.topDict.hasName('FontMatrix')) {
  36595. var base = cff.topDict.getByName('FontMatrix');
  36596. cff.topDict.removeByName('FontMatrix');
  36597. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  36598. var subDict = cff.fdArray[i];
  36599. var matrix = base.slice(0);
  36600. if (subDict.hasName('FontMatrix')) {
  36601. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  36602. }
  36603. subDict.setByName('FontMatrix', matrix);
  36604. }
  36605. }
  36606. }
  36607. var compiled = this.compileTopDicts([cff.topDict],
  36608. output.length,
  36609. cff.isCIDFont);
  36610. output.add(compiled.output);
  36611. var topDictTracker = compiled.trackers[0];
  36612. var stringIndex = this.compileStringIndex(cff.strings.strings);
  36613. output.add(stringIndex);
  36614. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  36615. output.add(globalSubrIndex);
  36616. // Now start on the other entries that have no specfic order.
  36617. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  36618. if (cff.encoding.predefined) {
  36619. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  36620. output);
  36621. } else {
  36622. var encoding = this.compileEncoding(cff.encoding);
  36623. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  36624. output.add(encoding);
  36625. }
  36626. }
  36627. if (cff.charset && cff.topDict.hasName('charset')) {
  36628. if (cff.charset.predefined) {
  36629. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  36630. output);
  36631. } else {
  36632. var charset = this.compileCharset(cff.charset);
  36633. topDictTracker.setEntryLocation('charset', [output.length], output);
  36634. output.add(charset);
  36635. }
  36636. }
  36637. var charStrings = this.compileCharStrings(cff.charStrings);
  36638. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  36639. output.add(charStrings);
  36640. if (cff.isCIDFont) {
  36641. // For some reason FDSelect must be in front of FDArray on windows. OSX
  36642. // and linux don't seem to care.
  36643. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  36644. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  36645. output.add(fdSelect);
  36646. // It is unclear if the sub font dictionary can have CID related
  36647. // dictionary keys, but the sanitizer doesn't like them so remove them.
  36648. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  36649. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  36650. output.add(compiled.output);
  36651. var fontDictTrackers = compiled.trackers;
  36652. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  36653. }
  36654. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  36655. // If the font data ends with INDEX whose object data is zero-length,
  36656. // the sanitizer will bail out. Add a dummy byte to avoid that.
  36657. output.add([0]);
  36658. return output.data;
  36659. },
  36660. encodeNumber: function CFFCompiler_encodeNumber(value) {
  36661. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  36662. return this.encodeInteger(value);
  36663. } else {
  36664. return this.encodeFloat(value);
  36665. }
  36666. },
  36667. encodeFloat: function CFFCompiler_encodeFloat(num) {
  36668. var value = num.toString();
  36669. // rounding inaccurate doubles
  36670. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  36671. if (m) {
  36672. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  36673. value = (Math.round(num * epsilon) / epsilon).toString();
  36674. }
  36675. var nibbles = '';
  36676. var i, ii;
  36677. for (i = 0, ii = value.length; i < ii; ++i) {
  36678. var a = value[i];
  36679. if (a === 'e') {
  36680. nibbles += value[++i] === '-' ? 'c' : 'b';
  36681. } else if (a === '.') {
  36682. nibbles += 'a';
  36683. } else if (a === '-') {
  36684. nibbles += 'e';
  36685. } else {
  36686. nibbles += a;
  36687. }
  36688. }
  36689. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  36690. var out = [30];
  36691. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  36692. out.push(parseInt(nibbles.substr(i, 2), 16));
  36693. }
  36694. return out;
  36695. },
  36696. encodeInteger: function CFFCompiler_encodeInteger(value) {
  36697. var code;
  36698. if (value >= -107 && value <= 107) {
  36699. code = [value + 139];
  36700. } else if (value >= 108 && value <= 1131) {
  36701. value = [value - 108];
  36702. code = [(value >> 8) + 247, value & 0xFF];
  36703. } else if (value >= -1131 && value <= -108) {
  36704. value = -value - 108;
  36705. code = [(value >> 8) + 251, value & 0xFF];
  36706. } else if (value >= -32768 && value <= 32767) {
  36707. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  36708. } else {
  36709. code = [0x1d,
  36710. (value >> 24) & 0xFF,
  36711. (value >> 16) & 0xFF,
  36712. (value >> 8) & 0xFF,
  36713. value & 0xFF];
  36714. }
  36715. return code;
  36716. },
  36717. compileHeader: function CFFCompiler_compileHeader(header) {
  36718. return [
  36719. header.major,
  36720. header.minor,
  36721. header.hdrSize,
  36722. header.offSize
  36723. ];
  36724. },
  36725. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  36726. var nameIndex = new CFFIndex();
  36727. for (var i = 0, ii = names.length; i < ii; ++i) {
  36728. nameIndex.add(stringToBytes(names[i]));
  36729. }
  36730. return this.compileIndex(nameIndex);
  36731. },
  36732. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  36733. length,
  36734. removeCidKeys) {
  36735. var fontDictTrackers = [];
  36736. var fdArrayIndex = new CFFIndex();
  36737. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36738. var fontDict = dicts[i];
  36739. if (removeCidKeys) {
  36740. fontDict.removeByName('CIDFontVersion');
  36741. fontDict.removeByName('CIDFontRevision');
  36742. fontDict.removeByName('CIDFontType');
  36743. fontDict.removeByName('CIDCount');
  36744. fontDict.removeByName('UIDBase');
  36745. }
  36746. var fontDictTracker = new CFFOffsetTracker();
  36747. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  36748. fontDictTrackers.push(fontDictTracker);
  36749. fdArrayIndex.add(fontDictData);
  36750. fontDictTracker.offset(length);
  36751. }
  36752. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  36753. return {
  36754. trackers: fontDictTrackers,
  36755. output: fdArrayIndex
  36756. };
  36757. },
  36758. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  36759. trackers,
  36760. output) {
  36761. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36762. var fontDict = dicts[i];
  36763. assert(fontDict.privateDict && fontDict.hasName('Private'),
  36764. 'There must be an private dictionary.');
  36765. var privateDict = fontDict.privateDict;
  36766. var privateDictTracker = new CFFOffsetTracker();
  36767. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  36768. var outputLength = output.length;
  36769. privateDictTracker.offset(outputLength);
  36770. if (!privateDictData.length) {
  36771. // The private dictionary was empty, set the output length to zero to
  36772. // ensure the offset length isn't out of bounds in the eyes of the
  36773. // sanitizer.
  36774. outputLength = 0;
  36775. }
  36776. trackers[i].setEntryLocation('Private',
  36777. [privateDictData.length, outputLength],
  36778. output);
  36779. output.add(privateDictData);
  36780. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  36781. var subrs = this.compileIndex(privateDict.subrsIndex);
  36782. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  36783. output);
  36784. output.add(subrs);
  36785. }
  36786. }
  36787. },
  36788. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  36789. var out = [];
  36790. // The dictionary keys must be in a certain order.
  36791. var order = dict.order;
  36792. for (var i = 0; i < order.length; ++i) {
  36793. var key = order[i];
  36794. if (!(key in dict.values)) {
  36795. continue;
  36796. }
  36797. var values = dict.values[key];
  36798. var types = dict.types[key];
  36799. if (!isArray(types)) {
  36800. types = [types];
  36801. }
  36802. if (!isArray(values)) {
  36803. values = [values];
  36804. }
  36805. // Remove any empty dict values.
  36806. if (values.length === 0) {
  36807. continue;
  36808. }
  36809. for (var j = 0, jj = types.length; j < jj; ++j) {
  36810. var type = types[j];
  36811. var value = values[j];
  36812. switch (type) {
  36813. case 'num':
  36814. case 'sid':
  36815. out = out.concat(this.encodeNumber(value));
  36816. break;
  36817. case 'offset':
  36818. // For offsets we just insert a 32bit integer so we don't have to
  36819. // deal with figuring out the length of the offset when it gets
  36820. // replaced later on by the compiler.
  36821. var name = dict.keyToNameMap[key];
  36822. // Some offsets have the offset and the length, so just record the
  36823. // position of the first one.
  36824. if (!offsetTracker.isTracking(name)) {
  36825. offsetTracker.track(name, out.length);
  36826. }
  36827. out = out.concat([0x1d, 0, 0, 0, 0]);
  36828. break;
  36829. case 'array':
  36830. case 'delta':
  36831. out = out.concat(this.encodeNumber(value));
  36832. for (var k = 1, kk = values.length; k < kk; ++k) {
  36833. out = out.concat(this.encodeNumber(values[k]));
  36834. }
  36835. break;
  36836. default:
  36837. error('Unknown data type of ' + type);
  36838. break;
  36839. }
  36840. }
  36841. out = out.concat(dict.opcodes[key]);
  36842. }
  36843. return out;
  36844. },
  36845. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  36846. var stringIndex = new CFFIndex();
  36847. for (var i = 0, ii = strings.length; i < ii; ++i) {
  36848. stringIndex.add(stringToBytes(strings[i]));
  36849. }
  36850. return this.compileIndex(stringIndex);
  36851. },
  36852. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  36853. var globalSubrIndex = this.cff.globalSubrIndex;
  36854. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  36855. },
  36856. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  36857. return this.compileIndex(charStrings);
  36858. },
  36859. compileCharset: function CFFCompiler_compileCharset(charset) {
  36860. return this.compileTypedArray(charset.raw);
  36861. },
  36862. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  36863. return this.compileTypedArray(encoding.raw);
  36864. },
  36865. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  36866. return this.compileTypedArray(fdSelect);
  36867. },
  36868. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  36869. var out = [];
  36870. for (var i = 0, ii = data.length; i < ii; ++i) {
  36871. out[i] = data[i];
  36872. }
  36873. return out;
  36874. },
  36875. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  36876. trackers = trackers || [];
  36877. var objects = index.objects;
  36878. // First 2 bytes contains the number of objects contained into this index
  36879. var count = objects.length;
  36880. // If there is no object, just create an index. This technically
  36881. // should just be [0, 0] but OTS has an issue with that.
  36882. if (count === 0) {
  36883. return [0, 0, 0];
  36884. }
  36885. var data = [(count >> 8) & 0xFF, count & 0xff];
  36886. var lastOffset = 1, i;
  36887. for (i = 0; i < count; ++i) {
  36888. lastOffset += objects[i].length;
  36889. }
  36890. var offsetSize;
  36891. if (lastOffset < 0x100) {
  36892. offsetSize = 1;
  36893. } else if (lastOffset < 0x10000) {
  36894. offsetSize = 2;
  36895. } else if (lastOffset < 0x1000000) {
  36896. offsetSize = 3;
  36897. } else {
  36898. offsetSize = 4;
  36899. }
  36900. // Next byte contains the offset size use to reference object in the file
  36901. data.push(offsetSize);
  36902. // Add another offset after this one because we need a new offset
  36903. var relativeOffset = 1;
  36904. for (i = 0; i < count + 1; i++) {
  36905. if (offsetSize === 1) {
  36906. data.push(relativeOffset & 0xFF);
  36907. } else if (offsetSize === 2) {
  36908. data.push((relativeOffset >> 8) & 0xFF,
  36909. relativeOffset & 0xFF);
  36910. } else if (offsetSize === 3) {
  36911. data.push((relativeOffset >> 16) & 0xFF,
  36912. (relativeOffset >> 8) & 0xFF,
  36913. relativeOffset & 0xFF);
  36914. } else {
  36915. data.push((relativeOffset >>> 24) & 0xFF,
  36916. (relativeOffset >> 16) & 0xFF,
  36917. (relativeOffset >> 8) & 0xFF,
  36918. relativeOffset & 0xFF);
  36919. }
  36920. if (objects[i]) {
  36921. relativeOffset += objects[i].length;
  36922. }
  36923. }
  36924. for (i = 0; i < count; i++) {
  36925. // Notify the tracker where the object will be offset in the data.
  36926. if (trackers[i]) {
  36927. trackers[i].offset(data.length);
  36928. }
  36929. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  36930. data.push(objects[i][j]);
  36931. }
  36932. }
  36933. return data;
  36934. }
  36935. };
  36936. return CFFCompiler;
  36937. })();
  36938. function _enableSeacAnalysis(enabled) {
  36939. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  36940. }
  36941. // Workaround for seac on Windows.
  36942. (function checkSeacSupport() {
  36943. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  36944. SEAC_ANALYSIS_ENABLED = true;
  36945. }
  36946. })();
  36947. // Workaround for Private Use Area characters in Chrome on Windows
  36948. // http://code.google.com/p/chromium/issues/detail?id=122465
  36949. // https://github.com/mozilla/pdf.js/issues/1689
  36950. (function checkChromeWindows() {
  36951. if (typeof navigator !== 'undefined' &&
  36952. /Windows.*Chrome/.test(navigator.userAgent)) {
  36953. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  36954. }
  36955. })();
  36956. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  36957. exports.CFFCompiler = CFFCompiler;
  36958. exports.CFFIndex = CFFIndex;
  36959. exports.CFFParser = CFFParser;
  36960. exports.CFFStrings = CFFStrings;
  36961. exports.Encodings = Encodings;
  36962. exports.ErrorFont = ErrorFont;
  36963. exports.FontFlags = FontFlags;
  36964. exports.Font = Font;
  36965. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  36966. exports.NormalizedUnicodes = NormalizedUnicodes;
  36967. exports.ToUnicodeMap = ToUnicodeMap;
  36968. exports.Type1Parser = Type1Parser;
  36969. exports.getFontType = getFontType;
  36970. exports.reverseIfRtl = reverseIfRtl;
  36971. exports.serifFonts = serifFonts;
  36972. exports.symbolsFonts = symbolsFonts;
  36973. exports.stdFontMap = stdFontMap;
  36974. exports._enableSeacAnalysis = _enableSeacAnalysis;
  36975. // TODO refactor to remove cyclic dependency on font_renderer.js
  36976. coreFontRenderer._setCoreFonts(exports);
  36977. }));
  36978. (function (root, factory) {
  36979. {
  36980. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  36981. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  36982. }
  36983. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  36984. var error = sharedUtil.error;
  36985. var info = sharedUtil.info;
  36986. var isArray = sharedUtil.isArray;
  36987. var isBool = sharedUtil.isBool;
  36988. var isDict = corePrimitives.isDict;
  36989. var isStream = corePrimitives.isStream;
  36990. var PostScriptLexer = corePsParser.PostScriptLexer;
  36991. var PostScriptParser = corePsParser.PostScriptParser;
  36992. var PDFFunction = (function PDFFunctionClosure() {
  36993. var CONSTRUCT_SAMPLED = 0;
  36994. var CONSTRUCT_INTERPOLATED = 2;
  36995. var CONSTRUCT_STICHED = 3;
  36996. var CONSTRUCT_POSTSCRIPT = 4;
  36997. return {
  36998. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  36999. str) {
  37000. var i, ii;
  37001. var length = 1;
  37002. for (i = 0, ii = size.length; i < ii; i++) {
  37003. length *= size[i];
  37004. }
  37005. length *= outputSize;
  37006. var array = new Array(length);
  37007. var codeSize = 0;
  37008. var codeBuf = 0;
  37009. // 32 is a valid bps so shifting won't work
  37010. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  37011. var strBytes = str.getBytes((length * bps + 7) / 8);
  37012. var strIdx = 0;
  37013. for (i = 0; i < length; i++) {
  37014. while (codeSize < bps) {
  37015. codeBuf <<= 8;
  37016. codeBuf |= strBytes[strIdx++];
  37017. codeSize += 8;
  37018. }
  37019. codeSize -= bps;
  37020. array[i] = (codeBuf >> codeSize) * sampleMul;
  37021. codeBuf &= (1 << codeSize) - 1;
  37022. }
  37023. return array;
  37024. },
  37025. getIR: function PDFFunction_getIR(xref, fn) {
  37026. var dict = fn.dict;
  37027. if (!dict) {
  37028. dict = fn;
  37029. }
  37030. var types = [this.constructSampled,
  37031. null,
  37032. this.constructInterpolated,
  37033. this.constructStiched,
  37034. this.constructPostScript];
  37035. var typeNum = dict.get('FunctionType');
  37036. var typeFn = types[typeNum];
  37037. if (!typeFn) {
  37038. error('Unknown type of function');
  37039. }
  37040. return typeFn.call(this, fn, dict, xref);
  37041. },
  37042. fromIR: function PDFFunction_fromIR(IR) {
  37043. var type = IR[0];
  37044. switch (type) {
  37045. case CONSTRUCT_SAMPLED:
  37046. return this.constructSampledFromIR(IR);
  37047. case CONSTRUCT_INTERPOLATED:
  37048. return this.constructInterpolatedFromIR(IR);
  37049. case CONSTRUCT_STICHED:
  37050. return this.constructStichedFromIR(IR);
  37051. //case CONSTRUCT_POSTSCRIPT:
  37052. default:
  37053. return this.constructPostScriptFromIR(IR);
  37054. }
  37055. },
  37056. parse: function PDFFunction_parse(xref, fn) {
  37057. var IR = this.getIR(xref, fn);
  37058. return this.fromIR(IR);
  37059. },
  37060. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  37061. if (!isArray(fnObj)) {
  37062. // not an array -- parsing as regular function
  37063. return this.parse(xref, fnObj);
  37064. }
  37065. var fnArray = [];
  37066. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  37067. var obj = xref.fetchIfRef(fnObj[j]);
  37068. fnArray.push(PDFFunction.parse(xref, obj));
  37069. }
  37070. return function (src, srcOffset, dest, destOffset) {
  37071. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  37072. fnArray[i](src, srcOffset, dest, destOffset + i);
  37073. }
  37074. };
  37075. },
  37076. constructSampled: function PDFFunction_constructSampled(str, dict) {
  37077. function toMultiArray(arr) {
  37078. var inputLength = arr.length;
  37079. var out = [];
  37080. var index = 0;
  37081. for (var i = 0; i < inputLength; i += 2) {
  37082. out[index] = [arr[i], arr[i + 1]];
  37083. ++index;
  37084. }
  37085. return out;
  37086. }
  37087. var domain = dict.get('Domain');
  37088. var range = dict.get('Range');
  37089. if (!domain || !range) {
  37090. error('No domain or range');
  37091. }
  37092. var inputSize = domain.length / 2;
  37093. var outputSize = range.length / 2;
  37094. domain = toMultiArray(domain);
  37095. range = toMultiArray(range);
  37096. var size = dict.get('Size');
  37097. var bps = dict.get('BitsPerSample');
  37098. var order = dict.get('Order') || 1;
  37099. if (order !== 1) {
  37100. // No description how cubic spline interpolation works in PDF32000:2008
  37101. // As in poppler, ignoring order, linear interpolation may work as good
  37102. info('No support for cubic spline interpolation: ' + order);
  37103. }
  37104. var encode = dict.get('Encode');
  37105. if (!encode) {
  37106. encode = [];
  37107. for (var i = 0; i < inputSize; ++i) {
  37108. encode.push(0);
  37109. encode.push(size[i] - 1);
  37110. }
  37111. }
  37112. encode = toMultiArray(encode);
  37113. var decode = dict.get('Decode');
  37114. if (!decode) {
  37115. decode = range;
  37116. } else {
  37117. decode = toMultiArray(decode);
  37118. }
  37119. var samples = this.getSampleArray(size, outputSize, bps, str);
  37120. return [
  37121. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  37122. outputSize, Math.pow(2, bps) - 1, range
  37123. ];
  37124. },
  37125. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  37126. // See chapter 3, page 109 of the PDF reference
  37127. function interpolate(x, xmin, xmax, ymin, ymax) {
  37128. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  37129. }
  37130. return function constructSampledFromIRResult(src, srcOffset,
  37131. dest, destOffset) {
  37132. // See chapter 3, page 110 of the PDF reference.
  37133. var m = IR[1];
  37134. var domain = IR[2];
  37135. var encode = IR[3];
  37136. var decode = IR[4];
  37137. var samples = IR[5];
  37138. var size = IR[6];
  37139. var n = IR[7];
  37140. //var mask = IR[8];
  37141. var range = IR[9];
  37142. // Building the cube vertices: its part and sample index
  37143. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  37144. var cubeVertices = 1 << m;
  37145. var cubeN = new Float64Array(cubeVertices);
  37146. var cubeVertex = new Uint32Array(cubeVertices);
  37147. var i, j;
  37148. for (j = 0; j < cubeVertices; j++) {
  37149. cubeN[j] = 1;
  37150. }
  37151. var k = n, pos = 1;
  37152. // Map x_i to y_j for 0 <= i < m using the sampled function.
  37153. for (i = 0; i < m; ++i) {
  37154. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  37155. var domain_2i = domain[i][0];
  37156. var domain_2i_1 = domain[i][1];
  37157. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  37158. domain_2i_1);
  37159. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  37160. // Encode_2i, Encode_2i+1)
  37161. var e = interpolate(xi, domain_2i, domain_2i_1,
  37162. encode[i][0], encode[i][1]);
  37163. // e_i' = min(max(e_i, 0), Size_i - 1)
  37164. var size_i = size[i];
  37165. e = Math.min(Math.max(e, 0), size_i - 1);
  37166. // Adjusting the cube: N and vertex sample index
  37167. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  37168. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  37169. var n1 = e - e0; // (e - e0) / (e1 - e0);
  37170. var offset0 = e0 * k;
  37171. var offset1 = offset0 + k; // e1 * k
  37172. for (j = 0; j < cubeVertices; j++) {
  37173. if (j & pos) {
  37174. cubeN[j] *= n1;
  37175. cubeVertex[j] += offset1;
  37176. } else {
  37177. cubeN[j] *= n0;
  37178. cubeVertex[j] += offset0;
  37179. }
  37180. }
  37181. k *= size_i;
  37182. pos <<= 1;
  37183. }
  37184. for (j = 0; j < n; ++j) {
  37185. // Sum all cube vertices' samples portions
  37186. var rj = 0;
  37187. for (i = 0; i < cubeVertices; i++) {
  37188. rj += samples[cubeVertex[i] + j] * cubeN[i];
  37189. }
  37190. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  37191. // Decode_2j, Decode_2j+1)
  37192. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  37193. // y_j = min(max(r_j, range_2j), range_2j+1)
  37194. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  37195. range[j][1]);
  37196. }
  37197. };
  37198. },
  37199. constructInterpolated: function PDFFunction_constructInterpolated(str,
  37200. dict) {
  37201. var c0 = dict.get('C0') || [0];
  37202. var c1 = dict.get('C1') || [1];
  37203. var n = dict.get('N');
  37204. if (!isArray(c0) || !isArray(c1)) {
  37205. error('Illegal dictionary for interpolated function');
  37206. }
  37207. var length = c0.length;
  37208. var diff = [];
  37209. for (var i = 0; i < length; ++i) {
  37210. diff.push(c1[i] - c0[i]);
  37211. }
  37212. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  37213. },
  37214. constructInterpolatedFromIR:
  37215. function PDFFunction_constructInterpolatedFromIR(IR) {
  37216. var c0 = IR[1];
  37217. var diff = IR[2];
  37218. var n = IR[3];
  37219. var length = diff.length;
  37220. return function constructInterpolatedFromIRResult(src, srcOffset,
  37221. dest, destOffset) {
  37222. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  37223. for (var j = 0; j < length; ++j) {
  37224. dest[destOffset + j] = c0[j] + (x * diff[j]);
  37225. }
  37226. };
  37227. },
  37228. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  37229. var domain = dict.get('Domain');
  37230. if (!domain) {
  37231. error('No domain');
  37232. }
  37233. var inputSize = domain.length / 2;
  37234. if (inputSize !== 1) {
  37235. error('Bad domain for stiched function');
  37236. }
  37237. var fnRefs = dict.get('Functions');
  37238. var fns = [];
  37239. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  37240. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  37241. }
  37242. var bounds = dict.get('Bounds');
  37243. var encode = dict.get('Encode');
  37244. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  37245. },
  37246. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  37247. var domain = IR[1];
  37248. var bounds = IR[2];
  37249. var encode = IR[3];
  37250. var fnsIR = IR[4];
  37251. var fns = [];
  37252. var tmpBuf = new Float32Array(1);
  37253. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  37254. fns.push(PDFFunction.fromIR(fnsIR[i]));
  37255. }
  37256. return function constructStichedFromIRResult(src, srcOffset,
  37257. dest, destOffset) {
  37258. var clip = function constructStichedFromIRClip(v, min, max) {
  37259. if (v > max) {
  37260. v = max;
  37261. } else if (v < min) {
  37262. v = min;
  37263. }
  37264. return v;
  37265. };
  37266. // clip to domain
  37267. var v = clip(src[srcOffset], domain[0], domain[1]);
  37268. // calulate which bound the value is in
  37269. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  37270. if (v < bounds[i]) {
  37271. break;
  37272. }
  37273. }
  37274. // encode value into domain of function
  37275. var dmin = domain[0];
  37276. if (i > 0) {
  37277. dmin = bounds[i - 1];
  37278. }
  37279. var dmax = domain[1];
  37280. if (i < bounds.length) {
  37281. dmax = bounds[i];
  37282. }
  37283. var rmin = encode[2 * i];
  37284. var rmax = encode[2 * i + 1];
  37285. // Prevent the value from becoming NaN as a result
  37286. // of division by zero (fixes issue6113.pdf).
  37287. tmpBuf[0] = dmin === dmax ? rmin :
  37288. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  37289. // call the appropriate function
  37290. fns[i](tmpBuf, 0, dest, destOffset);
  37291. };
  37292. },
  37293. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  37294. xref) {
  37295. var domain = dict.get('Domain');
  37296. var range = dict.get('Range');
  37297. if (!domain) {
  37298. error('No domain.');
  37299. }
  37300. if (!range) {
  37301. error('No range.');
  37302. }
  37303. var lexer = new PostScriptLexer(fn);
  37304. var parser = new PostScriptParser(lexer);
  37305. var code = parser.parse();
  37306. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  37307. },
  37308. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  37309. IR) {
  37310. var domain = IR[1];
  37311. var range = IR[2];
  37312. var code = IR[3];
  37313. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  37314. if (compiled) {
  37315. // Compiled function consists of simple expressions such as addition,
  37316. // subtraction, Math.max, and also contains 'var' and 'return'
  37317. // statements. See the generation in the PostScriptCompiler below.
  37318. /*jshint -W054 */
  37319. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  37320. }
  37321. info('Unable to compile PS function');
  37322. var numOutputs = range.length >> 1;
  37323. var numInputs = domain.length >> 1;
  37324. var evaluator = new PostScriptEvaluator(code);
  37325. // Cache the values for a big speed up, the cache size is limited though
  37326. // since the number of possible values can be huge from a PS function.
  37327. var cache = {};
  37328. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  37329. // seen in our tests.
  37330. var MAX_CACHE_SIZE = 2048 * 4;
  37331. var cache_available = MAX_CACHE_SIZE;
  37332. var tmpBuf = new Float32Array(numInputs);
  37333. return function constructPostScriptFromIRResult(src, srcOffset,
  37334. dest, destOffset) {
  37335. var i, value;
  37336. var key = '';
  37337. var input = tmpBuf;
  37338. for (i = 0; i < numInputs; i++) {
  37339. value = src[srcOffset + i];
  37340. input[i] = value;
  37341. key += value + '_';
  37342. }
  37343. var cachedValue = cache[key];
  37344. if (cachedValue !== undefined) {
  37345. dest.set(cachedValue, destOffset);
  37346. return;
  37347. }
  37348. var output = new Float32Array(numOutputs);
  37349. var stack = evaluator.execute(input);
  37350. var stackIndex = stack.length - numOutputs;
  37351. for (i = 0; i < numOutputs; i++) {
  37352. value = stack[stackIndex + i];
  37353. var bound = range[i * 2];
  37354. if (value < bound) {
  37355. value = bound;
  37356. } else {
  37357. bound = range[i * 2 +1];
  37358. if (value > bound) {
  37359. value = bound;
  37360. }
  37361. }
  37362. output[i] = value;
  37363. }
  37364. if (cache_available > 0) {
  37365. cache_available--;
  37366. cache[key] = output;
  37367. }
  37368. dest.set(output, destOffset);
  37369. };
  37370. }
  37371. };
  37372. })();
  37373. function isPDFFunction(v) {
  37374. var fnDict;
  37375. if (typeof v !== 'object') {
  37376. return false;
  37377. } else if (isDict(v)) {
  37378. fnDict = v;
  37379. } else if (isStream(v)) {
  37380. fnDict = v.dict;
  37381. } else {
  37382. return false;
  37383. }
  37384. return fnDict.has('FunctionType');
  37385. }
  37386. var PostScriptStack = (function PostScriptStackClosure() {
  37387. var MAX_STACK_SIZE = 100;
  37388. function PostScriptStack(initialStack) {
  37389. this.stack = !initialStack ? [] :
  37390. Array.prototype.slice.call(initialStack, 0);
  37391. }
  37392. PostScriptStack.prototype = {
  37393. push: function PostScriptStack_push(value) {
  37394. if (this.stack.length >= MAX_STACK_SIZE) {
  37395. error('PostScript function stack overflow.');
  37396. }
  37397. this.stack.push(value);
  37398. },
  37399. pop: function PostScriptStack_pop() {
  37400. if (this.stack.length <= 0) {
  37401. error('PostScript function stack underflow.');
  37402. }
  37403. return this.stack.pop();
  37404. },
  37405. copy: function PostScriptStack_copy(n) {
  37406. if (this.stack.length + n >= MAX_STACK_SIZE) {
  37407. error('PostScript function stack overflow.');
  37408. }
  37409. var stack = this.stack;
  37410. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  37411. stack.push(stack[i]);
  37412. }
  37413. },
  37414. index: function PostScriptStack_index(n) {
  37415. this.push(this.stack[this.stack.length - n - 1]);
  37416. },
  37417. // rotate the last n stack elements p times
  37418. roll: function PostScriptStack_roll(n, p) {
  37419. var stack = this.stack;
  37420. var l = stack.length - n;
  37421. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  37422. for (i = l, j = r; i < j; i++, j--) {
  37423. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37424. }
  37425. for (i = l, j = c - 1; i < j; i++, j--) {
  37426. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37427. }
  37428. for (i = c, j = r; i < j; i++, j--) {
  37429. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37430. }
  37431. }
  37432. };
  37433. return PostScriptStack;
  37434. })();
  37435. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  37436. function PostScriptEvaluator(operators) {
  37437. this.operators = operators;
  37438. }
  37439. PostScriptEvaluator.prototype = {
  37440. execute: function PostScriptEvaluator_execute(initialStack) {
  37441. var stack = new PostScriptStack(initialStack);
  37442. var counter = 0;
  37443. var operators = this.operators;
  37444. var length = operators.length;
  37445. var operator, a, b;
  37446. while (counter < length) {
  37447. operator = operators[counter++];
  37448. if (typeof operator === 'number') {
  37449. // Operator is really an operand and should be pushed to the stack.
  37450. stack.push(operator);
  37451. continue;
  37452. }
  37453. switch (operator) {
  37454. // non standard ps operators
  37455. case 'jz': // jump if false
  37456. b = stack.pop();
  37457. a = stack.pop();
  37458. if (!a) {
  37459. counter = b;
  37460. }
  37461. break;
  37462. case 'j': // jump
  37463. a = stack.pop();
  37464. counter = a;
  37465. break;
  37466. // all ps operators in alphabetical order (excluding if/ifelse)
  37467. case 'abs':
  37468. a = stack.pop();
  37469. stack.push(Math.abs(a));
  37470. break;
  37471. case 'add':
  37472. b = stack.pop();
  37473. a = stack.pop();
  37474. stack.push(a + b);
  37475. break;
  37476. case 'and':
  37477. b = stack.pop();
  37478. a = stack.pop();
  37479. if (isBool(a) && isBool(b)) {
  37480. stack.push(a && b);
  37481. } else {
  37482. stack.push(a & b);
  37483. }
  37484. break;
  37485. case 'atan':
  37486. a = stack.pop();
  37487. stack.push(Math.atan(a));
  37488. break;
  37489. case 'bitshift':
  37490. b = stack.pop();
  37491. a = stack.pop();
  37492. if (a > 0) {
  37493. stack.push(a << b);
  37494. } else {
  37495. stack.push(a >> b);
  37496. }
  37497. break;
  37498. case 'ceiling':
  37499. a = stack.pop();
  37500. stack.push(Math.ceil(a));
  37501. break;
  37502. case 'copy':
  37503. a = stack.pop();
  37504. stack.copy(a);
  37505. break;
  37506. case 'cos':
  37507. a = stack.pop();
  37508. stack.push(Math.cos(a));
  37509. break;
  37510. case 'cvi':
  37511. a = stack.pop() | 0;
  37512. stack.push(a);
  37513. break;
  37514. case 'cvr':
  37515. // noop
  37516. break;
  37517. case 'div':
  37518. b = stack.pop();
  37519. a = stack.pop();
  37520. stack.push(a / b);
  37521. break;
  37522. case 'dup':
  37523. stack.copy(1);
  37524. break;
  37525. case 'eq':
  37526. b = stack.pop();
  37527. a = stack.pop();
  37528. stack.push(a === b);
  37529. break;
  37530. case 'exch':
  37531. stack.roll(2, 1);
  37532. break;
  37533. case 'exp':
  37534. b = stack.pop();
  37535. a = stack.pop();
  37536. stack.push(Math.pow(a, b));
  37537. break;
  37538. case 'false':
  37539. stack.push(false);
  37540. break;
  37541. case 'floor':
  37542. a = stack.pop();
  37543. stack.push(Math.floor(a));
  37544. break;
  37545. case 'ge':
  37546. b = stack.pop();
  37547. a = stack.pop();
  37548. stack.push(a >= b);
  37549. break;
  37550. case 'gt':
  37551. b = stack.pop();
  37552. a = stack.pop();
  37553. stack.push(a > b);
  37554. break;
  37555. case 'idiv':
  37556. b = stack.pop();
  37557. a = stack.pop();
  37558. stack.push((a / b) | 0);
  37559. break;
  37560. case 'index':
  37561. a = stack.pop();
  37562. stack.index(a);
  37563. break;
  37564. case 'le':
  37565. b = stack.pop();
  37566. a = stack.pop();
  37567. stack.push(a <= b);
  37568. break;
  37569. case 'ln':
  37570. a = stack.pop();
  37571. stack.push(Math.log(a));
  37572. break;
  37573. case 'log':
  37574. a = stack.pop();
  37575. stack.push(Math.log(a) / Math.LN10);
  37576. break;
  37577. case 'lt':
  37578. b = stack.pop();
  37579. a = stack.pop();
  37580. stack.push(a < b);
  37581. break;
  37582. case 'mod':
  37583. b = stack.pop();
  37584. a = stack.pop();
  37585. stack.push(a % b);
  37586. break;
  37587. case 'mul':
  37588. b = stack.pop();
  37589. a = stack.pop();
  37590. stack.push(a * b);
  37591. break;
  37592. case 'ne':
  37593. b = stack.pop();
  37594. a = stack.pop();
  37595. stack.push(a !== b);
  37596. break;
  37597. case 'neg':
  37598. a = stack.pop();
  37599. stack.push(-a);
  37600. break;
  37601. case 'not':
  37602. a = stack.pop();
  37603. if (isBool(a)) {
  37604. stack.push(!a);
  37605. } else {
  37606. stack.push(~a);
  37607. }
  37608. break;
  37609. case 'or':
  37610. b = stack.pop();
  37611. a = stack.pop();
  37612. if (isBool(a) && isBool(b)) {
  37613. stack.push(a || b);
  37614. } else {
  37615. stack.push(a | b);
  37616. }
  37617. break;
  37618. case 'pop':
  37619. stack.pop();
  37620. break;
  37621. case 'roll':
  37622. b = stack.pop();
  37623. a = stack.pop();
  37624. stack.roll(a, b);
  37625. break;
  37626. case 'round':
  37627. a = stack.pop();
  37628. stack.push(Math.round(a));
  37629. break;
  37630. case 'sin':
  37631. a = stack.pop();
  37632. stack.push(Math.sin(a));
  37633. break;
  37634. case 'sqrt':
  37635. a = stack.pop();
  37636. stack.push(Math.sqrt(a));
  37637. break;
  37638. case 'sub':
  37639. b = stack.pop();
  37640. a = stack.pop();
  37641. stack.push(a - b);
  37642. break;
  37643. case 'true':
  37644. stack.push(true);
  37645. break;
  37646. case 'truncate':
  37647. a = stack.pop();
  37648. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  37649. stack.push(a);
  37650. break;
  37651. case 'xor':
  37652. b = stack.pop();
  37653. a = stack.pop();
  37654. if (isBool(a) && isBool(b)) {
  37655. stack.push(a !== b);
  37656. } else {
  37657. stack.push(a ^ b);
  37658. }
  37659. break;
  37660. default:
  37661. error('Unknown operator ' + operator);
  37662. break;
  37663. }
  37664. }
  37665. return stack.stack;
  37666. }
  37667. };
  37668. return PostScriptEvaluator;
  37669. })();
  37670. // Most of the PDFs functions consist of simple operations such as:
  37671. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  37672. //
  37673. // We can compile most of such programs, and at the same moment, we can
  37674. // optimize some expressions using basic math properties. Keeping track of
  37675. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  37676. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  37677. function AstNode(type) {
  37678. this.type = type;
  37679. }
  37680. AstNode.prototype.visit = function (visitor) {
  37681. throw new Error('abstract method');
  37682. };
  37683. function AstArgument(index, min, max) {
  37684. AstNode.call(this, 'args');
  37685. this.index = index;
  37686. this.min = min;
  37687. this.max = max;
  37688. }
  37689. AstArgument.prototype = Object.create(AstNode.prototype);
  37690. AstArgument.prototype.visit = function (visitor) {
  37691. visitor.visitArgument(this);
  37692. };
  37693. function AstLiteral(number) {
  37694. AstNode.call(this, 'literal');
  37695. this.number = number;
  37696. this.min = number;
  37697. this.max = number;
  37698. }
  37699. AstLiteral.prototype = Object.create(AstNode.prototype);
  37700. AstLiteral.prototype.visit = function (visitor) {
  37701. visitor.visitLiteral(this);
  37702. };
  37703. function AstBinaryOperation(op, arg1, arg2, min, max) {
  37704. AstNode.call(this, 'binary');
  37705. this.op = op;
  37706. this.arg1 = arg1;
  37707. this.arg2 = arg2;
  37708. this.min = min;
  37709. this.max = max;
  37710. }
  37711. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  37712. AstBinaryOperation.prototype.visit = function (visitor) {
  37713. visitor.visitBinaryOperation(this);
  37714. };
  37715. function AstMin(arg, max) {
  37716. AstNode.call(this, 'max');
  37717. this.arg = arg;
  37718. this.min = arg.min;
  37719. this.max = max;
  37720. }
  37721. AstMin.prototype = Object.create(AstNode.prototype);
  37722. AstMin.prototype.visit = function (visitor) {
  37723. visitor.visitMin(this);
  37724. };
  37725. function AstVariable(index, min, max) {
  37726. AstNode.call(this, 'var');
  37727. this.index = index;
  37728. this.min = min;
  37729. this.max = max;
  37730. }
  37731. AstVariable.prototype = Object.create(AstNode.prototype);
  37732. AstVariable.prototype.visit = function (visitor) {
  37733. visitor.visitVariable(this);
  37734. };
  37735. function AstVariableDefinition(variable, arg) {
  37736. AstNode.call(this, 'definition');
  37737. this.variable = variable;
  37738. this.arg = arg;
  37739. }
  37740. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  37741. AstVariableDefinition.prototype.visit = function (visitor) {
  37742. visitor.visitVariableDefinition(this);
  37743. };
  37744. function ExpressionBuilderVisitor() {
  37745. this.parts = [];
  37746. }
  37747. ExpressionBuilderVisitor.prototype = {
  37748. visitArgument: function (arg) {
  37749. this.parts.push('Math.max(', arg.min, ', Math.min(',
  37750. arg.max, ', src[srcOffset + ', arg.index, ']))');
  37751. },
  37752. visitVariable: function (variable) {
  37753. this.parts.push('v', variable.index);
  37754. },
  37755. visitLiteral: function (literal) {
  37756. this.parts.push(literal.number);
  37757. },
  37758. visitBinaryOperation: function (operation) {
  37759. this.parts.push('(');
  37760. operation.arg1.visit(this);
  37761. this.parts.push(' ', operation.op, ' ');
  37762. operation.arg2.visit(this);
  37763. this.parts.push(')');
  37764. },
  37765. visitVariableDefinition: function (definition) {
  37766. this.parts.push('var ');
  37767. definition.variable.visit(this);
  37768. this.parts.push(' = ');
  37769. definition.arg.visit(this);
  37770. this.parts.push(';');
  37771. },
  37772. visitMin: function (max) {
  37773. this.parts.push('Math.min(');
  37774. max.arg.visit(this);
  37775. this.parts.push(', ', max.max, ')');
  37776. },
  37777. toString: function () {
  37778. return this.parts.join('');
  37779. }
  37780. };
  37781. function buildAddOperation(num1, num2) {
  37782. if (num2.type === 'literal' && num2.number === 0) {
  37783. // optimization: second operand is 0
  37784. return num1;
  37785. }
  37786. if (num1.type === 'literal' && num1.number === 0) {
  37787. // optimization: first operand is 0
  37788. return num2;
  37789. }
  37790. if (num2.type === 'literal' && num1.type === 'literal') {
  37791. // optimization: operands operand are literals
  37792. return new AstLiteral(num1.number + num2.number);
  37793. }
  37794. return new AstBinaryOperation('+', num1, num2,
  37795. num1.min + num2.min, num1.max + num2.max);
  37796. }
  37797. function buildMulOperation(num1, num2) {
  37798. if (num2.type === 'literal') {
  37799. // optimization: second operands is a literal...
  37800. if (num2.number === 0) {
  37801. return new AstLiteral(0); // and it's 0
  37802. } else if (num2.number === 1) {
  37803. return num1; // and it's 1
  37804. } else if (num1.type === 'literal') {
  37805. // ... and first operands is a literal too
  37806. return new AstLiteral(num1.number * num2.number);
  37807. }
  37808. }
  37809. if (num1.type === 'literal') {
  37810. // optimization: first operands is a literal...
  37811. if (num1.number === 0) {
  37812. return new AstLiteral(0); // and it's 0
  37813. } else if (num1.number === 1) {
  37814. return num2; // and it's 1
  37815. }
  37816. }
  37817. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  37818. num1.max * num2.min, num1.max * num2.max);
  37819. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  37820. num1.max * num2.min, num1.max * num2.max);
  37821. return new AstBinaryOperation('*', num1, num2, min, max);
  37822. }
  37823. function buildSubOperation(num1, num2) {
  37824. if (num2.type === 'literal') {
  37825. // optimization: second operands is a literal...
  37826. if (num2.number === 0) {
  37827. return num1; // ... and it's 0
  37828. } else if (num1.type === 'literal') {
  37829. // ... and first operands is a literal too
  37830. return new AstLiteral(num1.number - num2.number);
  37831. }
  37832. }
  37833. if (num2.type === 'binary' && num2.op === '-' &&
  37834. num1.type === 'literal' && num1.number === 1 &&
  37835. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  37836. // optimization for case: 1 - (1 - x)
  37837. return num2.arg2;
  37838. }
  37839. return new AstBinaryOperation('-', num1, num2,
  37840. num1.min - num2.max, num1.max - num2.min);
  37841. }
  37842. function buildMinOperation(num1, max) {
  37843. if (num1.min >= max) {
  37844. // optimization: num1 min value is not less than required max
  37845. return new AstLiteral(max); // just returning max
  37846. } else if (num1.max <= max) {
  37847. // optimization: num1 max value is not greater than required max
  37848. return num1; // just returning an argument
  37849. }
  37850. return new AstMin(num1, max);
  37851. }
  37852. function PostScriptCompiler() {}
  37853. PostScriptCompiler.prototype = {
  37854. compile: function PostScriptCompiler_compile(code, domain, range) {
  37855. var stack = [];
  37856. var i, ii;
  37857. var instructions = [];
  37858. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  37859. var lastRegister = 0;
  37860. var n, j;
  37861. var num1, num2, ast1, ast2, tmpVar, item;
  37862. for (i = 0; i < inputSize; i++) {
  37863. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  37864. }
  37865. for (i = 0, ii = code.length; i < ii; i++) {
  37866. item = code[i];
  37867. if (typeof item === 'number') {
  37868. stack.push(new AstLiteral(item));
  37869. continue;
  37870. }
  37871. switch (item) {
  37872. case 'add':
  37873. if (stack.length < 2) {
  37874. return null;
  37875. }
  37876. num2 = stack.pop();
  37877. num1 = stack.pop();
  37878. stack.push(buildAddOperation(num1, num2));
  37879. break;
  37880. case 'cvr':
  37881. if (stack.length < 1) {
  37882. return null;
  37883. }
  37884. break;
  37885. case 'mul':
  37886. if (stack.length < 2) {
  37887. return null;
  37888. }
  37889. num2 = stack.pop();
  37890. num1 = stack.pop();
  37891. stack.push(buildMulOperation(num1, num2));
  37892. break;
  37893. case 'sub':
  37894. if (stack.length < 2) {
  37895. return null;
  37896. }
  37897. num2 = stack.pop();
  37898. num1 = stack.pop();
  37899. stack.push(buildSubOperation(num1, num2));
  37900. break;
  37901. case 'exch':
  37902. if (stack.length < 2) {
  37903. return null;
  37904. }
  37905. ast1 = stack.pop(); ast2 = stack.pop();
  37906. stack.push(ast1, ast2);
  37907. break;
  37908. case 'pop':
  37909. if (stack.length < 1) {
  37910. return null;
  37911. }
  37912. stack.pop();
  37913. break;
  37914. case 'index':
  37915. if (stack.length < 1) {
  37916. return null;
  37917. }
  37918. num1 = stack.pop();
  37919. if (num1.type !== 'literal') {
  37920. return null;
  37921. }
  37922. n = num1.number;
  37923. if (n < 0 || (n|0) !== n || stack.length < n) {
  37924. return null;
  37925. }
  37926. ast1 = stack[stack.length - n - 1];
  37927. if (ast1.type === 'literal' || ast1.type === 'var') {
  37928. stack.push(ast1);
  37929. break;
  37930. }
  37931. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37932. stack[stack.length - n - 1] = tmpVar;
  37933. stack.push(tmpVar);
  37934. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37935. break;
  37936. case 'dup':
  37937. if (stack.length < 1) {
  37938. return null;
  37939. }
  37940. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  37941. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  37942. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  37943. // special case of the commands sequence for the min operation
  37944. num1 = stack.pop();
  37945. stack.push(buildMinOperation(num1, code[i + 1]));
  37946. i += 6;
  37947. break;
  37948. }
  37949. ast1 = stack[stack.length - 1];
  37950. if (ast1.type === 'literal' || ast1.type === 'var') {
  37951. // we don't have to save into intermediate variable a literal or
  37952. // variable.
  37953. stack.push(ast1);
  37954. break;
  37955. }
  37956. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37957. stack[stack.length - 1] = tmpVar;
  37958. stack.push(tmpVar);
  37959. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37960. break;
  37961. case 'roll':
  37962. if (stack.length < 2) {
  37963. return null;
  37964. }
  37965. num2 = stack.pop();
  37966. num1 = stack.pop();
  37967. if (num2.type !== 'literal' || num1.type !== 'literal') {
  37968. // both roll operands must be numbers
  37969. return null;
  37970. }
  37971. j = num2.number;
  37972. n = num1.number;
  37973. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  37974. // ... and integers
  37975. return null;
  37976. }
  37977. j = ((j % n) + n) % n;
  37978. if (j === 0) {
  37979. break; // just skipping -- there are nothing to rotate
  37980. }
  37981. Array.prototype.push.apply(stack,
  37982. stack.splice(stack.length - n, n - j));
  37983. break;
  37984. default:
  37985. return null; // unsupported operator
  37986. }
  37987. }
  37988. if (stack.length !== outputSize) {
  37989. return null;
  37990. }
  37991. var result = [];
  37992. instructions.forEach(function (instruction) {
  37993. var statementBuilder = new ExpressionBuilderVisitor();
  37994. instruction.visit(statementBuilder);
  37995. result.push(statementBuilder.toString());
  37996. });
  37997. stack.forEach(function (expr, i) {
  37998. var statementBuilder = new ExpressionBuilderVisitor();
  37999. expr.visit(statementBuilder);
  38000. var min = range[i * 2], max = range[i * 2 + 1];
  38001. var out = [statementBuilder.toString()];
  38002. if (min > expr.min) {
  38003. out.unshift('Math.max(', min, ', ');
  38004. out.push(')');
  38005. }
  38006. if (max < expr.max) {
  38007. out.unshift('Math.min(', max, ', ');
  38008. out.push(')');
  38009. }
  38010. out.unshift('dest[destOffset + ', i, '] = ');
  38011. out.push(';');
  38012. result.push(out.join(''));
  38013. });
  38014. return result.join('\n');
  38015. }
  38016. };
  38017. return PostScriptCompiler;
  38018. })();
  38019. exports.isPDFFunction = isPDFFunction;
  38020. exports.PDFFunction = PDFFunction;
  38021. exports.PostScriptEvaluator = PostScriptEvaluator;
  38022. exports.PostScriptCompiler = PostScriptCompiler;
  38023. }));
  38024. (function (root, factory) {
  38025. {
  38026. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  38027. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  38028. }
  38029. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  38030. coreStream) {
  38031. var error = sharedUtil.error;
  38032. var info = sharedUtil.info;
  38033. var isArray = sharedUtil.isArray;
  38034. var isString = sharedUtil.isString;
  38035. var shadow = sharedUtil.shadow;
  38036. var warn = sharedUtil.warn;
  38037. var isDict = corePrimitives.isDict;
  38038. var isName = corePrimitives.isName;
  38039. var isStream = corePrimitives.isStream;
  38040. var PDFFunction = coreFunction.PDFFunction;
  38041. var coreImage; // see _setCoreImage below
  38042. var PDFImage; // = coreImage.PDFImage;
  38043. var ColorSpace = (function ColorSpaceClosure() {
  38044. // Constructor should define this.numComps, this.defaultColor, this.name
  38045. function ColorSpace() {
  38046. error('should not call ColorSpace constructor');
  38047. }
  38048. ColorSpace.prototype = {
  38049. /**
  38050. * Converts the color value to the RGB color. The color components are
  38051. * located in the src array starting from the srcOffset. Returns the array
  38052. * of the rgb components, each value ranging from [0,255].
  38053. */
  38054. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  38055. var rgb = new Uint8Array(3);
  38056. this.getRgbItem(src, srcOffset, rgb, 0);
  38057. return rgb;
  38058. },
  38059. /**
  38060. * Converts the color value to the RGB color, similar to the getRgb method.
  38061. * The result placed into the dest array starting from the destOffset.
  38062. */
  38063. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  38064. dest, destOffset) {
  38065. error('Should not call ColorSpace.getRgbItem');
  38066. },
  38067. /**
  38068. * Converts the specified number of the color values to the RGB colors.
  38069. * The colors are located in the src array starting from the srcOffset.
  38070. * The result is placed into the dest array starting from the destOffset.
  38071. * The src array items shall be in [0,2^bits) range, the dest array items
  38072. * will be in [0,255] range. alpha01 indicates how many alpha components
  38073. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  38074. * array).
  38075. */
  38076. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  38077. dest, destOffset, bits,
  38078. alpha01) {
  38079. error('Should not call ColorSpace.getRgbBuffer');
  38080. },
  38081. /**
  38082. * Determines the number of bytes required to store the result of the
  38083. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  38084. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  38085. */
  38086. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  38087. alpha01) {
  38088. error('Should not call ColorSpace.getOutputLength');
  38089. },
  38090. /**
  38091. * Returns true if source data will be equal the result/output data.
  38092. */
  38093. isPassthrough: function ColorSpace_isPassthrough(bits) {
  38094. return false;
  38095. },
  38096. /**
  38097. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  38098. * how many alpha components there are in the dest array; it will be either
  38099. * 0 (RGB array) or 1 (RGBA array).
  38100. */
  38101. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  38102. originalHeight, width, height,
  38103. actualHeight, bpc, comps, alpha01) {
  38104. var count = originalWidth * originalHeight;
  38105. var rgbBuf = null;
  38106. var numComponentColors = 1 << bpc;
  38107. var needsResizing = originalHeight !== height || originalWidth !== width;
  38108. var i, ii;
  38109. if (this.isPassthrough(bpc)) {
  38110. rgbBuf = comps;
  38111. } else if (this.numComps === 1 && count > numComponentColors &&
  38112. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  38113. // Optimization: create a color map when there is just one component and
  38114. // we are converting more colors than the size of the color map. We
  38115. // don't build the map if the colorspace is gray or rgb since those
  38116. // methods are faster than building a map. This mainly offers big speed
  38117. // ups for indexed and alternate colorspaces.
  38118. //
  38119. // TODO it may be worth while to cache the color map. While running
  38120. // testing I never hit a cache so I will leave that out for now (perhaps
  38121. // we are reparsing colorspaces too much?).
  38122. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  38123. new Uint16Array(numComponentColors);
  38124. var key;
  38125. for (i = 0; i < numComponentColors; i++) {
  38126. allColors[i] = i;
  38127. }
  38128. var colorMap = new Uint8Array(numComponentColors * 3);
  38129. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  38130. /* alpha01 = */ 0);
  38131. var destPos, rgbPos;
  38132. if (!needsResizing) {
  38133. // Fill in the RGB values directly into |dest|.
  38134. destPos = 0;
  38135. for (i = 0; i < count; ++i) {
  38136. key = comps[i] * 3;
  38137. dest[destPos++] = colorMap[key];
  38138. dest[destPos++] = colorMap[key + 1];
  38139. dest[destPos++] = colorMap[key + 2];
  38140. destPos += alpha01;
  38141. }
  38142. } else {
  38143. rgbBuf = new Uint8Array(count * 3);
  38144. rgbPos = 0;
  38145. for (i = 0; i < count; ++i) {
  38146. key = comps[i] * 3;
  38147. rgbBuf[rgbPos++] = colorMap[key];
  38148. rgbBuf[rgbPos++] = colorMap[key + 1];
  38149. rgbBuf[rgbPos++] = colorMap[key + 2];
  38150. }
  38151. }
  38152. } else {
  38153. if (!needsResizing) {
  38154. // Fill in the RGB values directly into |dest|.
  38155. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  38156. alpha01);
  38157. } else {
  38158. rgbBuf = new Uint8Array(count * 3);
  38159. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  38160. /* alpha01 = */ 0);
  38161. }
  38162. }
  38163. if (rgbBuf) {
  38164. if (needsResizing) {
  38165. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  38166. height, dest, alpha01);
  38167. } else {
  38168. rgbPos = 0;
  38169. destPos = 0;
  38170. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  38171. dest[destPos++] = rgbBuf[rgbPos++];
  38172. dest[destPos++] = rgbBuf[rgbPos++];
  38173. dest[destPos++] = rgbBuf[rgbPos++];
  38174. destPos += alpha01;
  38175. }
  38176. }
  38177. }
  38178. },
  38179. /**
  38180. * True if the colorspace has components in the default range of [0, 1].
  38181. * This should be true for all colorspaces except for lab color spaces
  38182. * which are [0,100], [-128, 127], [-128, 127].
  38183. */
  38184. usesZeroToOneRange: true
  38185. };
  38186. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38187. var IR = ColorSpace.parseToIR(cs, xref, res);
  38188. if (IR instanceof AlternateCS) {
  38189. return IR;
  38190. }
  38191. return ColorSpace.fromIR(IR);
  38192. };
  38193. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38194. var name = isArray(IR) ? IR[0] : IR;
  38195. var whitePoint, blackPoint, gamma;
  38196. switch (name) {
  38197. case 'DeviceGrayCS':
  38198. return this.singletons.gray;
  38199. case 'DeviceRgbCS':
  38200. return this.singletons.rgb;
  38201. case 'DeviceCmykCS':
  38202. return this.singletons.cmyk;
  38203. case 'CalGrayCS':
  38204. whitePoint = IR[1].WhitePoint;
  38205. blackPoint = IR[1].BlackPoint;
  38206. gamma = IR[1].Gamma;
  38207. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38208. case 'CalRGBCS':
  38209. whitePoint = IR[1].WhitePoint;
  38210. blackPoint = IR[1].BlackPoint;
  38211. gamma = IR[1].Gamma;
  38212. var matrix = IR[1].Matrix;
  38213. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38214. case 'PatternCS':
  38215. var basePatternCS = IR[1];
  38216. if (basePatternCS) {
  38217. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38218. }
  38219. return new PatternCS(basePatternCS);
  38220. case 'IndexedCS':
  38221. var baseIndexedCS = IR[1];
  38222. var hiVal = IR[2];
  38223. var lookup = IR[3];
  38224. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38225. case 'AlternateCS':
  38226. var numComps = IR[1];
  38227. var alt = IR[2];
  38228. var tintFnIR = IR[3];
  38229. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38230. PDFFunction.fromIR(tintFnIR));
  38231. case 'LabCS':
  38232. whitePoint = IR[1].WhitePoint;
  38233. blackPoint = IR[1].BlackPoint;
  38234. var range = IR[1].Range;
  38235. return new LabCS(whitePoint, blackPoint, range);
  38236. default:
  38237. error('Unknown name ' + name);
  38238. }
  38239. return null;
  38240. };
  38241. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38242. if (isName(cs)) {
  38243. var colorSpaces = res.get('ColorSpace');
  38244. if (isDict(colorSpaces)) {
  38245. var refcs = colorSpaces.get(cs.name);
  38246. if (refcs) {
  38247. cs = refcs;
  38248. }
  38249. }
  38250. }
  38251. cs = xref.fetchIfRef(cs);
  38252. var mode;
  38253. if (isName(cs)) {
  38254. mode = cs.name;
  38255. this.mode = mode;
  38256. switch (mode) {
  38257. case 'DeviceGray':
  38258. case 'G':
  38259. return 'DeviceGrayCS';
  38260. case 'DeviceRGB':
  38261. case 'RGB':
  38262. return 'DeviceRgbCS';
  38263. case 'DeviceCMYK':
  38264. case 'CMYK':
  38265. return 'DeviceCmykCS';
  38266. case 'Pattern':
  38267. return ['PatternCS', null];
  38268. default:
  38269. error('unrecognized colorspace ' + mode);
  38270. }
  38271. } else if (isArray(cs)) {
  38272. mode = xref.fetchIfRef(cs[0]).name;
  38273. this.mode = mode;
  38274. var numComps, params, alt;
  38275. switch (mode) {
  38276. case 'DeviceGray':
  38277. case 'G':
  38278. return 'DeviceGrayCS';
  38279. case 'DeviceRGB':
  38280. case 'RGB':
  38281. return 'DeviceRgbCS';
  38282. case 'DeviceCMYK':
  38283. case 'CMYK':
  38284. return 'DeviceCmykCS';
  38285. case 'CalGray':
  38286. params = xref.fetchIfRef(cs[1]).getAll();
  38287. return ['CalGrayCS', params];
  38288. case 'CalRGB':
  38289. params = xref.fetchIfRef(cs[1]).getAll();
  38290. return ['CalRGBCS', params];
  38291. case 'ICCBased':
  38292. var stream = xref.fetchIfRef(cs[1]);
  38293. var dict = stream.dict;
  38294. numComps = dict.get('N');
  38295. alt = dict.get('Alternate');
  38296. if (alt) {
  38297. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38298. // Parse the /Alternate CS to ensure that the number of components
  38299. // are correct, and also (indirectly) that it is not a PatternCS.
  38300. var altCS = ColorSpace.fromIR(altIR);
  38301. if (altCS.numComps === numComps) {
  38302. return altIR;
  38303. }
  38304. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38305. }
  38306. if (numComps === 1) {
  38307. return 'DeviceGrayCS';
  38308. } else if (numComps === 3) {
  38309. return 'DeviceRgbCS';
  38310. } else if (numComps === 4) {
  38311. return 'DeviceCmykCS';
  38312. }
  38313. break;
  38314. case 'Pattern':
  38315. var basePatternCS = cs[1] || null;
  38316. if (basePatternCS) {
  38317. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38318. }
  38319. return ['PatternCS', basePatternCS];
  38320. case 'Indexed':
  38321. case 'I':
  38322. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38323. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38324. var lookup = xref.fetchIfRef(cs[3]);
  38325. if (isStream(lookup)) {
  38326. lookup = lookup.getBytes();
  38327. }
  38328. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38329. case 'Separation':
  38330. case 'DeviceN':
  38331. var name = xref.fetchIfRef(cs[1]);
  38332. numComps = 1;
  38333. if (isName(name)) {
  38334. numComps = 1;
  38335. } else if (isArray(name)) {
  38336. numComps = name.length;
  38337. }
  38338. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38339. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38340. return ['AlternateCS', numComps, alt, tintFnIR];
  38341. case 'Lab':
  38342. params = xref.fetchIfRef(cs[1]).getAll();
  38343. return ['LabCS', params];
  38344. default:
  38345. error('unimplemented color space object "' + mode + '"');
  38346. }
  38347. } else {
  38348. error('unrecognized color space object: "' + cs + '"');
  38349. }
  38350. return null;
  38351. };
  38352. /**
  38353. * Checks if a decode map matches the default decode map for a color space.
  38354. * This handles the general decode maps where there are two values per
  38355. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38356. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38357. * slightly different.
  38358. * @param {Array} decode Decode map (usually from an image).
  38359. * @param {Number} n Number of components the color space has.
  38360. */
  38361. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38362. if (!isArray(decode)) {
  38363. return true;
  38364. }
  38365. if (n * 2 !== decode.length) {
  38366. warn('The decode map is not the correct length');
  38367. return true;
  38368. }
  38369. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38370. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38371. return false;
  38372. }
  38373. }
  38374. return true;
  38375. };
  38376. ColorSpace.singletons = {
  38377. get gray() {
  38378. return shadow(this, 'gray', new DeviceGrayCS());
  38379. },
  38380. get rgb() {
  38381. return shadow(this, 'rgb', new DeviceRgbCS());
  38382. },
  38383. get cmyk() {
  38384. return shadow(this, 'cmyk', new DeviceCmykCS());
  38385. }
  38386. };
  38387. return ColorSpace;
  38388. })();
  38389. /**
  38390. * Alternate color space handles both Separation and DeviceN color spaces. A
  38391. * Separation color space is actually just a DeviceN with one color component.
  38392. * Both color spaces use a tinting function to convert colors to a base color
  38393. * space.
  38394. */
  38395. var AlternateCS = (function AlternateCSClosure() {
  38396. function AlternateCS(numComps, base, tintFn) {
  38397. this.name = 'Alternate';
  38398. this.numComps = numComps;
  38399. this.defaultColor = new Float32Array(numComps);
  38400. for (var i = 0; i < numComps; ++i) {
  38401. this.defaultColor[i] = 1;
  38402. }
  38403. this.base = base;
  38404. this.tintFn = tintFn;
  38405. this.tmpBuf = new Float32Array(base.numComps);
  38406. }
  38407. AlternateCS.prototype = {
  38408. getRgb: ColorSpace.prototype.getRgb,
  38409. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38410. dest, destOffset) {
  38411. var tmpBuf = this.tmpBuf;
  38412. this.tintFn(src, srcOffset, tmpBuf, 0);
  38413. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38414. },
  38415. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38416. dest, destOffset, bits,
  38417. alpha01) {
  38418. var tintFn = this.tintFn;
  38419. var base = this.base;
  38420. var scale = 1 / ((1 << bits) - 1);
  38421. var baseNumComps = base.numComps;
  38422. var usesZeroToOneRange = base.usesZeroToOneRange;
  38423. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38424. alpha01 === 0;
  38425. var pos = isPassthrough ? destOffset : 0;
  38426. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38427. var numComps = this.numComps;
  38428. var scaled = new Float32Array(numComps);
  38429. var tinted = new Float32Array(baseNumComps);
  38430. var i, j;
  38431. if (usesZeroToOneRange) {
  38432. for (i = 0; i < count; i++) {
  38433. for (j = 0; j < numComps; j++) {
  38434. scaled[j] = src[srcOffset++] * scale;
  38435. }
  38436. tintFn(scaled, 0, tinted, 0);
  38437. for (j = 0; j < baseNumComps; j++) {
  38438. baseBuf[pos++] = tinted[j] * 255;
  38439. }
  38440. }
  38441. } else {
  38442. for (i = 0; i < count; i++) {
  38443. for (j = 0; j < numComps; j++) {
  38444. scaled[j] = src[srcOffset++] * scale;
  38445. }
  38446. tintFn(scaled, 0, tinted, 0);
  38447. base.getRgbItem(tinted, 0, baseBuf, pos);
  38448. pos += baseNumComps;
  38449. }
  38450. }
  38451. if (!isPassthrough) {
  38452. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38453. }
  38454. },
  38455. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38456. alpha01) {
  38457. return this.base.getOutputLength(inputLength *
  38458. this.base.numComps / this.numComps,
  38459. alpha01);
  38460. },
  38461. isPassthrough: ColorSpace.prototype.isPassthrough,
  38462. fillRgb: ColorSpace.prototype.fillRgb,
  38463. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38464. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38465. },
  38466. usesZeroToOneRange: true
  38467. };
  38468. return AlternateCS;
  38469. })();
  38470. var PatternCS = (function PatternCSClosure() {
  38471. function PatternCS(baseCS) {
  38472. this.name = 'Pattern';
  38473. this.base = baseCS;
  38474. }
  38475. PatternCS.prototype = {};
  38476. return PatternCS;
  38477. })();
  38478. var IndexedCS = (function IndexedCSClosure() {
  38479. function IndexedCS(base, highVal, lookup) {
  38480. this.name = 'Indexed';
  38481. this.numComps = 1;
  38482. this.defaultColor = new Uint8Array([0]);
  38483. this.base = base;
  38484. this.highVal = highVal;
  38485. var baseNumComps = base.numComps;
  38486. var length = baseNumComps * highVal;
  38487. var lookupArray;
  38488. if (isStream(lookup)) {
  38489. lookupArray = new Uint8Array(length);
  38490. var bytes = lookup.getBytes(length);
  38491. lookupArray.set(bytes);
  38492. } else if (isString(lookup)) {
  38493. lookupArray = new Uint8Array(length);
  38494. for (var i = 0; i < length; ++i) {
  38495. lookupArray[i] = lookup.charCodeAt(i);
  38496. }
  38497. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38498. lookupArray = lookup;
  38499. } else {
  38500. error('Unrecognized lookup table: ' + lookup);
  38501. }
  38502. this.lookup = lookupArray;
  38503. }
  38504. IndexedCS.prototype = {
  38505. getRgb: ColorSpace.prototype.getRgb,
  38506. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38507. dest, destOffset) {
  38508. var numComps = this.base.numComps;
  38509. var start = src[srcOffset] * numComps;
  38510. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38511. },
  38512. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38513. dest, destOffset, bits,
  38514. alpha01) {
  38515. var base = this.base;
  38516. var numComps = base.numComps;
  38517. var outputDelta = base.getOutputLength(numComps, alpha01);
  38518. var lookup = this.lookup;
  38519. for (var i = 0; i < count; ++i) {
  38520. var lookupPos = src[srcOffset++] * numComps;
  38521. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38522. destOffset += outputDelta;
  38523. }
  38524. },
  38525. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38526. return this.base.getOutputLength(inputLength * this.base.numComps,
  38527. alpha01);
  38528. },
  38529. isPassthrough: ColorSpace.prototype.isPassthrough,
  38530. fillRgb: ColorSpace.prototype.fillRgb,
  38531. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38532. // indexed color maps shouldn't be changed
  38533. return true;
  38534. },
  38535. usesZeroToOneRange: true
  38536. };
  38537. return IndexedCS;
  38538. })();
  38539. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38540. function DeviceGrayCS() {
  38541. this.name = 'DeviceGray';
  38542. this.numComps = 1;
  38543. this.defaultColor = new Float32Array([0]);
  38544. }
  38545. DeviceGrayCS.prototype = {
  38546. getRgb: ColorSpace.prototype.getRgb,
  38547. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38548. dest, destOffset) {
  38549. var c = (src[srcOffset] * 255) | 0;
  38550. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38551. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38552. },
  38553. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38554. dest, destOffset, bits,
  38555. alpha01) {
  38556. var scale = 255 / ((1 << bits) - 1);
  38557. var j = srcOffset, q = destOffset;
  38558. for (var i = 0; i < count; ++i) {
  38559. var c = (scale * src[j++]) | 0;
  38560. dest[q++] = c;
  38561. dest[q++] = c;
  38562. dest[q++] = c;
  38563. q += alpha01;
  38564. }
  38565. },
  38566. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38567. alpha01) {
  38568. return inputLength * (3 + alpha01);
  38569. },
  38570. isPassthrough: ColorSpace.prototype.isPassthrough,
  38571. fillRgb: ColorSpace.prototype.fillRgb,
  38572. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38573. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38574. },
  38575. usesZeroToOneRange: true
  38576. };
  38577. return DeviceGrayCS;
  38578. })();
  38579. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38580. function DeviceRgbCS() {
  38581. this.name = 'DeviceRGB';
  38582. this.numComps = 3;
  38583. this.defaultColor = new Float32Array([0, 0, 0]);
  38584. }
  38585. DeviceRgbCS.prototype = {
  38586. getRgb: ColorSpace.prototype.getRgb,
  38587. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38588. dest, destOffset) {
  38589. var r = (src[srcOffset] * 255) | 0;
  38590. var g = (src[srcOffset + 1] * 255) | 0;
  38591. var b = (src[srcOffset + 2] * 255) | 0;
  38592. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38593. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38594. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38595. },
  38596. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38597. dest, destOffset, bits,
  38598. alpha01) {
  38599. if (bits === 8 && alpha01 === 0) {
  38600. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38601. return;
  38602. }
  38603. var scale = 255 / ((1 << bits) - 1);
  38604. var j = srcOffset, q = destOffset;
  38605. for (var i = 0; i < count; ++i) {
  38606. dest[q++] = (scale * src[j++]) | 0;
  38607. dest[q++] = (scale * src[j++]) | 0;
  38608. dest[q++] = (scale * src[j++]) | 0;
  38609. q += alpha01;
  38610. }
  38611. },
  38612. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38613. alpha01) {
  38614. return (inputLength * (3 + alpha01) / 3) | 0;
  38615. },
  38616. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38617. return bits === 8;
  38618. },
  38619. fillRgb: ColorSpace.prototype.fillRgb,
  38620. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38621. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38622. },
  38623. usesZeroToOneRange: true
  38624. };
  38625. return DeviceRgbCS;
  38626. })();
  38627. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38628. // The coefficients below was found using numerical analysis: the method of
  38629. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38630. // where color_value is the tabular value from the table of sampled RGB colors
  38631. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38632. // CMYK color conversion using the estimation below:
  38633. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38634. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38635. var c = src[srcOffset + 0] * srcScale;
  38636. var m = src[srcOffset + 1] * srcScale;
  38637. var y = src[srcOffset + 2] * srcScale;
  38638. var k = src[srcOffset + 3] * srcScale;
  38639. var r =
  38640. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38641. 18.82290502165302 * y + 212.25662451639585 * k +
  38642. -285.2331026137004) +
  38643. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38644. -17.873870861415444 * k - 5.497006427196366) +
  38645. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38646. 17.5119270841813) +
  38647. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38648. var g =
  38649. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38650. 6.871425592049007 * y + 31.159100130055922 * k +
  38651. -79.2970844816548) +
  38652. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38653. 131.35250912493976 * k - 190.9453302588951) +
  38654. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38655. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38656. var b =
  38657. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38658. 30.89978309703729 * y - 0.23883238689178934 * k +
  38659. -14.183576799673286) +
  38660. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38661. 50.606957656360734 * k - 112.23884253719248) +
  38662. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38663. -193.58209356861505) +
  38664. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38665. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38666. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38667. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38668. }
  38669. function DeviceCmykCS() {
  38670. this.name = 'DeviceCMYK';
  38671. this.numComps = 4;
  38672. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38673. }
  38674. DeviceCmykCS.prototype = {
  38675. getRgb: ColorSpace.prototype.getRgb,
  38676. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38677. dest, destOffset) {
  38678. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38679. },
  38680. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38681. dest, destOffset, bits,
  38682. alpha01) {
  38683. var scale = 1 / ((1 << bits) - 1);
  38684. for (var i = 0; i < count; i++) {
  38685. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38686. srcOffset += 4;
  38687. destOffset += 3 + alpha01;
  38688. }
  38689. },
  38690. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38691. alpha01) {
  38692. return (inputLength / 4 * (3 + alpha01)) | 0;
  38693. },
  38694. isPassthrough: ColorSpace.prototype.isPassthrough,
  38695. fillRgb: ColorSpace.prototype.fillRgb,
  38696. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38697. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38698. },
  38699. usesZeroToOneRange: true
  38700. };
  38701. return DeviceCmykCS;
  38702. })();
  38703. //
  38704. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38705. //
  38706. var CalGrayCS = (function CalGrayCSClosure() {
  38707. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38708. this.name = 'CalGray';
  38709. this.numComps = 1;
  38710. this.defaultColor = new Float32Array([0]);
  38711. if (!whitePoint) {
  38712. error('WhitePoint missing - required for color space CalGray');
  38713. }
  38714. blackPoint = blackPoint || [0, 0, 0];
  38715. gamma = gamma || 1;
  38716. // Translate arguments to spec variables.
  38717. this.XW = whitePoint[0];
  38718. this.YW = whitePoint[1];
  38719. this.ZW = whitePoint[2];
  38720. this.XB = blackPoint[0];
  38721. this.YB = blackPoint[1];
  38722. this.ZB = blackPoint[2];
  38723. this.G = gamma;
  38724. // Validate variables as per spec.
  38725. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38726. error('Invalid WhitePoint components for ' + this.name +
  38727. ', no fallback available');
  38728. }
  38729. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38730. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38731. this.XB = this.YB = this.ZB = 0;
  38732. }
  38733. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38734. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38735. ', ZB: ' + this.ZB + ', only default values are supported.');
  38736. }
  38737. if (this.G < 1) {
  38738. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38739. ', falling back to default');
  38740. this.G = 1;
  38741. }
  38742. }
  38743. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38744. // A represents a gray component of a calibrated gray space.
  38745. // A <---> AG in the spec
  38746. var A = src[srcOffset] * scale;
  38747. var AG = Math.pow(A, cs.G);
  38748. // Computes L as per spec. ( = cs.YW * AG )
  38749. // Except if other than default BlackPoint values are used.
  38750. var L = cs.YW * AG;
  38751. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38752. // Convert values to rgb range [0, 255].
  38753. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38754. dest[destOffset] = val;
  38755. dest[destOffset + 1] = val;
  38756. dest[destOffset + 2] = val;
  38757. }
  38758. CalGrayCS.prototype = {
  38759. getRgb: ColorSpace.prototype.getRgb,
  38760. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38761. dest, destOffset) {
  38762. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38763. },
  38764. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38765. dest, destOffset, bits,
  38766. alpha01) {
  38767. var scale = 1 / ((1 << bits) - 1);
  38768. for (var i = 0; i < count; ++i) {
  38769. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38770. srcOffset += 1;
  38771. destOffset += 3 + alpha01;
  38772. }
  38773. },
  38774. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38775. return inputLength * (3 + alpha01);
  38776. },
  38777. isPassthrough: ColorSpace.prototype.isPassthrough,
  38778. fillRgb: ColorSpace.prototype.fillRgb,
  38779. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38780. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38781. },
  38782. usesZeroToOneRange: true
  38783. };
  38784. return CalGrayCS;
  38785. })();
  38786. //
  38787. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38788. //
  38789. var CalRGBCS = (function CalRGBCSClosure() {
  38790. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38791. // matrices.
  38792. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38793. 0.8951, 0.2664, -0.1614,
  38794. -0.7502, 1.7135, 0.0367,
  38795. 0.0389, -0.0685, 1.0296]);
  38796. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38797. 0.9869929, -0.1470543, 0.1599627,
  38798. 0.4323053, 0.5183603, 0.0492912,
  38799. -0.0085287, 0.0400428, 0.9684867]);
  38800. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38801. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38802. 3.2404542, -1.5371385, -0.4985314,
  38803. -0.9692660, 1.8760108, 0.0415560,
  38804. 0.0556434, -0.2040259, 1.0572252]);
  38805. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38806. var tempNormalizeMatrix = new Float32Array(3);
  38807. var tempConvertMatrix1 = new Float32Array(3);
  38808. var tempConvertMatrix2 = new Float32Array(3);
  38809. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38810. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38811. this.name = 'CalRGB';
  38812. this.numComps = 3;
  38813. this.defaultColor = new Float32Array(3);
  38814. if (!whitePoint) {
  38815. error('WhitePoint missing - required for color space CalRGB');
  38816. }
  38817. blackPoint = blackPoint || new Float32Array(3);
  38818. gamma = gamma || new Float32Array([1, 1, 1]);
  38819. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38820. // Translate arguments to spec variables.
  38821. var XW = whitePoint[0];
  38822. var YW = whitePoint[1];
  38823. var ZW = whitePoint[2];
  38824. this.whitePoint = whitePoint;
  38825. var XB = blackPoint[0];
  38826. var YB = blackPoint[1];
  38827. var ZB = blackPoint[2];
  38828. this.blackPoint = blackPoint;
  38829. this.GR = gamma[0];
  38830. this.GG = gamma[1];
  38831. this.GB = gamma[2];
  38832. this.MXA = matrix[0];
  38833. this.MYA = matrix[1];
  38834. this.MZA = matrix[2];
  38835. this.MXB = matrix[3];
  38836. this.MYB = matrix[4];
  38837. this.MZB = matrix[5];
  38838. this.MXC = matrix[6];
  38839. this.MYC = matrix[7];
  38840. this.MZC = matrix[8];
  38841. // Validate variables as per spec.
  38842. if (XW < 0 || ZW < 0 || YW !== 1) {
  38843. error('Invalid WhitePoint components for ' + this.name +
  38844. ', no fallback available');
  38845. }
  38846. if (XB < 0 || YB < 0 || ZB < 0) {
  38847. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  38848. ', ' + ZB + '], falling back to default');
  38849. this.blackPoint = new Float32Array(3);
  38850. }
  38851. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  38852. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  38853. '] for ' + this.name + ', falling back to default');
  38854. this.GR = this.GG = this.GB = 1;
  38855. }
  38856. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  38857. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  38858. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  38859. info('Invalid Matrix for ' + this.name + ' [' +
  38860. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  38861. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  38862. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  38863. '], falling back to default');
  38864. this.MXA = this.MYB = this.MZC = 1;
  38865. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  38866. }
  38867. }
  38868. function matrixProduct(a, b, result) {
  38869. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  38870. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  38871. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  38872. }
  38873. function convertToFlat(sourceWhitePoint, LMS, result) {
  38874. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  38875. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  38876. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  38877. }
  38878. function convertToD65(sourceWhitePoint, LMS, result) {
  38879. var D65X = 0.95047;
  38880. var D65Y = 1;
  38881. var D65Z = 1.08883;
  38882. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  38883. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  38884. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  38885. }
  38886. function sRGBTransferFunction(color) {
  38887. // See http://en.wikipedia.org/wiki/SRGB.
  38888. if (color <= 0.0031308){
  38889. return adjustToRange(0, 1, 12.92 * color);
  38890. }
  38891. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  38892. }
  38893. function adjustToRange(min, max, value) {
  38894. return Math.max(min, Math.min(max, value));
  38895. }
  38896. function decodeL(L) {
  38897. if (L < 0) {
  38898. return -decodeL(-L);
  38899. }
  38900. if (L > 8.0) {
  38901. return Math.pow(((L + 16) / 116), 3);
  38902. }
  38903. return L * DECODE_L_CONSTANT;
  38904. }
  38905. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  38906. // In case the blackPoint is already the default blackPoint then there is
  38907. // no need to do compensation.
  38908. if (sourceBlackPoint[0] === 0 &&
  38909. sourceBlackPoint[1] === 0 &&
  38910. sourceBlackPoint[2] === 0) {
  38911. result[0] = XYZ_Flat[0];
  38912. result[1] = XYZ_Flat[1];
  38913. result[2] = XYZ_Flat[2];
  38914. return;
  38915. }
  38916. // For the blackPoint calculation details, please see
  38917. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38918. // AdobeBPC.pdf.
  38919. // The destination blackPoint is the default blackPoint [0, 0, 0].
  38920. var zeroDecodeL = decodeL(0);
  38921. var X_DST = zeroDecodeL;
  38922. var X_SRC = decodeL(sourceBlackPoint[0]);
  38923. var Y_DST = zeroDecodeL;
  38924. var Y_SRC = decodeL(sourceBlackPoint[1]);
  38925. var Z_DST = zeroDecodeL;
  38926. var Z_SRC = decodeL(sourceBlackPoint[2]);
  38927. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  38928. var X_Offset = 1 - X_Scale;
  38929. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  38930. var Y_Offset = 1 - Y_Scale;
  38931. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  38932. var Z_Offset = 1 - Z_Scale;
  38933. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  38934. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  38935. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  38936. }
  38937. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  38938. // In case the whitePoint is already flat then there is no need to do
  38939. // normalization.
  38940. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  38941. result[0] = XYZ_In[0];
  38942. result[1] = XYZ_In[1];
  38943. result[2] = XYZ_In[2];
  38944. return;
  38945. }
  38946. var LMS = result;
  38947. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38948. var LMS_Flat = tempNormalizeMatrix;
  38949. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  38950. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  38951. }
  38952. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  38953. var LMS = result;
  38954. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38955. var LMS_D65 = tempNormalizeMatrix;
  38956. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  38957. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  38958. }
  38959. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38960. // A, B and C represent a red, green and blue components of a calibrated
  38961. // rgb space.
  38962. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  38963. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  38964. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  38965. // A <---> AGR in the spec
  38966. // B <---> BGG in the spec
  38967. // C <---> CGB in the spec
  38968. var AGR = Math.pow(A, cs.GR);
  38969. var BGG = Math.pow(B, cs.GG);
  38970. var CGB = Math.pow(C, cs.GB);
  38971. // Computes intermediate variables L, M, N as per spec.
  38972. // To decode X, Y, Z values map L, M, N directly to them.
  38973. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  38974. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  38975. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  38976. // The following calculations are based on this document:
  38977. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38978. // AdobeBPC.pdf.
  38979. var XYZ = tempConvertMatrix1;
  38980. XYZ[0] = X;
  38981. XYZ[1] = Y;
  38982. XYZ[2] = Z;
  38983. var XYZ_Flat = tempConvertMatrix2;
  38984. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  38985. var XYZ_Black = tempConvertMatrix1;
  38986. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  38987. var XYZ_D65 = tempConvertMatrix2;
  38988. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  38989. var SRGB = tempConvertMatrix1;
  38990. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  38991. var sR = sRGBTransferFunction(SRGB[0]);
  38992. var sG = sRGBTransferFunction(SRGB[1]);
  38993. var sB = sRGBTransferFunction(SRGB[2]);
  38994. // Convert the values to rgb range [0, 255].
  38995. dest[destOffset] = Math.round(sR * 255);
  38996. dest[destOffset + 1] = Math.round(sG * 255);
  38997. dest[destOffset + 2] = Math.round(sB * 255);
  38998. }
  38999. CalRGBCS.prototype = {
  39000. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  39001. var rgb = new Uint8Array(3);
  39002. this.getRgbItem(src, srcOffset, rgb, 0);
  39003. return rgb;
  39004. },
  39005. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  39006. dest, destOffset) {
  39007. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  39008. },
  39009. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  39010. dest, destOffset, bits,
  39011. alpha01) {
  39012. var scale = 1 / ((1 << bits) - 1);
  39013. for (var i = 0; i < count; ++i) {
  39014. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  39015. srcOffset += 3;
  39016. destOffset += 3 + alpha01;
  39017. }
  39018. },
  39019. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  39020. return (inputLength * (3 + alpha01) / 3) | 0;
  39021. },
  39022. isPassthrough: ColorSpace.prototype.isPassthrough,
  39023. fillRgb: ColorSpace.prototype.fillRgb,
  39024. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  39025. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39026. },
  39027. usesZeroToOneRange: true
  39028. };
  39029. return CalRGBCS;
  39030. })();
  39031. //
  39032. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  39033. //
  39034. var LabCS = (function LabCSClosure() {
  39035. function LabCS(whitePoint, blackPoint, range) {
  39036. this.name = 'Lab';
  39037. this.numComps = 3;
  39038. this.defaultColor = new Float32Array([0, 0, 0]);
  39039. if (!whitePoint) {
  39040. error('WhitePoint missing - required for color space Lab');
  39041. }
  39042. blackPoint = blackPoint || [0, 0, 0];
  39043. range = range || [-100, 100, -100, 100];
  39044. // Translate args to spec variables
  39045. this.XW = whitePoint[0];
  39046. this.YW = whitePoint[1];
  39047. this.ZW = whitePoint[2];
  39048. this.amin = range[0];
  39049. this.amax = range[1];
  39050. this.bmin = range[2];
  39051. this.bmax = range[3];
  39052. // These are here just for completeness - the spec doesn't offer any
  39053. // formulas that use BlackPoint in Lab
  39054. this.XB = blackPoint[0];
  39055. this.YB = blackPoint[1];
  39056. this.ZB = blackPoint[2];
  39057. // Validate vars as per spec
  39058. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39059. error('Invalid WhitePoint components, no fallback available');
  39060. }
  39061. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39062. info('Invalid BlackPoint, falling back to default');
  39063. this.XB = this.YB = this.ZB = 0;
  39064. }
  39065. if (this.amin > this.amax || this.bmin > this.bmax) {
  39066. info('Invalid Range, falling back to defaults');
  39067. this.amin = -100;
  39068. this.amax = 100;
  39069. this.bmin = -100;
  39070. this.bmax = 100;
  39071. }
  39072. }
  39073. // Function g(x) from spec
  39074. function fn_g(x) {
  39075. if (x >= 6 / 29) {
  39076. return x * x * x;
  39077. } else {
  39078. return (108 / 841) * (x - 4 / 29);
  39079. }
  39080. }
  39081. function decode(value, high1, low2, high2) {
  39082. return low2 + (value) * (high2 - low2) / (high1);
  39083. }
  39084. // If decoding is needed maxVal should be 2^bits per component - 1.
  39085. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  39086. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  39087. // not the usual [0, 1]. If a command like setFillColor is used the src
  39088. // values will already be within the correct range. However, if we are
  39089. // converting an image we have to map the values to the correct range given
  39090. // above.
  39091. // Ls,as,bs <---> L*,a*,b* in the spec
  39092. var Ls = src[srcOffset];
  39093. var as = src[srcOffset + 1];
  39094. var bs = src[srcOffset + 2];
  39095. if (maxVal !== false) {
  39096. Ls = decode(Ls, maxVal, 0, 100);
  39097. as = decode(as, maxVal, cs.amin, cs.amax);
  39098. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  39099. }
  39100. // Adjust limits of 'as' and 'bs'
  39101. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  39102. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  39103. // Computes intermediate variables X,Y,Z as per spec
  39104. var M = (Ls + 16) / 116;
  39105. var L = M + (as / 500);
  39106. var N = M - (bs / 200);
  39107. var X = cs.XW * fn_g(L);
  39108. var Y = cs.YW * fn_g(M);
  39109. var Z = cs.ZW * fn_g(N);
  39110. var r, g, b;
  39111. // Using different conversions for D50 and D65 white points,
  39112. // per http://www.color.org/srgb.pdf
  39113. if (cs.ZW < 1) {
  39114. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  39115. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  39116. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  39117. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  39118. } else {
  39119. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  39120. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  39121. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  39122. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  39123. }
  39124. // clamp color values to [0,1] range then convert to [0,255] range.
  39125. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  39126. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  39127. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  39128. }
  39129. LabCS.prototype = {
  39130. getRgb: ColorSpace.prototype.getRgb,
  39131. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  39132. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  39133. },
  39134. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  39135. dest, destOffset, bits,
  39136. alpha01) {
  39137. var maxVal = (1 << bits) - 1;
  39138. for (var i = 0; i < count; i++) {
  39139. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  39140. srcOffset += 3;
  39141. destOffset += 3 + alpha01;
  39142. }
  39143. },
  39144. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  39145. return (inputLength * (3 + alpha01) / 3) | 0;
  39146. },
  39147. isPassthrough: ColorSpace.prototype.isPassthrough,
  39148. fillRgb: ColorSpace.prototype.fillRgb,
  39149. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  39150. // XXX: Decoding is handled with the lab conversion because of the strange
  39151. // ranges that are used.
  39152. return true;
  39153. },
  39154. usesZeroToOneRange: false
  39155. };
  39156. return LabCS;
  39157. })();
  39158. // TODO refactor to remove dependency on image.js
  39159. function _setCoreImage(coreImage_) {
  39160. coreImage = coreImage_;
  39161. PDFImage = coreImage_.PDFImage;
  39162. }
  39163. exports._setCoreImage = _setCoreImage;
  39164. exports.ColorSpace = ColorSpace;
  39165. // TODO refactor to remove dependency on colorspace.js
  39166. coreStream._setCoreColorSpace(exports);
  39167. }));
  39168. (function (root, factory) {
  39169. {
  39170. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39171. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39172. root.pdfjsCoreJpx);
  39173. }
  39174. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39175. coreStream, coreJpx) {
  39176. var ImageKind = sharedUtil.ImageKind;
  39177. var assert = sharedUtil.assert;
  39178. var error = sharedUtil.error;
  39179. var info = sharedUtil.info;
  39180. var isArray = sharedUtil.isArray;
  39181. var warn = sharedUtil.warn;
  39182. var Name = corePrimitives.Name;
  39183. var isStream = corePrimitives.isStream;
  39184. var ColorSpace = coreColorSpace.ColorSpace;
  39185. var DecodeStream = coreStream.DecodeStream;
  39186. var Stream = coreStream.Stream;
  39187. var JpegStream = coreStream.JpegStream;
  39188. var JpxImage = coreJpx.JpxImage;
  39189. var PDFImage = (function PDFImageClosure() {
  39190. /**
  39191. * Decode the image in the main thread if it supported. Resovles the promise
  39192. * when the image data is ready.
  39193. */
  39194. function handleImageData(handler, xref, res, image) {
  39195. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  39196. // For natively supported jpegs send them to the main thread for decoding.
  39197. var dict = image.dict;
  39198. var colorSpace = dict.get('ColorSpace', 'CS');
  39199. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39200. var numComps = colorSpace.numComps;
  39201. var decodePromise = handler.sendWithPromise('JpegDecode',
  39202. [image.getIR(), numComps]);
  39203. return decodePromise.then(function (message) {
  39204. var data = message.data;
  39205. return new Stream(data, 0, data.length, image.dict);
  39206. });
  39207. } else {
  39208. return Promise.resolve(image);
  39209. }
  39210. }
  39211. /**
  39212. * Decode and clamp a value. The formula is different from the spec because we
  39213. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39214. */
  39215. function decodeAndClamp(value, addend, coefficient, max) {
  39216. value = addend + value * coefficient;
  39217. // Clamp the value to the range
  39218. return (value < 0 ? 0 : (value > max ? max : value));
  39219. }
  39220. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  39221. this.image = image;
  39222. var dict = image.dict;
  39223. if (dict.has('Filter')) {
  39224. var filter = dict.get('Filter').name;
  39225. if (filter === 'JPXDecode') {
  39226. var jpxImage = new JpxImage();
  39227. jpxImage.parseImageProperties(image.stream);
  39228. image.stream.reset();
  39229. image.bitsPerComponent = jpxImage.bitsPerComponent;
  39230. image.numComps = jpxImage.componentsCount;
  39231. } else if (filter === 'JBIG2Decode') {
  39232. image.bitsPerComponent = 1;
  39233. image.numComps = 1;
  39234. }
  39235. }
  39236. // TODO cache rendered images?
  39237. this.width = dict.get('Width', 'W');
  39238. this.height = dict.get('Height', 'H');
  39239. if (this.width < 1 || this.height < 1) {
  39240. error('Invalid image width: ' + this.width + ' or height: ' +
  39241. this.height);
  39242. }
  39243. this.interpolate = dict.get('Interpolate', 'I') || false;
  39244. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39245. this.matte = dict.get('Matte') || false;
  39246. var bitsPerComponent = image.bitsPerComponent;
  39247. if (!bitsPerComponent) {
  39248. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39249. if (!bitsPerComponent) {
  39250. if (this.imageMask) {
  39251. bitsPerComponent = 1;
  39252. } else {
  39253. error('Bits per component missing in image: ' + this.imageMask);
  39254. }
  39255. }
  39256. }
  39257. this.bpc = bitsPerComponent;
  39258. if (!this.imageMask) {
  39259. var colorSpace = dict.get('ColorSpace', 'CS');
  39260. if (!colorSpace) {
  39261. info('JPX images (which do not require color spaces)');
  39262. switch (image.numComps) {
  39263. case 1:
  39264. colorSpace = Name.get('DeviceGray');
  39265. break;
  39266. case 3:
  39267. colorSpace = Name.get('DeviceRGB');
  39268. break;
  39269. case 4:
  39270. colorSpace = Name.get('DeviceCMYK');
  39271. break;
  39272. default:
  39273. error('JPX images with ' + this.numComps +
  39274. ' color components not supported.');
  39275. }
  39276. }
  39277. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39278. this.numComps = this.colorSpace.numComps;
  39279. }
  39280. this.decode = dict.get('Decode', 'D');
  39281. this.needsDecode = false;
  39282. if (this.decode &&
  39283. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39284. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39285. this.needsDecode = true;
  39286. // Do some preprocessing to avoid more math.
  39287. var max = (1 << bitsPerComponent) - 1;
  39288. this.decodeCoefficients = [];
  39289. this.decodeAddends = [];
  39290. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39291. var dmin = this.decode[i];
  39292. var dmax = this.decode[i + 1];
  39293. this.decodeCoefficients[j] = dmax - dmin;
  39294. this.decodeAddends[j] = max * dmin;
  39295. }
  39296. }
  39297. if (smask) {
  39298. this.smask = new PDFImage(xref, res, smask, false);
  39299. } else if (mask) {
  39300. if (isStream(mask)) {
  39301. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39302. if (!imageMask) {
  39303. warn('Ignoring /Mask in image without /ImageMask.');
  39304. } else {
  39305. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39306. }
  39307. } else {
  39308. // Color key mask (just an array).
  39309. this.mask = mask;
  39310. }
  39311. }
  39312. }
  39313. /**
  39314. * Handles processing of image data and returns the Promise that is resolved
  39315. * with a PDFImage when the image is ready to be used.
  39316. */
  39317. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39318. res, image, inline) {
  39319. var imagePromise = handleImageData(handler, xref, res, image);
  39320. var smaskPromise;
  39321. var maskPromise;
  39322. var smask = image.dict.get('SMask');
  39323. var mask = image.dict.get('Mask');
  39324. if (smask) {
  39325. smaskPromise = handleImageData(handler, xref, res, smask);
  39326. maskPromise = Promise.resolve(null);
  39327. } else {
  39328. smaskPromise = Promise.resolve(null);
  39329. if (mask) {
  39330. if (isStream(mask)) {
  39331. maskPromise = handleImageData(handler, xref, res, mask);
  39332. } else if (isArray(mask)) {
  39333. maskPromise = Promise.resolve(mask);
  39334. } else {
  39335. warn('Unsupported mask format.');
  39336. maskPromise = Promise.resolve(null);
  39337. }
  39338. } else {
  39339. maskPromise = Promise.resolve(null);
  39340. }
  39341. }
  39342. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39343. function(results) {
  39344. var imageData = results[0];
  39345. var smaskData = results[1];
  39346. var maskData = results[2];
  39347. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39348. });
  39349. };
  39350. /**
  39351. * Resize an image using the nearest neighbor algorithm. Currently only
  39352. * supports one and three component images.
  39353. * @param {TypedArray} pixels The original image with one component.
  39354. * @param {Number} bpc Number of bits per component.
  39355. * @param {Number} components Number of color components, 1 or 3 is supported.
  39356. * @param {Number} w1 Original width.
  39357. * @param {Number} h1 Original height.
  39358. * @param {Number} w2 New width.
  39359. * @param {Number} h2 New height.
  39360. * @param {TypedArray} dest (Optional) The destination buffer.
  39361. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  39362. * @return {TypedArray} Resized image data.
  39363. */
  39364. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  39365. w1, h1, w2, h2, dest, alpha01) {
  39366. if (components !== 1 && components !== 3) {
  39367. error('Unsupported component count for resizing.');
  39368. }
  39369. var length = w2 * h2 * components;
  39370. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  39371. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39372. var xRatio = w1 / w2;
  39373. var yRatio = h1 / h2;
  39374. var i, j, py, newIndex = 0, oldIndex;
  39375. var xScaled = new Uint16Array(w2);
  39376. var w1Scanline = w1 * components;
  39377. if (alpha01 !== 1) {
  39378. alpha01 = 0;
  39379. }
  39380. for (j = 0; j < w2; j++) {
  39381. xScaled[j] = Math.floor(j * xRatio) * components;
  39382. }
  39383. if (components === 1) {
  39384. for (i = 0; i < h2; i++) {
  39385. py = Math.floor(i * yRatio) * w1Scanline;
  39386. for (j = 0; j < w2; j++) {
  39387. oldIndex = py + xScaled[j];
  39388. temp[newIndex++] = pixels[oldIndex];
  39389. }
  39390. }
  39391. } else if (components === 3) {
  39392. for (i = 0; i < h2; i++) {
  39393. py = Math.floor(i * yRatio) * w1Scanline;
  39394. for (j = 0; j < w2; j++) {
  39395. oldIndex = py + xScaled[j];
  39396. temp[newIndex++] = pixels[oldIndex++];
  39397. temp[newIndex++] = pixels[oldIndex++];
  39398. temp[newIndex++] = pixels[oldIndex++];
  39399. newIndex += alpha01;
  39400. }
  39401. }
  39402. }
  39403. return temp;
  39404. };
  39405. PDFImage.createMask =
  39406. function PDFImage_createMask(imgArray, width, height,
  39407. imageIsFromDecodeStream, inverseDecode) {
  39408. // |imgArray| might not contain full data for every pixel of the mask, so
  39409. // we need to distinguish between |computedLength| and |actualLength|.
  39410. // In particular, if inverseDecode is true, then the array we return must
  39411. // have a length of |computedLength|.
  39412. var computedLength = ((width + 7) >> 3) * height;
  39413. var actualLength = imgArray.byteLength;
  39414. var haveFullData = computedLength === actualLength;
  39415. var data, i;
  39416. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39417. // imgArray came from a DecodeStream and its data is in an appropriate
  39418. // form, so we can just transfer it.
  39419. data = imgArray;
  39420. } else if (!inverseDecode) {
  39421. data = new Uint8Array(actualLength);
  39422. data.set(imgArray);
  39423. } else {
  39424. data = new Uint8Array(computedLength);
  39425. data.set(imgArray);
  39426. for (i = actualLength; i < computedLength; i++) {
  39427. data[i] = 0xff;
  39428. }
  39429. }
  39430. // If necessary, invert the original mask data (but not any extra we might
  39431. // have added above). It's safe to modify the array -- whether it's the
  39432. // original or a copy, we're about to transfer it anyway, so nothing else
  39433. // in this thread can be relying on its contents.
  39434. if (inverseDecode) {
  39435. for (i = 0; i < actualLength; i++) {
  39436. data[i] = ~data[i];
  39437. }
  39438. }
  39439. return {data: data, width: width, height: height};
  39440. };
  39441. PDFImage.prototype = {
  39442. get drawWidth() {
  39443. return Math.max(this.width,
  39444. this.smask && this.smask.width || 0,
  39445. this.mask && this.mask.width || 0);
  39446. },
  39447. get drawHeight() {
  39448. return Math.max(this.height,
  39449. this.smask && this.smask.height || 0,
  39450. this.mask && this.mask.height || 0);
  39451. },
  39452. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39453. var bpc = this.bpc;
  39454. var numComps = this.numComps;
  39455. var decodeAddends = this.decodeAddends;
  39456. var decodeCoefficients = this.decodeCoefficients;
  39457. var max = (1 << bpc) - 1;
  39458. var i, ii;
  39459. if (bpc === 1) {
  39460. // If the buffer needed decode that means it just needs to be inverted.
  39461. for (i = 0, ii = buffer.length; i < ii; i++) {
  39462. buffer[i] = +!(buffer[i]);
  39463. }
  39464. return;
  39465. }
  39466. var index = 0;
  39467. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39468. for (var j = 0; j < numComps; j++) {
  39469. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39470. decodeCoefficients[j], max);
  39471. index++;
  39472. }
  39473. }
  39474. },
  39475. getComponents: function PDFImage_getComponents(buffer) {
  39476. var bpc = this.bpc;
  39477. // This image doesn't require any extra work.
  39478. if (bpc === 8) {
  39479. return buffer;
  39480. }
  39481. var width = this.width;
  39482. var height = this.height;
  39483. var numComps = this.numComps;
  39484. var length = width * height * numComps;
  39485. var bufferPos = 0;
  39486. var output = (bpc <= 8 ? new Uint8Array(length) :
  39487. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39488. var rowComps = width * numComps;
  39489. var max = (1 << bpc) - 1;
  39490. var i = 0, ii, buf;
  39491. if (bpc === 1) {
  39492. // Optimization for reading 1 bpc images.
  39493. var mask, loop1End, loop2End;
  39494. for (var j = 0; j < height; j++) {
  39495. loop1End = i + (rowComps & ~7);
  39496. loop2End = i + rowComps;
  39497. // unroll loop for all full bytes
  39498. while (i < loop1End) {
  39499. buf = buffer[bufferPos++];
  39500. output[i] = (buf >> 7) & 1;
  39501. output[i + 1] = (buf >> 6) & 1;
  39502. output[i + 2] = (buf >> 5) & 1;
  39503. output[i + 3] = (buf >> 4) & 1;
  39504. output[i + 4] = (buf >> 3) & 1;
  39505. output[i + 5] = (buf >> 2) & 1;
  39506. output[i + 6] = (buf >> 1) & 1;
  39507. output[i + 7] = buf & 1;
  39508. i += 8;
  39509. }
  39510. // handle remaing bits
  39511. if (i < loop2End) {
  39512. buf = buffer[bufferPos++];
  39513. mask = 128;
  39514. while (i < loop2End) {
  39515. output[i++] = +!!(buf & mask);
  39516. mask >>= 1;
  39517. }
  39518. }
  39519. }
  39520. } else {
  39521. // The general case that handles all other bpc values.
  39522. var bits = 0;
  39523. buf = 0;
  39524. for (i = 0, ii = length; i < ii; ++i) {
  39525. if (i % rowComps === 0) {
  39526. buf = 0;
  39527. bits = 0;
  39528. }
  39529. while (bits < bpc) {
  39530. buf = (buf << 8) | buffer[bufferPos++];
  39531. bits += 8;
  39532. }
  39533. var remainingBits = bits - bpc;
  39534. var value = buf >> remainingBits;
  39535. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39536. buf = buf & ((1 << remainingBits) - 1);
  39537. bits = remainingBits;
  39538. }
  39539. }
  39540. return output;
  39541. },
  39542. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39543. actualHeight, image) {
  39544. var smask = this.smask;
  39545. var mask = this.mask;
  39546. var alphaBuf, sw, sh, i, ii, j;
  39547. if (smask) {
  39548. sw = smask.width;
  39549. sh = smask.height;
  39550. alphaBuf = new Uint8Array(sw * sh);
  39551. smask.fillGrayBuffer(alphaBuf);
  39552. if (sw !== width || sh !== height) {
  39553. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  39554. height);
  39555. }
  39556. } else if (mask) {
  39557. if (mask instanceof PDFImage) {
  39558. sw = mask.width;
  39559. sh = mask.height;
  39560. alphaBuf = new Uint8Array(sw * sh);
  39561. mask.numComps = 1;
  39562. mask.fillGrayBuffer(alphaBuf);
  39563. // Need to invert values in rgbaBuf
  39564. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39565. alphaBuf[i] = 255 - alphaBuf[i];
  39566. }
  39567. if (sw !== width || sh !== height) {
  39568. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  39569. height);
  39570. }
  39571. } else if (isArray(mask)) {
  39572. // Color key mask: if any of the compontents are outside the range
  39573. // then they should be painted.
  39574. alphaBuf = new Uint8Array(width * height);
  39575. var numComps = this.numComps;
  39576. for (i = 0, ii = width * height; i < ii; ++i) {
  39577. var opacity = 0;
  39578. var imageOffset = i * numComps;
  39579. for (j = 0; j < numComps; ++j) {
  39580. var color = image[imageOffset + j];
  39581. var maskOffset = j * 2;
  39582. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39583. opacity = 255;
  39584. break;
  39585. }
  39586. }
  39587. alphaBuf[i] = opacity;
  39588. }
  39589. } else {
  39590. error('Unknown mask format.');
  39591. }
  39592. }
  39593. if (alphaBuf) {
  39594. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39595. rgbaBuf[j] = alphaBuf[i];
  39596. }
  39597. } else {
  39598. // No mask.
  39599. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39600. rgbaBuf[j] = 255;
  39601. }
  39602. }
  39603. },
  39604. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39605. var matte = this.smask && this.smask.matte;
  39606. if (!matte) {
  39607. return;
  39608. }
  39609. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39610. var matteR = matteRgb[0];
  39611. var matteG = matteRgb[1];
  39612. var matteB = matteRgb[2];
  39613. var length = width * height * 4;
  39614. var r, g, b;
  39615. for (var i = 0; i < length; i += 4) {
  39616. var alpha = buffer[i + 3];
  39617. if (alpha === 0) {
  39618. // according formula we have to get Infinity in all components
  39619. // making it white (typical paper color) should be okay
  39620. buffer[i] = 255;
  39621. buffer[i + 1] = 255;
  39622. buffer[i + 2] = 255;
  39623. continue;
  39624. }
  39625. var k = 255 / alpha;
  39626. r = (buffer[i] - matteR) * k + matteR;
  39627. g = (buffer[i + 1] - matteG) * k + matteG;
  39628. b = (buffer[i + 2] - matteB) * k + matteB;
  39629. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  39630. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  39631. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  39632. }
  39633. },
  39634. createImageData: function PDFImage_createImageData(forceRGBA) {
  39635. var drawWidth = this.drawWidth;
  39636. var drawHeight = this.drawHeight;
  39637. var imgData = { // other fields are filled in below
  39638. width: drawWidth,
  39639. height: drawHeight
  39640. };
  39641. var numComps = this.numComps;
  39642. var originalWidth = this.width;
  39643. var originalHeight = this.height;
  39644. var bpc = this.bpc;
  39645. // Rows start at byte boundary.
  39646. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  39647. var imgArray;
  39648. if (!forceRGBA) {
  39649. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  39650. // without any complications, we pass a same-sized copy to the main
  39651. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  39652. // of memory for many scanned documents. It's also much faster.
  39653. //
  39654. // Similarly, if it is a 24-bit-per pixel RGB image without any
  39655. // complications, we avoid expanding by 1.333x to RGBA form.
  39656. var kind;
  39657. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  39658. kind = ImageKind.GRAYSCALE_1BPP;
  39659. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  39660. !this.needsDecode) {
  39661. kind = ImageKind.RGB_24BPP;
  39662. }
  39663. if (kind && !this.smask && !this.mask &&
  39664. drawWidth === originalWidth && drawHeight === originalHeight) {
  39665. imgData.kind = kind;
  39666. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39667. // If imgArray came from a DecodeStream, we're safe to transfer it
  39668. // (and thus neuter it) because it will constitute the entire
  39669. // DecodeStream's data. But if it came from a Stream, we need to
  39670. // copy it because it'll only be a portion of the Stream's data, and
  39671. // the rest will be read later on.
  39672. if (this.image instanceof DecodeStream) {
  39673. imgData.data = imgArray;
  39674. } else {
  39675. var newArray = new Uint8Array(imgArray.length);
  39676. newArray.set(imgArray);
  39677. imgData.data = newArray;
  39678. }
  39679. if (this.needsDecode) {
  39680. // Invert the buffer (which must be grayscale if we reached here).
  39681. assert(kind === ImageKind.GRAYSCALE_1BPP);
  39682. var buffer = imgData.data;
  39683. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39684. buffer[i] ^= 0xff;
  39685. }
  39686. }
  39687. return imgData;
  39688. }
  39689. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  39690. (this.colorSpace.name === 'DeviceGray' ||
  39691. this.colorSpace.name === 'DeviceRGB' ||
  39692. this.colorSpace.name === 'DeviceCMYK')) {
  39693. imgData.kind = ImageKind.RGB_24BPP;
  39694. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  39695. drawWidth, drawHeight, true);
  39696. return imgData;
  39697. }
  39698. }
  39699. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39700. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  39701. var actualHeight = 0 | (imgArray.length / rowBytes *
  39702. drawHeight / originalHeight);
  39703. var comps = this.getComponents(imgArray);
  39704. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  39705. // more compact RGB_24BPP form if allowable.
  39706. var alpha01, maybeUndoPreblend;
  39707. if (!forceRGBA && !this.smask && !this.mask) {
  39708. imgData.kind = ImageKind.RGB_24BPP;
  39709. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  39710. alpha01 = 0;
  39711. maybeUndoPreblend = false;
  39712. } else {
  39713. imgData.kind = ImageKind.RGBA_32BPP;
  39714. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  39715. alpha01 = 1;
  39716. maybeUndoPreblend = true;
  39717. // Color key masking (opacity) must be performed before decoding.
  39718. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  39719. comps);
  39720. }
  39721. if (this.needsDecode) {
  39722. this.decodeBuffer(comps);
  39723. }
  39724. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  39725. drawWidth, drawHeight, actualHeight, bpc, comps,
  39726. alpha01);
  39727. if (maybeUndoPreblend) {
  39728. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  39729. }
  39730. return imgData;
  39731. },
  39732. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  39733. var numComps = this.numComps;
  39734. if (numComps !== 1) {
  39735. error('Reading gray scale from a color image: ' + numComps);
  39736. }
  39737. var width = this.width;
  39738. var height = this.height;
  39739. var bpc = this.bpc;
  39740. // rows start at byte boundary
  39741. var rowBytes = (width * numComps * bpc + 7) >> 3;
  39742. var imgArray = this.getImageBytes(height * rowBytes);
  39743. var comps = this.getComponents(imgArray);
  39744. var i, length;
  39745. if (bpc === 1) {
  39746. // inline decoding (= inversion) for 1 bpc images
  39747. length = width * height;
  39748. if (this.needsDecode) {
  39749. // invert and scale to {0, 255}
  39750. for (i = 0; i < length; ++i) {
  39751. buffer[i] = (comps[i] - 1) & 255;
  39752. }
  39753. } else {
  39754. // scale to {0, 255}
  39755. for (i = 0; i < length; ++i) {
  39756. buffer[i] = (-comps[i]) & 255;
  39757. }
  39758. }
  39759. return;
  39760. }
  39761. if (this.needsDecode) {
  39762. this.decodeBuffer(comps);
  39763. }
  39764. length = width * height;
  39765. // we aren't using a colorspace so we need to scale the value
  39766. var scale = 255 / ((1 << bpc) - 1);
  39767. for (i = 0; i < length; ++i) {
  39768. buffer[i] = (scale * comps[i]) | 0;
  39769. }
  39770. },
  39771. getImageBytes: function PDFImage_getImageBytes(length,
  39772. drawWidth, drawHeight,
  39773. forceRGB) {
  39774. this.image.reset();
  39775. this.image.drawWidth = drawWidth || this.width;
  39776. this.image.drawHeight = drawHeight || this.height;
  39777. this.image.forceRGB = !!forceRGB;
  39778. return this.image.getBytes(length);
  39779. }
  39780. };
  39781. return PDFImage;
  39782. })();
  39783. exports.PDFImage = PDFImage;
  39784. // TODO refactor to remove dependency on colorspace.js
  39785. coreColorSpace._setCoreImage(exports);
  39786. }));
  39787. (function (root, factory) {
  39788. {
  39789. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  39790. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  39791. root.pdfjsCoreColorSpace);
  39792. }
  39793. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  39794. coreColorSpace) {
  39795. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39796. var MissingDataException = sharedUtil.MissingDataException;
  39797. var Util = sharedUtil.Util;
  39798. var assert = sharedUtil.assert;
  39799. var error = sharedUtil.error;
  39800. var info = sharedUtil.info;
  39801. var warn = sharedUtil.warn;
  39802. var isStream = corePrimitives.isStream;
  39803. var PDFFunction = coreFunction.PDFFunction;
  39804. var ColorSpace = coreColorSpace.ColorSpace;
  39805. var ShadingType = {
  39806. FUNCTION_BASED: 1,
  39807. AXIAL: 2,
  39808. RADIAL: 3,
  39809. FREE_FORM_MESH: 4,
  39810. LATTICE_FORM_MESH: 5,
  39811. COONS_PATCH_MESH: 6,
  39812. TENSOR_PATCH_MESH: 7
  39813. };
  39814. var Pattern = (function PatternClosure() {
  39815. // Constructor should define this.getPattern
  39816. function Pattern() {
  39817. error('should not call Pattern constructor');
  39818. }
  39819. Pattern.prototype = {
  39820. // Input: current Canvas context
  39821. // Output: the appropriate fillStyle or strokeStyle
  39822. getPattern: function Pattern_getPattern(ctx) {
  39823. error('Should not call Pattern.getStyle: ' + ctx);
  39824. }
  39825. };
  39826. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  39827. res, handler) {
  39828. var dict = isStream(shading) ? shading.dict : shading;
  39829. var type = dict.get('ShadingType');
  39830. try {
  39831. switch (type) {
  39832. case ShadingType.AXIAL:
  39833. case ShadingType.RADIAL:
  39834. // Both radial and axial shadings are handled by RadialAxial shading.
  39835. return new Shadings.RadialAxial(dict, matrix, xref, res);
  39836. case ShadingType.FREE_FORM_MESH:
  39837. case ShadingType.LATTICE_FORM_MESH:
  39838. case ShadingType.COONS_PATCH_MESH:
  39839. case ShadingType.TENSOR_PATCH_MESH:
  39840. return new Shadings.Mesh(shading, matrix, xref, res);
  39841. default:
  39842. throw new Error('Unsupported ShadingType: ' + type);
  39843. }
  39844. } catch (ex) {
  39845. if (ex instanceof MissingDataException) {
  39846. throw ex;
  39847. }
  39848. handler.send('UnsupportedFeature',
  39849. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  39850. warn(ex);
  39851. return new Shadings.Dummy();
  39852. }
  39853. };
  39854. return Pattern;
  39855. })();
  39856. var Shadings = {};
  39857. // A small number to offset the first/last color stops so we can insert ones to
  39858. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  39859. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  39860. // internally so we have to go bigger.
  39861. Shadings.SMALL_NUMBER = 1e-2;
  39862. // Radial and axial shading have very similar implementations
  39863. // If needed, the implementations can be broken into two classes
  39864. Shadings.RadialAxial = (function RadialAxialClosure() {
  39865. function RadialAxial(dict, matrix, xref, res) {
  39866. this.matrix = matrix;
  39867. this.coordsArr = dict.get('Coords');
  39868. this.shadingType = dict.get('ShadingType');
  39869. this.type = 'Pattern';
  39870. var cs = dict.get('ColorSpace', 'CS');
  39871. cs = ColorSpace.parse(cs, xref, res);
  39872. this.cs = cs;
  39873. var t0 = 0.0, t1 = 1.0;
  39874. if (dict.has('Domain')) {
  39875. var domainArr = dict.get('Domain');
  39876. t0 = domainArr[0];
  39877. t1 = domainArr[1];
  39878. }
  39879. var extendStart = false, extendEnd = false;
  39880. if (dict.has('Extend')) {
  39881. var extendArr = dict.get('Extend');
  39882. extendStart = extendArr[0];
  39883. extendEnd = extendArr[1];
  39884. }
  39885. if (this.shadingType === ShadingType.RADIAL &&
  39886. (!extendStart || !extendEnd)) {
  39887. // Radial gradient only currently works if either circle is fully within
  39888. // the other circle.
  39889. var x1 = this.coordsArr[0];
  39890. var y1 = this.coordsArr[1];
  39891. var r1 = this.coordsArr[2];
  39892. var x2 = this.coordsArr[3];
  39893. var y2 = this.coordsArr[4];
  39894. var r2 = this.coordsArr[5];
  39895. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  39896. if (r1 <= r2 + distance &&
  39897. r2 <= r1 + distance) {
  39898. warn('Unsupported radial gradient.');
  39899. }
  39900. }
  39901. this.extendStart = extendStart;
  39902. this.extendEnd = extendEnd;
  39903. var fnObj = dict.get('Function');
  39904. var fn = PDFFunction.parseArray(xref, fnObj);
  39905. // 10 samples seems good enough for now, but probably won't work
  39906. // if there are sharp color changes. Ideally, we would implement
  39907. // the spec faithfully and add lossless optimizations.
  39908. var diff = t1 - t0;
  39909. var step = diff / 10;
  39910. var colorStops = this.colorStops = [];
  39911. // Protect against bad domains so we don't end up in an infinte loop below.
  39912. if (t0 >= t1 || step <= 0) {
  39913. // Acrobat doesn't seem to handle these cases so we'll ignore for
  39914. // now.
  39915. info('Bad shading domain.');
  39916. return;
  39917. }
  39918. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  39919. var rgbColor;
  39920. for (var i = t0; i <= t1; i += step) {
  39921. ratio[0] = i;
  39922. fn(ratio, 0, color, 0);
  39923. rgbColor = cs.getRgb(color, 0);
  39924. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  39925. colorStops.push([(i - t0) / diff, cssColor]);
  39926. }
  39927. var background = 'transparent';
  39928. if (dict.has('Background')) {
  39929. rgbColor = cs.getRgb(dict.get('Background'), 0);
  39930. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  39931. }
  39932. if (!extendStart) {
  39933. // Insert a color stop at the front and offset the first real color stop
  39934. // so it doesn't conflict with the one we insert.
  39935. colorStops.unshift([0, background]);
  39936. colorStops[1][0] += Shadings.SMALL_NUMBER;
  39937. }
  39938. if (!extendEnd) {
  39939. // Same idea as above in extendStart but for the end.
  39940. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  39941. colorStops.push([1, background]);
  39942. }
  39943. this.colorStops = colorStops;
  39944. }
  39945. RadialAxial.prototype = {
  39946. getIR: function RadialAxial_getIR() {
  39947. var coordsArr = this.coordsArr;
  39948. var shadingType = this.shadingType;
  39949. var type, p0, p1, r0, r1;
  39950. if (shadingType === ShadingType.AXIAL) {
  39951. p0 = [coordsArr[0], coordsArr[1]];
  39952. p1 = [coordsArr[2], coordsArr[3]];
  39953. r0 = null;
  39954. r1 = null;
  39955. type = 'axial';
  39956. } else if (shadingType === ShadingType.RADIAL) {
  39957. p0 = [coordsArr[0], coordsArr[1]];
  39958. p1 = [coordsArr[3], coordsArr[4]];
  39959. r0 = coordsArr[2];
  39960. r1 = coordsArr[5];
  39961. type = 'radial';
  39962. } else {
  39963. error('getPattern type unknown: ' + shadingType);
  39964. }
  39965. var matrix = this.matrix;
  39966. if (matrix) {
  39967. p0 = Util.applyTransform(p0, matrix);
  39968. p1 = Util.applyTransform(p1, matrix);
  39969. if (shadingType === ShadingType.RADIAL) {
  39970. var scale = Util.singularValueDecompose2dScale(matrix);
  39971. r0 *= scale[0];
  39972. r1 *= scale[1];
  39973. }
  39974. }
  39975. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  39976. }
  39977. };
  39978. return RadialAxial;
  39979. })();
  39980. // All mesh shading. For now, they will be presented as set of the triangles
  39981. // to be drawn on the canvas and rgb color for each vertex.
  39982. Shadings.Mesh = (function MeshClosure() {
  39983. function MeshStreamReader(stream, context) {
  39984. this.stream = stream;
  39985. this.context = context;
  39986. this.buffer = 0;
  39987. this.bufferLength = 0;
  39988. var numComps = context.numComps;
  39989. this.tmpCompsBuf = new Float32Array(numComps);
  39990. var csNumComps = context.colorSpace.numComps;
  39991. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  39992. this.tmpCompsBuf;
  39993. }
  39994. MeshStreamReader.prototype = {
  39995. get hasData() {
  39996. if (this.stream.end) {
  39997. return this.stream.pos < this.stream.end;
  39998. }
  39999. if (this.bufferLength > 0) {
  40000. return true;
  40001. }
  40002. var nextByte = this.stream.getByte();
  40003. if (nextByte < 0) {
  40004. return false;
  40005. }
  40006. this.buffer = nextByte;
  40007. this.bufferLength = 8;
  40008. return true;
  40009. },
  40010. readBits: function MeshStreamReader_readBits(n) {
  40011. var buffer = this.buffer;
  40012. var bufferLength = this.bufferLength;
  40013. if (n === 32) {
  40014. if (bufferLength === 0) {
  40015. return ((this.stream.getByte() << 24) |
  40016. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  40017. this.stream.getByte()) >>> 0;
  40018. }
  40019. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  40020. (this.stream.getByte() << 8) | this.stream.getByte();
  40021. var nextByte = this.stream.getByte();
  40022. this.buffer = nextByte & ((1 << bufferLength) - 1);
  40023. return ((buffer << (8 - bufferLength)) |
  40024. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  40025. }
  40026. if (n === 8 && bufferLength === 0) {
  40027. return this.stream.getByte();
  40028. }
  40029. while (bufferLength < n) {
  40030. buffer = (buffer << 8) | this.stream.getByte();
  40031. bufferLength += 8;
  40032. }
  40033. bufferLength -= n;
  40034. this.bufferLength = bufferLength;
  40035. this.buffer = buffer & ((1 << bufferLength) - 1);
  40036. return buffer >> bufferLength;
  40037. },
  40038. align: function MeshStreamReader_align() {
  40039. this.buffer = 0;
  40040. this.bufferLength = 0;
  40041. },
  40042. readFlag: function MeshStreamReader_readFlag() {
  40043. return this.readBits(this.context.bitsPerFlag);
  40044. },
  40045. readCoordinate: function MeshStreamReader_readCoordinate() {
  40046. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  40047. var xi = this.readBits(bitsPerCoordinate);
  40048. var yi = this.readBits(bitsPerCoordinate);
  40049. var decode = this.context.decode;
  40050. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  40051. 2.3283064365386963e-10; // 2 ^ -32
  40052. return [
  40053. xi * scale * (decode[1] - decode[0]) + decode[0],
  40054. yi * scale * (decode[3] - decode[2]) + decode[2]
  40055. ];
  40056. },
  40057. readComponents: function MeshStreamReader_readComponents() {
  40058. var numComps = this.context.numComps;
  40059. var bitsPerComponent = this.context.bitsPerComponent;
  40060. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  40061. 2.3283064365386963e-10; // 2 ^ -32
  40062. var decode = this.context.decode;
  40063. var components = this.tmpCompsBuf;
  40064. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  40065. var ci = this.readBits(bitsPerComponent);
  40066. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  40067. }
  40068. var color = this.tmpCsCompsBuf;
  40069. if (this.context.colorFn) {
  40070. this.context.colorFn(components, 0, color, 0);
  40071. }
  40072. return this.context.colorSpace.getRgb(color, 0);
  40073. }
  40074. };
  40075. function decodeType4Shading(mesh, reader) {
  40076. var coords = mesh.coords;
  40077. var colors = mesh.colors;
  40078. var operators = [];
  40079. var ps = []; // not maintaining cs since that will match ps
  40080. var verticesLeft = 0; // assuming we have all data to start a new triangle
  40081. while (reader.hasData) {
  40082. var f = reader.readFlag();
  40083. var coord = reader.readCoordinate();
  40084. var color = reader.readComponents();
  40085. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  40086. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  40087. switch (f) {
  40088. case 0:
  40089. verticesLeft = 3;
  40090. break;
  40091. case 1:
  40092. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  40093. verticesLeft = 1;
  40094. break;
  40095. case 2:
  40096. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  40097. verticesLeft = 1;
  40098. break;
  40099. }
  40100. operators.push(f);
  40101. }
  40102. ps.push(coords.length);
  40103. coords.push(coord);
  40104. colors.push(color);
  40105. verticesLeft--;
  40106. reader.align();
  40107. }
  40108. mesh.figures.push({
  40109. type: 'triangles',
  40110. coords: new Int32Array(ps),
  40111. colors: new Int32Array(ps),
  40112. });
  40113. }
  40114. function decodeType5Shading(mesh, reader, verticesPerRow) {
  40115. var coords = mesh.coords;
  40116. var colors = mesh.colors;
  40117. var ps = []; // not maintaining cs since that will match ps
  40118. while (reader.hasData) {
  40119. var coord = reader.readCoordinate();
  40120. var color = reader.readComponents();
  40121. ps.push(coords.length);
  40122. coords.push(coord);
  40123. colors.push(color);
  40124. }
  40125. mesh.figures.push({
  40126. type: 'lattice',
  40127. coords: new Int32Array(ps),
  40128. colors: new Int32Array(ps),
  40129. verticesPerRow: verticesPerRow
  40130. });
  40131. }
  40132. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  40133. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  40134. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  40135. var getB = (function getBClosure() {
  40136. function buildB(count) {
  40137. var lut = [];
  40138. for (var i = 0; i <= count; i++) {
  40139. var t = i / count, t_ = 1 - t;
  40140. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  40141. 3 * t * t * t_, t * t * t]));
  40142. }
  40143. return lut;
  40144. }
  40145. var cache = [];
  40146. return function getB(count) {
  40147. if (!cache[count]) {
  40148. cache[count] = buildB(count);
  40149. }
  40150. return cache[count];
  40151. };
  40152. })();
  40153. function buildFigureFromPatch(mesh, index) {
  40154. var figure = mesh.figures[index];
  40155. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  40156. var coords = mesh.coords, colors = mesh.colors;
  40157. var pi = figure.coords;
  40158. var ci = figure.colors;
  40159. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  40160. coords[pi[12]][0], coords[pi[15]][0]);
  40161. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  40162. coords[pi[12]][1], coords[pi[15]][1]);
  40163. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  40164. coords[pi[12]][0], coords[pi[15]][0]);
  40165. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  40166. coords[pi[12]][1], coords[pi[15]][1]);
  40167. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  40168. (mesh.bounds[2] - mesh.bounds[0]));
  40169. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  40170. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  40171. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  40172. (mesh.bounds[3] - mesh.bounds[1]));
  40173. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  40174. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  40175. var verticesPerRow = splitXBy + 1;
  40176. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  40177. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  40178. var k = 0;
  40179. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  40180. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  40181. c2 = colors[ci[2]], c3 = colors[ci[3]];
  40182. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  40183. for (var row = 0; row <= splitYBy; row++) {
  40184. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  40185. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  40186. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  40187. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  40188. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  40189. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  40190. for (var col = 0; col <= splitXBy; col++, k++) {
  40191. if ((row === 0 || row === splitYBy) &&
  40192. (col === 0 || col === splitXBy)) {
  40193. continue;
  40194. }
  40195. var x = 0, y = 0;
  40196. var q = 0;
  40197. for (var i = 0; i <= 3; i++) {
  40198. for (var j = 0; j <= 3; j++, q++) {
  40199. var m = bRow[row][i] * bCol[col][j];
  40200. x += coords[pi[q]][0] * m;
  40201. y += coords[pi[q]][1] * m;
  40202. }
  40203. }
  40204. figureCoords[k] = coords.length;
  40205. coords.push([x, y]);
  40206. figureColors[k] = colors.length;
  40207. var newColor = new Uint8Array(3);
  40208. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  40209. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  40210. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  40211. colors.push(newColor);
  40212. }
  40213. }
  40214. figureCoords[0] = pi[0];
  40215. figureColors[0] = ci[0];
  40216. figureCoords[splitXBy] = pi[3];
  40217. figureColors[splitXBy] = ci[1];
  40218. figureCoords[verticesPerRow * splitYBy] = pi[12];
  40219. figureColors[verticesPerRow * splitYBy] = ci[2];
  40220. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  40221. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  40222. mesh.figures[index] = {
  40223. type: 'lattice',
  40224. coords: figureCoords,
  40225. colors: figureColors,
  40226. verticesPerRow: verticesPerRow
  40227. };
  40228. }
  40229. function decodeType6Shading(mesh, reader) {
  40230. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  40231. var coords = mesh.coords;
  40232. var colors = mesh.colors;
  40233. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  40234. var cs = new Int32Array(4); // c00, c30, c03, c33
  40235. while (reader.hasData) {
  40236. var f = reader.readFlag();
  40237. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  40238. var i, ii;
  40239. var pi = coords.length;
  40240. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  40241. coords.push(reader.readCoordinate());
  40242. }
  40243. var ci = colors.length;
  40244. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  40245. colors.push(reader.readComponents());
  40246. }
  40247. var tmp1, tmp2, tmp3, tmp4;
  40248. switch (f) {
  40249. case 0:
  40250. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  40251. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  40252. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  40253. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  40254. cs[2] = ci + 1; cs[3] = ci + 2;
  40255. cs[0] = ci; cs[1] = ci + 3;
  40256. break;
  40257. case 1:
  40258. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  40259. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40260. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40261. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  40262. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40263. tmp1 = cs[2]; tmp2 = cs[3];
  40264. cs[2] = tmp2; cs[3] = ci;
  40265. cs[0] = tmp1; cs[1] = ci + 1;
  40266. break;
  40267. case 2:
  40268. tmp1 = ps[15];
  40269. tmp2 = ps[11];
  40270. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40271. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40272. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  40273. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40274. tmp1 = cs[3];
  40275. cs[2] = cs[1]; cs[3] = ci;
  40276. cs[0] = tmp1; cs[1] = ci + 1;
  40277. break;
  40278. case 3:
  40279. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40280. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40281. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  40282. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40283. cs[2] = cs[0]; cs[3] = ci;
  40284. cs[0] = cs[1]; cs[1] = ci + 1;
  40285. break;
  40286. }
  40287. // set p11, p12, p21, p22
  40288. ps[5] = coords.length;
  40289. coords.push([
  40290. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  40291. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  40292. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40293. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  40294. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  40295. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  40296. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40297. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  40298. ]);
  40299. ps[6] = coords.length;
  40300. coords.push([
  40301. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  40302. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  40303. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40304. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  40305. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  40306. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  40307. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40308. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  40309. ]);
  40310. ps[9] = coords.length;
  40311. coords.push([
  40312. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  40313. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  40314. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40315. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  40316. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  40317. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  40318. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40319. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  40320. ]);
  40321. ps[10] = coords.length;
  40322. coords.push([
  40323. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  40324. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  40325. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40326. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  40327. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  40328. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  40329. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40330. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  40331. ]);
  40332. mesh.figures.push({
  40333. type: 'patch',
  40334. coords: new Int32Array(ps), // making copies of ps and cs
  40335. colors: new Int32Array(cs)
  40336. });
  40337. }
  40338. }
  40339. function decodeType7Shading(mesh, reader) {
  40340. var coords = mesh.coords;
  40341. var colors = mesh.colors;
  40342. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  40343. var cs = new Int32Array(4); // c00, c30, c03, c33
  40344. while (reader.hasData) {
  40345. var f = reader.readFlag();
  40346. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  40347. var i, ii;
  40348. var pi = coords.length;
  40349. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  40350. coords.push(reader.readCoordinate());
  40351. }
  40352. var ci = colors.length;
  40353. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  40354. colors.push(reader.readComponents());
  40355. }
  40356. var tmp1, tmp2, tmp3, tmp4;
  40357. switch (f) {
  40358. case 0:
  40359. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  40360. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  40361. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  40362. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  40363. cs[2] = ci + 1; cs[3] = ci + 2;
  40364. cs[0] = ci; cs[1] = ci + 3;
  40365. break;
  40366. case 1:
  40367. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  40368. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40369. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40370. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40371. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40372. tmp1 = cs[2]; tmp2 = cs[3];
  40373. cs[2] = tmp2; cs[3] = ci;
  40374. cs[0] = tmp1; cs[1] = ci + 1;
  40375. break;
  40376. case 2:
  40377. tmp1 = ps[15];
  40378. tmp2 = ps[11];
  40379. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40380. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40381. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40382. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40383. tmp1 = cs[3];
  40384. cs[2] = cs[1]; cs[3] = ci;
  40385. cs[0] = tmp1; cs[1] = ci + 1;
  40386. break;
  40387. case 3:
  40388. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40389. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40390. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40391. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40392. cs[2] = cs[0]; cs[3] = ci;
  40393. cs[0] = cs[1]; cs[1] = ci + 1;
  40394. break;
  40395. }
  40396. mesh.figures.push({
  40397. type: 'patch',
  40398. coords: new Int32Array(ps), // making copies of ps and cs
  40399. colors: new Int32Array(cs)
  40400. });
  40401. }
  40402. }
  40403. function updateBounds(mesh) {
  40404. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  40405. maxX = minX, maxY = minY;
  40406. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  40407. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  40408. minX = minX > x ? x : minX;
  40409. minY = minY > y ? y : minY;
  40410. maxX = maxX < x ? x : maxX;
  40411. maxY = maxY < y ? y : maxY;
  40412. }
  40413. mesh.bounds = [minX, minY, maxX, maxY];
  40414. }
  40415. function packData(mesh) {
  40416. var i, ii, j, jj;
  40417. var coords = mesh.coords;
  40418. var coordsPacked = new Float32Array(coords.length * 2);
  40419. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  40420. var xy = coords[i];
  40421. coordsPacked[j++] = xy[0];
  40422. coordsPacked[j++] = xy[1];
  40423. }
  40424. mesh.coords = coordsPacked;
  40425. var colors = mesh.colors;
  40426. var colorsPacked = new Uint8Array(colors.length * 3);
  40427. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  40428. var c = colors[i];
  40429. colorsPacked[j++] = c[0];
  40430. colorsPacked[j++] = c[1];
  40431. colorsPacked[j++] = c[2];
  40432. }
  40433. mesh.colors = colorsPacked;
  40434. var figures = mesh.figures;
  40435. for (i = 0, ii = figures.length; i < ii; i++) {
  40436. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  40437. for (j = 0, jj = ps.length; j < jj; j++) {
  40438. ps[j] *= 2;
  40439. cs[j] *= 3;
  40440. }
  40441. }
  40442. }
  40443. function Mesh(stream, matrix, xref, res) {
  40444. assert(isStream(stream), 'Mesh data is not a stream');
  40445. var dict = stream.dict;
  40446. this.matrix = matrix;
  40447. this.shadingType = dict.get('ShadingType');
  40448. this.type = 'Pattern';
  40449. this.bbox = dict.get('BBox');
  40450. var cs = dict.get('ColorSpace', 'CS');
  40451. cs = ColorSpace.parse(cs, xref, res);
  40452. this.cs = cs;
  40453. this.background = dict.has('Background') ?
  40454. cs.getRgb(dict.get('Background'), 0) : null;
  40455. var fnObj = dict.get('Function');
  40456. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  40457. this.coords = [];
  40458. this.colors = [];
  40459. this.figures = [];
  40460. var decodeContext = {
  40461. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  40462. bitsPerComponent: dict.get('BitsPerComponent'),
  40463. bitsPerFlag: dict.get('BitsPerFlag'),
  40464. decode: dict.get('Decode'),
  40465. colorFn: fn,
  40466. colorSpace: cs,
  40467. numComps: fn ? 1 : cs.numComps
  40468. };
  40469. var reader = new MeshStreamReader(stream, decodeContext);
  40470. var patchMesh = false;
  40471. switch (this.shadingType) {
  40472. case ShadingType.FREE_FORM_MESH:
  40473. decodeType4Shading(this, reader);
  40474. break;
  40475. case ShadingType.LATTICE_FORM_MESH:
  40476. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  40477. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  40478. decodeType5Shading(this, reader, verticesPerRow);
  40479. break;
  40480. case ShadingType.COONS_PATCH_MESH:
  40481. decodeType6Shading(this, reader);
  40482. patchMesh = true;
  40483. break;
  40484. case ShadingType.TENSOR_PATCH_MESH:
  40485. decodeType7Shading(this, reader);
  40486. patchMesh = true;
  40487. break;
  40488. default:
  40489. error('Unsupported mesh type.');
  40490. break;
  40491. }
  40492. if (patchMesh) {
  40493. // dirty bounds calculation for determining, how dense shall be triangles
  40494. updateBounds(this);
  40495. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  40496. buildFigureFromPatch(this, i);
  40497. }
  40498. }
  40499. // calculate bounds
  40500. updateBounds(this);
  40501. packData(this);
  40502. }
  40503. Mesh.prototype = {
  40504. getIR: function Mesh_getIR() {
  40505. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  40506. this.bounds, this.matrix, this.bbox, this.background];
  40507. }
  40508. };
  40509. return Mesh;
  40510. })();
  40511. Shadings.Dummy = (function DummyClosure() {
  40512. function Dummy() {
  40513. this.type = 'Pattern';
  40514. }
  40515. Dummy.prototype = {
  40516. getIR: function Dummy_getIR() {
  40517. return ['Dummy'];
  40518. }
  40519. };
  40520. return Dummy;
  40521. })();
  40522. function getTilingPatternIR(operatorList, dict, args) {
  40523. var matrix = dict.get('Matrix');
  40524. var bbox = dict.get('BBox');
  40525. var xstep = dict.get('XStep');
  40526. var ystep = dict.get('YStep');
  40527. var paintType = dict.get('PaintType');
  40528. var tilingType = dict.get('TilingType');
  40529. return [
  40530. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  40531. paintType, tilingType
  40532. ];
  40533. }
  40534. exports.Pattern = Pattern;
  40535. exports.getTilingPatternIR = getTilingPatternIR;
  40536. }));
  40537. (function (root, factory) {
  40538. {
  40539. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  40540. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  40541. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  40542. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  40543. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  40544. }
  40545. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  40546. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  40547. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  40548. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  40549. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  40550. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  40551. var ImageKind = sharedUtil.ImageKind;
  40552. var OPS = sharedUtil.OPS;
  40553. var TextRenderingMode = sharedUtil.TextRenderingMode;
  40554. var Util = sharedUtil.Util;
  40555. var assert = sharedUtil.assert;
  40556. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40557. var error = sharedUtil.error;
  40558. var info = sharedUtil.info;
  40559. var isArray = sharedUtil.isArray;
  40560. var isNum = sharedUtil.isNum;
  40561. var isString = sharedUtil.isString;
  40562. var warn = sharedUtil.warn;
  40563. var Dict = corePrimitives.Dict;
  40564. var Name = corePrimitives.Name;
  40565. var isCmd = corePrimitives.isCmd;
  40566. var isDict = corePrimitives.isDict;
  40567. var isName = corePrimitives.isName;
  40568. var isRef = corePrimitives.isRef;
  40569. var isStream = corePrimitives.isStream;
  40570. var DecodeStream = coreStream.DecodeStream;
  40571. var JpegStream = coreStream.JpegStream;
  40572. var Lexer = coreParser.Lexer;
  40573. var Parser = coreParser.Parser;
  40574. var isEOF = coreParser.isEOF;
  40575. var PDFImage = coreImage.PDFImage;
  40576. var ColorSpace = coreColorSpace.ColorSpace;
  40577. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  40578. var Encodings = coreFonts.Encodings;
  40579. var ErrorFont = coreFonts.ErrorFont;
  40580. var FontFlags = coreFonts.FontFlags;
  40581. var Font = coreFonts.Font;
  40582. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  40583. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  40584. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  40585. var getFontType = coreFonts.getFontType;
  40586. var reverseIfRtl = coreFonts.reverseIfRtl;
  40587. var serifFonts = coreFonts.serifFonts;
  40588. var symbolsFonts = coreFonts.symbolsFonts;
  40589. var stdFontMap = coreFonts.stdFontMap;
  40590. var isPDFFunction = coreFunction.isPDFFunction;
  40591. var PDFFunction = coreFunction.PDFFunction;
  40592. var Pattern = corePattern.Pattern;
  40593. var getTilingPatternIR = corePattern.getTilingPatternIR;
  40594. var CMapFactory = coreCMap.CMapFactory;
  40595. var IdentityCMap = coreCMap.IdentityCMap;
  40596. var Metrics = coreMetrics.Metrics;
  40597. var bidi = coreBidi.bidi;
  40598. var PartialEvaluator = (function PartialEvaluatorClosure() {
  40599. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  40600. uniquePrefix, idCounters, fontCache) {
  40601. this.pdfManager = pdfManager;
  40602. this.xref = xref;
  40603. this.handler = handler;
  40604. this.pageIndex = pageIndex;
  40605. this.uniquePrefix = uniquePrefix;
  40606. this.idCounters = idCounters;
  40607. this.fontCache = fontCache;
  40608. }
  40609. // Trying to minimize Date.now() usage and check every 100 time
  40610. var TIME_SLOT_DURATION_MS = 20;
  40611. var CHECK_TIME_EVERY = 100;
  40612. function TimeSlotManager() {
  40613. this.reset();
  40614. }
  40615. TimeSlotManager.prototype = {
  40616. check: function TimeSlotManager_check() {
  40617. if (++this.checked < CHECK_TIME_EVERY) {
  40618. return false;
  40619. }
  40620. this.checked = 0;
  40621. return this.endTime <= Date.now();
  40622. },
  40623. reset: function TimeSlotManager_reset() {
  40624. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  40625. this.checked = 0;
  40626. }
  40627. };
  40628. var deferred = Promise.resolve();
  40629. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  40630. PartialEvaluator.prototype = {
  40631. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  40632. if (!isDict(resources)) {
  40633. return false;
  40634. }
  40635. var processed = Object.create(null);
  40636. if (resources.objId) {
  40637. processed[resources.objId] = true;
  40638. }
  40639. var nodes = [resources];
  40640. while (nodes.length) {
  40641. var key;
  40642. var node = nodes.shift();
  40643. // First check the current resources for blend modes.
  40644. var graphicStates = node.get('ExtGState');
  40645. if (isDict(graphicStates)) {
  40646. graphicStates = graphicStates.getAll();
  40647. for (key in graphicStates) {
  40648. var graphicState = graphicStates[key];
  40649. var bm = graphicState['BM'];
  40650. if (isName(bm) && bm.name !== 'Normal') {
  40651. return true;
  40652. }
  40653. }
  40654. }
  40655. // Descend into the XObjects to look for more resources and blend modes.
  40656. var xObjects = node.get('XObject');
  40657. if (!isDict(xObjects)) {
  40658. continue;
  40659. }
  40660. xObjects = xObjects.getAll();
  40661. for (key in xObjects) {
  40662. var xObject = xObjects[key];
  40663. if (!isStream(xObject)) {
  40664. continue;
  40665. }
  40666. if (xObject.dict.objId) {
  40667. if (processed[xObject.dict.objId]) {
  40668. // stream has objId and is processed already
  40669. continue;
  40670. }
  40671. processed[xObject.dict.objId] = true;
  40672. }
  40673. var xResources = xObject.dict.get('Resources');
  40674. // Checking objId to detect an infinite loop.
  40675. if (isDict(xResources) &&
  40676. (!xResources.objId || !processed[xResources.objId])) {
  40677. nodes.push(xResources);
  40678. if (xResources.objId) {
  40679. processed[xResources.objId] = true;
  40680. }
  40681. }
  40682. }
  40683. }
  40684. return false;
  40685. },
  40686. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  40687. xobj, smask,
  40688. operatorList,
  40689. task,
  40690. initialState) {
  40691. var matrix = xobj.dict.getArray('Matrix');
  40692. var bbox = xobj.dict.getArray('BBox');
  40693. var group = xobj.dict.get('Group');
  40694. if (group) {
  40695. var groupOptions = {
  40696. matrix: matrix,
  40697. bbox: bbox,
  40698. smask: smask,
  40699. isolated: false,
  40700. knockout: false
  40701. };
  40702. var groupSubtype = group.get('S');
  40703. var colorSpace;
  40704. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  40705. groupOptions.isolated = (group.get('I') || false);
  40706. groupOptions.knockout = (group.get('K') || false);
  40707. colorSpace = (group.has('CS') ?
  40708. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  40709. }
  40710. if (smask && smask.backdrop) {
  40711. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  40712. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  40713. }
  40714. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  40715. }
  40716. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  40717. return this.getOperatorList(xobj, task,
  40718. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  40719. then(function () {
  40720. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  40721. if (group) {
  40722. operatorList.addOp(OPS.endGroup, [groupOptions]);
  40723. }
  40724. });
  40725. },
  40726. buildPaintImageXObject:
  40727. function PartialEvaluator_buildPaintImageXObject(resources, image,
  40728. inline, operatorList,
  40729. cacheKey, imageCache) {
  40730. var self = this;
  40731. var dict = image.dict;
  40732. var w = dict.get('Width', 'W');
  40733. var h = dict.get('Height', 'H');
  40734. if (!(w && isNum(w)) || !(h && isNum(h))) {
  40735. warn('Image dimensions are missing, or not numbers.');
  40736. return;
  40737. }
  40738. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  40739. warn('Image exceeded maximum allowed size and was removed.');
  40740. return;
  40741. }
  40742. var imageMask = (dict.get('ImageMask', 'IM') || false);
  40743. var imgData, args;
  40744. if (imageMask) {
  40745. // This depends on a tmpCanvas being filled with the
  40746. // current fillStyle, such that processing the pixel
  40747. // data can't be done here. Instead of creating a
  40748. // complete PDFImage, only read the information needed
  40749. // for later.
  40750. var width = dict.get('Width', 'W');
  40751. var height = dict.get('Height', 'H');
  40752. var bitStrideLength = (width + 7) >> 3;
  40753. var imgArray = image.getBytes(bitStrideLength * height);
  40754. var decode = dict.get('Decode', 'D');
  40755. var inverseDecode = (!!decode && decode[0] > 0);
  40756. imgData = PDFImage.createMask(imgArray, width, height,
  40757. image instanceof DecodeStream,
  40758. inverseDecode);
  40759. imgData.cached = true;
  40760. args = [imgData];
  40761. operatorList.addOp(OPS.paintImageMaskXObject, args);
  40762. if (cacheKey) {
  40763. imageCache[cacheKey] = {
  40764. fn: OPS.paintImageMaskXObject,
  40765. args: args
  40766. };
  40767. }
  40768. return;
  40769. }
  40770. var softMask = (dict.get('SMask', 'SM') || false);
  40771. var mask = (dict.get('Mask') || false);
  40772. var SMALL_IMAGE_DIMENSIONS = 200;
  40773. // Inlining small images into the queue as RGB data
  40774. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  40775. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  40776. var imageObj = new PDFImage(this.xref, resources, image,
  40777. inline, null, null);
  40778. // We force the use of RGBA_32BPP images here, because we can't handle
  40779. // any other kind.
  40780. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  40781. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  40782. return;
  40783. }
  40784. // If there is no imageMask, create the PDFImage and a lot
  40785. // of image processing can be done here.
  40786. var uniquePrefix = (this.uniquePrefix || '');
  40787. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  40788. operatorList.addDependency(objId);
  40789. args = [objId, w, h];
  40790. if (!softMask && !mask && image instanceof JpegStream &&
  40791. image.isNativelySupported(this.xref, resources)) {
  40792. // These JPEGs don't need any more processing so we can just send it.
  40793. operatorList.addOp(OPS.paintJpegXObject, args);
  40794. this.handler.send('obj',
  40795. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  40796. return;
  40797. }
  40798. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  40799. then(function(imageObj) {
  40800. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  40801. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  40802. [imgData.data.buffer]);
  40803. }).then(undefined, function (reason) {
  40804. warn('Unable to decode image: ' + reason);
  40805. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  40806. });
  40807. operatorList.addOp(OPS.paintImageXObject, args);
  40808. if (cacheKey) {
  40809. imageCache[cacheKey] = {
  40810. fn: OPS.paintImageXObject,
  40811. args: args
  40812. };
  40813. }
  40814. },
  40815. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  40816. operatorList, task,
  40817. stateManager) {
  40818. var smaskContent = smask.get('G');
  40819. var smaskOptions = {
  40820. subtype: smask.get('S').name,
  40821. backdrop: smask.get('BC')
  40822. };
  40823. // The SMask might have a alpha/luminosity value transfer function --
  40824. // we will build a map of integer values in range 0..255 to be fast.
  40825. var transferObj = smask.get('TR');
  40826. if (isPDFFunction(transferObj)) {
  40827. var transferFn = PDFFunction.parse(this.xref, transferObj);
  40828. var transferMap = new Uint8Array(256);
  40829. var tmp = new Float32Array(1);
  40830. for (var i = 0; i < 255; i++) {
  40831. tmp[0] = i / 255;
  40832. transferFn(tmp, 0, tmp, 0);
  40833. transferMap[i] = (tmp[0] * 255) | 0;
  40834. }
  40835. smaskOptions.transferMap = transferMap;
  40836. }
  40837. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  40838. operatorList, task, stateManager.state.clone());
  40839. },
  40840. handleTilingType:
  40841. function PartialEvaluator_handleTilingType(fn, args, resources,
  40842. pattern, patternDict,
  40843. operatorList, task) {
  40844. // Create an IR of the pattern code.
  40845. var tilingOpList = new OperatorList();
  40846. // Merge the available resources, to prevent issues when the patternDict
  40847. // is missing some /Resources entries (fixes issue6541.pdf).
  40848. var resourcesArray = [patternDict.get('Resources'), resources];
  40849. var patternResources = Dict.merge(this.xref, resourcesArray);
  40850. return this.getOperatorList(pattern, task, patternResources,
  40851. tilingOpList).then(function () {
  40852. // Add the dependencies to the parent operator list so they are
  40853. // resolved before sub operator list is executed synchronously.
  40854. operatorList.addDependencies(tilingOpList.dependencies);
  40855. operatorList.addOp(fn, getTilingPatternIR({
  40856. fnArray: tilingOpList.fnArray,
  40857. argsArray: tilingOpList.argsArray
  40858. }, patternDict, args));
  40859. });
  40860. },
  40861. handleSetFont:
  40862. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  40863. operatorList, task, state) {
  40864. // TODO(mack): Not needed?
  40865. var fontName;
  40866. if (fontArgs) {
  40867. fontArgs = fontArgs.slice();
  40868. fontName = fontArgs[0].name;
  40869. }
  40870. var self = this;
  40871. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  40872. function (translated) {
  40873. if (!translated.font.isType3Font) {
  40874. return translated;
  40875. }
  40876. return translated.loadType3Data(self, resources, operatorList, task).
  40877. then(function () {
  40878. return translated;
  40879. }, function (reason) {
  40880. // Error in the font data -- sending unsupported feature notification.
  40881. self.handler.send('UnsupportedFeature',
  40882. {featureId: UNSUPPORTED_FEATURES.font});
  40883. return new TranslatedFont('g_font_error',
  40884. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  40885. });
  40886. }).then(function (translated) {
  40887. state.font = translated.font;
  40888. translated.send(self.handler);
  40889. return translated.loadedName;
  40890. });
  40891. },
  40892. handleText: function PartialEvaluator_handleText(chars, state) {
  40893. var font = state.font;
  40894. var glyphs = font.charsToGlyphs(chars);
  40895. var isAddToPathSet = !!(state.textRenderingMode &
  40896. TextRenderingMode.ADD_TO_PATH_FLAG);
  40897. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  40898. var buildPath = function (fontChar) {
  40899. if (!font.renderer.hasBuiltPath(fontChar)) {
  40900. var path = font.renderer.getPathJs(fontChar);
  40901. this.handler.send('commonobj', [
  40902. font.loadedName + '_path_' + fontChar,
  40903. 'FontPath',
  40904. path
  40905. ]);
  40906. }
  40907. }.bind(this);
  40908. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  40909. var glyph = glyphs[i];
  40910. buildPath(glyph.fontChar);
  40911. // If the glyph has an accent we need to build a path for its
  40912. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  40913. var accent = glyph.accent;
  40914. if (accent && accent.fontChar) {
  40915. buildPath(accent.fontChar);
  40916. }
  40917. }
  40918. }
  40919. return glyphs;
  40920. },
  40921. setGState: function PartialEvaluator_setGState(resources, gState,
  40922. operatorList, task,
  40923. xref, stateManager) {
  40924. // This array holds the converted/processed state data.
  40925. var gStateObj = [];
  40926. var gStateMap = gState.map;
  40927. var self = this;
  40928. var promise = Promise.resolve();
  40929. for (var key in gStateMap) {
  40930. var value = gStateMap[key];
  40931. switch (key) {
  40932. case 'Type':
  40933. break;
  40934. case 'LW':
  40935. case 'LC':
  40936. case 'LJ':
  40937. case 'ML':
  40938. case 'D':
  40939. case 'RI':
  40940. case 'FL':
  40941. case 'CA':
  40942. case 'ca':
  40943. gStateObj.push([key, value]);
  40944. break;
  40945. case 'Font':
  40946. promise = promise.then(function () {
  40947. return self.handleSetFont(resources, null, value[0], operatorList,
  40948. task, stateManager.state).
  40949. then(function (loadedName) {
  40950. operatorList.addDependency(loadedName);
  40951. gStateObj.push([key, [loadedName, value[1]]]);
  40952. });
  40953. });
  40954. break;
  40955. case 'BM':
  40956. gStateObj.push([key, value]);
  40957. break;
  40958. case 'SMask':
  40959. if (isName(value) && value.name === 'None') {
  40960. gStateObj.push([key, false]);
  40961. break;
  40962. }
  40963. var dict = xref.fetchIfRef(value);
  40964. if (isDict(dict)) {
  40965. promise = promise.then(function () {
  40966. return self.handleSMask(dict, resources, operatorList,
  40967. task, stateManager);
  40968. });
  40969. gStateObj.push([key, true]);
  40970. } else {
  40971. warn('Unsupported SMask type');
  40972. }
  40973. break;
  40974. // Only generate info log messages for the following since
  40975. // they are unlikely to have a big impact on the rendering.
  40976. case 'OP':
  40977. case 'op':
  40978. case 'OPM':
  40979. case 'BG':
  40980. case 'BG2':
  40981. case 'UCR':
  40982. case 'UCR2':
  40983. case 'TR':
  40984. case 'TR2':
  40985. case 'HT':
  40986. case 'SM':
  40987. case 'SA':
  40988. case 'AIS':
  40989. case 'TK':
  40990. // TODO implement these operators.
  40991. info('graphic state operator ' + key);
  40992. break;
  40993. default:
  40994. info('Unknown graphic state operator ' + key);
  40995. break;
  40996. }
  40997. }
  40998. return promise.then(function () {
  40999. if (gStateObj.length >= 0) {
  41000. operatorList.addOp(OPS.setGState, [gStateObj]);
  41001. }
  41002. });
  41003. },
  41004. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  41005. resources) {
  41006. function errorFont() {
  41007. return Promise.resolve(new TranslatedFont('g_font_error',
  41008. new ErrorFont('Font ' + fontName + ' is not available'), font));
  41009. }
  41010. var fontRef;
  41011. if (font) { // Loading by ref.
  41012. assert(isRef(font));
  41013. fontRef = font;
  41014. } else { // Loading by name.
  41015. var fontRes = resources.get('Font');
  41016. if (fontRes) {
  41017. fontRef = fontRes.getRaw(fontName);
  41018. } else {
  41019. warn('fontRes not available');
  41020. return errorFont();
  41021. }
  41022. }
  41023. if (!fontRef) {
  41024. warn('fontRef not available');
  41025. return errorFont();
  41026. }
  41027. if (this.fontCache.has(fontRef)) {
  41028. return this.fontCache.get(fontRef);
  41029. }
  41030. font = xref.fetchIfRef(fontRef);
  41031. if (!isDict(font)) {
  41032. return errorFont();
  41033. }
  41034. // We are holding font.translated references just for fontRef that are not
  41035. // dictionaries (Dict). See explanation below.
  41036. if (font.translated) {
  41037. return font.translated;
  41038. }
  41039. var fontCapability = createPromiseCapability();
  41040. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  41041. var descriptor = preEvaluatedFont.descriptor;
  41042. var fontID = fontRef.num + '_' + fontRef.gen;
  41043. if (isDict(descriptor)) {
  41044. if (!descriptor.fontAliases) {
  41045. descriptor.fontAliases = Object.create(null);
  41046. }
  41047. var fontAliases = descriptor.fontAliases;
  41048. var hash = preEvaluatedFont.hash;
  41049. if (fontAliases[hash]) {
  41050. var aliasFontRef = fontAliases[hash].aliasRef;
  41051. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  41052. this.fontCache.putAlias(fontRef, aliasFontRef);
  41053. return this.fontCache.get(fontRef);
  41054. }
  41055. }
  41056. if (!fontAliases[hash]) {
  41057. fontAliases[hash] = {
  41058. fontID: Font.getFontID()
  41059. };
  41060. }
  41061. fontAliases[hash].aliasRef = fontRef;
  41062. fontID = fontAliases[hash].fontID;
  41063. }
  41064. // Workaround for bad PDF generators that don't reference fonts
  41065. // properly, i.e. by not using an object identifier.
  41066. // Check if the fontRef is a Dict (as opposed to a standard object),
  41067. // in which case we don't cache the font and instead reference it by
  41068. // fontName in font.loadedName below.
  41069. var fontRefIsDict = isDict(fontRef);
  41070. if (!fontRefIsDict) {
  41071. this.fontCache.put(fontRef, fontCapability.promise);
  41072. }
  41073. // Keep track of each font we translated so the caller can
  41074. // load them asynchronously before calling display on a page.
  41075. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  41076. fontName.replace(/\W/g, '') : fontID);
  41077. font.translated = fontCapability.promise;
  41078. // TODO move promises into translate font
  41079. var translatedPromise;
  41080. try {
  41081. translatedPromise = Promise.resolve(
  41082. this.translateFont(preEvaluatedFont, xref));
  41083. } catch (e) {
  41084. translatedPromise = Promise.reject(e);
  41085. }
  41086. var self = this;
  41087. translatedPromise.then(function (translatedFont) {
  41088. if (translatedFont.fontType !== undefined) {
  41089. var xrefFontStats = xref.stats.fontTypes;
  41090. xrefFontStats[translatedFont.fontType] = true;
  41091. }
  41092. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41093. translatedFont, font));
  41094. }, function (reason) {
  41095. // TODO fontCapability.reject?
  41096. // Error in the font data -- sending unsupported feature notification.
  41097. self.handler.send('UnsupportedFeature',
  41098. {featureId: UNSUPPORTED_FEATURES.font});
  41099. try {
  41100. // error, but it's still nice to have font type reported
  41101. var descriptor = preEvaluatedFont.descriptor;
  41102. var fontFile3 = descriptor && descriptor.get('FontFile3');
  41103. var subtype = fontFile3 && fontFile3.get('Subtype');
  41104. var fontType = getFontType(preEvaluatedFont.type,
  41105. subtype && subtype.name);
  41106. var xrefFontStats = xref.stats.fontTypes;
  41107. xrefFontStats[fontType] = true;
  41108. } catch (ex) { }
  41109. fontCapability.resolve(new TranslatedFont(font.loadedName,
  41110. new ErrorFont(reason instanceof Error ? reason.message : reason),
  41111. font));
  41112. });
  41113. return fontCapability.promise;
  41114. },
  41115. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  41116. var lastIndex = operatorList.length - 1;
  41117. if (!args) {
  41118. args = [];
  41119. }
  41120. if (lastIndex < 0 ||
  41121. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  41122. operatorList.addOp(OPS.constructPath, [[fn], args]);
  41123. } else {
  41124. var opArgs = operatorList.argsArray[lastIndex];
  41125. opArgs[0].push(fn);
  41126. Array.prototype.push.apply(opArgs[1], args);
  41127. }
  41128. },
  41129. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  41130. cs, patterns, resources, task, xref) {
  41131. // compile tiling patterns
  41132. var patternName = args[args.length - 1];
  41133. // SCN/scn applies patterns along with normal colors
  41134. var pattern;
  41135. if (isName(patternName) &&
  41136. (pattern = patterns.get(patternName.name))) {
  41137. var dict = (isStream(pattern) ? pattern.dict : pattern);
  41138. var typeNum = dict.get('PatternType');
  41139. if (typeNum === TILING_PATTERN) {
  41140. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  41141. return this.handleTilingType(fn, color, resources, pattern,
  41142. dict, operatorList, task);
  41143. } else if (typeNum === SHADING_PATTERN) {
  41144. var shading = dict.get('Shading');
  41145. var matrix = dict.get('Matrix');
  41146. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  41147. this.handler);
  41148. operatorList.addOp(fn, pattern.getIR());
  41149. return Promise.resolve();
  41150. } else {
  41151. return Promise.reject('Unknown PatternType: ' + typeNum);
  41152. }
  41153. }
  41154. // TODO shall we fail here?
  41155. operatorList.addOp(fn, args);
  41156. return Promise.resolve();
  41157. },
  41158. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  41159. task,
  41160. resources,
  41161. operatorList,
  41162. initialState) {
  41163. var self = this;
  41164. var xref = this.xref;
  41165. var imageCache = {};
  41166. assert(operatorList);
  41167. resources = (resources || Dict.empty);
  41168. var xobjs = (resources.get('XObject') || Dict.empty);
  41169. var patterns = (resources.get('Pattern') || Dict.empty);
  41170. var stateManager = new StateManager(initialState || new EvalState());
  41171. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  41172. var timeSlotManager = new TimeSlotManager();
  41173. return new Promise(function next(resolve, reject) {
  41174. task.ensureNotTerminated();
  41175. timeSlotManager.reset();
  41176. var stop, operation = {}, i, ii, cs;
  41177. while (!(stop = timeSlotManager.check())) {
  41178. // The arguments parsed by read() are used beyond this loop, so we
  41179. // cannot reuse the same array on each iteration. Therefore we pass
  41180. // in |null| as the initial value (see the comment on
  41181. // EvaluatorPreprocessor_read() for why).
  41182. operation.args = null;
  41183. if (!(preprocessor.read(operation))) {
  41184. break;
  41185. }
  41186. var args = operation.args;
  41187. var fn = operation.fn;
  41188. switch (fn | 0) {
  41189. case OPS.paintXObject:
  41190. if (args[0].code) {
  41191. break;
  41192. }
  41193. // eagerly compile XForm objects
  41194. var name = args[0].name;
  41195. if (!name) {
  41196. warn('XObject must be referred to by name.');
  41197. continue;
  41198. }
  41199. if (imageCache[name] !== undefined) {
  41200. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  41201. args = null;
  41202. continue;
  41203. }
  41204. var xobj = xobjs.get(name);
  41205. if (xobj) {
  41206. assert(isStream(xobj), 'XObject should be a stream');
  41207. var type = xobj.dict.get('Subtype');
  41208. assert(isName(type),
  41209. 'XObject should have a Name subtype');
  41210. if (type.name === 'Form') {
  41211. stateManager.save();
  41212. return self.buildFormXObject(resources, xobj, null,
  41213. operatorList, task,
  41214. stateManager.state.clone()).
  41215. then(function () {
  41216. stateManager.restore();
  41217. next(resolve, reject);
  41218. }, reject);
  41219. } else if (type.name === 'Image') {
  41220. self.buildPaintImageXObject(resources, xobj, false,
  41221. operatorList, name, imageCache);
  41222. args = null;
  41223. continue;
  41224. } else if (type.name === 'PS') {
  41225. // PostScript XObjects are unused when viewing documents.
  41226. // See section 4.7.1 of Adobe's PDF reference.
  41227. info('Ignored XObject subtype PS');
  41228. continue;
  41229. } else {
  41230. error('Unhandled XObject subtype ' + type.name);
  41231. }
  41232. }
  41233. break;
  41234. case OPS.setFont:
  41235. var fontSize = args[1];
  41236. // eagerly collect all fonts
  41237. return self.handleSetFont(resources, args, null, operatorList,
  41238. task, stateManager.state).
  41239. then(function (loadedName) {
  41240. operatorList.addDependency(loadedName);
  41241. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  41242. next(resolve, reject);
  41243. }, reject);
  41244. case OPS.endInlineImage:
  41245. var cacheKey = args[0].cacheKey;
  41246. if (cacheKey) {
  41247. var cacheEntry = imageCache[cacheKey];
  41248. if (cacheEntry !== undefined) {
  41249. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  41250. args = null;
  41251. continue;
  41252. }
  41253. }
  41254. self.buildPaintImageXObject(resources, args[0], true,
  41255. operatorList, cacheKey, imageCache);
  41256. args = null;
  41257. continue;
  41258. case OPS.showText:
  41259. args[0] = self.handleText(args[0], stateManager.state);
  41260. break;
  41261. case OPS.showSpacedText:
  41262. var arr = args[0];
  41263. var combinedGlyphs = [];
  41264. var arrLength = arr.length;
  41265. var state = stateManager.state;
  41266. for (i = 0; i < arrLength; ++i) {
  41267. var arrItem = arr[i];
  41268. if (isString(arrItem)) {
  41269. Array.prototype.push.apply(combinedGlyphs,
  41270. self.handleText(arrItem, state));
  41271. } else if (isNum(arrItem)) {
  41272. combinedGlyphs.push(arrItem);
  41273. }
  41274. }
  41275. args[0] = combinedGlyphs;
  41276. fn = OPS.showText;
  41277. break;
  41278. case OPS.nextLineShowText:
  41279. operatorList.addOp(OPS.nextLine);
  41280. args[0] = self.handleText(args[0], stateManager.state);
  41281. fn = OPS.showText;
  41282. break;
  41283. case OPS.nextLineSetSpacingShowText:
  41284. operatorList.addOp(OPS.nextLine);
  41285. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  41286. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  41287. args[0] = self.handleText(args[0], stateManager.state);
  41288. fn = OPS.showText;
  41289. break;
  41290. case OPS.setTextRenderingMode:
  41291. stateManager.state.textRenderingMode = args[0];
  41292. break;
  41293. case OPS.setFillColorSpace:
  41294. stateManager.state.fillColorSpace =
  41295. ColorSpace.parse(args[0], xref, resources);
  41296. continue;
  41297. case OPS.setStrokeColorSpace:
  41298. stateManager.state.strokeColorSpace =
  41299. ColorSpace.parse(args[0], xref, resources);
  41300. continue;
  41301. case OPS.setFillColor:
  41302. cs = stateManager.state.fillColorSpace;
  41303. args = cs.getRgb(args, 0);
  41304. fn = OPS.setFillRGBColor;
  41305. break;
  41306. case OPS.setStrokeColor:
  41307. cs = stateManager.state.strokeColorSpace;
  41308. args = cs.getRgb(args, 0);
  41309. fn = OPS.setStrokeRGBColor;
  41310. break;
  41311. case OPS.setFillGray:
  41312. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  41313. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41314. fn = OPS.setFillRGBColor;
  41315. break;
  41316. case OPS.setStrokeGray:
  41317. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  41318. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41319. fn = OPS.setStrokeRGBColor;
  41320. break;
  41321. case OPS.setFillCMYKColor:
  41322. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  41323. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41324. fn = OPS.setFillRGBColor;
  41325. break;
  41326. case OPS.setStrokeCMYKColor:
  41327. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  41328. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41329. fn = OPS.setStrokeRGBColor;
  41330. break;
  41331. case OPS.setFillRGBColor:
  41332. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  41333. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41334. break;
  41335. case OPS.setStrokeRGBColor:
  41336. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  41337. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41338. break;
  41339. case OPS.setFillColorN:
  41340. cs = stateManager.state.fillColorSpace;
  41341. if (cs.name === 'Pattern') {
  41342. return self.handleColorN(operatorList, OPS.setFillColorN,
  41343. args, cs, patterns, resources, task, xref).then(function() {
  41344. next(resolve, reject);
  41345. }, reject);
  41346. }
  41347. args = cs.getRgb(args, 0);
  41348. fn = OPS.setFillRGBColor;
  41349. break;
  41350. case OPS.setStrokeColorN:
  41351. cs = stateManager.state.strokeColorSpace;
  41352. if (cs.name === 'Pattern') {
  41353. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  41354. args, cs, patterns, resources, task, xref).then(function() {
  41355. next(resolve, reject);
  41356. }, reject);
  41357. }
  41358. args = cs.getRgb(args, 0);
  41359. fn = OPS.setStrokeRGBColor;
  41360. break;
  41361. case OPS.shadingFill:
  41362. var shadingRes = resources.get('Shading');
  41363. if (!shadingRes) {
  41364. error('No shading resource found');
  41365. }
  41366. var shading = shadingRes.get(args[0].name);
  41367. if (!shading) {
  41368. error('No shading object found');
  41369. }
  41370. var shadingFill = Pattern.parseShading(shading, null, xref,
  41371. resources, self.handler);
  41372. var patternIR = shadingFill.getIR();
  41373. args = [patternIR];
  41374. fn = OPS.shadingFill;
  41375. break;
  41376. case OPS.setGState:
  41377. var dictName = args[0];
  41378. var extGState = resources.get('ExtGState');
  41379. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  41380. break;
  41381. }
  41382. var gState = extGState.get(dictName.name);
  41383. return self.setGState(resources, gState, operatorList, task,
  41384. xref, stateManager).then(function() {
  41385. next(resolve, reject);
  41386. }, reject);
  41387. case OPS.moveTo:
  41388. case OPS.lineTo:
  41389. case OPS.curveTo:
  41390. case OPS.curveTo2:
  41391. case OPS.curveTo3:
  41392. case OPS.closePath:
  41393. self.buildPath(operatorList, fn, args);
  41394. continue;
  41395. case OPS.rectangle:
  41396. self.buildPath(operatorList, fn, args);
  41397. continue;
  41398. case OPS.markPoint:
  41399. case OPS.markPointProps:
  41400. case OPS.beginMarkedContent:
  41401. case OPS.beginMarkedContentProps:
  41402. case OPS.endMarkedContent:
  41403. case OPS.beginCompat:
  41404. case OPS.endCompat:
  41405. // Ignore operators where the corresponding handlers are known to
  41406. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  41407. // serialization errors and is also a bit more efficient.
  41408. // We could also try to serialize all objects in a general way,
  41409. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  41410. // but doing so is meaningless without knowing the semantics.
  41411. continue;
  41412. default:
  41413. // Note: Let's hope that the ignored operator does not have any
  41414. // non-serializable arguments, otherwise postMessage will throw
  41415. // "An object could not be cloned.".
  41416. }
  41417. operatorList.addOp(fn, args);
  41418. }
  41419. if (stop) {
  41420. deferred.then(function () {
  41421. next(resolve, reject);
  41422. }, reject);
  41423. return;
  41424. }
  41425. // Some PDFs don't close all restores inside object/form.
  41426. // Closing those for them.
  41427. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  41428. operatorList.addOp(OPS.restore, []);
  41429. }
  41430. resolve();
  41431. });
  41432. },
  41433. getTextContent:
  41434. function PartialEvaluator_getTextContent(stream, task, resources,
  41435. stateManager,
  41436. normalizeWhitespace) {
  41437. stateManager = (stateManager || new StateManager(new TextState()));
  41438. var WhitespaceRegexp = /\s/g;
  41439. var textContent = {
  41440. items: [],
  41441. styles: Object.create(null)
  41442. };
  41443. var textContentItem = {
  41444. initialized: false,
  41445. str: [],
  41446. width: 0,
  41447. height: 0,
  41448. vertical: false,
  41449. lastAdvanceWidth: 0,
  41450. lastAdvanceHeight: 0,
  41451. textAdvanceScale: 0,
  41452. spaceWidth: 0,
  41453. fakeSpaceMin: Infinity,
  41454. fakeMultiSpaceMin: Infinity,
  41455. fakeMultiSpaceMax: -0,
  41456. textRunBreakAllowed: false,
  41457. transform: null,
  41458. fontName: null
  41459. };
  41460. var SPACE_FACTOR = 0.3;
  41461. var MULTI_SPACE_FACTOR = 1.5;
  41462. var MULTI_SPACE_FACTOR_MAX = 4;
  41463. var self = this;
  41464. var xref = this.xref;
  41465. resources = (xref.fetchIfRef(resources) || Dict.empty);
  41466. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  41467. var xobjs = null;
  41468. var xobjsCache = {};
  41469. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  41470. var textState;
  41471. function ensureTextContentItem() {
  41472. if (textContentItem.initialized) {
  41473. return textContentItem;
  41474. }
  41475. var font = textState.font;
  41476. if (!(font.loadedName in textContent.styles)) {
  41477. textContent.styles[font.loadedName] = {
  41478. fontFamily: font.fallbackName,
  41479. ascent: font.ascent,
  41480. descent: font.descent,
  41481. vertical: font.vertical
  41482. };
  41483. }
  41484. textContentItem.fontName = font.loadedName;
  41485. // 9.4.4 Text Space Details
  41486. var tsm = [textState.fontSize * textState.textHScale, 0,
  41487. 0, textState.fontSize,
  41488. 0, textState.textRise];
  41489. if (font.isType3Font &&
  41490. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  41491. textState.fontSize === 1) {
  41492. var glyphHeight = font.bbox[3] - font.bbox[1];
  41493. if (glyphHeight > 0) {
  41494. glyphHeight = glyphHeight * textState.fontMatrix[3];
  41495. tsm[3] *= glyphHeight;
  41496. }
  41497. }
  41498. var trm = Util.transform(textState.ctm,
  41499. Util.transform(textState.textMatrix, tsm));
  41500. textContentItem.transform = trm;
  41501. if (!font.vertical) {
  41502. textContentItem.width = 0;
  41503. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  41504. textContentItem.vertical = false;
  41505. } else {
  41506. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  41507. textContentItem.height = 0;
  41508. textContentItem.vertical = true;
  41509. }
  41510. var a = textState.textLineMatrix[0];
  41511. var b = textState.textLineMatrix[1];
  41512. var scaleLineX = Math.sqrt(a * a + b * b);
  41513. a = textState.ctm[0];
  41514. b = textState.ctm[1];
  41515. var scaleCtmX = Math.sqrt(a * a + b * b);
  41516. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  41517. textContentItem.lastAdvanceWidth = 0;
  41518. textContentItem.lastAdvanceHeight = 0;
  41519. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  41520. if (spaceWidth) {
  41521. textContentItem.spaceWidth = spaceWidth;
  41522. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  41523. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  41524. textContentItem.fakeMultiSpaceMax =
  41525. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  41526. // It's okay for monospace fonts to fake as much space as needed.
  41527. textContentItem.textRunBreakAllowed = !font.isMonospace;
  41528. } else {
  41529. textContentItem.spaceWidth = 0;
  41530. textContentItem.fakeSpaceMin = Infinity;
  41531. textContentItem.fakeMultiSpaceMin = Infinity;
  41532. textContentItem.fakeMultiSpaceMax = 0;
  41533. textContentItem.textRunBreakAllowed = false;
  41534. }
  41535. textContentItem.initialized = true;
  41536. return textContentItem;
  41537. }
  41538. function replaceWhitespace(str) {
  41539. // Replaces all whitespaces with standard spaces (0x20), to avoid
  41540. // alignment issues between the textLayer and the canvas if the text
  41541. // contains e.g. tabs (fixes issue6612.pdf).
  41542. var i = 0, ii = str.length, code;
  41543. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  41544. i++;
  41545. }
  41546. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  41547. }
  41548. function runBidiTransform(textChunk) {
  41549. var str = textChunk.str.join('');
  41550. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  41551. return {
  41552. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  41553. bidiResult.str),
  41554. dir: bidiResult.dir,
  41555. width: textChunk.width,
  41556. height: textChunk.height,
  41557. transform: textChunk.transform,
  41558. fontName: textChunk.fontName
  41559. };
  41560. }
  41561. function handleSetFont(fontName, fontRef) {
  41562. return self.loadFont(fontName, fontRef, xref, resources).
  41563. then(function (translated) {
  41564. textState.font = translated.font;
  41565. textState.fontMatrix = translated.font.fontMatrix ||
  41566. FONT_IDENTITY_MATRIX;
  41567. });
  41568. }
  41569. function buildTextContentItem(chars) {
  41570. var font = textState.font;
  41571. var textChunk = ensureTextContentItem();
  41572. var width = 0;
  41573. var height = 0;
  41574. var glyphs = font.charsToGlyphs(chars);
  41575. var defaultVMetrics = font.defaultVMetrics;
  41576. for (var i = 0; i < glyphs.length; i++) {
  41577. var glyph = glyphs[i];
  41578. var vMetricX = null;
  41579. var vMetricY = null;
  41580. var glyphWidth = null;
  41581. if (font.vertical) {
  41582. if (glyph.vmetric) {
  41583. glyphWidth = glyph.vmetric[0];
  41584. vMetricX = glyph.vmetric[1];
  41585. vMetricY = glyph.vmetric[2];
  41586. } else {
  41587. glyphWidth = glyph.width;
  41588. vMetricX = glyph.width * 0.5;
  41589. vMetricY = defaultVMetrics[2];
  41590. }
  41591. } else {
  41592. glyphWidth = glyph.width;
  41593. }
  41594. var glyphUnicode = glyph.unicode;
  41595. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  41596. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  41597. }
  41598. glyphUnicode = reverseIfRtl(glyphUnicode);
  41599. // The following will calculate the x and y of the individual glyphs.
  41600. // if (font.vertical) {
  41601. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  41602. // textState.fontMatrix[0];
  41603. // tsm[5] -= vMetricY * textState.fontSize *
  41604. // textState.fontMatrix[0];
  41605. // }
  41606. // var trm = Util.transform(textState.textMatrix, tsm);
  41607. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  41608. // var x = pt[0];
  41609. // var y = pt[1];
  41610. var charSpacing = textState.charSpacing;
  41611. if (glyph.isSpace) {
  41612. var wordSpacing = textState.wordSpacing;
  41613. charSpacing += wordSpacing;
  41614. if (wordSpacing > 0) {
  41615. addFakeSpaces(wordSpacing, textChunk.str);
  41616. }
  41617. }
  41618. var tx = 0;
  41619. var ty = 0;
  41620. if (!font.vertical) {
  41621. var w0 = glyphWidth * textState.fontMatrix[0];
  41622. tx = (w0 * textState.fontSize + charSpacing) *
  41623. textState.textHScale;
  41624. width += tx;
  41625. } else {
  41626. var w1 = glyphWidth * textState.fontMatrix[0];
  41627. ty = w1 * textState.fontSize + charSpacing;
  41628. height += ty;
  41629. }
  41630. textState.translateTextMatrix(tx, ty);
  41631. textChunk.str.push(glyphUnicode);
  41632. }
  41633. if (!font.vertical) {
  41634. textChunk.lastAdvanceWidth = width;
  41635. textChunk.width += width * textChunk.textAdvanceScale;
  41636. } else {
  41637. textChunk.lastAdvanceHeight = height;
  41638. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  41639. }
  41640. return textChunk;
  41641. }
  41642. function addFakeSpaces(width, strBuf) {
  41643. if (width < textContentItem.fakeSpaceMin) {
  41644. return;
  41645. }
  41646. if (width < textContentItem.fakeMultiSpaceMin) {
  41647. strBuf.push(' ');
  41648. return;
  41649. }
  41650. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  41651. while (fakeSpaces-- > 0) {
  41652. strBuf.push(' ');
  41653. }
  41654. }
  41655. function flushTextContentItem() {
  41656. if (!textContentItem.initialized) {
  41657. return;
  41658. }
  41659. textContent.items.push(runBidiTransform(textContentItem));
  41660. textContentItem.initialized = false;
  41661. textContentItem.str.length = 0;
  41662. }
  41663. var timeSlotManager = new TimeSlotManager();
  41664. return new Promise(function next(resolve, reject) {
  41665. task.ensureNotTerminated();
  41666. timeSlotManager.reset();
  41667. var stop, operation = {}, args = [];
  41668. while (!(stop = timeSlotManager.check())) {
  41669. // The arguments parsed by read() are not used beyond this loop, so
  41670. // we can reuse the same array on every iteration, thus avoiding
  41671. // unnecessary allocations.
  41672. args.length = 0;
  41673. operation.args = args;
  41674. if (!(preprocessor.read(operation))) {
  41675. break;
  41676. }
  41677. textState = stateManager.state;
  41678. var fn = operation.fn;
  41679. args = operation.args;
  41680. var advance;
  41681. switch (fn | 0) {
  41682. case OPS.setFont:
  41683. flushTextContentItem();
  41684. textState.fontSize = args[1];
  41685. return handleSetFont(args[0].name).then(function() {
  41686. next(resolve, reject);
  41687. }, reject);
  41688. case OPS.setTextRise:
  41689. flushTextContentItem();
  41690. textState.textRise = args[0];
  41691. break;
  41692. case OPS.setHScale:
  41693. flushTextContentItem();
  41694. textState.textHScale = args[0] / 100;
  41695. break;
  41696. case OPS.setLeading:
  41697. flushTextContentItem();
  41698. textState.leading = args[0];
  41699. break;
  41700. case OPS.moveText:
  41701. // Optimization to treat same line movement as advance
  41702. var isSameTextLine = !textState.font ? false :
  41703. ((textState.font.vertical ? args[0] : args[1]) === 0);
  41704. advance = args[0] - args[1];
  41705. if (isSameTextLine && textContentItem.initialized &&
  41706. advance > 0 &&
  41707. advance <= textContentItem.fakeMultiSpaceMax) {
  41708. textState.translateTextLineMatrix(args[0], args[1]);
  41709. textContentItem.width +=
  41710. (args[0] - textContentItem.lastAdvanceWidth);
  41711. textContentItem.height +=
  41712. (args[1] - textContentItem.lastAdvanceHeight);
  41713. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  41714. (args[1] - textContentItem.lastAdvanceHeight);
  41715. addFakeSpaces(diff, textContentItem.str);
  41716. break;
  41717. }
  41718. flushTextContentItem();
  41719. textState.translateTextLineMatrix(args[0], args[1]);
  41720. textState.textMatrix = textState.textLineMatrix.slice();
  41721. break;
  41722. case OPS.setLeadingMoveText:
  41723. flushTextContentItem();
  41724. textState.leading = -args[1];
  41725. textState.translateTextLineMatrix(args[0], args[1]);
  41726. textState.textMatrix = textState.textLineMatrix.slice();
  41727. break;
  41728. case OPS.nextLine:
  41729. flushTextContentItem();
  41730. textState.carriageReturn();
  41731. break;
  41732. case OPS.setTextMatrix:
  41733. flushTextContentItem();
  41734. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  41735. args[4], args[5]);
  41736. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  41737. args[4], args[5]);
  41738. break;
  41739. case OPS.setCharSpacing:
  41740. textState.charSpacing = args[0];
  41741. break;
  41742. case OPS.setWordSpacing:
  41743. textState.wordSpacing = args[0];
  41744. break;
  41745. case OPS.beginText:
  41746. flushTextContentItem();
  41747. textState.textMatrix = IDENTITY_MATRIX.slice();
  41748. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  41749. break;
  41750. case OPS.showSpacedText:
  41751. var items = args[0];
  41752. var offset;
  41753. for (var j = 0, jj = items.length; j < jj; j++) {
  41754. if (typeof items[j] === 'string') {
  41755. buildTextContentItem(items[j]);
  41756. } else {
  41757. ensureTextContentItem();
  41758. // PDF Specification 5.3.2 states:
  41759. // The number is expressed in thousandths of a unit of text
  41760. // space.
  41761. // This amount is subtracted from the current horizontal or
  41762. // vertical coordinate, depending on the writing mode.
  41763. // In the default coordinate system, a positive adjustment
  41764. // has the effect of moving the next glyph painted either to
  41765. // the left or down by the given amount.
  41766. advance = items[j] * textState.fontSize / 1000;
  41767. var breakTextRun = false;
  41768. if (textState.font.vertical) {
  41769. offset = advance *
  41770. (textState.textHScale * textState.textMatrix[2] +
  41771. textState.textMatrix[3]);
  41772. textState.translateTextMatrix(0, advance);
  41773. breakTextRun = textContentItem.textRunBreakAllowed &&
  41774. advance > textContentItem.fakeMultiSpaceMax;
  41775. if (!breakTextRun) {
  41776. // Value needs to be added to height to paint down.
  41777. textContentItem.height += offset;
  41778. }
  41779. } else {
  41780. advance = -advance;
  41781. offset = advance * (
  41782. textState.textHScale * textState.textMatrix[0] +
  41783. textState.textMatrix[1]);
  41784. textState.translateTextMatrix(advance, 0);
  41785. breakTextRun = textContentItem.textRunBreakAllowed &&
  41786. advance > textContentItem.fakeMultiSpaceMax;
  41787. if (!breakTextRun) {
  41788. // Value needs to be subtracted from width to paint left.
  41789. textContentItem.width += offset;
  41790. }
  41791. }
  41792. if (breakTextRun) {
  41793. flushTextContentItem();
  41794. } else if (advance > 0) {
  41795. addFakeSpaces(advance, textContentItem.str);
  41796. }
  41797. }
  41798. }
  41799. break;
  41800. case OPS.showText:
  41801. buildTextContentItem(args[0]);
  41802. break;
  41803. case OPS.nextLineShowText:
  41804. flushTextContentItem();
  41805. textState.carriageReturn();
  41806. buildTextContentItem(args[0]);
  41807. break;
  41808. case OPS.nextLineSetSpacingShowText:
  41809. flushTextContentItem();
  41810. textState.wordSpacing = args[0];
  41811. textState.charSpacing = args[1];
  41812. textState.carriageReturn();
  41813. buildTextContentItem(args[2]);
  41814. break;
  41815. case OPS.paintXObject:
  41816. flushTextContentItem();
  41817. if (args[0].code) {
  41818. break;
  41819. }
  41820. if (!xobjs) {
  41821. xobjs = (resources.get('XObject') || Dict.empty);
  41822. }
  41823. var name = args[0].name;
  41824. if (xobjsCache.key === name) {
  41825. if (xobjsCache.texts) {
  41826. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  41827. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  41828. }
  41829. break;
  41830. }
  41831. var xobj = xobjs.get(name);
  41832. if (!xobj) {
  41833. break;
  41834. }
  41835. assert(isStream(xobj), 'XObject should be a stream');
  41836. var type = xobj.dict.get('Subtype');
  41837. assert(isName(type),
  41838. 'XObject should have a Name subtype');
  41839. if ('Form' !== type.name) {
  41840. xobjsCache.key = name;
  41841. xobjsCache.texts = null;
  41842. break;
  41843. }
  41844. stateManager.save();
  41845. var matrix = xobj.dict.get('Matrix');
  41846. if (isArray(matrix) && matrix.length === 6) {
  41847. stateManager.transform(matrix);
  41848. }
  41849. return self.getTextContent(xobj, task,
  41850. xobj.dict.get('Resources') || resources, stateManager,
  41851. normalizeWhitespace).then(function (formTextContent) {
  41852. Util.appendToArray(textContent.items, formTextContent.items);
  41853. Util.extendObj(textContent.styles, formTextContent.styles);
  41854. stateManager.restore();
  41855. xobjsCache.key = name;
  41856. xobjsCache.texts = formTextContent;
  41857. next(resolve, reject);
  41858. }, reject);
  41859. case OPS.setGState:
  41860. flushTextContentItem();
  41861. var dictName = args[0];
  41862. var extGState = resources.get('ExtGState');
  41863. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  41864. break;
  41865. }
  41866. var gsStateMap = extGState.get(dictName.name);
  41867. var gsStateFont = null;
  41868. for (var key in gsStateMap) {
  41869. if (key === 'Font') {
  41870. assert(!gsStateFont);
  41871. gsStateFont = gsStateMap[key];
  41872. }
  41873. }
  41874. if (gsStateFont) {
  41875. textState.fontSize = gsStateFont[1];
  41876. return handleSetFont(gsStateFont[0]).then(function() {
  41877. next(resolve, reject);
  41878. }, reject);
  41879. }
  41880. break;
  41881. } // switch
  41882. } // while
  41883. if (stop) {
  41884. deferred.then(function () {
  41885. next(resolve, reject);
  41886. }, reject);
  41887. return;
  41888. }
  41889. flushTextContentItem();
  41890. resolve(textContent);
  41891. });
  41892. },
  41893. extractDataStructures: function
  41894. partialEvaluatorExtractDataStructures(dict, baseDict,
  41895. xref, properties) {
  41896. // 9.10.2
  41897. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  41898. if (toUnicode) {
  41899. properties.toUnicode = this.readToUnicode(toUnicode);
  41900. }
  41901. if (properties.composite) {
  41902. // CIDSystemInfo helps to match CID to glyphs
  41903. var cidSystemInfo = dict.get('CIDSystemInfo');
  41904. if (isDict(cidSystemInfo)) {
  41905. properties.cidSystemInfo = {
  41906. registry: cidSystemInfo.get('Registry'),
  41907. ordering: cidSystemInfo.get('Ordering'),
  41908. supplement: cidSystemInfo.get('Supplement')
  41909. };
  41910. }
  41911. var cidToGidMap = dict.get('CIDToGIDMap');
  41912. if (isStream(cidToGidMap)) {
  41913. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  41914. }
  41915. }
  41916. // Based on 9.6.6 of the spec the encoding can come from multiple places
  41917. // and depends on the font type. The base encoding and differences are
  41918. // read here, but the encoding that is actually used is chosen during
  41919. // glyph mapping in the font.
  41920. // TODO: Loading the built in encoding in the font would allow the
  41921. // differences to be merged in here not require us to hold on to it.
  41922. var differences = [];
  41923. var baseEncodingName = null;
  41924. var encoding;
  41925. if (dict.has('Encoding')) {
  41926. encoding = dict.get('Encoding');
  41927. if (isDict(encoding)) {
  41928. baseEncodingName = encoding.get('BaseEncoding');
  41929. baseEncodingName = (isName(baseEncodingName) ?
  41930. baseEncodingName.name : null);
  41931. // Load the differences between the base and original
  41932. if (encoding.has('Differences')) {
  41933. var diffEncoding = encoding.get('Differences');
  41934. var index = 0;
  41935. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  41936. var data = diffEncoding[j];
  41937. if (isNum(data)) {
  41938. index = data;
  41939. } else if (isName(data)) {
  41940. differences[index++] = data.name;
  41941. } else if (isRef(data)) {
  41942. diffEncoding[j--] = xref.fetch(data);
  41943. continue;
  41944. } else {
  41945. error('Invalid entry in \'Differences\' array: ' + data);
  41946. }
  41947. }
  41948. }
  41949. } else if (isName(encoding)) {
  41950. baseEncodingName = encoding.name;
  41951. } else {
  41952. error('Encoding is not a Name nor a Dict');
  41953. }
  41954. // According to table 114 if the encoding is a named encoding it must be
  41955. // one of these predefined encodings.
  41956. if ((baseEncodingName !== 'MacRomanEncoding' &&
  41957. baseEncodingName !== 'MacExpertEncoding' &&
  41958. baseEncodingName !== 'WinAnsiEncoding')) {
  41959. baseEncodingName = null;
  41960. }
  41961. }
  41962. if (baseEncodingName) {
  41963. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  41964. } else {
  41965. encoding = (properties.type === 'TrueType' ?
  41966. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  41967. // The Symbolic attribute can be misused for regular fonts
  41968. // Heuristic: we have to check if the font is a standard one also
  41969. if (!!(properties.flags & FontFlags.Symbolic)) {
  41970. encoding = Encodings.MacRomanEncoding;
  41971. if (!properties.file) {
  41972. if (/Symbol/i.test(properties.name)) {
  41973. encoding = Encodings.SymbolSetEncoding;
  41974. } else if (/Dingbats/i.test(properties.name)) {
  41975. encoding = Encodings.ZapfDingbatsEncoding;
  41976. }
  41977. }
  41978. }
  41979. properties.defaultEncoding = encoding;
  41980. }
  41981. properties.differences = differences;
  41982. properties.baseEncodingName = baseEncodingName;
  41983. properties.dict = dict;
  41984. },
  41985. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  41986. var cmap, cmapObj = toUnicode;
  41987. if (isName(cmapObj)) {
  41988. cmap = CMapFactory.create(cmapObj,
  41989. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  41990. if (cmap instanceof IdentityCMap) {
  41991. return new IdentityToUnicodeMap(0, 0xFFFF);
  41992. }
  41993. return new ToUnicodeMap(cmap.getMap());
  41994. } else if (isStream(cmapObj)) {
  41995. cmap = CMapFactory.create(cmapObj,
  41996. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  41997. if (cmap instanceof IdentityCMap) {
  41998. return new IdentityToUnicodeMap(0, 0xFFFF);
  41999. }
  42000. var map = new Array(cmap.length);
  42001. // Convert UTF-16BE
  42002. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  42003. // to iterate over all keys.
  42004. cmap.forEach(function(charCode, token) {
  42005. var str = [];
  42006. for (var k = 0; k < token.length; k += 2) {
  42007. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42008. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  42009. str.push(w1);
  42010. continue;
  42011. }
  42012. k += 2;
  42013. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  42014. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  42015. }
  42016. map[charCode] = String.fromCharCode.apply(String, str);
  42017. });
  42018. return new ToUnicodeMap(map);
  42019. }
  42020. return null;
  42021. },
  42022. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  42023. // Extract the encoding from the CIDToGIDMap
  42024. var glyphsData = cidToGidStream.getBytes();
  42025. // Set encoding 0 to later verify the font has an encoding
  42026. var result = [];
  42027. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  42028. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  42029. if (glyphID === 0) {
  42030. continue;
  42031. }
  42032. var code = j >> 1;
  42033. result[code] = glyphID;
  42034. }
  42035. return result;
  42036. },
  42037. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  42038. descriptor,
  42039. properties) {
  42040. var glyphsWidths = [];
  42041. var defaultWidth = 0;
  42042. var glyphsVMetrics = [];
  42043. var defaultVMetrics;
  42044. var i, ii, j, jj, start, code, widths;
  42045. if (properties.composite) {
  42046. defaultWidth = dict.get('DW') || 1000;
  42047. widths = dict.get('W');
  42048. if (widths) {
  42049. for (i = 0, ii = widths.length; i < ii; i++) {
  42050. start = widths[i++];
  42051. code = xref.fetchIfRef(widths[i]);
  42052. if (isArray(code)) {
  42053. for (j = 0, jj = code.length; j < jj; j++) {
  42054. glyphsWidths[start++] = code[j];
  42055. }
  42056. } else {
  42057. var width = widths[++i];
  42058. for (j = start; j <= code; j++) {
  42059. glyphsWidths[j] = width;
  42060. }
  42061. }
  42062. }
  42063. }
  42064. if (properties.vertical) {
  42065. var vmetrics = (dict.get('DW2') || [880, -1000]);
  42066. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  42067. vmetrics = dict.get('W2');
  42068. if (vmetrics) {
  42069. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  42070. start = vmetrics[i++];
  42071. code = xref.fetchIfRef(vmetrics[i]);
  42072. if (isArray(code)) {
  42073. for (j = 0, jj = code.length; j < jj; j++) {
  42074. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  42075. }
  42076. } else {
  42077. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  42078. for (j = start; j <= code; j++) {
  42079. glyphsVMetrics[j] = vmetric;
  42080. }
  42081. }
  42082. }
  42083. }
  42084. }
  42085. } else {
  42086. var firstChar = properties.firstChar;
  42087. widths = dict.get('Widths');
  42088. if (widths) {
  42089. j = firstChar;
  42090. for (i = 0, ii = widths.length; i < ii; i++) {
  42091. glyphsWidths[j++] = widths[i];
  42092. }
  42093. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  42094. } else {
  42095. // Trying get the BaseFont metrics (see comment above).
  42096. var baseFontName = dict.get('BaseFont');
  42097. if (isName(baseFontName)) {
  42098. var metrics = this.getBaseFontMetrics(baseFontName.name);
  42099. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  42100. properties);
  42101. defaultWidth = metrics.defaultWidth;
  42102. }
  42103. }
  42104. }
  42105. // Heuristic: detection of monospace font by checking all non-zero widths
  42106. var isMonospace = true;
  42107. var firstWidth = defaultWidth;
  42108. for (var glyph in glyphsWidths) {
  42109. var glyphWidth = glyphsWidths[glyph];
  42110. if (!glyphWidth) {
  42111. continue;
  42112. }
  42113. if (!firstWidth) {
  42114. firstWidth = glyphWidth;
  42115. continue;
  42116. }
  42117. if (firstWidth !== glyphWidth) {
  42118. isMonospace = false;
  42119. break;
  42120. }
  42121. }
  42122. if (isMonospace) {
  42123. properties.flags |= FontFlags.FixedPitch;
  42124. }
  42125. properties.defaultWidth = defaultWidth;
  42126. properties.widths = glyphsWidths;
  42127. properties.defaultVMetrics = defaultVMetrics;
  42128. properties.vmetrics = glyphsVMetrics;
  42129. },
  42130. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  42131. // Simulating descriptor flags attribute
  42132. var fontNameWoStyle = baseFontName.split('-')[0];
  42133. return (fontNameWoStyle in serifFonts) ||
  42134. (fontNameWoStyle.search(/serif/gi) !== -1);
  42135. },
  42136. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  42137. var defaultWidth = 0;
  42138. var widths = [];
  42139. var monospace = false;
  42140. var lookupName = (stdFontMap[name] || name);
  42141. if (!(lookupName in Metrics)) {
  42142. // Use default fonts for looking up font metrics if the passed
  42143. // font is not a base font
  42144. if (this.isSerifFont(name)) {
  42145. lookupName = 'Times-Roman';
  42146. } else {
  42147. lookupName = 'Helvetica';
  42148. }
  42149. }
  42150. var glyphWidths = Metrics[lookupName];
  42151. if (isNum(glyphWidths)) {
  42152. defaultWidth = glyphWidths;
  42153. monospace = true;
  42154. } else {
  42155. widths = glyphWidths;
  42156. }
  42157. return {
  42158. defaultWidth: defaultWidth,
  42159. monospace: monospace,
  42160. widths: widths
  42161. };
  42162. },
  42163. buildCharCodeToWidth:
  42164. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  42165. properties) {
  42166. var widths = Object.create(null);
  42167. var differences = properties.differences;
  42168. var encoding = properties.defaultEncoding;
  42169. for (var charCode = 0; charCode < 256; charCode++) {
  42170. if (charCode in differences &&
  42171. widthsByGlyphName[differences[charCode]]) {
  42172. widths[charCode] = widthsByGlyphName[differences[charCode]];
  42173. continue;
  42174. }
  42175. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  42176. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  42177. continue;
  42178. }
  42179. }
  42180. return widths;
  42181. },
  42182. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  42183. var baseDict = dict;
  42184. var type = dict.get('Subtype');
  42185. assert(isName(type), 'invalid font Subtype');
  42186. var composite = false;
  42187. var uint8array;
  42188. if (type.name === 'Type0') {
  42189. // If font is a composite
  42190. // - get the descendant font
  42191. // - set the type according to the descendant font
  42192. // - get the FontDescriptor from the descendant font
  42193. var df = dict.get('DescendantFonts');
  42194. if (!df) {
  42195. error('Descendant fonts are not specified');
  42196. }
  42197. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  42198. type = dict.get('Subtype');
  42199. assert(isName(type), 'invalid font Subtype');
  42200. composite = true;
  42201. }
  42202. var descriptor = dict.get('FontDescriptor');
  42203. if (descriptor) {
  42204. var hash = new MurmurHash3_64();
  42205. var encoding = baseDict.getRaw('Encoding');
  42206. if (isName(encoding)) {
  42207. hash.update(encoding.name);
  42208. } else if (isRef(encoding)) {
  42209. hash.update(encoding.num + '_' + encoding.gen);
  42210. } else if (isDict(encoding)) {
  42211. var keys = encoding.getKeys();
  42212. for (var i = 0, ii = keys.length; i < ii; i++) {
  42213. var entry = encoding.getRaw(keys[i]);
  42214. if (isName(entry)) {
  42215. hash.update(entry.name);
  42216. } else if (isRef(entry)) {
  42217. hash.update(entry.num + '_' + entry.gen);
  42218. } else if (isArray(entry)) { // 'Differences' entry.
  42219. // Ideally we should check the contents of the array, but to avoid
  42220. // parsing it here and then again in |extractDataStructures|,
  42221. // we only use the array length for now (fixes bug1157493.pdf).
  42222. hash.update(entry.length.toString());
  42223. }
  42224. }
  42225. }
  42226. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  42227. if (isStream(toUnicode)) {
  42228. var stream = toUnicode.str || toUnicode;
  42229. uint8array = stream.buffer ?
  42230. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  42231. new Uint8Array(stream.bytes.buffer,
  42232. stream.start, stream.end - stream.start);
  42233. hash.update(uint8array);
  42234. } else if (isName(toUnicode)) {
  42235. hash.update(toUnicode.name);
  42236. }
  42237. var widths = dict.get('Widths') || baseDict.get('Widths');
  42238. if (widths) {
  42239. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  42240. hash.update(uint8array);
  42241. }
  42242. }
  42243. return {
  42244. descriptor: descriptor,
  42245. dict: dict,
  42246. baseDict: baseDict,
  42247. composite: composite,
  42248. type: type.name,
  42249. hash: hash ? hash.hexdigest() : ''
  42250. };
  42251. },
  42252. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  42253. xref) {
  42254. var baseDict = preEvaluatedFont.baseDict;
  42255. var dict = preEvaluatedFont.dict;
  42256. var composite = preEvaluatedFont.composite;
  42257. var descriptor = preEvaluatedFont.descriptor;
  42258. var type = preEvaluatedFont.type;
  42259. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  42260. var properties;
  42261. if (!descriptor) {
  42262. if (type === 'Type3') {
  42263. // FontDescriptor is only required for Type3 fonts when the document
  42264. // is a tagged pdf. Create a barbebones one to get by.
  42265. descriptor = new Dict(null);
  42266. descriptor.set('FontName', Name.get(type));
  42267. descriptor.set('FontBBox', dict.get('FontBBox'));
  42268. } else {
  42269. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  42270. // FontDescriptor was not required.
  42271. // This case is here for compatibility.
  42272. var baseFontName = dict.get('BaseFont');
  42273. if (!isName(baseFontName)) {
  42274. error('Base font is not specified');
  42275. }
  42276. // Using base font name as a font name.
  42277. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  42278. var metrics = this.getBaseFontMetrics(baseFontName);
  42279. // Simulating descriptor flags attribute
  42280. var fontNameWoStyle = baseFontName.split('-')[0];
  42281. var flags =
  42282. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  42283. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  42284. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  42285. FontFlags.Nonsymbolic);
  42286. properties = {
  42287. type: type,
  42288. name: baseFontName,
  42289. widths: metrics.widths,
  42290. defaultWidth: metrics.defaultWidth,
  42291. flags: flags,
  42292. firstChar: 0,
  42293. lastChar: maxCharIndex
  42294. };
  42295. this.extractDataStructures(dict, dict, xref, properties);
  42296. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  42297. properties);
  42298. return new Font(baseFontName, null, properties);
  42299. }
  42300. }
  42301. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  42302. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  42303. // to ignore this rule when a variant of a standart font is used.
  42304. // TODO Fill the width array depending on which of the base font this is
  42305. // a variant.
  42306. var firstChar = (dict.get('FirstChar') || 0);
  42307. var lastChar = (dict.get('LastChar') || maxCharIndex);
  42308. var fontName = descriptor.get('FontName');
  42309. var baseFont = dict.get('BaseFont');
  42310. // Some bad PDFs have a string as the font name.
  42311. if (isString(fontName)) {
  42312. fontName = Name.get(fontName);
  42313. }
  42314. if (isString(baseFont)) {
  42315. baseFont = Name.get(baseFont);
  42316. }
  42317. if (type !== 'Type3') {
  42318. var fontNameStr = fontName && fontName.name;
  42319. var baseFontStr = baseFont && baseFont.name;
  42320. if (fontNameStr !== baseFontStr) {
  42321. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  42322. '" but should be the same as the Font\'s BaseFont "' +
  42323. baseFontStr + '"');
  42324. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  42325. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  42326. if (fontNameStr && baseFontStr &&
  42327. baseFontStr.indexOf(fontNameStr) === 0) {
  42328. fontName = baseFont;
  42329. }
  42330. }
  42331. }
  42332. fontName = (fontName || baseFont);
  42333. assert(isName(fontName), 'invalid font name');
  42334. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  42335. if (fontFile) {
  42336. if (fontFile.dict) {
  42337. var subtype = fontFile.dict.get('Subtype');
  42338. if (subtype) {
  42339. subtype = subtype.name;
  42340. }
  42341. var length1 = fontFile.dict.get('Length1');
  42342. var length2 = fontFile.dict.get('Length2');
  42343. }
  42344. }
  42345. properties = {
  42346. type: type,
  42347. name: fontName.name,
  42348. subtype: subtype,
  42349. file: fontFile,
  42350. length1: length1,
  42351. length2: length2,
  42352. loadedName: baseDict.loadedName,
  42353. composite: composite,
  42354. wideChars: composite,
  42355. fixedPitch: false,
  42356. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  42357. firstChar: firstChar || 0,
  42358. lastChar: (lastChar || maxCharIndex),
  42359. bbox: descriptor.get('FontBBox'),
  42360. ascent: descriptor.get('Ascent'),
  42361. descent: descriptor.get('Descent'),
  42362. xHeight: descriptor.get('XHeight'),
  42363. capHeight: descriptor.get('CapHeight'),
  42364. flags: descriptor.get('Flags'),
  42365. italicAngle: descriptor.get('ItalicAngle'),
  42366. coded: false
  42367. };
  42368. if (composite) {
  42369. var cidEncoding = baseDict.get('Encoding');
  42370. if (isName(cidEncoding)) {
  42371. properties.cidEncoding = cidEncoding.name;
  42372. }
  42373. properties.cMap = CMapFactory.create(cidEncoding,
  42374. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42375. properties.vertical = properties.cMap.vertical;
  42376. }
  42377. this.extractDataStructures(dict, baseDict, xref, properties);
  42378. this.extractWidths(dict, xref, descriptor, properties);
  42379. if (type === 'Type3') {
  42380. properties.isType3Font = true;
  42381. }
  42382. return new Font(fontName.name, fontFile, properties);
  42383. }
  42384. };
  42385. return PartialEvaluator;
  42386. })();
  42387. var TranslatedFont = (function TranslatedFontClosure() {
  42388. function TranslatedFont(loadedName, font, dict) {
  42389. this.loadedName = loadedName;
  42390. this.font = font;
  42391. this.dict = dict;
  42392. this.type3Loaded = null;
  42393. this.sent = false;
  42394. }
  42395. TranslatedFont.prototype = {
  42396. send: function (handler) {
  42397. if (this.sent) {
  42398. return;
  42399. }
  42400. var fontData = this.font.exportData();
  42401. handler.send('commonobj', [
  42402. this.loadedName,
  42403. 'Font',
  42404. fontData
  42405. ]);
  42406. this.sent = true;
  42407. },
  42408. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  42409. assert(this.font.isType3Font);
  42410. if (this.type3Loaded) {
  42411. return this.type3Loaded;
  42412. }
  42413. var translatedFont = this.font;
  42414. var loadCharProcsPromise = Promise.resolve();
  42415. var charProcs = this.dict.get('CharProcs').getAll();
  42416. var fontResources = this.dict.get('Resources') || resources;
  42417. var charProcKeys = Object.keys(charProcs);
  42418. var charProcOperatorList = {};
  42419. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  42420. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  42421. var glyphStream = charProcs[key];
  42422. var operatorList = new OperatorList();
  42423. return evaluator.getOperatorList(glyphStream, task, fontResources,
  42424. operatorList).then(function () {
  42425. charProcOperatorList[key] = operatorList.getIR();
  42426. // Add the dependencies to the parent operator list so they are
  42427. // resolved before sub operator list is executed synchronously.
  42428. parentOperatorList.addDependencies(operatorList.dependencies);
  42429. }, function (reason) {
  42430. warn('Type3 font resource \"' + key + '\" is not available');
  42431. var operatorList = new OperatorList();
  42432. charProcOperatorList[key] = operatorList.getIR();
  42433. });
  42434. }.bind(this, charProcKeys[i]));
  42435. }
  42436. this.type3Loaded = loadCharProcsPromise.then(function () {
  42437. translatedFont.charProcOperatorList = charProcOperatorList;
  42438. });
  42439. return this.type3Loaded;
  42440. }
  42441. };
  42442. return TranslatedFont;
  42443. })();
  42444. var OperatorList = (function OperatorListClosure() {
  42445. var CHUNK_SIZE = 1000;
  42446. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  42447. function getTransfers(queue) {
  42448. var transfers = [];
  42449. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  42450. for (var i = 0, ii = queue.length; i < ii; i++) {
  42451. switch (fnArray[i]) {
  42452. case OPS.paintInlineImageXObject:
  42453. case OPS.paintInlineImageXObjectGroup:
  42454. case OPS.paintImageMaskXObject:
  42455. var arg = argsArray[i][0]; // first param in imgData
  42456. if (!arg.cached) {
  42457. transfers.push(arg.data.buffer);
  42458. }
  42459. break;
  42460. }
  42461. }
  42462. return transfers;
  42463. }
  42464. function OperatorList(intent, messageHandler, pageIndex) {
  42465. this.messageHandler = messageHandler;
  42466. this.fnArray = [];
  42467. this.argsArray = [];
  42468. this.dependencies = {};
  42469. this._totalLength = 0;
  42470. this.pageIndex = pageIndex;
  42471. this.intent = intent;
  42472. }
  42473. OperatorList.prototype = {
  42474. get length() {
  42475. return this.argsArray.length;
  42476. },
  42477. /**
  42478. * @returns {number} The total length of the entire operator list,
  42479. * since `this.length === 0` after flushing.
  42480. */
  42481. get totalLength() {
  42482. return (this._totalLength + this.length);
  42483. },
  42484. addOp: function(fn, args) {
  42485. this.fnArray.push(fn);
  42486. this.argsArray.push(args);
  42487. if (this.messageHandler) {
  42488. if (this.fnArray.length >= CHUNK_SIZE) {
  42489. this.flush();
  42490. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  42491. (fn === OPS.restore || fn === OPS.endText)) {
  42492. // heuristic to flush on boundary of restore or endText
  42493. this.flush();
  42494. }
  42495. }
  42496. },
  42497. addDependency: function(dependency) {
  42498. if (dependency in this.dependencies) {
  42499. return;
  42500. }
  42501. this.dependencies[dependency] = true;
  42502. this.addOp(OPS.dependency, [dependency]);
  42503. },
  42504. addDependencies: function(dependencies) {
  42505. for (var key in dependencies) {
  42506. this.addDependency(key);
  42507. }
  42508. },
  42509. addOpList: function(opList) {
  42510. Util.extendObj(this.dependencies, opList.dependencies);
  42511. for (var i = 0, ii = opList.length; i < ii; i++) {
  42512. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  42513. }
  42514. },
  42515. getIR: function() {
  42516. return {
  42517. fnArray: this.fnArray,
  42518. argsArray: this.argsArray,
  42519. length: this.length
  42520. };
  42521. },
  42522. flush: function(lastChunk) {
  42523. if (this.intent !== 'oplist') {
  42524. new QueueOptimizer().optimize(this);
  42525. }
  42526. var transfers = getTransfers(this);
  42527. var length = this.length;
  42528. this._totalLength += length;
  42529. this.messageHandler.send('RenderPageChunk', {
  42530. operatorList: {
  42531. fnArray: this.fnArray,
  42532. argsArray: this.argsArray,
  42533. lastChunk: lastChunk,
  42534. length: length
  42535. },
  42536. pageIndex: this.pageIndex,
  42537. intent: this.intent
  42538. }, transfers);
  42539. this.dependencies = {};
  42540. this.fnArray.length = 0;
  42541. this.argsArray.length = 0;
  42542. }
  42543. };
  42544. return OperatorList;
  42545. })();
  42546. var StateManager = (function StateManagerClosure() {
  42547. function StateManager(initialState) {
  42548. this.state = initialState;
  42549. this.stateStack = [];
  42550. }
  42551. StateManager.prototype = {
  42552. save: function () {
  42553. var old = this.state;
  42554. this.stateStack.push(this.state);
  42555. this.state = old.clone();
  42556. },
  42557. restore: function () {
  42558. var prev = this.stateStack.pop();
  42559. if (prev) {
  42560. this.state = prev;
  42561. }
  42562. },
  42563. transform: function (args) {
  42564. this.state.ctm = Util.transform(this.state.ctm, args);
  42565. }
  42566. };
  42567. return StateManager;
  42568. })();
  42569. var TextState = (function TextStateClosure() {
  42570. function TextState() {
  42571. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42572. this.fontSize = 0;
  42573. this.font = null;
  42574. this.fontMatrix = FONT_IDENTITY_MATRIX;
  42575. this.textMatrix = IDENTITY_MATRIX.slice();
  42576. this.textLineMatrix = IDENTITY_MATRIX.slice();
  42577. this.charSpacing = 0;
  42578. this.wordSpacing = 0;
  42579. this.leading = 0;
  42580. this.textHScale = 1;
  42581. this.textRise = 0;
  42582. }
  42583. TextState.prototype = {
  42584. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42585. var m = this.textMatrix;
  42586. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42587. },
  42588. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42589. var m = this.textLineMatrix;
  42590. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42591. },
  42592. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  42593. var m = this.textMatrix;
  42594. m[4] = m[0] * x + m[2] * y + m[4];
  42595. m[5] = m[1] * x + m[3] * y + m[5];
  42596. },
  42597. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  42598. var m = this.textLineMatrix;
  42599. m[4] = m[0] * x + m[2] * y + m[4];
  42600. m[5] = m[1] * x + m[3] * y + m[5];
  42601. },
  42602. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  42603. // 9.4.4 Text Space Details
  42604. var tsm = [this.fontSize * this.textHScale, 0,
  42605. 0, this.fontSize,
  42606. 0, this.textRise];
  42607. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  42608. },
  42609. carriageReturn: function TextState_carriageReturn() {
  42610. this.translateTextLineMatrix(0, -this.leading);
  42611. this.textMatrix = this.textLineMatrix.slice();
  42612. },
  42613. clone: function TextState_clone() {
  42614. var clone = Object.create(this);
  42615. clone.textMatrix = this.textMatrix.slice();
  42616. clone.textLineMatrix = this.textLineMatrix.slice();
  42617. clone.fontMatrix = this.fontMatrix.slice();
  42618. return clone;
  42619. }
  42620. };
  42621. return TextState;
  42622. })();
  42623. var EvalState = (function EvalStateClosure() {
  42624. function EvalState() {
  42625. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42626. this.font = null;
  42627. this.textRenderingMode = TextRenderingMode.FILL;
  42628. this.fillColorSpace = ColorSpace.singletons.gray;
  42629. this.strokeColorSpace = ColorSpace.singletons.gray;
  42630. }
  42631. EvalState.prototype = {
  42632. clone: function CanvasExtraState_clone() {
  42633. return Object.create(this);
  42634. },
  42635. };
  42636. return EvalState;
  42637. })();
  42638. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  42639. // Specifies properties for each command
  42640. //
  42641. // If variableArgs === true: [0, `numArgs`] expected
  42642. // If variableArgs === false: exactly `numArgs` expected
  42643. var OP_MAP = {
  42644. // Graphic state
  42645. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  42646. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  42647. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  42648. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  42649. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  42650. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  42651. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  42652. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  42653. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  42654. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  42655. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  42656. // Path
  42657. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  42658. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  42659. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  42660. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  42661. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  42662. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  42663. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  42664. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  42665. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  42666. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42667. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42668. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  42669. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  42670. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  42671. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  42672. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  42673. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  42674. // Clipping
  42675. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  42676. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  42677. // Text
  42678. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  42679. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  42680. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  42681. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  42682. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  42683. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  42684. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  42685. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  42686. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  42687. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  42688. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  42689. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  42690. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  42691. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  42692. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  42693. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  42694. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  42695. variableArgs: false },
  42696. // Type3 fonts
  42697. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  42698. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  42699. // Color
  42700. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  42701. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  42702. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  42703. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  42704. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  42705. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  42706. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  42707. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  42708. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  42709. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  42710. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  42711. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  42712. // Shading
  42713. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  42714. // Images
  42715. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  42716. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  42717. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  42718. // XObjects
  42719. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  42720. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  42721. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  42722. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  42723. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  42724. variableArgs: false },
  42725. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  42726. // Compatibility
  42727. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  42728. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  42729. // (reserved partial commands for the lexer)
  42730. BM: null,
  42731. BD: null,
  42732. 'true': null,
  42733. fa: null,
  42734. fal: null,
  42735. fals: null,
  42736. 'false': null,
  42737. nu: null,
  42738. nul: null,
  42739. 'null': null
  42740. };
  42741. function EvaluatorPreprocessor(stream, xref, stateManager) {
  42742. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  42743. // dictionary
  42744. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  42745. this.stateManager = stateManager;
  42746. this.nonProcessedArgs = [];
  42747. }
  42748. EvaluatorPreprocessor.prototype = {
  42749. get savedStatesDepth() {
  42750. return this.stateManager.stateStack.length;
  42751. },
  42752. // |operation| is an object with two fields:
  42753. //
  42754. // - |fn| is an out param.
  42755. //
  42756. // - |args| is an inout param. On entry, it should have one of two values.
  42757. //
  42758. // - An empty array. This indicates that the caller is providing the
  42759. // array in which the args will be stored in. The caller should use
  42760. // this value if it can reuse a single array for each call to read().
  42761. //
  42762. // - |null|. This indicates that the caller needs this function to create
  42763. // the array in which any args are stored in. If there are zero args,
  42764. // this function will leave |operation.args| as |null| (thus avoiding
  42765. // allocations that would occur if we used an empty array to represent
  42766. // zero arguments). Otherwise, it will replace |null| with a new array
  42767. // containing the arguments. The caller should use this value if it
  42768. // cannot reuse an array for each call to read().
  42769. //
  42770. // These two modes are present because this function is very hot and so
  42771. // avoiding allocations where possible is worthwhile.
  42772. //
  42773. read: function EvaluatorPreprocessor_read(operation) {
  42774. var args = operation.args;
  42775. while (true) {
  42776. var obj = this.parser.getObj();
  42777. if (isCmd(obj)) {
  42778. var cmd = obj.cmd;
  42779. // Check that the command is valid
  42780. var opSpec = OP_MAP[cmd];
  42781. if (!opSpec) {
  42782. warn('Unknown command "' + cmd + '"');
  42783. continue;
  42784. }
  42785. var fn = opSpec.id;
  42786. var numArgs = opSpec.numArgs;
  42787. var argsLength = args !== null ? args.length : 0;
  42788. if (!opSpec.variableArgs) {
  42789. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  42790. if (argsLength !== numArgs) {
  42791. var nonProcessedArgs = this.nonProcessedArgs;
  42792. while (argsLength > numArgs) {
  42793. nonProcessedArgs.push(args.shift());
  42794. argsLength--;
  42795. }
  42796. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  42797. if (!args) {
  42798. args = [];
  42799. }
  42800. args.unshift(nonProcessedArgs.pop());
  42801. argsLength++;
  42802. }
  42803. }
  42804. if (argsLength < numArgs) {
  42805. // If we receive too few args, it's not possible to possible
  42806. // to execute the command, so skip the command
  42807. info('Command ' + fn + ': because expected ' +
  42808. numArgs + ' args, but received ' + argsLength +
  42809. ' args; skipping');
  42810. args = null;
  42811. continue;
  42812. }
  42813. } else if (argsLength > numArgs) {
  42814. info('Command ' + fn + ': expected [0,' + numArgs +
  42815. '] args, but received ' + argsLength + ' args');
  42816. }
  42817. // TODO figure out how to type-check vararg functions
  42818. this.preprocessCommand(fn, args);
  42819. operation.fn = fn;
  42820. operation.args = args;
  42821. return true;
  42822. } else {
  42823. if (isEOF(obj)) {
  42824. return false; // no more commands
  42825. }
  42826. // argument
  42827. if (obj !== null) {
  42828. if (!args) {
  42829. args = [];
  42830. }
  42831. args.push((obj instanceof Dict ? obj.getAll() : obj));
  42832. assert(args.length <= 33, 'Too many arguments');
  42833. }
  42834. }
  42835. }
  42836. },
  42837. preprocessCommand:
  42838. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  42839. switch (fn | 0) {
  42840. case OPS.save:
  42841. this.stateManager.save();
  42842. break;
  42843. case OPS.restore:
  42844. this.stateManager.restore();
  42845. break;
  42846. case OPS.transform:
  42847. this.stateManager.transform(args);
  42848. break;
  42849. }
  42850. }
  42851. };
  42852. return EvaluatorPreprocessor;
  42853. })();
  42854. var QueueOptimizer = (function QueueOptimizerClosure() {
  42855. function addState(parentState, pattern, fn) {
  42856. var state = parentState;
  42857. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  42858. var item = pattern[i];
  42859. state = (state[item] || (state[item] = []));
  42860. }
  42861. state[pattern[pattern.length - 1]] = fn;
  42862. }
  42863. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  42864. argsArray) {
  42865. // Handles special case of mainly LaTeX documents which use image masks to
  42866. // draw lines with the current fill style.
  42867. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  42868. // have been found at iFirstSave.
  42869. var iFirstPIMXO = iFirstSave + 2;
  42870. for (var i = 0; i < count; i++) {
  42871. var arg = argsArray[iFirstPIMXO + 4 * i];
  42872. var imageMask = arg.length === 1 && arg[0];
  42873. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  42874. (!imageMask.data.length ||
  42875. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  42876. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  42877. continue;
  42878. }
  42879. break;
  42880. }
  42881. return count - i;
  42882. }
  42883. var InitialState = [];
  42884. // This replaces (save, transform, paintInlineImageXObject, restore)+
  42885. // sequences with one |paintInlineImageXObjectGroup| operation.
  42886. addState(InitialState,
  42887. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  42888. function foundInlineImageGroup(context) {
  42889. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  42890. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  42891. var MAX_WIDTH = 1000;
  42892. var IMAGE_PADDING = 1;
  42893. var fnArray = context.fnArray, argsArray = context.argsArray;
  42894. var curr = context.iCurr;
  42895. var iFirstSave = curr - 3;
  42896. var iFirstTransform = curr - 2;
  42897. var iFirstPIIXO = curr - 1;
  42898. // Look for the quartets.
  42899. var i = iFirstSave + 4;
  42900. var ii = fnArray.length;
  42901. while (i + 3 < ii) {
  42902. if (fnArray[i] !== OPS.save ||
  42903. fnArray[i + 1] !== OPS.transform ||
  42904. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  42905. fnArray[i + 3] !== OPS.restore) {
  42906. break; // ops don't match
  42907. }
  42908. i += 4;
  42909. }
  42910. // At this point, i is the index of the first op past the last valid
  42911. // quartet.
  42912. var count = Math.min((i - iFirstSave) / 4,
  42913. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  42914. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  42915. return i;
  42916. }
  42917. // assuming that heights of those image is too small (~1 pixel)
  42918. // packing as much as possible by lines
  42919. var maxX = 0;
  42920. var map = [], maxLineHeight = 0;
  42921. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  42922. var q;
  42923. for (q = 0; q < count; q++) {
  42924. var transform = argsArray[iFirstTransform + (q << 2)];
  42925. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  42926. if (currentX + img.width > MAX_WIDTH) {
  42927. // starting new line
  42928. maxX = Math.max(maxX, currentX);
  42929. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  42930. currentX = 0;
  42931. maxLineHeight = 0;
  42932. }
  42933. map.push({
  42934. transform: transform,
  42935. x: currentX, y: currentY,
  42936. w: img.width, h: img.height
  42937. });
  42938. currentX += img.width + 2 * IMAGE_PADDING;
  42939. maxLineHeight = Math.max(maxLineHeight, img.height);
  42940. }
  42941. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  42942. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  42943. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  42944. var imgRowSize = imgWidth << 2;
  42945. for (q = 0; q < count; q++) {
  42946. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  42947. // Copy image by lines and extends pixels into padding.
  42948. var rowSize = map[q].w << 2;
  42949. var dataOffset = 0;
  42950. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  42951. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  42952. for (var k = 0, kk = map[q].h; k < kk; k++) {
  42953. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  42954. dataOffset += rowSize;
  42955. offset += imgRowSize;
  42956. }
  42957. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  42958. while (offset >= 0) {
  42959. data[offset - 4] = data[offset];
  42960. data[offset - 3] = data[offset + 1];
  42961. data[offset - 2] = data[offset + 2];
  42962. data[offset - 1] = data[offset + 3];
  42963. data[offset + rowSize] = data[offset + rowSize - 4];
  42964. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  42965. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  42966. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  42967. offset -= imgRowSize;
  42968. }
  42969. }
  42970. // Replace queue items.
  42971. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  42972. argsArray.splice(iFirstSave, count * 4,
  42973. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  42974. data: imgData }, map]);
  42975. return iFirstSave + 1;
  42976. });
  42977. // This replaces (save, transform, paintImageMaskXObject, restore)+
  42978. // sequences with one |paintImageMaskXObjectGroup| or one
  42979. // |paintImageMaskXObjectRepeat| operation.
  42980. addState(InitialState,
  42981. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  42982. function foundImageMaskGroup(context) {
  42983. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  42984. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  42985. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  42986. var fnArray = context.fnArray, argsArray = context.argsArray;
  42987. var curr = context.iCurr;
  42988. var iFirstSave = curr - 3;
  42989. var iFirstTransform = curr - 2;
  42990. var iFirstPIMXO = curr - 1;
  42991. // Look for the quartets.
  42992. var i = iFirstSave + 4;
  42993. var ii = fnArray.length;
  42994. while (i + 3 < ii) {
  42995. if (fnArray[i] !== OPS.save ||
  42996. fnArray[i + 1] !== OPS.transform ||
  42997. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  42998. fnArray[i + 3] !== OPS.restore) {
  42999. break; // ops don't match
  43000. }
  43001. i += 4;
  43002. }
  43003. // At this point, i is the index of the first op past the last valid
  43004. // quartet.
  43005. var count = (i - iFirstSave) / 4;
  43006. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  43007. argsArray);
  43008. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  43009. return i;
  43010. }
  43011. var q;
  43012. var isSameImage = false;
  43013. var iTransform, transformArgs;
  43014. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  43015. if (argsArray[iFirstTransform][1] === 0 &&
  43016. argsArray[iFirstTransform][2] === 0) {
  43017. isSameImage = true;
  43018. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43019. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43020. iTransform = iFirstTransform + 4;
  43021. var iPIMXO = iFirstPIMXO + 4;
  43022. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  43023. transformArgs = argsArray[iTransform];
  43024. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  43025. transformArgs[0] !== firstTransformArg0 ||
  43026. transformArgs[1] !== 0 ||
  43027. transformArgs[2] !== 0 ||
  43028. transformArgs[3] !== firstTransformArg3) {
  43029. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  43030. isSameImage = false;
  43031. } else {
  43032. count = q;
  43033. }
  43034. break; // different image or transform
  43035. }
  43036. }
  43037. }
  43038. if (isSameImage) {
  43039. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  43040. var positions = new Float32Array(count * 2);
  43041. iTransform = iFirstTransform;
  43042. for (q = 0; q < count; q++, iTransform += 4) {
  43043. transformArgs = argsArray[iTransform];
  43044. positions[(q << 1)] = transformArgs[4];
  43045. positions[(q << 1) + 1] = transformArgs[5];
  43046. }
  43047. // Replace queue items.
  43048. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  43049. argsArray.splice(iFirstSave, count * 4,
  43050. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  43051. } else {
  43052. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  43053. var images = [];
  43054. for (q = 0; q < count; q++) {
  43055. transformArgs = argsArray[iFirstTransform + (q << 2)];
  43056. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  43057. images.push({ data: maskParams.data, width: maskParams.width,
  43058. height: maskParams.height,
  43059. transform: transformArgs });
  43060. }
  43061. // Replace queue items.
  43062. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  43063. argsArray.splice(iFirstSave, count * 4, [images]);
  43064. }
  43065. return iFirstSave + 1;
  43066. });
  43067. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  43068. // with one paintImageXObjectRepeat operation, if the |transform| and
  43069. // |paintImageXObjectRepeat| ops are appropriate.
  43070. addState(InitialState,
  43071. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  43072. function (context) {
  43073. var MIN_IMAGES_IN_BLOCK = 3;
  43074. var MAX_IMAGES_IN_BLOCK = 1000;
  43075. var fnArray = context.fnArray, argsArray = context.argsArray;
  43076. var curr = context.iCurr;
  43077. var iFirstSave = curr - 3;
  43078. var iFirstTransform = curr - 2;
  43079. var iFirstPIXO = curr - 1;
  43080. var iFirstRestore = curr;
  43081. if (argsArray[iFirstTransform][1] !== 0 ||
  43082. argsArray[iFirstTransform][2] !== 0) {
  43083. return iFirstRestore + 1; // transform has the wrong form
  43084. }
  43085. // Look for the quartets.
  43086. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  43087. var firstTransformArg0 = argsArray[iFirstTransform][0];
  43088. var firstTransformArg3 = argsArray[iFirstTransform][3];
  43089. var i = iFirstSave + 4;
  43090. var ii = fnArray.length;
  43091. while (i + 3 < ii) {
  43092. if (fnArray[i] !== OPS.save ||
  43093. fnArray[i + 1] !== OPS.transform ||
  43094. fnArray[i + 2] !== OPS.paintImageXObject ||
  43095. fnArray[i + 3] !== OPS.restore) {
  43096. break; // ops don't match
  43097. }
  43098. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  43099. argsArray[i + 1][1] !== 0 ||
  43100. argsArray[i + 1][2] !== 0 ||
  43101. argsArray[i + 1][3] !== firstTransformArg3) {
  43102. break; // transforms don't match
  43103. }
  43104. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  43105. break; // images don't match
  43106. }
  43107. i += 4;
  43108. }
  43109. // At this point, i is the index of the first op past the last valid
  43110. // quartet.
  43111. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  43112. if (count < MIN_IMAGES_IN_BLOCK) {
  43113. return i;
  43114. }
  43115. // Extract the (x,y) positions from all of the matching transforms.
  43116. var positions = new Float32Array(count * 2);
  43117. var iTransform = iFirstTransform;
  43118. for (var q = 0; q < count; q++, iTransform += 4) {
  43119. var transformArgs = argsArray[iTransform];
  43120. positions[(q << 1)] = transformArgs[4];
  43121. positions[(q << 1) + 1] = transformArgs[5];
  43122. }
  43123. // Replace queue items.
  43124. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  43125. positions];
  43126. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  43127. argsArray.splice(iFirstSave, count * 4, args);
  43128. return iFirstSave + 1;
  43129. });
  43130. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  43131. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  43132. // sequences, if the font for each one is the same.
  43133. addState(InitialState,
  43134. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  43135. function (context) {
  43136. var MIN_CHARS_IN_BLOCK = 3;
  43137. var MAX_CHARS_IN_BLOCK = 1000;
  43138. var fnArray = context.fnArray, argsArray = context.argsArray;
  43139. var curr = context.iCurr;
  43140. var iFirstBeginText = curr - 4;
  43141. var iFirstSetFont = curr - 3;
  43142. var iFirstSetTextMatrix = curr - 2;
  43143. var iFirstShowText = curr - 1;
  43144. var iFirstEndText = curr;
  43145. // Look for the quintets.
  43146. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  43147. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  43148. var i = iFirstBeginText + 5;
  43149. var ii = fnArray.length;
  43150. while (i + 4 < ii) {
  43151. if (fnArray[i] !== OPS.beginText ||
  43152. fnArray[i + 1] !== OPS.setFont ||
  43153. fnArray[i + 2] !== OPS.setTextMatrix ||
  43154. fnArray[i + 3] !== OPS.showText ||
  43155. fnArray[i + 4] !== OPS.endText) {
  43156. break; // ops don't match
  43157. }
  43158. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  43159. argsArray[i + 1][1] !== firstSetFontArg1) {
  43160. break; // fonts don't match
  43161. }
  43162. i += 5;
  43163. }
  43164. // At this point, i is the index of the first op past the last valid
  43165. // quintet.
  43166. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  43167. if (count < MIN_CHARS_IN_BLOCK) {
  43168. return i;
  43169. }
  43170. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  43171. // showText, endText), include that as well. (E.g. <something> might be
  43172. // |dependency|.)
  43173. var iFirst = iFirstBeginText;
  43174. if (iFirstBeginText >= 4 &&
  43175. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  43176. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  43177. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  43178. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  43179. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  43180. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  43181. count++;
  43182. iFirst -= 5;
  43183. }
  43184. // Remove (endText, beginText, setFont) trios.
  43185. var iEndText = iFirst + 4;
  43186. for (var q = 1; q < count; q++) {
  43187. fnArray.splice(iEndText, 3);
  43188. argsArray.splice(iEndText, 3);
  43189. iEndText += 2;
  43190. }
  43191. return iEndText + 1;
  43192. });
  43193. function QueueOptimizer() {}
  43194. QueueOptimizer.prototype = {
  43195. optimize: function QueueOptimizer_optimize(queue) {
  43196. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43197. var context = {
  43198. iCurr: 0,
  43199. fnArray: fnArray,
  43200. argsArray: argsArray
  43201. };
  43202. var state;
  43203. var i = 0, ii = fnArray.length;
  43204. while (i < ii) {
  43205. state = (state || InitialState)[fnArray[i]];
  43206. if (typeof state === 'function') { // we found some handler
  43207. context.iCurr = i;
  43208. // state() returns the index of the first non-matching op (if we
  43209. // didn't match) or the first op past the modified ops (if we did
  43210. // match and replace).
  43211. i = state(context);
  43212. state = undefined; // reset the state machine
  43213. ii = context.fnArray.length;
  43214. } else {
  43215. i++;
  43216. }
  43217. }
  43218. }
  43219. };
  43220. return QueueOptimizer;
  43221. })();
  43222. exports.OperatorList = OperatorList;
  43223. exports.PartialEvaluator = PartialEvaluator;
  43224. }));
  43225. (function (root, factory) {
  43226. {
  43227. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  43228. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  43229. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  43230. }
  43231. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  43232. coreColorSpace, coreObj, coreEvaluator) {
  43233. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  43234. var AnnotationFlag = sharedUtil.AnnotationFlag;
  43235. var AnnotationType = sharedUtil.AnnotationType;
  43236. var OPS = sharedUtil.OPS;
  43237. var Util = sharedUtil.Util;
  43238. var isArray = sharedUtil.isArray;
  43239. var isInt = sharedUtil.isInt;
  43240. var isValidUrl = sharedUtil.isValidUrl;
  43241. var stringToBytes = sharedUtil.stringToBytes;
  43242. var stringToPDFString = sharedUtil.stringToPDFString;
  43243. var stringToUTF8String = sharedUtil.stringToUTF8String;
  43244. var warn = sharedUtil.warn;
  43245. var Dict = corePrimitives.Dict;
  43246. var isDict = corePrimitives.isDict;
  43247. var isName = corePrimitives.isName;
  43248. var Stream = coreStream.Stream;
  43249. var ColorSpace = coreColorSpace.ColorSpace;
  43250. var ObjectLoader = coreObj.ObjectLoader;
  43251. var OperatorList = coreEvaluator.OperatorList;
  43252. /**
  43253. * @class
  43254. * @alias AnnotationFactory
  43255. */
  43256. function AnnotationFactory() {}
  43257. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  43258. /**
  43259. * @param {XRef} xref
  43260. * @param {Object} ref
  43261. * @returns {Annotation}
  43262. */
  43263. create: function AnnotationFactory_create(xref, ref) {
  43264. var dict = xref.fetchIfRef(ref);
  43265. if (!isDict(dict)) {
  43266. return;
  43267. }
  43268. // Determine the annotation's subtype.
  43269. var subtype = dict.get('Subtype');
  43270. subtype = isName(subtype) ? subtype.name : '';
  43271. // Return the right annotation object based on the subtype and field type.
  43272. var parameters = {
  43273. dict: dict,
  43274. ref: ref
  43275. };
  43276. switch (subtype) {
  43277. case 'Link':
  43278. return new LinkAnnotation(parameters);
  43279. case 'Text':
  43280. return new TextAnnotation(parameters);
  43281. case 'Widget':
  43282. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43283. if (isName(fieldType) && fieldType.name === 'Tx') {
  43284. return new TextWidgetAnnotation(parameters);
  43285. }
  43286. return new WidgetAnnotation(parameters);
  43287. case 'Popup':
  43288. return new PopupAnnotation(parameters);
  43289. default:
  43290. warn('Unimplemented annotation type "' + subtype + '", ' +
  43291. 'falling back to base annotation');
  43292. return new Annotation(parameters);
  43293. }
  43294. }
  43295. };
  43296. var Annotation = (function AnnotationClosure() {
  43297. // 12.5.5: Algorithm: Appearance streams
  43298. function getTransformMatrix(rect, bbox, matrix) {
  43299. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  43300. var minX = bounds[0];
  43301. var minY = bounds[1];
  43302. var maxX = bounds[2];
  43303. var maxY = bounds[3];
  43304. if (minX === maxX || minY === maxY) {
  43305. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  43306. // just apply the transform for rect
  43307. return [1, 0, 0, 1, rect[0], rect[1]];
  43308. }
  43309. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  43310. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  43311. return [
  43312. xRatio,
  43313. 0,
  43314. 0,
  43315. yRatio,
  43316. rect[0] - minX * xRatio,
  43317. rect[1] - minY * yRatio
  43318. ];
  43319. }
  43320. function getDefaultAppearance(dict) {
  43321. var appearanceState = dict.get('AP');
  43322. if (!isDict(appearanceState)) {
  43323. return;
  43324. }
  43325. var appearance;
  43326. var appearances = appearanceState.get('N');
  43327. if (isDict(appearances)) {
  43328. var as = dict.get('AS');
  43329. if (as && appearances.has(as.name)) {
  43330. appearance = appearances.get(as.name);
  43331. }
  43332. } else {
  43333. appearance = appearances;
  43334. }
  43335. return appearance;
  43336. }
  43337. function Annotation(params) {
  43338. var dict = params.dict;
  43339. this.setFlags(dict.get('F'));
  43340. this.setRectangle(dict.get('Rect'));
  43341. this.setColor(dict.get('C'));
  43342. this.setBorderStyle(dict);
  43343. this.appearance = getDefaultAppearance(dict);
  43344. // Expose public properties using a data object.
  43345. this.data = {};
  43346. this.data.id = params.ref.toString();
  43347. this.data.subtype = dict.get('Subtype').name;
  43348. this.data.annotationFlags = this.flags;
  43349. this.data.rect = this.rectangle;
  43350. this.data.color = this.color;
  43351. this.data.borderStyle = this.borderStyle;
  43352. this.data.hasAppearance = !!this.appearance;
  43353. }
  43354. Annotation.prototype = {
  43355. /**
  43356. * @return {boolean}
  43357. */
  43358. get viewable() {
  43359. if (this.flags) {
  43360. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43361. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  43362. !this.hasFlag(AnnotationFlag.NOVIEW);
  43363. }
  43364. return true;
  43365. },
  43366. /**
  43367. * @return {boolean}
  43368. */
  43369. get printable() {
  43370. if (this.flags) {
  43371. return this.hasFlag(AnnotationFlag.PRINT) &&
  43372. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43373. !this.hasFlag(AnnotationFlag.HIDDEN);
  43374. }
  43375. return false;
  43376. },
  43377. /**
  43378. * Set the flags.
  43379. *
  43380. * @public
  43381. * @memberof Annotation
  43382. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  43383. * characteristics
  43384. * @see {@link shared/util.js}
  43385. */
  43386. setFlags: function Annotation_setFlags(flags) {
  43387. if (isInt(flags)) {
  43388. this.flags = flags;
  43389. } else {
  43390. this.flags = 0;
  43391. }
  43392. },
  43393. /**
  43394. * Check if a provided flag is set.
  43395. *
  43396. * @public
  43397. * @memberof Annotation
  43398. * @param {number} flag - Hexadecimal representation for an annotation
  43399. * characteristic
  43400. * @return {boolean}
  43401. * @see {@link shared/util.js}
  43402. */
  43403. hasFlag: function Annotation_hasFlag(flag) {
  43404. if (this.flags) {
  43405. return (this.flags & flag) > 0;
  43406. }
  43407. return false;
  43408. },
  43409. /**
  43410. * Set the rectangle.
  43411. *
  43412. * @public
  43413. * @memberof Annotation
  43414. * @param {Array} rectangle - The rectangle array with exactly four entries
  43415. */
  43416. setRectangle: function Annotation_setRectangle(rectangle) {
  43417. if (isArray(rectangle) && rectangle.length === 4) {
  43418. this.rectangle = Util.normalizeRect(rectangle);
  43419. } else {
  43420. this.rectangle = [0, 0, 0, 0];
  43421. }
  43422. },
  43423. /**
  43424. * Set the color and take care of color space conversion.
  43425. *
  43426. * @public
  43427. * @memberof Annotation
  43428. * @param {Array} color - The color array containing either 0
  43429. * (transparent), 1 (grayscale), 3 (RGB) or
  43430. * 4 (CMYK) elements
  43431. */
  43432. setColor: function Annotation_setColor(color) {
  43433. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  43434. if (!isArray(color)) {
  43435. this.color = rgbColor;
  43436. return;
  43437. }
  43438. switch (color.length) {
  43439. case 0: // Transparent, which we indicate with a null value
  43440. this.color = null;
  43441. break;
  43442. case 1: // Convert grayscale to RGB
  43443. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  43444. this.color = rgbColor;
  43445. break;
  43446. case 3: // Convert RGB percentages to RGB
  43447. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  43448. this.color = rgbColor;
  43449. break;
  43450. case 4: // Convert CMYK to RGB
  43451. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  43452. this.color = rgbColor;
  43453. break;
  43454. default:
  43455. this.color = rgbColor;
  43456. break;
  43457. }
  43458. },
  43459. /**
  43460. * Set the border style (as AnnotationBorderStyle object).
  43461. *
  43462. * @public
  43463. * @memberof Annotation
  43464. * @param {Dict} borderStyle - The border style dictionary
  43465. */
  43466. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  43467. this.borderStyle = new AnnotationBorderStyle();
  43468. if (!isDict(borderStyle)) {
  43469. return;
  43470. }
  43471. if (borderStyle.has('BS')) {
  43472. var dict = borderStyle.get('BS');
  43473. var dictType;
  43474. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  43475. dictType.name === 'Border')) {
  43476. this.borderStyle.setWidth(dict.get('W'));
  43477. this.borderStyle.setStyle(dict.get('S'));
  43478. this.borderStyle.setDashArray(dict.get('D'));
  43479. }
  43480. } else if (borderStyle.has('Border')) {
  43481. var array = borderStyle.get('Border');
  43482. if (isArray(array) && array.length >= 3) {
  43483. this.borderStyle.setHorizontalCornerRadius(array[0]);
  43484. this.borderStyle.setVerticalCornerRadius(array[1]);
  43485. this.borderStyle.setWidth(array[2]);
  43486. if (array.length === 4) { // Dash array available
  43487. this.borderStyle.setDashArray(array[3]);
  43488. }
  43489. }
  43490. } else {
  43491. // There are no border entries in the dictionary. According to the
  43492. // specification, we should draw a solid border of width 1 in that
  43493. // case, but Adobe Reader did not implement that part of the
  43494. // specification and instead draws no border at all, so we do the same.
  43495. // See also https://github.com/mozilla/pdf.js/issues/6179.
  43496. this.borderStyle.setWidth(0);
  43497. }
  43498. },
  43499. loadResources: function Annotation_loadResources(keys) {
  43500. return new Promise(function (resolve, reject) {
  43501. this.appearance.dict.getAsync('Resources').then(function (resources) {
  43502. if (!resources) {
  43503. resolve();
  43504. return;
  43505. }
  43506. var objectLoader = new ObjectLoader(resources.map,
  43507. keys,
  43508. resources.xref);
  43509. objectLoader.load().then(function() {
  43510. resolve(resources);
  43511. }, reject);
  43512. }, reject);
  43513. }.bind(this));
  43514. },
  43515. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  43516. if (!this.appearance) {
  43517. return Promise.resolve(new OperatorList());
  43518. }
  43519. var data = this.data;
  43520. var appearanceDict = this.appearance.dict;
  43521. var resourcesPromise = this.loadResources([
  43522. 'ExtGState',
  43523. 'ColorSpace',
  43524. 'Pattern',
  43525. 'Shading',
  43526. 'XObject',
  43527. 'Font'
  43528. // ProcSet
  43529. // Properties
  43530. ]);
  43531. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  43532. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  43533. var transform = getTransformMatrix(data.rect, bbox, matrix);
  43534. var self = this;
  43535. return resourcesPromise.then(function(resources) {
  43536. var opList = new OperatorList();
  43537. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  43538. return evaluator.getOperatorList(self.appearance, task,
  43539. resources, opList).
  43540. then(function () {
  43541. opList.addOp(OPS.endAnnotation, []);
  43542. self.appearance.reset();
  43543. return opList;
  43544. });
  43545. });
  43546. }
  43547. };
  43548. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  43549. annotations, opList, partialEvaluator, task, intent) {
  43550. var annotationPromises = [];
  43551. for (var i = 0, n = annotations.length; i < n; ++i) {
  43552. if ((intent === 'display' && annotations[i].viewable) ||
  43553. (intent === 'print' && annotations[i].printable)) {
  43554. annotationPromises.push(
  43555. annotations[i].getOperatorList(partialEvaluator, task));
  43556. }
  43557. }
  43558. return Promise.all(annotationPromises).then(function(operatorLists) {
  43559. opList.addOp(OPS.beginAnnotations, []);
  43560. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  43561. opList.addOpList(operatorLists[i]);
  43562. }
  43563. opList.addOp(OPS.endAnnotations, []);
  43564. });
  43565. };
  43566. return Annotation;
  43567. })();
  43568. /**
  43569. * Contains all data regarding an annotation's border style.
  43570. *
  43571. * @class
  43572. */
  43573. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  43574. /**
  43575. * @constructor
  43576. * @private
  43577. */
  43578. function AnnotationBorderStyle() {
  43579. this.width = 1;
  43580. this.style = AnnotationBorderStyleType.SOLID;
  43581. this.dashArray = [3];
  43582. this.horizontalCornerRadius = 0;
  43583. this.verticalCornerRadius = 0;
  43584. }
  43585. AnnotationBorderStyle.prototype = {
  43586. /**
  43587. * Set the width.
  43588. *
  43589. * @public
  43590. * @memberof AnnotationBorderStyle
  43591. * @param {integer} width - The width
  43592. */
  43593. setWidth: function AnnotationBorderStyle_setWidth(width) {
  43594. if (width === (width | 0)) {
  43595. this.width = width;
  43596. }
  43597. },
  43598. /**
  43599. * Set the style.
  43600. *
  43601. * @public
  43602. * @memberof AnnotationBorderStyle
  43603. * @param {Object} style - The style object
  43604. * @see {@link shared/util.js}
  43605. */
  43606. setStyle: function AnnotationBorderStyle_setStyle(style) {
  43607. if (!style) {
  43608. return;
  43609. }
  43610. switch (style.name) {
  43611. case 'S':
  43612. this.style = AnnotationBorderStyleType.SOLID;
  43613. break;
  43614. case 'D':
  43615. this.style = AnnotationBorderStyleType.DASHED;
  43616. break;
  43617. case 'B':
  43618. this.style = AnnotationBorderStyleType.BEVELED;
  43619. break;
  43620. case 'I':
  43621. this.style = AnnotationBorderStyleType.INSET;
  43622. break;
  43623. case 'U':
  43624. this.style = AnnotationBorderStyleType.UNDERLINE;
  43625. break;
  43626. default:
  43627. break;
  43628. }
  43629. },
  43630. /**
  43631. * Set the dash array.
  43632. *
  43633. * @public
  43634. * @memberof AnnotationBorderStyle
  43635. * @param {Array} dashArray - The dash array with at least one element
  43636. */
  43637. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  43638. // We validate the dash array, but we do not use it because CSS does not
  43639. // allow us to change spacing of dashes. For more information, visit
  43640. // http://www.w3.org/TR/css3-background/#the-border-style.
  43641. if (isArray(dashArray) && dashArray.length > 0) {
  43642. // According to the PDF specification: the elements in a dashArray
  43643. // shall be numbers that are nonnegative and not all equal to zero.
  43644. var isValid = true;
  43645. var allZeros = true;
  43646. for (var i = 0, len = dashArray.length; i < len; i++) {
  43647. var element = dashArray[i];
  43648. var validNumber = (+element >= 0);
  43649. if (!validNumber) {
  43650. isValid = false;
  43651. break;
  43652. } else if (element > 0) {
  43653. allZeros = false;
  43654. }
  43655. }
  43656. if (isValid && !allZeros) {
  43657. this.dashArray = dashArray;
  43658. } else {
  43659. this.width = 0; // Adobe behavior when the array is invalid.
  43660. }
  43661. } else if (dashArray) {
  43662. this.width = 0; // Adobe behavior when the array is invalid.
  43663. }
  43664. },
  43665. /**
  43666. * Set the horizontal corner radius (from a Border dictionary).
  43667. *
  43668. * @public
  43669. * @memberof AnnotationBorderStyle
  43670. * @param {integer} radius - The horizontal corner radius
  43671. */
  43672. setHorizontalCornerRadius:
  43673. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  43674. if (radius === (radius | 0)) {
  43675. this.horizontalCornerRadius = radius;
  43676. }
  43677. },
  43678. /**
  43679. * Set the vertical corner radius (from a Border dictionary).
  43680. *
  43681. * @public
  43682. * @memberof AnnotationBorderStyle
  43683. * @param {integer} radius - The vertical corner radius
  43684. */
  43685. setVerticalCornerRadius:
  43686. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  43687. if (radius === (radius | 0)) {
  43688. this.verticalCornerRadius = radius;
  43689. }
  43690. }
  43691. };
  43692. return AnnotationBorderStyle;
  43693. })();
  43694. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  43695. function WidgetAnnotation(params) {
  43696. Annotation.call(this, params);
  43697. var dict = params.dict;
  43698. var data = this.data;
  43699. data.annotationType = AnnotationType.WIDGET;
  43700. data.fieldValue = stringToPDFString(
  43701. Util.getInheritableProperty(dict, 'V') || '');
  43702. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  43703. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  43704. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43705. data.fieldType = isName(fieldType) ? fieldType.name : '';
  43706. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  43707. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  43708. // Hide unsupported Widget signatures.
  43709. if (data.fieldType === 'Sig') {
  43710. warn('unimplemented annotation type: Widget signature');
  43711. this.setFlags(AnnotationFlag.HIDDEN);
  43712. }
  43713. // Building the full field name by collecting the field and
  43714. // its ancestors 'T' data and joining them using '.'.
  43715. var fieldName = [];
  43716. var namedItem = dict;
  43717. var ref = params.ref;
  43718. while (namedItem) {
  43719. var parent = namedItem.get('Parent');
  43720. var parentRef = namedItem.getRaw('Parent');
  43721. var name = namedItem.get('T');
  43722. if (name) {
  43723. fieldName.unshift(stringToPDFString(name));
  43724. } else if (parent && ref) {
  43725. // The field name is absent, that means more than one field
  43726. // with the same name may exist. Replacing the empty name
  43727. // with the '`' plus index in the parent's 'Kids' array.
  43728. // This is not in the PDF spec but necessary to id the
  43729. // the input controls.
  43730. var kids = parent.get('Kids');
  43731. var j, jj;
  43732. for (j = 0, jj = kids.length; j < jj; j++) {
  43733. var kidRef = kids[j];
  43734. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  43735. break;
  43736. }
  43737. }
  43738. fieldName.unshift('`' + j);
  43739. }
  43740. namedItem = parent;
  43741. ref = parentRef;
  43742. }
  43743. data.fullName = fieldName.join('.');
  43744. }
  43745. Util.inherit(WidgetAnnotation, Annotation, {});
  43746. return WidgetAnnotation;
  43747. })();
  43748. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  43749. function TextWidgetAnnotation(params) {
  43750. WidgetAnnotation.call(this, params);
  43751. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  43752. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  43753. }
  43754. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  43755. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  43756. task) {
  43757. if (this.appearance) {
  43758. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  43759. }
  43760. var opList = new OperatorList();
  43761. var data = this.data;
  43762. // Even if there is an appearance stream, ignore it. This is the
  43763. // behaviour used by Adobe Reader.
  43764. if (!data.defaultAppearance) {
  43765. return Promise.resolve(opList);
  43766. }
  43767. var stream = new Stream(stringToBytes(data.defaultAppearance));
  43768. return evaluator.getOperatorList(stream, task,
  43769. this.fieldResources, opList).
  43770. then(function () {
  43771. return opList;
  43772. });
  43773. }
  43774. });
  43775. return TextWidgetAnnotation;
  43776. })();
  43777. var TextAnnotation = (function TextAnnotationClosure() {
  43778. var DEFAULT_ICON_SIZE = 22; // px
  43779. function TextAnnotation(parameters) {
  43780. Annotation.call(this, parameters);
  43781. this.data.annotationType = AnnotationType.TEXT;
  43782. this.data.hasHtml = true;
  43783. var dict = parameters.dict;
  43784. if (this.data.hasAppearance) {
  43785. this.data.name = 'NoIcon';
  43786. } else {
  43787. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  43788. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  43789. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  43790. }
  43791. if (!dict.has('C')) {
  43792. // Fall back to the default background color.
  43793. this.data.color = null;
  43794. }
  43795. this.data.hasPopup = dict.has('Popup');
  43796. if (!this.data.hasPopup) {
  43797. // There is no associated Popup annotation, so the Text annotation
  43798. // must create its own popup.
  43799. this.data.title = stringToPDFString(dict.get('T') || '');
  43800. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  43801. this.data.hasHtml = (this.data.title || this.data.contents);
  43802. }
  43803. }
  43804. Util.inherit(TextAnnotation, Annotation, {});
  43805. return TextAnnotation;
  43806. })();
  43807. var LinkAnnotation = (function LinkAnnotationClosure() {
  43808. function LinkAnnotation(params) {
  43809. Annotation.call(this, params);
  43810. var dict = params.dict;
  43811. var data = this.data;
  43812. data.annotationType = AnnotationType.LINK;
  43813. data.hasHtml = true;
  43814. var action = dict.get('A');
  43815. if (action && isDict(action)) {
  43816. var linkType = action.get('S').name;
  43817. if (linkType === 'URI') {
  43818. var url = action.get('URI');
  43819. if (isName(url)) {
  43820. // Some bad PDFs do not put parentheses around relative URLs.
  43821. url = '/' + url.name;
  43822. } else if (url) {
  43823. url = addDefaultProtocolToUrl(url);
  43824. }
  43825. // TODO: pdf spec mentions urls can be relative to a Base
  43826. // entry in the dictionary.
  43827. if (!isValidUrl(url, false)) {
  43828. url = '';
  43829. }
  43830. // According to ISO 32000-1:2008, section 12.6.4.7,
  43831. // URI should to be encoded in 7-bit ASCII.
  43832. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  43833. try {
  43834. data.url = stringToUTF8String(url);
  43835. } catch (e) {
  43836. // Fall back to a simple copy.
  43837. data.url = url;
  43838. }
  43839. } else if (linkType === 'GoTo') {
  43840. data.dest = action.get('D');
  43841. } else if (linkType === 'GoToR') {
  43842. var urlDict = action.get('F');
  43843. if (isDict(urlDict)) {
  43844. // We assume that the 'url' is a Filspec dictionary
  43845. // and fetch the url without checking any further
  43846. url = urlDict.get('F') || '';
  43847. }
  43848. // TODO: pdf reference says that GoToR
  43849. // can also have 'NewWindow' attribute
  43850. if (!isValidUrl(url, false)) {
  43851. url = '';
  43852. }
  43853. data.url = url;
  43854. data.dest = action.get('D');
  43855. } else if (linkType === 'Named') {
  43856. data.action = action.get('N').name;
  43857. } else {
  43858. warn('unrecognized link type: ' + linkType);
  43859. }
  43860. } else if (dict.has('Dest')) {
  43861. // simple destination link
  43862. var dest = dict.get('Dest');
  43863. data.dest = isName(dest) ? dest.name : dest;
  43864. }
  43865. }
  43866. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  43867. function addDefaultProtocolToUrl(url) {
  43868. if (url && url.indexOf('www.') === 0) {
  43869. return ('http://' + url);
  43870. }
  43871. return url;
  43872. }
  43873. Util.inherit(LinkAnnotation, Annotation, {});
  43874. return LinkAnnotation;
  43875. })();
  43876. var PopupAnnotation = (function PopupAnnotationClosure() {
  43877. function PopupAnnotation(parameters) {
  43878. Annotation.call(this, parameters);
  43879. this.data.annotationType = AnnotationType.POPUP;
  43880. var dict = parameters.dict;
  43881. var parentItem = dict.get('Parent');
  43882. if (!parentItem) {
  43883. warn('Popup annotation has a missing or invalid parent annotation.');
  43884. return;
  43885. }
  43886. this.data.parentId = dict.getRaw('Parent').toString();
  43887. this.data.title = stringToPDFString(parentItem.get('T') || '');
  43888. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  43889. if (!parentItem.has('C')) {
  43890. // Fall back to the default background color.
  43891. this.data.color = null;
  43892. } else {
  43893. this.setColor(parentItem.get('C'));
  43894. this.data.color = this.color;
  43895. }
  43896. this.data.hasHtml = (this.data.title || this.data.contents);
  43897. }
  43898. Util.inherit(PopupAnnotation, Annotation, {});
  43899. return PopupAnnotation;
  43900. })();
  43901. exports.Annotation = Annotation;
  43902. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  43903. exports.AnnotationFactory = AnnotationFactory;
  43904. }));
  43905. (function (root, factory) {
  43906. {
  43907. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  43908. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  43909. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  43910. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  43911. }
  43912. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  43913. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  43914. var MissingDataException = sharedUtil.MissingDataException;
  43915. var Util = sharedUtil.Util;
  43916. var assert = sharedUtil.assert;
  43917. var error = sharedUtil.error;
  43918. var info = sharedUtil.info;
  43919. var isArray = sharedUtil.isArray;
  43920. var isArrayBuffer = sharedUtil.isArrayBuffer;
  43921. var isString = sharedUtil.isString;
  43922. var shadow = sharedUtil.shadow;
  43923. var stringToBytes = sharedUtil.stringToBytes;
  43924. var stringToPDFString = sharedUtil.stringToPDFString;
  43925. var warn = sharedUtil.warn;
  43926. var Dict = corePrimitives.Dict;
  43927. var isDict = corePrimitives.isDict;
  43928. var isName = corePrimitives.isName;
  43929. var isStream = corePrimitives.isStream;
  43930. var NullStream = coreStream.NullStream;
  43931. var Stream = coreStream.Stream;
  43932. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  43933. var Catalog = coreObj.Catalog;
  43934. var ObjectLoader = coreObj.ObjectLoader;
  43935. var XRef = coreObj.XRef;
  43936. var Lexer = coreParser.Lexer;
  43937. var Linearization = coreParser.Linearization;
  43938. var calculateMD5 = coreCrypto.calculateMD5;
  43939. var OperatorList = coreEvaluator.OperatorList;
  43940. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  43941. var Annotation = coreAnnotation.Annotation;
  43942. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  43943. var Page = (function PageClosure() {
  43944. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  43945. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  43946. this.pdfManager = pdfManager;
  43947. this.pageIndex = pageIndex;
  43948. this.pageDict = pageDict;
  43949. this.xref = xref;
  43950. this.ref = ref;
  43951. this.fontCache = fontCache;
  43952. this.idCounters = {
  43953. obj: 0
  43954. };
  43955. this.resourcesPromise = null;
  43956. }
  43957. Page.prototype = {
  43958. getPageProp: function Page_getPageProp(key) {
  43959. return this.pageDict.get(key);
  43960. },
  43961. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  43962. var dict = this.pageDict, valueArray = null, loopCount = 0;
  43963. var MAX_LOOP_COUNT = 100;
  43964. // Always walk up the entire parent chain, to be able to find
  43965. // e.g. \Resources placed on multiple levels of the tree.
  43966. while (dict) {
  43967. var value = dict.get(key);
  43968. if (value) {
  43969. if (!valueArray) {
  43970. valueArray = [];
  43971. }
  43972. valueArray.push(value);
  43973. }
  43974. if (++loopCount > MAX_LOOP_COUNT) {
  43975. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  43976. break;
  43977. }
  43978. dict = dict.get('Parent');
  43979. }
  43980. if (!valueArray) {
  43981. return Dict.empty;
  43982. }
  43983. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  43984. loopCount > MAX_LOOP_COUNT) {
  43985. return valueArray[0];
  43986. }
  43987. return Dict.merge(this.xref, valueArray);
  43988. },
  43989. get content() {
  43990. return this.getPageProp('Contents');
  43991. },
  43992. get resources() {
  43993. // For robustness: The spec states that a \Resources entry has to be
  43994. // present, but can be empty. Some document omit it still, in this case
  43995. // we return an empty dictionary.
  43996. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  43997. },
  43998. get mediaBox() {
  43999. var obj = this.getInheritedPageProp('MediaBox');
  44000. // Reset invalid media box to letter size.
  44001. if (!isArray(obj) || obj.length !== 4) {
  44002. obj = LETTER_SIZE_MEDIABOX;
  44003. }
  44004. return shadow(this, 'mediaBox', obj);
  44005. },
  44006. get view() {
  44007. var mediaBox = this.mediaBox;
  44008. var cropBox = this.getInheritedPageProp('CropBox');
  44009. if (!isArray(cropBox) || cropBox.length !== 4) {
  44010. return shadow(this, 'view', mediaBox);
  44011. }
  44012. // From the spec, 6th ed., p.963:
  44013. // "The crop, bleed, trim, and art boxes should not ordinarily
  44014. // extend beyond the boundaries of the media box. If they do, they are
  44015. // effectively reduced to their intersection with the media box."
  44016. cropBox = Util.intersect(cropBox, mediaBox);
  44017. if (!cropBox) {
  44018. return shadow(this, 'view', mediaBox);
  44019. }
  44020. return shadow(this, 'view', cropBox);
  44021. },
  44022. get rotate() {
  44023. var rotate = this.getInheritedPageProp('Rotate') || 0;
  44024. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  44025. if (rotate % 90 !== 0) {
  44026. rotate = 0;
  44027. } else if (rotate >= 360) {
  44028. rotate = rotate % 360;
  44029. } else if (rotate < 0) {
  44030. // The spec doesn't cover negatives, assume its counterclockwise
  44031. // rotation. The following is the other implementation of modulo.
  44032. rotate = ((rotate % 360) + 360) % 360;
  44033. }
  44034. return shadow(this, 'rotate', rotate);
  44035. },
  44036. getContentStream: function Page_getContentStream() {
  44037. var content = this.content;
  44038. var stream;
  44039. if (isArray(content)) {
  44040. // fetching items
  44041. var xref = this.xref;
  44042. var i, n = content.length;
  44043. var streams = [];
  44044. for (i = 0; i < n; ++i) {
  44045. streams.push(xref.fetchIfRef(content[i]));
  44046. }
  44047. stream = new StreamsSequenceStream(streams);
  44048. } else if (isStream(content)) {
  44049. stream = content;
  44050. } else {
  44051. // replacing non-existent page content with empty one
  44052. stream = new NullStream();
  44053. }
  44054. return stream;
  44055. },
  44056. loadResources: function Page_loadResources(keys) {
  44057. if (!this.resourcesPromise) {
  44058. // TODO: add async getInheritedPageProp and remove this.
  44059. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  44060. }
  44061. return this.resourcesPromise.then(function resourceSuccess() {
  44062. var objectLoader = new ObjectLoader(this.resources.map,
  44063. keys,
  44064. this.xref);
  44065. return objectLoader.load();
  44066. }.bind(this));
  44067. },
  44068. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  44069. var self = this;
  44070. var pdfManager = this.pdfManager;
  44071. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  44072. []);
  44073. var resourcesPromise = this.loadResources([
  44074. 'ExtGState',
  44075. 'ColorSpace',
  44076. 'Pattern',
  44077. 'Shading',
  44078. 'XObject',
  44079. 'Font'
  44080. // ProcSet
  44081. // Properties
  44082. ]);
  44083. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  44084. handler, this.pageIndex,
  44085. 'p' + this.pageIndex + '_',
  44086. this.idCounters,
  44087. this.fontCache);
  44088. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  44089. var pageListPromise = dataPromises.then(function(data) {
  44090. var contentStream = data[0];
  44091. var opList = new OperatorList(intent, handler, self.pageIndex);
  44092. handler.send('StartRenderPage', {
  44093. transparency: partialEvaluator.hasBlendModes(self.resources),
  44094. pageIndex: self.pageIndex,
  44095. intent: intent
  44096. });
  44097. return partialEvaluator.getOperatorList(contentStream, task,
  44098. self.resources, opList).then(function () {
  44099. return opList;
  44100. });
  44101. });
  44102. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  44103. return Promise.all([pageListPromise, annotationsPromise]).then(
  44104. function(datas) {
  44105. var pageOpList = datas[0];
  44106. var annotations = datas[1];
  44107. if (annotations.length === 0) {
  44108. pageOpList.flush(true);
  44109. return pageOpList;
  44110. }
  44111. var annotationsReadyPromise = Annotation.appendToOperatorList(
  44112. annotations, pageOpList, partialEvaluator, task, intent);
  44113. return annotationsReadyPromise.then(function () {
  44114. pageOpList.flush(true);
  44115. return pageOpList;
  44116. });
  44117. });
  44118. },
  44119. extractTextContent: function Page_extractTextContent(task,
  44120. normalizeWhitespace) {
  44121. var handler = {
  44122. on: function nullHandlerOn() {},
  44123. send: function nullHandlerSend() {}
  44124. };
  44125. var self = this;
  44126. var pdfManager = this.pdfManager;
  44127. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  44128. []);
  44129. var resourcesPromise = this.loadResources([
  44130. 'ExtGState',
  44131. 'XObject',
  44132. 'Font'
  44133. ]);
  44134. var dataPromises = Promise.all([contentStreamPromise,
  44135. resourcesPromise]);
  44136. return dataPromises.then(function(data) {
  44137. var contentStream = data[0];
  44138. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  44139. handler, self.pageIndex,
  44140. 'p' + self.pageIndex + '_',
  44141. self.idCounters,
  44142. self.fontCache);
  44143. return partialEvaluator.getTextContent(contentStream,
  44144. task,
  44145. self.resources,
  44146. /* stateManager = */ null,
  44147. normalizeWhitespace);
  44148. });
  44149. },
  44150. getAnnotationsData: function Page_getAnnotationsData(intent) {
  44151. var annotations = this.annotations;
  44152. var annotationsData = [];
  44153. for (var i = 0, n = annotations.length; i < n; ++i) {
  44154. if (intent) {
  44155. if (!(intent === 'display' && annotations[i].viewable) &&
  44156. !(intent === 'print' && annotations[i].printable)) {
  44157. continue;
  44158. }
  44159. }
  44160. annotationsData.push(annotations[i].data);
  44161. }
  44162. return annotationsData;
  44163. },
  44164. get annotations() {
  44165. var annotations = [];
  44166. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  44167. var annotationFactory = new AnnotationFactory();
  44168. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  44169. var annotationRef = annotationRefs[i];
  44170. var annotation = annotationFactory.create(this.xref, annotationRef);
  44171. if (annotation) {
  44172. annotations.push(annotation);
  44173. }
  44174. }
  44175. return shadow(this, 'annotations', annotations);
  44176. }
  44177. };
  44178. return Page;
  44179. })();
  44180. /**
  44181. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  44182. * `PDFDoc`, this one doesn't have any job management code.
  44183. * Right now there exists one PDFDocument on the main thread + one object
  44184. * for each worker. If there is no worker support enabled, there are two
  44185. * `PDFDocument` objects on the main thread created.
  44186. */
  44187. var PDFDocument = (function PDFDocumentClosure() {
  44188. var FINGERPRINT_FIRST_BYTES = 1024;
  44189. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  44190. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  44191. function PDFDocument(pdfManager, arg, password) {
  44192. if (isStream(arg)) {
  44193. init.call(this, pdfManager, arg, password);
  44194. } else if (isArrayBuffer(arg)) {
  44195. init.call(this, pdfManager, new Stream(arg), password);
  44196. } else {
  44197. error('PDFDocument: Unknown argument type');
  44198. }
  44199. }
  44200. function init(pdfManager, stream, password) {
  44201. assert(stream.length > 0, 'stream must have data');
  44202. this.pdfManager = pdfManager;
  44203. this.stream = stream;
  44204. var xref = new XRef(this.stream, password, pdfManager);
  44205. this.xref = xref;
  44206. }
  44207. function find(stream, needle, limit, backwards) {
  44208. var pos = stream.pos;
  44209. var end = stream.end;
  44210. var strBuf = [];
  44211. if (pos + limit > end) {
  44212. limit = end - pos;
  44213. }
  44214. for (var n = 0; n < limit; ++n) {
  44215. strBuf.push(String.fromCharCode(stream.getByte()));
  44216. }
  44217. var str = strBuf.join('');
  44218. stream.pos = pos;
  44219. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  44220. if (index === -1) {
  44221. return false; /* not found */
  44222. }
  44223. stream.pos += index;
  44224. return true; /* found */
  44225. }
  44226. var DocumentInfoValidators = {
  44227. get entries() {
  44228. // Lazily build this since all the validation functions below are not
  44229. // defined until after this file loads.
  44230. return shadow(this, 'entries', {
  44231. Title: isString,
  44232. Author: isString,
  44233. Subject: isString,
  44234. Keywords: isString,
  44235. Creator: isString,
  44236. Producer: isString,
  44237. CreationDate: isString,
  44238. ModDate: isString,
  44239. Trapped: isName
  44240. });
  44241. }
  44242. };
  44243. PDFDocument.prototype = {
  44244. parse: function PDFDocument_parse(recoveryMode) {
  44245. this.setup(recoveryMode);
  44246. var version = this.catalog.catDict.get('Version');
  44247. if (isName(version)) {
  44248. this.pdfFormatVersion = version.name;
  44249. }
  44250. try {
  44251. // checking if AcroForm is present
  44252. this.acroForm = this.catalog.catDict.get('AcroForm');
  44253. if (this.acroForm) {
  44254. this.xfa = this.acroForm.get('XFA');
  44255. var fields = this.acroForm.get('Fields');
  44256. if ((!fields || !isArray(fields) || fields.length === 0) &&
  44257. !this.xfa) {
  44258. // no fields and no XFA -- not a form (?)
  44259. this.acroForm = null;
  44260. }
  44261. }
  44262. } catch (ex) {
  44263. info('Something wrong with AcroForm entry');
  44264. this.acroForm = null;
  44265. }
  44266. },
  44267. get linearization() {
  44268. var linearization = null;
  44269. if (this.stream.length) {
  44270. try {
  44271. linearization = Linearization.create(this.stream);
  44272. } catch (err) {
  44273. if (err instanceof MissingDataException) {
  44274. throw err;
  44275. }
  44276. info(err);
  44277. }
  44278. }
  44279. // shadow the prototype getter with a data property
  44280. return shadow(this, 'linearization', linearization);
  44281. },
  44282. get startXRef() {
  44283. var stream = this.stream;
  44284. var startXRef = 0;
  44285. var linearization = this.linearization;
  44286. if (linearization) {
  44287. // Find end of first obj.
  44288. stream.reset();
  44289. if (find(stream, 'endobj', 1024)) {
  44290. startXRef = stream.pos + 6;
  44291. }
  44292. } else {
  44293. // Find startxref by jumping backward from the end of the file.
  44294. var step = 1024;
  44295. var found = false, pos = stream.end;
  44296. while (!found && pos > 0) {
  44297. pos -= step - 'startxref'.length;
  44298. if (pos < 0) {
  44299. pos = 0;
  44300. }
  44301. stream.pos = pos;
  44302. found = find(stream, 'startxref', step, true);
  44303. }
  44304. if (found) {
  44305. stream.skip(9);
  44306. var ch;
  44307. do {
  44308. ch = stream.getByte();
  44309. } while (Lexer.isSpace(ch));
  44310. var str = '';
  44311. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  44312. str += String.fromCharCode(ch);
  44313. ch = stream.getByte();
  44314. }
  44315. startXRef = parseInt(str, 10);
  44316. if (isNaN(startXRef)) {
  44317. startXRef = 0;
  44318. }
  44319. }
  44320. }
  44321. // shadow the prototype getter with a data property
  44322. return shadow(this, 'startXRef', startXRef);
  44323. },
  44324. get mainXRefEntriesOffset() {
  44325. var mainXRefEntriesOffset = 0;
  44326. var linearization = this.linearization;
  44327. if (linearization) {
  44328. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  44329. }
  44330. // shadow the prototype getter with a data property
  44331. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  44332. },
  44333. // Find the header, remove leading garbage and setup the stream
  44334. // starting from the header.
  44335. checkHeader: function PDFDocument_checkHeader() {
  44336. var stream = this.stream;
  44337. stream.reset();
  44338. if (find(stream, '%PDF-', 1024)) {
  44339. // Found the header, trim off any garbage before it.
  44340. stream.moveStart();
  44341. // Reading file format version
  44342. var MAX_VERSION_LENGTH = 12;
  44343. var version = '', ch;
  44344. while ((ch = stream.getByte()) > 0x20) { // SPACE
  44345. if (version.length >= MAX_VERSION_LENGTH) {
  44346. break;
  44347. }
  44348. version += String.fromCharCode(ch);
  44349. }
  44350. if (!this.pdfFormatVersion) {
  44351. // removing "%PDF-"-prefix
  44352. this.pdfFormatVersion = version.substring(5);
  44353. }
  44354. return;
  44355. }
  44356. // May not be a PDF file, continue anyway.
  44357. },
  44358. parseStartXRef: function PDFDocument_parseStartXRef() {
  44359. var startXRef = this.startXRef;
  44360. this.xref.setStartXRef(startXRef);
  44361. },
  44362. setup: function PDFDocument_setup(recoveryMode) {
  44363. this.xref.parse(recoveryMode);
  44364. var self = this;
  44365. var pageFactory = {
  44366. createPage: function (pageIndex, dict, ref, fontCache) {
  44367. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  44368. fontCache);
  44369. }
  44370. };
  44371. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  44372. },
  44373. get numPages() {
  44374. var linearization = this.linearization;
  44375. var num = linearization ? linearization.numPages : this.catalog.numPages;
  44376. // shadow the prototype getter
  44377. return shadow(this, 'numPages', num);
  44378. },
  44379. get documentInfo() {
  44380. var docInfo = {
  44381. PDFFormatVersion: this.pdfFormatVersion,
  44382. IsAcroFormPresent: !!this.acroForm,
  44383. IsXFAPresent: !!this.xfa
  44384. };
  44385. var infoDict;
  44386. try {
  44387. infoDict = this.xref.trailer.get('Info');
  44388. } catch (err) {
  44389. info('The document information dictionary is invalid.');
  44390. }
  44391. if (infoDict) {
  44392. var validEntries = DocumentInfoValidators.entries;
  44393. // Only fill the document info with valid entries from the spec.
  44394. for (var key in validEntries) {
  44395. if (infoDict.has(key)) {
  44396. var value = infoDict.get(key);
  44397. // Make sure the value conforms to the spec.
  44398. if (validEntries[key](value)) {
  44399. docInfo[key] = (typeof value !== 'string' ?
  44400. value : stringToPDFString(value));
  44401. } else {
  44402. info('Bad value in document info for "' + key + '"');
  44403. }
  44404. }
  44405. }
  44406. }
  44407. return shadow(this, 'documentInfo', docInfo);
  44408. },
  44409. get fingerprint() {
  44410. var xref = this.xref, hash, fileID = '';
  44411. var idArray = xref.trailer.get('ID');
  44412. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  44413. idArray[0] !== EMPTY_FINGERPRINT) {
  44414. hash = stringToBytes(idArray[0]);
  44415. } else {
  44416. if (this.stream.ensureRange) {
  44417. this.stream.ensureRange(0,
  44418. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  44419. }
  44420. hash = calculateMD5(this.stream.bytes.subarray(0,
  44421. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  44422. }
  44423. for (var i = 0, n = hash.length; i < n; i++) {
  44424. var hex = hash[i].toString(16);
  44425. fileID += hex.length === 1 ? '0' + hex : hex;
  44426. }
  44427. return shadow(this, 'fingerprint', fileID);
  44428. },
  44429. getPage: function PDFDocument_getPage(pageIndex) {
  44430. return this.catalog.getPage(pageIndex);
  44431. },
  44432. cleanup: function PDFDocument_cleanup() {
  44433. return this.catalog.cleanup();
  44434. }
  44435. };
  44436. return PDFDocument;
  44437. })();
  44438. exports.Page = Page;
  44439. exports.PDFDocument = PDFDocument;
  44440. }));
  44441. (function (root, factory) {
  44442. {
  44443. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  44444. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  44445. root.pdfjsCoreDocument);
  44446. }
  44447. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  44448. coreDocument) {
  44449. var NotImplementedException = sharedUtil.NotImplementedException;
  44450. var MissingDataException = sharedUtil.MissingDataException;
  44451. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44452. var Util = sharedUtil.Util;
  44453. var Stream = coreStream.Stream;
  44454. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  44455. var PDFDocument = coreDocument.PDFDocument;
  44456. var BasePdfManager = (function BasePdfManagerClosure() {
  44457. function BasePdfManager() {
  44458. throw new Error('Cannot initialize BaseManagerManager');
  44459. }
  44460. BasePdfManager.prototype = {
  44461. get docId() {
  44462. return this._docId;
  44463. },
  44464. onLoadedStream: function BasePdfManager_onLoadedStream() {
  44465. throw new NotImplementedException();
  44466. },
  44467. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  44468. return this.ensure(this.pdfDocument, prop, args);
  44469. },
  44470. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  44471. return this.ensure(this.pdfDocument.xref, prop, args);
  44472. },
  44473. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  44474. return this.ensure(this.pdfDocument.catalog, prop, args);
  44475. },
  44476. getPage: function BasePdfManager_getPage(pageIndex) {
  44477. return this.pdfDocument.getPage(pageIndex);
  44478. },
  44479. cleanup: function BasePdfManager_cleanup() {
  44480. return this.pdfDocument.cleanup();
  44481. },
  44482. ensure: function BasePdfManager_ensure(obj, prop, args) {
  44483. return new NotImplementedException();
  44484. },
  44485. requestRange: function BasePdfManager_requestRange(begin, end) {
  44486. return new NotImplementedException();
  44487. },
  44488. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  44489. return new NotImplementedException();
  44490. },
  44491. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  44492. return new NotImplementedException();
  44493. },
  44494. updatePassword: function BasePdfManager_updatePassword(password) {
  44495. this.pdfDocument.xref.password = this.password = password;
  44496. if (this._passwordChangedCapability) {
  44497. this._passwordChangedCapability.resolve();
  44498. }
  44499. },
  44500. passwordChanged: function BasePdfManager_passwordChanged() {
  44501. this._passwordChangedCapability = createPromiseCapability();
  44502. return this._passwordChangedCapability.promise;
  44503. },
  44504. terminate: function BasePdfManager_terminate() {
  44505. return new NotImplementedException();
  44506. }
  44507. };
  44508. return BasePdfManager;
  44509. })();
  44510. var LocalPdfManager = (function LocalPdfManagerClosure() {
  44511. function LocalPdfManager(docId, data, password) {
  44512. this._docId = docId;
  44513. var stream = new Stream(data);
  44514. this.pdfDocument = new PDFDocument(this, stream, password);
  44515. this._loadedStreamCapability = createPromiseCapability();
  44516. this._loadedStreamCapability.resolve(stream);
  44517. }
  44518. Util.inherit(LocalPdfManager, BasePdfManager, {
  44519. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  44520. return new Promise(function (resolve, reject) {
  44521. try {
  44522. var value = obj[prop];
  44523. var result;
  44524. if (typeof value === 'function') {
  44525. result = value.apply(obj, args);
  44526. } else {
  44527. result = value;
  44528. }
  44529. resolve(result);
  44530. } catch (e) {
  44531. reject(e);
  44532. }
  44533. });
  44534. },
  44535. requestRange: function LocalPdfManager_requestRange(begin, end) {
  44536. return Promise.resolve();
  44537. },
  44538. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  44539. return;
  44540. },
  44541. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  44542. return this._loadedStreamCapability.promise;
  44543. },
  44544. terminate: function LocalPdfManager_terminate() {
  44545. return;
  44546. }
  44547. });
  44548. return LocalPdfManager;
  44549. })();
  44550. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  44551. function NetworkPdfManager(docId, args, msgHandler) {
  44552. this._docId = docId;
  44553. this.msgHandler = msgHandler;
  44554. var params = {
  44555. msgHandler: msgHandler,
  44556. httpHeaders: args.httpHeaders,
  44557. withCredentials: args.withCredentials,
  44558. chunkedViewerLoading: args.chunkedViewerLoading,
  44559. disableAutoFetch: args.disableAutoFetch,
  44560. initialData: args.initialData
  44561. };
  44562. this.streamManager = new ChunkedStreamManager(args.length,
  44563. args.rangeChunkSize,
  44564. args.url, params);
  44565. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  44566. args.password);
  44567. }
  44568. Util.inherit(NetworkPdfManager, BasePdfManager, {
  44569. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  44570. var pdfManager = this;
  44571. return new Promise(function (resolve, reject) {
  44572. function ensureHelper() {
  44573. try {
  44574. var result;
  44575. var value = obj[prop];
  44576. if (typeof value === 'function') {
  44577. result = value.apply(obj, args);
  44578. } else {
  44579. result = value;
  44580. }
  44581. resolve(result);
  44582. } catch(e) {
  44583. if (!(e instanceof MissingDataException)) {
  44584. reject(e);
  44585. return;
  44586. }
  44587. pdfManager.streamManager.requestRange(e.begin, e.end).
  44588. then(ensureHelper, reject);
  44589. }
  44590. }
  44591. ensureHelper();
  44592. });
  44593. },
  44594. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  44595. return this.streamManager.requestRange(begin, end);
  44596. },
  44597. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  44598. this.streamManager.requestAllChunks();
  44599. },
  44600. sendProgressiveData:
  44601. function NetworkPdfManager_sendProgressiveData(chunk) {
  44602. this.streamManager.onReceiveData({ chunk: chunk });
  44603. },
  44604. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  44605. return this.streamManager.onLoadedStream();
  44606. },
  44607. terminate: function NetworkPdfManager_terminate() {
  44608. this.streamManager.abort();
  44609. }
  44610. });
  44611. return NetworkPdfManager;
  44612. })();
  44613. exports.LocalPdfManager = LocalPdfManager;
  44614. exports.NetworkPdfManager = NetworkPdfManager;
  44615. }));
  44616. (function (root, factory) {
  44617. {
  44618. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  44619. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  44620. root.pdfjsSharedGlobal);
  44621. }
  44622. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  44623. sharedGlobal) {
  44624. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  44625. var InvalidPDFException = sharedUtil.InvalidPDFException;
  44626. var MessageHandler = sharedUtil.MessageHandler;
  44627. var MissingPDFException = sharedUtil.MissingPDFException;
  44628. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  44629. var PasswordException = sharedUtil.PasswordException;
  44630. var PasswordResponses = sharedUtil.PasswordResponses;
  44631. var UnknownErrorException = sharedUtil.UnknownErrorException;
  44632. var XRefParseException = sharedUtil.XRefParseException;
  44633. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44634. var error = sharedUtil.error;
  44635. var info = sharedUtil.info;
  44636. var isInt = sharedUtil.isInt;
  44637. var warn = sharedUtil.warn;
  44638. var Ref = corePrimitives.Ref;
  44639. var LocalPdfManager = corePdfManager.LocalPdfManager;
  44640. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  44641. var globalScope = sharedGlobal.globalScope;
  44642. var PDFJS = sharedGlobal.PDFJS;
  44643. var WorkerTask = (function WorkerTaskClosure() {
  44644. function WorkerTask(name) {
  44645. this.name = name;
  44646. this.terminated = false;
  44647. this._capability = createPromiseCapability();
  44648. }
  44649. WorkerTask.prototype = {
  44650. get finished() {
  44651. return this._capability.promise;
  44652. },
  44653. finish: function () {
  44654. this._capability.resolve();
  44655. },
  44656. terminate: function () {
  44657. this.terminated = true;
  44658. },
  44659. ensureNotTerminated: function () {
  44660. if (this.terminated) {
  44661. throw new Error('Worker task was terminated');
  44662. }
  44663. }
  44664. };
  44665. return WorkerTask;
  44666. })();
  44667. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  44668. setup: function wphSetup(handler, port) {
  44669. handler.on('test', function wphSetupTest(data) {
  44670. // check if Uint8Array can be sent to worker
  44671. if (!(data instanceof Uint8Array)) {
  44672. handler.send('test', 'main', false);
  44673. return;
  44674. }
  44675. // making sure postMessage transfers are working
  44676. var supportTransfers = data[0] === 255;
  44677. handler.postMessageTransfers = supportTransfers;
  44678. // check if the response property is supported by xhr
  44679. var xhr = new XMLHttpRequest();
  44680. var responseExists = 'response' in xhr;
  44681. // check if the property is actually implemented
  44682. try {
  44683. var dummy = xhr.responseType;
  44684. } catch (e) {
  44685. responseExists = false;
  44686. }
  44687. if (!responseExists) {
  44688. handler.send('test', false);
  44689. return;
  44690. }
  44691. handler.send('test', {
  44692. supportTypedArray: true,
  44693. supportTransfers: supportTransfers
  44694. });
  44695. });
  44696. handler.on('GetDocRequest', function wphSetupDoc(data) {
  44697. return WorkerMessageHandler.createDocumentHandler(data, port);
  44698. });
  44699. },
  44700. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  44701. // This context is actually holds references on pdfManager and handler,
  44702. // until the latter is destroyed.
  44703. var pdfManager;
  44704. var terminated = false;
  44705. var cancelXHRs = null;
  44706. var WorkerTasks = [];
  44707. var docId = docParams.docId;
  44708. var workerHandlerName = docParams.docId + '_worker';
  44709. var handler = new MessageHandler(workerHandlerName, docId, port);
  44710. function ensureNotTerminated() {
  44711. if (terminated) {
  44712. throw new Error('Worker was terminated');
  44713. }
  44714. }
  44715. function startWorkerTask(task) {
  44716. WorkerTasks.push(task);
  44717. }
  44718. function finishWorkerTask(task) {
  44719. task.finish();
  44720. var i = WorkerTasks.indexOf(task);
  44721. WorkerTasks.splice(i, 1);
  44722. }
  44723. function loadDocument(recoveryMode) {
  44724. var loadDocumentCapability = createPromiseCapability();
  44725. var parseSuccess = function parseSuccess() {
  44726. var numPagesPromise = pdfManager.ensureDoc('numPages');
  44727. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  44728. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  44729. Promise.all([numPagesPromise, fingerprintPromise,
  44730. encryptedPromise]).then(function onDocReady(results) {
  44731. var doc = {
  44732. numPages: results[0],
  44733. fingerprint: results[1],
  44734. encrypted: !!results[2],
  44735. };
  44736. loadDocumentCapability.resolve(doc);
  44737. },
  44738. parseFailure);
  44739. };
  44740. var parseFailure = function parseFailure(e) {
  44741. loadDocumentCapability.reject(e);
  44742. };
  44743. pdfManager.ensureDoc('checkHeader', []).then(function() {
  44744. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  44745. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  44746. parseSuccess, parseFailure);
  44747. }, parseFailure);
  44748. }, parseFailure);
  44749. return loadDocumentCapability.promise;
  44750. }
  44751. function getPdfManager(data) {
  44752. var pdfManagerCapability = createPromiseCapability();
  44753. var pdfManager;
  44754. var source = data.source;
  44755. var disableRange = data.disableRange;
  44756. if (source.data) {
  44757. try {
  44758. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  44759. pdfManagerCapability.resolve(pdfManager);
  44760. } catch (ex) {
  44761. pdfManagerCapability.reject(ex);
  44762. }
  44763. return pdfManagerCapability.promise;
  44764. } else if (source.chunkedViewerLoading) {
  44765. try {
  44766. pdfManager = new NetworkPdfManager(docId, source, handler);
  44767. pdfManagerCapability.resolve(pdfManager);
  44768. } catch (ex) {
  44769. pdfManagerCapability.reject(ex);
  44770. }
  44771. return pdfManagerCapability.promise;
  44772. }
  44773. var networkManager = new NetworkManager(source.url, {
  44774. httpHeaders: source.httpHeaders,
  44775. withCredentials: source.withCredentials
  44776. });
  44777. var cachedChunks = [];
  44778. var fullRequestXhrId = networkManager.requestFull({
  44779. onHeadersReceived: function onHeadersReceived() {
  44780. if (disableRange) {
  44781. return;
  44782. }
  44783. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  44784. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  44785. return;
  44786. }
  44787. var contentEncoding =
  44788. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  44789. if (contentEncoding !== 'identity') {
  44790. return;
  44791. }
  44792. var length = fullRequestXhr.getResponseHeader('Content-Length');
  44793. length = parseInt(length, 10);
  44794. if (!isInt(length)) {
  44795. return;
  44796. }
  44797. source.length = length;
  44798. if (length <= 2 * source.rangeChunkSize) {
  44799. // The file size is smaller than the size of two chunks, so it does
  44800. // not make any sense to abort the request and retry with a range
  44801. // request.
  44802. return;
  44803. }
  44804. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  44805. // We can continue fetching when progressive loading is enabled,
  44806. // and we don't need the autoFetch feature.
  44807. source.disableAutoFetch = true;
  44808. } else {
  44809. // NOTE: by cancelling the full request, and then issuing range
  44810. // requests, there will be an issue for sites where you can only
  44811. // request the pdf once. However, if this is the case, then the
  44812. // server should not be returning that it can support range
  44813. // requests.
  44814. networkManager.abortRequest(fullRequestXhrId);
  44815. }
  44816. try {
  44817. pdfManager = new NetworkPdfManager(docId, source, handler);
  44818. pdfManagerCapability.resolve(pdfManager);
  44819. } catch (ex) {
  44820. pdfManagerCapability.reject(ex);
  44821. }
  44822. cancelXHRs = null;
  44823. },
  44824. onProgressiveData: source.disableStream ? null :
  44825. function onProgressiveData(chunk) {
  44826. if (!pdfManager) {
  44827. cachedChunks.push(chunk);
  44828. return;
  44829. }
  44830. pdfManager.sendProgressiveData(chunk);
  44831. },
  44832. onDone: function onDone(args) {
  44833. if (pdfManager) {
  44834. return; // already processed
  44835. }
  44836. var pdfFile;
  44837. if (args === null) {
  44838. // TODO add some streaming manager, e.g. for unknown length files.
  44839. // The data was returned in the onProgressiveData, combining...
  44840. var pdfFileLength = 0, pos = 0;
  44841. cachedChunks.forEach(function (chunk) {
  44842. pdfFileLength += chunk.byteLength;
  44843. });
  44844. if (source.length && pdfFileLength !== source.length) {
  44845. warn('reported HTTP length is different from actual');
  44846. }
  44847. var pdfFileArray = new Uint8Array(pdfFileLength);
  44848. cachedChunks.forEach(function (chunk) {
  44849. pdfFileArray.set(new Uint8Array(chunk), pos);
  44850. pos += chunk.byteLength;
  44851. });
  44852. pdfFile = pdfFileArray.buffer;
  44853. } else {
  44854. pdfFile = args.chunk;
  44855. }
  44856. // the data is array, instantiating directly from it
  44857. try {
  44858. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  44859. pdfManagerCapability.resolve(pdfManager);
  44860. } catch (ex) {
  44861. pdfManagerCapability.reject(ex);
  44862. }
  44863. cancelXHRs = null;
  44864. },
  44865. onError: function onError(status) {
  44866. var exception;
  44867. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  44868. exception = new MissingPDFException('Missing PDF "' +
  44869. source.url + '".');
  44870. handler.send('MissingPDF', exception);
  44871. } else {
  44872. exception = new UnexpectedResponseException(
  44873. 'Unexpected server response (' + status +
  44874. ') while retrieving PDF "' + source.url + '".', status);
  44875. handler.send('UnexpectedResponse', exception);
  44876. }
  44877. cancelXHRs = null;
  44878. },
  44879. onProgress: function onProgress(evt) {
  44880. handler.send('DocProgress', {
  44881. loaded: evt.loaded,
  44882. total: evt.lengthComputable ? evt.total : source.length
  44883. });
  44884. }
  44885. });
  44886. cancelXHRs = function () {
  44887. networkManager.abortRequest(fullRequestXhrId);
  44888. };
  44889. return pdfManagerCapability.promise;
  44890. }
  44891. var setupDoc = function(data) {
  44892. var onSuccess = function(doc) {
  44893. ensureNotTerminated();
  44894. handler.send('GetDoc', { pdfInfo: doc });
  44895. };
  44896. var onFailure = function(e) {
  44897. if (e instanceof PasswordException) {
  44898. if (e.code === PasswordResponses.NEED_PASSWORD) {
  44899. handler.send('NeedPassword', e);
  44900. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  44901. handler.send('IncorrectPassword', e);
  44902. }
  44903. } else if (e instanceof InvalidPDFException) {
  44904. handler.send('InvalidPDF', e);
  44905. } else if (e instanceof MissingPDFException) {
  44906. handler.send('MissingPDF', e);
  44907. } else if (e instanceof UnexpectedResponseException) {
  44908. handler.send('UnexpectedResponse', e);
  44909. } else {
  44910. handler.send('UnknownError',
  44911. new UnknownErrorException(e.message, e.toString()));
  44912. }
  44913. };
  44914. ensureNotTerminated();
  44915. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  44916. -1 : data.maxImageSize;
  44917. PDFJS.disableFontFace = data.disableFontFace;
  44918. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  44919. PDFJS.verbosity = data.verbosity;
  44920. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  44921. null : data.cMapUrl;
  44922. PDFJS.cMapPacked = data.cMapPacked === true;
  44923. getPdfManager(data).then(function (newPdfManager) {
  44924. if (terminated) {
  44925. // We were in a process of setting up the manager, but it got
  44926. // terminated in the middle.
  44927. newPdfManager.terminate();
  44928. throw new Error('Worker was terminated');
  44929. }
  44930. pdfManager = newPdfManager;
  44931. handler.send('PDFManagerReady', null);
  44932. pdfManager.onLoadedStream().then(function(stream) {
  44933. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  44934. });
  44935. }).then(function pdfManagerReady() {
  44936. ensureNotTerminated();
  44937. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  44938. ensureNotTerminated();
  44939. // Try again with recoveryMode == true
  44940. if (!(ex instanceof XRefParseException)) {
  44941. if (ex instanceof PasswordException) {
  44942. // after password exception prepare to receive a new password
  44943. // to repeat loading
  44944. pdfManager.passwordChanged().then(pdfManagerReady);
  44945. }
  44946. onFailure(ex);
  44947. return;
  44948. }
  44949. pdfManager.requestLoadedStream();
  44950. pdfManager.onLoadedStream().then(function() {
  44951. ensureNotTerminated();
  44952. loadDocument(true).then(onSuccess, onFailure);
  44953. });
  44954. }, onFailure);
  44955. }, onFailure);
  44956. };
  44957. handler.on('GetPage', function wphSetupGetPage(data) {
  44958. return pdfManager.getPage(data.pageIndex).then(function(page) {
  44959. var rotatePromise = pdfManager.ensure(page, 'rotate');
  44960. var refPromise = pdfManager.ensure(page, 'ref');
  44961. var viewPromise = pdfManager.ensure(page, 'view');
  44962. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  44963. function(results) {
  44964. return {
  44965. rotate: results[0],
  44966. ref: results[1],
  44967. view: results[2]
  44968. };
  44969. });
  44970. });
  44971. });
  44972. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  44973. var ref = new Ref(data.ref.num, data.ref.gen);
  44974. var catalog = pdfManager.pdfDocument.catalog;
  44975. return catalog.getPageIndex(ref);
  44976. });
  44977. handler.on('GetDestinations',
  44978. function wphSetupGetDestinations(data) {
  44979. return pdfManager.ensureCatalog('destinations');
  44980. }
  44981. );
  44982. handler.on('GetDestination',
  44983. function wphSetupGetDestination(data) {
  44984. return pdfManager.ensureCatalog('getDestination', [data.id]);
  44985. }
  44986. );
  44987. handler.on('GetAttachments',
  44988. function wphSetupGetAttachments(data) {
  44989. return pdfManager.ensureCatalog('attachments');
  44990. }
  44991. );
  44992. handler.on('GetJavaScript',
  44993. function wphSetupGetJavaScript(data) {
  44994. return pdfManager.ensureCatalog('javaScript');
  44995. }
  44996. );
  44997. handler.on('GetOutline',
  44998. function wphSetupGetOutline(data) {
  44999. return pdfManager.ensureCatalog('documentOutline');
  45000. }
  45001. );
  45002. handler.on('GetMetadata',
  45003. function wphSetupGetMetadata(data) {
  45004. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  45005. pdfManager.ensureCatalog('metadata')]);
  45006. }
  45007. );
  45008. handler.on('GetData', function wphSetupGetData(data) {
  45009. pdfManager.requestLoadedStream();
  45010. return pdfManager.onLoadedStream().then(function(stream) {
  45011. return stream.bytes;
  45012. });
  45013. });
  45014. handler.on('GetStats',
  45015. function wphSetupGetStats(data) {
  45016. return pdfManager.pdfDocument.xref.stats;
  45017. }
  45018. );
  45019. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  45020. pdfManager.updatePassword(data);
  45021. });
  45022. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  45023. return pdfManager.getPage(data.pageIndex).then(function(page) {
  45024. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  45025. });
  45026. });
  45027. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  45028. var pageIndex = data.pageIndex;
  45029. pdfManager.getPage(pageIndex).then(function(page) {
  45030. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  45031. startWorkerTask(task);
  45032. var pageNum = pageIndex + 1;
  45033. var start = Date.now();
  45034. // Pre compile the pdf page and fetch the fonts/images.
  45035. page.getOperatorList(handler, task, data.intent).then(
  45036. function(operatorList) {
  45037. finishWorkerTask(task);
  45038. info('page=' + pageNum + ' - getOperatorList: time=' +
  45039. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  45040. }, function(e) {
  45041. finishWorkerTask(task);
  45042. if (task.terminated) {
  45043. return; // ignoring errors from the terminated thread
  45044. }
  45045. // For compatibility with older behavior, generating unknown
  45046. // unsupported feature notification on errors.
  45047. handler.send('UnsupportedFeature',
  45048. {featureId: UNSUPPORTED_FEATURES.unknown});
  45049. var minimumStackMessage =
  45050. 'worker.js: while trying to getPage() and getOperatorList()';
  45051. var wrappedException;
  45052. // Turn the error into an obj that can be serialized
  45053. if (typeof e === 'string') {
  45054. wrappedException = {
  45055. message: e,
  45056. stack: minimumStackMessage
  45057. };
  45058. } else if (typeof e === 'object') {
  45059. wrappedException = {
  45060. message: e.message || e.toString(),
  45061. stack: e.stack || minimumStackMessage
  45062. };
  45063. } else {
  45064. wrappedException = {
  45065. message: 'Unknown exception type: ' + (typeof e),
  45066. stack: minimumStackMessage
  45067. };
  45068. }
  45069. handler.send('PageError', {
  45070. pageNum: pageNum,
  45071. error: wrappedException,
  45072. intent: data.intent
  45073. });
  45074. });
  45075. });
  45076. }, this);
  45077. handler.on('GetTextContent', function wphExtractText(data) {
  45078. var pageIndex = data.pageIndex;
  45079. var normalizeWhitespace = data.normalizeWhitespace;
  45080. return pdfManager.getPage(pageIndex).then(function(page) {
  45081. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  45082. startWorkerTask(task);
  45083. var pageNum = pageIndex + 1;
  45084. var start = Date.now();
  45085. return page.extractTextContent(task, normalizeWhitespace).then(
  45086. function(textContent) {
  45087. finishWorkerTask(task);
  45088. info('text indexing: page=' + pageNum + ' - time=' +
  45089. (Date.now() - start) + 'ms');
  45090. return textContent;
  45091. }, function (reason) {
  45092. finishWorkerTask(task);
  45093. if (task.terminated) {
  45094. return; // ignoring errors from the terminated thread
  45095. }
  45096. throw reason;
  45097. });
  45098. });
  45099. });
  45100. handler.on('Cleanup', function wphCleanup(data) {
  45101. return pdfManager.cleanup();
  45102. });
  45103. handler.on('Terminate', function wphTerminate(data) {
  45104. terminated = true;
  45105. if (pdfManager) {
  45106. pdfManager.terminate();
  45107. pdfManager = null;
  45108. }
  45109. if (cancelXHRs) {
  45110. cancelXHRs();
  45111. }
  45112. var waitOn = [];
  45113. WorkerTasks.forEach(function (task) {
  45114. waitOn.push(task.finished);
  45115. task.terminate();
  45116. });
  45117. return Promise.all(waitOn).then(function () {
  45118. // Notice that even if we destroying handler, resolved response promise
  45119. // must be sent back.
  45120. handler.destroy();
  45121. handler = null;
  45122. });
  45123. });
  45124. handler.on('Ready', function wphReady(data) {
  45125. setupDoc(docParams);
  45126. docParams = null; // we don't need docParams anymore -- saving memory.
  45127. });
  45128. return workerHandlerName;
  45129. }
  45130. };
  45131. var consoleTimer = {};
  45132. var workerConsole = {
  45133. log: function log() {
  45134. var args = Array.prototype.slice.call(arguments);
  45135. globalScope.postMessage({
  45136. targetName: 'main',
  45137. action: 'console_log',
  45138. data: args
  45139. });
  45140. },
  45141. error: function error() {
  45142. var args = Array.prototype.slice.call(arguments);
  45143. globalScope.postMessage({
  45144. targetName: 'main',
  45145. action: 'console_error',
  45146. data: args
  45147. });
  45148. throw 'pdf.js execution error';
  45149. },
  45150. time: function time(name) {
  45151. consoleTimer[name] = Date.now();
  45152. },
  45153. timeEnd: function timeEnd(name) {
  45154. var time = consoleTimer[name];
  45155. if (!time) {
  45156. error('Unknown timer name ' + name);
  45157. }
  45158. this.log('Timer:', name, Date.now() - time);
  45159. }
  45160. };
  45161. // Worker thread?
  45162. if (typeof window === 'undefined' &&
  45163. !(typeof module !== 'undefined' && module.require)) {
  45164. if (!('console' in globalScope)) {
  45165. globalScope.console = workerConsole;
  45166. }
  45167. var handler = new MessageHandler('worker', 'main', self);
  45168. WorkerMessageHandler.setup(handler, self);
  45169. }
  45170. exports.WorkerTask = WorkerTask;
  45171. exports.WorkerMessageHandler = WorkerMessageHandler;
  45172. }));
  45173. }).call((typeof window === 'undefined') ? this : window);
  45174. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  45175. // workerSrc is not set -- using last script url to define default location
  45176. PDFJS.workerSrc = (function () {
  45177. 'use strict';
  45178. var pdfJsSrc = document.currentScript.src;
  45179. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  45180. })();
  45181. }